Skip to content

Commit 1eec154

Browse files
Akeruagccie
authored andcommitted
Additional fixes (#48)
* Fix #22 and #27 by refactoring user add/edit logic Fix #28 by adding API call at load Fix #30 and #31 by refactoring fabric add/edit logic Fix #32 Fix #42 by disabling animation globally Work #41 by updating CSS classes * Fix #21 Fix #44 Fix #45 Fix #46 Fix #47 * Fix typo in role checking
1 parent 5844b87 commit 1eec154

10 files changed

+52
-54
lines changed

UIAssets/src/app/_model/user.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class User {
2121
role: number = 2,
2222
password: string = '',
2323
last_login: number = 0,
24-
is_new: boolean = false,
24+
is_new: boolean = true,
2525
password_confirm: string = ''
2626
) {
2727
this.username = username;

UIAssets/src/app/comparison/comparison.component.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h4>
88
<button class="btn btn--icon btn--small btn--primary" (click)='getComparisons()'>
99
<span class="icon-refresh"></span>
1010
</button>
11-
<button class="btn btn--icon btn--small btn--success" (click)='openAddModal(addtemplate)'>
11+
<button *ngIf="userRole == 0" class="btn btn--icon btn--small btn--success" (click)='openAddModal(addtemplate)'>
1212
<span class="icon-add"></span>
1313
</button>
1414
</h4>
@@ -96,7 +96,7 @@ <h4>
9696
<a class="btn btn--small btn--icon btn--primary" [routerLink]="['/comparison', row._id]">
9797
<span class="icon-search"></span>
9898
</a>
99-
<a class="btn btn--small btn--icon btn--negative" (click)='openModal(deletetemplate, row)'>
99+
<a *ngIf="userRole == 0" class="btn btn--small btn--icon btn--negative" (click)='openModal(deletetemplate, row)'>
100100
<span class="icon-trash"></span>
101101
</a>
102102
</ng-template>
@@ -185,7 +185,7 @@ <h6>
185185
<span class="checkbox__label">Remap</span>
186186
</label>
187187
</div>
188-
<div class="form-group form-group--inline">
188+
<div *ngIf="false" class="form-group form-group--inline">
189189
<label class="checkbox">
190190
<input type="checkbox" [(ngModel)]="comparison.serialize" name="serialize">
191191
<span class="checkbox__input"></span>

UIAssets/src/app/comparison/comparison.component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ export class ComparisonComponent implements OnInit, OnDestroy {
2626
updateQueue: any = [];
2727
predefinedNodes: any = ['global'];
2828
comparisonSort: any;
29+
userRole: number;
2930

3031
constructor(private backendService: BackendService, private notificationService: NotificationsService,
3132
private modalService: BsModalService) {
3233
this.loadingMessage = 'Loading comparisons';
3334
this.comparisonSort = this.backendService.prefs.comparison_sort;
35+
this.userRole = parseInt(localStorage.getItem('userRole'));
3436
}
3537

3638
ngOnInit(): void {

UIAssets/src/app/definition/definition.component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ export class DefinitionComponent implements OnInit {
1919
definitions: Definition[];
2020
managedObjects: any[];
2121
definitionSort: any;
22+
userRole: number;
2223

2324
constructor(private backendService: BackendService, private notificationService: NotificationsService,
2425
private modalService: BsModalService) {
2526
this.loadingMessage = 'Loading definitions';
2627
this.definitionSort = this.backendService.prefs.definition_sort;
28+
this.userRole = parseInt(localStorage.getItem('userRole'));
2729
}
2830

2931
ngOnInit(): void {

UIAssets/src/app/fabric/fabric.component.html

+2-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ <h4>
88
<button class="btn btn--icon btn--small btn--primary" (click)='getFabrics()'>
99
<span class="icon-refresh"></span>
1010
</button>
11-
<button class="btn btn--icon btn--small btn--success" (click)='openAddModal(addtemplate)'>
11+
<button *ngIf="userRole == 0" class="btn btn--icon btn--small btn--success" (click)='openAddModal(addtemplate)'>
1212
<span class="icon-add"></span>
1313
</button>
1414
</h4>
@@ -75,7 +75,7 @@ <h4>
7575
{{ row.controllers }}
7676
</ng-template>
7777
</ngx-datatable-column>
78-
<ngx-datatable-column name="Actions" [flexGrow]="0.1">
78+
<ngx-datatable-column *ngIf="userRole == 0" name="Actions" [flexGrow]="0.1">
7979
<ng-template let-row="row" let-value="value" ngx-datatable-cell-template>
8080
<a class="btn btn--small btn--icon btn--primary" title="Edit" (click)='openModal(addtemplate,row)'>
8181
<span data-balloon="Edit" data-balloon-pos="left">
@@ -142,13 +142,6 @@ <h6 *ngIf="!fabric.is_new"> Edit fabric </h6>
142142
<label for="apic_password">Password</label>
143143
</div>
144144
</div>
145-
<div class="form-group" [ngClass]="{'form-group--error':fabric.apic_password !== fabric.password_confirm}">
146-
<div class="form-group__text">
147-
<input id="password_confirm" type="password" [required]="fabric.is_new" [(ngModel)]="fabric.password_confirm"
148-
name="password_confirm">
149-
<label for="password_confirm">Confirm password</label>
150-
</div>
151-
</div>
152145
<div class="form-group form-group--inline">
153146
<label class="checkbox">
154147
<input type="checkbox" [(ngModel)]="fabric.validate" name="validate">

UIAssets/src/app/fabric/fabric.component.ts

+34-33
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ export class FabricComponent implements OnInit {
1818
fabric: Fabric;
1919
fabrics: Fabric[];
2020
fabricSorts: any;
21+
userRole: number;
2122

2223
constructor(private backendService: BackendService, private notificationService: NotificationsService,
2324
private modalService: BsModalService) {
2425
this.loadingMessage = 'Loading fabrics';
2526
this.fabricSorts = this.backendService.prefs.fabric_sort;
27+
this.userRole = parseInt(localStorage.getItem('userRole'));
2628
}
2729

2830
ngOnInit(): void {
@@ -99,39 +101,38 @@ export class FabricComponent implements OnInit {
99101
}
100102

101103
public onSubmit() {
102-
if (this.fabric.apic_password !== undefined && this.fabric.apic_password != '' && this.fabric.apic_password == this.fabric.password_confirm) {
103-
const validate = this.fabric.validate;
104-
if (this.fabric.is_new) {
105-
this.backendService.createFabric(this.fabric).subscribe((results) => {
106-
if (validate) {
107-
this.verifyFabric(this.fabric);
108-
} else {
109-
this.getFabrics();
110-
}
111-
}, (err) => {
112-
if (err['error'] !== undefined && err['error']['error'] !== undefined) {
113-
this.notificationService.error(err['error']['error']);
114-
} else {
115-
this.notificationService.error('Error', 'Could not add fabric');
116-
}
117-
this.loading = false;
118-
});
119-
} else {
120-
this.backendService.updateFabric(this.fabric).subscribe((results) => {
121-
if (validate) {
122-
this.verifyFabric(this.fabric);
123-
} else {
124-
this.getFabrics();
125-
}
126-
}, (err) => {
127-
if (err['error'] !== undefined && err['error']['error'] !== undefined) {
128-
this.notificationService.error(err['error']['error']);
129-
} else {
130-
this.notificationService.error('Error', 'Could not update fabric');
131-
}
132-
this.loading = false;
133-
});
134-
}
104+
this.hideModal();
105+
const validate = this.fabric.validate;
106+
if (this.fabric.is_new) {
107+
this.backendService.createFabric(this.fabric).subscribe((results) => {
108+
if (validate) {
109+
this.verifyFabric(this.fabric);
110+
} else {
111+
this.getFabrics();
112+
}
113+
}, (err) => {
114+
if (err['error'] !== undefined && err['error']['error'] !== undefined) {
115+
this.notificationService.error(err['error']['error']);
116+
} else {
117+
this.notificationService.error('Error', 'Could not add fabric');
118+
}
119+
this.loading = false;
120+
});
121+
} else {
122+
this.backendService.updateFabric(this.fabric).subscribe((results) => {
123+
if (validate) {
124+
this.verifyFabric(this.fabric);
125+
} else {
126+
this.getFabrics();
127+
}
128+
}, (err) => {
129+
if (err['error'] !== undefined && err['error']['error'] !== undefined) {
130+
this.notificationService.error(err['error']['error']);
131+
} else {
132+
this.notificationService.error('Error', 'Could not update fabric');
133+
}
134+
this.loading = false;
135+
});
135136
}
136137
}
137138

UIAssets/src/app/login/login.component.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {Router} from "@angular/router";
33
import {BackendService} from "../_service/backend.service";
44
import {HttpErrorResponse} from "@angular/common/http";
55
import {NotificationsService} from "angular2-notifications";
6-
import {CookieService} from "ngx-cookie-service";
76

87
@Component({
98
templateUrl: './login.component.html',
@@ -14,8 +13,7 @@ export class LoginComponent implements OnInit {
1413
username: string;
1514
password: string;
1615

17-
constructor(public router: Router, private backendService: BackendService,
18-
private notificationService: NotificationsService, private cookieService: CookieService) {
16+
constructor(public router: Router, private backendService: BackendService, private notificationService: NotificationsService) {
1917
}
2018

2119
ngOnInit(): void {

UIAssets/src/app/snapshot/snapshot.component.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ <h4>
1010
<span class="icon-refresh"></span>
1111
</span>
1212
</button>
13-
<button class="btn btn--icon btn--small btn--success" title="Add" (click)='openAddModal(addtemplate)'>
13+
<button *ngIf="userRole == 0" class="btn btn--icon btn--small btn--success" title="Add" (click)='openAddModal(addtemplate)'>
1414
<span data-balloon="Add" data-balloon-pos="left">
1515
<span class="icon-add"></span>
1616
</span>
1717
</button>
18-
<button (click)="fileInput.click()" class="btn btn--icon btn--small" title="Upload">
18+
<button *ngIf="userRole == 0" (click)="fileInput.click()" class="btn btn--icon btn--small" title="Upload">
1919
<span data-balloon="Upload" data-balloon-pos="left">
2020
<span class="icon-upload-contain"></span>
2121
</span>
@@ -101,12 +101,12 @@ <h4>
101101
<span class="icon-search"></span>
102102
</span>
103103
</a>
104-
<a class="btn btn--small btn--icon" title="Download" (click)='fileDownloadHandler(row)'>
104+
<a *ngIf="userRole == 0" class="btn btn--small btn--icon" title="Download" (click)='fileDownloadHandler(row)'>
105105
<span data-balloon="Download" data-balloon-pos="left">
106106
<span class="icon-download-contain"></span>
107107
</span>
108108
</a>
109-
<a class="btn btn--small btn--icon btn--negative" title="Delete"
109+
<a *ngIf="userRole == 0" class="btn btn--small btn--icon btn--negative" title="Delete"
110110
(click)='openModal(deletetemplate, row)'>
111111
<span data-balloon="Delete" data-balloon-pos="left">
112112
<span class="icon-trash"></span>

UIAssets/src/app/snapshot/snapshot.component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class SnapshotComponent implements OnInit {
2727
definitions: Definition[];
2828
app_mode: boolean;
2929
snapshotSorts: any;
30+
userRole: number;
3031

3132
constructor(private backendService: BackendService, private notificationService: NotificationsService,
3233
private modalService: BsModalService) {
@@ -35,6 +36,7 @@ export class SnapshotComponent implements OnInit {
3536
this.loadingMessage = this.appLoadMessage;
3637
this.app_mode = environment.app_mode;
3738
this.snapshotSorts = this.backendService.prefs.snapshot_sort;
39+
this.userRole = parseInt(localStorage.getItem('userRole'));
3840
}
3941

4042
ngOnInit(): void {

UIAssets/src/app/user/user.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ <h6 *ngIf="!user.is_new"> Edit user </h6>
128128
<label for="password_confirm">Confirm password</label>
129129
</div>
130130
</div>
131-
<div class="form-group">
131+
<div class="form-group" *ngIf="user.is_new || userRole == 0">
132132
<div class="form-group__text select">
133133
<select class="form-control" id="role" required [(ngModel)]="user.role" name="role">
134134
<option *ngFor="let role of roles" [value]="role.id">{{ role.name }}</option>

0 commit comments

Comments
 (0)