3 * Copyright (C) 2017-2018 "IoT.bzh"
4 * Author Sebastien Douheret <sebastien@iot.bzh>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import { Component, ViewEncapsulation, OnInit, isDevMode } from '@angular/core';
20 import { Observable } from 'rxjs/Observable';
21 import { LocalDataSource } from 'ng2-smart-table';
22 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
23 import { ConfirmModalComponent, EType } from '../../confirm/confirm-modal/confirm-modal.component';
24 import { SdkInstallComponent } from './sdk-install.component';
26 import { AlertService } from '../../../@core-xds/services/alert.service';
27 import { SdkService, ISdk, StatusType } from '../../../@core-xds/services/sdk.service';
28 import { ISdkMessage } from '../../../@core-xds/services/xdsagent.service';
30 interface ISdkMgt extends ISdk {
37 * - support install of multi SDKs (see settings.selectMode: 'multi')
38 * - add Uninstall button (use delete)
39 * - add (mouseover) to display description, date, size, ...
43 selector: 'xds-sdk-management',
44 templateUrl: 'sdk-management.component.html',
45 styleUrls: ['sdk-management.component.scss'],
46 encapsulation: ViewEncapsulation.None,
49 export class SdkManagementComponent implements OnInit {
52 source: LocalDataSource = new LocalDataSource();
59 delete: false, // TODO, add delete == uninstall
61 { name: 'install', title: '<i class="nb-plus"></i>' },
65 deleteButtonContent: '<i class="nb-trash"></i>',
69 name: { title: 'Name', editable: false },
70 profile: { title: 'Profile', editable: false, filter: { type: 'list', config: {} } },
71 arch: { title: 'Architecture', editable: false, filter: { type: 'list', config: {} } },
72 version: { title: 'Version', editable: false },
73 // TODO: add status when delete supported:
74 // status: { title: 'Status', editable: false },
75 link: { title: 'Link', editable: false, type: 'html', filter: false, width: '2%' },
80 private alert: AlertService,
81 private sdkSvr: SdkService,
82 private modalService: NgbModal,
87 this.sdkSvr.Sdks$.subscribe(sdks => {
92 if (sdks.length === 0) {
97 // only display not installed SDK
98 if (s.status !== StatusType.NOT_INSTALLED) {
101 profMap[s.profile] = s.profile;
102 archMap[s.arch] = s.arch;
104 const sm = <ISdkMgt>s;
107 sm.link = '<a href="' + s.url.substr(0, s.url.lastIndexOf('/')) + '" target="_blank" class="fa fa-external-link"></a>';
113 // Create new reference of settings object to trig ngOnChanges event in ng2-smart-table
114 // and consequently rebuild settings grid
115 this.settings = Object.assign({}, this.settings);
117 // Add text box filter for Profile and Arch columns
119 Object.keys(profMap).forEach(a => profList.push({ value: a, title: a }));
121 this.settings.columns.profile.filter = {
123 config: { selectText: 'Select...', list: profList },
127 Object.keys(archMap).forEach(a => archList.push({ value: a, title: a }));
129 this.settings.columns.arch.filter = {
131 config: { selectText: 'Select...', list: archList },
135 this.source.load(this.sdks);
140 onCustom(event): void {
141 if (event.action === 'install') {
142 const sdk = <ISdkMgt>event.data;
143 const modal = this.modalService.open(ConfirmModalComponent, {
146 container: 'nb-layout',
148 modal.componentInstance.title = 'Confirm SDK installation';
149 modal.componentInstance.type = EType.YesNo;
150 modal.componentInstance.question = `
151 Please confirm installation of <b>` + sdk.name + `'</b> SDK ?<br>
153 <i><small>(size: ` + sdk.size + `, date: ` + sdk.date + `)</small></i>`;
155 modal.result.then(res => {
157 const modalInstall = this.modalService.open(SdkInstallComponent, {
160 container: 'nb-layout',
162 modalInstall.componentInstance.sdk = sdk;
164 // Request installation
165 this.sdkSvr.install(sdk).subscribe(
168 modalInstall.dismiss('SDK install failure');
169 this.alert.error(err);
175 } else if (event.action === 'uninstall') {
179 /* tslint:disable:no-console */
181 console.error('onCustom: unknown event action: ', event);