Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Use takeWhile to cancel Observables #520

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import {ConfirmationModalComponent} from "../shared/dialog/confirmation-modal.co
templateUrl: './analysis-context-form.component.html',
styleUrls: ['analysis-context-form.component.scss']
})
export class AnalysisContextFormComponent extends FormComponent
implements OnInit, OnDestroy, IsDirty
export class AnalysisContextFormComponent extends FormComponent implements OnInit, IsDirty
{
@ViewChild(NgForm)
private analysisContextForm: NgForm;
Expand Down Expand Up @@ -131,35 +130,35 @@ export class AnalysisContextFormComponent extends FormComponent
this.initializeAnalysisContext();

this.dialog = this._dialogService.getConfirmationDialog();
this.dialogSubscription = this.dialog.confirmed.subscribe(() => this.saveConfiguration());
this.dialogSubscription = this.dialog.confirmed.takeUntil(this.destroy).subscribe(() => this.saveConfiguration());
}

ngOnInit() {
this.saveInProgress = false;

this._configurationOptionsService.getAll().subscribe((options: ConfigurationOption[]) => {
this._configurationOptionsService.getAll().takeUntil(this.destroy).subscribe((options: ConfigurationOption[]) => {
this.configurationOptions = options;
});

this.routerSubscription = this._router.events.filter(event => event instanceof NavigationEnd).subscribe(_ => {
this._router.events.filter(event => event instanceof NavigationEnd).takeUntil(this.destroy).subscribe(_ => {
let flatRouteData = this._routeFlattener.getFlattenedRouteData(this._activatedRoute.snapshot);
this.flatRouteData = flatRouteData;

if (flatRouteData.data['project']) {
let project = flatRouteData.data['project'];

// Load the apps of this project.
this._appService.getApplicationsByProjectID(project.id).subscribe(apps => {
this._appService.getApplicationsByProjectID(project.id).takeUntil(this.destroy).subscribe(apps => {
this.availableApps = apps;

// Reload the App from the service to ensure fresh data
this._migrationProjectService.get(project.id).subscribe(loadedProject => {
this._migrationProjectService.get(project.id).takeUntil(this.destroy).subscribe(loadedProject => {
this.project = loadedProject;
if (project.defaultAnalysisContextId == null) {
this.initializeAnalysisContext();
this.analysisContext.applications = apps.slice();
} else {
this._analysisContextService.get(project.defaultAnalysisContextId)
this._analysisContextService.get(project.defaultAnalysisContextId).takeUntil(this.destroy)
.subscribe(context => {
this.analysisContext = context;
if (this.analysisContext.migrationPath == null)
Expand All @@ -181,11 +180,6 @@ export class AnalysisContextFormComponent extends FormComponent

}

ngOnDestroy(): void {
this.routerSubscription.unsubscribe();
this.dialogSubscription.unsubscribe();
}

// Apps selection checkboxes
static getDefaultAnalysisContext() {
let analysisContext = <AnalysisContext>{};
Expand Down Expand Up @@ -254,7 +248,7 @@ export class AnalysisContextFormComponent extends FormComponent
});
*/

forkJoin(registeredPackagesObservables).subscribe((packageMetadataArray: PackageMetadata[]) => {
forkJoin(registeredPackagesObservables).takeUntil(this.destroy).subscribe((packageMetadataArray: PackageMetadata[]) => {
let arrayOfRoots = [].concat(...packageMetadataArray.map((singlePackageMetadata) => singlePackageMetadata.packageTree));
let mergedRoots = this._packageRegistryService.mergePackageRoots(arrayOfRoots);
mergedRoots.forEach(singleRoot => this._packageRegistryService.putHierarchy(singleRoot));
Expand Down Expand Up @@ -322,7 +316,7 @@ export class AnalysisContextFormComponent extends FormComponent

this.saveInProgress = true;

this._analysisContextService.saveAsDefault(this.analysisContext, this.project).subscribe(
this._analysisContextService.saveAsDefault(this.analysisContext, this.project).takeUntil(this.destroy).subscribe(
updatedContext => {
this._dirty = false;
this.onSuccess(updatedContext);
Expand All @@ -338,6 +332,7 @@ export class AnalysisContextFormComponent extends FormComponent

if (this.action === Action.SaveAndRun) {
this._windupExecutionService.execute(analysisContext, this.project)
.takeUntil(this.destroy)
.subscribe(execution => {
this.saveInProgress = false;
this._router.navigate([`/projects/${this.project.id}`]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import {Component, Input, OnInit, Output, EventEmitter} from '@angular/core';
import {RulesPath} from "../generated/windup-services";

import {ConfigurationService} from "../configuration/configuration.service";
import {AbstractComponent} from "../shared/AbstractComponent";


@Component({
selector: 'wu-custom-rule-selection',
templateUrl: './custom-rule-selection.component.html'
})
export class CustomRuleSelectionComponent implements OnInit {
export class CustomRuleSelectionComponent extends AbstractComponent implements OnInit {
private _selectedRulePaths: RulesPath[];

@Output()
Expand Down Expand Up @@ -43,10 +44,12 @@ export class CustomRuleSelectionComponent implements OnInit {

rulesPaths: RulesPath[] = [];

constructor(private _configurationService: ConfigurationService) { }
constructor(private _configurationService: ConfigurationService) {
super();
}

ngOnInit() {
this._configurationService.getCustomRulesetPaths().subscribe(
this._configurationService.getCustomRulesetPaths().takeUntil(this.destroy).subscribe(
rulesPaths => {
this.rulesPaths = rulesPaths;
},
Expand Down
14 changes: 11 additions & 3 deletions ui/src/main/webapp/src/app/components/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import {AfterViewInit, Component, ViewChild} from "@angular/core";
import {AfterViewInit, Component, OnDestroy, ViewChild} from "@angular/core";
import {Router, NavigationEnd, ActivatedRouteSnapshot, ActivatedRoute} from "@angular/router";
import {RouteHistoryService} from "../core/routing/route-history.service";
import {RouteFlattenerService} from "../core/routing/route-flattener.service";
import {ConfirmationModalComponent} from "../shared/dialog/confirmation-modal.component";
import {DialogService} from "../shared/dialog/dialog.service";
import {Subscription} from "rxjs/Subscription";

@Component({
selector: 'windup-app',
templateUrl: './app.component.html'
})
export class AppComponent implements AfterViewInit {
export class AppComponent implements AfterViewInit, OnDestroy {
@ViewChild('reusableModalDialog')
confirmationDialog: ConfirmationModalComponent;

routerSubscription: Subscription;

/*
* This is for Augury Chrome extension to display router tree
* See https://github.com/rangle/augury/issues/715
Expand All @@ -26,7 +29,7 @@ export class AppComponent implements AfterViewInit {
private activatedRoute: ActivatedRoute,
private dialogService: DialogService
) {
router.events
this.routerSubscription = router.events
.filter(event => event instanceof NavigationEnd)
.subscribe((event: NavigationEnd) => {
this.routeHistoryService.addNavigationEvent(event);
Expand All @@ -37,4 +40,9 @@ export class AppComponent implements AfterViewInit {
ngAfterViewInit(): void {
this.dialogService.setConfirmationDialog(this.confirmationDialog);
}


ngOnDestroy(): void {
this.routerSubscription.unsubscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ export class AddRulesPathModalComponent extends FormComponent implements OnInit,
return paths[paths.length - 1];
};

private subscriptions: Subscription[] = [];

constructor(
private _formBuilder: FormBuilder,
private _fileService: FileService,
Expand All @@ -68,17 +66,17 @@ export class AddRulesPathModalComponent extends FormComponent implements OnInit,
super();
this.multipartUploader = <FileUploaderWrapper>_ruleService.getMultipartUploader();

this.subscriptions.push(this.multipartUploader.observables.onSuccessItem.subscribe((result) => {
this.multipartUploader.observables.onSuccessItem.takeUntil(this.destroy).subscribe((result) => {
this.countUploadedRules++;
const rulesPath = JSON.parse(result.response);
this.uploadedRules = [ ...this.uploadedRules, rulesPath ];
}));
});

this.subscriptions.push(this.multipartUploader.observables.onErrorItem.subscribe((result) => {
this.multipartUploader.observables.onErrorItem.takeUntil(this.destroy).subscribe((result) => {
this.handleError(utils.parseServerResponse(result.response));
}));
this.subscriptions.push(this.multipartUploader.observables.onAfterAddingFile.subscribe(() => this.uploadRule()));
this.subscriptions.push(this.multipartUploader.observables.onWhenAddingFileFailed.subscribe(result => {
});
this.multipartUploader.observables.onAfterAddingFile.takeUntil(this.destroy).subscribe(() => this.uploadRule());
this.multipartUploader.observables.onWhenAddingFileFailed.takeUntil(this.destroy).subscribe(result => {
const item = result.item;
const filter = result.filter;

Expand Down Expand Up @@ -109,7 +107,7 @@ export class AddRulesPathModalComponent extends FormComponent implements OnInit,
}
}
this.handleError(msg);
}));
});

let suffixes = ['.xml'];
this.multipartUploader.options.filters.push(<FilterFunction>{
Expand All @@ -128,11 +126,6 @@ export class AddRulesPathModalComponent extends FormComponent implements OnInit,
});
}

ngOnDestroy(): void {
this.subscriptions.forEach(subscription => subscription.unsubscribe());
this.subscriptions = [];
}

show(): void {
this.countUploadedRules = 0;
this.uploadedRules = [];
Expand All @@ -153,7 +146,7 @@ export class AddRulesPathModalComponent extends FormComponent implements OnInit,
if (this.mode === 'PATH') {
this.addPath();
} else {
this._configurationService.get().subscribe(configuration => {
this._configurationService.get().takeUntil(this.destroy).subscribe(configuration => {
this.configurationSaved.emit({ configuration });
this.hide();
});
Expand All @@ -166,11 +159,11 @@ export class AddRulesPathModalComponent extends FormComponent implements OnInit,
let newPath = <RulesPath>{};
newPath.path = this.inputPath;
newPath.rulesPathType = "USER_PROVIDED";
newPath.scanRecursively = this.scanRecursively;
(<any>newPath).scanRecursively = this.scanRecursively;

newConfiguration.rulesPaths.push(newPath);

this._configurationService.save(newConfiguration).subscribe(
this._configurationService.save(newConfiguration).takeUntil(this.destroy).subscribe(
configuration => {
this.configuration = configuration;
this.configurationSaved.emit({
Expand All @@ -188,7 +181,7 @@ export class AddRulesPathModalComponent extends FormComponent implements OnInit,
return;
}

this._ruleService.uploadRules().subscribe(
this._ruleService.uploadRules().takeUntil(this.destroy).subscribe(
() => {},
error => this.handleError(<any>error)
);
Expand All @@ -204,11 +197,11 @@ export class AddRulesPathModalComponent extends FormComponent implements OnInit,
dialog.body = `Are you sure you want to remove rule provider '${rulesPath.path}'?`;
dialog.data = rulesPath;
dialog.show();
this.dialogSubscription = dialog.confirmed.subscribe(rulePath => this.removeRulesPath(rulePath));
this.dialogSubscription = dialog.confirmed.takeUntil(this.destroy).subscribe(rulePath => this.removeRulesPath(rulePath));
}

removeRulesPath(rulesPath: RulesPath) {
this._ruleService.deleteRule(rulesPath).subscribe(() => {
this._ruleService.deleteRule(rulesPath).takeUntil(this.destroy).subscribe(() => {
this.uploadedRules = this.uploadedRules.filter(item => item.id !== rulesPath.id);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import Arrays = utils.Arrays;
import {FilterConfiguration} from "../shared/toolbar/toolbar.component";
import {getAvailableFilters} from "./technology-filter";
import {DomSanitizer} from '@angular/platform-browser';
import {AbstractComponent} from "../shared/AbstractComponent";

declare function prettyPrint();

@Component({
templateUrl: './configuration.component.html',
styleUrls: ['./configuration.component.scss']
})
export class ConfigurationComponent implements OnInit, AfterViewInit {
export class ConfigurationComponent extends AbstractComponent implements OnInit, AfterViewInit {

forceReloadAttempted: boolean = false;
rescanInProgress: boolean = false;
Expand Down Expand Up @@ -68,18 +69,18 @@ export class ConfigurationComponent implements OnInit, AfterViewInit {
private _element: ElementRef,
private _sanitizer: DomSanitizer
) {

super();
}

ngOnInit(): void {
this._activatedRoute.data.subscribe((data: {configuration: Configuration}) => {
this._activatedRoute.data.takeUntil(this.destroy).subscribe((data: {configuration: Configuration}) => {
this.configuration = data.configuration;
this.loadProviders();
});
}

ngAfterViewInit(): void {
this.removeRulesConfirmationModal.confirmed.subscribe(rulePath => this.removeRulesPath(rulePath));
this.removeRulesConfirmationModal.confirmed.takeUntil(this.destroy).subscribe(rulePath => this.removeRulesPath(rulePath));
}

loadProviders() {
Expand All @@ -92,15 +93,15 @@ export class ConfigurationComponent implements OnInit, AfterViewInit {
forceReload() {
this.forceReloadAttempted = true;
this.rescanInProgress = true;
this._configurationService.reloadConfigration().subscribe(() => {
this._configurationService.reloadConfigration().takeUntil(this.destroy).subscribe(() => {
this.rescanInProgress = false;
this.loadRuleProviderDetails()
});
}

loadRuleProviderDetails() {
this.configuration.rulesPaths.forEach((rulesPath) => {
this._ruleService.getByRulesPath(rulesPath).subscribe(
this._ruleService.getByRulesPath(rulesPath).takeUntil(this.destroy).subscribe(
(ruleProviders:RuleProviderEntity[]) => {
this.ruleProvidersByPath.set(rulesPath, ruleProviders);
if (!this.forceReloadAttempted && rulesPath.rulesPathType == "SYSTEM_PROVIDED" && ruleProviders.length == 0) // needs to be loaded
Expand Down Expand Up @@ -178,7 +179,7 @@ export class ConfigurationComponent implements OnInit, AfterViewInit {
}

removeRulesPath(rulesPath: RulesPath) {
this._ruleService.deleteRule(rulesPath).subscribe(() => {
this._ruleService.deleteRule(rulesPath).takeUntil(this.destroy).subscribe(() => {
this._notificationService.success('Rule was deleted');

this._configurationService.get().subscribe(newConfig => {
Expand All @@ -189,7 +190,7 @@ export class ConfigurationComponent implements OnInit, AfterViewInit {
}

reloadConfiguration() {
this._configurationService.reloadConfigration().subscribe(
this._configurationService.reloadConfigration().takeUntil(this.destroy).subscribe(
configuration => {
this.configuration = configuration;
this.loadProviders();
Expand All @@ -202,7 +203,7 @@ export class ConfigurationComponent implements OnInit, AfterViewInit {

confirmRemoveRules(rulesPath: RulesPath) {
console.log("Checking rules path " + rulesPath.path);
this._ruleService.checkIfUsedRulesPath(rulesPath).subscribe(
this._ruleService.checkIfUsedRulesPath(rulesPath).takeUntil(this.destroy).subscribe(
response => {
if (response.valueOf())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ export class AllExecutionsComponent extends ExecutionsMonitoringComponent implem
this.addSubscription(
this._eventBus.onEvent
.filter(event => event.isTypeOf(ExecutionEvent))
.takeUntil(this.destroy)
.subscribe((event: ExecutionEvent) => this.onExecutionEvent(event))
);

this.addSubscription(
this._eventBus.onEvent
.filter(event => event.isTypeOf(NewExecutionStartedEvent))
.takeUntil(this.destroy)
.subscribe((event: NewExecutionStartedEvent) => { this.loadExecutions(); })
);
}

protected loadExecutions() {
this._windupService.getAllExecutions().subscribe(
this._windupService.getAllExecutions().takeUntil(this.destroy).subscribe(
executions => {
this.executions = executions;
super.loadActiveExecutions(executions);
Expand Down
Loading