Browse Source

Minor bugfixes.

pull/65/merge
Sebastian Stehle 9 years ago
parent
commit
ffa844fbb8
  1. 19
      src/Squidex.Domain.Users/UserManagerExtensions.cs
  2. 2
      src/Squidex/app/features/apps/pages/apps-page.component.ts
  3. 4
      src/Squidex/app/framework/angular/focus-on-change.directive.spec.ts
  4. 4
      src/Squidex/app/framework/angular/focus-on-init.directive.spec.ts
  5. 2
      src/Squidex/app/framework/angular/root-view.directive.spec.ts
  6. 2
      src/Squidex/app/shared/components/app.component-base.ts
  7. 2
      src/Squidex/app/shared/guards/resolve-app-languages.guard.ts
  8. 2
      src/Squidex/app/shared/guards/resolve-content.guard.ts
  9. 2
      src/Squidex/app/shared/guards/resolve-published-schema.guard.ts
  10. 2
      src/Squidex/app/shared/guards/resolve-schema.guard.ts
  11. 2
      src/Squidex/app/shared/guards/resolve-user.guard.ts
  12. 30
      src/Squidex/app/shared/services/apps-store.service.spec.ts
  13. 75
      src/Squidex/app/shared/services/apps-store.service.ts
  14. 7
      src/Squidex/app/shared/services/auth.service.ts
  15. 4
      src/Squidex/app/shell/pages/internal/apps-menu.component.html
  16. 2
      src/Squidex/app/shell/pages/internal/apps-menu.component.ts
  17. 2
      src/Squidex/app/shell/pages/internal/profile-menu.component.ts

19
src/Squidex.Domain.Users/UserManagerExtensions.cs

@ -54,14 +54,23 @@ namespace Squidex.Domain.Users
{
var user = factory.Create(email);
user.UpdateDisplayName(displayName);
user.SetPictureUrlFromGravatar(email);
try
{
user.UpdateDisplayName(displayName);
user.SetPictureUrlFromGravatar(email);
await DoChecked(() => userManager.CreateAsync(user), "Cannot create user.");
await DoChecked(() => userManager.CreateAsync(user), "Cannot create user.");
if (!string.IsNullOrWhiteSpace(password))
if (!string.IsNullOrWhiteSpace(password))
{
await DoChecked(() => userManager.AddPasswordAsync(user, password), "Cannot create user.");
}
}
catch
{
await DoChecked(() => userManager.AddPasswordAsync(user, password), "Cannot create user.");
await userManager.DeleteAsync(user);
throw;
}
return user;

2
src/Squidex/app/features/apps/pages/apps-page.component.ts

@ -24,7 +24,7 @@ import {
export class AppsPageComponent implements OnInit {
public addAppDialog = new ModalView();
public apps = this.appsStore.apps.map(a => a || []);
public apps = this.appsStore.apps;
constructor(
private readonly appsStore: AppsStoreService

4
src/Squidex/app/framework/angular/focus-on-change.directive.spec.ts

@ -23,8 +23,8 @@ describe('FocusOnChangeDirective', () => {
const calledElements: any[] = [];
const renderer = {
invokeElementMethod: (element: any, method: any, args: any) => {
calledElements.push(element);
invokeElementMethod: (elem: any, method: any, args: any) => {
calledElements.push(elem);
calledMethods.push(method);
}
};

4
src/Squidex/app/framework/angular/focus-on-init.directive.spec.ts

@ -23,8 +23,8 @@ describe('FocusOnInitDirective', () => {
const calledElements: any[] = [];
const renderer = {
invokeElementMethod: (element: any, method: any, args: any) => {
calledElements.push(element);
invokeElementMethod: (elem: any, method: any, args: any) => {
calledElements.push(elem);
calledMethods.push(method);
}
};

2
src/Squidex/app/framework/angular/root-view.directive.spec.ts

@ -7,6 +7,8 @@
import { RootViewDirective } from './../';
/* tslint:disable:no-unused-expression */
describe('RootViewDirective', () => {
it('should call init of service in ctor', () => {
let viewRef = {};

2
src/Squidex/app/shared/components/app.component-base.ts

@ -27,7 +27,7 @@ export abstract class AppComponentBase extends ComponentBase {
}
public appNameOnce(): Observable<string> {
return this.appName$.take(1);
return this.appName$.first();
}
}

2
src/Squidex/app/shared/guards/resolve-app-languages.guard.ts

@ -39,7 +39,7 @@ export class ResolveAppLanguagesGuard implements Resolve<AppLanguageDto[]> {
}
return dto;
}).catch(() => {
}, error => {
this.router.navigate(['/404']);
return null;

2
src/Squidex/app/shared/guards/resolve-content.guard.ts

@ -51,7 +51,7 @@ export class ResolveContentGuard implements Resolve<ContentDto> {
}
return dto;
}).catch(() => {
}, error => {
this.router.navigate(['/404']);
return null;

2
src/Squidex/app/shared/guards/resolve-published-schema.guard.ts

@ -45,7 +45,7 @@ export class ResolvePublishedSchemaGuard implements Resolve<SchemaDetailsDto> {
}
return dto;
}).catch(() => {
}, error => {
this.router.navigate(['/404']);
return null;

2
src/Squidex/app/shared/guards/resolve-schema.guard.ts

@ -45,7 +45,7 @@ export class ResolveSchemaGuard implements Resolve<SchemaDetailsDto> {
}
return dto;
}).catch(() => {
}, error => {
this.router.navigate(['/404']);
return null;

2
src/Squidex/app/shared/guards/resolve-user.guard.ts

@ -39,7 +39,7 @@ export class ResolveUserGuard implements Resolve<UserDto> {
}
return dto;
}).catch(() => {
}, error => {
this.router.navigate(['/404']);
return null;

30
src/Squidex/app/shared/services/apps-store.service.spec.ts

@ -59,36 +59,6 @@ describe('AppsStoreService', () => {
appsService.verifyAll();
});
it('should reload value from apps-service when called', () => {
authService.setup(x => x.isAuthenticated)
.returns(() => Observable.of(true))
.verifiable(Times.once());
appsService.setup(x => x.getApps())
.returns(() => Observable.of(oldApps))
.verifiable(Times.exactly(2));
const store = new AppsStoreService(authService.object, appsService.object);
let result1: AppDto[] | null = null;
let result2: AppDto[] | null = null;
store.apps.subscribe(x => {
result1 = x;
}).unsubscribe();
store.reload();
store.apps.subscribe(x => {
result2 = x;
}).unsubscribe();
expect(result1).toEqual(oldApps);
expect(result2).toEqual(oldApps);
appsService.verifyAll();
});
it('should add app to cache when created', () => {
authService.setup(x => x.isAuthenticated)
.returns(() => Observable.of(true))

75
src/Squidex/app/shared/services/apps-store.service.ts

@ -6,7 +6,7 @@
*/
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable, Subject } from 'rxjs';
import { BehaviorSubject, Observable, Observer, ReplaySubject } from 'rxjs';
import { DateTime } from 'framework';
@ -20,70 +20,45 @@ import { AuthService } from './auth.service';
@Injectable()
export class AppsStoreService {
private readonly apps$ = new Subject<AppDto[]>();
private readonly appName$ = new BehaviorSubject<string | null>(null);
private lastApps: AppDto[] | null = null;
private isAuthenticated = false;
private readonly appsPublished$ =
this.apps$
.distinctUntilChanged()
.publishReplay(1);
private readonly selectedApp$ =
this.appsPublished$.combineLatest(this.appName$, (apps, name) => apps && name ? apps.find(x => x.name === name) || null : null)
.distinctUntilChanged()
.publishReplay(1);
private readonly apps$ = new ReplaySubject<AppDto[]>();
private readonly app$ = new BehaviorSubject<AppDto | null>(null);
public get apps(): Observable<AppDto[]> {
return this.appsPublished$;
return this.apps$;
}
public get selectedApp(): Observable<AppDto | null> {
return this.selectedApp$;
return this.app$;
}
constructor(
private readonly authService: AuthService,
private readonly appsService: AppsService
) {
if (!authService || !appsService) {
if (!appsService) {
return;
}
this.selectedApp$.connect();
this.appsPublished$.connect();
this.appsPublished$.subscribe(apps => {
this.lastApps = apps;
});
this.authService.isAuthenticated.subscribe(isAuthenticated => {
this.isAuthenticated = isAuthenticated;
if (isAuthenticated) {
this.load();
}
});
}
public reload() {
if (this.isAuthenticated) {
this.load();
}
}
private load() {
this.appsService.getApps()
this.authService.isAuthenticated.filter(t => !!t).first()
.switchMap(() => this.appsService.getApps())
.subscribe(apps => {
this.apps$.next(apps);
});
}
public selectApp(name: string | null): Promise<boolean> {
this.appName$.next(name);
return Observable.create((observer: Observer<boolean>) => {
this.apps$.subscribe(apps => {
const app = apps.find(x => x.name === name) || null;
return this.selectedApp.skip(1).map(app => app !== null).toPromise();
this.app$.next(app);
observer.next(app !== null);
observer.complete();
}, error => {
observer.error(error);
});
}).toPromise();
}
public createApp(dto: CreateAppDto, now?: DateTime): Observable<AppDto> {
@ -91,14 +66,14 @@ export class AppsStoreService {
.map(created => {
now = now || DateTime.now();
const app = new AppDto(created.id, dto.name, 'Owner', now, now);
return app;
return new AppDto(created.id, dto.name, 'Owner', now, now);
})
.do(app => {
if (this.lastApps && app) {
this.apps$.next(this.lastApps.concat([app]));
}
this.apps$.defaultIfEmpty().first().subscribe(apps => {
if (apps) {
this.apps$.next(apps.concat([app]));
}
});
});
}
}

7
src/Squidex/app/shared/services/auth.service.ts

@ -107,11 +107,10 @@ export class AuthService {
public checkLogin(): Promise<boolean> {
if (this.loginCompleted) {
return Promise.resolve(this.currentUser !== null);
} else if (this.loginCache) {
return this.loginCache;
} else {
this.loginCache = this.checkState(this.userManager.signinSilent());
if (!this.loginCache) {
this.loginCache = this.checkState(this.userManager.signinSilent());
}
return this.loginCache;
}
}

4
src/Squidex/app/shell/pages/internal/apps-menu.component.html

@ -5,12 +5,12 @@
<div class="dropdown-menu" *sqxModalView="modalMenu" closeAlways="true" [@fade]>
<a class="dropdown-item all-apps" routerLink="/app">
<span class="all-apps-text">All Apps</span>
<span class="all-apps-pill tag tag-pill tag-default">{{apps.length || 0}}</span>
<span class="all-apps-pill tag tag-pill tag-default">{{apps.length}}</span>
</a>
<div class="dropdown-divider"></div>
<div *ngIf="apps && apps.length > 0">
<div *ngIf="apps.length > 0">
<a class="dropdown-item" *ngFor="let app of apps" [routerLink]="['/app', app.name]" routerLinkActive="active">{{app.name}}</a>
<div class="dropdown-divider"></div>

2
src/Squidex/app/shell/pages/internal/apps-menu.component.ts

@ -49,7 +49,7 @@ export class AppsMenuComponent implements OnInit, OnDestroy {
public ngOnInit() {
this.appsSubscription =
this.appsStore.apps.subscribe(apps => {
this.apps = apps || [];
this.apps = apps;
});
this.appSubscription =

2
src/Squidex/app/shell/pages/internal/profile-menu.component.ts

@ -47,7 +47,7 @@ export class ProfileMenuComponent implements OnInit, OnDestroy {
public ngOnInit() {
this.authenticationSubscription =
this.authService.isAuthenticated.take(1)
this.authService.isAuthenticated.first()
.subscribe(() => {
const user = this.authService.user;

Loading…
Cancel
Save