Class: CompositionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- CompositionsController
- Includes:
- RenderControllerConfiguration
- Defined in:
- app/controllers/compositions_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #autocomplete ⇒ Object
- #composition_class ⇒ Class? private
-
#composition_params ⇒ Object
private
type is set only on create.
-
#create ⇒ Object
POST /compositions POST /compositions.json.
-
#destroy ⇒ Object
DELETE /compositions/1 DELETE /compositions/1.json.
-
#edit ⇒ Object
GET /compositions/1/edit.
-
#index ⇒ Object
GET /compositions GET /compositions.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /compositions/new.
- #search ⇒ Object
-
#select_options ⇒ Object
GET /compositions/select_options.json?type=Layout::LightTable.
- #set_composition ⇒ Object private
-
#show ⇒ Object
GET /compositions/1 GET /compositions/1.json.
-
#update ⇒ Object
PATCH/PUT /compositions/1 PATCH/PUT /compositions/1.json.
-
#visible_compositions ⇒ Scope
private
Compositions visible to the project, optionally only those of params (e.g. Layout), including its subclasses.
Methods included from RenderControllerConfiguration
#set_hub_model, #set_hub_model_metadata, #set_is_render_controller
Methods inherited from ApplicationController
Methods included from RedirectHelper
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
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
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#autocomplete ⇒ Object
99 100 101 102 103 104 105 |
# File 'app/controllers/compositions_controller.rb', line 99 def autocomplete # TODO: expand, move to queries..autocomplete @compositions = visible_compositions .where('name ILIKE ?', "%#{params.require(:term)}%") .order(:type, :name) .limit(20) end |
#composition_class ⇒ Class? (private)
124 125 126 127 128 |
# File 'app/controllers/compositions_controller.rb', line 124 def composition_class return Composition if params[:type].blank? klass = params[:type].safe_constantize klass if klass.is_a?(Class) && klass <= Composition end |
#composition_params ⇒ Object (private)
type is set only on create
146 147 148 |
# File 'app/controllers/compositions_controller.rb', line 146 def composition_params params.require(:composition).permit(:name, :description, :is_community) end |
#create ⇒ Object
POST /compositions POST /compositions.json
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/compositions_controller.rb', line 47 def create @composition = Composition.new(composition_params.merge(type: params.dig(:composition, :type))) respond_to do |format| if @composition.save format.html { redirect_to url_for(@composition.), notice: 'Composition was successfully created.' } format.json { render :show, status: :created, location: @composition. } else format.html { render :new } format.json { render json: @composition.errors, status: :unprocessable_content } end end end |
#destroy ⇒ Object
DELETE /compositions/1 DELETE /compositions/1.json
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/compositions_controller.rb', line 78 def destroy @composition.destroy respond_to do |format| if @composition.destroyed? format.html { redirect_to compositions_url, notice: 'Composition was successfully destroyed.' } format.json { head :no_content } else format.html { destroy_redirect @composition, notice: 'Composition was not destroyed, ' + @composition.errors..join('; ') } format.json { render json: @composition.errors, status: :unprocessable_content } end end end |
#edit ⇒ Object
GET /compositions/1/edit
36 37 |
# File 'app/controllers/compositions_controller.rb', line 36 def edit end |
#index ⇒ Object
GET /compositions GET /compositions.json
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/compositions_controller.rb', line 9 def index respond_to do |format| format.html do @recent_objects = Composition.visible_to_project(sessions_current_project_id) .order(updated_at: :desc).limit(10) render '/shared/data/all/index' end format.json { @compositions = visible_compositions .order(:type, :name) .page(params[:page]) .per(params[:per]) } end end |
#list ⇒ Object
39 40 41 42 43 |
# File 'app/controllers/compositions_controller.rb', line 39 def list @compositions = Composition.visible_to_project(sessions_current_project_id) .order(:id) .page(params[:page]) end |
#new ⇒ Object
GET /compositions/new
31 32 33 |
# File 'app/controllers/compositions_controller.rb', line 31 def new @composition = Composition.new end |
#search ⇒ Object
91 92 93 94 95 96 97 |
# File 'app/controllers/compositions_controller.rb', line 91 def search if params[:id].blank? redirect_to compositions_path, alert: 'You must select an item from the list with a click or tab press before clicking show.' else redirect_to composition_path(params[:id]) end end |
#select_options ⇒ Object
GET /compositions/select_options.json?type=Layout::LightTable
108 109 110 111 112 113 114 115 116 117 |
# File 'app/controllers/compositions_controller.rb', line 108 def klass = composition_class @compositions = if klass klass.select_optimized( sessions_current_user_id, sessions_current_project_id ) else {quick: [], pinboard: [], recent: []} end end |
#set_composition ⇒ Object (private)
140 141 142 143 |
# File 'app/controllers/compositions_controller.rb', line 140 def set_composition @composition = Composition.visible_to_project(sessions_current_project_id).find(params[:id]) @recent_object = @composition end |
#show ⇒ Object
GET /compositions/1 GET /compositions/1.json
27 28 |
# File 'app/controllers/compositions_controller.rb', line 27 def show end |
#update ⇒ Object
PATCH/PUT /compositions/1 PATCH/PUT /compositions/1.json
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/compositions_controller.rb', line 63 def update respond_to do |format| if @composition.update(composition_params) @composition = @composition. format.html { redirect_to url_for(@composition), notice: 'Composition was successfully updated.' } format.json { render :show, status: :ok, location: @composition } else format.html { render :edit } format.json { render json: @composition.errors, status: :unprocessable_content } end end end |
#visible_compositions ⇒ Scope (private)
Returns Compositions visible to the project, optionally only those of params (e.g. Layout), including its subclasses. An unknown type matches nothing.
134 135 136 137 138 |
# File 'app/controllers/compositions_controller.rb', line 134 def visible_compositions klass = composition_class return Composition.none if klass.nil? klass.visible_to_project(sessions_current_project_id) end |