Class: NamespacesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- NamespacesController
- Defined in:
- app/controllers/namespaces_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #autocomplete ⇒ Object
- #batch_load ⇒ Object
- #batch_params ⇒ Object private
-
#create ⇒ Object
POST /namespaces POST /namespaces.json.
- #create_simple_batch_load ⇒ Object
-
#destroy ⇒ Object
DELETE /namespaces/1 DELETE /namespaces/1.json.
-
#download ⇒ Object
GET /namespaces/download.
-
#edit ⇒ Object
GET /namespaces/1/edit.
-
#index ⇒ Object
GET /namespaces GET /namespaces.json.
- #list ⇒ Object
- #namespace_params ⇒ Object private
-
#new ⇒ Object
GET /namespaces/new.
- #preview_simple_batch_load ⇒ Object
- #search ⇒ Object
-
#select_options ⇒ Object
GET /namespaces/select_options?klass=CollectionObject.
- #set_namespace ⇒ Object private
-
#show ⇒ Object
GET /namespaces/1 GET /namespaces/1.json.
-
#update ⇒ Object
PATCH/PUT /namespaces/1 PATCH/PUT /namespaces/1.json.
Methods included from DataControllerConfiguration::SharedDataControllerConfiguration
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
#autocomplete ⇒ Object
88 89 90 |
# File 'app/controllers/namespaces_controller.rb', line 88 def autocomplete @namespaces = Queries::Namespace::Autocomplete.new(params.require(:term)).all end |
#batch_load ⇒ Object
102 103 |
# File 'app/controllers/namespaces_controller.rb', line 102 def batch_load end |
#batch_params ⇒ Object (private)
142 143 144 |
# File 'app/controllers/namespaces_controller.rb', line 142 def batch_params params.permit(:file, :import_level).merge(user_id: sessions_current_user_id, project_id: sessions_current_project_id).to_h.symbolize_keys end |
#create ⇒ Object
POST /namespaces POST /namespaces.json
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/namespaces_controller.rb', line 38 def create @namespace = Namespace.new(namespace_params) respond_to do |format| if @namespace.save format.html { redirect_to @namespace, notice: "Namespace '#{@namespace.name}' was successfully created." } format.json { render action: 'show', status: :created, location: @namespace } else format.html { render action: 'new' } format.json { render json: @namespace.errors, status: :unprocessable_entity } end end end |
#create_simple_batch_load ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/controllers/namespaces_controller.rb', line 116 def create_simple_batch_load if params[:file] && (params[:file].tempfile, :Simple_namespaces_md5) @result = BatchLoad::Import::Namespaces::SimpleInterpreter.new(**batch_params) if @result.create flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} namespaces were created." render 'namespaces/batch_load/simple/create' and return else flash[:alert] = 'Batch import failed.' end else flash[:alert] = 'File to batch upload must be supplied.' end render :batch_load end |
#destroy ⇒ Object
DELETE /namespaces/1 DELETE /namespaces/1.json
68 69 70 71 72 73 74 |
# File 'app/controllers/namespaces_controller.rb', line 68 def destroy @namespace.destroy respond_to do |format| format.html { redirect_to namespaces_url } format.json { head :no_content } end end |
#download ⇒ Object
GET /namespaces/download
93 94 95 |
# File 'app/controllers/namespaces_controller.rb', line 93 def download send_data Export::CSV.generate_csv(Namespace.all), type: 'text', filename: "namespaces_#{DateTime.now}.tsv" end |
#edit ⇒ Object
GET /namespaces/1/edit
32 33 34 |
# File 'app/controllers/namespaces_controller.rb', line 32 def edit redirect_to new_namespace_task_path(namespace_id: @namespace.to_param) end |
#index ⇒ Object
GET /namespaces GET /namespaces.json
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/namespaces_controller.rb', line 8 def index respond_to do |format| format.html do @recent_objects = Namespace.order(updated_at: :desc).limit(10) render '/shared/data/all/index' end format.json { @namespaces = Queries::Namespace::Filter.new(params).all.page(params[:page]).per(params[:per]) } end end |
#list ⇒ Object
76 77 78 |
# File 'app/controllers/namespaces_controller.rb', line 76 def list @namespaces = Namespace.order(:id).page(params[:page]) #.per(10) #.per(3) end |
#namespace_params ⇒ Object (private)
138 139 140 |
# File 'app/controllers/namespaces_controller.rb', line 138 def namespace_params params.require(:namespace).permit(:institution, :name, :short_name, :verbatim_short_name, :delimiter, :is_virtual) end |
#new ⇒ Object
GET /namespaces/new
26 27 28 29 |
# File 'app/controllers/namespaces_controller.rb', line 26 def new redirect_to new_namespace_task_path # @namespace = Namespace.new end |
#preview_simple_batch_load ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'app/controllers/namespaces_controller.rb', line 105 def preview_simple_batch_load if params[:file] @result = BatchLoad::Import::Namespaces::SimpleInterpreter.new(**batch_params) (params[:file].tempfile, :Simple_namespaces_md5) render 'namespaces/batch_load/simple/preview' else flash[:notice] = 'No file provided!' redirect_to action: :batch_load end end |
#search ⇒ Object
80 81 82 83 84 85 86 |
# File 'app/controllers/namespaces_controller.rb', line 80 def search if params[:id].blank? redirect_to namespace_path, alert: 'You must select an item from the list with a click or tab press before clicking show.' else redirect_to namespace_path(params[:id]) end end |
#select_options ⇒ Object
GET /namespaces/select_options?klass=CollectionObject
98 99 100 |
# File 'app/controllers/namespaces_controller.rb', line 98 def @namespaces = Namespace.select_optimized(sessions_current_user_id, sessions_current_project_id, params.require(:klass)) end |
#set_namespace ⇒ Object (private)
133 134 135 136 |
# File 'app/controllers/namespaces_controller.rb', line 133 def set_namespace @namespace = Namespace.find(params[:id]) @recent_object = @namespace end |
#show ⇒ Object
GET /namespaces/1 GET /namespaces/1.json
22 23 |
# File 'app/controllers/namespaces_controller.rb', line 22 def show end |
#update ⇒ Object
PATCH/PUT /namespaces/1 PATCH/PUT /namespaces/1.json
54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/namespaces_controller.rb', line 54 def update respond_to do |format| if @namespace.update(namespace_params) format.html { redirect_to @namespace, notice: 'Namespace was successfully updated.' } format.json { render action: 'show', status: :ok, location: @namespace } else format.html { render action: 'edit' } format.json { render json: @namespace.errors, status: :unprocessable_entity } end end end |