Class: DocumentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- DocumentsController
- Defined in:
- app/controllers/documents_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #autocomplete ⇒ Object
-
#create ⇒ Object
POST /documents POST /documents.json.
-
#destroy ⇒ Object
DELETE /documents/1 DELETE /documents/1.json.
- #document_params ⇒ Object private
-
#download ⇒ Object
GET /documents/download.
-
#edit ⇒ Object
GET /documents/1/edit.
-
#file_extensions ⇒ Object
GET /documents/file_extensions.json.
-
#index ⇒ Object
GET /documents GET /documents.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /documents/new.
- #search ⇒ Object
-
#select_options ⇒ Object
GET /documents/select_options?target=Source.
- #set_document ⇒ Object private
-
#show ⇒ Object
GET /documents/1 GET /documents/1.json.
-
#update ⇒ Object
PATCH/PUT /documents/1 PATCH/PUT /documents/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
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, #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
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#autocomplete ⇒ Object
98 99 100 |
# File 'app/controllers/documents_controller.rb', line 98 def autocomplete @documents = Queries::Document::Autocomplete.new(params[:term], project_id: params[:project_id]).all end |
#create ⇒ Object
POST /documents POST /documents.json
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/documents_controller.rb', line 42 def create @document = Document.new(document_params) respond_to do |format| if @document.save format.html { redirect_to @document, notice: 'Document was successfully created.' } format.json { render action: 'show', status: :created, location: @document } else format.html { render action: 'new' } format.json { render json: @document.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /documents/1 DELETE /documents/1.json
72 73 74 75 76 77 78 |
# File 'app/controllers/documents_controller.rb', line 72 def destroy @document.destroy respond_to do |format| format.html { redirect_to documents_url, notice: 'Document was successfully destroyed.' } format.json { head :no_content } end end |
#document_params ⇒ Object (private)
118 119 120 |
# File 'app/controllers/documents_controller.rb', line 118 def document_params params.require(:document).permit(:document_file, :initialize_start_page, :is_public) end |
#download ⇒ Object
GET /documents/download
81 82 83 84 |
# File 'app/controllers/documents_controller.rb', line 81 def download send_data Export::CSV.generate_csv( Document.where(project_id: sessions_current_project_id)), type: 'text', filename: "documents_#{DateTime.now}.tsv" end |
#edit ⇒ Object
GET /documents/1/edit
37 38 |
# File 'app/controllers/documents_controller.rb', line 37 def edit end |
#file_extensions ⇒ Object
GET /documents/file_extensions.json
108 109 110 |
# File 'app/controllers/documents_controller.rb', line 108 def file_extensions @extension_groups = FILE_EXTENSIONS_DATA end |
#index ⇒ Object
GET /documents GET /documents.json
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/documents_controller.rb', line 8 def index respond_to do |format| format.html { @recent_objects = Document .recent_from_project_id(sessions_current_project_id) .order(updated_at: :desc) .limit(10) render '/shared/data/all/index' } format.json { @documents = ::Queries::Document::Filter.new(params).all .order(updated_at: :desc) .page(params[:page]) .per(params[:per]) } end end |
#list ⇒ Object
86 87 88 |
# File 'app/controllers/documents_controller.rb', line 86 def list @documents = Document.with_project_id(sessions_current_project_id).order(:id).page(params[:page]) #.per(10) end |
#new ⇒ Object
GET /documents/new
32 33 34 |
# File 'app/controllers/documents_controller.rb', line 32 def new @document = Document.new end |
#search ⇒ Object
90 91 92 93 94 95 96 |
# File 'app/controllers/documents_controller.rb', line 90 def search if params[:id].blank? redirect_to documents_path, alert: 'You must select an item from the list with a click or tab press before clicking show.' else redirect_to document_path(params[:id]) end end |
#select_options ⇒ Object
GET /documents/select_options?target=Source
103 104 105 |
# File 'app/controllers/documents_controller.rb', line 103 def @documents = Document.select_optimized(sessions_current_user_id, sessions_current_project_id, params[:target]) end |
#set_document ⇒ Object (private)
114 115 116 |
# File 'app/controllers/documents_controller.rb', line 114 def set_document @document = Document.where(project_id: sessions_current_project_id).find(params[:id]) end |
#show ⇒ Object
GET /documents/1 GET /documents/1.json
28 29 |
# File 'app/controllers/documents_controller.rb', line 28 def show end |
#update ⇒ Object
PATCH/PUT /documents/1 PATCH/PUT /documents/1.json
58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/documents_controller.rb', line 58 def update respond_to do |format| if @document.update(document_params) format.html { redirect_to @document, notice: 'Document was successfully updated.' } format.json { render :show, status: :ok, location: @document } else format.html { render :edit } format.json { render json: @document.errors, status: :unprocessable_entity } end end end |