add archived template and submission pages
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TemplatesArchivedController < ApplicationController
|
||||
def index
|
||||
templates = current_account.templates.where.not(deleted_at: nil).preload(:author).order(id: :desc)
|
||||
|
||||
@pagy, @templates = pagy(templates, items: 12)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TemplatesArchivedSubmissionsController < ApplicationController
|
||||
def show
|
||||
@template = current_account.templates.find(params[:template_id])
|
||||
|
||||
@pagy, @submissions = pagy(@template.submissions.where.not(deleted_at: nil).preload(:submitters).order(id: :desc))
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
@@ -4,9 +4,11 @@ class TemplatesController < ApplicationController
|
||||
before_action :load_base_template, only: %i[new create]
|
||||
|
||||
def show
|
||||
@template = current_account.templates.active.find(params[:id])
|
||||
@template = current_account.templates.find(params[:id])
|
||||
submissions = @template.submissions
|
||||
submissions = submissions.active if @template.deleted_at.blank?
|
||||
|
||||
@pagy, @submissions = pagy(@template.submissions.active.preload(:submitters).order(id: :desc))
|
||||
@pagy, @submissions = pagy(submissions.preload(:submitters).order(id: :desc))
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TemplatesRestoreController < ApplicationController
|
||||
def create
|
||||
template = current_account.templates.find(params[:template_id])
|
||||
|
||||
template.update!(deleted_at: nil)
|
||||
|
||||
redirect_to template_path(template), notice: 'Template has been unarchived'
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user