deprecate profile resolver (#686)

* resolve profile at startup

* remove profile resolver, load profile on app ready

* dispose subscriptions
This commit is contained in:
Denys Vuika
2018-10-03 19:43:01 +01:00
committed by GitHub
parent cead6c3ebc
commit ba967d0e25
6 changed files with 31 additions and 121 deletions

View File

@@ -31,7 +31,7 @@ import {
PageTitleService,
UploadService
} from '@alfresco/adf-core';
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { AppExtensionService } from './extensions/extension.service';
@@ -40,24 +40,28 @@ import {
SetCurrentUrlAction,
SetInitialStateAction,
CloseModalDialogsAction,
SetRepositoryStatusAction
SetRepositoryStatusAction,
SetUserProfileAction
} from './store/actions';
import {
AppStore,
AppState,
INITIAL_APP_STATE
} from './store/states/app.state';
import { filter } from 'rxjs/operators';
import { filter, takeUntil } from 'rxjs/operators';
import { ContentApiService } from './services/content-api.service';
import { DiscoveryEntry } from 'alfresco-js-api';
import { AppService } from './services/app.service';
import { Subject } from 'rxjs';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
export class AppComponent implements OnInit, OnDestroy {
onDestroy$: Subject<boolean> = new Subject<boolean>();
constructor(
private route: ActivatedRoute,
private router: Router,
@@ -83,11 +87,6 @@ export class AppComponent implements OnInit {
this.store.dispatch(new CloseModalDialogsAction());
this.router.navigate(['/login']);
this.appService.waitForAuth().subscribe(() => {
this.loadRepositoryStatus();
// todo: load external auth-enabled plugins here
});
}
}
});
@@ -119,12 +118,18 @@ export class AppComponent implements OnInit {
this.onFileUploadedError(error)
);
this.appService.waitForAuth().subscribe(() => {
this.appService.ready$.pipe(takeUntil(this.onDestroy$)).subscribe(() => {
this.loadRepositoryStatus();
this.loadUserProfile();
// todo: load external auth-enabled plugins here
});
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
private loadRepositoryStatus() {
this.contentApi
.getRepositoryInformation()
@@ -135,6 +140,12 @@ export class AppComponent implements OnInit {
});
}
private loadUserProfile() {
this.contentApi.getPerson('-me-').subscribe(person => {
this.store.dispatch(new SetUserProfileAction(person.entry));
});
}
private loadAppSettings() {
const baseShareUrl =
this.config.get<string>('baseShareUrl') ||

View File

@@ -29,7 +29,6 @@ import { FilesComponent } from './components/files/files.component';
import { LibrariesComponent } from './components/libraries/libraries.component';
import { GenericErrorComponent } from './components/common/generic-error/generic-error.component';
import { SearchResultsComponent } from './components/search/search-results/search-results.component';
import { ProfileResolver } from './services/profile.resolver';
import { LoginComponent } from './components/login/login.component';
import { AppAuthGuard } from './guards/auth.guard';
import { AppSharedRuleGuard } from './guards/shared.guard';
@@ -55,9 +54,6 @@ export const APP_ROUTES: Routes = [
{
path: '',
component: LayoutComponent,
resolve: {
profile: ProfileResolver
},
children: [
{
path: '',

View File

@@ -29,7 +29,6 @@ import { Route } from '@angular/router';
import { AppStore, RepositoryState } from '../store/states';
import { ruleContext } from '../store/selectors/app.selectors';
import { NodePermissionService } from '../services/node-permission.service';
import { ProfileResolver } from '../services/profile.resolver';
import {
SelectionState,
NavigationState,
@@ -224,7 +223,6 @@ export class AppExtensionService implements RuleContext {
component: this.getComponentById(route.layout || this.defaults.layout),
canActivateChild: guards,
canActivate: guards,
resolve: { profile: ProfileResolver },
children: [
{
path: '',

View File

@@ -25,21 +25,21 @@
import { Injectable } from '@angular/core';
import { AuthenticationService } from '@alfresco/adf-core';
import { Observable, of } from 'rxjs';
import { take } from 'rxjs/operators';
import { Observable, BehaviorSubject } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class AppService {
constructor(private auth: AuthenticationService) {}
private ready: BehaviorSubject<boolean>;
ready$: Observable<boolean>;
waitForAuth(): Observable<any> {
const isLoggedIn = this.auth.isLoggedIn();
if (isLoggedIn) {
return of(true);
} else {
return this.auth.onLogin.pipe(take(1));
}
constructor(auth: AuthenticationService) {
this.ready = new BehaviorSubject(auth.isLoggedIn());
this.ready$ = this.ready.asObservable();
auth.onLogin.subscribe(e => {
this.ready.next(true);
});
}
}

View File

@@ -1,32 +0,0 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2018 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { ProfileResolver } from './profile.resolver';
describe('ProfileResolver', () => {
it('should be defined', () => {
expect(ProfileResolver).toBeDefined();
});
});

View File

@@ -1,63 +0,0 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2018 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { Store } from '@ngrx/store';
import { Injectable } from '@angular/core';
import { Resolve, Router } from '@angular/router';
import { Person } from 'alfresco-js-api';
import { Observable } from 'rxjs';
import { AppStore } from '../store/states/app.state';
import { SetUserProfileAction } from '../store/actions';
import { ContentApiService } from './content-api.service';
@Injectable({
providedIn: 'root'
})
export class ProfileResolver implements Resolve<Person> {
constructor(
private store: Store<AppStore>,
private contentApi: ContentApiService,
private router: Router
) {}
resolve(): Observable<Person> {
return new Observable(observer => {
this.contentApi.getPerson('-me-').subscribe(
person => {
this.store.dispatch(new SetUserProfileAction(person.entry));
observer.next(person.entry);
observer.complete();
},
err => {
if (err && err.status === 401) {
observer.next(null);
observer.complete();
this.router.navigate(['login']);
}
}
);
});
}
}