-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f463d2
commit 299d22c
Showing
8 changed files
with
144 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Any, Dict, Optional, Type | ||
|
||
from django.http import HttpRequest | ||
|
||
|
||
class ComponentRegistry: | ||
_registry: Dict[str, Type] = {} | ||
|
||
@classmethod | ||
def register_class(cls, component_cls: Type) -> None: | ||
if not issubclass(component_cls, BaseComponent): | ||
raise ValueError( | ||
f"Class '{component_cls.__name__}' must inherit from BaseComponent." | ||
) | ||
|
||
class_name = component_cls.__name__ | ||
|
||
if class_name in cls._registry: | ||
raise ValueError(f"Class '{class_name}' is already registered.") | ||
|
||
cls._registry[class_name] = component_cls | ||
|
||
@classmethod | ||
def get_class(cls, class_name: str) -> Optional[Type]: | ||
return cls._registry.get(class_name) | ||
|
||
@classmethod | ||
def create_instance(cls, class_name: str, **kwargs: Any) -> Any: | ||
component_cls = cls.get_class(class_name) | ||
|
||
if component_cls is None: | ||
raise ValueError(f"Class '{class_name}' is not registered.") | ||
|
||
return component_cls(**kwargs) | ||
|
||
|
||
def register_component(cls: Type) -> Type: | ||
ComponentRegistry.register_class(cls) | ||
return cls | ||
|
||
|
||
class BaseComponent: | ||
def __init__(self, request: HttpRequest): | ||
self.request = request | ||
|
||
def get_context_data(self, **kwargs): | ||
return kwargs |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<div class="overflow-auto w-full" data-simplebar> | ||
<table class="w-full"> | ||
<thead> | ||
<tr> | ||
<th></th> | ||
|
||
{% for header in data.headers %} | ||
<th class="font-normal px-3 pb-2.5 text-left "> | ||
<div class="font-semibold text-font-important-light truncate dark:text-font-important-dark"> | ||
{{ header.title }} | ||
</div> | ||
|
||
{% if header.subtitle %} | ||
<div class="mt-0.5 text-xs truncate"> | ||
{{ header.subtitle }} | ||
</div> | ||
{% endif %} | ||
</th> | ||
{% endfor %} | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
{% for row in data.rows %} | ||
<tr class="h-full"> | ||
<td> | ||
<div class="pr-3 py-2.5"> | ||
<div class="font-semibold text-font-important-light dark:text-font-important-dark"> | ||
{{ row.header.title }} | ||
</div> | ||
|
||
{% if row.header.subtitle %} | ||
<div class="mt-0.5 text-xs"> | ||
{{ row.header.subtitle }} | ||
</div> | ||
{% endif %} | ||
</div> | ||
</td> | ||
|
||
{% for col in row.cols %} | ||
<td class="h-full"> | ||
<div class="flex flex-col h-full justify-center px-3 py-2.5 rounded-md {% if col.color %}{{ col.color }}{% else %}bg-gray-50 border border-dashed dark:bg-gray-800 dark:border-gray-700{% endif %}"> | ||
{{ col.value }} | ||
</div> | ||
</td> | ||
{% endfor %} | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<ul class="flex flex-row gap-0.5 overflow-hidden rounded"> | ||
{% for item in data %} | ||
<li class="h-8 px-px size-full {% if item.color %}{{ item.color }}{% else %}bg-gray-300 dark:bg-gray-400{% endif %} hover:opacity-50" title="{{ item.tooltip }}"></li> | ||
{% endfor %} | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters