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

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

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

#confidence_objectObject (private)



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

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



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

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)



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

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)



134
135
136
137
138
139
140
# File 'app/controllers/confidences_controller.rb', line 134

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



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

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



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

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



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

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

#editObject

GET /confidences/1/edit



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

def edit
end

#existsObject



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

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



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

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



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

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

#newObject

GET /confidences/new



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

def new
  @confidence_object = confidence_object
end

#searchObject



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

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)



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

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



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

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