X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=blueprints%2Fcommon%2Feliot-ui%2Ffrontend-src%2Fsrc%2Fapp%2Fdeployments%2Fdeployments.component.ts;h=bca3a91728333cc146776e439234b575eebe8ae1;hb=5c2048d4d3e672783eea4f306aa9a03f33a1a9f2;hp=553febdbceb856c1235eab63615a8a2b555ecf66;hpb=59f512662c02a16c1d5c45b090b185d2e773310f;p=eliot.git diff --git a/blueprints/common/eliot-ui/frontend-src/src/app/deployments/deployments.component.ts b/blueprints/common/eliot-ui/frontend-src/src/app/deployments/deployments.component.ts index 553febd..bca3a91 100644 --- a/blueprints/common/eliot-ui/frontend-src/src/app/deployments/deployments.component.ts +++ b/blueprints/common/eliot-ui/frontend-src/src/app/deployments/deployments.component.ts @@ -1,4 +1,13 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, TemplateRef } from '@angular/core'; +import { EliotserviceService } from '../eliotservice.service'; +import { deploymentData, nodeDeploy } from '../datainterface'; +import { FormBuilder, FormGroup } from '@angular/forms'; +import { ToolbarService } from './../toolbar/toolbar.service'; +import {MatTableDataSource} from '@angular/material/table'; + +import { YAML } from 'yaml'; + +import { ToastService } from './toast.service'; @Component({ selector: 'app-deployments', @@ -6,10 +15,184 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./deployments.component.scss'] }) export class DeploymentsComponent implements OnInit { + host: {'[class.ngb-toasts]': 'true'} + isLinear = false; + fileContent: string = ''; + deployParam = false; + + isTemplate(toast) { return toast.textOrTpl instanceof TemplateRef; } + fileData: File = null; + previewFile: any = null; + deployData = {} as deploymentData; + uploadForm: FormGroup; + deployForm: FormGroup; + typePanelOpenState = false; + + nodeSelected: string; + nodesArray: string[]; + nodes: string[] = []; + nodeLabelMentioned: string; + + nodeDetails = {} as nodeDeploy; - constructor() { } + constructor( + private serviceobj: EliotserviceService, + private formBuilder: FormBuilder, + public toolbarService: ToolbarService, + public toastService: ToastService + ) { } ngOnInit() { + this.toolbarService.show(); + this.typePanelOpenState = false; + this.uploadForm = this.formBuilder.group( + { + yamlfile: [''], + sample: [''], + } + ); + this.deployForm = this.formBuilder.group( + { + // sampleone: [''], + // sampletwo: [''], + // samplethree: [''], + // samplefour: [''], + deployyamlfile: [''] + } + ); + + this.getNodes(); + + } + + fileProgress(event) { + debugger; + + if(event.target.files.length > 0 ){ + const deployfile = event.target.files[0]; + let filee = event.target.files[0]; + // this.uploadForm.get('yamlfile').setValue(file); + this.deployForm.get('deployyamlfile').setValue(deployfile); + // this.uploadForm.get('sample'); + debugger; + // var reader = new FileReader(); + // reader.readAsDataURL(deployfile); + let filecon: string = ''; + // reader.onload = (_event) => { + // // this.previewFile = reader.result; + // this.previewFile = reader.readAsText.toString; + + // console.log("Preview File"); + // console.log(this.previewFile); + // } + + let fileReader: FileReader = new FileReader(); + + // fileReader.onloadend = function(x) { + // // fileContent = fileReader.result; + // fileReader.result; + // } + // fileReader.readAsText(deployfile); + debugger; + console.log(YAML.parse(deployfile)); + debugger; + + // this.fileContent = fileReader.result.toString; + + } + + + console.log("Inside fileProgress...") + // this.fileData = fileInput.target.files[0]; + // console.log(this.fileData); } + + onSubmit() { + console.log("Inside onSubmit() ....") + const formData = new FormData(); + // formData.append('file',this.uploadForm.get('yamlfile').value); + // formData.append('sss',this.deployForm.get('sampleone').value); + // formData.append('ssa',this.deployForm.get('sampletwo').value); + // formData.append('ssb',this.deployForm.get('samplethree').value); + // formData.append('ssc',this.deployForm.get('samplefour').value); + formData.append('deployfile',this.deployForm.get('deployyamlfile').value); + // formData.append('sample',this.formBuilder.) + debugger; + // this.deployData.deployFile = formData.get('yamlfile'); + // this.deployData.deployFile = formData.get('deployyamlfile'); + this.deployData.deployFile = this.deployForm.value.deployyamlfile; + console.log("deploydata..."); + console.log(this.deployData); + console.log("formData...."); + console.log(formData); + // formData.append('file', this.fileData); + // this.deployData.deployFile = formData.get('yamlfile') + console.log(this.deployForm.value); + debugger; + this.serviceobj.postDeploymentPackage(formData) + .subscribe(data => { + console.log(data); + this.showSuccess(); + // console.log(data); + } + ,error => console.log(error) + ); + // this.http.post('url/to/your/api', formData) + // .subscribe(res => { + // console.log(res); + // alert('SUCCESS !!'); + // }) + // this.showSuccess(); + } + + showSuccess() { + this.toastService.show('Application ( csar ) package uploaded Successfully', { classname: 'bg-success text-light', delay: 10000 }); + } + + deploySuccess() { + this.deployParam = true; + this.serviceobj.postDeployRequest(this.deployParam,this.nodeDetails) + .subscribe(data => { + console.log(data); + this.toastService.show('ELIOT IOT Application / Yaml deployed Successfully', { classname: 'bg-success text-light', delay: 10000 }); + } + ,error => console.log(error) + ); + + + } + + getNodes() { + this.serviceobj.getNodesArray() + .subscribe(data => { + debugger; + console.log(data); + data.nodesArray.forEach( + nodeData => { + debugger; + this.nodes.push(nodeData.value); + + }); + + // this.sessionArr.forEach(data => { + // if (data.month == m) { + // this.january.push(data); + // this.historyDataSource = new MatTableDataSource(this.january); + // } + // }) + + console.log(this.nodesArray); + debugger; + // this.nodewise = data; + // this.nodesArray = this.nodewise.nodesArray; + }, + error => console.log(error)); + } + + addNodeDetails() { + this.nodeDetails.deployNodeLabel = this.nodeLabelMentioned; + debugger; + this.nodeDetails.deployNodeName = this.nodeSelected; + } }