mirror of
https://github.com/docusealco/docuseal.git
synced 2026-08-07 07:14:43 +00:00
show archived shared templates
This commit is contained in:
@@ -48,7 +48,7 @@ module Api
|
||||
|
||||
archived = params.key?(:archived) ? params[:archived] : params.dig(:template, :archived)
|
||||
|
||||
if archived.in?([true, false])
|
||||
if archived.in?([true, false]) && current_ability.can?(:destroy, @template)
|
||||
@template.archived_at = archived == true ? Time.current : nil
|
||||
end
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ class TemplatesRestoreController < ApplicationController
|
||||
load_and_authorize_resource :template
|
||||
|
||||
def create
|
||||
authorize!(:update, @template)
|
||||
authorize!(:destroy, @template)
|
||||
|
||||
@template.update!(archived_at: nil)
|
||||
|
||||
|
||||
@@ -4,10 +4,16 @@ class TemplatesSharedController < ApplicationController
|
||||
def index
|
||||
authorize!(:read, Template)
|
||||
|
||||
@is_archived = params[:archived] == 'true'
|
||||
|
||||
@templates = Templates.shared(current_user)
|
||||
.active
|
||||
.preload(:author, :template_accesses, :template_sharings)
|
||||
.order(id: :desc)
|
||||
|
||||
@has_archived = !@is_archived && @templates.archived.exists?
|
||||
|
||||
@templates = @is_archived ? @templates.archived : @templates.active
|
||||
|
||||
@templates = @templates.preload(:author, :template_accesses, :template_sharings)
|
||||
.order(id: :desc)
|
||||
|
||||
@templates = Templates.search(current_user, @templates, params[:q])
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
<input name="<%= key %>" value="<%= params[key] %>" class="hidden">
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if params[:archived].present? %>
|
||||
<input name="archived" value="<%= params[:archived] %>" class="hidden">
|
||||
<% end %>
|
||||
<% if params[:q].present? %>
|
||||
<div class="relative">
|
||||
<a href="<%= url_for(params: request.query_parameters.except('q')) %>" title="<%= t('clear') %>" class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-auto text-neutral text-2xl font-extralight">
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<%= 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>
|
||||
</span>
|
||||
<% if template.archived_at? %>
|
||||
<% if local_assigns[:with_folder] %>
|
||||
<span class="flex items-center space-x-1 w-1/2">
|
||||
<%= svg_icon('folder', class: 'w-4 h-4 flex-shrink-0') %>
|
||||
<span class="truncate"><%= template.folder.full_name %></span>
|
||||
@@ -37,14 +37,14 @@
|
||||
</a>
|
||||
</span>
|
||||
<% end %>
|
||||
<% if template.archived_at? && can?(:update, template) %>
|
||||
<% if template.archived_at? && can?(:destroy, template) %>
|
||||
<span class="tooltip tooltip-left" data-tip="<%= t('restore') %>">
|
||||
<%= 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 %>
|
||||
</span>
|
||||
<% elsif can?(:update, template) %>
|
||||
<% elsif !template.archived_at? && can?(:update, template) %>
|
||||
<span class="tooltip tooltip-left" data-tip="<%= t('edit') %>">
|
||||
<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') %>
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if template.archived_at? %>
|
||||
<% if can?(:create, template) %>
|
||||
<% if can?(:destroy, template) %>
|
||||
<%= button_to button_title(title: t('restore'), disabled_with: t('restoring')[..-4], icon: svg_icon('rotate', class: 'w-6 h-6')), template_restore_index_path(template), class: 'btn btn-outline btn-sm flex-1' %>
|
||||
<% end %>
|
||||
<%= link_to template_preview_path(template), class: 'btn btn-outline btn-sm flex-1' do %>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
</div>
|
||||
<% if @pagy.count.nil? || @pagy.count > 0 %>
|
||||
<div class="grid gap-4 md:grid-cols-3">
|
||||
<%= render partial: 'templates/template', collection: @templates %>
|
||||
<%= render partial: 'templates/template', collection: @templates, locals: { with_folder: true } %>
|
||||
</div>
|
||||
<% elsif params[:q].present? %>
|
||||
<div class="text-center">
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
<div>
|
||||
<%= link_to root_path, class: 'flex items-center' do %>
|
||||
<%= link_to(@is_archived ? templates_shared_index_path : root_path, class: 'flex items-center') do %>
|
||||
<%= svg_icon('chevron_left', class: 'w-5 h-5') %>
|
||||
<span style="margin-left: 3px"><%= t('home') %></span>
|
||||
<span style="margin-left: 3px"><%= @is_archived ? t('back_to_active') : t('home') %></span>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="relative flex justify-between items-center w-full mb-4">
|
||||
<h1 class="text-2xl truncate md:text-3xl font-bold flex items-center flex-grow min-w-0 space-x-2 md:flex <%= 'hidden' if params[:q].present? %>">
|
||||
<%= svg_icon('folder', class: 'w-9 h-9 flex-shrink-0') %>
|
||||
<span class="truncate capitalize"><%= t('shared') %></span>
|
||||
<% if @is_archived %>
|
||||
<span class="badge badge-outline badge-lg align-middle"><%= t('archived') %></span>
|
||||
<% end %>
|
||||
</h1>
|
||||
<div class="flex space-x-2">
|
||||
<% if params[:q].present? || @pagy.pages > 1 %>
|
||||
@@ -15,6 +18,13 @@
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% view_archived_html = capture do %>
|
||||
<% if @has_archived %>
|
||||
<div>
|
||||
<a href="<%= templates_shared_index_path(archived: true) %>" class="link text-sm"><%= t('view_archived') %></a>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if @pagy.count.nil? || @pagy.count > 0 %>
|
||||
<div class="grid gap-4 md:grid-cols-3">
|
||||
<%= render partial: 'templates/template', collection: @templates %>
|
||||
@@ -26,4 +36,10 @@
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= render 'shared/pagination', pagy: @pagy, items_name: 'templates' %>
|
||||
<% 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 %>
|
||||
|
||||
Reference in New Issue
Block a user