1 import { Component, OnInit, TemplateRef } from '@angular/core';
2 import { EliotserviceService } from '../eliotservice.service';
3 import { deploymentData, nodeDeploy } from '../datainterface';
4 import { FormBuilder, FormGroup } from '@angular/forms';
5 import { ToolbarService } from './../toolbar/toolbar.service';
6 import {MatTableDataSource} from '@angular/material/table';
8 import { YAML } from 'yaml';
10 import { ToastService } from './toast.service';
13 selector: 'app-deployments',
14 templateUrl: './deployments.component.html',
15 styleUrls: ['./deployments.component.scss']
17 export class DeploymentsComponent implements OnInit {
18 host: {'[class.ngb-toasts]': 'true'}
20 fileContent: string = '';
23 isTemplate(toast) { return toast.textOrTpl instanceof TemplateRef; }
24 fileData: File = null;
25 previewFile: any = null;
26 deployData = {} as deploymentData;
27 uploadForm: FormGroup;
28 deployForm: FormGroup;
29 typePanelOpenState = false;
34 nodeLabelMentioned: string;
36 nodeDetails = {} as nodeDeploy;
39 private serviceobj: EliotserviceService,
40 private formBuilder: FormBuilder,
41 public toolbarService: ToolbarService,
42 public toastService: ToastService
46 this.toolbarService.show();
47 this.typePanelOpenState = false;
48 this.uploadForm = this.formBuilder.group(
54 this.deployForm = this.formBuilder.group(
71 if(event.target.files.length > 0 ){
72 const deployfile = event.target.files[0];
73 let filee = event.target.files[0];
74 // this.uploadForm.get('yamlfile').setValue(file);
75 this.deployForm.get('deployyamlfile').setValue(deployfile);
76 // this.uploadForm.get('sample');
78 // var reader = new FileReader();
79 // reader.readAsDataURL(deployfile);
80 let filecon: string = '';
81 // reader.onload = (_event) => {
82 // // this.previewFile = reader.result;
83 // this.previewFile = reader.readAsText.toString;
85 // console.log("Preview File");
86 // console.log(this.previewFile);
89 let fileReader: FileReader = new FileReader();
91 // fileReader.onloadend = function(x) {
92 // // fileContent = fileReader.result;
95 // fileReader.readAsText(deployfile);
97 console.log(YAML.parse(deployfile));
100 // this.fileContent = fileReader.result.toString;
105 console.log("Inside fileProgress...")
106 // this.fileData = <File>fileInput.target.files[0];
107 // console.log(this.fileData);
111 console.log("Inside onSubmit() ....")
112 const formData = new FormData();
114 // formData.append('file',this.uploadForm.get('yamlfile').value);
115 // formData.append('sss',this.deployForm.get('sampleone').value);
116 // formData.append('ssa',this.deployForm.get('sampletwo').value);
117 // formData.append('ssb',this.deployForm.get('samplethree').value);
118 // formData.append('ssc',this.deployForm.get('samplefour').value);
119 formData.append('deployfile',this.deployForm.get('deployyamlfile').value);
120 // formData.append('sample',this.formBuilder.)
122 // this.deployData.deployFile = formData.get('yamlfile');
123 // this.deployData.deployFile = formData.get('deployyamlfile');
124 this.deployData.deployFile = this.deployForm.value.deployyamlfile;
125 console.log("deploydata...");
126 console.log(this.deployData);
127 console.log("formData....");
128 console.log(formData);
129 // formData.append('file', this.fileData);
130 // this.deployData.deployFile = formData.get('yamlfile')
131 console.log(this.deployForm.value);
133 this.serviceobj.postDeploymentPackage(formData)
137 // console.log(data);
139 ,error => console.log(error)
141 // this.http.post('url/to/your/api', formData)
142 // .subscribe(res => {
144 // alert('SUCCESS !!');
146 // this.showSuccess();
150 this.toastService.show('Application ( csar ) package uploaded Successfully', { classname: 'bg-success text-light', delay: 10000 });
154 this.deployParam = true;
155 this.serviceobj.postDeployRequest(this.deployParam,this.nodeDetails)
158 this.toastService.show('ELIOT IOT Application / Yaml deployed Successfully', { classname: 'bg-success text-light', delay: 10000 });
160 ,error => console.log(error)
167 this.serviceobj.getNodesArray()
171 data.nodesArray.forEach(
174 this.nodes.push(nodeData.value);
178 // this.sessionArr.forEach(data => {
179 // if (data.month == m) {
180 // this.january.push(data);
181 // this.historyDataSource = new MatTableDataSource(this.january);
185 console.log(this.nodesArray);
187 // this.nodewise = data;
188 // this.nodesArray = this.nodewise.nodesArray;
190 error => console.log(error));
194 this.nodeDetails.deployNodeLabel = this.nodeLabelMentioned;
196 this.nodeDetails.deployNodeName = this.nodeSelected;