Class: AssertedEnvironmentsController

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

#set_time_zone

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, #cumulative_projects_created_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_initials, #project_link, #project_login_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #sound_cumulative_gb_per_year, #sound_gb_per_year, #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

#asserted_environment_paramsObject (private)



122
123
124
125
126
127
# File 'app/controllers/asserted_environments_controller.rb', line 122

def asserted_environment_params
  params.require(:asserted_environment).permit(
    :asserted_environment_object_id, :asserted_environment_object_type,
    :uri, :uri_label, :position
  )
end

#autocompleteObject

GET /asserted_environments/autocomplete.json



91
92
93
94
95
96
# File 'app/controllers/asserted_environments_controller.rb', line 91

def autocomplete
  @asserted_environments = ::Queries::AssertedEnvironment::Autocomplete.new(
    params.require(:term),
    project_id: sessions_current_project_id
  ).autocomplete
end

#autoselectObject

GET /asserted_environments/autoselect



99
100
101
102
103
104
105
106
107
# File 'app/controllers/asserted_environments_controller.rb', line 99

def autoselect
  render json: ::Autoselect::AssertedEnvironment::Autoselect.new(
    term: params[:term],
    level: params[:level],
    project_id: sessions_current_project_id,
    user_id: sessions_current_user_id,
    **autoselect_params
  ).response
end

#autoselect_paramsObject (private)



129
130
131
# File 'app/controllers/asserted_environments_controller.rb', line 129

def autoselect_params
  params.permit(:show_info).to_h.symbolize_keys
end

#createObject

POST /asserted_environments.json



60
61
62
63
64
65
66
67
68
# File 'app/controllers/asserted_environments_controller.rb', line 60

def create
  @asserted_environment = AssertedEnvironment.new(asserted_environment_params)

  if @asserted_environment.save
    render :show, status: :created, location: @asserted_environment
  else
    render json: @asserted_environment.errors, status: :unprocessable_content
  end
end

#destroyObject

DELETE /asserted_environments/1.json



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

def destroy
  if @asserted_environment.destroy
    head :no_content
  else
    render json: @asserted_environment.errors, status: :unprocessable_content
  end
end

#downloadObject

GET /asserted_environments/download



42
43
44
45
46
47
48
49
# File 'app/controllers/asserted_environments_controller.rb', line 42

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

#editObject

GET /asserted_environments/1/edit



56
57
# File 'app/controllers/asserted_environments_controller.rb', line 56

def edit
end

#indexObject

GET /asserted_environments or /asserted_environments.json



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

def index
  respond_to do |format|
    format.html {
      @recent_objects = AssertedEnvironment
        .where(project_id: sessions_current_project_id)
        .order(updated_at: :desc).limit(10)

      render '/shared/data/all/index'
    }
    format.json {
      @asserted_environments = ::Queries::AssertedEnvironment::Filter.new(params).all
        .where(project_id: sessions_current_project_id)
        .includes(:asserted_environment_object)
        .order(:cached, :id)
        .page(params[:page]).per(params[:per] || 500)
    }
  end
end

#listObject

GET /asserted_environments/list



34
35
36
37
38
39
# File 'app/controllers/asserted_environments_controller.rb', line 34

def list
  @asserted_environments = AssertedEnvironment
    .where(project_id: sessions_current_project_id)
    .order(:id)
    .page(params[:page])
end

#newObject

GET /asserted_environments/new



52
53
# File 'app/controllers/asserted_environments_controller.rb', line 52

def new
end

#object_typesObject

GET /asserted_environments/object_types



110
111
112
# File 'app/controllers/asserted_environments_controller.rb', line 110

def object_types
  render json: ENVIRONMENT_ASSERTABLE_TYPES.sort
end

#searchObject

GET /asserted_environments/search Target of the quick search form (see _quick_search_form.html.erb).



81
82
83
84
85
86
87
88
# File 'app/controllers/asserted_environments_controller.rb', line 81

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

#set_asserted_environmentObject (private)



116
117
118
119
120
# File 'app/controllers/asserted_environments_controller.rb', line 116

def set_asserted_environment
  @asserted_environment = AssertedEnvironment
    .where(project_id: sessions_current_project_id)
    .find(params[:id])
end

#showObject

GET /asserted_environments/1 or /asserted_environments/1.json



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

def show
end