template fixes

This commit is contained in:
VLE2FE
2020-08-27 13:56:55 +02:00
parent 6f95ff4148
commit 04c2ff2678
7 changed files with 60 additions and 16 deletions

View File

@ -56,7 +56,6 @@
<th>Device</th>
<th>Models</th>
<th></th>
<th></th>
</tr>
<tr *ngFor="let user of users">
@ -71,8 +70,7 @@
{{(i > 0 ? ', ' : '') + modelIds[model]}}
</ng-container>
</td>
<td><span [class]="'rb-ic clickable ' + (user.status === 'new' ? 'rb-ic-edit': 'rb-ic-undo')"
(click)="user.status === 'new' ? user.edit = true: restoreUser(user)"></span></td>
<td><span class="rb-ic clickable rb-ic-edit" (click)="user.edit = true"></span></td>
</ng-container>
<ng-template #editUser>
<td>
@ -134,6 +132,37 @@
</tr>
</rb-table>
<rb-accordion>
<rb-accordion-title [open]="false"><span class="rb-ic rb-ic-delete"></span>&nbsp; Deleted users</rb-accordion-title>
<rb-accordion-body>
<rb-table scrollTop>
<tr>
<th>Name</th>
<th>Email</th>
<th>Level</th>
<th>Location</th>
<th>Device</th>
<th>Models</th>
<th></th>
</tr>
<tr *ngFor="let user of deletedUsers">
<td>{{user.name}}</td>
<td>{{user.email}}</td>
<td>{{user.level}}</td>
<td>{{user.location}}</td>
<td>{{user.devices}}</td>
<td>
<ng-container *ngFor="let model of user.models; index as i">
{{(i > 0 ? ', ' : '') + modelIds[model]}}
</ng-container>
</td>
<td><span class="rb-ic clickable rb-ic-undo" (click)="restoreUser(user)"></span></td>
</tr>
</rb-table>
</rb-accordion-body>
</rb-accordion>
<ng-template #modelOptions>
<option value=""></option>
<ng-container *ngFor="let model of modelSelect">

View File

@ -14,6 +14,7 @@ import {DataService} from '../services/data.service';
export class UsersComponent implements OnInit {
users: UserModel[] = [];
deletedUsers: UserModel[] = [];
newUser: UserModel | null = null;
newUserPass = '';
modelSelect: {id: string, name: string}[] = [];
@ -28,7 +29,8 @@ export class UsersComponent implements OnInit {
ngOnInit(): void {
this.api.get<UserModel[]>('/users', data => {
this.users = data.map(e => new UserModel().deserialize(e));
this.users = data.map(e => new UserModel().deserialize(e)).filter(e => e.status !== 'deleted');
this.deletedUsers = data.map(e => new UserModel().deserialize(e)).filter(e => e.status === 'deleted');
});
this.d.load('modelGroups', () => {
this.d.arr.modelGroups.forEach(group => {
@ -63,6 +65,8 @@ export class UsersComponent implements OnInit {
this.api.delete('/user/' + user.name, () => {
user.status = 'deleted';
user.edit = false;
this.deletedUsers.push(user);
this.users.splice(this.users.findIndex(e => e.name === user.name), 1);
});
}
});
@ -71,6 +75,8 @@ export class UsersComponent implements OnInit {
restoreUser(user) {
this.api.put('/user/restore/' + user.name, {}, () => {
user.status = 'new';
this.users.push(user);
this.deletedUsers.splice(this.deletedUsers.findIndex(e => e.name === user.name), 1);
});
}
}