Class: RepositoriesController

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

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::SharedDataControllerConfiguration

#set_is_shared_data_model

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

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

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#autocompleteObject



80
81
82
# File 'app/controllers/repositories_controller.rb', line 80

def autocomplete
  @repositories = ::Queries::Repository::Autocomplete.new(params[:term], **autocomplete_params).autocomplete
end

#autocomplete_paramsObject (private)



96
97
98
# File 'app/controllers/repositories_controller.rb', line 96

def autocomplete_params
  params.permit(alternate_value_type: []).merge(project_id: sessions_current_project_id).to_h.symbolize_keys
end

#createObject

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

#destroyObject

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

#downloadObject

GET /repositories/download



85
86
87
# File 'app/controllers/repositories_controller.rb', line 85

def download
  send_data Export::CSV.generate_csv(Repository.all), type: 'text', filename: "repositories_#{DateTime.now}.tsv"
end

#editObject

GET /repositories/1/edit



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

def edit
end

#indexObject

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

#listObject



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

#newObject

GET /repositories/new



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

def new
  @repository = Repository.new
end

#repository_paramsObject (private)



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

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

#searchObject



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, alert: '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

#select_optionsObject

GET /repositories/select_options



90
91
92
# File 'app/controllers/repositories_controller.rb', line 90

def select_options
  @repositories = Repository.select_optimized(sessions_current_user_id, sessions_current_project_id)
end

#set_repositoryObject (private)



100
101
102
103
# File 'app/controllers/repositories_controller.rb', line 100

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

#showObject

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



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

def show
end

#updateObject

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