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 62e2072 commit 7bc19ba
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
15 changes: 15 additions & 0 deletions backend/capellacollab/settings/modelsources/t4c/injectables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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,27 @@ <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">{{
this.isArchived ? "unarchive" : "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 7bc19ba

Please sign in to comment.