Skip to content

Commit 5f0aa26

Browse files
committed
finalized create-pe-it form and api
1 parent 184bc2d commit 5f0aa26

28 files changed

+338
-347
lines changed

client/src/app/modules/information/components/create-pe-it-form/create-pe-it-form.component.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

client/src/app/modules/information/components/create-pe-it-form/create-pe-it-form.component.scss

Whitespace-only changes.

client/src/app/modules/information/components/create-pe-it-form/create-pe-it-form.component.spec.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

client/src/app/modules/information/components/create-pe-it-form/create-pe-it-form.component.ts

Lines changed: 0 additions & 86 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
<div class="gv-create-new">
1+
<form *ngIf="formGroup" [connect]="['information', 'entityCreateNew', 'formValue']" [formGroup]="formGroup" (ngSubmit)="submit()">
22

3-
<gv-pe-it [parentPath]="basePath"></gv-pe-it>
3+
<div class="form-group">
4+
<gv-pe-it *ngIf="formGroup.get(formCtrlName)" [parentPath]="basePath" [formControlName]="formCtrlName"></gv-pe-it>
5+
</div>
46

5-
</div>
7+
</form>

client/src/app/modules/information/components/entity-add-create-new/entity-add-create-new.component.ts

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
1+
import { Component, OnInit, Input, Output, EventEmitter, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
22
import { EntityAddModalComponent } from '../entity-add-modal/entity-add-modal.component';
33
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
44
import { InfPersistentItem, EntityEditorService, InfPersistentItemApi, Project, InfEntityProjectRel } from 'app/core';
@@ -13,29 +13,32 @@ import { StateCreatorService } from '../../shared/state-creator.service';
1313
import { StateToDataService } from '../../shared/state-to-data.service';
1414
import { entityCreateNewReducer } from './entity-add-create-new.reducer';
1515
import { AutoUnsubscribe } from 'ngx-auto-unsubscribe';
16+
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
17+
import { Subscription } from 'rxjs';
1618

17-
@AutoUnsubscribe()
19+
@AutoUnsubscribe({
20+
includeArrays: true
21+
})
1822
@Component({
1923
selector: 'gv-entity-add-create-new',
2024
templateUrl: './entity-add-create-new.component.html',
21-
styleUrls: ['./entity-add-create-new.component.scss']
25+
styleUrls: ['./entity-add-create-new.component.scss'],
26+
changeDetection: ChangeDetectionStrategy.OnPush,
2227
})
2328
export class EntityAddCreateNewComponent implements OnInit {
2429

2530
readonly basePath = ['information', 'entityCreateNew']
2631
getBasePath = () => this.basePath
2732
localStore: ObservableStore<IEntityCreateNewState>;
2833

29-
30-
@select() peItState$: Observable<IPeItState>;
31-
32-
peItToCreate: InfPersistentItem;
3334
loading: boolean = false;
3435
errorMessages: any;
3536

36-
isReadyToCreate: boolean;
37+
formGroup: FormGroup;
3738

38-
pkEntity: number;
39+
formCtrlName = 'persistent_item';
40+
41+
subs: Subscription[] = [];
3942

4043
constructor(
4144
private persistentItemApi: InfPersistentItemApi,
@@ -44,42 +47,79 @@ export class EntityAddCreateNewComponent implements OnInit {
4447
private slimLoadingBarService: SlimLoadingBarService,
4548
private ngRedux: NgRedux<IEntityCreateNewState>,
4649
private actions: EntityCreateNewActions,
47-
private stateCreator: StateCreatorService
50+
private stateCreator: StateCreatorService,
51+
private fb: FormBuilder,
52+
private ref: ChangeDetectorRef
4853
) {
4954
this.localStore = this.ngRedux.configureSubStore(this.basePath, entityCreateNewReducer);
5055

56+
this.formGroup = this.fb.group({})
57+
// subscribe to the form
58+
this.subs.push(this.formGroup.valueChanges.subscribe(val=>{
59+
if(this.formGroup.valid){
60+
this.onPeItReadyToCreate(val[this.formCtrlName])
61+
}else{
62+
this.onPeItNotReadyToCreate();
63+
}
64+
65+
}))
5166
}
5267

68+
5369
ngOnInit() {
5470

5571
this.modalService.previousState = EntityAddModalState[1];
5672

5773
this.modalService.modalTitle = "Create a new " + this.modalService.selectedClass.dfh_standard_label
5874

75+
this.modalService.addButtonVisible = false;
5976

60-
this.ngRedux.select<Project>('activeProject').subscribe(project => {
61-
this.stateCreator.initializePeItToCreate(this.modalService.selectedClass.dfh_pk_class).subscribe(peItState => {
62-
let wrapper = new EntityCreateNewState({
63-
peItState: peItState
64-
});
77+
// Init the state
78+
const sub1 = this.stateCreator.initializePeItToCreate(this.modalService.selectedClass.dfh_pk_class, this.modalService.searchString).subscribe(peItState => {
79+
let wrapper = new EntityCreateNewState({
80+
peItState: peItState
81+
});
6582

66-
this.localStore.dispatch(this.actions.entityCreateNewInitialized(wrapper));
83+
this.localStore.dispatch(this.actions.entityCreateNewInitialized(wrapper));
84+
})
85+
this.subs.push(sub1)
86+
87+
// wait for the peItState and activeProject to configure the form
88+
const sub2 = Observable.combineLatest(
89+
this.localStore.select<IPeItState>('peItState'),
90+
this.ngRedux.select<Project>('activeProject')
91+
).subscribe(results => {
92+
const peItState = results[0], project = results[1];
93+
if (peItState) {
94+
95+
this.formGroup.addControl(this.formCtrlName, new FormControl(
96+
peItState.peIt,
97+
[
98+
Validators.required
99+
]
100+
))
101+
102+
this.ref.detectChanges();
103+
}
104+
105+
106+
//TEMP
107+
// let epr = new  InfEntityProjectRel;
108+
// epr.fk_project = project.pk_project;
109+
// StateToDataService.peItStateToPeItToRelate(peItState, epr)
110+
})
67111

68-
this.modalService.addButtonVisible = true;
112+
this.subs.push(sub2)
69113

70-
//TEMP
71-
// let epr = new  InfEntityProjectRel;
72-
// epr.fk_project = project.pk_project;
73-
// StateToDataService.peItStateToPeItToRelate(peItState, epr)
74-
75-
this.peItState$.subscribe(d => this.modalService.peItStateToAdd = d)
76-
})
77-
})
114+
// this.peItState$.subscribe(d => this.modalService.peItStateToAdd = d)
78115

79116

80117
}
81118

82119
ngOnDestroy() {
120+
this.ref.detach()
121+
this.subs.forEach(sub => { sub.unsubscribe() })
122+
83123
this.localStore.dispatch(this.actions.entityCreateNewDestroyed())
84124
}
85125

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,6 @@ export class PeItEntityAddComponent implements OnInit {
4343

4444

4545
constructor(
46-
// peItApi: InfPersistentItemApi,
47-
// peItService: PeItService,
48-
// propertyPipe: PropertyPipe,
49-
// activePeItService: ActivePeItService,
50-
// slimLoadingBarService: SlimLoadingBarService,
51-
// entityEditor: EntityEditorService,
52-
// changeDetector: ChangeDetectorRef,
53-
// actions: PeItActions,
54-
// ngRedux: NgRedux<IPeItState>,
55-
// classService: ClassService,
56-
// roleService: RoleService,
57-
// propertyService: PropertyService,
58-
// private router: Router,
59-
// private route: ActivatedRoute,
60-
// roleSetListService: RoleSetListService
6146
private modalService: NgbModal,
6247
private entityAddModalService: EntityAddModalService
6348
) {

0 commit comments

Comments
 (0)