mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
Link template folders to their contents
Clicking on template folder navigates to a page that displays that folder's contents. This reuses the existing choose template view by adding a filter based on optional `template_folder_id` argument. Service model methods are rewritten to match `all_templates` and `get_template`. New `get_template_folder_path` method returns a list of folders (from root to the current one) that the selected folder is nested inside.
This commit is contained in:
@@ -259,5 +259,26 @@ class Service():
|
||||
return bool(self.inbound_number)
|
||||
|
||||
@cached_property
|
||||
def template_folders(self):
|
||||
def all_template_folders(self):
|
||||
return template_folder_api_client.get_template_folders(self.id)
|
||||
|
||||
def get_template_folders(self, parent_folder_id=None):
|
||||
return [
|
||||
folder for folder in self.all_template_folders
|
||||
if folder['parent_id'] == parent_folder_id
|
||||
]
|
||||
|
||||
def get_template_folder_path(self, template_folder_id):
|
||||
if template_folder_id is None:
|
||||
return []
|
||||
|
||||
id_to_folder = {folder['id']: folder for folder in self.all_template_folders}
|
||||
|
||||
folder = id_to_folder[template_folder_id]
|
||||
path = [folder]
|
||||
|
||||
while folder['parent_id']:
|
||||
folder = id_to_folder[folder['parent_id']]
|
||||
path.append(folder)
|
||||
|
||||
return list(reversed(path))
|
||||
|
||||
Reference in New Issue
Block a user