| .. | .. |
|---|
| 10 | 10 | import { FormBase, IComboOption } from './base'; |
|---|
| 11 | 11 | import { ActivatedRoute, Router } from '@angular/router'; |
|---|
| 12 | 12 | |
|---|
| 13 | | -var app_example = { |
|---|
| 14 | | - code: 'CICS', |
|---|
| 15 | | - creation_timestamp: 1418384439000, |
|---|
| 16 | | - description: 'Wellbore integrity analysis software', |
|---|
| 13 | +var lt_example = { |
|---|
| 17 | 14 | id: 1, |
|---|
| 18 | | - license_filename: 'config_server.lic', |
|---|
| 19 | | - name: 'CurisIntegrity', |
|---|
| 20 | | - metadata: |
|---|
| 21 | | - [ { key: 'max_docs', |
|---|
| 22 | | - value: '250000', |
|---|
| 23 | | - readonly: true, |
|---|
| 24 | | - mandatory: true } ] |
|---|
| 15 | + code: 'CI01', |
|---|
| 16 | + name: 'CI ConfigServer ext', |
|---|
| 17 | + application_id: 1, |
|---|
| 18 | + application_name: 'CurisIntegrity', |
|---|
| 19 | + creation_timestamp: 1418384535000, |
|---|
| 20 | + description: 'CI ConfigServer with extended mode and 50 lines', |
|---|
| 21 | + metadata: [ { key: 'max_docs', value: '250000', mandatory: true } ] |
|---|
| 25 | 22 | } |
|---|
| 23 | + |
|---|
| 26 | 24 | |
|---|
| 27 | 25 | @Component({ |
|---|
| 28 | 26 | selector: 'licensetype-form', |
|---|
| 29 | 27 | templateUrl: 'src/app/forms/licensetype.form.html' |
|---|
| 30 | 28 | }) |
|---|
| 31 | 29 | export class LicenseTypeFormComponent extends FormBase { |
|---|
| 32 | | - |
|---|
| 30 | + |
|---|
| 31 | + allApplications: IComboOption[]; |
|---|
| 33 | 32 | constructor(private http: Http, |
|---|
| 34 | 33 | private licenseTypes: LicenseTypesService, |
|---|
| 35 | 34 | private applications: ApplicationsService, |
|---|
| .. | .. |
|---|
| 41 | 40 | super($L, router, route, toaster, licenseTypes, $L.get('license type'), dialogs); |
|---|
| 42 | 41 | } |
|---|
| 43 | 42 | |
|---|
| 44 | | - |
|---|
| 43 | + private _prepareMetadata(metadata : any[]) : any[] { |
|---|
| 44 | + metadata.forEach((md : any) => { |
|---|
| 45 | + if (md.value !== null && md.value !== '') { |
|---|
| 46 | + md.readonly = true; |
|---|
| 47 | + } |
|---|
| 48 | + }); |
|---|
| 49 | + return metadata; |
|---|
| 50 | + } |
|---|
| 51 | + |
|---|
| 52 | + changeApplication(event: any) : void{ |
|---|
| 53 | + console.log(event); |
|---|
| 54 | + this.applications.get(this.data.application_id) |
|---|
| 55 | + .map(app_data => this._prepareMetadata(app_data.metadata)) |
|---|
| 56 | + .subscribe( |
|---|
| 57 | + metadata => this.data.metadata = metadata, |
|---|
| 58 | + err => console.error('Error loading application metadata') |
|---|
| 59 | + ); |
|---|
| 60 | + } |
|---|
| 61 | + |
|---|
| 62 | + |
|---|
| 63 | + |
|---|
| 64 | + loadCombos() : void { |
|---|
| 65 | + this.applications.get() |
|---|
| 66 | + .map(list => list.map((app : any) => <IComboOption>{id: app.id, label: `(${app.code}) ${app.name}`})) |
|---|
| 67 | + .subscribe( |
|---|
| 68 | + data => this.allApplications = (<IComboOption[]>data).sort((e1, e2) => e1.label.localeCompare(e2.label)), |
|---|
| 69 | + err => console.error('Error loading applications') |
|---|
| 70 | + ); |
|---|
| 71 | + } |
|---|
| 72 | + |
|---|
| 45 | 73 | goBack(): void { |
|---|
| 46 | 74 | this.router.navigate([`licensetypes`]); |
|---|
| 47 | 75 | } |
|---|
| 48 | 76 | |
|---|
| 49 | 77 | init() : void { |
|---|
| 78 | + this.loadCombos(); |
|---|
| 50 | 79 | super.setFirstFocus(); |
|---|
| 51 | 80 | super.reset(); |
|---|
| 52 | | - super.prepareInitialData('licenseTypeId', { |
|---|
| 81 | + super.prepareInitialData('licensetypeId', { |
|---|
| 53 | 82 | metadata: [] |
|---|
| 54 | | - }); |
|---|
| 83 | + }, (data) => this._prepareMetadata(data.metadata)); |
|---|
| 55 | 84 | } |
|---|
| 56 | 85 | |
|---|
| 57 | 86 | ngAfterViewInit(): void { |
|---|