rename to templates
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
class FlowsController < ApiBaseController
|
||||
def update
|
||||
@flow = current_account.flows.find(params[:id])
|
||||
|
||||
@flow.update!(flow_params)
|
||||
|
||||
render :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def flow_params
|
||||
params.require(:flow).permit(:name,
|
||||
schema: [%i[attachment_uuid name]],
|
||||
fields: [[:uuid, :name, :type, :required,
|
||||
{ options: [], areas: [%i[x y w h attachment_uuid page]] }]])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
class TemplatesController < ApiBaseController
|
||||
def update
|
||||
@template = current_account.templates.find(params[:id])
|
||||
|
||||
@template.update!(template_params)
|
||||
|
||||
render :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def template_params
|
||||
params.require(:template).permit(:name,
|
||||
schema: [%i[attachment_uuid name]],
|
||||
fields: [[:uuid, :name, :type, :required,
|
||||
{ options: [], areas: [%i[x y w h attachment_uuid page]] }]])
|
||||
end
|
||||
end
|
||||
end
|
||||
+4
-4
@@ -1,17 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Api
|
||||
class FlowsDocumentsController < ApiBaseController
|
||||
class TemplatesDocumentsController < ApiBaseController
|
||||
def create
|
||||
@flow = current_account.flows.find(params[:flow_id])
|
||||
@template = current_account.templates.find(params[:template_id])
|
||||
|
||||
documents =
|
||||
params[:blobs].map do |blob|
|
||||
blob = ActiveStorage::Blob.find_signed(blob[:signed_id])
|
||||
|
||||
document = @flow.documents.create!(blob:)
|
||||
document = @template.documents.create!(blob:)
|
||||
|
||||
Flows::ProcessDocument.call(document)
|
||||
Templates::ProcessDocument.call(document)
|
||||
end
|
||||
|
||||
schema = documents.map do |doc|
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
class DashboardController < ApplicationController
|
||||
def index
|
||||
@flows = current_account.flows.active
|
||||
@templates = current_account.templates.active
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class FlowsController < ApplicationController
|
||||
layout false
|
||||
|
||||
def show
|
||||
@flow = current_account.flows.preload(documents_attachments: { preview_images_attachments: :blob })
|
||||
.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@flow = current_account.flows.new
|
||||
end
|
||||
|
||||
def create
|
||||
@flow = current_account.flows.new(flow_params)
|
||||
@flow.author = current_user
|
||||
|
||||
if @flow.save
|
||||
redirect_to flow_path(@flow)
|
||||
else
|
||||
render turbo_stream: turbo_stream.replace(:modal, template: 'flows/new'), status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@flow = current_account.flows.find(params[:id])
|
||||
@flow.update!(deleted_at: Time.current)
|
||||
|
||||
redirect_to settings_users_path, notice: 'Flow has been archived.'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def flow_params
|
||||
params.require(:flow).permit(:name, :schema)
|
||||
end
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SendSubmissionEmailController < ApplicationController
|
||||
layout 'flow'
|
||||
layout 'form'
|
||||
|
||||
skip_before_action :authenticate_user!
|
||||
skip_before_action :verify_authenticity_token
|
||||
@@ -10,8 +10,8 @@ class SendSubmissionEmailController < ApplicationController
|
||||
|
||||
def create
|
||||
@submission =
|
||||
if params[:flow_slug]
|
||||
Submission.joins(:flow).find_by!(email: params[:email], flow: { slug: params[:flow_slug] })
|
||||
if params[:template_slug]
|
||||
Submission.joins(:template).find_by!(email: params[:email], template: { slug: params[:template_slug] })
|
||||
else
|
||||
Submission.find_by!(slug: params[:submission_slug])
|
||||
end
|
||||
|
||||
+11
-11
@@ -1,23 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class StartFlowController < ApplicationController
|
||||
layout 'flow'
|
||||
class StartFormController < ApplicationController
|
||||
layout 'form'
|
||||
|
||||
skip_before_action :authenticate_user!
|
||||
|
||||
before_action :load_flow
|
||||
before_action :load_template
|
||||
|
||||
def show
|
||||
@submission = @flow.submissions.new
|
||||
@submission = @template.submissions.new
|
||||
end
|
||||
|
||||
def update
|
||||
@submission = @flow.submissions.find_or_initialize_by(
|
||||
@submission = @template.submissions.find_or_initialize_by(
|
||||
deleted_at: nil, **submission_params
|
||||
)
|
||||
|
||||
if @submission.completed_at?
|
||||
redirect_to start_flow_completed_path(@flow.slug, email: submission_params[:email])
|
||||
redirect_to start_form_completed_path(@template.slug, email: submission_params[:email])
|
||||
else
|
||||
@submission.assign_attributes(
|
||||
opened_at: Time.current,
|
||||
@@ -26,7 +26,7 @@ class StartFlowController < ApplicationController
|
||||
)
|
||||
|
||||
if @submission.save
|
||||
redirect_to submit_flow_path(@submission.slug)
|
||||
redirect_to submit_form_path(@submission.slug)
|
||||
else
|
||||
render :show
|
||||
end
|
||||
@@ -34,7 +34,7 @@ class StartFlowController < ApplicationController
|
||||
end
|
||||
|
||||
def completed
|
||||
@submission = @flow.submissions.find_by(email: params[:email])
|
||||
@submission = @template.submissions.find_by(email: params[:email])
|
||||
end
|
||||
|
||||
private
|
||||
@@ -43,9 +43,9 @@ class StartFlowController < ApplicationController
|
||||
params.require(:submission).permit(:email)
|
||||
end
|
||||
|
||||
def load_flow
|
||||
slug = params[:slug] || params[:start_flow_slug]
|
||||
def load_template
|
||||
slug = params[:slug] || params[:start_template_slug]
|
||||
|
||||
@flow = Flow.find_by!(slug:)
|
||||
@template = Template.find_by!(slug:)
|
||||
end
|
||||
end
|
||||
@@ -1,16 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SubmissionsController < ApplicationController
|
||||
before_action :load_flow, only: %i[index new create]
|
||||
before_action :load_template, only: %i[index new create]
|
||||
|
||||
def index
|
||||
@submissions = @flow.submissions.active
|
||||
@submissions = @template.submissions.active
|
||||
end
|
||||
|
||||
def show
|
||||
@submission =
|
||||
Submission.joins(:flow).where(flow: { account_id: current_account.id })
|
||||
.preload(flow: { documents_attachments: { preview_images_attachments: :blob } })
|
||||
Submission.joins(:template).where(template: { account_id: current_account.id })
|
||||
.preload(template: { documents_attachments: { preview_images_attachments: :blob } })
|
||||
.find(params[:id])
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@ class SubmissionsController < ApplicationController
|
||||
|
||||
submissions =
|
||||
emails.map do |email|
|
||||
submission = @flow.submissions.create!(email:, sent_at: params[:send_email] == '1' ? Time.current : nil)
|
||||
submission = @template.submissions.create!(email:, sent_at: params[:send_email] == '1' ? Time.current : nil)
|
||||
|
||||
if params[:send_email] == '1'
|
||||
SubmissionMailer.invitation_email(submission, message: params[:message]).deliver_later!
|
||||
@@ -30,21 +30,21 @@ class SubmissionsController < ApplicationController
|
||||
submission
|
||||
end
|
||||
|
||||
redirect_to flow_submissions_path(@flow), notice: "#{submissions.size} recepients added"
|
||||
redirect_to template_submissions_path(@template), notice: "#{submissions.size} recepients added"
|
||||
end
|
||||
|
||||
def destroy
|
||||
submission = Submission.joins(:flow).where(flow: { account_id: current_account.id })
|
||||
submission = Submission.joins(:template).where(template: { account_id: current_account.id })
|
||||
.find(params[:id])
|
||||
|
||||
submission.update!(deleted_at: Time.current)
|
||||
|
||||
redirect_to flow_submissions_path(submission.flow), notice: 'Submission has been archieved'
|
||||
redirect_to template_submissions_path(submission.template), notice: 'Submission has been archieved'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_flow
|
||||
@flow = current_account.flows.find(params[:flow_id])
|
||||
def load_template
|
||||
@template = current_account.templates.find(params[:template_id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SubmissionsDebugController < ApplicationController
|
||||
layout 'flow'
|
||||
layout 'form'
|
||||
|
||||
skip_before_action :authenticate_user!
|
||||
|
||||
def index
|
||||
@submission = Submission.preload({ attachments_attachments: :blob },
|
||||
flow: { documents_attachments: :blob })
|
||||
template: { documents_attachments: :blob })
|
||||
.find_by(slug: params[:submission_slug])
|
||||
|
||||
respond_to do |f|
|
||||
f.html do
|
||||
render 'submit_flow/show'
|
||||
render 'submit_template/show'
|
||||
end
|
||||
f.pdf do
|
||||
Submissions::GenerateResultAttachments.call(@submission)
|
||||
|
||||
+5
-5
@@ -1,15 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SubmitFlowController < ApplicationController
|
||||
layout 'flow'
|
||||
class SubmitFormController < ApplicationController
|
||||
layout 'form'
|
||||
|
||||
skip_before_action :authenticate_user!
|
||||
|
||||
def show
|
||||
@submission = Submission.preload(flow: { documents_attachments: { preview_images_attachments: :blob } })
|
||||
@submission = Submission.preload(template: { documents_attachments: { preview_images_attachments: :blob } })
|
||||
.find_by!(slug: params[:slug])
|
||||
|
||||
return redirect_to submit_flow_completed_path(@submission.slug) if @submission.completed_at?
|
||||
return redirect_to submit_form_completed_path(@submission.slug) if @submission.completed_at?
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -23,7 +23,7 @@ class SubmitFlowController < ApplicationController
|
||||
end
|
||||
|
||||
def completed
|
||||
@submission = Submission.find_by!(slug: params[:submit_flow_slug])
|
||||
@submission = Submission.find_by!(slug: params[:submit_form_slug])
|
||||
end
|
||||
|
||||
private
|
||||
@@ -0,0 +1,38 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TemplatesController < ApplicationController
|
||||
layout false
|
||||
|
||||
def show
|
||||
@template = current_account.templates.preload(documents_attachments: { preview_images_attachments: :blob })
|
||||
.find(params[:id])
|
||||
end
|
||||
|
||||
def new
|
||||
@template = current_account.templates.new
|
||||
end
|
||||
|
||||
def create
|
||||
@template = current_account.templates.new(template_params)
|
||||
@template.author = current_user
|
||||
|
||||
if @template.save
|
||||
redirect_to template_path(@template)
|
||||
else
|
||||
render turbo_stream: turbo_stream.replace(:modal, template: 'templates/new'), status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@template = current_account.templates.find(params[:id])
|
||||
@template.update!(deleted_at: Time.current)
|
||||
|
||||
redirect_to settings_users_path, notice: 'template has been archived.'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def template_params
|
||||
params.require(:template).permit(:name, :schema)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user