add archived template and submission pages

pull/112/head
Alex Turchyn 2 years ago
parent 3faec9d174
commit 7f6c0af0e8

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

@ -11,39 +11,22 @@
</div>
</div>
<div class="grid gap-4 md:grid-cols-3">
<% @templates.each do |template| %>
<div class="h-36 relative group">
<a href="<%= template_path(template) %>" class="flex h-full flex-col justify-between rounded-2xl pt-6 px-7 w-full bg-base-200 peer">
<div class="pb-4 text-xl font-semibold" style="overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;">
<%= template.name %>
</div>
<div class="pb-6 pt-1 space-y-1">
<p class="flex items-center space-x-1 text-xs text-base-content/60">
<%= svg_icon('user', class: 'w-4 h-4') %>
<span><%= template.author.full_name.presence || template.author.email %></span>
</p>
<p class="flex items-center space-x-1 text-xs text-base-content/60">
<%= svg_icon('calendar', class: 'w-4 h-4') %>
<span><%= l(template.created_at.in_time_zone(current_account.timezone), format: :short, locale: current_account.locale) %></span>
</p>
</div>
</a>
<div class="absolute top-0 bottom-0 w-0 pt-7 space-y-1.5 hidden md:group-hover:block" style="right: 40px">
<a href="<%= edit_template_path(template) %>" class="btn btn-xs hover:btn-outline bg-base-200 btn-circle">
<%= svg_icon('pencil', class: 'w-4 h-4') %>
</a>
<a href="<%= new_template_path(base_template_id: template.id) %>" data-turbo-frame="modal" class="btn btn-xs hover:btn-outline bg-base-200 btn-circle">
<%= svg_icon('copy', class: 'w-4 h-4') %>
</a>
<%= button_to template_path(template), data: { turbo_confirm: 'Are you sure?' }, method: :delete, class: 'btn btn-xs hover:btn-outline bg-base-200 btn-circle' do %>
<%= svg_icon('trash', class: 'w-4 h-4 enabled') %>
<%= svg_icon('loader', class: 'w-4 h-4 animate-spin disabled') %>
<% end %>
</div>
<%= render partial: 'templates/template', collection: @templates %>
</div>
<% view_archived_html = capture do %>
<% if current_account.templates.where.not(deleted_at: nil).exists? %>
<div>
<a href="<%= templates_archived_index_path %>" class="link text-sm">View Archived</a>
</div>
<% end %>
</div>
<%= render 'shared/pagination', pagy: @pagy, items_name: 'templates' %>
<% end %>
<% if @pagy.pages > 1 %>
<%= render 'shared/pagination', pagy: @pagy, items_name: 'templates', left_additional_html: view_archived_html %>
<% else %>
<div class="mt-2">
<%= view_archived_html %>
</div>
<% end %>
<% else %>
<div class="card bg-base-200 h-96 mb-2">
<div class="card-body text-center">

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" class="<%= local_assigns[:class] %>" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M19.95 11a8 8 0 1 0 -.5 4m.5 5v-5h-5"></path>
</svg>

After

Width:  |  Height:  |  Size: 345 B

@ -3,6 +3,7 @@
<div class="flex my-6 justify-center md:justify-between">
<div class="hidden md:block text-sm">
<%= @pagy.from %>-<%= @pagy.to %> of <%= @pagy.count %> <%= local_assigns[:items_name] || 'items' %>
<%= local_assigns[:left_additional_html] %>
</div>
<div class="join">
<% if @pagy.prev %>

@ -38,7 +38,9 @@
<%= render 'shared/clipboard_copy', text: submit_form_url(slug: submitter.slug), class: 'btn btn-sm btn-neutral text-white md:w-36 flex', icon_class: 'w-6 h-6 text-white', copy_title: 'Copy Link', copy_title_md: 'Copy', copied_title_md: 'Copied' %>
<% end %>
<span class="btn btn-outline btn-sm w-20 md:w-24">View</span>
<%= button_to button_title(title: nil, disabled_with: 'Remov', icon: svg_icon('trash', class: 'w-6 h-6')), submission_path(submission), class: 'btn btn-outline btn-sm', title: 'Delete', method: :delete, data: { turbo_confirm: 'Are you sure?' }, onclick: 'event.stopPropagation()' %>
<% unless submission.deleted_at? %>
<%= button_to button_title(title: nil, disabled_with: 'Remov', icon: svg_icon('trash', class: 'w-6 h-6')), submission_path(submission), class: 'btn btn-outline btn-sm', title: 'Delete', method: :delete, data: { turbo_confirm: 'Are you sure?' }, onclick: 'event.stopPropagation()' %>
<% end %>
</div>
<% else %>
<div class="space-y-1 w-full md:mr-2">
@ -110,7 +112,9 @@
</form>
<% end %>
<span class="btn btn-outline btn-sm w-20 md:w-24">View</span>
<%= button_to button_title(title: nil, disabled_with: 'Remov', icon: svg_icon('trash', class: 'w-6 h-6')), submission_path(submission), class: 'btn btn-outline btn-sm', title: 'Delete', method: :delete, data: { turbo_confirm: 'Are you sure?' }, onclick: 'event.stopPropagation()' %>
<% unless submission.deleted_at? %>
<%= button_to button_title(title: nil, disabled_with: 'Remov', icon: svg_icon('trash', class: 'w-6 h-6')), submission_path(submission), class: 'btn btn-outline btn-sm', title: 'Delete', method: :delete, data: { turbo_confirm: 'Are you sure?' }, onclick: 'event.stopPropagation()' %>
<% end %>
</div>
<% end %>
</a>

@ -0,0 +1,38 @@
<div class="h-36 relative group">
<a href="<%= template_path(template) %>" class="flex h-full flex-col justify-between rounded-2xl pt-6 px-7 w-full bg-base-200 peer">
<div class="pb-4 text-xl font-semibold" style="overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;">
<%= template.name %>
</div>
<div class="pb-6 pt-1 space-y-1">
<p class="flex items-center space-x-1 text-xs text-base-content/60">
<%= svg_icon('user', class: 'w-4 h-4') %>
<span><%= template.author.full_name.presence || template.author.email %></span>
</p>
<p class="flex items-center space-x-1 text-xs text-base-content/60">
<%= svg_icon('calendar', class: 'w-4 h-4') %>
<span><%= l(template.created_at.in_time_zone(current_account.timezone), format: :short, locale: current_account.locale) %></span>
</p>
</div>
</a>
<div class="absolute top-0 bottom-0 w-0 pt-7 space-y-1.5 hidden md:group-hover:block" style="right: 40px">
<% if template.deleted_at? %>
<%= button_to template_restore_index_path(template), class: 'btn btn-xs hover:btn-outline bg-base-200 btn-circle' do %>
<%= svg_icon('rotate', class: 'w-4 h-4 enabled') %>
<%= svg_icon('loader', class: 'w-4 h-4 animate-spin disabled') %>
<% end %>
<% else %>
<a href="<%= edit_template_path(template) %>" class="btn btn-xs hover:btn-outline bg-base-200 btn-circle">
<%= svg_icon('pencil', class: 'w-4 h-4') %>
</a>
<% end %>
<a href="<%= new_template_path(base_template_id: template.id) %>" data-turbo-frame="modal" class="btn btn-xs hover:btn-outline bg-base-200 btn-circle">
<%= svg_icon('copy', class: 'w-4 h-4') %>
</a>
<% unless template.deleted_at? %>
<%= button_to template_path(template), data: { turbo_confirm: 'Are you sure?' }, method: :delete, class: 'btn btn-xs hover:btn-outline bg-base-200 btn-circle', aria_label: 'Restore' do %>
<%= svg_icon('trash', class: 'w-4 h-4 enabled') %>
<%= svg_icon('loader', class: 'w-4 h-4 animate-spin disabled') %>
<% end %>
<% end %>
</div>
</div>

@ -0,0 +1,28 @@
<div class="flex flex-col items-start md:flex-row space-y-2 md:space-y-0 md:justify-between md:items-center mb-8">
<h1 class="text-4xl font-semibold mr-4" style="overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;">
<%= template.name %>
<% if template.deleted_at? %>
<span class="badge badge-outline badge-lg align-middle">Archived</span>
<% end %>
</h1>
<div class="flex md:justify-between space-x-2 flex-none">
<% unless template.deleted_at? %>
<%= button_to button_title(title: 'Remove', disabled_with: 'Removing', icon: svg_icon('trash', class: 'w-6 h-6')), template_path(template), class: 'btn btn-outline btn-sm', method: :delete, data: { turbo_confirm: 'Are you sure?' } %>
<% end %>
<%= link_to new_template_path(base_template_id: template.id), class: 'btn btn-outline btn-sm', data: { turbo_frame: :modal } do %>
<%= svg_icon('copy', class: 'w-6 h-6') %>
<span>Clone</span>
<% end %>
<% unless template.deleted_at? %>
<%= link_to edit_template_path(template), class: 'btn btn-outline btn-sm' do %>
<span class="flex items-center justify-center space-x-2">
<%= svg_icon('pencil', class: 'w-6 h-6') %>
<span>Edit</span>
</span>
<% end %>
<% end %>
<% if template.deleted_at? %>
<%= button_to button_title(title: 'Restore', disabled_with: 'Restoring', icon: svg_icon('rotate', class: 'w-6 h-6')), template_restore_index_path(template), class: 'btn btn-outline btn-sm' %>
<% end %>
</div>
</div>

@ -1,21 +1,4 @@
<div class="flex flex-col items-start md:flex-row space-y-2 md:space-y-0 md:justify-between md:items-center mb-8">
<h1 class="text-4xl font-semibold mr-4" style="overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;">
<%= @template.name %>
</h1>
<div class="flex md:justify-between space-x-2 flex-none">
<%= button_to button_title(title: 'Remove', disabled_with: 'Removing', icon: svg_icon('trash', class: 'w-6 h-6')), template_path(@template), class: 'btn btn-outline btn-sm', method: :delete, data: { turbo_confirm: 'Are you sure?' } %>
<%= link_to new_template_path(base_template_id: @template.id), class: 'btn btn-outline btn-sm', data: { turbo_frame: :modal } do %>
<%= svg_icon('copy', class: 'w-6 h-6') %>
<span>Clone</span>
<% end %>
<%= link_to edit_template_path(@template), class: 'btn btn-outline btn-sm' do %>
<span class="flex items-center justify-center space-x-2">
<%= svg_icon('pencil', class: 'w-6 h-6') %>
<span>Edit</span>
</span>
<% end %>
</div>
</div>
<%= render 'title', template: @template %>
<% if !@pagy.count.zero? || @template.submitters.to_a.size == 1 %>
<div class="flex justify-between mb-6 md:items-end flex-col md:flex-row">
<p class="text-3xl font-bold">Submissions</p>
@ -24,12 +7,12 @@
<%= svg_icon('download', class: 'w-6 h-6 stroke-2') %>
<span>Export</span>
<% end %>
<% if @template.submitters.to_a.size == 1 %>
<% if @template.submitters.to_a.size == 1 && !@template.deleted_at? %>
<span class="order-1">
<%= render 'shared/clipboard_copy', text: start_form_url(slug: @template.slug), class: 'base-button', icon_class: 'w-6 h-6 text-white', copy_title: 'Copy Share Link', copied_title: 'Copied to Clipboard', copy_title_md: 'Copy', copied_title_md: 'Copied' %>
</span>
<% end %>
<% unless @pagy.count.zero? %>
<% if !@pagy.count.zero? && !@template.deleted_at? %>
<%= link_to new_template_submission_path(@template), class: 'order-1 btn btn-primary text-base', data: { turbo_frame: 'modal' } do %>
<%= svg_icon('plus', class: 'w-6 h-6 stroke-2') %>
<span>Add <span class="hidden md:inline">Recipients</span></span>
@ -42,21 +25,36 @@
<div class="space-y-4">
<%= render partial: 'submission', collection: @submissions %>
</div>
<%= render 'shared/pagination', pagy: @pagy, items_name: 'submissions' %>
<% view_archived_html = capture do %>
<% if @template.submissions.where.not(deleted_at: nil).exists? && !@template.deleted_at? %>
<div>
<a href="<%= template_archived_path(@template) %>" class="link text-sm">View Archived</a>
</div>
<% end %>
<% end %>
<% if @pagy.pages > 1 %>
<%= render 'shared/pagination', pagy: @pagy, items_name: 'submissions', left_additional_html: view_archived_html %>
<% else %>
<div class="mt-2">
<%= view_archived_html %>
</div>
<% end %>
<% else %>
<div class="card bg-base-200">
<div class="card-body text-center py-16">
<div class="max-w-lg mx-auto">
<p class="text-3xl font-bold text-base-content mb-4">There are no Submissions</p>
<p class="text-gray-600">Send an invitation to fill and complete the form</p>
<div class="space-x-2">
<%= link_to new_template_submission_path(@template), class: 'base-button mt-6', data: { turbo_frame: 'modal' } do %>
<%= svg_icon('plus', class: 'w-6 h-6 stroke-2') %>
<span class="mr-1">Add Recipients</span>
<% end %>
<%= link_to start_form_url(slug: @template.slug), class: 'white-button mt-6', target: '_blank', rel: 'noopener' do %>
<%= svg_icon('writing', class: 'w-6 h-6') %>
<span class="mr-1">Submit it Yourself</span>
<% if @template.deleted_at.blank? %>
<p class="text-gray-600">Send an invitation to fill and complete the form</p>
<div class="space-x-2">
<%= link_to new_template_submission_path(@template), class: 'base-button mt-6', data: { turbo_frame: 'modal' } do %>
<%= svg_icon('plus', class: 'w-6 h-6 stroke-2') %>
<span class="mr-1">Add Recipients</span>
<% end %>
<%= link_to start_form_url(slug: @template.slug), class: 'white-button mt-6', target: '_blank', rel: 'noopener' do %>
<%= svg_icon('writing', class: 'w-6 h-6') %>
<span class="mr-1">Submit it Yourself</span>
<% end %>
<% end %>
</div>
</div>

@ -0,0 +1,13 @@
<div>
<%= link_to root_path(@template) do %>
&larr;
<span>Back to Active</span>
<% end %>
</div>
<div class="flex justify-between mb-4 items-center">
<h1 class="text-4xl font-bold"><span class="hidden md:inline">Document</span> Templates <span class="badge badge-outline badge-lg align-middle">Archived</span></h1>
</div>
<div class="grid gap-4 md:grid-cols-3">
<%= render partial: 'templates/template', collection: @templates %>
</div>
<%= render 'shared/pagination', pagy: @pagy, items_name: 'templates' %>

@ -0,0 +1,20 @@
<%= render 'templates/title', template: @template %>
<div>
<%= link_to template_path(@template) do %>
&larr;
<span>Back to Active</span>
<% end %>
</div>
<div class="flex justify-between mb-6 md:items-end flex-col md:flex-row">
<p class="text-3xl font-bold">Submissions <span class="badge badge-outline badge-lg align-middle">Archived</span></p>
<div class="flex space-x-2 mt-3 md:mt-0">
<%= link_to new_template_submissions_export_path(@template), class: 'order-3 md:order-1 btn btn-ghost text-base', data: { turbo_frame: 'modal' } do %>
<%= svg_icon('download', class: 'w-6 h-6 stroke-2') %>
<span>Export</span>
<% end %>
</div>
</div>
<div class="space-y-4">
<%= render partial: 'templates/submission', collection: @submissions %>
</div>
<%= render 'shared/pagination', pagy: @pagy, items_name: 'submissions' %>

@ -48,7 +48,10 @@ Rails.application.routes.draw do
resources :submissions, only: %i[show destroy]
resources :console_redirect, only: %i[index]
resource :templates_upload, only: %i[create]
resources :templates_archived, only: %i[index], path: 'archived'
resources :templates, only: %i[new create edit show destroy] do
resources :restore, only: %i[create], controller: 'templates_restore'
resource :archived, only: %i[show], controller: 'templates_archived_submissions'
resources :submissions, only: %i[new create]
resources :submissions_export, only: %i[index new]
end

@ -51,7 +51,6 @@ RSpec.describe 'Template' do
end.to change { Template.active.count }.by(-1)
expect(page).to have_content('Template has been archived')
expect(page).to have_current_path(root_path, ignore_query: true)
end
it 'edits a template' do

Loading…
Cancel
Save