From 9c9c1ad6f0d0ea28cdca3823c9744e4e266fbfa7 Mon Sep 17 00:00:00 2001 From: Alex Turchyn Date: Wed, 28 Jun 2023 00:22:34 +0300 Subject: [PATCH] adjust dashboard templates style --- app/controllers/dashboard_controller.rb | 4 +- app/controllers/submissions_controller.rb | 10 +- app/controllers/templates_controller.rb | 27 ++--- app/javascript/template_builder/builder.vue | 2 +- app/views/dashboard/index.html.erb | 36 ++++--- app/views/layouts/application.html.erb | 2 +- app/views/shared/_navbar.html.erb | 2 +- app/views/shared/_pagination.html.erb | 15 +-- app/views/submissions/index.html.erb | 103 ------------------- app/views/templates/edit.html.erb | 1 + app/views/templates/new.html.erb | 4 +- app/views/templates/show.html.erb | 104 +++++++++++++++++++- app/views/users/index.html.erb | 2 +- config/routes.rb | 4 +- 14 files changed, 166 insertions(+), 150 deletions(-) delete mode 100644 app/views/submissions/index.html.erb create mode 100644 app/views/templates/edit.html.erb diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 04bdda1e..95afc887 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -6,6 +6,8 @@ class DashboardController < ApplicationController def index return render 'pages/landing' unless signed_in? - @pagy, @templates = pagy(current_account.templates.active, items: 12) + templates = current_account.templates.active.preload(:author).order(id: :desc) + + @pagy, @templates = pagy(templates, items: 12) end end diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 6722b1e2..a337b3de 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -1,11 +1,7 @@ # frozen_string_literal: true class SubmissionsController < ApplicationController - before_action :load_template, only: %i[index new create] - - def index - @pagy, @submissions = pagy(@template.submissions.active) - end + before_action :load_template, only: %i[new create] def show @submission = @@ -32,7 +28,7 @@ class SubmissionsController < ApplicationController end end - redirect_to template_submissions_path(@template), + redirect_to template_path(@template), notice: "#{submissions.size} #{'recipient'.pluralize(submissions.size)} added" end @@ -42,7 +38,7 @@ class SubmissionsController < ApplicationController submission.update!(deleted_at: Time.current) - redirect_to template_submissions_path(submission.template), notice: 'Submission has been archived' + redirect_back(fallback_location: template_path(submission.template), notice: 'Submission has been archived') end private diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 31e1b410..f8735827 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -1,13 +1,12 @@ # frozen_string_literal: true class TemplatesController < ApplicationController - layout 'plain' - before_action :load_base_template, only: %i[new create] def show - @template = current_account.templates.preload(documents_attachments: { preview_images_attachments: :blob }) - .find(params[:id]) + @template = current_account.templates.find(params[:id]) + + @pagy, @submissions = pagy(@template.submissions.active) end def new @@ -15,20 +14,22 @@ class TemplatesController < ApplicationController @template.name = "#{@base_template.name} (Clone)" if @base_template end - def create - @template = - if @base_template - current_account.templates.new(**@base_template.slice(:fields, :schema, :submitters), **template_params) - else - current_account.templates.new(template_params) - end + def edit + @template = current_account.templates.preload(documents_attachments: { preview_images_attachments: :blob }) + .find(params[:id]) + render :edit, layout: 'plain' + end + + def create + @template = current_account.templates.new(template_params) @template.author = current_user + @template.assign_attributes(@base_template.slice(:fields, :schema, :submitters)) if @base_template if @template.save Templates::CloneAttachments.call(template: @template, original_template: @base_template) if @base_template - redirect_to template_path(@template) + redirect_to edit_template_path(@template) else render turbo_stream: turbo_stream.replace(:modal, template: 'templates/new'), status: :unprocessable_entity end @@ -38,7 +39,7 @@ class TemplatesController < ApplicationController @template = current_account.templates.find(params[:id]) @template.update!(deleted_at: Time.current) - redirect_to settings_users_path, notice: 'template has been archived.' + redirect_back(fallback_location: root_path, notice: 'Template has been archived.') end private diff --git a/app/javascript/template_builder/builder.vue b/app/javascript/template_builder/builder.vue index 98605952..51bf35b3 100644 --- a/app/javascript/template_builder/builder.vue +++ b/app/javascript/template_builder/builder.vue @@ -405,7 +405,7 @@ export default { this.isSaving = true this.save().then(() => { - window.Turbo.visit(`/templates/${this.template.id}/submissions`) + window.Turbo.visit(`/templates/${this.template.id}`) }).finally(() => { this.isSaving = false }) diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index c8f45b40..a3a80b60 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -1,4 +1,4 @@ -<%- if @templates.any? %> +<% if @templates.any? %>

Templates

<%= link_to new_template_path, class: 'btn btn-primary btn-md gap-2', data: { turbo_frame: :modal } do %> @@ -8,24 +8,38 @@
<% @templates.each do |template| %> -
-
-

- <%= link_to template.name, template_submissions_path(template) %> - <%= link_to 'Edit', template_path(template), class: 'btn btn-outline btn-xs' %> -

-
-

Created by <%= template.author.full_name %>

-

+

+ +
+ <%= template.name %> +
+
+

+ <%= svg_icon('user', class: 'w-4 h-4') %> + <%= template.author.full_name %> +

+

<%= svg_icon('calendar', class: 'w-4 h-4') %> <%= l(template.created_at, format: :long) %>

+
+
<% end %>
- <%= render 'shared/pagination', pagy: @pagy %> + <%= render 'shared/pagination', pagy: @pagy, items_name: 'Templates' %> <% else %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e0ac91ec..08250e79 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -15,7 +15,7 @@ <%= render 'shared/navbar' %> <% if flash.present? %><%= render 'shared/flash' %><% end %> -
+
<%= yield %>
diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb index 6760a156..df6fd25c 100644 --- a/app/views/shared/_navbar.html.erb +++ b/app/views/shared/_navbar.html.erb @@ -5,7 +5,7 @@ <% if signed_in? %>
- <%= link_to 'Settings', settings_storage_index_path, class: 'font-medium text-lg' %> + <%= link_to 'Settings', settings_profile_index_path, class: 'font-medium text-lg' %>
- <%= f.button button_title(title: 'Create', disabled_with: 'Creating'), class: 'base-button' %> + <%= f.button button_title(title: @base_template ? 'Submit' : 'Create', disabled_with: 'Creating'), class: 'base-button' %>
<% end %> <% end %> diff --git a/app/views/templates/show.html.erb b/app/views/templates/show.html.erb index f1b8892c..4a9973da 100644 --- a/app/views/templates/show.html.erb +++ b/app/views/templates/show.html.erb @@ -1 +1,103 @@ - +
+
+
+

+ <%= @template.name %> +

+
+ <%= 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') %> + Clone + <% end %> + <%= link_to edit_template_path(@template), class: 'btn btn-outline btn-sm' do %> + + <%= svg_icon('pencil', class: 'w-6 h-6') %> + Edit + + <% end %> +
+
+ <% if @template.submitters.size == 1 %> +
+ + Share link + + + + <%= svg_icon('clipboard', class: 'w-6 h-6 swap-on text-white') %> + <%= svg_icon('clipboard_copy', class: 'w-6 h-6 swap-off text-white') %> + +
+ <% end %> +
+
+
+

Recipients

+ <%= link_to new_template_submission_path(@template), class: 'btn btn-primary btn-sm gap-2', data: { turbo_frame: 'modal' } do %> + <%= svg_icon('plus', class: 'w-6 h-6') %> + + <% end %> +
+
+ <%- if @submissions.any? %> + + + + + + + + + + + <% @submissions.each do |submission| %> + + + + + + + <% end %> + +
+ Email + + Status + + Share Link + +
+ <% submission.submitters.each do |submitter| %> + <%= submitter.email %> +
+ <% end %> +
+ <% submission.submitters.each do |submitter| %> +
+ + <%= submitter.status %> + +
+ <% end %> +
+ <% submission.submitters.each do |submitter| %> + <% share_link_input_id = "share-link-input_#{submitter.id}" %> +
+ + + <%= svg_icon('clipboard', class: 'w-3 h-3 swap-on text-white') %> + <%= svg_icon('clipboard_copy', class: 'w-3 h-3 swap-off text-white') %> + +
+
+ <% end %> +
+ <%= link_to 'View', submission_path(submission), title: 'View', class: 'btn btn-outline btn-xs' %> + <%= button_to 'Remove', submission_path(submission), class: 'btn btn-outline btn-error btn-xs', title: 'Delete', method: :delete, data: { turbo_confirm: 'Are you sure?' } %> +
+
+ <%= render 'shared/pagination', pagy: @pagy, items_name: 'Submissions' %> +<% else %> + <%= render 'shared/no_data_banner' %> +<% end %> +
diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index c1307039..edd35d06 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -58,6 +58,6 @@
- <%= render 'shared/pagination', pagy: @pagy %> + <%= render 'shared/pagination', pagy: @pagy, items_name: 'Users' %>
diff --git a/config/routes.rb b/config/routes.rb index 8b8c1753..616235bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,8 +30,8 @@ Rails.application.routes.draw do resources :setup, only: %i[index create] resources :users, only: %i[new create edit update destroy] resources :submissions, only: %i[show destroy] - resources :templates, only: %i[new create show destroy] do - resources :submissions, only: %i[index new create] + resources :templates, only: %i[new create edit show destroy] do + resources :submissions, only: %i[new create] end resources :start_form, only: %i[show update], path: 'd', param: 'slug' do