Class: TaxonNameClassificationsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/taxon_name_classifications_controller.rb

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#api_indexObject

GET /api/v1/taxon_name_classifications



149
150
151
152
153
154
155
156
# File 'app/controllers/taxon_name_classifications_controller.rb', line 149

def api_index
  @taxon_name_classifications = Queries::TaxonNameClassification::Filter.new(params.merge!(api: true)).all
    .where(project_id: sessions_current_project_id)
    .order('taxon_name_classifications.id')
    .page(params[:page])
    .per(params[:per])
  render '/taxon_name_classifications/api/v1/index'
end

#api_showObject

GET /api/v1/taxon_name_classifications//:id



159
160
161
# File 'app/controllers/taxon_name_classifications_controller.rb', line 159

def api_show
  render '/taxon_name_classifications/api/v1/show'
end

#autocompleteObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/controllers/taxon_name_classifications_controller.rb', line 121

def autocomplete
  # TODO: make reasonable, if used
  @taxon_name_classifications = TaxonNameClassification.where(id: params[:term]).with_project_id(params[:project_id])
  data = @taxon_name_classifications.collect do |t|
    { id: t.id,
     label: TaxonNameClassificationsHelper.taxon_name_classification_tag(t),
     response_values: {
      params[:method] => t.id,
    },
     label_html: TaxonNameClassificationsHelper.taxon_name_classification_tag(t)
 #  render_to_string(:partial => 'shared/autocomplete/taxon_name.html', :object => t)
       }
  end

  render json: data
end

#createObject

POST /taxon_name_classifications POST /taxon_name_classifications.json



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/taxon_name_classifications_controller.rb', line 35

def create
  @taxon_name_classification = TaxonNameClassification.new(taxon_name_classification_params)

  respond_to do |format|
    if @taxon_name_classification.save
      format.html {
        redirect_to url_for(@taxon_name_classification.taxon_name.metamorphosize),
                    notice: 'Taxon name classification was successfully created.'
      }
      format.json { render :show, status: :created, location: @taxon_name_classification.metamorphosize }
    else
      format.html {
        redirect_back(fallback_location: (request.referer || root_path),
                      notice: 'Taxon name classification was NOT successfully created.')
      }
      format.json { render json: @taxon_name_classification.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /taxon_name_classifications/1 DELETE /taxon_name_classifications/1.json



92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/controllers/taxon_name_classifications_controller.rb', line 92

def destroy
  @taxon_name_classification.destroy
  respond_to do |format|
    if @taxon_name_classification.destroyed?
      format.html { destroy_redirect @taxon_name_classification, notice: 'Taxon name classification was successfully destroyed.' }
      format.json { head :no_content }
    else
      format.html { destroy_redirect @taxon_name_classification, notice: 'Taxon name classification was not destroyed, ' + @taxon_name_classification.errors.full_messages.join('; ') }
      format.json { render json: @taxon_name_classification.errors, status: :unprocessable_entity }
    end
  end
end

#downloadObject

GET /taxon_name_classifications/download



139
140
141
142
# File 'app/controllers/taxon_name_classifications_controller.rb', line 139

def download
  send_data Export::CSV.generate_csv(TaxonNameClassification.where(project_id: sessions_current_project_id)),
        type: 'text', filename: "taxon_name_classifications_#{DateTime.now}.tsv"
end

#editObject



29
30
31
# File 'app/controllers/taxon_name_classifications_controller.rb', line 29

def edit
  redirect_to new_taxon_name_task_path(taxon_name_id: @taxon_name_classification.taxon_name)
end

#indexObject

GET /taxon_name_classifications GET /taxon_name_classifications.json



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/taxon_name_classifications_controller.rb', line 9

def index
  respond_to do |format|
    format.html do
      @recent_objects = TaxonNameClassification.recent_from_project_id(sessions_current_project_id)
        .order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @taxon_name_classifications = Queries::TaxonNameClassification::Filter.new(params)
        .all
        .page(params[:page])
        .per(params[:per])
    }
  end
end

#listObject



105
106
107
108
# File 'app/controllers/taxon_name_classifications_controller.rb', line 105

def list
  @taxon_name_classifications = TaxonNameClassification.with_project_id(sessions_current_project_id)
    .order(:id).page(params[:page])
end

#newObject



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/taxon_name_classifications_controller.rb', line 76

def new
  taxon_name_id = params[:taxon_name_classification].try(:[], :taxon_name_id)
  taxon_name = TaxonName.where(
    id: taxon_name_id,
    project_id: sessions_current_project_id,
  ).first

  if taxon_name
    redirect_to new_taxon_name_task_path(taxon_name_id: taxon_name.id)
  else
    redirect_to new_taxon_name_task_path, notice: 'Create TaxonNameClassifications in the context of a TaxonName.'
  end
end

#searchObject

GET /taxon_name_classifications/search



111
112
113
114
115
116
117
118
119
# File 'app/controllers/taxon_name_classifications_controller.rb', line 111

def search
  if params[:id].blank?
    redirect_to taxon_name_classification_path,
      notice: 'You must select an item from the list with a click or ' \
      'tab press before clicking show.'
  else
    redirect_to taxon_name_classification_path(params[:id])
  end
end

#set_taxon_name_classificationObject (private)



165
166
167
# File 'app/controllers/taxon_name_classifications_controller.rb', line 165

def set_taxon_name_classification
  @taxon_name_classification = TaxonNameClassification.with_project_id(sessions_current_project_id).find(params[:id])
end

#showObject

GET /taxon_name_classifications/id.json



26
27
# File 'app/controllers/taxon_name_classifications_controller.rb', line 26

def show
end

#taxon_name_classification_paramsObject (private)



169
170
171
172
173
174
# File 'app/controllers/taxon_name_classifications_controller.rb', line 169

def taxon_name_classification_params
  params.require(:taxon_name_classification).permit(
    :taxon_name_id, :type,
    origin_citation_attributes: [:id, :_destroy, :source_id, :pages],
  )
end

#taxon_name_classification_typesObject



144
145
146
# File 'app/controllers/taxon_name_classifications_controller.rb', line 144

def taxon_name_classification_types
  render json: TAXON_NAME_CLASSIFICATION_JSON
end

#updateObject

PATCH/PUT /taxon_name_classifications/1 PATCH/PUT /taxon_name_classifications/1.json



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/taxon_name_classifications_controller.rb', line 57

def update
  respond_to do |format|
    if @taxon_name_classification.update(taxon_name_classification_params)
      @taxon_name_classification = TaxonNameClassification.find(@taxon_name_classification.id)
      format.html {
        redirect_back(fallback_location: (request.referer || root_path),
                      notice: 'Taxon name classification was successfully updated.')
      }
      format.json { render :show, status: :ok, location: @taxon_name_classification.metamorphosize }
    else
      format.html {
        redirect_back(fallback_location: (request.referer || root_path),
                      notice: 'Taxon name classification was NOT successfully updated.')
      }
      format.json { render json: @taxon_name_classification.errors, status: :unprocessable_entity }
    end
  end
end