Class: NamespacesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- NamespacesController
- Defined in:
- app/controllers/namespaces_controller.rb
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 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
#autocomplete ⇒ Object
79 80 81 |
# File 'app/controllers/namespaces_controller.rb', line 79 def autocomplete @namespaces = Queries::Namespace::Autocomplete.new(params.require(:term)).all end |
#batch_load ⇒ Object
93 94 |
# File 'app/controllers/namespaces_controller.rb', line 93 def batch_load end |
#batch_params ⇒ Object (private)
134 135 136 |
# File 'app/controllers/namespaces_controller.rb', line 134 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
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/namespaces_controller.rb', line 29 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
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/controllers/namespaces_controller.rb', line 107 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
59 60 61 62 63 64 65 |
# File 'app/controllers/namespaces_controller.rb', line 59 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
84 85 86 |
# File 'app/controllers/namespaces_controller.rb', line 84 def download send_data Export::Download.generate_csv(Namespace.all), type: 'text', filename: "namespaces_#{DateTime.now}.csv" end |
#edit ⇒ Object
GET /namespaces/1/edit
24 25 |
# File 'app/controllers/namespaces_controller.rb', line 24 def edit end |
#index ⇒ Object
GET /namespaces GET /namespaces.json
8 9 10 11 |
# File 'app/controllers/namespaces_controller.rb', line 8 def index @recent_objects = Namespace.order(updated_at: :desc).limit(10) render '/shared/data/all/index' end |
#list ⇒ Object
67 68 69 |
# File 'app/controllers/namespaces_controller.rb', line 67 def list @namespaces = Namespace.order(:id).page(params[:page]) #.per(10) #.per(3) end |
#namespace_params ⇒ Object (private)
130 131 132 |
# File 'app/controllers/namespaces_controller.rb', line 130 def namespace_params params.require(:namespace).permit(:institution, :name, :short_name, :verbatim_short_name, :delimiter) end |
#new ⇒ Object
GET /namespaces/new
19 20 21 |
# File 'app/controllers/namespaces_controller.rb', line 19 def new @namespace = Namespace.new end |
#preview_simple_batch_load ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'app/controllers/namespaces_controller.rb', line 96 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
71 72 73 74 75 76 77 |
# File 'app/controllers/namespaces_controller.rb', line 71 def search if params[:id].blank? redirect_to namespace_path, notice: '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
89 90 91 |
# File 'app/controllers/namespaces_controller.rb', line 89 def @namespaces = Namespace.select_optimized(sessions_current_user_id, sessions_current_project_id, params.require(:klass)) end |
#set_namespace ⇒ Object (private)
125 126 127 128 |
# File 'app/controllers/namespaces_controller.rb', line 125 def set_namespace @namespace = Namespace.find(params[:id]) @recent_object = @namespace end |
#show ⇒ Object
GET /namespaces/1 GET /namespaces/1.json
15 16 |
# File 'app/controllers/namespaces_controller.rb', line 15 def show end |
#update ⇒ Object
PATCH/PUT /namespaces/1 PATCH/PUT /namespaces/1.json
45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/namespaces_controller.rb', line 45 def update respond_to do |format| if @namespace.update(namespace_params) format.html { redirect_to @namespace, notice: 'Namespace was successfully updated.' } format.json { head :no_content } else format.html { render action: 'edit' } format.json { render json: @namespace.errors, status: :unprocessable_entity } end end end |