-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugin-store): Make Plugins editable
- Loading branch information
Showing
19 changed files
with
460 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { LoaderInterceptor } from './loader.interceptor'; | ||
|
||
describe('InterceptorsInterceptor', () => { | ||
beforeEach(() => TestBed.configureTestingModule({ | ||
providers: [ | ||
LoaderInterceptor | ||
] | ||
})); | ||
|
||
it('should be created', () => { | ||
const interceptor: LoaderInterceptor = TestBed.inject(LoaderInterceptor); | ||
expect(interceptor).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { | ||
HttpRequest, | ||
HttpHandler, | ||
HttpEvent, | ||
HttpInterceptor, | ||
} from '@angular/common/http'; | ||
import { Observable } from 'rxjs'; | ||
import { LoaderService } from '../services/loader/loader.service'; | ||
import { finalize } from 'rxjs/operators'; | ||
|
||
@Injectable() | ||
export class LoaderInterceptor implements HttpInterceptor { | ||
|
||
constructor(private loaderService: LoaderService) { | ||
} | ||
|
||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> { | ||
this.loaderService.show(); | ||
|
||
return next.handle(request).pipe( | ||
finalize(() => this.loaderService.hide()), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.overlay { | ||
position: fixed; | ||
display: block; | ||
width: 100%; | ||
height: 100%; | ||
top: 0; | ||
left: 0; | ||
background-color: rgba(74, 74, 74, .8); | ||
z-index: 99999; | ||
} | ||
|
||
.spinner { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div *ngIf="isLoading | async" class="overlay"> | ||
<ngx-skeleton-loader appearance="line"></ngx-skeleton-loader> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { LoaderComponent } from './loader.component'; | ||
|
||
describe('LoaderComponent', () => { | ||
let component: LoaderComponent; | ||
let fixture: ComponentFixture<LoaderComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ LoaderComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(LoaderComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Component } from '@angular/core'; | ||
import { Subject } from 'rxjs'; | ||
import { LoaderService } from '../services/loader/loader.service'; | ||
|
||
@Component({ | ||
selector: 'app-loader', | ||
templateUrl: './loader.component.html', | ||
styleUrls: ['./loader.component.css'], | ||
}) | ||
export class LoaderComponent { | ||
isLoading: Subject<boolean> = this.loaderService.isLoading; | ||
|
||
constructor(private loaderService: LoaderService) { | ||
} | ||
|
||
ngOnInit(): void { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
frontend/src/app/plugins/store/plugin-detail/plugin-details.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#title { | ||
margin-left: 10px; | ||
} | ||
|
||
.metadata-item { | ||
flex-basis: 50%; | ||
} |
56 changes: 56 additions & 0 deletions
56
frontend/src/app/plugins/store/plugin-detail/plugin-details.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!-- | ||
~ SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<h2 id="title">Plugin information</h2> | ||
<mat-card> | ||
<form [formGroup]="editPluginForm" (ngSubmit)="onSubmit()"> | ||
Direct URL to a raw `mbse-works-plugin.yml`: | ||
<fieldset> | ||
<mat-form-field appearance="outline"> | ||
<mat-label>Remote URL</mat-label> | ||
<input matInput formControlName="remote" /> | ||
<mat-error *ngIf="editPluginForm.controls.remote.errors?.required"> | ||
The remote URL is required. | ||
</mat-error> | ||
</mat-form-field> | ||
</fieldset> | ||
Basic authentication to fetch template. <br /> | ||
<div class="flex-space-between"> | ||
<div> | ||
<mat-form-field id="username" appearance="outline"> | ||
<mat-label>Username (optional)</mat-label> | ||
<input matInput formControlName="username" /> | ||
</mat-form-field> | ||
<mat-form-field id="password" appearance="outline"> | ||
<mat-label>Password (optional)</mat-label> | ||
<input type="password" matInput formControlName="password" /> | ||
</mat-form-field> | ||
</div> | ||
<button type="submit" mat-raised-button color="primary"> | ||
Save plugin | ||
</button> | ||
</div> | ||
</form> | ||
</mat-card> | ||
<mat-card> | ||
<div class="flex-space-between"> | ||
<span> Currently used template: </span> | ||
<button | ||
mat-raised-button | ||
color="primary" | ||
id="reload" | ||
(click)="refreshPluginContent()" | ||
> | ||
<mat-icon>refresh</mat-icon> Reload from remote | ||
</button> | ||
</div> | ||
<div id="fetched-result"> | ||
{{ | ||
prettifyJSON( | ||
this.peekContent || (pluginStoreService.plugin | async)?.content | ||
) | ||
}} | ||
</div> | ||
</mat-card> |
98 changes: 98 additions & 0 deletions
98
frontend/src/app/plugins/store/plugin-detail/plugin-details.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Component } from '@angular/core'; | ||
import { ActivatedRoute, Router } from '@angular/router'; | ||
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; | ||
import { ToastService } from 'src/app/helpers/toast/toast.service'; | ||
import { filter } from 'rxjs'; | ||
import { FormControl, FormGroup, Validators } from '@angular/forms'; | ||
import { Plugin, PluginStoreService } from '../service/plugin-store.service'; | ||
|
||
@UntilDestroy() | ||
@Component({ | ||
selector: 'app-plugin-details', | ||
templateUrl: './plugin-details.component.html', | ||
styleUrls: ['./plugin-details.component.css'], | ||
}) | ||
export class PluginDetailsComponent { | ||
canDelete = false; | ||
peekContent = ''; | ||
plugin?: Plugin; | ||
|
||
constructor( | ||
public pluginStoreService: PluginStoreService, | ||
private toastService: ToastService, | ||
private router: Router, | ||
private route: ActivatedRoute | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.pluginStoreService.plugin | ||
.pipe(untilDestroyed(this), filter(Boolean)) | ||
.subscribe((plugin) => { | ||
this.plugin = plugin; | ||
this.editPluginForm.patchValue(plugin); | ||
}); | ||
} | ||
|
||
editPluginForm = new FormGroup({ | ||
remote: new FormControl('', Validators.required), | ||
username: new FormControl(''), | ||
password: new FormControl(''), | ||
}); | ||
|
||
onSubmit() { | ||
if (this.editPluginForm.valid) { | ||
this.pluginStoreService | ||
.updatePlugin(this.plugin!.id, this.editPluginForm.value as Plugin) | ||
.subscribe(() => { | ||
this.pluginStoreService.fetchPluginsFromStore(); | ||
this.router.navigate(['/plugins']); | ||
}); | ||
} | ||
} | ||
|
||
refreshPluginContent() { | ||
this.peekContent = this.pluginStoreService.fetchPluginContentFromRemote( | ||
this.editPluginForm.value as Plugin | ||
); | ||
} | ||
|
||
prettifyJSON(content: any, spaces: number = 2) { | ||
return JSON.stringify(content, null, spaces); | ||
} | ||
|
||
deletePlugin(): void { | ||
if ( | ||
!this.canDelete || | ||
!window.confirm( | ||
`Do you really want to delete this project? All assigned users will lose access to it! The project cannot be restored!` | ||
) | ||
) { | ||
return; | ||
} | ||
|
||
this.pluginStoreService.plugin.subscribe((plugin) => { | ||
const pluginId: number = plugin!.id; | ||
this.pluginStoreService.deletePlugin(pluginId).subscribe({ | ||
next: () => { | ||
this.toastService.showSuccess( | ||
'Project deleted', | ||
`${pluginId} has been deleted` | ||
); | ||
this.router.navigate(['../../plugins'], { relativeTo: this.route }); | ||
}, | ||
error: () => { | ||
this.toastService.showError( | ||
'Plugin deletion failed', | ||
`${pluginId} has not been deleted` | ||
); | ||
}, | ||
}); | ||
}) | ||
|
||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
frontend/src/app/plugins/store/plugin-wrapper/plugin-wrapper.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
* SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ |
6 changes: 6 additions & 0 deletions
6
frontend/src/app/plugins/store/plugin-wrapper/plugin-wrapper.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!-- | ||
~ SPDX-FileCopyrightText: Copyright DB Netz AG and the capella-collab-manager contributors | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<router-outlet></router-outlet> |
Oops, something went wrong.