Skip to content

Commit

Permalink
Merge pull request #98 from Thymis-io/feat/device-limit
Browse files Browse the repository at this point in the history
Device Limit
  • Loading branch information
MSchmoecker authored Oct 3, 2024
2 parents 866adea + b6fd7a8 commit 7aa42d9
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
1 change: 1 addition & 0 deletions controller/thymis_controller/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class CompositeTask(Task):
__all__ = [
"TaskState",
"Task",
"PlainTask",
"CommandTask",
"CompositeTask",
"NixProcessStatus",
Expand Down
11 changes: 10 additions & 1 deletion controller/thymis_controller/task/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def __init__(self, display_name: str):

def get_model(self):
return models.PlainTask(
id=self.id,
id=str(self.id),
start_time=self.start_time,
end_time=self.end_time,
display_name=self.display_name,
Expand Down Expand Up @@ -547,6 +547,8 @@ def __init__(self, repo_dir):


class DeployProjectTask(CompositeTask):
project: "project.Project"

def __init__(self, project: "project.Project", ssh_key_path: str):
super().__init__(
[
Expand All @@ -555,8 +557,15 @@ def __init__(self, project: "project.Project", ssh_key_path: str):
]
)

self.project = project
self.display_name = "Deploying project"

def _run(self):
device_count = len(self.project.read_state().devices)
if device_count > 5:
raise Exception(f"Too many devices for free license ({device_count}/5)")
return super()._run()


class DeployDeviceTask(NixCommandTask):
def __init__(self, repo_dir, device: models.Device, ssh_key_path: str):
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/lib/components/DeployActions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
let openDeploy = false;
</script>

<div class="flex flex-wrap justify-end align-start gap-1 sm:gap-2 w-64 sm:w-96">
<div class="flex flex-wrap justify-end align-start gap-1 sm:gap-2 w-96 sm:w-[400px]">
<Button color="alternative" class="gap-2 px-2 sm:px-4 py-1 sm:py-2 h-min" on:click={build}>
<PlaySolid class="w-[10px] sm:w-[14px]" />
<PlaySolid class="w-[10px] sm:w-[12px]" />
<span class="text-xs sm:text-sm">{$t('deploy.build')}</span>
</Button>
<Button color="alternative" class="gap-2 px-2 sm:px-4 py-1 sm:py-2 h-min" on:click={update}>
<ArrowsRotateSolid class="w-[12px] sm:w-[18px]" />
<ArrowsRotateSolid class="w-[12px] sm:w-[16px]" />
<span class="text-xs sm:text-sm">{$t('deploy.update')}</span>
</Button>
<Button
color="alternative"
class="gap-2 px-2 sm:px-4 py-1 sm:py-2 h-min"
on:click={() => (openDeploy = true)}
>
<GearsSolid class="w-[14px] sm:w-[20px]" />
<GearsSolid class="w-[14px] sm:w-[18px]" />
<span class="text-xs sm:text-sm">{$t('deploy.deploy')}</span>
</Button>
<DeployModal bind:open={openDeploy} />
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"control-device": "Gerät Steuern"
},
"devices": {
"create-new": "Neues Gerät Erstellen",
"create-new": "Neues Gerät Erstellen ({deviceCount}/{deviceLimit})",
"table": {
"name": "Name",
"target-host": "Ziel Host",
Expand All @@ -49,7 +49,8 @@
"edit-name-title": "Namen Bearbeiten",
"edit-hostname-title": "Ziel Hostnamen Bearbeiten",
"edit-tags-title": "Tags Bearbeiten",
"new-tag-placeholder": "Neuer Tag..."
"new-tag-placeholder": "Neuer Tag...",
"limit-explain": "Sie können bis zu {deviceLimit} Geräte verwalten.\nFür größere Projekte bieten wir auf thymis.io/ skalierbare Pläne an, die Ihren Anforderungen entsprechen"
},
"create-device": {
"title": "Neues Gerät Erstellen",
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"control-device": "Control Device"
},
"devices": {
"create-new": "Create New Device",
"create-new": "Create New Device ({deviceCount}/{deviceLimit})",
"table": {
"name": "Name",
"target-host": "Target Host",
Expand All @@ -49,7 +49,8 @@
"edit-name-title": "Edit Name",
"edit-hostname-title": "Edit target hostname",
"edit-tags-title": "Edit Tags",
"new-tag-placeholder": "New Tag..."
"new-tag-placeholder": "New Tag...",
"limit-explain": "You can manage up to {deviceLimit} devices.\nFor larger projects, we offer scalable plans to meet your needs at thymis.io/"
},
"create-device": {
"title": "Create a new device",
Expand Down
26 changes: 23 additions & 3 deletions frontend/src/routes/(authenticated)/devices/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
TableBodyCell,
TableBodyRow,
TableHead,
TableHeadCell
TableHeadCell,
Tooltip
} from 'flowbite-svelte';
import TagIcon from 'lucide-svelte/icons/tag';
import GripVertical from 'lucide-svelte/icons/grip-vertical';
Expand Down Expand Up @@ -96,9 +97,28 @@
</script>

<div class="flex justify-between mb-4">
<Button color="alternative" on:click={() => (deviceModalOpen = true)}>
{$t('devices.create-new')}
<Button
color="alternative"
class="whitespace-nowrap"
on:click={() => (deviceModalOpen = true)}
disabled={devices.length >= 5}
>
{$t('devices.create-new', {
values: {
deviceCount: devices.length,
deviceLimit: 5
}
})}
</Button>
{#if devices.length >= 5}
<Tooltip class="z-50 whitespace-pre">
{$t('devices.limit-explain', {
values: {
deviceLimit: 5
}
})}
</Tooltip>
{/if}
<DeployActions />
</div>
<CreateDeviceModal bind:open={deviceModalOpen} />
Expand Down

0 comments on commit 7aa42d9

Please sign in to comment.