diff --git a/app/controllers/template_folders_controller.rb b/app/controllers/template_folders_controller.rb
index 05b19814..e5cb2bbf 100644
--- a/app/controllers/template_folders_controller.rb
+++ b/app/controllers/template_folders_controller.rb
@@ -7,7 +7,7 @@ class TemplateFoldersController < ApplicationController
@templates = @template_folder.templates.active.accessible_by(current_ability)
.preload(:author, :template_accesses)
@templates = Templates.search(@templates, params[:q])
- @templates = Templates::Order.call(@templates, cookies.permanent[:dashboard_templates_order])
+ @templates = Templates::Order.call(@templates, current_user, cookies.permanent[:dashboard_templates_order])
@pagy, @templates = pagy(@templates, limit: 12)
end
diff --git a/app/controllers/templates_dashboard_controller.rb b/app/controllers/templates_dashboard_controller.rb
index f6964432..0bd9a2be 100644
--- a/app/controllers/templates_dashboard_controller.rb
+++ b/app/controllers/templates_dashboard_controller.rb
@@ -12,7 +12,8 @@ class TemplatesDashboardController < ApplicationController
@template_folders = @template_folders.where(id: @templates.active.select(:folder_id))
@template_folders = TemplateFolders.search(@template_folders, params[:q])
- @template_folders = sort_template_folders(@template_folders, cookies.permanent[:dashboard_templates_order])
+ @template_folders = sort_template_folders(@template_folders, current_user,
+ cookies.permanent[:dashboard_templates_order])
@pagy, @template_folders = pagy(
@template_folders,
@@ -25,7 +26,7 @@ class TemplatesDashboardController < ApplicationController
else
@template_folders = @template_folders.reject { |e| e.name == TemplateFolder::DEFAULT_NAME }
@templates = filter_templates(@templates)
- @templates = Templates::Order.call(@templates, cookies.permanent[:dashboard_templates_order])
+ @templates = Templates::Order.call(@templates, current_user, cookies.permanent[:dashboard_templates_order])
limit =
if @template_folders.size < 4
@@ -57,12 +58,13 @@ class TemplatesDashboardController < ApplicationController
Templates.search(rel, params[:q])
end
- def sort_template_folders(template_folders, order)
+ def sort_template_folders(template_folders, current_user, order)
case order
when 'used_at'
subquery =
Template.left_joins(:submissions)
.group(:folder_id)
+ .where(account_id: current_user.account_id)
.select(
:folder_id,
Template.arel_table[:updated_at].maximum.as('updated_at_max'),
diff --git a/app/views/shared/_templates_order_select.html.erb b/app/views/shared/_templates_order_select.html.erb
index 520ecae1..90a80a8e 100644
--- a/app/views/shared/_templates_order_select.html.erb
+++ b/app/views/shared/_templates_order_select.html.erb
@@ -12,14 +12,16 @@
-
-
-
-
-
+ <% if local_assigns[:with_recently_used] != false %>
+
+
+
+
+
+ <% end %>