mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
added pinned projects to project item
This commit is contained in:
parent
8196ee2b07
commit
7ce23aff07
1 changed files with 32 additions and 18 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
|
from __future__ import annotations
|
||||||
import contextlib
|
import contextlib
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import Dict, Any
|
from typing import Dict, Any
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
import ayon_api
|
import ayon_api
|
||||||
|
|
||||||
|
|
@ -140,6 +142,7 @@ class TaskTypeItem:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class ProjectItem:
|
class ProjectItem:
|
||||||
"""Item representing folder entity on a server.
|
"""Item representing folder entity on a server.
|
||||||
|
|
||||||
|
|
@ -150,21 +153,14 @@ class ProjectItem:
|
||||||
active (Union[str, None]): Parent folder id. If 'None' then project
|
active (Union[str, None]): Parent folder id. If 'None' then project
|
||||||
is parent.
|
is parent.
|
||||||
"""
|
"""
|
||||||
|
name: str
|
||||||
def __init__(self, name, active, is_library, icon=None):
|
active: bool
|
||||||
self.name = name
|
is_library: bool
|
||||||
self.active = active
|
icon: dict[str, Any]
|
||||||
self.is_library = is_library
|
is_pinned: bool = False
|
||||||
if icon is None:
|
|
||||||
icon = {
|
|
||||||
"type": "awesome-font",
|
|
||||||
"name": "fa.book" if is_library else "fa.map",
|
|
||||||
"color": get_default_entity_icon_color(),
|
|
||||||
}
|
|
||||||
self.icon = icon
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_entity(cls, project_entity):
|
def from_entity(cls, project_entity: dict[str, Any]) -> "ProjectItem":
|
||||||
"""Creates folder item from entity.
|
"""Creates folder item from entity.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|
@ -174,10 +170,16 @@ class ProjectItem:
|
||||||
ProjectItem: Project item.
|
ProjectItem: Project item.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
icon = {
|
||||||
|
"type": "awesome-font",
|
||||||
|
"name": "fa.book" if project_entity["library"] else "fa.map",
|
||||||
|
"color": get_default_entity_icon_color(),
|
||||||
|
}
|
||||||
return cls(
|
return cls(
|
||||||
project_entity["name"],
|
project_entity["name"],
|
||||||
project_entity["active"],
|
project_entity["active"],
|
||||||
project_entity["library"],
|
project_entity["library"],
|
||||||
|
icon
|
||||||
)
|
)
|
||||||
|
|
||||||
def to_data(self):
|
def to_data(self):
|
||||||
|
|
@ -208,16 +210,18 @@ class ProjectItem:
|
||||||
return cls(**data)
|
return cls(**data)
|
||||||
|
|
||||||
|
|
||||||
def _get_project_items_from_entitiy(projects):
|
def _get_project_items_from_entitiy(
|
||||||
|
projects: list[dict[str, Any]]
|
||||||
|
) -> list[ProjectItem]:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
projects (list[dict[str, Any]]): List of projects.
|
projects (list[dict[str, Any]]): List of projects.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
ProjectItem: Project item.
|
list[ProjectItem]: Project item.
|
||||||
"""
|
|
||||||
|
|
||||||
|
"""
|
||||||
return [
|
return [
|
||||||
ProjectItem.from_entity(project)
|
ProjectItem.from_entity(project)
|
||||||
for project in projects
|
for project in projects
|
||||||
|
|
@ -428,9 +432,19 @@ class ProjectsModel(object):
|
||||||
self._projects_cache.update_data(project_items)
|
self._projects_cache.update_data(project_items)
|
||||||
return self._projects_cache.get_data()
|
return self._projects_cache.get_data()
|
||||||
|
|
||||||
def _query_projects(self):
|
def _query_projects(self) -> list[ProjectItem]:
|
||||||
projects = ayon_api.get_projects(fields=["name", "active", "library"])
|
projects = ayon_api.get_projects(fields=["name", "active", "library"])
|
||||||
return _get_project_items_from_entitiy(projects)
|
user = ayon_api.get_user()
|
||||||
|
pinned_projects = (
|
||||||
|
user
|
||||||
|
.get("data", {})
|
||||||
|
.get("frontendPreferences", {})
|
||||||
|
.get("pinnedProjects")
|
||||||
|
) or []
|
||||||
|
project_items = _get_project_items_from_entitiy(list(projects))
|
||||||
|
for project in project_items:
|
||||||
|
project.is_pinned = project.name in pinned_projects
|
||||||
|
return project_items
|
||||||
|
|
||||||
def _status_items_getter(self, project_entity):
|
def _status_items_getter(self, project_entity):
|
||||||
if not project_entity:
|
if not project_entity:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue