From 7bc19ba3763ab355efb028ed5909969c7224095a Mon Sep 17 00:00:00 2001 From: dominik003 Date: Mon, 18 Sep 2023 16:04:52 +0200 Subject: [PATCH] feat: Add possibilty to archive t4c instance --- .../toolmodels/modelsources/t4c/routes.py | 2 +- .../settings/modelsources/t4c/injectables.py | 15 +++++++++++ .../manage-t4c-model.component.html | 4 +++ .../services/settings/t4c-instance.service.ts | 12 +++++++-- .../edit-t4c-instance.component.html | 24 +++++++++++++++--- .../edit-t4c-instance.component.ts | 25 +++++++++++++++++-- .../t4c-settings/t4c-settings.component.html | 13 +++++++++- 7 files changed, 86 insertions(+), 9 deletions(-) diff --git a/backend/capellacollab/projects/toolmodels/modelsources/t4c/routes.py b/backend/capellacollab/projects/toolmodels/modelsources/t4c/routes.py index 3bb4969e6e..916bbd0bbb 100644 --- a/backend/capellacollab/projects/toolmodels/modelsources/t4c/routes.py +++ b/backend/capellacollab/projects/toolmodels/modelsources/t4c/routes.py @@ -79,7 +79,7 @@ def create_t4c_model( ), db: orm.Session = fastapi.Depends(database.get_db), ): - instance = settings_t4c_injecatbles.get_existing_instance( + instance = settings_t4c_injecatbles.get_existing_unarchived_instance( body.t4c_instance_id, db ) repository = ( diff --git a/backend/capellacollab/settings/modelsources/t4c/injectables.py b/backend/capellacollab/settings/modelsources/t4c/injectables.py index 3334eb0a1a..0449141f03 100644 --- a/backend/capellacollab/settings/modelsources/t4c/injectables.py +++ b/backend/capellacollab/settings/modelsources/t4c/injectables.py @@ -22,3 +22,18 @@ def get_existing_instance( "reason": f"The t4c instance with the id {t4c_instance_id} does not exist.", }, ) + + +def get_existing_unarchived_instance( + t4c_instance_id: int, db: orm.Session = fastapi.Depends(database.get_db) +): + t4c_instance = get_existing_instance(t4c_instance_id, db) + if t4c_instance.is_archived: + raise fastapi.HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail={ + "reason": f"The T4C instance identified by {t4c_instance.id} is archived, thus prohibiting the execution of the requested operation." + }, + ) + + return t4c_instance diff --git a/frontend/src/app/projects/models/model-source/t4c/manage-t4c-model/manage-t4c-model.component.html b/frontend/src/app/projects/models/model-source/t4c/manage-t4c-model/manage-t4c-model.component.html index c3cb95aadb..7a4d27a247 100644 --- a/frontend/src/app/projects/models/model-source/t4c/manage-t4c-model/manage-t4c-model.component.html +++ b/frontend/src/app/projects/models/model-source/t4c/manage-t4c-model/manage-t4c-model.component.html @@ -24,6 +24,10 @@ {{ instance.name }} diff --git a/frontend/src/app/services/settings/t4c-instance.service.ts b/frontend/src/app/services/settings/t4c-instance.service.ts index 5c2588c9fa..6313d331ef 100644 --- a/frontend/src/app/services/settings/t4c-instance.service.ts +++ b/frontend/src/app/services/settings/t4c-instance.service.ts @@ -5,7 +5,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { BehaviorSubject, Observable, tap } from 'rxjs'; +import { BehaviorSubject, Observable, map, tap } from 'rxjs'; import { environment } from 'src/environments/environment'; export type Protocol = 'tcp' | 'ssl' | 'ws' | 'wss'; @@ -25,6 +25,8 @@ export type BaseT4CInstance = { is_archived: boolean; }; +export type PatchT4CInstance = Partial; + export type NewT4CInstance = BaseT4CInstance & { name: string; }; @@ -59,6 +61,12 @@ export class T4CInstanceService { ); public readonly t4cInstance$ = this._t4cInstance.asObservable(); + public readonly unarchivedT4cInstances$ = this._t4cInstances.pipe( + map((t4cInstances) => + t4cInstances?.filter((t4cInstance) => !t4cInstance.is_archived) + ) + ); + loadInstances(): void { this.http.get(this.baseUrl).subscribe({ next: (instances) => this._t4cInstances.next(instances), @@ -84,7 +92,7 @@ export class T4CInstanceService { updateInstance( instanceId: number, - instance: BaseT4CInstance + instance: PatchT4CInstance ): Observable { return this.http .patch(this.urlFactory(instanceId), instance) diff --git a/frontend/src/app/settings/modelsources/t4c-settings/edit-t4c-instance/edit-t4c-instance.component.html b/frontend/src/app/settings/modelsources/t4c-settings/edit-t4c-instance/edit-t4c-instance.component.html index c441f7e62a..28389af23f 100644 --- a/frontend/src/app/settings/modelsources/t4c-settings/edit-t4c-instance/edit-t4c-instance.component.html +++ b/frontend/src/app/settings/modelsources/t4c-settings/edit-t4c-instance/edit-t4c-instance.component.html @@ -176,9 +176,27 @@

Add a Team4Capella instance

-
- +
+ +
+
+
diff --git a/frontend/src/app/settings/modelsources/t4c-settings/edit-t4c-instance/edit-t4c-instance.component.ts b/frontend/src/app/settings/modelsources/t4c-settings/edit-t4c-instance/edit-t4c-instance.component.ts index 150c3a698a..12377e2c5c 100644 --- a/frontend/src/app/settings/modelsources/t4c-settings/edit-t4c-instance/edit-t4c-instance.component.ts +++ b/frontend/src/app/settings/modelsources/t4c-settings/edit-t4c-instance/edit-t4c-instance.component.ts @@ -11,8 +11,8 @@ import { filter, map } from 'rxjs'; import { BreadcrumbsService } from 'src/app/general/breadcrumbs/breadcrumbs.service'; import { ToastService } from 'src/app/helpers/toast/toast.service'; import { - BaseT4CInstance, NewT4CInstance, + PatchT4CInstance, Protocol, T4CInstanceService, } from 'src/app/services/settings/t4c-instance.service'; @@ -34,6 +34,8 @@ export class EditT4CInstanceComponent implements OnInit, OnDestroy { instanceId?: number; capellaVersions?: ToolVersion[]; + isArchived?: boolean; + portValidators = [ Validators.pattern(/^\d*$/), Validators.min(0), @@ -91,6 +93,7 @@ export class EditT4CInstanceComponent implements OnInit, OnDestroy { .pipe(untilDestroyed(this), filter(Boolean)) .subscribe((t4cInstance) => { t4cInstance.password = '***********'; + this.isArchived = t4cInstance.is_archived; this.form.patchValue(t4cInstance); this.breadcrumbsService.updatePlaceholder({ t4cInstance }); }); @@ -139,7 +142,7 @@ export class EditT4CInstanceComponent implements OnInit, OnDestroy { update(): void { if (this.form.valid && this.instanceId) { this.t4cInstanceService - .updateInstance(this.instanceId, this.form.value as BaseT4CInstance) + .updateInstance(this.instanceId, this.form.value as PatchT4CInstance) .subscribe((instance) => { this.editing = false; this.form.disable(); @@ -151,6 +154,24 @@ export class EditT4CInstanceComponent implements OnInit, OnDestroy { } } + toggleArchive(): void { + if (this.instanceId) { + this.t4cInstanceService + .updateInstance(this.instanceId, { + is_archived: !this.isArchived, + }) + .subscribe((instance) => { + this.isArchived = instance.is_archived; + this.toastService.showSuccess( + 'Instance updated', + `The instance “${instance.name}” is now ${ + this.isArchived ? 'archived' : 'unarchived' + }.` + ); + }); + } + } + submit(): void { if (this.existing) { this.update(); diff --git a/frontend/src/app/settings/modelsources/t4c-settings/t4c-settings.component.html b/frontend/src/app/settings/modelsources/t4c-settings/t4c-settings.component.html index 804c43b309..cce15fc2e6 100644 --- a/frontend/src/app/settings/modelsources/t4c-settings/t4c-settings.component.html +++ b/frontend/src/app/settings/modelsources/t4c-settings/t4c-settings.component.html @@ -19,7 +19,11 @@ *ngFor="let instance of t4cInstanceService.t4cInstances$ | async" [routerLink]="['instance', instance.id]" > - +
{{ instance.name }}
tag Capella version: @@ -28,6 +32,13 @@ link Host: {{ instance.protocol }}://{{ instance.host }}:{{ instance.port }}
+ +
+ Archived +