diff --git a/web/src/app/administration/classification/details/classification-details.component.html b/web/src/app/administration/classification/details/classification-details.component.html
index 2d735b9b0..1bd29c2af 100644
--- a/web/src/app/administration/classification/details/classification-details.component.html
+++ b/web/src/app/administration/classification/details/classification-details.component.html
@@ -26,9 +26,9 @@
\ No newline at end of file
diff --git a/web/src/app/app-routing.module.ts b/web/src/app/app-routing.module.ts
index 39683b68c..3ca49d81c 100644
--- a/web/src/app/app-routing.module.ts
+++ b/web/src/app/app-routing.module.ts
@@ -9,12 +9,13 @@ import { NoAccessComponent } from './administration/workbasket/details/noAccess/
import { ClassificationListComponent } from './administration/classification/master/list/classification-list.component';
import { ClassificationDetailsComponent } from 'app/administration/classification/details/classification-details.component';
import { EnvironmentUrlGuard } from 'app/guards/environment-url-guard';
+import { DomainGuard } from 'app/guards/domain-guard';
const appRoutes: Routes = [
{
path: 'administration/workbaskets',
component: MasterAndDetailComponent,
- canActivate: [EnvironmentUrlGuard],
+ canActivate: [EnvironmentUrlGuard, DomainGuard],
children: [
{
path: '',
@@ -41,7 +42,7 @@ const appRoutes: Routes = [
{
path: 'administration/classifications',
component: MasterAndDetailComponent,
- canActivate: [EnvironmentUrlGuard],
+ canActivate: [EnvironmentUrlGuard, DomainGuard],
children: [
{
path: '',
diff --git a/web/src/app/app.module.ts b/web/src/app/app.module.ts
index e913c5b9b..4fd2d8a3f 100644
--- a/web/src/app/app.module.ts
+++ b/web/src/app/app.module.ts
@@ -73,6 +73,7 @@ import { DomainService } from './services/domain/domain.service';
* Guards
*/
import { EnvironmentUrlGuard } from './guards/environment-url-guard';
+import { DomainGuard } from './guards/domain-guard';
const MODULES = [
BrowserModule,
@@ -142,7 +143,8 @@ const DECLARATIONS = [
TreeService,
ClassificationTypesService,
ClassificationCategoriesService,
- EnvironmentUrlGuard
+ EnvironmentUrlGuard,
+ DomainGuard
],
bootstrap: [AppComponent]
})
diff --git a/web/src/app/guards/domain-guard.ts b/web/src/app/guards/domain-guard.ts
new file mode 100644
index 000000000..5ddf40c11
--- /dev/null
+++ b/web/src/app/guards/domain-guard.ts
@@ -0,0 +1,22 @@
+import { Observable } from 'rxjs/Observable';
+import { HttpClient } from '@angular/common/http';
+import { CanActivate } from '@angular/router';
+import { Injectable } from '@angular/core';
+import { DomainService } from 'app/services/domain/domain.service';
+import { ErrorModalService } from 'app/services/errorModal/error-modal.service';
+import { ErrorModel } from 'app/models/modal-error';
+
+@Injectable()
+export class DomainGuard implements CanActivate {
+ constructor(private domainService: DomainService, private errorModalService: ErrorModalService) { }
+
+ canActivate() {
+ return this.domainService.getDomains().map(domain => {
+ return true;
+ }).catch(() => {
+ this.errorModalService.triggerError(new ErrorModel(
+ 'There was an error, please contact with your administrator', 'There was an error getting Domains'))
+ return Observable.of(false)
+ });
+ }
+}
diff --git a/web/src/app/services/classification-categories-service/classification-categories.service.ts b/web/src/app/services/classification-categories-service/classification-categories.service.ts
index 47e7d79f0..ce3e40c6e 100644
--- a/web/src/app/services/classification-categories-service/classification-categories.service.ts
+++ b/web/src/app/services/classification-categories-service/classification-categories.service.ts
@@ -3,7 +3,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'environments/environment';
import { Observable } from 'rxjs/Observable';
-
+import { ReplaySubject } from 'rxjs/ReplaySubject';
@Injectable()
export class ClassificationCategoriesService {
@@ -14,10 +14,21 @@ export class ClassificationCategoriesService {
'Authorization': 'Basic VEVBTUxFQURfMTpURUFNTEVBRF8x'
})
};
+ private dataObs$ = new ReplaySubject
>(1);
constructor(private httpClient: HttpClient) { }
- getCategories(): Observable> {
- return this.httpClient.get>(this.url, this.httpOptions);
+ getCategories(forceRefresh = false): Observable> {
+ if (!this.dataObs$.observers.length || forceRefresh) {
+ this.httpClient.get>(this.url, this.httpOptions).subscribe(
+ data => this.dataObs$.next(data),
+ error => {
+ this.dataObs$.error(error);
+ this.dataObs$ = new ReplaySubject(1);
+ }
+ );
+ }
+
+ return this.dataObs$;
};
}
diff --git a/web/src/app/services/classification-types/classification-types.service.ts b/web/src/app/services/classification-types/classification-types.service.ts
index 2e67197eb..8b4b8beb7 100644
--- a/web/src/app/services/classification-types/classification-types.service.ts
+++ b/web/src/app/services/classification-types/classification-types.service.ts
@@ -4,6 +4,7 @@ import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { environment } from 'environments/environment';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
+import { ReplaySubject } from 'rxjs/ReplaySubject';
@Injectable()
export class ClassificationTypesService {
@@ -16,11 +17,23 @@ export class ClassificationTypesService {
};
private classificationTypeSelectedValue = 'TASK';
private classificationTypeSelected = new BehaviorSubject(this.classificationTypeSelectedValue);
+ private dataObs$ = new ReplaySubject>(1);
constructor(private httpClient: HttpClient) { }
- getClassificationTypes(): Observable> {
- return this.httpClient.get>(this.url, this.httpOptions);
+ getClassificationTypes(forceRefresh = false): Observable> {
+
+ if (!this.dataObs$.observers.length || forceRefresh) {
+ this.httpClient.get>(this.url, this.httpOptions).subscribe(
+ data => this.dataObs$.next(data),
+ error => {
+ this.dataObs$.error(error);
+ this.dataObs$ = new ReplaySubject(1);
+ }
+ );
+ }
+
+ return this.dataObs$;
};
selectClassificationType(id: string) {
diff --git a/web/src/app/services/classifications/classifications.service.ts b/web/src/app/services/classifications/classifications.service.ts
index 876ba33b2..051db18e7 100644
--- a/web/src/app/services/classifications/classifications.service.ts
+++ b/web/src/app/services/classifications/classifications.service.ts
@@ -29,7 +29,6 @@ export class ClassificationsService {
})
};
- private classificationRef: Observable;
private classificationTypes: Array;
constructor(
@@ -42,14 +41,9 @@ export class ClassificationsService {
getClassifications(forceRequest = false): Observable {
return this.domainService.getSelectedDomain().mergeMap(domain => {
const classificationTypes = this.classificationTypeService.getSelectedClassificationType();
- if (!forceRequest && this.classificationRef) {
- return this.getClassificationObservable(this.classificationRef)
- }
- this.classificationRef = this.httpClient.get(
+ return this.getClassificationObservable(this.httpClient.get(
`${environment.taskanaRestUrl}/v1/classifications/?domain=${domain}`,
- this.httpOptions)
-
- return this.getClassificationObservable(this.classificationRef);
+ this.httpOptions));
}).do(() => {
this.domainService.domainChangedComplete();
diff --git a/web/src/app/services/domain/domain.service.mock.ts b/web/src/app/services/domain/domain.service.mock.ts
index c8fdb899d..d0752bc57 100644
--- a/web/src/app/services/domain/domain.service.mock.ts
+++ b/web/src/app/services/domain/domain.service.mock.ts
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
+import { Subject } from 'rxjs/Subject';
@Injectable()
export class DomainServiceMock {
@@ -8,6 +9,7 @@ export class DomainServiceMock {
private domainSelectedValue;
private domainSelected = new BehaviorSubject('DOMAIN_A');
+ private domainSwitched = new Subject();
constructor() {
}
@@ -32,6 +34,12 @@ export class DomainServiceMock {
getSelectedDomainValue() {
}
+ getSwitchedDomain(): Observable {
+ return this.domainSwitched.asObservable();
+ }
-
+ switchDomain(value: string) {
+ this.selectDomain(value)
+ this.domainSwitched.next(value)
+ }
}
diff --git a/web/src/app/services/domain/domain.service.ts b/web/src/app/services/domain/domain.service.ts
index 497d28fdc..01c8b90a6 100644
--- a/web/src/app/services/domain/domain.service.ts
+++ b/web/src/app/services/domain/domain.service.ts
@@ -5,6 +5,7 @@ import { environment } from '../../../environments/environment';
import { Router } from '@angular/router';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { RequestInProgressService } from '../requestInProgress/request-in-progress.service';
+import { Subject } from 'rxjs/Subject';
@Injectable()
export class DomainService {
@@ -19,6 +20,7 @@ export class DomainService {
};
private domainSelectedValue;
private domainSelected = new BehaviorSubject('');
+ private domainSwitched = new Subject();
constructor(
private httpClient: HttpClient,
@@ -40,13 +42,22 @@ export class DomainService {
return this.domainSelected.asObservable();
}
+ getSwitchedDomain(): Observable {
+ return this.domainSwitched.asObservable();
+ }
+
selectDomain(value: string) {
this.requestInProgressService.setRequestInProgress(true);
- // this.router.navigate(['']);
this.domainSelectedValue = value;
this.domainSelected.next(value);
}
+ switchDomain(value: string) {
+ this.selectDomain(value);
+ this.domainSwitched.next(value);
+ this.router.navigate([this.getNavigationUrl()]);
+ }
+
domainChangedComplete() {
this.requestInProgressService.setRequestInProgress(false);
}
@@ -54,4 +65,12 @@ export class DomainService {
getSelectedDomainValue() {
return this.domainSelectedValue;
}
+
+ private getNavigationUrl(): string {
+ if (this.router.url.indexOf('workbaskets') !== -1) {
+ return 'administration/workbaskets';
+ } else if (this.router.url.indexOf('classifications') !== -1) {
+ return 'administration/classifications';
+ }
+ }
}
diff --git a/web/src/app/services/errorModal/error-modal.service.ts b/web/src/app/services/errorModal/error-modal.service.ts
index c6987d316..3e6ca001d 100644
--- a/web/src/app/services/errorModal/error-modal.service.ts
+++ b/web/src/app/services/errorModal/error-modal.service.ts
@@ -6,7 +6,7 @@ import { ErrorModel } from 'app/models/modal-error';
@Injectable()
export class ErrorModalService {
- public errorTriggered = new Subject();
+ private errorTriggered = new Subject();
constructor() { }
diff --git a/web/src/app/shared/nav-bar/nav-bar.component.html b/web/src/app/shared/nav-bar/nav-bar.component.html
index 2416152e7..21a545804 100644
--- a/web/src/app/shared/nav-bar/nav-bar.component.html
+++ b/web/src/app/shared/nav-bar/nav-bar.component.html
@@ -24,7 +24,7 @@