Skip to content

Commit

Permalink
Feature/grid overview (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensWe authored Oct 29, 2024
2 parents 3c7f69e + b368631 commit 7375fcb
Show file tree
Hide file tree
Showing 19 changed files with 590 additions and 185 deletions.
20 changes: 20 additions & 0 deletions amt/api/group_by_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from collections.abc import Callable

from fastapi import Request

from ..schema.localized_value_item import LocalizedValueItem
from .localizable import LocalizableEnum, get_localized_enums


class GroupByCategories(LocalizableEnum):
LIFECYCLE = "levenscyclus"

@classmethod
def get_display_values(cls: type["GroupByCategories"], _: Callable[[str], str]) -> dict["GroupByCategories", str]:
return {
cls.LIFECYCLE: _("Lifecycle"),
}


def get_localized_group_by_categories(request: Request) -> list[LocalizedValueItem | None]:
return get_localized_enums(GroupByCategories, request)
36 changes: 31 additions & 5 deletions amt/api/routes/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

from amt.api.ai_act_profile import get_ai_act_profile_selector
from amt.api.deps import templates
from amt.api.group_by_category import get_localized_group_by_categories
from amt.api.lifecycles import Lifecycles, get_localized_lifecycle, get_localized_lifecycles
from amt.api.navigation import Navigation, resolve_base_navigation_items, resolve_navigation_items
from amt.api.publication_category import (
PublicationCategories,
get_localized_publication_categories,
get_localized_publication_category,
)
from amt.models import Project
from amt.schema.localized_value_item import LocalizedValueItem
from amt.schema.project import ProjectNew
from amt.services.instruments import InstrumentsService
Expand Down Expand Up @@ -44,6 +46,7 @@ async def get_root(
skip: int = Query(0, ge=0),
limit: int = Query(5000, ge=1), # todo: fix infinite scroll
search: str = Query(""),
display_type: str = Query(""),
) -> HTMLResponse:
active_filters = {
k.removeprefix("active-filter-"): v
Expand All @@ -62,11 +65,31 @@ async def get_root(
k.removeprefix("sort-by-"): v for k, v in request.query_params.items() if k.startswith("sort-by-") and v != ""
}

projects = await projects_service.paginate(skip=skip, limit=limit, search=search, filters=filters, sort=sort_by)
# todo: the lifecycle has to be 'localized', maybe for display 'Project' should become a different object
for project in projects:
project.lifecycle = get_localized_lifecycle(project.lifecycle, request) # pyright: ignore [reportAttributeAccessIssue]

amount_algorithm_systems: int = 0
if display_type == "LIFECYCLE":
projects: dict[str, list[Project]] = {}

# When the lifecycle filter is active, only show these algorithm systems
if "lifecycle" in filters:
for lifecycle in Lifecycles:
projects[lifecycle.name] = []
projects[filters["lifecycle"]] = await projects_service.paginate(
skip=skip, limit=limit, search=search, filters=filters, sort=sort_by
)
amount_algorithm_systems += len(projects[filters["lifecycle"]])
else:
for lifecycle in Lifecycles:
filters["lifecycle"] = lifecycle.name
projects[lifecycle.name] = await projects_service.paginate(
skip=skip, limit=limit, search=search, filters=filters, sort=sort_by
)
amount_algorithm_systems += len(projects[lifecycle.name])
else:
projects = await projects_service.paginate(skip=skip, limit=limit, search=search, filters=filters, sort=sort_by) # pyright: ignore [reportAssignmentType]
# todo: the lifecycle has to be 'localized', maybe for display 'Project' should become a different object
for project in projects:
project.lifecycle = get_localized_lifecycle(project.lifecycle, request) # pyright: ignore [reportAttributeAccessIssue, reportUnknownMemberType, reportUnknownArgumentType]
amount_algorithm_systems += len(projects)
next = skip + limit

sub_menu_items = resolve_navigation_items([Navigation.PROJECTS_OVERVIEW], request) # pyright: ignore [reportUnusedVariable] # noqa
Expand All @@ -76,14 +99,17 @@ async def get_root(
"breadcrumbs": breadcrumbs,
"sub_menu_items": {}, # sub_menu_items disabled for now
"projects": projects,
"amount_algorithm_systems": amount_algorithm_systems,
"next": next,
"limit": limit,
"start": skip,
"search": search,
"lifecycles": get_localized_lifecycles(request),
"publication_categories": get_localized_publication_categories(request),
"group_by_categories": get_localized_group_by_categories(request),
"filters": localized_filters,
"sort_by": sort_by,
"display_type": display_type,
}

if request.state.htmx and drop_filters:
Expand Down
95 changes: 70 additions & 25 deletions amt/locale/base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2024.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
Expand Down Expand Up @@ -41,6 +40,13 @@ msgstr ""
msgid "Role"
msgstr ""

#: amt/api/group_by_category.py:15
#: amt/site/templates/parts/filter_list.html.j2:94
#: amt/site/templates/projects/details_info.html.j2:24
#: amt/site/templates/projects/new.html.j2:38
msgid "Lifecycle"
msgstr ""

#: amt/api/lifecycles.py:23
msgid "Organizational Responsibilities"
msgstr ""
Expand Down Expand Up @@ -283,6 +289,18 @@ msgstr ""
msgid "Algorithmic Management Toolkit (AMT)"
msgstr ""

#: amt/site/templates/macros/algorithm_systems_grid.html.j2:36
msgid ""
"\n"
" Algorithm system\n"
" "
msgid_plural ""
"\n"
" Algorithm systems\n"
" "
msgstr[0] ""
msgstr[1] ""

#: amt/site/templates/macros/editable.html.j2:24
#: amt/site/templates/macros/editable.html.j2:27
#: amt/site/templates/projects/details_requirements.html.j2:55
Expand All @@ -299,6 +317,10 @@ msgstr ""
msgid "Cancel"
msgstr ""

#: amt/site/templates/macros/table_row.html.j2:15
msgid " ago"
msgstr ""

#: amt/site/templates/macros/tasks.html.j2:11
msgid "Todo"
msgstr ""
Expand Down Expand Up @@ -326,7 +348,8 @@ msgstr ""
#: amt/site/templates/pages/assessment_card.html.j2:7
#: amt/site/templates/pages/model_card.html.j2:6
#: amt/site/templates/pages/system_card.html.j2:4
#: amt/site/templates/parts/filter_list.html.j2:103
#: amt/site/templates/parts/filter_list.html.j2:98
#: amt/site/templates/parts/filter_list.html.j2:120
#: amt/site/templates/projects/details_info.html.j2:28
msgid "Last updated"
msgstr ""
Expand Down Expand Up @@ -402,37 +425,39 @@ msgstr ""
msgid "for more information on how the toolkit can support your organization."
msgstr ""

#: amt/site/templates/parts/filter_list.html.j2:12
msgid " ago"
msgstr ""

#: amt/site/templates/parts/filter_list.html.j2:44
msgid "result"
msgstr ""

#: amt/site/templates/parts/filter_list.html.j2:45
msgid "results"
msgstr ""

#: amt/site/templates/parts/filter_list.html.j2:47
#: amt/site/templates/parts/filter_list.html.j2:32
#, python-format
msgid ""
"\n"
" %(amount_algorithm_systems)s result\n"
" "
msgid_plural ""
"\n"
" %(amount_algorithm_systems)s results\n"
" "
msgstr[0] ""
msgstr[1] ""

#: amt/site/templates/parts/filter_list.html.j2:39
msgid "for"
msgstr ""

#: amt/site/templates/parts/filter_list.html.j2:77
#: amt/site/templates/parts/filter_list.html.j2:70
msgid ""
"No Algorithm system match your selected filters. Try adjusting your "
"filters or clearing them to see more\n"
" algorithm systems."
"filters or clearing them to\n"
" see more\n"
" algorithm systems."
msgstr ""

#: amt/site/templates/parts/filter_list.html.j2:95
#: amt/site/templates/parts/filter_list.html.j2:90
msgid "Algorithm system name"
msgstr ""

#: amt/site/templates/parts/filter_list.html.j2:99
#: amt/site/templates/projects/details_info.html.j2:24
#: amt/site/templates/projects/new.html.j2:38
msgid "Lifecycle"
#: amt/site/templates/parts/filter_list.html.j2:114
msgid ""
"Algorithm system\n"
" name"
msgstr ""

#: amt/site/templates/parts/header.html.j2:7
Expand All @@ -453,18 +478,38 @@ msgstr ""
msgid "New algorithm system"
msgstr ""

#: amt/site/templates/parts/project_search.html.j2:30
#: amt/site/templates/parts/project_search.html.j2:25
msgid "Search"
msgstr ""

#: amt/site/templates/parts/project_search.html.j2:32
msgid "Find algorithm system..."
msgstr ""

#: amt/site/templates/parts/project_search.html.j2:49
msgid "Phase"
msgstr ""

#: amt/site/templates/parts/project_search.html.j2:54
msgid "Select lifecycle"
msgstr ""

#: amt/site/templates/parts/project_search.html.j2:60
#: amt/site/templates/parts/project_search.html.j2:63
msgid "Category"
msgstr ""

#: amt/site/templates/parts/project_search.html.j2:68
msgid "Select publication category"
msgstr ""

#: amt/site/templates/parts/project_search.html.j2:86
msgid "Group by"
msgstr ""

#: amt/site/templates/parts/project_search.html.j2:96
msgid "Select group by"
msgstr ""

#: amt/site/templates/projects/details_base.html.j2:26
msgid "Does the algorithm meet the requirements?"
msgstr ""
Expand Down
Binary file modified amt/locale/en_US/LC_MESSAGES/messages.mo
Binary file not shown.
Loading

0 comments on commit 7375fcb

Please sign in to comment.