Class: MatViews::Admin::MatViewDefinitionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/mat_views/admin/mat_view_definitions_controller.rb

Overview

MatViews::Admin::MatViewDefinitionsController


Admin CRUD controller for MatViewDefinition records.

Responsibilities:

  • Full CRUD lifecycle: index, show, new, create, edit, update, destroy.

  • Admin-only actions to trigger materialised view operations:

  • Integrates with Turbo Frames (uses frame-aware redirects/responses).

  • Normalizes array fields (‘unique_index_columns`, `dependencies`) from comma-separated params into arrays.

Filters:

  • ‘before_action :set_definition` for member actions.

  • ‘before_action :normalize_array_fields` for create/update.

  • ‘before_action :ensure_frame` to enforce frame context.

Instance Method Summary collapse

Methods included from AuthBridge

#user

Instance Method Details

#createvoid

This method returns an undefined value.

POST /:lang/admin/definitions

Creates a new definition from params.



77
78
79
80
81
82
83
84
85
# File 'app/controllers/mat_views/admin/mat_view_definitions_controller.rb', line 77

def create
  authorize_mat_views!(:create, MatViews::MatViewDefinition)
  @definition = MatViews::MatViewDefinition.new(definition_params)
  if @definition.save
    handle_frame_response(status: 298)
  else
    render 'form', formats: :html, layout: 'mat_views/turbo_frame', status: :unprocessable_content
  end
end

#create_nowvoid

This method returns an undefined value.

POST /:lang/admin/definitions/:id/create_now

Immediately enqueues a background job to create the materialised view.



131
132
133
134
135
136
137
138
139
140
# File 'app/controllers/mat_views/admin/mat_view_definitions_controller.rb', line 131

def create_now
  force = params[:force].to_s.downcase == 'true'
  authorize_mat_views!(:create_view, @definition)
  MatViews::Jobs::Adapter.enqueue(
    MatViews::CreateViewJob,
    queue: MatViews.configuration.job_queue,
    args: [@definition.id, force, row_count_strategy]
  )
  handle_frame_response
end

#delete_nowvoid

This method returns an undefined value.

POST /:lang/admin/definitions/:id/delete_now

Immediately enqueues a background job to delete the materialised view.



162
163
164
165
166
167
168
169
170
171
172
# File 'app/controllers/mat_views/admin/mat_view_definitions_controller.rb', line 162

def delete_now
  authorize_mat_views!(:delete_view, @definition)

  cascade = params[:cascade].to_s.downcase == 'true'
  MatViews::Jobs::Adapter.enqueue(
    MatViews::DeleteViewJob,
    queue: MatViews.configuration.job_queue,
    args: [@definition.id, cascade, row_count_strategy]
  )
  handle_frame_response
end

#destroyvoid

This method returns an undefined value.

DELETE /:lang/admin/definitions/:id

Destroys the definition. Frame-specific redirect/empty response.



116
117
118
119
120
121
122
123
124
# File 'app/controllers/mat_views/admin/mat_view_definitions_controller.rb', line 116

def destroy
  authorize_mat_views!(:destroy, @definition)
  @definition.destroy!
  if @frame_id == 'dash-definitions'
    redirect_to admin_mat_view_definitions_path(frame_id: @frame_id, frame_action: @frame_action), status: :see_other
  else
    render 'empty', formats: :html, layout: 'mat_views/turbo_frame', status: 298
  end
end

#editvoid

This method returns an undefined value.

GET /:lang/admin/definitions/:id/edit

Renders the edit form for an existing definition.



92
93
94
95
# File 'app/controllers/mat_views/admin/mat_view_definitions_controller.rb', line 92

def edit
  authorize_mat_views!(:update, @definition)
  render 'form', formats: :html, layout: 'mat_views/turbo_frame'
end

#indexvoid

This method returns an undefined value.

GET /:lang/admin/definitions

Lists all definitions with existence checks against the database.



39
40
41
42
43
44
45
46
47
# File 'app/controllers/mat_views/admin/mat_view_definitions_controller.rb', line 39

def index
  # sleep 20
  authorize_mat_views!(:read, MatViews::MatViewDefinition)
  @definitions = MatViews::MatViewDefinition.order(:name).to_a
  @mv_exists_map = @definitions.index_with do |defn|
    MatViews::Services::CheckMatviewExists.new(defn).call.response[:exists]
  end
  render 'index', formats: :html, layout: 'mat_views/turbo_frame'
end

#newvoid

This method returns an undefined value.

GET /:lang/admin/definitions/new

Renders the new definition form.



66
67
68
69
70
# File 'app/controllers/mat_views/admin/mat_view_definitions_controller.rb', line 66

def new
  authorize_mat_views!(:create, MatViews::MatViewDefinition)
  @definition = MatViews::MatViewDefinition.new
  render 'form', formats: :html, layout: 'mat_views/turbo_frame'
end

#refreshvoid

This method returns an undefined value.

POST /:lang/admin/definitions/:id/refresh

Immediately enqueues a background job to refresh the materialised view.



147
148
149
150
151
152
153
154
155
# File 'app/controllers/mat_views/admin/mat_view_definitions_controller.rb', line 147

def refresh
  authorize_mat_views!(:refresh, @definition)
  MatViews::Jobs::Adapter.enqueue(
    MatViews::RefreshViewJob,
    queue: MatViews.configuration.job_queue,
    args: [@definition.id, row_count_strategy]
  )
  handle_frame_response
end

#showvoid

This method returns an undefined value.

GET /:lang/admin/definitions/:id

Shows a single definition, including run history.



54
55
56
57
58
59
# File 'app/controllers/mat_views/admin/mat_view_definitions_controller.rb', line 54

def show
  authorize_mat_views!(:read, @definition)
  @mv_exists = MatViews::Services::CheckMatviewExists.new(@definition).call.response[:exists]
  @runs = @definition.mat_view_runs.order(created_at: :desc).to_a
  render 'show', formats: :html, layout: 'mat_views/turbo_frame'
end

#updatevoid

This method returns an undefined value.

PATCH/PUT /:lang/admin/definitions/:id

Updates an existing definition.



102
103
104
105
106
107
108
109
# File 'app/controllers/mat_views/admin/mat_view_definitions_controller.rb', line 102

def update
  authorize_mat_views!(:update, @definition)
  if @definition.update(definition_params)
    handle_frame_response(status: 298)
  else
    render 'form', formats: :html, layout: 'mat_views/turbo_frame', status: :unprocessable_content
  end
end