From 62118179ffd2380a72369a3659f97328836a97b6 Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Thu, 2 Jul 2020 17:06:47 +0300 Subject: [PATCH] Update the cost listing (near finalization) and fix some issues while loading costs from the backend --- .../add-cost/add-cost.component.ts | 2 +- .../cost-listing/cost-listing.component.html | 16 ++++++++-- .../cost-listing/cost-listing.component.ts | 30 +++++++++++++------ .../extra-properties-form.model.ts | 6 ++-- .../general-tab/general-tab.component.html | 2 +- .../general-tab/general-tab.component.scss | 4 +++ 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/dmp-frontend/src/app/ui/dmp/editor/cost-editor/add-cost/add-cost.component.ts b/dmp-frontend/src/app/ui/dmp/editor/cost-editor/add-cost/add-cost.component.ts index e6f8d57e7..7a4da0f75 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/cost-editor/add-cost/add-cost.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/cost-editor/add-cost/add-cost.component.ts @@ -23,7 +23,7 @@ export class AddCostComponent extends BaseComponent implements OnInit { initialItems: () => this.searchCurrency(''), displayFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name, titleFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name, - valueAssign: (item) => typeof (item) == 'string' ? JSON.parse(item)['value'] : item.value + valueAssign: (item) => JSON.stringify(item) }; constructor( diff --git a/dmp-frontend/src/app/ui/dmp/editor/cost-editor/cost-listing/cost-listing.component.html b/dmp-frontend/src/app/ui/dmp/editor/cost-editor/cost-listing/cost-listing.component.html index 1fb26780b..8ed92f09d 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/cost-editor/cost-listing/cost-listing.component.html +++ b/dmp-frontend/src/app/ui/dmp/editor/cost-editor/cost-listing/cost-listing.component.html @@ -9,20 +9,30 @@
- +
- +
- +
+
+
+
+
+
+
+
+
+
+
diff --git a/dmp-frontend/src/app/ui/dmp/editor/cost-editor/cost-listing/cost-listing.component.ts b/dmp-frontend/src/app/ui/dmp/editor/cost-editor/cost-listing/cost-listing.component.ts index 1272e51c6..16bbc9a89 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/cost-editor/cost-listing/cost-listing.component.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/cost-editor/cost-listing/cost-listing.component.ts @@ -1,12 +1,13 @@ import { Component, OnInit, Input } from '@angular/core'; import { BaseComponent } from '@common/base/base.component'; -import { FormArray } from '@angular/forms'; +import { FormArray, FormControl } from '@angular/forms'; import { takeUntil } from 'rxjs/operators'; import { CostModel } from '@app/core/model/dmp/cost'; import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration'; import { CurrencyService } from '@app/core/services/currency/currency.service'; import { Observable } from 'rxjs'; import { LocalFetchModel } from '@app/core/model/local-fetch/local-fetch.model'; +import { CostEditorModel } from '../add-cost/add-cost.model'; @Component({ selector: 'app-cost-listing', @@ -17,14 +18,14 @@ export class CostListingComponent extends BaseComponent implements OnInit { @Input() form: FormArray; - costs: CostModel[] = []; + private cost: CostEditorModel[] = []; currencyAutoCompleteConfiguration: SingleAutoCompleteConfiguration = { filterFn: this.searchCurrency.bind(this), initialItems: () => this.searchCurrency(''), displayFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name, titleFn: (item) => typeof (item) == 'string' ? JSON.parse(item)['name'] : item.name, - valueAssign: (item) => this.getValue(item) + valueAssign: (item) => JSON.stringify(item) }; constructor( @@ -34,18 +35,29 @@ export class CostListingComponent extends BaseComponent implements OnInit { } ngOnInit() { - this.form.valueChanges.pipe(takeUntil(this._destroyed)).subscribe(value => { - this.costs = value; - }); } searchCurrency(like: string): Observable { return this.currencyService.get(like); } - getValue(item: any): any { - console.log(item); - return item; +switchEditMode(event: number) { + const control = this.form.at(event); + if (control.disabled) { + this.cost[event] = control.value; + control.enable(); + } else { + control.disable(); } +} + +removeCost(event: number) { + this.form.removeAt(event); +} + +revertEdits(event: number) { + this.form.at(event).setValue(this.cost[event]); + this.form.at(event).disable(); +} } diff --git a/dmp-frontend/src/app/ui/dmp/editor/general-tab/extra-properties-form.model.ts b/dmp-frontend/src/app/ui/dmp/editor/general-tab/extra-properties-form.model.ts index 8124cc5d5..8ef442501 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/general-tab/extra-properties-form.model.ts +++ b/dmp-frontend/src/app/ui/dmp/editor/general-tab/extra-properties-form.model.ts @@ -20,7 +20,9 @@ export class ExtraPropertiesFormModel { this.publicDate = item.publicDate; this.contact = item.contact; if (!isNullOrUndefined(item.costs)) { - this.costs = item.costs; + (item.costs).forEach(element => { + this.costs.push(new CostEditorModel().fromModel(element)); + }); } return this; } @@ -40,7 +42,7 @@ export class ExtraPropertiesFormModel { const costArray = new Array(); //if (this.externalDatasets && this.externalDatasets.length > 0) { this.costs.forEach(item => { - costArray.push(item.buildForm(context.getValidation('externalDatasets').descendantValidations, disabled)); + costArray.push(item.buildForm(context.getValidation('costs').descendantValidations, disabled)); }); // } else { // //externalDatasetsFormArray.push(new ExternalDatasetModel().buildForm(context.getValidation('externalDatasets').descendantValidations, disabled)); diff --git a/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.html b/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.html index 2d85e7ccc..78852a3a6 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.html +++ b/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.html @@ -143,7 +143,7 @@
Costs -
diff --git a/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.scss b/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.scss index 595aabb5c..322c63d34 100644 --- a/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.scss +++ b/dmp-frontend/src/app/ui/dmp/editor/general-tab/general-tab.component.scss @@ -41,3 +41,7 @@ .cost-placeholder { text-decoration: underline; } + +.cost-add { + margin-top: 1em; +}