Class: AlternateValuesController

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

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

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

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

Methods included from Api::Intercept

#intercept_api

Instance Method Details

#alternate_value_paramsObject (private)



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

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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/alternate_values_controller.rb', line 81

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)



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

def breakout_types(collection)
  collection
end

#createObject

POST /alternate_values POST /alternate_values.json



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/alternate_values_controller.rb', line 27

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



59
60
61
62
63
64
65
# File 'app/controllers/alternate_values_controller.rb', line 59

def destroy
  @alternate_value.destroy
  respond_to do |format|
    format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Alternate value was successfully destroyed.')}
    format.json { head :no_content }
  end
end

#downloadObject

GET /alternate_values/download



97
98
99
# File 'app/controllers/alternate_values_controller.rb', line 97

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

#editObject



21
22
23
# File 'app/controllers/alternate_values_controller.rb', line 21

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

#indexObject

GET /alternate_values GET /alternate_values.json



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/alternate_values_controller.rb', line 8

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

#listObject



67
68
69
# File 'app/controllers/alternate_values_controller.rb', line 67

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



102
103
104
# File 'app/controllers/alternate_values_controller.rb', line 102

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

#searchObject

GET /alternate_values/search



72
73
74
75
76
77
78
79
# File 'app/controllers/alternate_values_controller.rb', line 72

def search
  if params[:id].blank?
    redirect_to alternate_values_path, notice: '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)



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

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

#updateObject

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



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/alternate_values_controller.rb', line 44

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 json: @alternate_value, 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