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 Oct 9, 2023
1 parent 5a93ef4 commit 428c1f9
Show file tree
Hide file tree
Showing 5 changed files with 60 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
12 changes: 10 additions & 2 deletions frontend/src/app/services/settings/t4c-instance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 @@ -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<T4CInstance[]>(this.baseUrl).subscribe({
next: (instances) => this._t4cInstances.next(instances),
Expand All @@ -84,7 +92,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,24 @@ <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 style="flex-grow: 1"></div>
</ng-template>
<button mat-flat-button color="primary" (click)="toggleArchive()">
{{ 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,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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 428c1f9

Please sign in to comment.