3 * Copyright (C) 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, Input, Pipe, PipeTransform } from '@angular/core';
20 import { TargetService, ITarget, TargetType, TargetTypeEnum, TargetTypes } from '../../../@core-xds/services/target.service';
21 import { AlertService } from '../../../@core-xds/services/alert.service';
22 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
23 import { ConfirmModalComponent, EType } from '../../confirm/confirm-modal/confirm-modal.component';
24 import { find } from 'rxjs/operator/find';
25 import { findIndex } from 'rxjs/operator/findIndex';
28 selector: 'xds-target-card',
29 styleUrls: ['./target-card.component.scss'],
30 templateUrl: './target-card.component.html',
32 export class TargetCardComponent {
34 // FIXME workaround of https://github.com/angular/angular-cli/issues/2034
35 // should be removed with angular 5
36 // @Input() target: ITarget;
37 @Input() target = <ITarget>null;
40 private alert: AlertService,
41 private targetSvr: TargetService,
42 private modalService: NgbModal,
46 delete(tgt: ITarget) {
48 const modal = this.modalService.open(ConfirmModalComponent, {
51 container: 'nb-layout',
53 modal.componentInstance.title = 'Confirm SDK deletion';
54 modal.componentInstance.type = EType.YesNo;
55 modal.componentInstance.question = `
56 Do you <b>permanently delete '` + tgt.name + `'</b> target ?
58 <i><small>(Target ID: ` + tgt.id + ` )</small></i>`;
63 this.targetSvr.delete(tgt).subscribe(
65 err => this.alert.error('ERROR delete: ' + err),
74 // Make Target type human readable
79 export class TargetReadableTypePipe implements PipeTransform {
80 transform(type: TargetTypeEnum): string {
81 const tt = TargetTypes.find(el => type === el.value);