Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/components/base/form/form-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion app/components/base/form/simple-form/simple-form.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<bl-complex-form [submit]="submit" [containerRef]="containerRef" [multiUse]="multiUse" [actionName]="actionName" [actionColor]="actionColor"
[actionName]="actionName" [cancelText]="cancelText" [size]="size" [stickyFooter]="stickyFooter">
[actionName]="actionName" [cancelText]="cancelText" [size]="size" [stickyFooter]="stickyFooter" (done)="done.emit()">
<bl-form-page main-form-page [title]="title" [subtitle]="subtitle">
<bl-form-section>
<ng-content></ng-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 || [],
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/pool/start-task/start-task-edit-form.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="edit-form">
<h2>Edit start task for pool: {{pool.id}}</h2>
<bl-simple-form [formGroup]="form" [submit]="submit" saveText="Update" (done)="close.emit()">
<bl-simple-form [formGroup]="form" [submit]="submit" saveText="Update" (done)="closeForm()">
<form novalidate [formGroup]="form">
<div class="form-element">
<md-slide-toggle formControlName="enableStartTask" color="primary">
Expand Down
21 changes: 20 additions & 1 deletion app/core/record/record.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { List, Map } from "immutable";

import { nil } from "app/utils";
import { metadataForRecord, primitives } from "./helpers";

/**
Expand All @@ -25,9 +26,27 @@ export class Record<TInput> {
}

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.
*/
Expand Down
8 changes: 4 additions & 4 deletions app/models/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export class Pool extends Record<PoolAttributes> {
public allocationState: string;
@Prop()
public allocationStateTransitionTime: Date;
@Prop()
public applicationPackageReferences: any[];
@Prop()
public certificateReferences: any[];
@ListProp(Object)
public applicationPackageReferences: List<any>;
@ListProp(Object)
public certificateReferences: List<any>;
@Prop()
public cloudServiceConfiguration: CloudServiceConfiguration;
@Prop()
Expand Down
6 changes: 6 additions & 0 deletions test/app/core/record.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
Expand Down