Skip to content

Commit 8bc7ef1

Browse files
committed
unsubscribe subscriptions
1 parent 5f0aa26 commit 8bc7ef1

31 files changed

+686
-507
lines changed

client/src/app/modules/information/components/appellation/appellation.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div [ngClass]="{'dev-view': entityEditor.devView}">
22

33
<span *ngIf="entityEditor.devView">
4-
[state: {{peItAppeState}}]
4+
[state: {{peItAppeState}}]
55
</span>
66

77

@@ -13,7 +13,7 @@
1313

1414
</div>
1515

16-
<form [formGroup]="formGroup" class="d-flex flex-row" *ngIf=" peItAppeState === 'edit' || peItAppeState === 'create' || peItAppeState === 'create-pe-it' || peItAppeState === 'create-pe-it-role'">
16+
<form [formGroup]="formGroup" class="d-flex flex-row" *ngIf=" peItAppeState === 'edit' || peItAppeState === 'create' || peItAppeState === 'create-pe-it' || peItAppeState === 'create-pe-it-role' || peItAppeState === 'create-te-ent-role'">
1717

1818
<gv-appellation-label-editor formControlName="appellationLabel" (touched)="markAsTouched()"></gv-appellation-label-editor>
1919

client/src/app/modules/information/components/appellation/appellation.component.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, Input, Output, EventEmitter, ChangeDetectionStrategy, forwardRef } from '@angular/core';
1+
import { Component, OnInit, Input, Output, EventEmitter, ChangeDetectionStrategy, forwardRef, OnDestroy } from '@angular/core';
22

33
import { SlimLoadingBarService } from 'ng2-slim-loading-bar';
44
import { InfAppellation, InfAppellationApi, ActiveProjectService, EntityEditorService, InfEntityProjectRel } from 'app/core';
@@ -9,6 +9,7 @@ import { IAppellationState } from './appellation.model';
99
import { NgRedux, ObservableStore } from '@angular-redux/store';
1010
import { NG_VALUE_ACCESSOR, FormBuilder, FormGroup, FormControl, Validators, ControlValueAccessor } from '@angular/forms';
1111
import { Token, TokenInterface } from '../../shared/appellation-token/appellation-token';
12+
import { Subscription } from 'rxjs';
1213

1314

1415
@AutoUnsubscribe()
@@ -25,7 +26,7 @@ import { Token, TokenInterface } from '../../shared/appellation-token/appellatio
2526
}
2627
]
2728
})
28-
export class AppellationComponent implements OnInit, ControlValueAccessor {
29+
export class AppellationComponent implements OnInit, OnDestroy, ControlValueAccessor {
2930

3031
@Input() parentPath: string[];
3132

@@ -64,6 +65,7 @@ export class AppellationComponent implements OnInit, ControlValueAccessor {
6465

6566
appellationLabelInEdit: AppellationLabel;
6667

68+
subs: Subscription[] = [];
6769

6870
constructor(
6971
private fb: FormBuilder,
@@ -78,7 +80,7 @@ export class AppellationComponent implements OnInit, ControlValueAccessor {
7880
this.formGroup = this.fb.group({})
7981

8082
// subscribe to form changes here
81-
this.formGroup.valueChanges.subscribe(val => {
83+
this.subs.push(this.formGroup.valueChanges.subscribe(val => {
8284
if (this.formGroup.valid) {
8385

8486
// build a appe with the appellation_label given by the formControl
@@ -101,20 +103,32 @@ export class AppellationComponent implements OnInit, ControlValueAccessor {
101103
else {
102104
this.onChange(null)
103105
}
104-
})
106+
}))
105107

106108
}
107109

110+
ngOnDestroy() {
111+
this.subs.forEach(sub => sub.unsubscribe())
112+
}
113+
108114
ngOnInit() {
109115

110116
this.basePath = this.getBasePath();
111-
this.ngRedux.select<IAppellationState>(this.basePath).subscribe(d => {
117+
this.subs.push(this.ngRedux.select<IAppellationState>(this.basePath).subscribe(d => {
112118
this.appeState = d;
113-
if(d){
119+
if (d) {
114120
this.appellation = this.appeState.appellation;
115121
this.peItAppeState = this.appeState.state;
122+
123+
this.formGroup.addControl('appellationLabel', new FormControl(
124+
this.appeState.appellation.appellation_label,
125+
[
126+
Validators.required
127+
]
128+
))
129+
116130
}
117-
});
131+
}));
118132

119133
if (this.appellation.appellation_label) {
120134
this.appellationLabel = new AppellationLabel(this.appellation.appellation_label);
@@ -180,7 +194,7 @@ export class AppellationComponent implements OnInit, ControlValueAccessor {
180194
save(appeLabel: AppellationLabel) {
181195
this.startLoading();
182196

183-
this.appellationApi.findOrCreateAppellation(
197+
this.subs.push(this.appellationApi.findOrCreateAppellation(
184198
this.activeProjectService.project.pk_project,
185199
{
186200
pk_entity: this.appellation.pk_entity,
@@ -198,7 +212,8 @@ export class AppellationComponent implements OnInit, ControlValueAccessor {
198212
isDisplayRoleInProject: false
199213
})
200214

201-
})
215+
}))
216+
202217
this.cancelEdit.emit()
203218

204219
}
@@ -245,12 +260,6 @@ export class AppellationComponent implements OnInit, ControlValueAccessor {
245260
*/
246261
writeValue(appellation: InfAppellation): void {
247262

248-
this.formGroup.addControl('appellationLabel', new FormControl(
249-
this.appeState.appellation.appellation_label,
250-
[
251-
Validators.required
252-
]
253-
))
254263

255264
}
256265

@@ -285,7 +294,7 @@ export class AppellationComponent implements OnInit, ControlValueAccessor {
285294
onTouched = () => {
286295
};
287296

288-
markAsTouched(){
297+
markAsTouched() {
289298
this.onTouched()
290299
this.touched.emit()
291300
}

client/src/app/modules/information/components/pe-it-entity-add/pe-it-entity-add.component.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, Input, Output, ChangeDetectorRef, EventEmitter, AfterViewInit } from '@angular/core';
1+
import { Component, OnInit, Input, Output, ChangeDetectorRef, EventEmitter, AfterViewInit, OnDestroy } from '@angular/core';
22
import { Router, ActivatedRoute } from '@angular/router';
33

44
import { SlimLoadingBarService } from 'ng2-slim-loading-bar';
@@ -19,20 +19,21 @@ import { RoleService } from '../../shared/role.service';
1919
import { PropertyService } from '../../shared/property.service';
2020
import { RoleSetListService } from '../../shared/role-set-list.service';
2121
import { EntityAddModalComponent } from '../entity-add-modal/entity-add-modal.component';
22+
import { Subscriber, Subscription } from 'rxjs';
2223

2324

2425
@Component({
2526
selector: 'gv-pe-it-entity-add',
2627
templateUrl: './pe-it-entity-add.component.html',
2728
styleUrls: ['./pe-it-entity-add.component.scss']
2829
})
29-
export class PeItEntityAddComponent implements OnInit {
30+
export class PeItEntityAddComponent implements OnInit, OnDestroy {
3031

3132

3233
/**
3334
* Inputs
3435
*/
35-
@Input() dfhClass: DfhClass;
36+
@Input() dfhClass: DfhClass;
3637

3738
/**
3839
* Output
@@ -41,6 +42,7 @@ export class PeItEntityAddComponent implements OnInit {
4142

4243
@Output() open: EventEmitter<number> = new EventEmitter();
4344

45+
subs: Subscription[] = [];
4446

4547
constructor(
4648
private modalService: NgbModal,
@@ -49,9 +51,12 @@ export class PeItEntityAddComponent implements OnInit {
4951
// super(peItApi, peItService, propertyPipe, activePeItService, slimLoadingBarService, entityEditor, changeDetector, ngRedux, actions, classService, roleService, propertyService, roleSetListService)
5052
}
5153

52-
ngOnInit(){
54+
ngOnInit() {
5355
this.openModal()
5456
}
57+
ngOnDestroy() {
58+
this.subs.forEach(sub => sub.unsubscribe())
59+
}
5560

5661
openModal() {
5762

@@ -66,10 +71,10 @@ export class PeItEntityAddComponent implements OnInit {
6671
this.entityAddModalService.state = 'search-existing';
6772
this.entityAddModalService.selectRoleRange = true;
6873
this.entityAddModalService.selectedClass = this.dfhClass;
69-
this.entityAddModalService.onSelect.subscribe(pkEntity => {
74+
this.subs.push(this.entityAddModalService.onSelect.subscribe(pkEntity => {
7075
this.selected.emit(pkEntity);
7176

72-
})
77+
}))
7378

7479
}
7580

client/src/app/modules/information/components/pe-it-entity-preview/pe-it-entity-preview.component.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, Input, Output, ChangeDetectorRef, EventEmitter, ChangeDetectionStrategy, forwardRef } from '@angular/core';
1+
import { Component, OnInit, Input, Output, ChangeDetectorRef, EventEmitter, ChangeDetectionStrategy, forwardRef, OnDestroy } from '@angular/core';
22
import { Router, ActivatedRoute } from '@angular/router';
33

44
import { SlimLoadingBarService } from 'ng2-slim-loading-bar';
@@ -23,6 +23,7 @@ import { peItReducer } from '../../containers/pe-it/pe-it.reducer';
2323
import { AutoUnsubscribe } from 'ngx-auto-unsubscribe';
2424
import { FormBuilder, ControlValueAccessor, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms';
2525
import { StateCreatorService } from '../../shared/state-creator.service';
26+
import { Subscription } from 'rxjs';
2627

2728
@AutoUnsubscribe()
2829
@Component({
@@ -37,7 +38,7 @@ import { StateCreatorService } from '../../shared/state-creator.service';
3738
}
3839
]
3940
})
40-
export class PeItEntityPreviewComponent implements OnInit, ControlValueAccessor {
41+
export class PeItEntityPreviewComponent implements OnInit, OnDestroy, ControlValueAccessor {
4142

4243
@Input() pkEntity: number;
4344
@Input() isCircular: boolean;
@@ -67,6 +68,8 @@ export class PeItEntityPreviewComponent implements OnInit, ControlValueAccessor
6768

6869
pkProject: number;
6970

71+
subs: Subscription[] = [];
72+
7073
constructor(
7174
private route: ActivatedRoute,
7275
private router: Router,
@@ -75,24 +78,28 @@ export class PeItEntityPreviewComponent implements OnInit, ControlValueAccessor
7578
private fb: FormBuilder,
7679
private roleSetListService: RoleSetListService,
7780
private stateCreator: StateCreatorService,
81+
private ref:ChangeDetectorRef
7882
) {
7983
}
8084

8185

8286
ngOnInit() {
8387

8488
this.basePath = this.getBasePath();
85-
this.ngRedux.select<IPeItState>(this.basePath).subscribe(d => {
89+
this.subs.push(this.ngRedux.select<IPeItState>(this.basePath).subscribe(d => {
8690
this.peItState = d;
8791
if (d)
8892
this.label = this.roleSetListService.getDisplayAppeLabelOfPeItRoleSets(d.roleSets);
89-
})
93+
}))
9094

91-
this.ngRedux.select<number>(['activeProject', 'pk_project']).subscribe(d => {
95+
this.subs.push(this.ngRedux.select<number>(['activeProject', 'pk_project']).subscribe(d => {
9296
this.pkProject = d;
93-
})
94-
97+
}))
98+
}
9599

100+
ngOnDestroy() {
101+
this.subs.forEach(sub => sub.unsubscribe())
102+
this.ref.detach()
96103
}
97104

98105

@@ -108,9 +115,10 @@ export class PeItEntityPreviewComponent implements OnInit, ControlValueAccessor
108115
selected(pkEntity: number) {
109116
this.isSelected = true
110117

111-
this.stateCreator.initializePeItState(pkEntity, this.pkProject, 'view').subscribe(peItState => {
118+
this.subs.push(this.stateCreator.initializePeItState(pkEntity, this.pkProject, 'view').subscribe(peItState => {
112119
this.label = this.roleSetListService.getDisplayAppeLabelOfPeItRoleSets(peItState.roleSets);
113-
})
120+
this.ref.detectChanges()
121+
}))
114122

115123
// send the pkEntity to the parent form
116124
this.onChange(pkEntity)

client/src/app/modules/information/components/pe-it-role-set/pe-it-role-set.component.html

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<span *ngIf="entityEditor.devView">
33
<ng-container *ngTemplateOutlet="dev"></ng-container>
44
</span>
5+
6+
57
<!--
68
************************* Editable State & Create PeIt-Role State ************************* -->
79

@@ -12,13 +14,22 @@
1214
<ng-container *ngTemplateOutlet="header"></ng-container>
1315

1416
<div [@slideInOut]="(toggle$|async)">
15-
1617
<!-- The roles that are added -->
17-
1818
<div class="card-body">
1919
<gv-pe-it-role *ngFor="let entry of (roleStatesInProject$ | async) | keys; trackBy:getKey" [parentPath]="basePath" [index]="entry.key"
2020
(appeChange)="emitAppeChange($event)" (onRequestStandard)="changeStandardRole($event)" (readyToAdd)="onRoleReadyToAdd($event)"
21-
(roleRemoved)="onRoleRemoved($event)"></gv-pe-it-role>
21+
(roleRemoved)="onRoleRemoved($event)">
22+
23+
<div headerRight ngbDropdown placement="bottom-right" class="gv-name-dropdown">
24+
<button class="btn btn-link" ngbDropdownToggle>
25+
<i class="fa fa-ellipsis-v"></i>
26+
</button>
27+
<div ngbDropdownMenu aria-labelledby="dropdown" class="dropdown-menu">
28+
<button class="dropdown-item" (click)="removeFromProject(entry.key)">Remove from project </button>
29+
</div>
30+
</div>
31+
32+
</gv-pe-it-role>
2233
</div>
2334

2435
<!-- If no roles in Project, show a big add button -->
@@ -44,8 +55,8 @@
4455

4556
<form [formGroup]="formGroup" *ngIf="formGroup" [connect]="formValPath">
4657
<div *ngFor="let entry of (roleStatesToCreate$ | async) | keys; trackBy:getKey">
47-
<gv-pe-it-role [parentPath]="basePath" intermediatePathSegment="roleStatesToCreate" [index]="entry.key"
48-
[formControlName]="entry.key" (touched)="markAsTouched()"></gv-pe-it-role>
58+
<gv-pe-it-role [parentPath]="basePath" intermediatePathSegment="roleStatesToCreate" [index]="entry.key" [formControlName]="entry.key"
59+
(touched)="markAsTouched()"></gv-pe-it-role>
4960
</div>
5061

5162
<div class="card-body">
@@ -219,7 +230,7 @@
219230
</a>
220231
</div>
221232
</div>
222-
<button class="btn btn-secondary rounded-bottom-0" (click)="removePropertySection()" *ngIf="removeSectionBtnVisible">
233+
<button class="btn btn-secondary rounded-bottom-0" (click)="removeRoleSet()" *ngIf="removeRoleSetBtnVisible">
223234
<i class="fa fa-close"></i>
224235
</button>
225236
</div>

0 commit comments

Comments
 (0)