Skip to content

Commit 7b1088e

Browse files
author
abodart
committed
Fix datacenter#22 and datacenter#27 by refactoring user add/edit logic
Fix datacenter#28 by adding API call at load Fix datacenter#30 and datacenter#31 by refactoring fabric add/edit logic Fix datacenter#32 Fix datacenter#42 by disabling animation globally Work datacenter#41 by updating CSS classes
1 parent 980b165 commit 7b1088e

14 files changed

+212
-228
lines changed

UIAssets/src/app/_model/fabric.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,29 @@ export class Fabric {
1515
apic_password: string;
1616
controllers: string[];
1717
fabric: string;
18+
validate: boolean;
19+
is_new: boolean;
20+
password_confirm: string;
1821

19-
constructor(apic_cert?: string, apic_hostname?: string, apic_username?: string, apic_password?: string, controllers?: string[], fabric?: string) {
22+
constructor(
23+
apic_cert: string = '',
24+
apic_hostname: string = '',
25+
apic_username: string = '',
26+
apic_password: string = '',
27+
controllers: string[] = [],
28+
fabric: string = '',
29+
validate: boolean = true,
30+
is_new: boolean = true,
31+
password_confirm: string = ''
32+
) {
2033
this.apic_cert = apic_cert;
2134
this.apic_hostname = apic_hostname;
2235
this.apic_username = apic_username;
2336
this.apic_password = apic_password;
2437
this.controllers = controllers;
2538
this.fabric = fabric;
39+
this.validate = validate;
40+
this.is_new = is_new;
41+
this.password_confirm = password_confirm;
2642
}
2743
}

UIAssets/src/app/_model/user.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,25 @@ export class UserList {
1010

1111
export class User {
1212
username: string;
13-
role: any;
13+
role: number;
1414
password: string;
1515
last_login: number;
16+
is_new: boolean;
17+
password_confirm: string;
1618

17-
public constructor() {
19+
constructor(
20+
username: string = '',
21+
role: number = 2,
22+
password: string = '',
23+
last_login: number = 0,
24+
is_new: boolean = false,
25+
password_confirm: string = ''
26+
) {
27+
this.username = username;
28+
this.role = role;
29+
this.password = password;
30+
this.last_login = last_login;
31+
this.is_new = is_new;
32+
this.password_confirm = password_confirm;
1833
}
1934
}

UIAssets/src/app/_service/backend.service.ts

+49-12
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,30 @@ export class BackendService {
5252
}
5353

5454
createUser(user: User): Observable<any> {
55-
return this.http.post(this.baseUrl + 'users', user);
55+
let toSave = new User(
56+
user.username,
57+
user.role,
58+
user.password
59+
);
60+
delete toSave.last_login;
61+
delete toSave.is_new;
62+
delete toSave.password_confirm;
63+
return this.http.post(this.baseUrl + 'users', toSave);
5664
}
5765

5866
updateUser(user: User): Observable<any> {
59-
if (user.role === 'Admin') {
60-
user.role = 0;
61-
} else if (user.role === 'User') {
62-
user.role = 1;
63-
} else if (user.role === 'Blacklist') {
64-
user.role = 2;
67+
let toSave = new User(
68+
user.username,
69+
user.role,
70+
user.password
71+
);
72+
delete toSave.is_new;
73+
delete toSave.password_confirm;
74+
delete toSave.last_login;
75+
if (toSave.password == '') {
76+
delete toSave.password;
6577
}
66-
delete user.last_login;
67-
return this.http.patch(this.baseUrl + 'users/' + user.username, user);
78+
return this.http.patch(this.baseUrl + 'users/' + toSave.username, toSave);
6879
}
6980

7081
deleteUser(user: User): Observable<any> {
@@ -110,7 +121,19 @@ export class BackendService {
110121
}
111122

112123
createFabric(fabric: Fabric): Observable<any> {
113-
return this.http.post(this.baseUrl + 'aci/fabrics', fabric);
124+
let toSave = new Fabric(
125+
fabric.apic_cert,
126+
fabric.apic_hostname,
127+
fabric.apic_username,
128+
fabric.apic_password,
129+
fabric.controllers,
130+
fabric.fabric
131+
);
132+
delete toSave.controllers;
133+
delete toSave.validate;
134+
delete toSave.is_new;
135+
delete toSave.password_confirm;
136+
return this.http.post(this.baseUrl + 'aci/fabrics', toSave);
114137
}
115138

116139
getFabrics(): Observable<FabricList> {
@@ -121,8 +144,22 @@ export class BackendService {
121144
}
122145

123146
updateFabric(fabric: Fabric): Observable<any> {
124-
delete fabric.controllers;
125-
return this.http.patch(this.baseUrl + 'aci/fabrics/' + fabric.fabric, fabric);
147+
let toSave = new Fabric(
148+
fabric.apic_cert,
149+
fabric.apic_hostname,
150+
fabric.apic_username,
151+
fabric.apic_password,
152+
fabric.controllers,
153+
fabric.fabric
154+
);
155+
delete toSave.controllers;
156+
delete toSave.validate;
157+
delete toSave.is_new;
158+
delete toSave.password_confirm;
159+
if (toSave.apic_password == '') {
160+
delete toSave.apic_password;
161+
}
162+
return this.http.patch(this.baseUrl + 'aci/fabrics/' + toSave.fabric, toSave);
126163
}
127164

128165
deleteFabric(fabric: Fabric): Observable<any> {

UIAssets/src/app/app.component.ts

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {environment} from '../environments/environment';
77
import {BackendService} from './_service/backend.service';
88
import {Title} from '@angular/platform-browser';
99
import {CookieService} from 'ngx-cookie-service';
10+
import {UserList} from "./_model/user";
1011

1112
@Component({
1213
selector: 'app-root',
@@ -53,6 +54,10 @@ export class AppComponent implements OnInit, OnDestroy {
5354
} else {
5455
this.app_loaded = true;
5556
}
57+
if (environment.login_required) {
58+
this.backendService.getUsers().subscribe((results: UserList) => {
59+
});
60+
}
5661
this.login_required = (localStorage.getItem('isLoggedIn') != 'true' && environment.login_required);
5762
this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe(event => {
5863
this.login_required = (localStorage.getItem('isLoggedIn') != 'true' && environment.login_required);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ <h3>Parameters</h3>
241241
[sortable]="true"
242242
[flexGrow]="0.2">
243243
<ng-template let-row="row" let-value="value" ngx-datatable-cell-template>
244-
<span *ngIf="row['node_id'] === 0 ; spanElse">Global</span>
244+
<span *ngIf="row['node_id'] === 0">Global</span>
245245
<span *ngIf="row['node_id'] !== 0">{{ row['node_id'] | number }}</span>
246246
</ng-template>
247247
</ngx-datatable-column>

UIAssets/src/app/comparison-result-detail/comparison-result-detail.component.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ <h6>
8888
<div *ngIf="type=='modified'" class="row">
8989
<div class="col-md-4">
9090
<div class="row">
91-
<div class="col-md-6">
91+
<div class="col-md-4">
9292
Line diff mode
9393
</div>
94-
<div class="col-md-6">
95-
<label class="switch-icon">
94+
<div class="col-md-8">
95+
<label class="switch">
9696
<input
9797
#diffModeCheckBox
9898
id="diffModeCheckBox"

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -171,27 +171,35 @@ <h6>
171171
</div>
172172
</div>
173173
<div class="col-md-12">
174-
<div class="form-group">
174+
<div class="form-group form-group--inline">
175175
<label class="checkbox">
176176
<input type="checkbox" [(ngModel)]="comparison.dynamic" name="dynamic">
177177
<span class="checkbox__input"></span>
178178
<span class="checkbox__label">Dynamic</span>
179179
</label>
180+
</div>
181+
<div class="form-group form-group--inline">
180182
<label class="checkbox">
181183
<input type="checkbox" [(ngModel)]="comparison.remap" name="remap">
182184
<span class="checkbox__input"></span>
183185
<span class="checkbox__label">Remap</span>
184186
</label>
187+
</div>
188+
<div class="form-group form-group--inline">
185189
<label class="checkbox">
186190
<input type="checkbox" [(ngModel)]="comparison.serialize" name="serialize">
187191
<span class="checkbox__input"></span>
188192
<span class="checkbox__label">Serialize</span>
189193
</label>
194+
</div>
195+
<div class="form-group form-group--inline">
190196
<label class="checkbox">
191197
<input type="checkbox" [(ngModel)]="comparison.statistic" name="statistic">
192198
<span class="checkbox__input"></span>
193199
<span class="checkbox__label">Statistic</span>
194200
</label>
201+
</div>
202+
<div class="form-group form-group--inline">
195203
<label class="checkbox">
196204
<input type="checkbox" [(ngModel)]="comparison.timestamp" name="timestamp">
197205
<span class="checkbox__input"></span>

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

+20-59
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ <h4>
7777
</ngx-datatable-column>
7878
<ngx-datatable-column name="Actions" [flexGrow]="0.1">
7979
<ng-template let-row="row" let-value="value" ngx-datatable-cell-template>
80-
<a class="btn btn--small btn--icon btn--primary" title="Update" (click)='openModal(editTemplate,row)'>
81-
<span data-balloon="Update" data-balloon-pos="left">
80+
<a class="btn btn--small btn--icon btn--primary" title="Edit" (click)='openModal(addtemplate,row)'>
81+
<span data-balloon="Edit" data-balloon-pos="left">
8282
<span class="icon-pencil"></span>
8383
</span>
8484
</a>
@@ -112,14 +112,14 @@ <h4>
112112
<ng-template #addtemplate>
113113
<form #fabricForm="ngForm" (ngSubmit)="onSubmit()">
114114
<div class="modal-body">
115-
<h6>
116-
Add a new fabric
117-
</h6>
115+
<h6 *ngIf="fabric.is_new"> Add a new fabric </h6>
116+
<h6 *ngIf="!fabric.is_new"> Edit fabric </h6>
118117
<div class="row">
119118
<div class="col-md-12">
120119
<div class="form-group">
121120
<div class="form-group__text">
122-
<input id="fabric" type="text" required [(ngModel)]="fabric.fabric" name="name">
121+
<input id="fabric" type="text" [disabled]="!fabric.is_new" [required]="fabric.is_new"
122+
[(ngModel)]="fabric.fabric" name="name">
123123
<label for="fabric">Name</label>
124124
</div>
125125
</div>
@@ -137,65 +137,24 @@ <h6>
137137
</div>
138138
<div class="form-group">
139139
<div class="form-group__text">
140-
<input id="apic_password" type="password" required [(ngModel)]="fabric.apic_password"
140+
<input id="apic_password" type="password" [required]="fabric.is_new" [(ngModel)]="fabric.apic_password"
141141
name="apic_password">
142142
<label for="apic_password">Password</label>
143143
</div>
144144
</div>
145-
</div>
146-
<div class="col-md-12">
147-
&nbsp;
148-
</div>
149-
</div>
150-
</div>
151-
<br>
152-
<div class="modal-footer">
153-
<button type="submit" class="btn btn--small btn--primary" [disabled]="!fabricForm.form.valid">Add</button>
154-
<button type="reset" class="btn btn--small" (click)="hideModal()">Cancel</button>
155-
</div>
156-
</form>
157-
</ng-template>
158-
<ng-template #editTemplate>
159-
<form #editfabricForm="ngForm" (ngSubmit)="updateValue()">
160-
<div class="modal-body">
161-
<h6>
162-
Edit fabric
163-
</h6>
164-
<div class="row">
165-
<div class="col-md-12">
166-
<div class="form-group">
145+
<div class="form-group" [ngClass]="{'form-group--error':fabric.apic_password !== fabric.password_confirm}">
167146
<div class="form-group__text">
168-
<input id="editfabric" type="text" required [ngModel]="fabric.fabric" name="name" readonly>
169-
<label for="editfabric">Name</label>
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>
170150
</div>
171151
</div>
172-
<div class="form-group">
173-
<div class="form-group__text">
174-
<input id="edit_apic_hostname" type="text" required [(ngModel)]="fabric.apic_hostname"
175-
name="apic_hostname">
176-
<label for="edit_apic_hostname">Hostname</label>
177-
</div>
178-
</div>
179-
<div class="form-group">
180-
<div class="form-group__text">
181-
<input id="edit_apic_username" type="text" required [(ngModel)]="fabric.apic_username"
182-
name="apic_username">
183-
<label for="edit_apic_username">Username</label>
184-
</div>
185-
</div>
186-
<div class="form-group">
187-
<div class="form-group__text">
188-
<input id="edit_apic_password" type="password" required [(ngModel)]="fabric.apic_password"
189-
name="apic_password">
190-
<label for="edit_apic_password">Password</label>
191-
</div>
192-
</div>
193-
<div class="form-group">
194-
<div class="form-group__text">
195-
<input id="confirm_apic_password" type="password" required [(ngModel)]="confirmPassword"
196-
name="confirm_apic_password">
197-
<label for="confirm_apic_password">Confirm Password</label>
198-
</div>
152+
<div class="form-group form-group--inline">
153+
<label class="checkbox">
154+
<input type="checkbox" [(ngModel)]="fabric.validate" name="validate">
155+
<span class="checkbox__input"></span>
156+
<span class="checkbox__label">Validate credentials</span>
157+
</label>
199158
</div>
200159
</div>
201160
<div class="col-md-12">
@@ -205,7 +164,9 @@ <h6>
205164
</div>
206165
<br>
207166
<div class="modal-footer">
208-
<button type="submit" class="btn btn--small btn--primary" [disabled]="!editfabricForm.form.valid">Update</button>
167+
<button type="submit" class="btn btn--small btn--primary" [disabled]="!fabricForm.form.valid">
168+
{{ fabric.is_new?'Add':'Save'}}
169+
</button>
209170
<button type="reset" class="btn btn--small" (click)="hideModal()">Cancel</button>
210171
</div>
211172
</form>

0 commit comments

Comments
 (0)