From 428c1f95f30f0169afb4960ebb33de7cd18def15 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 --- .../manage-t4c-model.component.html | 4 ++++ .../services/settings/t4c-instance.service.ts | 12 ++++++++-- .../edit-t4c-instance.component.html | 21 ++++++++++++++--- .../edit-t4c-instance.component.ts | 23 +++++++++++++++++-- .../t4c-settings/t4c-settings.component.html | 7 ++++++ 5 files changed, 60 insertions(+), 7 deletions(-) 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..e508d1c933 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,24 @@

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..ba29a08e37 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,22 @@ 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 archived.` + ); + }); + } + } + 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..4635e267ef 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 @@ -28,6 +28,13 @@ link Host: {{ instance.protocol }}://{{ instance.host }}:{{ instance.port }}
+ +
+ Archived +