Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

110 lines
2.9 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import {
AuthService,
ComponentBase,
ImmutableArray,
NotificationService,
Pager,
UserDto,
UserManagementService
} from 'shared';
@Component({
selector: 'sqx-users-page',
styleUrls: ['./users-page.component.scss'],
templateUrl: './users-page.component.html'
})
export class UsersPageComponent extends ComponentBase implements OnInit {
public currentUserId: string;
public usersItems = ImmutableArray.empty<UserDto>();
public usersPager = new Pager(0);
public usersFilter = new FormControl();
public usersQuery = '';
constructor(notifications: NotificationService,
private readonly userManagementService: UserManagementService,
private readonly authService: AuthService
) {
super(notifications);
}
public ngOnInit() {
this.currentUserId = this.authService.user!.id;
this.load();
}
public search() {
this.usersPager = new Pager(0);
this.usersQuery = this.usersFilter.value;
this.load();
}
private load(showInfo = false) {
this.userManagementService.getUsers(this.usersPager.pageSize, this.usersPager.skip, this.usersQuery)
.subscribe(dtos => {
this.usersItems = ImmutableArray.of(dtos.items);
this.usersPager = this.usersPager.setCount(dtos.total);
if (showInfo) {
this.notifyInfo('Users reloaded.');
}
}, error => {
this.notifyError(error);
});
}
public lock(id: string) {
this.userManagementService.lockUser(id)
.subscribe(() => {
this.usersItems = this.usersItems.map(u => {
if (u.id === id) {
return new UserDto(u.id, u.email, u.displayName, u.pictureUrl, true);
} else {
return u;
}
});
}, error => {
this.notifyError(error);
});
}
public unlock(id: string) {
this.userManagementService.unlockUser(id)
.subscribe(() => {
this.usersItems = this.usersItems.map(u => {
if (u.id === id) {
return new UserDto(u.id, u.email, u.displayName, u.pictureUrl, false);
} else {
return u;
}
});
}, error => {
this.notifyError(error);
});
}
public goNext() {
this.usersPager = this.usersPager.goNext();
this.load();
}
public goPrev() {
this.usersPager = this.usersPager.goPrev();
this.load();
}
}