Skip to content

Commit

Permalink
feat: Add possibilty to archive t4c instance
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik003 committed Sep 28, 2023
1 parent 9579da7 commit 28f1647
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<mat-option
*ngFor="let instance of t4cInstanceService.t4cInstances$ | async"
[value]="instance.id"
[disabled]="instance.is_archived"
[matTooltip]="
instance.is_archived ? 'This instance is archived' : ''
"
>
{{ instance.name }}
</mat-option>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/app/services/settings/t4c-instance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export type BaseT4CInstance = {
is_archived: boolean;
};

export type PatchT4CInstance = Partial<BaseT4CInstance>;

export type NewT4CInstance = BaseT4CInstance & {
name: string;
};
Expand Down Expand Up @@ -84,7 +86,7 @@ export class T4CInstanceService {

updateInstance(
instanceId: number,
instance: BaseT4CInstance
instance: PatchT4CInstance
): Observable<T4CInstance> {
return this.http
.patch<T4CInstance>(this.urlFactory(instanceId), instance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,25 @@ <h2 *ngIf="!existing">Add a Team4Capella instance</h2>
</button>
<button mat-flat-button type="submit" color="primary">Submit</button>
</div>
<div *ngIf="!editing && existing" class="flex justify-between">
<button mat-flat-button color="primary" (click)="enableEditing()">
Edit
<div
*ngIf="
!editing &&
existing &&
(t4cInstanceService.t4cInstance$ | async) !== undefined
"
class="flex justify-between"
>
<div *ngIf="!isArchived; else archivePlaceholder">
<button mat-flat-button color="primary" (click)="enableEditing()">
Edit
</button>
</div>
<ng-template #archivePlaceholder>
<div class="grow"></div>
</ng-template>
<button mat-flat-button color="primary" (click)="toggleArchive()">
<mat-icon class="mat-icon-position left">archive</mat-icon>
{{ this.isArchived ? "Unarchive" : "Archive" }}
</button>
</div>
<div *ngIf="!existing" class="text-right">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -34,6 +34,8 @@ export class EditT4CInstanceComponent implements OnInit, OnDestroy {
instanceId?: number;
capellaVersions?: ToolVersion[];

isArchived?: boolean;

portValidators = [
Validators.pattern(/^\d*$/),
Validators.min(0),
Expand Down Expand Up @@ -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 });
});
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
*ngFor="let instance of t4cInstanceService.t4cInstances$ | async"
[routerLink]="['instance', instance.id]"
>
<mat-card matRipple class="mat-card-overview">
<mat-card
matRipple
class="mat-card-overview"
[ngClass]="{ 'bg-gray-300': instance.is_archived }"
>
<div class="header">{{ instance.name }}</div>
<div class="content">
<mat-icon class="aligned">tag</mat-icon> <b> Capella version:</b>
Expand All @@ -28,6 +32,13 @@
<mat-icon class="aligned">link</mat-icon><b> Host:</b>
{{ instance.protocol }}://{{ instance.host }}:{{ instance.port }}
</div>

<div
*ngIf="instance.is_archived"
class="fixed bottom-2 right-2 text-right text-stone-500"
>
Archived
</div>
</mat-card>
</a>
</article>

0 comments on commit 28f1647

Please sign in to comment.