Class: ContentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ContentsController
- Defined in:
- app/controllers/contents_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
-
#api_index ⇒ Object
GET /api/v1/content.
-
#api_show ⇒ Object
GET /api/v1/content/:id.
- #autocomplete ⇒ Object
- #content_params ⇒ Object private
-
#create ⇒ Object
POST /contents POST /contents.json.
-
#destroy ⇒ Object
DELETE /contents/1 DELETE /contents/1.json.
-
#download ⇒ Object
GET /contents/download.
-
#edit ⇒ Object
GET /contents/1/edit.
-
#index ⇒ Object
GET /contents GET /contents.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /contents/new.
- #search ⇒ Object
- #select_options ⇒ Object
- #set_content ⇒ Object private
-
#show ⇒ Object
GET /contents/1 GET /contents/1.json.
-
#update ⇒ Object
PATCH/PUT /contents/1 PATCH/PUT /contents/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
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, #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
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#api_index ⇒ Object
GET /api/v1/content
121 122 123 124 125 126 127 |
# File 'app/controllers/contents_controller.rb', line 121 def api_index @contents = ::Queries::Content::Filter.new(params.merge!(api: true)).all .order('contents.otu_id, contents.topic_id') .page(params[:page]) .per(params[:per]) render '/contents/api/v1/index' end |
#api_show ⇒ Object
GET /api/v1/content/:id
130 131 132 |
# File 'app/controllers/contents_controller.rb', line 130 def api_show render '/contents/api/v1/show' end |
#autocomplete ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/controllers/contents_controller.rb', line 97 def autocomplete @contents = ::Content.find_for_autocomplete(params).where(project_id: sessions_current_project_id) data = @contents.collect do |t| {id: t.id, label: ApplicationController.helpers.taxon_works_content_tag(t), response_values: { params[:method] => t.id }, label_html: ApplicationController.helpers.taxon_works_content_tag(t) } end render json: data end |
#content_params ⇒ Object (private)
141 142 143 |
# File 'app/controllers/contents_controller.rb', line 141 def content_params params.require(:content).permit(:text, :otu_id, :topic_id, :is_public) end |
#create ⇒ Object
POST /contents POST /contents.json
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/contents_controller.rb', line 37 def create @content = ::Content.new(content_params) respond_to do |format| if @content.save format.html { redirect_to url_for(@content), notice: 'Content was successfully created.' } format.json { render :show, status: :created, location: @content } else format.html { render :new } format.json { render json: @content.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /contents/1 DELETE /contents/1.json
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/contents_controller.rb', line 67 def destroy @content.destroy respond_to do |format| if @content.destroyed? format.html { destroy_redirect @content, notice: 'Content was successfully destroyed.' } format.json { head :no_content} else format.html { destroy_redirect @content, notice: 'Content was not destroyed, ' + @content.errors..join('; ') } format.json { render json: @content.errors, status: :unprocessable_entity } end end end |
#download ⇒ Object
GET /contents/download
113 114 115 116 117 118 |
# File 'app/controllers/contents_controller.rb', line 113 def download send_data( Export::CSV.generate_csv(::Content.where(project_id: sessions_current_project_id)), type: 'text', filename: "contents_#{DateTime.now}.tsv") end |
#edit ⇒ Object
GET /contents/1/edit
32 33 |
# File 'app/controllers/contents_controller.rb', line 32 def edit end |
#index ⇒ Object
GET /contents GET /contents.json
9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/contents_controller.rb', line 9 def index respond_to do |format| format.html do @recent_objects = ::Content.where(project_id: sessions_current_project_id).recently_updated.limit(10) render '/shared/data/all/index' end format.json { @contents = ::Queries::Content::Filter.new(params).all.page(params[:page]).per(params[:per]) } end end |
#list ⇒ Object
80 81 82 |
# File 'app/controllers/contents_controller.rb', line 80 def list @contents = ::Content.with_project_id(sessions_current_project_id).order(:id).page(params[:page]) end |
#new ⇒ Object
GET /contents/new
27 28 29 |
# File 'app/controllers/contents_controller.rb', line 27 def new @content = ::Content.new end |
#search ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'app/controllers/contents_controller.rb', line 84 def search if params[:id].blank? redirect_to content_path, alert: 'You must select an item from the list with a click or tab press before clicking show.' else redirect_to content_path(params[:id]) end end |
#select_options ⇒ Object
93 94 95 |
# File 'app/controllers/contents_controller.rb', line 93 def @contents = ::Content.select_optimized(sessions_current_user_id, sessions_current_project_id) end |
#set_content ⇒ Object (private)
136 137 138 139 |
# File 'app/controllers/contents_controller.rb', line 136 def set_content @content = ::Content.with_project_id(sessions_current_project_id).find(params[:id]) @recent_object = @content end |
#show ⇒ Object
GET /contents/1 GET /contents/1.json
23 24 |
# File 'app/controllers/contents_controller.rb', line 23 def show end |
#update ⇒ Object
PATCH/PUT /contents/1 PATCH/PUT /contents/1.json
53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/contents_controller.rb', line 53 def update respond_to do |format| if @content.update(content_params) format.html { redirect_to url_for(@content), notice: 'Content was successfully updated.' } format.json { render :show, status: :ok, location: @content } else format.html { render :edit } format.json { render json: @content.errors, status: :unprocessable_entity } end end end |