Commit 04a1fbfd authored by Alexander Philipp Nowosad's avatar Alexander Philipp Nowosad
Browse files

Add element loader service

parent 86fa3d9e
Pipeline #137892 failed with stages
in 11 minutes and 29 seconds
import { Injectable, OnDestroy } from '@angular/core';
import { Injectable } from '@angular/core';
import { CompanyModelService } from '../../canvas-meta-model/company-model.service';
import { Observable, Subject, Subscription } from 'rxjs';
import { CompanyModel } from '../../canvas-meta-model/company-model';
import { Instance } from '../../canvas-meta-model/instance';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, ParamMap } from '@angular/router';
import { ElementLoaderService } from '../../database/element-loader.service';
@Injectable()
export class InstanceLoaderService implements OnDestroy {
export class InstanceLoaderService extends ElementLoaderService {
companyModel: CompanyModel = null;
instance: Instance = null;
loaded: Observable<void> = null;
private $loaded: Subject<void> = null;
private routeSubscription: Subscription = null;
private changesFeed: Subscription = null;
constructor(
private companyModelService: CompanyModelService,
private route: ActivatedRoute
route: ActivatedRoute
) {
this.init();
}
private init() {
this.$loaded = new Subject<void>();
this.loaded = this.$loaded.asObservable();
this.routeSubscription = this.route.paramMap.subscribe((paramMap) => {
const companyModelId = paramMap.get('companyModelId');
const instanceId = +paramMap.get('instanceId');
this.checkUnsubscribeChangesFeed();
this.changesFeed = this.companyModelService
.getChangesFeed(companyModelId)
.subscribe(() => this.loadInstance(companyModelId, instanceId));
this.loadInstance(companyModelId, instanceId).then();
});
}
ngOnDestroy() {
this.checkUnsubscribeChangesFeed();
this.routeSubscription.unsubscribe();
this.$loaded.complete();
super(route);
}
private checkUnsubscribeChangesFeed() {
if (this.changesFeed) {
this.changesFeed.unsubscribe();
this.changesFeed = null;
}
protected initParams(paramMap: ParamMap) {
const companyModelId = paramMap.get('companyModelId');
const instanceId = +paramMap.get('instanceId');
this.changesFeed = this.companyModelService
.getChangesFeed(companyModelId)
.subscribe(() => this.loadInstance(companyModelId, instanceId));
this.loadInstance(companyModelId, instanceId).then();
}
private async loadInstance(companyModelId: string, instanceId: number) {
this.companyModel = await this.companyModelService.get(companyModelId);
this.instance = this.companyModel.getInstance(instanceId);
this.$loaded.next();
this.elementLoaded();
}
}
import { Injectable, OnDestroy } from '@angular/core';
import { Observable, Subject, Subscription } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { Injectable } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';
import { ExpertModel } from '../../canvas-meta-model/expert-model';
import { ExpertModelService } from '../../canvas-meta-model/expert-model.service';
import { ElementLoaderService } from '../../database/element-loader.service';
@Injectable()
export class ExpertModelLoaderService implements OnDestroy {
export class ExpertModelLoaderService extends ElementLoaderService {
expertModel: ExpertModel = null;
loaded: Observable<void> = null;
private $loaded: Subject<void> = null;
private routeSubscription: Subscription = null;
private changesFeed: Subscription = null;
constructor(
private expertModelService: ExpertModelService,
private route: ActivatedRoute
route: ActivatedRoute
) {
this.init();
}
private init() {
this.$loaded = new Subject<void>();
this.loaded = this.$loaded.asObservable();
this.routeSubscription = this.route.paramMap.subscribe((paramMap) => {
const expertModelId = paramMap.get('id');
this.checkUnsubscribeChangesFeed();
this.changesFeed = this.expertModelService
.getChangesFeed(expertModelId)
.subscribe(() => this.loadExpertModel(expertModelId));
this.loadExpertModel(expertModelId).then();
});
}
ngOnDestroy() {
this.checkUnsubscribeChangesFeed();
this.routeSubscription.unsubscribe();
this.$loaded.complete();
super(route);
}
private checkUnsubscribeChangesFeed() {
if (this.changesFeed) {
this.changesFeed.unsubscribe();
this.changesFeed = null;
}
protected initParams(paramMap: ParamMap) {
const expertModelId = paramMap.get('id');
this.changesFeed = this.expertModelService
.getChangesFeed(expertModelId)
.subscribe(() => this.loadExpertModel(expertModelId));
this.loadExpertModel(expertModelId).then();
}
private async loadExpertModel(bmProcessId: string) {
this.expertModel = await this.expertModelService.get(bmProcessId);
this.$loaded.next();
this.elementLoaded();
}
}
import { Injectable, OnDestroy } from '@angular/core';
import { asapScheduler, Observable, Subject, Subscription } from 'rxjs';
import { ActivatedRoute, ParamMap } from '@angular/router';
import { subscribeOn, tap } from 'rxjs/operators';
@Injectable()
export abstract class ElementLoaderService implements OnDestroy {
private _loadedObservable: Observable<void> = null;
private _loaded: Subject<void> = null;
get loaded() {
return this._loadedObservable;
}
private routeSubscription: Subscription = null;
private _changesFeed: Subscription = null;
protected set changesFeed(changesFeed: Subscription) {
this._changesFeed = changesFeed;
}
protected constructor(private route: ActivatedRoute) {
this.init();
}
private init() {
this._loaded = new Subject<void>();
this._loadedObservable = this._loaded.asObservable();
this.routeSubscription = this.route.paramMap
.pipe(
tap(() => this.checkUnsubscribeChangesFeed()),
subscribeOn(asapScheduler) // needs to subscribe after the initialization of the subclass
)
.subscribe((paramMap) => this.initParams(paramMap));
}
/**
* Called if the param map observable has new values
*
* @param paramMap the param map
*/
protected abstract initParams(paramMap: ParamMap);
ngOnDestroy() {
this.checkUnsubscribeChangesFeed();
this.routeSubscription.unsubscribe();
this._loaded.complete();
}
private checkUnsubscribeChangesFeed() {
if (this._changesFeed) {
this._changesFeed.unsubscribe();
this._changesFeed = null;
}
}
protected elementLoaded() {
this._loaded.next();
}
}
import { Injectable, OnDestroy } from '@angular/core';
import { Observable, Subject, Subscription } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { Injectable } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';
import { BmProcess } from '../../development-process-registry/bm-process/bm-process';
import { BmProcessService } from '../../development-process-registry/bm-process/bm-process.service';
import { ElementLoaderService } from '../../database/element-loader.service';
@Injectable()
export class BmProcessLoaderService implements OnDestroy {
export class BmProcessLoaderService extends ElementLoaderService {
bmProcess: BmProcess = null;
loaded: Observable<void> = null;
private $loaded: Subject<void> = null;
private routeSubscription: Subscription = null;
private changesFeed: Subscription = null;
constructor(
private bmProcessService: BmProcessService,
private route: ActivatedRoute
route: ActivatedRoute
) {
this.init();
}
private init() {
this.$loaded = new Subject<void>();
this.loaded = this.$loaded.asObservable();
this.routeSubscription = this.route.paramMap.subscribe((paramMap) => {
const bmProcessId = paramMap.get('id');
this.checkUnsubscribeChangesFeed();
this.changesFeed = this.bmProcessService
.getChangesFeed(bmProcessId)
.subscribe(() => this.loadBmProcess(bmProcessId));
this.loadBmProcess(bmProcessId).then();
});
}
ngOnDestroy() {
this.checkUnsubscribeChangesFeed();
this.routeSubscription.unsubscribe();
this.$loaded.complete();
super(route);
}
private checkUnsubscribeChangesFeed() {
if (this.changesFeed) {
this.changesFeed.unsubscribe();
this.changesFeed = null;
}
protected initParams(paramMap: ParamMap) {
const bmProcessId = paramMap.get('id');
this.changesFeed = this.bmProcessService
.getChangesFeed(bmProcessId)
.subscribe(() => this.loadBmProcess(bmProcessId));
this.loadBmProcess(bmProcessId).then();
}
private async loadBmProcess(bmProcessId: string) {
this.bmProcess = await this.bmProcessService.get(bmProcessId);
this.$loaded.next();
this.elementLoaded();
}
}
import { Injectable, OnDestroy } from '@angular/core';
import { Observable, Subject, Subscription } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { Injectable } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';
import { RunningArtifact } from '../../development-process-registry/running-process/running-artifact';
import { ConcreteArtifactService } from '../../development-process-registry/running-process/concrete-artifact.service';
import { ElementLoaderService } from '../../database/element-loader.service';
@Injectable()
export class ConcreteArtifactLoaderService implements OnDestroy {
export class ConcreteArtifactLoaderService extends ElementLoaderService {
artifact: RunningArtifact = null;
loaded: Observable<void> = null;
private $loaded: Subject<void> = null;
private routeSubscription: Subscription = null;
private changesFeed: Subscription = null;
constructor(
private concreteArtifactService: ConcreteArtifactService,
private route: ActivatedRoute
route: ActivatedRoute
) {
this.init();
}
private init() {
this.$loaded = new Subject<void>();
this.loaded = this.$loaded.asObservable();
this.routeSubscription = this.route.paramMap.subscribe((paramMap) => {
const artifactId = paramMap.get('id');
this.checkUnsubscribeChangesFeed();
this.changesFeed = this.concreteArtifactService
.getChangesFeed(artifactId)
.subscribe(() => this.loadArtifact(artifactId));
this.loadArtifact(artifactId).then();
});
}
ngOnDestroy() {
this.checkUnsubscribeChangesFeed();
this.routeSubscription.unsubscribe();
this.$loaded.complete();
super(route);
}
private checkUnsubscribeChangesFeed() {
if (this.changesFeed) {
this.changesFeed.unsubscribe();
this.changesFeed = null;
}
protected initParams(paramMap: ParamMap) {
const artifactId = paramMap.get('id');
this.changesFeed = this.concreteArtifactService
.getChangesFeed(artifactId)
.subscribe(() => this.loadArtifact(artifactId));
this.loadArtifact(artifactId).then();
}
private async loadArtifact(artifactId: string) {
this.artifact = await this.concreteArtifactService.get(artifactId);
this.$loaded.next();
this.elementLoaded();
}
}
import { Injectable, OnDestroy } from '@angular/core';
import { Observable, Subject, Subscription } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { Injectable } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';
import { DevelopmentMethod } from '../../development-process-registry/development-method/development-method';
import { DevelopmentMethodService } from '../../development-process-registry/development-method/development-method.service';
import { ElementLoaderService } from '../../database/element-loader.service';
@Injectable()
export class DevelopmentMethodLoaderService implements OnDestroy {
export class DevelopmentMethodLoaderService extends ElementLoaderService {
developmentMethod: DevelopmentMethod = null;
loaded: Observable<void> = null;
private $loaded: Subject<void> = null;
private routeSubscription: Subscription = null;
private changesFeed: Subscription = null;
constructor(
private developmentMethodService: DevelopmentMethodService,
private route: ActivatedRoute
route: ActivatedRoute
) {
this.init();
}
private init() {
this.$loaded = new Subject<void>();
this.loaded = this.$loaded.asObservable();
this.routeSubscription = this.route.paramMap.subscribe((paramMap) => {
const developmentMethodId = paramMap.get('id');
this.checkUnsubscribeChangesFeed();
this.changesFeed = this.developmentMethodService
.getChangesFeed(developmentMethodId)
.subscribe(() => this.loadDevelopmentMethod(developmentMethodId));
this.loadDevelopmentMethod(developmentMethodId).then();
});
}
ngOnDestroy() {
this.checkUnsubscribeChangesFeed();
this.routeSubscription.unsubscribe();
this.$loaded.complete();
super(route);
}
private checkUnsubscribeChangesFeed() {
if (this.changesFeed) {
this.changesFeed.unsubscribe();
this.changesFeed = null;
}
protected initParams(paramMap: ParamMap) {
const developmentMethodId = paramMap.get('id');
this.changesFeed = this.developmentMethodService
.getChangesFeed(developmentMethodId)
.subscribe(() => this.loadDevelopmentMethod(developmentMethodId));
this.loadDevelopmentMethod(developmentMethodId).then();
}
private async loadDevelopmentMethod(developmentMethodId: string) {
this.developmentMethod = await this.developmentMethodService.get(
developmentMethodId
);
this.$loaded.next();
this.elementLoaded();
}
}
import { Injectable, OnDestroy } from '@angular/core';
import { Observable, Subject, Subscription } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { Injectable } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';
import { Domain } from '../../development-process-registry/knowledge/domain';
import { DomainService } from '../../development-process-registry/knowledge/domain.service';
import { ElementLoaderService } from '../../database/element-loader.service';
@Injectable()
export class DomainLoaderService implements OnDestroy {
export class DomainLoaderService extends ElementLoaderService {
domain: Domain = null;
loaded: Observable<void> = null;
private $loaded: Subject<void> = null;
private routeSubscription: Subscription = null;
private changesFeed: Subscription = null;
constructor(
private domainService: DomainService,
private route: ActivatedRoute
) {
this.init();
}
private init() {
this.$loaded = new Subject<void>();
this.loaded = this.$loaded.asObservable();
this.routeSubscription = this.route.paramMap.subscribe((paramMap) => {
const domainId = paramMap.get('id');
this.checkUnsubscribeChangesFeed();
this.changesFeed = this.domainService
.getChangesFeed(domainId)
.subscribe(() => this.loadDomain(domainId));
this.loadDomain(domainId).then();
});
}
ngOnDestroy() {
this.checkUnsubscribeChangesFeed();
this.routeSubscription.unsubscribe();
this.$loaded.complete();
constructor(private domainService: DomainService, route: ActivatedRoute) {
super(route);
}
private checkUnsubscribeChangesFeed() {
if (this.changesFeed) {
this.changesFeed.unsubscribe();
this.changesFeed = null;
}
protected initParams(paramMap: ParamMap) {
const domainId = paramMap.get('id');
this.changesFeed = this.domainService
.getChangesFeed(domainId)
.subscribe(() => this.loadDomain(domainId));
this.loadDomain(domainId).then();
}
private async loadDomain(domainId: string) {
this.domain = await this.domainService.get(domainId);
this.$loaded.next();
this.elementLoaded();
}
}
import { Injectable, OnDestroy } from '@angular/core';
import { Observable, Subject, Subscription } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { Injectable } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';
import { MethodElement } from '../../development-process-registry/method-elements/method-element';
import { MethodElementService } from '../../development-process-registry/method-elements/method-element.service';
import { ElementLoaderService } from '../../database/element-loader.service';
@Injectable()
export class MethodElementLoaderService<T extends MethodElement>
implements OnDestroy
{
export class MethodElementLoaderService<
T extends MethodElement
> extends ElementLoaderService {
methodElement: T = null;
listNames: string[] = [];
loaded: Observable<void> = null;
private $loaded: Subject<void> = null;
private routeSubscription: Subscription = null;
private changesFeed: Subscription = null;
constructor(
private methodElementService: MethodElementService<T>,
private route: ActivatedRoute
route: ActivatedRoute
) {
this.init();
}
private init() {
this.$loaded = new Subject<void>();
this.loaded = this.$loaded.asObservable();
this.routeSubscription = this.route.paramMap.subscribe((paramMap) => {
const methodElementId = paramMap.get('id');
this.checkUnsubscribeChangesFeed();
this.changesFeed = this.methodElementService
.getChangesFeed(methodElementId)
.subscribe(() => this.loadMethodElement(methodElementId));
this.loadMethodElement(methodElementId).then();
});
}
ngOnDestroy() {
this.checkUnsubscribeChangesFeed();
this.routeSubscription.unsubscribe();
this.$loaded.complete();
super(route);
}
private checkUnsubscribeChangesFeed() {
if (this.changesFeed) {
this.changesFeed.unsubscribe();
this.changesFeed = null;
}
protected initParams(paramMap: ParamMap) {
const methodElementId = paramMap.get('id');
this.changesFeed = this.methodElementService
.getChangesFeed(methodElementId)
.subscribe(() => this.loadMethodElement(methodElementId));
this.loadMethodElement(methodElementId).then();
}
private async loadMethodElement(methodElementId: string) {
......@@ -55,6 +31,6 @@ export class MethodElementLoaderService<T extends MethodElement>
this.listNames = (await this.methodElementService.getLists()).map(
(list) => list.listName
);
this.$loaded.next();
this.elementLoaded();
}
}
import { Injectable, OnDestroy } from '@angular/core';
import { Observable, Subject, Subscription } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { Injectable } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';
import { ProcessPattern } from '../../development-process-registry/process-pattern/process-pattern';
import { ProcessPatternService } from '../../development-process-registry/process-pattern/process-pattern.service';
import { ElementLoaderService } from '../../database/element-loader.service';
@Injectable()
export class ProcessPatternLoaderService implements OnDestroy {
export class ProcessPatternLoaderService extends ElementLoaderService {
processPattern: ProcessPattern = null;
loaded: Observable<void> = null;
private $loaded: Subject<void> = null;
private routeSubscription: Subscription = null;
private changesFeed: Subscription = null;