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
- #attributes ⇒ Object
- #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 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
#attributes ⇒ Object
84 85 86 87 88 89 |
# File 'app/controllers/namespaces_controller.rb', line 84 def attributes render json: ::Namespace.columns.select{ |a| (Queries::Namespace::Filter::ATTRIBUTES).include?( a.name.to_sym) }.collect{|b| {'name' => b.name, 'type' => b.type } } end |
#autocomplete ⇒ Object
99 100 101 |
# File 'app/controllers/namespaces_controller.rb', line 99 def autocomplete @namespaces = Queries::Namespace::Autocomplete.new(params.require(:term)).all end |
#batch_load ⇒ Object
113 114 |
# File 'app/controllers/namespaces_controller.rb', line 113 def batch_load end |
#batch_params ⇒ Object (private)
153 154 155 |
# File 'app/controllers/namespaces_controller.rb', line 153 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
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/namespaces_controller.rb', line 42 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_content } end end end |
#create_simple_batch_load ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/controllers/namespaces_controller.rb', line 127 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
72 73 74 75 76 77 78 |
# File 'app/controllers/namespaces_controller.rb', line 72 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
104 105 106 |
# File 'app/controllers/namespaces_controller.rb', line 104 def download send_data Export::CSV.generate_csv(Namespace.all), type: 'text', filename: "namespaces_#{DateTime.now}.tsv" end |
#edit ⇒ Object
GET /namespaces/1/edit
36 37 38 |
# File 'app/controllers/namespaces_controller.rb', line 36 def edit redirect_to new_namespace_task_path(namespace_id: @namespace.to_param) end |
#index ⇒ Object
GET /namespaces GET /namespaces.json
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/controllers/namespaces_controller.rb', line 10 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
80 81 82 |
# File 'app/controllers/namespaces_controller.rb', line 80 def list @namespaces = Namespace.order(:id).page(params[:page]) #.per(10) #.per(3) end |
#namespace_params ⇒ Object (private)
149 150 151 |
# File 'app/controllers/namespaces_controller.rb', line 149 def namespace_params params.require(:namespace).permit(:institution, :name, :short_name, :verbatim_short_name, :delimiter, :is_virtual) end |
#new ⇒ Object
GET /namespaces/new
30 31 32 33 |
# File 'app/controllers/namespaces_controller.rb', line 30 def new redirect_to new_namespace_task_path # @namespace = Namespace.new end |
#preview_simple_batch_load ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'app/controllers/namespaces_controller.rb', line 116 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
91 92 93 94 95 96 97 |
# File 'app/controllers/namespaces_controller.rb', line 91 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
109 110 111 |
# File 'app/controllers/namespaces_controller.rb', line 109 def @namespaces = Namespace.select_optimized(sessions_current_user_id, sessions_current_project_id, params.require(:klass)) end |
#set_namespace ⇒ Object (private)
144 145 146 147 |
# File 'app/controllers/namespaces_controller.rb', line 144 def set_namespace @namespace = Namespace.find(params[:id]) @recent_object = @namespace end |
#show ⇒ Object
GET /namespaces/1 GET /namespaces/1.json
26 27 |
# File 'app/controllers/namespaces_controller.rb', line 26 def show end |
#update ⇒ Object
PATCH/PUT /namespaces/1 PATCH/PUT /namespaces/1.json
58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/namespaces_controller.rb', line 58 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_content } end end end |