Class: Observ::DatasetRunItemsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/observ/dataset_run_items_controller.rb

Instance Method Summary collapse

Instance Method Details

#details_drawerObject



9
10
11
# File 'app/controllers/observ/dataset_run_items_controller.rb', line 9

def details_drawer
  # The drawer template will use @run_item
end

#scoreObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/observ/dataset_run_items_controller.rb', line 17

def score
  value = params[:value].to_i == 1 ? 1.0 : 0.0

  score = @run_item.scores.find_or_initialize_by(name: "manual", source: :manual)
  score.assign_attributes(
    value: value,
    data_type: :boolean,
    comment: params[:comment],
    created_by: params[:created_by]
  )

  if score.save
    respond_to do |format|
      format.turbo_stream do
        render turbo_stream: [
          turbo_stream.replace("run-item-#{@run_item.id}-scores",
            partial: "observ/dataset_run_items/scores_cell",
            locals: { run_item: @run_item }),
          turbo_stream.update("drawer-content",
            partial: "observ/dataset_run_items/score_close_drawer")
        ]
      end
      format.html do
        if params[:review_mode].present?
          redirect_to review_dataset_run_path(@dataset, @run),
            notice: "Score saved!"
        else
          redirect_to dataset_run_path(@dataset, @run)
        end
      end
    end
  else
    respond_to do |format|
      format.turbo_stream do
        render turbo_stream: turbo_stream.replace(
          "drawer-content",
          partial: "observ/dataset_run_items/score_drawer",
          locals: { run_item: @run_item, error: score.errors.full_messages.join(", ") }
        )
      end
      format.html do
        if params[:review_mode].present?
          redirect_to review_dataset_run_path(@dataset, @run),
            alert: "Failed to save score: #{score.errors.full_messages.join(', ')}"
        else
          redirect_to dataset_run_path(@dataset, @run), alert: "Failed to save score."
        end
      end
    end
  end
end

#score_drawerObject



13
14
15
# File 'app/controllers/observ/dataset_run_items_controller.rb', line 13

def score_drawer
  # Renders the score drawer partial
end