Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Schemas Inventory |
| 3 | */ |
| 4 | import { Component, Input, OnInit } from '@angular/core'; |
| 5 | import { Schema } from './schema'; |
| 6 | import { SchemasService } from './schemas.service' |
| 7 | |
| 8 | @Component({ |
| 9 | selector : 'inventorySchemas', |
| 10 | templateUrl : './schemas.component.html', |
Radek Krejci | b479496 | 2017-09-21 14:16:28 +0200 | [diff] [blame] | 11 | styleUrls : ['../netopeer.css', './inventory.component.css'], |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 12 | providers: [SchemasService] |
| 13 | }) |
| 14 | |
| 15 | export class InventorySchemasComponent implements OnInit { |
| 16 | schemas: Schema[]; |
| 17 | @Input() selectedSchema: Schema; |
| 18 | addingSchema = false; |
| 19 | addingResult = -1; |
| 20 | constructor(private schemasService: SchemasService) { } |
| 21 | |
| 22 | getSchemas(): void { |
| 23 | this.schemasService.getSchemas().subscribe(schemas => this.schemas = schemas); |
| 24 | } |
| 25 | |
| 26 | showAddSchema() { |
| 27 | this.addingSchema = !this.addingSchema; |
| 28 | this.addingResult = -1; |
| 29 | } |
| 30 | |
| 31 | upload(schema: File) { |
| 32 | if (!schema) { |
| 33 | /* do nothing */ |
| 34 | return; |
| 35 | } |
| 36 | |
Radek Krejci | c58f347 | 2017-09-08 16:17:01 +0200 | [diff] [blame] | 37 | /* upload the schema file to the server, if success the schema list is refreshed */ |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 38 | this.schemasService.addSchema(schema).subscribe( |
Radek Krejci | c58f347 | 2017-09-08 16:17:01 +0200 | [diff] [blame] | 39 | result => {this.addingResult = result['success'] ? 1 : 0; this.getSchemas()}); |
| 40 | } |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 41 | |
Radek Krejci | c58f347 | 2017-09-08 16:17:01 +0200 | [diff] [blame] | 42 | remove(schema: Schema) { |
| 43 | this.schemasService.rmSchema(schema).subscribe( |
| 44 | result => {if (result['success']) { this.getSchemas()}}); |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | ngOnInit(): void { |
| 48 | this.getSchemas(); |
| 49 | } |
| 50 | |
| 51 | onSelect(schema: Schema): void { |
| 52 | this.selectedSchema = schema; |
| 53 | } |
| 54 | } |