diff --git a/app/components/base/form/form-base.ts b/app/components/base/form/form-base.ts index 62ac46a786..6106b17461 100644 --- a/app/components/base/form/form-base.ts +++ b/app/components/base/form/form-base.ts @@ -82,6 +82,9 @@ export class FormBase { public close() { this.done.emit(); const container = this.containerRef; + if (!container) { + return; + } if (container instanceof MdDialogRef) { container.close(); } else if (container instanceof SidebarRef) { diff --git a/app/components/base/form/simple-form/simple-form.component.ts b/app/components/base/form/simple-form/simple-form.component.ts index f55abb1e0e..ff09055780 100644 --- a/app/components/base/form/simple-form/simple-form.component.ts +++ b/app/components/base/form/simple-form/simple-form.component.ts @@ -1,4 +1,4 @@ -import { Component, Input } from "@angular/core"; +import { Component, EventEmitter, Input, Output } from "@angular/core"; import { FormGroup } from "@angular/forms"; import { Observable } from "rxjs"; @@ -13,6 +13,9 @@ import { ContainerRef } from "../form-base"; templateUrl: "simple-form.html", }) export class SimpleFormComponent { + @Output() + public done = new EventEmitter(); + @Input() public title: string; diff --git a/app/components/base/form/simple-form/simple-form.html b/app/components/base/form/simple-form/simple-form.html index 52f43786d7..c052d250e9 100644 --- a/app/components/base/form/simple-form/simple-form.html +++ b/app/components/base/form/simple-form/simple-form.html @@ -1,5 +1,5 @@ + [actionName]="actionName" [cancelText]="cancelText" [size]="size" [stickyFooter]="stickyFooter" (done)="done.emit()"> diff --git a/app/components/pool/start-task/start-task-edit-form.component.ts b/app/components/pool/start-task/start-task-edit-form.component.ts index 4762099a2a..fe3fac0ef4 100644 --- a/app/components/pool/start-task/start-task-edit-form.component.ts +++ b/app/components/pool/start-task/start-task-edit-form.component.ts @@ -45,6 +45,10 @@ export class StartTaskEditFormComponent { return this.form.controls["enableStartTask"].value; } + public closeForm() { + this.close.emit(); + } + @autobind() public submit() { const startTask = this.form.value.startTask; @@ -56,10 +60,11 @@ export class StartTaskEditFormComponent { }); } else { obs = this.poolService.getOnce(this.pool.id).cascade((pool) => { + const poolData = pool.toJS(); return this.poolService.replaceProperties(id, { - applicationPackageReferences: pool.applicationPackageReferences, - certificateReferences: pool.certificateReferences, - metadata: pool.metadata, + applicationPackageReferences: poolData.applicationPackageReferences || [], + certificateReferences: poolData.certificateReferences || [], + metadata: poolData.metadata || [], }); }); } diff --git a/app/components/pool/start-task/start-task-edit-form.html b/app/components/pool/start-task/start-task-edit-form.html index d60bcb6207..236fa3993d 100644 --- a/app/components/pool/start-task/start-task-edit-form.html +++ b/app/components/pool/start-task/start-task-edit-form.html @@ -1,6 +1,6 @@

Edit start task for pool: {{pool.id}}

- +
diff --git a/app/core/record/record.ts b/app/core/record/record.ts index b13616de74..6588ad845b 100644 --- a/app/core/record/record.ts +++ b/app/core/record/record.ts @@ -1,5 +1,6 @@ import { List, Map } from "immutable"; +import { nil } from "app/utils"; import { metadataForRecord, primitives } from "./helpers"; /** @@ -25,9 +26,27 @@ export class Record { } public toJS(): any { - return Object.assign({}, this._defaultValues, this._map.toJS()); + return Object.assign({}, this._defaultValues, this._toJS()); } + private _toJS() { + let output: any = {}; + const attrs = metadataForRecord(this); + for (let key of Object.keys(attrs)) { + if (!(key in this)) { + continue; + } + const value = this[key]; + if (nil(value)) { + output[key] = value; + } else if (value.toJS) { + output[key] = value.toJS(); + } else { + output[key] = value; + } + } + return output; + } /** * This method will be called by the decorator. */ diff --git a/app/models/pool.ts b/app/models/pool.ts index c45e85c88d..0a7ad1a62f 100644 --- a/app/models/pool.ts +++ b/app/models/pool.ts @@ -47,10 +47,10 @@ export class Pool extends Record { public allocationState: string; @Prop() public allocationStateTransitionTime: Date; - @Prop() - public applicationPackageReferences: any[]; - @Prop() - public certificateReferences: any[]; + @ListProp(Object) + public applicationPackageReferences: List; + @ListProp(Object) + public certificateReferences: List; @Prop() public cloudServiceConfiguration: CloudServiceConfiguration; @Prop() diff --git a/test/app/core/record.spec.ts b/test/app/core/record.spec.ts index 464236f87d..41f9eda01c 100644 --- a/test/app/core/record.spec.ts +++ b/test/app/core/record.spec.ts @@ -123,6 +123,12 @@ describe("Record", () => { expect(b.toJS()).toEqual({ id: "id-1", nested: { name: "name-1" }, nestedList: [{ name: "default-name" }] }); }); + it("toJS() should return compelex type toJS recursively", () => { + let a = new TestRec({ id: "id-1", nested: { name: "name-1" }, nestedList: [{ name: "name-2" }]}); + + expect(a.toJS()).toEqual({ id: "id-1", nested: { name: "name-1" }, nestedList: [{ name: "name-2" }]}); + }); + it("should have access to values in constructor", () => { @Model() class ComputedValueRec extends Record {