rsanchez
2017-06-26 08e725754836fd4b98d7aabbb6488764a0f2469a
Merge branch 'angular2' of
https://git.curisit.net/gitblit/git/common/securis into angular2

# Conflicts:
# securis/src/main/webapp/src/app/app.module2.ts
5 files modified
changed files
securis/src/main/webapp/src/app/common/utils.ts patch | view | blame | history
securis/src/main/webapp/src/app/forms/base.ts patch | view | blame | history
securis/src/main/webapp/src/app/forms/license.form.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/forms/licensetype.form.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/forms/pack.form.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/common/utils.ts
....@@ -1,5 +1,6 @@
11
22 import { Component, Injectable, Input } from '@angular/core';
3
+import { Response } from '@angular/http';
34 import { LocaleService } from './i18n';
45 import { Observable } from 'rxjs/Observable';
56
....@@ -42,6 +43,10 @@
4243
4344 constructor(protected $L: LocaleService) { }
4445
46
+ public setViewData(callback: any) {
47
+ setTimeout(callback, 0);
48
+ }
49
+
4550 public processErrorResponse(errorResponse: Response) {
4651 // In a real world app, we might use a remote logging infrastructure
4752 var error: IError = <IError>{};
securis/src/main/webapp/src/app/forms/base.ts
....@@ -91,22 +91,30 @@
9191 }
9292
9393 protected prepareInitialData(idparam: string, default_values: any = {}, callback?: (data: any) => void) : void {
94
- this.form_title = this.$L.get('{} data', this.resourceName.capitalize());
95
- this.isNew = true;
94
+ super.setViewData(() => {
95
+ this.form_title = this.$L.get('{} data', this.resourceName.capitalize());
96
+ this.isNew = true;
97
+ });
9698 !!this.route && this.route.params.subscribe(params => {
9799 var eleId = params[idparam];
98100 if (!eleId) {
99
- this.data = {};
100
- Object.keys(default_values).forEach((k : string) => this.data[k] = default_values[k]);
101
- this.form_subtitle = this.$L.get('Create a new {}', this.resourceName) ;
102
- } else {
103
- this.isNew = false;
104
- this.resourceServices.get(eleId).subscribe(eleData => {
105
- this.data = eleData;
106
- Object.keys(default_values).forEach((k : string) => (this.data[k] === undefined) && (this.data[k] = default_values[k]));
107
- callback && callback(this.data);
101
+ super.setViewData(() => {
102
+ this.data = {};
103
+ Object.keys(default_values).forEach((k : string) => this.data[k] = default_values[k]);
104
+ this.form_subtitle = this.$L.get('Create a new {}', this.resourceName) ;
108105 });
109
- this.form_subtitle = this.$L.get('Modify the {} data', this.resourceName) ;
106
+ } else {
107
+ super.setViewData(() => {
108
+ this.isNew = false;
109
+ this.resourceServices.get(eleId).subscribe(eleData => {
110
+ super.setViewData(() => {
111
+ this.data = eleData;
112
+ Object.keys(default_values).forEach((k : string) => (this.data[k] === undefined) && (this.data[k] = default_values[k]));
113
+ callback && callback(this.data);
114
+ });
115
+ });
116
+ this.form_subtitle = this.$L.get('Modify the {} data', this.resourceName) ;
117
+ });
110118 }
111119 });
112120 }
securis/src/main/webapp/src/app/forms/license.form.component.ts
....@@ -130,6 +130,9 @@
130130 this.packs.get(packId).subscribe(
131131 packData => {
132132 this.pack = packData;
133
+ if (this.isNew) {
134
+ this.data.metadata = packData.metadata;
135
+ }
133136 },
134137 err => console.error(err)
135138 );
securis/src/main/webapp/src/app/forms/licensetype.form.component.ts
....@@ -54,7 +54,7 @@
5454 this.applications.get(this.data.application_id)
5555 .map(app_data => this._prepareMetadata(app_data.metadata))
5656 .subscribe(
57
- metadata => this.data.metadata = metadata,
57
+ metadata => super.setViewData(() => this.data.metadata = metadata),
5858 err => console.error('Error loading application metadata')
5959 );
6060 }
....@@ -65,7 +65,7 @@
6565 this.applications.get()
6666 .map(list => list.map((app : any) => <IComboOption>{id: app.id, label: `(${app.code}) ${app.name}`}))
6767 .subscribe(
68
- data => this.allApplications = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label)),
68
+ data => super.setViewData(() => this.allApplications = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label))),
6969 err => console.error('Error loading applications')
7070 );
7171 }
....@@ -80,7 +80,7 @@
8080 super.reset();
8181 super.prepareInitialData('licensetypeId', {
8282 metadata: []
83
- }, (data) => this._prepareMetadata(data.metadata));
83
+ }, (data) => super.setViewData(() => this._prepareMetadata(data.metadata)));
8484 }
8585
8686 ngAfterViewInit(): void {
securis/src/main/webapp/src/app/forms/pack.form.component.ts
....@@ -27,7 +27,7 @@
2727 private packs: PacksService,
2828 router: Router,
2929 toaster: ToastsManager,
30
- route: ActivatedRoute,
30
+ route: ActivatedRoute,
3131 $L: LocaleService,
3232 dialogs: TdDialogService) {
3333 super($L, router, route, toaster, packs, $L.get('pack'), dialogs);
....@@ -37,13 +37,13 @@
3737 this.http.get('organization')
3838 .map(response => response.json().map((org : any) => <IComboOption>{id: org.id, label: `(${org.code}) ${org.name}`}))
3939 .subscribe(
40
- data => this.organizations = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label)),
40
+ data => super.setViewData(() => this.organizations = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label))),
4141 err => console.error('Error loading orgs')
4242 );
4343 this.licenseTypes.get()
4444 .map(list => list.map((lt : any) => <IComboOption>{id: lt.id, label: `(${lt.code}) ${lt.name}`}))
4545 .subscribe(
46
- data => this.licensetypes = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label)),
46
+ data => super.setViewData(() => this.licensetypes = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label))),
4747 err => console.error('Error loading license types')
4848 );
4949 }
....@@ -57,7 +57,7 @@
5757 this.licenseTypes.get(this.data.license_type_id)
5858 .map(lt_data => lt_data.metadata)
5959 .subscribe(
60
- metadata => this.data.metadata = metadata,
60
+ metadata => super.setViewData(() => this.data.metadata = metadata),
6161 err => {
6262 console.error('Error loading license type metadata');
6363 console.error(err);
....@@ -94,7 +94,8 @@
9494 init(): void {
9595 this.loadCombos();
9696 super.prepareInitialData('packId', {
97
- status: PACK_STATUS.CREATED
97
+ status: PACK_STATUS.CREATED,
98
+ frozen: false
9899 });
99100 }
100101 }