Skip to content

Commit 0bba7b9

Browse files
Add deployment modeling flags (#174)
* fix configuration * fix config saving in only admin mode fix some code analysis errors * fix some code analysis errors * enable editing deployment modeling props * fixed compilation errors - new pattern fields * use new auth port Co-authored-by: Alex <[email protected]>
1 parent 1eca37f commit 0bba7b9

15 files changed

+183
-114
lines changed

src/app/app.component.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,35 +32,35 @@
3232
<button *ngIf="!planqkUi" mat-menu-item routerLink="/user-info"> UserInfo </button>
3333
<button *ngIf="p.userHasPrivilege('USER_READ_ALL') | async" mat-menu-item routerLink="/admin"> Admin </button>
3434
<!-- <button mat-menu-item routerLink="/developer"> Developer </button> -->
35-
<button *ngIf="!planqkUi" mat-menu-item (click)="openFeatureToggleDialog()">
35+
<button *ngIf="showFeatureFlag" mat-menu-item (click)="openFeatureToggleDialog()">
3636
<span>Feature Toggles</span>
3737
</button>
38-
<button mat-menu-item color="warn" (click)="logout()"> Logout </button>
38+
<button mat-menu-item (click)="logout()"> Logout </button>
3939
</mat-menu>
4040
</div>
4141
</mat-toolbar>
4242

4343
<nav mat-tab-nav-bar>
4444
<a mat-tab-link [routerLink]="'/' + pathConstants.patternLanguages"
45-
routerLinkActive #rla1="routerLinkActive" [active]="rla1.isActive">
45+
routerLinkActive="" #rla1="routerLinkActive" [active]="rla1.isActive">
4646
Pattern Languages
4747
</a>
4848
<a mat-tab-link [routerLink]="'/' + pathConstants.patternViews"
49-
*patternAtlasUiShowOnFeature="UiFeatures.PATTERNVIEWS"
50-
routerLinkActive #rla2="routerLinkActive" [active]="rla2.isActive">
49+
*patternAtlasUiShowOnFeature="UiFeatures.PATTERN_VIEWS"
50+
routerLinkActive="" #rla2="routerLinkActive" [active]="rla2.isActive">
5151
Pattern Views
5252
</a>
5353
<a mat-tab-link [routerLink]="'/' + pathConstants.designModels"
5454
*patternAtlasUiShowOnFeature="UiFeatures.DESIGN_MODEL"
55-
routerLinkActive #rla3="routerLinkActive" [active]="rla3.isActive">
55+
routerLinkActive="" #rla3="routerLinkActive" [active]="rla3.isActive">
5656
Design Models
5757
</a>
58-
<a mat-tab-link [routerLink]="'/candidate'" *patternAtlasUiShowOnFeature="UiFeatures.PATTERNCANDIDATE"
59-
routerLinkActive #rla4="routerLinkActive" [active]="rla4.isActive">
58+
<a mat-tab-link [routerLink]="'/candidate'" *patternAtlasUiShowOnFeature="UiFeatures.PATTERN_CANDIDATE"
59+
routerLinkActive="" #rla4="routerLinkActive" [active]="rla4.isActive">
6060
Pattern Candidate
6161
</a>
6262
<a mat-tab-link [routerLink]="'/issue'" *patternAtlasUiShowOnFeature="UiFeatures.ISSUE"
63-
routerLinkActive #rla5="routerLinkActive" [active]="rla5.isActive">
63+
routerLinkActive="" #rla5="routerLinkActive" [active]="rla5.isActive">
6464
Issue
6565
</a>
6666
</nav>

src/app/app.component.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
1313
*/
1414

15-
import { Component, ChangeDetectionStrategy, ChangeDetectorRef, OnInit } from '@angular/core';
15+
import { Component, OnInit } from '@angular/core';
1616
import { AuthenticationService } from './authentication/_services/authentication.service';
1717
import { PrivilegeService } from './authentication/_services/privilege.service';
1818
import { globals } from './globals';
@@ -23,7 +23,7 @@ import { HttpErrorResponse } from '@angular/common/http';
2323
import { ToasterService } from 'angular2-toaster';
2424
import { MatDialog } from '@angular/material/dialog';
2525
import { FeatureToggleDialogComponent } from './core/component/feature-toggle-dialog/feature-toggle-dialog.component';
26-
import { ActivatedRoute, Router } from '@angular/router';
26+
import { UserRole } from './core/user-management';
2727

2828
@Component({
2929
selector: 'pp-root',
@@ -41,13 +41,14 @@ export class AppComponent implements OnInit {
4141
readonly pathConstants = globals.pathConstants;
4242
loading = true;
4343
planqkUi = false;
44+
showFeatureFlag = false;
45+
private isAdmin: boolean;
4446

4547
constructor(public auth: AuthenticationService,
4648
public p: PrivilegeService,
4749
private toasterService: ToasterService,
4850
private configService: PatternAtlasUiRepositoryConfigurationService,
49-
private dialog: MatDialog,
50-
private cdr: ChangeDetectorRef, private router: Router, private route: ActivatedRoute) {
51+
private dialog: MatDialog) {
5152
}
5253

5354
login() {
@@ -63,33 +64,42 @@ export class AppComponent implements OnInit {
6364
() => {
6465
this.loading = false;
6566
this.planqkUi = this.configService.configuration.features[UiFeatures.PLANQK_UI];
67+
this.updateShowFeatureDialogFlag();
6668
},
6769
(error: HttpErrorResponse) => {
6870
this.loading = false;
6971
this.planqkUi = true;
70-
if(error.status === globals.statusCodeNotFound){
72+
73+
if (error.status === globals.statusCodeNotFound) {
7174
this.configService.getDefaultConfiguration();
72-
}
73-
else if (this.configService.configuration.features[UiFeatures.SHOW_SETTINGS]) {
75+
} else if (this.configService.configuration.features[UiFeatures.SHOW_SETTINGS]) {
7476
console.log('default values applied');
7577
}
78+
this.updateShowFeatureDialogFlag();
7679
}
7780
);
7881
this.auth.user.subscribe(_user => {
7982
if (_user) {
83+
this.isAdmin = _user.role == UserRole.ADMIN;
8084
this.userName = _user.name;
8185
this.loggedIn = true;
86+
this.updateShowFeatureDialogFlag();
8287
} else {
8388
this.userName = null;
8489
this.loggedIn = false;
90+
this.updateShowFeatureDialogFlag();
8591
}
8692
})
8793
}
8894

8995
openFeatureToggleDialog() {
90-
this.dialog.open(FeatureToggleDialogComponent).afterClosed().subscribe(() => {
96+
this.dialog.open(FeatureToggleDialogComponent, { data: { isAdmin: this.isAdmin } }).afterClosed().subscribe(() => {
9197
// reload page to trigger ShowOnFeatureDirectives which use the ngOnInit lifecycle hook
9298
window.location.reload();
9399
});
94100
}
101+
102+
private updateShowFeatureDialogFlag() {
103+
this.showFeatureFlag = !this.planqkUi || this.isAdmin;
104+
}
95105
}

src/app/core/component/edit-url-dialog/edit-url-dialog.component.html

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@ <h1 mat-dialog-title>Edit Title or Icon for {{data.pattern.name}}</h1>
22
<div mat-dialog-content>
33
<mat-form-field>
44
<mat-label>Adjust Pattern Name</mat-label>
5-
<input matInput placeholder={{data.pattern.name}} [(ngModel)]="data.name">
5+
<input matInput placeholder={{data.pattern.name}} [(ngModel)]="data.pattern.name">
66
</mat-form-field>
77
<mat-form-field>
88
<mat-label>Adjust Icon URL</mat-label>
9-
<input matInput placeholder={{data.pattern.iconUrl}} [(ngModel)]="data.icon">
9+
<input matInput placeholder={{data.pattern.iconUrl}} [(ngModel)]="data.pattern.iconUrl">
1010
</mat-form-field>
1111
<mat-form-field>
1212
<mat-label>Adjust Paper Reference</mat-label>
13-
<input matInput placeholder={{data.pattern.patternRef}} [(ngModel)]="data.paperRef">
13+
<input matInput placeholder={{data.pattern.paperRef}} [(ngModel)]="data.pattern.paperRef">
1414
</mat-form-field>
1515

16+
<div *patternAtlasUiShowOnFeature="UiFeatures.DEPLOYMENT_MODELLING">
17+
<mat-checkbox [(ngModel)]="data.pattern.deploymentModelingBehaviorPattern">
18+
Behavior Pattern
19+
</mat-checkbox>
20+
<br>
21+
<mat-checkbox [(ngModel)]="data.pattern.deploymentModelingStructurePattern">
22+
Component Pattern
23+
</mat-checkbox>
24+
</div>
25+
1626
</div>
17-
<mat-dialog-actions align="end">
27+
<mat-dialog-actions>
1828
<button mat-button (click)="onNoClick()">Cancel</button>
19-
<button mat-button [mat-dialog-close]="data" cdkFocusInitial>Ok</button>
29+
<button mat-button [mat-dialog-close]="data">Ok</button>
2030
</mat-dialog-actions>

src/app/core/component/edit-url-dialog/edit-url-dialog.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Component, Inject } from '@angular/core';
22
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
3+
import { UiFeatures } from '../../directives/pattern-atlas-ui-repository-configuration.service';
4+
import Pattern from '../../model/hal/pattern.model';
35

46
@Component({
57
selector: 'pp-edit-url-dialog',
@@ -8,9 +10,13 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
810
})
911
export class EditUrlDialogComponent {
1012

13+
readonly UiFeatures = UiFeatures;
14+
1115
constructor(
1216
public dialogRef: MatDialogRef<EditUrlDialogComponent>,
13-
@Inject(MAT_DIALOG_DATA) public data) {
17+
@Inject(MAT_DIALOG_DATA) public data: {
18+
pattern: Pattern
19+
}) {
1420
}
1521

1622
onNoClick(): void {

src/app/core/component/feature-toggle-dialog/feature-toggle-dialog.component.html

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,40 @@ <h1 mat-dialog-title>Enable or Disable Feature: </h1>
22
<div mat-card-content>
33
<input type="checkbox" [(ngModel)]="config.features.designModel" id="designModel" name="designModel"
44
[checked]="config.features.designModel" (change)="toggleFeature(UiFeatures.DESIGN_MODEL, $event)"
5-
[disabled]="!config.features.showSettings">
5+
[disabled]="disabled()">
66
<label for="designModel">Design Model</label>
77
<br>
88
<input type="checkbox" [(ngModel)]="config.features.issue"
99
id="issue" name="issue"
1010
[checked]="config.features.issue"
11-
[disabled]="!config.features.showSettings"
11+
[disabled]="disabled()"
1212
(change)="toggleFeature(UiFeatures.ISSUE, $event)">
1313
<label for="issue">Issue</label>
1414
<br>
1515
<input type="checkbox" [(ngModel)]="config.features.patternCandidate" id="patternCandidate"
1616
name="patternCandidate"
1717
[checked]="config.features.patternCandidate"
18-
[disabled]="!config.features.showSettings"
19-
(change)="toggleFeature(UiFeatures.PATTERNCANDIDATE, $event)">
18+
[disabled]="disabled()"
19+
(change)="toggleFeature(UiFeatures.PATTERN_CANDIDATE, $event)">
2020
<label for="patternCandidate">Pattern Candidate</label>
2121
<br>
2222
<input type="checkbox" [(ngModel)]="config.features.patternViews" id="patternViews" name="patternViews"
2323
[checked]="config.features.patternViews"
24-
[disabled]="!config.features.showSettings"
25-
(change)="toggleFeature(UiFeatures.PATTERNVIEWS, $event)">
24+
[disabled]="disabled()"
25+
(change)="toggleFeature(UiFeatures.PATTERN_VIEWS, $event)">
2626
<label for="patternViews">Pattern Views</label>
2727
<br>
2828
<input type="checkbox" [(ngModel)]="config.features.editing" id="editing" name="editing"
2929
[checked]="config.features.editing"
30-
[disabled]="!config.features.showSettings"
30+
[disabled]="disabled()"
3131
(change)="toggleFeature(UiFeatures.EDITING, $event)">
32-
<label for="patternViews">Editing</label>
32+
<label for="editing">Editing</label>
33+
<br>
34+
<input type="checkbox" [(ngModel)]="config.features.deploymentModelling" id="deploymentModeling" name="deploymentModeling"
35+
[checked]="config.features.deploymentModelling"
36+
[disabled]="disabled()"
37+
(change)="toggleFeature(UiFeatures.DEPLOYMENT_MODELLING, $event)">
38+
<label for="deploymentModeling">Show Deployment Modeling settings</label>
3339
</div>
3440
<div mat-dialog-actions>
3541
<button mat-button (click)="onCloseDialogClick()">Close</button>

src/app/core/component/feature-toggle-dialog/feature-toggle-dialog.component.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, Inject, OnInit } from '@angular/core';
22
import {
33
PatternAtlasUiConfiguration, PatternAtlasUiRepositoryConfigurationService, UiFeatures
44
} from '../../directives/pattern-atlas-ui-repository-configuration.service';
5-
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
5+
import { HttpClient } from '@angular/common/http';
66
import { ToasterService } from 'angular2-toaster';
7-
import { MatDialogRef } from '@angular/material/dialog';
7+
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
88

99
@Component({
1010
selector: 'pp-feature-toggle-dialog',
@@ -19,19 +19,24 @@ export class FeatureToggleDialogComponent implements OnInit {
1919
constructor(
2020
private http: HttpClient, private toasterService: ToasterService,
2121
private configService: PatternAtlasUiRepositoryConfigurationService,
22-
public dialogRef: MatDialogRef<FeatureToggleDialogComponent>
22+
public dialogRef: MatDialogRef<FeatureToggleDialogComponent>,
23+
@Inject(MAT_DIALOG_DATA) public data: { isAdmin: boolean }
2324
) {
2425
}
2526

27+
public disabled(): boolean {
28+
return !(this.config.features.showSettings || this.data.isAdmin);
29+
}
30+
2631
ngOnInit(): void {
2732
this.config = this.configService.configuration;
2833
}
2934

3035
toggleFeature(feature: UiFeatures, event: Event): void {
31-
if (this.config.features.showSettings) {
36+
if (this.config.features.showSettings || this.data.isAdmin) {
3237
this.configService.applyConfig(feature, event.target['checked']).subscribe(
3338
() => this.toasterService.pop('success', 'Successfully updated the config!'),
34-
(error: HttpErrorResponse) =>
39+
() =>
3540
this.toasterService.pop(
3641
'error', 'Error while saving config!'
3742
)

0 commit comments

Comments
 (0)