diff --git a/src/operations/operation.module.ts b/src/operations/operation.module.ts index 1d60a6c..2fa0d98 100644 --- a/src/operations/operation.module.ts +++ b/src/operations/operation.module.ts @@ -2,8 +2,8 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { ReactiveFormsModule } from '@angular/forms'; import { HttpClientModule } from '@angular/common/http'; +import { FormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; import { NgLoggerModule, Level } from '@nsalaun/ng-logger'; @@ -22,15 +22,13 @@ import { OperationListComponent } from './operationList.component'; import { OperationNewComponent } from './operationNew.component'; import { OperationEditComponent } from './operationEdit.component'; import { OperationDeleteModalComponent } from './operationDeleteModal.component'; -import { OperationFormComponent } from './operationForm.component'; -import { OperationEditModalComponent } from './operationEditModal.component'; import { OperationRoutes } from './operation.states'; @NgModule({ imports: [ HttpClientModule, CommonModule, - ReactiveFormsModule, + FormsModule, RouterModule.forChild( OperationRoutes ), @@ -53,12 +51,9 @@ import { OperationRoutes } from './operation.states'; OperationEditComponent, OperationNewComponent, OperationDeleteModalComponent, - OperationFormComponent, - OperationEditModalComponent, ], entryComponents: [ OperationDeleteModalComponent, - OperationEditModalComponent, OperationListComponent, ] }) diff --git a/src/operations/operation.states.ts b/src/operations/operation.states.ts index 69ae329..b6de753 100644 --- a/src/operations/operation.states.ts +++ b/src/operations/operation.states.ts @@ -14,5 +14,5 @@ export const OperationRoutes: Routes = [{ component: OperationNewComponent, }, { path: 'account/:accountId/operations/:operationId/edit', - component: OperationEditComponent, + component: OperationNewComponent, }]; diff --git a/src/operations/operationNew.component.ts b/src/operations/operationNew.component.ts index 4395582..b3777b0 100644 --- a/src/operations/operationNew.component.ts +++ b/src/operations/operationNew.component.ts @@ -16,24 +16,86 @@ import { OperationFormComponent } from './operationForm.component'; template: `
- - -
+
+
+ -
- + - +
+ + The operation date is required. + +
+
+ +
+ + + + +
+ + The operation label is required. + +
+
+ +
+ + + + +
+ + The operation value is required. + +
+
+ +
+ + + + +
+ + The operation category is required. + +
+
+ + + + +
- ` + ` }) export class OperationNewComponent { - @ViewChild('operationForm') operationForm: OperationFormComponent; + public operation = new Operation(); constructor( private location: Location, @@ -44,18 +106,27 @@ export class OperationNewComponent { private operationService: OperationService ) {} + ngOnInit() { + let operationId = this.activatedRoute.snapshot.paramMap.get('operationId'); + + if (operationId) { + // Load Operation + this.operationService.get( + +operationId + ).subscribe((operation: Operation) => { + this.operation = operation; + + this.logger.info(operation); + }); + } else { + let accountId = this.activatedRoute.snapshot.paramMap.get('accountId'); + + this.operation.account_id = +accountId; + } + } + submit(): void { - let accountId = this.activatedRoute.snapshot.paramMap.get('accountId'); - let formModel = this.operationForm.form.value; - let operation = new Operation(); - - operation.account_id = +accountId; - operation.operation_date = formModel.operationDate; - operation.label = formModel.label; - operation.value = formModel.value; - operation.category = formModel.category; - - this.save(operation); + this.save(this.operation); } /* diff --git a/src/operations/operationRow.component.ts b/src/operations/operationRow.component.ts index 91bf263..2e158bc 100644 --- a/src/operations/operationRow.component.ts +++ b/src/operations/operationRow.component.ts @@ -41,11 +41,11 @@ import { OperationEditModalComponent } from './operationEditModal.component';
- +