Class: TagsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- TagsController
- Defined in:
- app/controllers/tags_controller.rb
Instance Method Summary collapse
-
#batch_create ⇒ Object
POST /tags/batch_create.json?keyword_id=123&object_type=CollectionObject&object_ids[]=123.
-
#batch_remove ⇒ Object
POST /tags/batch_remove?keyword_id=123&klass=456.
-
#create ⇒ Object
POST /tags POST /tags.json.
-
#destroy ⇒ Object
DELETE /tags/1 DELETE /tags/1.json.
-
#download ⇒ Object
GET /tags/download.
- #exists ⇒ Object
-
#index ⇒ Object
GET /tags GET /tags.json.
- #list ⇒ Object
- #new ⇒ Object
- #set_tag ⇒ Object private
- #tag_object_update ⇒ Object
- #tag_params ⇒ Object private
- #taggable_object ⇒ Object private
- #taggable_object_params ⇒ Object private
-
#update ⇒ Object
PATCH/PUT /tags/1 PATCH/PUT /tags/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
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
#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form
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
#batch_create ⇒ Object
POST /tags/batch_create.json?keyword_id=123&object_type=CollectionObject&object_ids[]=123
116 117 118 119 120 121 122 123 124 |
# File 'app/controllers/tags_controller.rb', line 116 def batch_create if Tag.batch_create( params.permit(:keyword_id, :object_type, object_ids: []).to_h.merge(user_id: sessions_current_user_id, project_id: sessions_current_project_id).symbolize_keys ) render json: {success: true} else render json: {success: false} end end |
#batch_remove ⇒ Object
POST /tags/batch_remove?keyword_id=123&klass=456
107 108 109 110 111 112 113 |
# File 'app/controllers/tags_controller.rb', line 107 def batch_remove if Tag.batch_remove(params.require(:keyword_id), params.require(:klass)) render json: {success: true} else render json: {success: false} end end |
#create ⇒ Object
POST /tags POST /tags.json
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/tags_controller.rb', line 41 def create @tag = Tag.new(tag_params) respond_to do |format| if @tag.save format.html { redirect_to url_for(@tag.tag_object.), notice: "Tag #{@tag.keyword.name} was successfully created." } format.json { render action: 'show', status: :created, location: @tag } else format.html { redirect_back(fallback_location: (request.referer || root_path), notice: 'Tag was NOT successfully created.') } format.json { render json: @tag.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /tags/1 DELETE /tags/1.json
76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/tags_controller.rb', line 76 def destroy @tag.destroy! respond_to do |format| # TODO: probably needs to be changed with new annotator format.html { redirect_back(fallback_location: (request.referer || root_path), notice: 'Tag was successfully destroyed.') } format.json { head :no_content } end end |
#download ⇒ Object
GET /tags/download
101 102 103 104 |
# File 'app/controllers/tags_controller.rb', line 101 def download send_data Export::Download.generate_csv(Tag.where(project_id: sessions_current_project_id)), type: 'text', filename: "tags_#{DateTime.now}.csv" end |
#exists ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/tags_controller.rb', line 90 def exists if @tag = Tag.exists?(params.require(:global_id), params.require(:keyword_id), sessions_current_project_id) render :show else render json: false end end |
#index ⇒ Object
GET /tags GET /tags.json
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/tags_controller.rb', line 10 def index respond_to do |format| format.html { @recent_objects = ::Tag.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10) render '/shared/data/all/index' } format.json { @tags = ::Queries::Tag::Filter.new(params).all.where(project_id: sessions_current_project_id). page(params[:page]).per(params[:per] || 500) } end end |
#list ⇒ Object
86 87 88 |
# File 'app/controllers/tags_controller.rb', line 86 def list @tags = Tag.where(project_id: sessions_current_project_id).order(:id).page(params[:page]) end |
#new ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/tags_controller.rb', line 23 def new if !Keyword.with_project_id(sessions_current_project_id).any? # if there are none @return_path = "/tags/new?tag[tag_object_attribute]=&tag[tag_object_id]=#{params[:tag_object_id]}" \ "&tag[tag_object_type]=#{params[:tag_object_type]}" redirect_to new_controlled_vocabulary_term_path(return_path: @return_path), notice: 'Create a keyword or two first!' and return end @taggable_object = taggable_object end |
#set_tag ⇒ Object (private)
128 129 130 |
# File 'app/controllers/tags_controller.rb', line 128 def set_tag @tag = Tag.with_project_id(sessions_current_project_id).find(params[:id]) end |
#tag_object_update ⇒ Object
34 35 36 37 |
# File 'app/controllers/tags_controller.rb', line 34 def tag_object_update taggable_object.update!(taggable_object_params) redirect_back(fallback_location: (request.referer || root_path)) end |
#tag_params ⇒ Object (private)
132 133 134 135 136 137 |
# File 'app/controllers/tags_controller.rb', line 132 def tag_params params.require(:tag).permit( :keyword_id, :tag_object_id, :tag_object_type, :tag_object_attribute, :annotated_global_entity, :_destroy, keyword_attributes: [:name, :definition, :uri, :uri_relation, :css_color] ) end |
#taggable_object ⇒ Object (private)
147 148 149 |
# File 'app/controllers/tags_controller.rb', line 147 def taggable_object whitelist_constantize(params.require(:tag_object_type)).find(params.require(:tag_object_id)) end |
#taggable_object_params ⇒ Object (private)
139 140 141 142 143 144 145 |
# File 'app/controllers/tags_controller.rb', line 139 def taggable_object_params params.require(:taggable_object).permit( tags_attributes: [:_destroy, :id, :keyword_id, :position, keyword_attributes: [:name, :definition, :uri, :html_color] ]) end |
#update ⇒ Object
PATCH/PUT /tags/1 PATCH/PUT /tags/1.json
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/tags_controller.rb', line 60 def update respond_to do |format| if @tag.update(tag_params) format.html { redirect_to url_for(@tag.tag_object.), notice: 'Tag was successfully updated.' } format.json { render :show, status: :ok, location: @tag } else format.html { redirect_back(fallback_location: (request.referer || root_path), notice: 'Tag was NOT successfully updated.') } format.json { render json: @tag.errors, status: :unprocessable_entity } end end end |