Class: RepositoriesController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::SharedDataControllerConfiguration
Defined in:
app/controllers/repositories_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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/repositories_controller.rb', line 80

def autocomplete

  @repositories = Queries::RepositoryAutocompleteQuery.new(params[:term]).all

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

  render :json => data
end

- (Object) create

POST /repositories POST /repositories.json



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/repositories_controller.rb', line 30

def create
  @repository = Repository.new(repository_params)

  respond_to do |format|
    if @repository.save
      format.html { redirect_to @repository, notice: 'Repository was successfully created.' }
      format.json { render action: 'show', status: :created, location: @repository }
    else
      format.html { render action: 'new' }
      format.json { render json: @repository.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /repositories/1 DELETE /repositories/1.json



60
61
62
63
64
65
66
# File 'app/controllers/repositories_controller.rb', line 60

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

- (Object) download

GET /repositories/download



98
99
100
# File 'app/controllers/repositories_controller.rb', line 98

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

- (Object) edit

GET /repositories/1/edit



25
26
# File 'app/controllers/repositories_controller.rb', line 25

def edit
end

- (Object) index

GET /repositories GET /repositories.json



8
9
10
11
12
# File 'app/controllers/repositories_controller.rb', line 8

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

- (Object) list



68
69
70
# File 'app/controllers/repositories_controller.rb', line 68

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

- (Object) new

GET /repositories/new



20
21
22
# File 'app/controllers/repositories_controller.rb', line 20

def new
  @repository = Repository.new
end

- (Object) repository_params (private)

Never trust parameters from the scary internet, only allow the white list through.



111
112
113
# File 'app/controllers/repositories_controller.rb', line 111

def repository_params
  params.require(:repository).permit(:name, :url, :acronym, :status, :institutional_LSID, :is_index_herbarioum_record)
end

- (Object) search



72
73
74
75
76
77
78
# File 'app/controllers/repositories_controller.rb', line 72

def search
  if params[:id].blank?
    redirect_to repositories_path, notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to repository_path(params[:id])
  end
end

- (Object) set_repository (private)

Use callbacks to share common setup or constraints between actions.



105
106
107
108
# File 'app/controllers/repositories_controller.rb', line 105

def set_repository
  @repository = Repository.find(params[:id])
  @recent_object = @repository
end

- (Object) show

GET /repositories/1 GET /repositories/1.json



16
17
# File 'app/controllers/repositories_controller.rb', line 16

def show
end

- (Object) update

PATCH/PUT /repositories/1 PATCH/PUT /repositories/1.json



46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/repositories_controller.rb', line 46

def update
  respond_to do |format|
    if @repository.update(repository_params)
      format.html { redirect_to @repository, notice: 'Repository was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: 'edit' }
      format.json { render json: @repository.errors, status: :unprocessable_entity }
    end
  end
end