From 400c25e15f86f3c2408886f4d048b79068785cd7 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 20 Nov 2018 12:18:18 +0000 Subject: [PATCH] Make search box appear based on all templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We reckon it’s jarring to have the search box appear and disappear as you navigate through the folders. Instead it should appear whenever your service has more things (templates or folders) than you can easily keep in your head (let’s go with 7 for now). This keeps the bahviour the same for current services that don’t have any folders. --- app/main/views/templates.py | 6 ++---- app/models/service.py | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 7e4164a9b..aa9ea60c9 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -121,8 +121,6 @@ def choose_template(service_id, template_type='all', template_folder_id=None): ) return redirect(request.url) - templates_on_page = current_service.get_templates(template_type, template_folder_id) - return render_template( 'views/templates/choose.html', current_template_folder_id=template_folder_id, @@ -130,8 +128,8 @@ def choose_template(service_id, template_type='all', template_folder_id=None): template_folder_path=current_service.get_template_folder_path(template_folder_id), template_folder_has_contents=current_service.get_template_folders_and_templates('all', template_folder_id), template_folders=current_service.get_template_folders(template_type, template_folder_id), - templates=templates_on_page, - show_search_box=(len(templates_on_page) > 7), + templates=current_service.get_templates(template_type, template_folder_id), + show_search_box=current_service.count_of_templates_and_folders > 7, show_template_nav=( current_service.has_multiple_template_types and (len(current_service.all_templates) > 2) diff --git a/app/models/service.py b/app/models/service.py index 7192b9e30..66d279430 100644 --- a/app/models/service.py +++ b/app/models/service.py @@ -367,6 +367,10 @@ class Service(): self.get_template_folders(template_type, template_folder_id) ) + @property + def count_of_templates_and_folders(self): + return len(self.get_template_folders_and_templates('all', None)) + def move_to_folder(self, ids_to_move, move_to): ids_to_move = set(ids_to_move)