Class: ConfidencesController

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

Overview

query_scope: taxon_name_query:

mode:

:add
:replace
:remove

keyword_id confidence_level_id

Constant Summary

Constants included from ProjectsHelper

ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

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

#batch_by_filter_scopeObject

POST



124
125
126
127
128
129
130
131
132
133
134
135
# File 'app/controllers/confidences_controller.rb', line 124

def batch_by_filter_scope
  if r = Confidence.batch_by_filter_scope(
      mode: params[:mode] || :add,
      filter_query: params.require(:filter_query), # like filter_query: { otu_query: {}}
      confidence_level_id: params.require(:confidence_level_id),
      replace_confidence_level_id: params[:replace_confidence_level_id]
  )
    render json: r.to_json, status: :ok
  else
    render json: {}, status: :unprocessable_entity
  end
end

#confidence_objectObject (private)



151
152
153
154
155
156
157
158
159
# File 'app/controllers/confidences_controller.rb', line 151

def confidence_object
  a = params[:confidence_object_type]
  b = params[:confidence_object_id]
  if a && b && o = whitelist_constantize(a)&.find(b)
    o
  else
    redirect_to confidences_path, alert: 'Object paramaters confidence_object_type and confidence_object_id were not provided.' and return
  end
end

#confidence_object_updateObject



80
81
82
83
84
85
86
87
88
# File 'app/controllers/confidences_controller.rb', line 80

def confidence_object_update
  @confidence_object = confidence_object
  if @confidence_object.update(confidences_params)
    flash[:notice] = 'Successfully updated record.'
  else
    flash[:error] = "Error updating record: #{@confidence_object.errors.full_messages.join('; ')}."
  end
  redirect_to new_confidence_path(confidence_object_type: @confidence_object.class.name, confidence_object_id: @confidence_object.id.to_s)
end

#confidence_paramsObject (private)



143
144
145
146
147
148
149
# File 'app/controllers/confidences_controller.rb', line 143

def confidence_params
  params.require(:confidence).permit(
    :annotated_global_entity,
    :confidence_level_id, :confidence_object_id, :confidence_object_type,
    confidence_level_attributes: [:_destroy, :id, :name, :definition, :uri, :uri_relation]
  )
end

#confidences_paramsObject (private)



161
162
163
164
165
166
167
# File 'app/controllers/confidences_controller.rb', line 161

def confidences_params
  params.require(:confidence_object).permit(
    :annotated_global_entity,
    :confidence_level_id,
    confidence_level_attributes: [:_destroy, :id, :name, :definition, :uri, :uri_relation]
  )
end

#createObject

POST /confidences POST /confidences.json



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/confidences_controller.rb', line 51

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

#destroyObject

DELETE /confidences/1 DELETE /confidences/1.json



92
93
94
95
96
97
98
# File 'app/controllers/confidences_controller.rb', line 92

def destroy
  @confidence.destroy
  respond_to do |format|
    format.html { redirect_to confidences_url, notice: 'Confidence was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#downloadObject

GET /confidences/download



109
110
111
# File 'app/controllers/confidences_controller.rb', line 109

def download
  send_data Export::CSV.generate_csv(Confidence.where(project_id: sessions_current_project_id)), type: 'text', filename: "confidences_#{DateTime.now}.tsv"
end

#editObject

GET /confidences/1/edit



42
43
# File 'app/controllers/confidences_controller.rb', line 42

def edit
end

#existsObject



113
114
115
116
117
118
119
120
121
# File 'app/controllers/confidences_controller.rb', line 113

def exists
  if @confidence = Confidence.exists?(params.require(:global_id),
      params.require(:confidence_level_id),
      sessions_current_project_id)
    render :show
  else
    render json: false
  end
end

#indexObject

GET /confidences GET /confidences.json GET /<model>/:id/confidences.json



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/confidences_controller.rb', line 23

def index
  respond_to do |format|
    format.html {
      @recent_objects = ::Confidence.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    }
    format.json {
      @confidences = ::Queries::Confidence::Filter.new(params).all.where(project_id: sessions_current_project_id).
      page(params[:page]).per(params[:per] || 500)
    }
  end
end

#listObject



45
46
47
# File 'app/controllers/confidences_controller.rb', line 45

def list
  @confidences = Confidence.with_project_id(sessions_current_project_id).page(params[:page])
end

#newObject

GET /confidences/new



37
38
39
# File 'app/controllers/confidences_controller.rb', line 37

def new
  @confidence_object = confidence_object
end

#searchObject



100
101
102
103
104
105
106
# File 'app/controllers/confidences_controller.rb', line 100

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

#set_confidenceObject (private)



139
140
141
# File 'app/controllers/confidences_controller.rb', line 139

def set_confidence
  @confidence = Confidence.where(project_id: sessions_current_project_id).find(params[:id])
end

#updateObject

PATCH/PUT /confidences/1 PATCH/PUT /confidences/1.json



68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/confidences_controller.rb', line 68

def update
  respond_to do |format|
    if @confidence.update(confidence_params)
      format.html { redirect_to @confidence, notice: 'Confidence was successfully updated.' }
      format.json { render :show, status: :ok, location: @confidence }
    else
      format.html { render :edit }
      format.json { render json: @confidence.errors, status: :unprocessable_entity }
    end
  end
end