blob: df2af1350b7e6187a4e43957dad102f9cf3ec842 [file] [log] [blame]
Radek Krejcid23f0df2017-08-31 16:34:49 +02001/*
2 * Schemas Inventory
3 */
4import { Component, Input, OnInit } from '@angular/core';
5import { Schema } from './schema';
6import { SchemasService } from './schemas.service'
7
8@Component({
9 selector : 'inventorySchemas',
10 templateUrl : './schemas.component.html',
Radek Krejcib4794962017-09-21 14:16:28 +020011 styleUrls : ['../netopeer.css', './inventory.component.css'],
Radek Krejcid23f0df2017-08-31 16:34:49 +020012 providers: [SchemasService]
13})
14
15export 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 Krejcic58f3472017-09-08 16:17:01 +020037 /* upload the schema file to the server, if success the schema list is refreshed */
Radek Krejcid23f0df2017-08-31 16:34:49 +020038 this.schemasService.addSchema(schema).subscribe(
Radek Krejcic58f3472017-09-08 16:17:01 +020039 result => {this.addingResult = result['success'] ? 1 : 0; this.getSchemas()});
40 }
Radek Krejcid23f0df2017-08-31 16:34:49 +020041
Radek Krejcic58f3472017-09-08 16:17:01 +020042 remove(schema: Schema) {
43 this.schemasService.rmSchema(schema).subscribe(
44 result => {if (result['success']) { this.getSchemas()}});
Radek Krejcid23f0df2017-08-31 16:34:49 +020045 }
46
47 ngOnInit(): void {
48 this.getSchemas();
49 }
50
51 onSelect(schema: Schema): void {
52 this.selectedSchema = schema;
53 }
54}