Class: CitationsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/citations_controller.rb

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

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

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

Methods included from Api::Intercept

#intercept_api

Instance Method Details

#api_indexObject



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

def api_index
  @citations = Queries::Citation::Filter.new(params).all
    .where(project_id: sessions_current_project_id).includes(:source)
    .order('sources.cached, sources.pages')
    .page(params[:page]).per(params[:per] || 50)     ### error when 500 !!
  @verbose_object = params[:verbose_object]
  render '/citations/api/v1/index'
end

#api_showObject



128
129
130
131
# File 'app/controllers/citations_controller.rb', line 128

def api_show
  @citation = Citation.where(project_id: sessions_current_project_id).find(params[:id])
  render '/citations/api/v1/show'
end

#autocompleteObject



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

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

#citation_paramsObject (private)



139
140
141
142
143
144
145
146
147
148
149
# File 'app/controllers/citations_controller.rb', line 139

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

#createObject

POST /citations POST /citations.json



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

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

#destroyObject

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



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

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, ' + @citation.errors.full_messages.join('; '))}
      format.json {render json: @citation.errors, status: :unprocessable_entity}
    end
  end
end

#downloadObject

GET /citations/download



115
116
117
# File 'app/controllers/citations_controller.rb', line 115

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

#editObject



28
29
30
# File 'app/controllers/citations_controller.rb', line 28

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

#indexObject

GET /citations GET /citations.json



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

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(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

#listObject



86
87
88
# File 'app/controllers/citations_controller.rb', line 86

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

#newObject



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

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

#searchObject



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

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

#set_citationObject (private)



135
136
137
# File 'app/controllers/citations_controller.rb', line 135

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

#showObject

Presently only used in autocomplete



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

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

#updateObject

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



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

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