From 98502a5d99f7d7418ae50a5080ad2ff51fb6912e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Schm=C3=B6cker?= Date: Tue, 1 Oct 2024 09:25:30 +0200 Subject: [PATCH 1/5] feat: abort deploy with too many devices --- controller/thymis_controller/models/task.py | 1 + controller/thymis_controller/task/__init__.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/controller/thymis_controller/models/task.py b/controller/thymis_controller/models/task.py index 21349a0a..23275f99 100644 --- a/controller/thymis_controller/models/task.py +++ b/controller/thymis_controller/models/task.py @@ -48,6 +48,7 @@ class CompositeTask(Task): __all__ = [ "TaskState", "Task", + "PlainTask", "CommandTask", "CompositeTask", "NixProcessStatus", diff --git a/controller/thymis_controller/task/__init__.py b/controller/thymis_controller/task/__init__.py index df8ca4e6..93d88720 100644 --- a/controller/thymis_controller/task/__init__.py +++ b/controller/thymis_controller/task/__init__.py @@ -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, @@ -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__( [ @@ -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): From 553e1e16fc88ddd37d4a105c87d73b665bd4ed87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Schm=C3=B6cker?= Date: Tue, 1 Oct 2024 11:19:00 +0200 Subject: [PATCH 2/5] feat: show device limit in frontend --- .../src/lib/components/DeployActions.svelte | 8 +++---- frontend/src/locales/de.json | 3 ++- frontend/src/locales/en.json | 3 ++- .../(authenticated)/devices/+page.svelte | 23 ++++++++++++++++--- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/frontend/src/lib/components/DeployActions.svelte b/frontend/src/lib/components/DeployActions.svelte index 7a457f46..28f5663f 100644 --- a/frontend/src/lib/components/DeployActions.svelte +++ b/frontend/src/lib/components/DeployActions.svelte @@ -17,13 +17,13 @@ let openDeploy = false; -
+
diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 10ed61cb..82f42faa 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -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...", + "device-limit-info": "{deviceCount}/{deviceLimit} Geräte in Gebrauch.\nUpgraden Sie Ihre Lizenz auf {licenceLink}" }, "create-device": { "title": "Neues Gerät Erstellen", diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index e8b52565..14a02ad4 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -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...", + "device-limit-info": "{deviceCount}/{deviceLimit} devices in use.\nUpgrade your licence at {licenceLink}" }, "create-device": { "title": "Create a new device", diff --git a/frontend/src/routes/(authenticated)/devices/+page.svelte b/frontend/src/routes/(authenticated)/devices/+page.svelte index b8816f9b..0c5cdb69 100644 --- a/frontend/src/routes/(authenticated)/devices/+page.svelte +++ b/frontend/src/routes/(authenticated)/devices/+page.svelte @@ -96,11 +96,28 @@
- +
+ +
+

+ {@html $t('devices.device-limit-info', { + values: { + deviceCount: devices.length, + deviceLimit: 5, + licenceLink: + 'Thymis.io' + } + })} +

Date: Thu, 3 Oct 2024 17:30:56 +0200 Subject: [PATCH 3/5] feat: make device limit less intrusive in frontend --- frontend/src/locales/de.json | 5 ++--- frontend/src/locales/en.json | 5 ++--- .../routes/(authenticated)/devices/+page.svelte | 17 ++++++----------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 82f42faa..9f8f8f5a 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -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", @@ -49,8 +49,7 @@ "edit-name-title": "Namen Bearbeiten", "edit-hostname-title": "Ziel Hostnamen Bearbeiten", "edit-tags-title": "Tags Bearbeiten", - "new-tag-placeholder": "Neuer Tag...", - "device-limit-info": "{deviceCount}/{deviceLimit} Geräte in Gebrauch.\nUpgraden Sie Ihre Lizenz auf {licenceLink}" + "new-tag-placeholder": "Neuer Tag..." }, "create-device": { "title": "Neues Gerät Erstellen", diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index 14a02ad4..36a13594 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -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", @@ -49,8 +49,7 @@ "edit-name-title": "Edit Name", "edit-hostname-title": "Edit target hostname", "edit-tags-title": "Edit Tags", - "new-tag-placeholder": "New Tag...", - "device-limit-info": "{deviceCount}/{deviceLimit} devices in use.\nUpgrade your licence at {licenceLink}" + "new-tag-placeholder": "New Tag..." }, "create-device": { "title": "Create a new device", diff --git a/frontend/src/routes/(authenticated)/devices/+page.svelte b/frontend/src/routes/(authenticated)/devices/+page.svelte index 0c5cdb69..ca8786b7 100644 --- a/frontend/src/routes/(authenticated)/devices/+page.svelte +++ b/frontend/src/routes/(authenticated)/devices/+page.svelte @@ -103,21 +103,16 @@ on:click={() => (deviceModalOpen = true)} disabled={devices.length >= 5} > - {$t('devices.create-new')} + {$t('devices.create-new', { + values: { + deviceCount: devices.length, + deviceLimit: 5 + } + })}
-

- {@html $t('devices.device-limit-info', { - values: { - deviceCount: devices.length, - deviceLimit: 5, - licenceLink: - 'Thymis.io' - } - })} -

Date: Thu, 3 Oct 2024 17:54:57 +0200 Subject: [PATCH 4/5] feat: explain device limit --- frontend/src/locales/de.json | 3 ++- frontend/src/locales/en.json | 3 ++- .../src/routes/(authenticated)/devices/+page.svelte | 12 +++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 9f8f8f5a..424ae64d 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -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", diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index 36a13594..034cba8c 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -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", diff --git a/frontend/src/routes/(authenticated)/devices/+page.svelte b/frontend/src/routes/(authenticated)/devices/+page.svelte index ca8786b7..5398195e 100644 --- a/frontend/src/routes/(authenticated)/devices/+page.svelte +++ b/frontend/src/routes/(authenticated)/devices/+page.svelte @@ -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'; @@ -110,6 +111,15 @@ } })} + {#if devices.length >= 5} + + {$t('devices.limit-explain', { + values: { + deviceLimit: 5 + } + })} + + {/if} From b6fd7a8d53e7f651a6feca865d2db88e63167b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Schm=C3=B6cker?= Date: Thu, 3 Oct 2024 17:57:05 +0200 Subject: [PATCH 5/5] fix: remove legacy div --- .../(authenticated)/devices/+page.svelte | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/frontend/src/routes/(authenticated)/devices/+page.svelte b/frontend/src/routes/(authenticated)/devices/+page.svelte index 5398195e..48e017ec 100644 --- a/frontend/src/routes/(authenticated)/devices/+page.svelte +++ b/frontend/src/routes/(authenticated)/devices/+page.svelte @@ -97,30 +97,28 @@
-
- + {#if devices.length >= 5} + + {$t('devices.limit-explain', { values: { - deviceCount: devices.length, deviceLimit: 5 } })} - - {#if devices.length >= 5} - - {$t('devices.limit-explain', { - values: { - deviceLimit: 5 - } - })} - - {/if} -
+ + {/if}