Class: DocumentsController

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

#polymorphic_filter_params

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



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

def autocomplete
  @documents = Queries::DocumentAutocompleteQuery.new(params[:term], project_id: params[:project_id]).all
  data = @documents.collect do |t|
    {
      id: t.id,
      label: ApplicationController.helpers.document_tag(t),
      response_values: {
        params[:method] => t.id
      },
      label_html: ApplicationController.helpers.document_tag(t) 
    }
  end

  render :json => data
end

- (Object) create

POST /documents POST /documents.json



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

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

- (Object) destroy

DELETE /documents/1 DELETE /documents/1.json



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

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

- (Object) document_params (private)



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

def document_params
  params.require(:document).permit(:document_file, :initialize_start_page)  
end

- (Object) edit

GET /documents/1/edit



24
25
# File 'app/controllers/documents_controller.rb', line 24

def edit
end

- (Object) index

GET /documents GET /documents.json



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

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

- (Object) list



67
68
69
# File 'app/controllers/documents_controller.rb', line 67

def list
  @documents = Document.with_project_id($project_id).order(:id).page(params[:page]) #.per(10)
end

- (Object) new

GET /documents/new



19
20
21
# File 'app/controllers/documents_controller.rb', line 19

def new
  @document = Document.new
end

- (Object) search



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

def search
  if params[:id].blank?
    redirect_to documents_path, notice: '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

- (Object) set_document (private)



97
98
99
# File 'app/controllers/documents_controller.rb', line 97

def set_document
  @document = Document.find(params[:id])
end

- (Object) show

GET /documents/1 GET /documents/1.json



15
16
# File 'app/controllers/documents_controller.rb', line 15

def show
end

- (Object) update

PATCH/PUT /documents/1 PATCH/PUT /documents/1.json



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

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