Class: CitationsController

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

#annotator_params

Methods inherited from ApplicationController

#digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #project_matches, #record_not_found, #set_project_from_params

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Methods included from InterceptApi

#intercept_api, #token_authenticate

Instance Method Details

- (Object) autocomplete



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/controllers/citations_controller.rb', line 96

def autocomplete
  @citations = Citation.find_for_autocomplete(params.merge(project_id: sessions_current_project_id))
  data = @citations.collect do |t|
    lbl = render_to_string(partial: 'tag', locals: {citation: t})
    {id: t.id,
     label: lbl,
     response_values: {
         params[:method] => t.id
     },
     label_html: lbl
    }
  end

  render json: data
end

- (Object) citation_params (private)



130
131
132
133
134
135
136
137
138
139
140
# File 'app/controllers/citations_controller.rb', line 130

def citation_params
  params.require(:citation).permit(
      :citation_object_type, :citation_object_id, :source_id, :pages, :is_original,
      :annotated_global_entity,
      citation_topics_attributes: [
          :id, :_destroy, :pages, :topic_id,
          topic_attributes: [:id, :_destroy, :name, :definition]
      ],
      topics_attributes: [:name, :definition]
  )
end

- (Object) create

POST /citations POST /citations.json



42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/citations_controller.rb', line 42

def create
  @citation = Citation.new(citation_params)
  respond_to do |format|
    if @citation.save
      format.html {redirect_to url_for(@citation.citation_object.metamorphosize), notice: 'Citation was successfully created.'}
      format.json {render :show, status: :created, location: @citation}
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Citation was NOT successfully created.')}
      format.json {render json: @citation.errors, status: :unprocessable_entity}
    end
  end
end

- (Object) destroy

DELETE /citations/1 DELETE /citations/1.json



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

def destroy
  @citation.destroy
  respond_to do |format|
    if @citation.destroyed?
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Citation was successfully destroyed.')}
      format.json {head :no_content}
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Citation was not destroyed, ' + errors.messages)}
      format.json {render json: @citation.errors, status: :unprocessable_entity}
    end
  end
end

- (Object) download

GET /citations/download



113
114
115
# File 'app/controllers/citations_controller.rb', line 113

def download
  send_data Download.generate_csv(Citation.where(project_id: sessions_current_project_id)), type: 'text', filename: "citations_#{DateTime.now}.csv"
end

- (Object) edit



26
27
28
# File 'app/controllers/citations_controller.rb', line 26

def edit
  @citation = Citation.find_by_id(params[:id]).metamorphosize
end

- (Object) filter_params (private)



119
120
121
122
123
124
# File 'app/controllers/citations_controller.rb', line 119

def filter_params
  params.permit(
      :citation_object_type, :citation_object_id, :source_id,
      Citation.related_foreign_keys.map(&:to_sym)
  ).merge(project_id: sessions_current_project_id)
end

- (Object) index

GET /citations GET /citations.json



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/citations_controller.rb', line 7

def index
  respond_to do |format|
    format.html {
      @recent_objects = Citation.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    }
    format.json {
      @citations = Queries::Citation::Filter.new(filter_params).all.where(project_id: sessions_current_project_id).includes(:source)
        .order(:source_id, :pages)
        .page(params[:page]).per(params[:per] || 500)
      @verbose_object = params[:verbose_object]
    }
  end
end

- (Object) list



84
85
86
# File 'app/controllers/citations_controller.rb', line 84

def list
  @citations = Citation.with_project_id(sessions_current_project_id).order(:citation_object_type).page(params[:page]) #.per(10) #.per(3)
end

- (Object) new



22
23
24
# File 'app/controllers/citations_controller.rb', line 22

def new
  @citation = Citation.new(citation_params)
end

- (Object) search



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

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

- (Object) set_citation (private)



126
127
128
# File 'app/controllers/citations_controller.rb', line 126

def set_citation
  @citation = Citation.with_project_id(sessions_current_project_id).find(params[:id])
end

- (Object) show

Presently only used in autocomplete



31
32
33
34
35
36
37
38
# File 'app/controllers/citations_controller.rb', line 31

def show
  respond_to do |format|
    format.html {
      redirect_to url_for(@citation.annotated_object.metamorphosize)
    }
    format.json {}
  end
end

- (Object) update

PATCH/PUT /citations/1 PATCH/PUT /citations/1.json



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

def update
  respond_to do |format|
    if @citation.update(citation_params)
      format.html {redirect_to url_for(@citation.citation_object.metamorphosize), notice: 'Citation was successfully updated.'}
      format.json {render :show, location: @citation}
    else
      format.html {redirect_back(fallback_location: (request.referer || root_path), notice: 'Citation was NOT successfully updated.')}
      format.json {render json: @citation.errors, status: :unprocessable_entity}
    end
  end
end