Class: NamespacesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::SharedDataControllerConfiguration
Defined in:
app/controllers/namespaces_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods included from DataControllerConfiguration::SharedDataControllerConfiguration

#set_is_shared_data_model

Methods inherited from ApplicationController

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) autocomplete



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/controllers/namespaces_controller.rb', line 107

def autocomplete
  @namespaces = Namespace.find_for_autocomplete(params)

  data = @namespaces.collect do |t|
    {id: t.id,
     label: ApplicationController.helpers.namespace_tag(t),
     response_values: {
         params[:method] => t.id
     },
     label_html: ApplicationController.helpers.namespace_tag(t)
    }
  end

  render :json => data
end

- (Object) batch_load



3
4
# File 'app/controllers/namespaces_controller.rb', line 3

def batch_load
end

- (Object) batch_params (private)



143
144
145
# File 'app/controllers/namespaces_controller.rb', line 143

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

- (Object) create

POST /namespaces POST /namespaces.json



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/namespaces_controller.rb', line 57

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

- (Object) create_simple_batch_load



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/namespaces_controller.rb', line 17

def create_simple_batch_load
  if params[:file] && digested_cookie_exists?(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

- (Object) destroy

DELETE /namespaces/1 DELETE /namespaces/1.json



87
88
89
90
91
92
93
# File 'app/controllers/namespaces_controller.rb', line 87

def destroy
  @namespace.destroy
  respond_to do |format|
    format.html { redirect_to namespaces_url }
    format.json { head :no_content }
  end
end

- (Object) download

GET /namespaces/download



124
125
126
# File 'app/controllers/namespaces_controller.rb', line 124

def download
  send_data Download.generate_csv(Namespace.all), type: 'text', filename: "namespaces_#{DateTime.now.to_s}.csv"
end

- (Object) edit

GET /namespaces/1/edit



52
53
# File 'app/controllers/namespaces_controller.rb', line 52

def edit
end

- (Object) index

GET /namespaces GET /namespaces.json



36
37
38
39
# File 'app/controllers/namespaces_controller.rb', line 36

def index
  @recent_objects = Namespace.order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



95
96
97
# File 'app/controllers/namespaces_controller.rb', line 95

def list
  @namespaces = Namespace.order(:id).page(params[:page]) #.per(10) #.per(3)
end

- (Object) namespace_params (private)



139
140
141
# File 'app/controllers/namespaces_controller.rb', line 139

def namespace_params
  params.require(:namespace).permit(:institution, :name, :short_name, :verbatim_short_name)
end

- (Object) new

GET /namespaces/new



47
48
49
# File 'app/controllers/namespaces_controller.rb', line 47

def new
  @namespace = Namespace.new
end

- (Object) preview_simple_batch_load



6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/namespaces_controller.rb', line 6

def preview_simple_batch_load 
  if params[:file] 
    @result = BatchLoad::Import::Namespaces::SimpleInterpreter.new(batch_params)
    digest_cookie(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

- (Object) search



99
100
101
102
103
104
105
# File 'app/controllers/namespaces_controller.rb', line 99

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

- (Object) select_options



128
129
130
# File 'app/controllers/namespaces_controller.rb', line 128

def select_options
  @namespaces = Namespace.select_optimized(sessions_current_user_id, sessions_current_project_id, params[:klass])
end

- (Object) set_namespace (private)



134
135
136
137
# File 'app/controllers/namespaces_controller.rb', line 134

def set_namespace
  @namespace = Namespace.find(params[:id])
  @recent_object = @namespace
end

- (Object) show

GET /namespaces/1 GET /namespaces/1.json



43
44
# File 'app/controllers/namespaces_controller.rb', line 43

def show
end

- (Object) update

PATCH/PUT /namespaces/1 PATCH/PUT /namespaces/1.json



73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/namespaces_controller.rb', line 73

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