6262@strawberry .type
6363class TaskType :
6464 name : str
65+ icon : str | None = None
66+ short_name : str | None = None
67+ color : str | None = None
6568
6669
6770@strawberry .type
6871class FolderType :
6972 name : str
73+ icon : str | None = None
74+ short_name : str | None = None
7075
71- @strawberry .field
72- def icon (self ) -> str :
73- return self .name .lower ()
76+
77+ @strawberry .type
78+ class LinkType :
79+ name : str
80+ link_type : str
81+ input_type : str
82+ output_type : str
83+ color : str | None = None
84+ style : str = "solid"
85+
86+
87+ @strawberry .type
88+ class Status :
89+ name : str
90+ short_name : str | None = None
91+ icon : str | None = None
92+ color : str | None = None
93+ state : str | None = None
94+ scope : list [str ] | None = None
95+
96+
97+ @strawberry .type
98+ class Tag :
99+ name : str
100+ color : str | None = None
74101
75102
76103@strawberry .type
@@ -191,36 +218,81 @@ def all_attrib(self) -> str:
191218
192219 @strawberry .field (description = "List of project's task types" )
193220 async def task_types (self , active_only : bool = False ) -> list [TaskType ]:
221+ cond = ""
194222 if active_only :
195- query = f"""
196- SELECT DISTINCT(task_type) AS task_type
197- FROM project_{ self .project_name } .tasks
198- """
199- else :
200- query = f"""
201- SELECT name AS task_type
202- FROM project_{ self .project_name } .task_types
203- ORDER BY position
223+ cond = f"""
224+ WHERE name IN (SELECT DISTINCT(task_type)
225+ FROM project_{ self .project_name } .tasks)
204226 """
227+ query = f"""
228+ SELECT name, data
229+ FROM project_{ self .project_name } .task_types
230+ { cond }
231+ ORDER BY position
232+ """
233+ res = await Postgres .fetch (query )
205234 return [
206- TaskType (name = row ["task_type" ]) async for row in Postgres .iterate (query )
235+ TaskType (
236+ name = row ["name" ],
237+ short_name = row ["data" ].get ("shortName" ),
238+ icon = row ["data" ].get ("icon" ),
239+ color = row ["data" ].get ("color" ),
240+ )
241+ for row in res
207242 ]
208243
209244 @strawberry .field (description = "List of project's folder types" )
210245 async def folder_types (self , active_only : bool = False ) -> list [FolderType ]:
246+ cond = ""
211247 if active_only :
212- query = f"""
213- SELECT DISTINCT(folder_type) AS folder_type
214- FROM project_{ self .project_name } .folders
248+ cond = f"""
249+ WHERE name IN ( SELECT DISTINCT(folder_type)
250+ FROM project_{ self .project_name } .folders)
215251 """
216- else :
217- query = f"""
218- SELECT name AS folder_type
219- FROM project_{ self .project_name } .folder_types
220- ORDER BY position
252+
253+ query = f"""
254+ SELECT name, data
255+ FROM project_{ self .project_name } .folder_types
256+ { cond }
257+ ORDER BY position
258+ """
259+ res = await Postgres .fetch (query )
260+ return [
261+ FolderType (
262+ name = row ["name" ],
263+ short_name = row ["data" ].get ("shortName" ),
264+ icon = row ["data" ].get ("icon" ),
265+ )
266+ for row in res
267+ ]
268+
269+ @strawberry .field (description = "List of project's link types" )
270+ async def link_types (self , active_only : bool = False ) -> list [LinkType ]:
271+ cond = ""
272+ if active_only :
273+ cond = f"""
274+ WHERE name IN (SELECT DISTINCT(link_type)
275+ FROM project_{ self .project_name } .links)
221276 """
277+
278+ query = f"""
279+ SELECT name, link_type, input_type, output_type, data
280+ FROM project_{ self .project_name } .link_types
281+ { cond }
282+ ORDER BY name
283+ """
284+
285+ res = await Postgres .fetch (query )
222286 return [
223- FolderType (name = row ["folder_type" ]) async for row in Postgres .iterate (query )
287+ LinkType (
288+ name = row ["name" ],
289+ link_type = row ["link_type" ],
290+ input_type = row ["input_type" ],
291+ output_type = row ["output_type" ],
292+ color = row ["data" ].get ("color" ),
293+ style = row ["data" ].get ("style" , "solid" ),
294+ )
295+ for row in res
224296 ]
225297
226298 @strawberry .field (description = "List of project's product types" )
@@ -243,6 +315,42 @@ async def product_types(self) -> list[ProductType]:
243315 )
244316 ]
245317
318+ @strawberry .field (description = "List of project's statuses" )
319+ async def statuses (self ) -> list [Status ]:
320+ query = f"""
321+ SELECT name, data
322+ FROM project_{ self .project_name } .statuses
323+ ORDER BY position
324+ """
325+ res = await Postgres .fetch (query )
326+ return [
327+ Status (
328+ name = row ["name" ],
329+ short_name = row ["data" ].get ("shortName" ),
330+ icon = row ["data" ].get ("icon" ),
331+ color = row ["data" ].get ("color" ),
332+ state = row ["data" ].get ("state" ),
333+ scope = row ["data" ].get ("scope" , []),
334+ )
335+ for row in res
336+ ]
337+
338+ @strawberry .field (description = "List of tags in the project" )
339+ async def tags (self ) -> list [Tag ]:
340+ query = f"""
341+ SELECT name, data
342+ FROM project_{ self .project_name } .tags
343+ ORDER BY position
344+ """
345+ res = await Postgres .fetch (query )
346+ return [
347+ Tag (
348+ name = row ["name" ],
349+ color = row ["data" ].get ("color" ),
350+ )
351+ for row in res
352+ ]
353+
246354 @strawberry .field (description = "List of tags used in the project" )
247355 async def used_tags (self ) -> list [str ]:
248356 return await get_used_project_tags (self .project_name )
0 commit comments