Class: AlternateValuesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/alternate_values_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

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

#alternate_value_paramsObject (private)



124
125
126
127
128
129
130
# File 'app/controllers/alternate_values_controller.rb', line 124

def alternate_value_params
  params.require(:alternate_value).permit(
    :value, :type, :language_id,
    :alternate_value_object_type, :alternate_value_object_id,
    :alternate_value_object_attribute, :is_community_annotation, :annotated_global_entity
  )
end

#autocompleteObject



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

def autocomplete
  @alternate_values = AlternateValue.find_for_autocomplete(params.merge(project_id: sessions_current_project_id))

  data = @alternate_values.collect do |t|
    str = render_to_string(partial: 'tag', locals: {alternate_value: t})
    {id:              t.id,
      label:           str,
      response_values: {params[:method] => t.id},
      label_html:      str
    }
  end

  render json: data
end

#breakout_types(collection) ⇒ Object (private)



132
133
134
# File 'app/controllers/alternate_values_controller.rb', line 132

def breakout_types(collection)
  collection
end

#createObject

POST /alternate_values POST /alternate_values.json



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/alternate_values_controller.rb', line 38

def create
  @alternate_value = AlternateValue.new(alternate_value_params)
  respond_to do |format|
    @alternate_value.project_id = sessions_current_project_id if params[:project_members_only] == 'checked'

    if @alternate_value.save
      format.html { redirect_to url_for(@alternate_value.alternate_value_object.metamorphosize), notice: 'Alternate value was successfully created.' }
      format.json { render action: :show, status: :created, location: @alternate_value.metamorphosize }
    else
      format.html { render 'new', notice: 'Alternate value was NOT successfully created.' }
      format.json { render json: @alternate_value.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /alternate_values/1 DELETE /alternate_values/1.json



70
71
72
73
74
75
76
# File 'app/controllers/alternate_values_controller.rb', line 70

def destroy
  @alternate_value.destroy
  respond_to do |format|
    format.html { destroy_redirect @alternate_value, notice: 'Alternate value was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#downloadObject

GET /alternate_values/download



108
109
110
# File 'app/controllers/alternate_values_controller.rb', line 108

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

#editObject



32
33
34
# File 'app/controllers/alternate_values_controller.rb', line 32

def edit
  @alternate_value = AlternateValue.find_by_id(params[:id]).metamorphosize
end

#indexObject

GET /alternate_values GET /alternate_values.json



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/alternate_values_controller.rb', line 9

def index
  respond_to do |format|
    format.html {
      # !! This is project-only, it will be tricky to find all created at this point. We would have
      # to reference all project members and link through created/modified on all community opbjects.
      # These would show up throughout the Users project as well, confusing things across project.
      @recent_objects = ::Queries::AlternateValue::Filter.new(params.merge(project_id: sessions_current_project_id))
        .all
        .order(updated_at: :desc).limit(10)
        render '/shared/data/all/index'
    }
    format.json {
      # !! You must merge project_id to handle community data exceptions.  This is a contrast to other filter patterns
      # where the project_id is scoped here.
      @alternate_values = ::Queries::AlternateValue::Filter.new(
        params.merge(project_id: sessions_current_project_id)
      )
      .all.page(params[:page])
      .per(params[:per])
    }
  end
end

#listObject



78
79
80
# File 'app/controllers/alternate_values_controller.rb', line 78

def list
  @alternate_values = AlternateValue.where(project_id: sessions_current_project_id).order(:alternate_value_object_type).page(params[:page])
end

#metadataObject

GET /alternate_values/:global_id/metadata



113
114
115
# File 'app/controllers/alternate_values_controller.rb', line 113

def 
  @object = GlobalID::Locator.locate(params.require(:global_id))
end

#searchObject

GET /alternate_values/search



83
84
85
86
87
88
89
90
# File 'app/controllers/alternate_values_controller.rb', line 83

def search
  if params[:id].blank?
    redirect_to alternate_values_path, alert: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    altval = AlternateValue.find_by_id(params[:id]).metamorphosize
    redirect_to url_for(altval.alternate_value_object.metamorphosize)
  end
end

#set_alternate_valueObject (private)



119
120
121
122
# File 'app/controllers/alternate_values_controller.rb', line 119

def set_alternate_value
  @alternate_value = AlternateValue.find(params[:id])
  render status: :not_found if @alternate_value.project_id.present? && (sessions_current_project_id != @alternate_value.project_id)
end

#updateObject

PATCH/PUT /alternate_values/1 PATCH/PUT /alternate_values/1.json



55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/alternate_values_controller.rb', line 55

def update
  respond_to do |format|
    @alternate_value.project_id = sessions_current_project_id if params[:project_members_only] == 'checked'
    if @alternate_value.update(alternate_value_params)
      format.html { redirect_to url_for(@alternate_value.alternate_value_object.metamorphosize), notice: 'Alternate value was successfully updated.' }
      format.json { render action: :show, status: :ok, location: @alternate_value.metamorphosize }
    else
      format.html { redirect_back(fallback_location: (request.referer || root_path), notice: 'Alternate value was NOT successfully updated.')}
      format.json { render json: @alternate_value.errors, status: :unprocessable_entity }
    end
  end
end