Browse Source

Users state improved

pull/271/head
Sebastian Stehle 9 years ago
parent
commit
071787696d
  1. 34
      src/Squidex/app/features/administration/state/users.state.spec.ts
  2. 12
      src/Squidex/app/features/administration/state/users.state.ts
  3. 4
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts
  4. 20
      src/Squidex/app/features/schemas/state/schemas.state.ts
  5. 4
      src/Squidex/app/framework/angular/forms/confirm-click.directive.ts
  6. 6
      src/Squidex/app/framework/angular/modals/dialog-renderer.component.ts

34
src/Squidex/app/features/administration/state/users.state.spec.ts

@ -29,7 +29,7 @@ describe('UsersState', () => {
const newUser = new UserDto('id3', 'mail3@mail.de', 'name3', false);
let authService: IMock<AuthService>;
let dialogService: IMock<DialogService>;
let dialogs: IMock<DialogService>;
let usersService: IMock<UsersService>;
let usersState: UsersState;
@ -39,28 +39,44 @@ describe('UsersState', () => {
authService.setup(x => x.user)
.returns(() => <any>{ id: 'id2' });
dialogService = Mock.ofType<DialogService>();
dialogs = Mock.ofType<DialogService>();
usersService = Mock.ofType<UsersService>();
usersService.setup(x => x.getUsers(10, 0, undefined))
.returns(() => Observable.of(new UsersDto(200, oldUsers)));
usersState = new UsersState(authService.object, dialogService.object, usersService.object);
usersState = new UsersState(authService.object, dialogs.object, usersService.object);
usersState.loadUsers().subscribe();
});
it('should load apps', () => {
it('should load users', () => {
expect(usersState.snapshot.users.values).toEqual(oldUsers);
expect(usersState.snapshot.usersPager.numberOfItems).toEqual(200);
usersService.verifyAll();
});
it('should replace selected user when reloading', () => {
usersState.selectUser('id1').subscribe();
const newUsers = [
new UserDto('id1', 'mail1@mail.de_new', 'name1_new', false),
new UserDto('id2', 'mail2@mail.de_new', 'name2_new', true)
];
usersService.setup(x => x.getUsers(10, 0, undefined))
.returns(() => Observable.of(new UsersDto(200, newUsers)));
usersState.loadUsers().subscribe();
expect(usersState.snapshot.selectedUser).toBe(newUsers[0]);
});
it('should raise notification on load when notify is true', () => {
usersState.loadUsers(true).subscribe();
dialogService.verify(x => x.notifyInfo(It.isAnyString()), Times.once());
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());
});
it('should not load user when already loaded', () => {
@ -140,7 +156,7 @@ describe('UsersState', () => {
usersState.lockUser(oldUsers[0]).onErrorResumeNext().subscribe();
dialogService.verify(x => x.notifyError(It.isAny()), Times.once());
dialogs.verify(x => x.notifyError(It.isAny()), Times.once());
});
it('should unmark user as locked', () => {
@ -160,7 +176,7 @@ describe('UsersState', () => {
usersState.unlockUser(oldUsers[1]).onErrorResumeNext().subscribe();
dialogService.verify(x => x.notifyError(It.isAny()), Times.once());
dialogs.verify(x => x.notifyError(It.isAny()), Times.once());
});
it('should update user on update', () => {
@ -185,7 +201,7 @@ describe('UsersState', () => {
usersState.updateUser(oldUsers[0], request).onErrorResumeNext().subscribe();
dialogService.verify(x => x.notifyError(It.isAny()), Times.never());
dialogs.verify(x => x.notifyError(It.isAny()), Times.never());
});
it('should add user to state when created', () => {
@ -208,7 +224,7 @@ describe('UsersState', () => {
usersState.createUser(request).onErrorResumeNext().subscribe();
dialogService.verify(x => x.notifyError(It.isAny()), Times.never());
dialogs.verify(x => x.notifyError(It.isAny()), Times.never());
});
it('should load next page and prev page when paging', () => {

12
src/Squidex/app/features/administration/state/users.state.ts

@ -140,7 +140,17 @@ export class UsersState extends State<Snapshot> {
const users = ImmutableArray.of(dtos.items);
const usersPager = s.usersPager.setCount(dtos.total);
return { ...s, users, usersPager, usersLoading: false };
let selectedUser = s.selectedUser;
if (selectedUser) {
const selectedFromResult = dtos.items.find(x => x.id === selectedUser!.id);
if (selectedFromResult) {
selectedUser = selectedFromResult;
}
}
return { ...s, users, usersPager, selectedUser, usersLoading: false };
});
})
.notify(this.dialogs);

4
src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts

@ -47,9 +47,9 @@ export class SchemasPageComponent implements OnDestroy, OnInit {
constructor(
public readonly appsState: AppsState,
private readonly schemasState: SchemasState,
private readonly messageBus: MessageBus,
private readonly route: ActivatedRoute,
private readonly messageBus: MessageBus
private readonly schemasState: SchemasState
) {
}

20
src/Squidex/app/features/schemas/state/schemas.state.ts

@ -144,14 +144,6 @@ interface Snapshot {
@Injectable()
export class SchemasState extends State<Snapshot> {
private get appName() {
return this.appsState.appName;
}
private get user() {
return this.authState.user!.token;
}
public selectedSchema =
this.changes.map(s => s.selectedSchema)
.distinctUntilChanged();
@ -160,6 +152,10 @@ export class SchemasState extends State<Snapshot> {
this.changes.map(s => s.schemas)
.distinctUntilChanged();
public get schemaName() {
return this.snapshot.selectedSchema!.name;
}
constructor(
private readonly appsState: AppsState,
private readonly authState: AuthService,
@ -339,6 +335,14 @@ export class SchemasState extends State<Snapshot> {
return { ...s, schemas, selectedSchema };
});
}
private get appName() {
return this.appsState.appName;
}
private get user() {
return this.authState.user!.token;
}
}
const setPublished = (schema: SchemaDto | SchemaDetailsDto, publish: boolean, user: string, version: Version, now?: DateTime) => {

4
src/Squidex/app/framework/angular/forms/confirm-click.directive.ts

@ -50,7 +50,7 @@ export class ConfirmClickDirective implements OnDestroy {
public clickConfirmed = new DelayEventEmitter();
constructor(
private readonly dialogService: DialogService
private readonly dialogs: DialogService
) {
}
@ -72,7 +72,7 @@ export class ConfirmClickDirective implements OnDestroy {
this.isOpen = true;
let subscription =
this.dialogService.confirm(this.confirmTitle, this.confirmText)
this.dialogs.confirm(this.confirmTitle, this.confirmText)
.subscribe(result => {
this.isOpen = false;

6
src/Squidex/app/framework/angular/modals/dialog-renderer.component.ts

@ -38,7 +38,7 @@ export class DialogRendererComponent implements OnDestroy, OnInit {
public position = 'bottomright';
constructor(
private readonly dialogService: DialogService
private readonly dialogs: DialogService
) {
}
@ -57,7 +57,7 @@ export class DialogRendererComponent implements OnDestroy, OnInit {
});
this.notificationsSubscription =
this.dialogService.notifications.subscribe(notification => {
this.dialogs.notifications.subscribe(notification => {
this.notifications.push(notification);
if (notification.displayTime > 0) {
@ -68,7 +68,7 @@ export class DialogRendererComponent implements OnDestroy, OnInit {
});
this.dialogsSubscription =
this.dialogService.dialogs
this.dialogs.dialogs
.subscribe(request => {
this.cancel();

Loading…
Cancel
Save