Merge branch 'angular2' of
https://git.curisit.net/gitblit/git/common/securis into angular2
# Conflicts:
# securis/src/main/webapp/src/app/app.module2.ts
| .. | .. |
|---|
| 1 | 1 | |
|---|
| 2 | 2 | import { Component, Injectable, Input } from '@angular/core'; |
|---|
| 3 | +import { Response } from '@angular/http'; |
|---|
| 3 | 4 | import { LocaleService } from './i18n'; |
|---|
| 4 | 5 | import { Observable } from 'rxjs/Observable'; |
|---|
| 5 | 6 | |
|---|
| .. | .. |
|---|
| 42 | 43 | |
|---|
| 43 | 44 | constructor(protected $L: LocaleService) { } |
|---|
| 44 | 45 | |
|---|
| 46 | + public setViewData(callback: any) { |
|---|
| 47 | + setTimeout(callback, 0); |
|---|
| 48 | + } |
|---|
| 49 | + |
|---|
| 45 | 50 | public processErrorResponse(errorResponse: Response) { |
|---|
| 46 | 51 | // In a real world app, we might use a remote logging infrastructure |
|---|
| 47 | 52 | var error: IError = <IError>{}; |
|---|
| .. | .. |
|---|
| 91 | 91 | } |
|---|
| 92 | 92 | |
|---|
| 93 | 93 | 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 | + }); |
|---|
| 96 | 98 | !!this.route && this.route.params.subscribe(params => { |
|---|
| 97 | 99 | var eleId = params[idparam]; |
|---|
| 98 | 100 | 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) ; |
|---|
| 108 | 105 | }); |
|---|
| 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 | + }); |
|---|
| 110 | 118 | } |
|---|
| 111 | 119 | }); |
|---|
| 112 | 120 | } |
|---|
| .. | .. |
|---|
| 130 | 130 | this.packs.get(packId).subscribe( |
|---|
| 131 | 131 | packData => { |
|---|
| 132 | 132 | this.pack = packData; |
|---|
| 133 | + if (this.isNew) { |
|---|
| 134 | + this.data.metadata = packData.metadata; |
|---|
| 135 | + } |
|---|
| 133 | 136 | }, |
|---|
| 134 | 137 | err => console.error(err) |
|---|
| 135 | 138 | ); |
|---|
| .. | .. |
|---|
| 54 | 54 | this.applications.get(this.data.application_id) |
|---|
| 55 | 55 | .map(app_data => this._prepareMetadata(app_data.metadata)) |
|---|
| 56 | 56 | .subscribe( |
|---|
| 57 | | - metadata => this.data.metadata = metadata, |
|---|
| 57 | + metadata => super.setViewData(() => this.data.metadata = metadata), |
|---|
| 58 | 58 | err => console.error('Error loading application metadata') |
|---|
| 59 | 59 | ); |
|---|
| 60 | 60 | } |
|---|
| .. | .. |
|---|
| 65 | 65 | this.applications.get() |
|---|
| 66 | 66 | .map(list => list.map((app : any) => <IComboOption>{id: app.id, label: `(${app.code}) ${app.name}`})) |
|---|
| 67 | 67 | .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))), |
|---|
| 69 | 69 | err => console.error('Error loading applications') |
|---|
| 70 | 70 | ); |
|---|
| 71 | 71 | } |
|---|
| .. | .. |
|---|
| 80 | 80 | super.reset(); |
|---|
| 81 | 81 | super.prepareInitialData('licensetypeId', { |
|---|
| 82 | 82 | metadata: [] |
|---|
| 83 | | - }, (data) => this._prepareMetadata(data.metadata)); |
|---|
| 83 | + }, (data) => super.setViewData(() => this._prepareMetadata(data.metadata))); |
|---|
| 84 | 84 | } |
|---|
| 85 | 85 | |
|---|
| 86 | 86 | ngAfterViewInit(): void { |
|---|
| .. | .. |
|---|
| 27 | 27 | private packs: PacksService, |
|---|
| 28 | 28 | router: Router, |
|---|
| 29 | 29 | toaster: ToastsManager, |
|---|
| 30 | | - route: ActivatedRoute, |
|---|
| 30 | + route: ActivatedRoute, |
|---|
| 31 | 31 | $L: LocaleService, |
|---|
| 32 | 32 | dialogs: TdDialogService) { |
|---|
| 33 | 33 | super($L, router, route, toaster, packs, $L.get('pack'), dialogs); |
|---|
| .. | .. |
|---|
| 37 | 37 | this.http.get('organization') |
|---|
| 38 | 38 | .map(response => response.json().map((org : any) => <IComboOption>{id: org.id, label: `(${org.code}) ${org.name}`})) |
|---|
| 39 | 39 | .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))), |
|---|
| 41 | 41 | err => console.error('Error loading orgs') |
|---|
| 42 | 42 | ); |
|---|
| 43 | 43 | this.licenseTypes.get() |
|---|
| 44 | 44 | .map(list => list.map((lt : any) => <IComboOption>{id: lt.id, label: `(${lt.code}) ${lt.name}`})) |
|---|
| 45 | 45 | .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))), |
|---|
| 47 | 47 | err => console.error('Error loading license types') |
|---|
| 48 | 48 | ); |
|---|
| 49 | 49 | } |
|---|
| .. | .. |
|---|
| 57 | 57 | this.licenseTypes.get(this.data.license_type_id) |
|---|
| 58 | 58 | .map(lt_data => lt_data.metadata) |
|---|
| 59 | 59 | .subscribe( |
|---|
| 60 | | - metadata => this.data.metadata = metadata, |
|---|
| 60 | + metadata => super.setViewData(() => this.data.metadata = metadata), |
|---|
| 61 | 61 | err => { |
|---|
| 62 | 62 | console.error('Error loading license type metadata'); |
|---|
| 63 | 63 | console.error(err); |
|---|
| .. | .. |
|---|
| 94 | 94 | init(): void { |
|---|
| 95 | 95 | this.loadCombos(); |
|---|
| 96 | 96 | super.prepareInitialData('packId', { |
|---|
| 97 | | - status: PACK_STATUS.CREATED |
|---|
| 97 | + status: PACK_STATUS.CREATED, |
|---|
| 98 | + frozen: false |
|---|
| 98 | 99 | }); |
|---|
| 99 | 100 | } |
|---|
| 100 | 101 | } |
|---|