Class: ConfidencesController

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

- (Object) confidence_object (private)



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

def confidence_object
  whitelist_constantize(params.require(:confidence_object_type)).find(params.require(:confidence_object_id))
end

- (Object) confidence_object_update



66
67
68
69
70
71
72
73
74
# File 'app/controllers/confidences_controller.rb', line 66

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

- (Object) confidence_params (private)



105
106
107
108
109
110
111
# File 'app/controllers/confidences_controller.rb', line 105

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

- (Object) confidences_params (private)



117
118
119
120
121
122
123
# File 'app/controllers/confidences_controller.rb', line 117

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

- (Object) create

POST /confidences POST /confidences.json



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/confidences_controller.rb', line 37

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

- (Object) destroy

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



78
79
80
81
82
83
84
# File 'app/controllers/confidences_controller.rb', line 78

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

- (Object) download

GET /confidences/download



95
96
97
# File 'app/controllers/confidences_controller.rb', line 95

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

- (Object) edit

GET /confidences/1/edit



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

def edit
end

- (Object) index

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



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

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

- (Object) list



31
32
33
# File 'app/controllers/confidences_controller.rb', line 31

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

- (Object) new

GET /confidences/new



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

def new
  @confidence_object = confidence_object
end

- (Object) search



86
87
88
89
90
91
92
# File 'app/controllers/confidences_controller.rb', line 86

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

- (Object) set_confidence (private)



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

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

- (Object) update

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



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

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