--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+import { Component, EventEmitter, Input, OnInit, Output, ViewChild, ElementRef, OnDestroy } from '@angular/core';\r
+import { MatDialog, MatSnackBar } from '@angular/material';\r
+import { SelectTestHeadModalComponent } from '../select-test-head-modal/select-test-head-modal.component';\r
+import { GroupService } from '../../services/group.service';\r
+import { TestDefinitionService } from '../../services/test-definition.service';\r
+import { AlertModalComponent } from '../alert-modal/alert-modal.component';\r
+import { Alert } from 'selenium-webdriver';\r
+import { ListService } from '../../services/list.service';\r
+import { AlertSnackbarComponent } from '../alert-snackbar/alert-snackbar.component';\r
+import { TestHeadService } from 'app/shared/services/test-head.service';\r
+import { FileUploader, FileItem, ParsedResponseHeaders } from 'ng2-file-upload';\r
+import { AppGlobals } from 'app/app.global';\r
+import { HttpHeaders } from '@angular/common/http';\r
+import { CookieService } from 'ngx-cookie-service';\r
+import { stringify } from '@angular/core/src/render3/util';\r
+import Modeler from 'bpmn-js';\r
+import { FileService } from 'app/shared/services/file.service';\r
+import { FileTransferService } from 'app/shared/services/file-transfer.service';\r
+import { TestDefinition } from './test-definition.class';\r
+import { connectableObservableDescriptor } from 'rxjs/internal/observable/ConnectableObservable';\r
+import { Buffer } from 'buffer';\r
+import { ViewWorkflowModalComponent } from '../view-workflow-modal/view-workflow-modal.component';\r
+import { BpmnFactoryService } from 'app/shared/factories/bpmn-factory.service';\r
+import { Bpmn } from 'app/shared/models/bpmn.model';\r
+\r
+\r
+@Component({\r
+ selector: 'app-create-test-form',\r
+ templateUrl: './create-test-form.component.pug',\r
+ styleUrls: ['./create-test-form.component.scss']\r
+})\r
+export class CreateTestFormComponent implements OnInit, OnDestroy {\r
+\r
+\r
+ public codeConfig = {\r
+ mode: 'yaml',\r
+ theme: 'eclipse',\r
+ lineNumbers: true\r
+ };\r
+\r
+ public trackByFn;\r
+\r
+ public selectedTestHead;\r
+ public groups;\r
+ public isUploading;\r
+ public successUpload = false;\r
+ public processDefinitionKey = false;\r
+ public validateResponse;\r
+ public pStatus;\r
+ public file: File;\r
+ public hasBeenSaved = false;\r
+ public saved = false;\r
+ public isClicked;\r
+ public isZip = true;\r
+ public viewer: Bpmn;\r
+ public scriptFiles = [];\r
+ public existingTd;\r
+\r
+ @ViewChild('testDefinitionForm') form: any;\r
+ @ViewChild('canvas') canvas;\r
+ @ViewChild('scripts') scripts: ElementRef;\r
+ @ViewChild('file') bpmnFileInput: ElementRef;\r
+\r
+ @Input() public listKey;\r
+\r
+ @Input() public formData;\r
+\r
+ @Output() public childEvent = new EventEmitter();\r
+\r
+ public uploader: FileUploader;\r
+ public bpmnUploader: FileUploader;\r
+\r
+ public inProgress = false;\r
+\r
+ // New variables\r
+ public ptd: TestDefinition;\r
+ public isNew = true;\r
+\r
+ constructor(\r
+ public dialog: MatDialog,\r
+ private list: ListService,\r
+ private testHead: TestHeadService,\r
+ private group: GroupService,\r
+ private testDefinition: TestDefinitionService,\r
+ private snack: MatSnackBar,\r
+ private cookie: CookieService,\r
+ private fileTransfer: FileTransferService,\r
+ private fileService: FileService,\r
+ private bpmnFactory: BpmnFactoryService\r
+ ) { }\r
+\r
+ print(){\r
+ console.log(this.ptd);\r
+ }\r
+\r
+ async ngOnInit() {\r
+ //this.setNew();\r
+\r
+ this.viewer = await this.bpmnFactory.setup({\r
+ mode: 'viewer',\r
+ options: {\r
+ container: this.canvas.nativeElement\r
+ }\r
+ })\r
+ \r
+ this.ptd = new TestDefinition();\r
+ this.ptd.reset();\r
+ this.ptd.switchVersion();\r
+\r
+ let uploadOptions = {\r
+ url: AppGlobals.baseAPIUrl + 'file-transfer',\r
+ authTokenHeader: 'Authorization',\r
+ authToken: 'Bearer ' + JSON.parse(this.cookie.get('access_token'))\r
+ };\r
+\r
+ //File Uploaders\r
+ this.uploader = new FileUploader(uploadOptions);\r
+ this.bpmnUploader = new FileUploader(uploadOptions);\r
+\r
+ if (this.formData && this.formData !== 'new') {\r
+ this.hasBeenSaved = true;\r
+ this.successUpload = true;\r
+ this.isNew = false;\r
+ this.setTestDefinition();\r
+ }\r
+\r
+ this.group.find({$limit: -1}).subscribe((x) => {\r
+ this.groups = x;\r
+ });\r
+\r
+ }\r
+\r
+ ngOnDestroy(){\r
+ \r
+ }\r
+\r
+ waitSave(){\r
+ return new Promise((resolve, reject) => {\r
+ console.log('waitsave')\r
+ //upload bpmn file\r
+ this.saveBpmnFile().then(bpmnFile => {\r
+ console.log(bpmnFile)\r
+ console.log('pass save bpmnfile')\r
+ this.checkTestDataTemplate();\r
+\r
+ let data = this.gatherTestDefinition(bpmnFile);\r
+ console.log(data)\r
+ //If this is not a new version\r
+ if(!this.existingTd){\r
+ delete data._id;\r
+ \r
+ this.create(data).then(\r
+ result => {\r
+ resolve(result);\r
+ this.setTestDefinition(result);\r
+ this.showHasBeenSaved();\r
+ }\r
+ ).catch(err => {\r
+ reject(err);\r
+ this.showHasNotBeenSaved();\r
+ });\r
+ }else{\r
+ //create version by updating definition\r
+ this.saveVersion(data).then(\r
+ result => {\r
+ resolve(result);\r
+ this.setTestDefinition(result);\r
+ this.showHasBeenSaved();\r
+ }\r
+ ).catch(err => {\r
+ reject(err);\r
+ this.showHasNotBeenSaved();\r
+ });\r
+ }\r
+ });\r
+ })\r
+ }\r
+ \r
+ // Saves Test Definition - Triggered by "Save" button\r
+ save() {\r
+ //set in progress\r
+ this.inProgress = true;\r
+ return this.waitSave();\r
+\r
+ }\r
+\r
+ // Updates Test Definition - Triggered by "Update" button\r
+ update() {\r
+ this.inProgress = true;\r
+ return this.saveBpmnFile().then(bpmnFile => {\r
+ this.checkTestDataTemplate();\r
+\r
+ var data = this.gatherTestDefinition(bpmnFile);\r
+\r
+ return this.testDefinition.patch(data)\r
+ .subscribe(\r
+ result => {\r
+ this.uploadResources(result).then(\r
+ res => {\r
+ this.setTestDefinition(res);\r
+ this.showHasBeenUpdated();\r
+ }\r
+ );\r
+ return result;\r
+ },\r
+ error => {\r
+ this.showHasNotBeenUpdated(error);\r
+ }\r
+ );\r
+ });\r
+ }\r
+\r
+ deleteVersion(){\r
+ let deleteDialog = this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: { type: 'confirmation', message: 'Are you sure you want to delete version ' + this.ptd.currentVersionName }\r
+ });\r
+\r
+ deleteDialog.afterClosed().subscribe(\r
+ result => {\r
+ if(result){\r
+ this.inProgress = true;\r
+ if(this.ptd.bpmnInstances.length == 1){\r
+ this.testDefinition.delete(this.ptd._id).subscribe(\r
+ result => {\r
+ this.childEvent.emit();\r
+ }\r
+ )\r
+ }else{\r
+ this.ptd.removeBpmnInstance(this.ptd.currentVersionName);\r
+ this.update().then(\r
+ res => {\r
+ this.inProgress = false;\r
+ }\r
+ );\r
+ }\r
+ }\r
+ }\r
+ )\r
+ }\r
+\r
+ // Deploys Test Definition version - Triggerd by "Deploy" button\r
+ deploy(versionName?) {\r
+ this.inProgress = true;\r
+ //console.log(this.ptd)\r
+ this.testDefinition.deploy(this.ptd, versionName)\r
+ .subscribe(result => {\r
+ \r
+ this.handleResponse(result);\r
+ this.inProgress = false;\r
+ if (result['statusCode'] == 200) {\r
+ this.snack.openFromComponent(AlertSnackbarComponent, {\r
+ duration: 1500,\r
+ data: {\r
+ message: 'Test Definition Deployed!'\r
+ }\r
+ });\r
+ this.ptd.currentInstance.isDeployed = true;\r
+ } else {\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: {\r
+ type: 'Alert',\r
+ message: JSON.stringify(result)\r
+ }\r
+ });\r
+ }\r
+ },\r
+ err => {\r
+ this.inProgress = false;\r
+ }\r
+\r
+ );\r
+ }\r
+\r
+ create(data){\r
+ return new Promise((resolve, reject) => {\r
+ this.testDefinition.create(data)\r
+ .subscribe(\r
+ result => {\r
+ this.uploadResources(result).then(\r
+ res => {\r
+ resolve(res);\r
+ }\r
+ );\r
+ },\r
+ error => {\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: {\r
+ type: 'Alert',\r
+ message: JSON.stringify(error)\r
+ }\r
+ });\r
+ reject(error);\r
+ }\r
+ );\r
+ });\r
+ }\r
+\r
+ newVersion(processDefinitionKey){\r
+ this.hasBeenSaved = false;\r
+ this.isNew = true;\r
+ this.ptd.reset();\r
+ this.ptd.switchVersion();\r
+ this.ptd.setProcessDefinitionKey(processDefinitionKey);\r
+ }\r
+\r
+ checkProcessDefinitionKey() {\r
+ this.pStatus = 'loading';\r
+ this.testDefinition.check(this.ptd.getProcessDefinitionKey()).subscribe(result => {\r
+ console.log(result);\r
+ if (result['statusCode'] == 200) {\r
+ this.pStatus = 'unique';\r
+ } else {\r
+ this.pStatus = 'notUnique';\r
+ }\r
+\r
+ this.ptd.bpmnInstances = this.ptd.bpmnInstances.filter((e, i) => {\r
+ return i == 0;\r
+ })\r
+ \r
+ // this.ptd.bpmnInstances.forEach((elem, val) => {\r
+ // if(val > 0){\r
+ // this.ptd.bpmnInstances.splice(val, 1);\r
+ // }\r
+ // })\r
+\r
+ //New Code\r
+ if(result['body'] && result['body'][0]){\r
+ //when changing bpmn dont\r
+ //if(this.ptd.currentInstance.isDeployed){\r
+ let res = result['body'][0];\r
+ this.existingTd = true;\r
+ this.ptd.setId(res._id);\r
+ this.ptd.setName(res.testName);\r
+ this.ptd.setDescription(res.testDescription);\r
+ this.ptd.setGroupId(res.groupId);\r
+ this.ptd.setVersion(res.bpmnInstances.length + 1);\r
+ //this.ptd.bpmnInstances = [];\r
+\r
+ for(let i = 0; i < res.bpmnInstances.length; i++){\r
+ this.ptd.addBpmnInstance(res.bpmnInstances[i]);\r
+ }\r
+\r
+ \r
+ //this.ptd.addBpmnInstance (res.bpmnInstances);\r
+ //}\r
+ }else{\r
+ this.existingTd = false;\r
+ this.ptd.setId(null);\r
+ this.ptd.setName('');\r
+ this.ptd.setDescription('');\r
+ this.ptd.setGroupId('');\r
+ this.ptd.setVersion(1);\r
+ }\r
+\r
+ if(!this.ptd.currentInstance.version){\r
+ this.ptd.setNewVersion();\r
+ }\r
+\r
+ });\r
+ }\r
+\r
+ validateFile() {\r
+\r
+ this.isUploading = true\r
+ this.fetchFileContents(val => {\r
+ //\r
+ this.ptd.currentInstance.bpmnXml = val;\r
+ if (!this.ptd.currentInstance.bpmnXml) {\r
+ this.isUploading = false;\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: {\r
+ type: 'Alert',\r
+ message: 'File was not selected. Please try again.'\r
+ }\r
+ });\r
+ return null;\r
+ }\r
+ \r
+ this.testDefinition.validate(this.ptd.getAll())\r
+ .subscribe(\r
+ result => {\r
+ this.handleResponse(result);\r
+ //\r
+ this.isUploading = false;\r
+ this.ptd.currentInstance.bpmnHasChanged = true;\r
+ this.loadDiagram();\r
+ },\r
+ err => {\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: {\r
+ type: 'Alert',\r
+ message: 'Something went wrong. Please try again'\r
+ }\r
+ });\r
+ this.isUploading = false;\r
+ }\r
+ );\r
+ });\r
+\r
+\r
+ }\r
+\r
+ showHasNotBeenSaved(){\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: {\r
+ type: 'Alert',\r
+ message: 'There was a problem with saving the test definition.'\r
+ }\r
+ });\r
+ this.inProgress = false;\r
+ }\r
+\r
+ showHasBeenSaved(){\r
+ this.snack.openFromComponent(AlertSnackbarComponent, {\r
+ duration: 1500,\r
+ data: {\r
+ message: 'Test Definition Saved!'\r
+ }\r
+ });\r
+ //this.switchVersion();\r
+ this.ptd.switchVersion();\r
+ this.hasBeenSaved = true;\r
+ this.saved = true;\r
+ this.form.form.markAsPristine();\r
+ this.inProgress = false;\r
+ }\r
+\r
+ showHasBeenUpdated(){\r
+ this.snack.openFromComponent(AlertSnackbarComponent, {\r
+ duration: 1500,\r
+ data: {\r
+ message: 'Test Definition Updated!'\r
+ }\r
+ });\r
+ //this.switchVersion();\r
+ this.ptd.switchVersion(this.ptd.currentInstance.version);\r
+ this.saved = true;\r
+ this.form.form.markAsPristine();\r
+ this.ptd.currentInstance.bpmnHasChanged = false;\r
+ this.inProgress = false;\r
+ }\r
+\r
+ showHasNotBeenUpdated(error = null){\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: {\r
+ type: 'Alert',\r
+ message: JSON.stringify(error)\r
+ }\r
+ });\r
+ this.inProgress = false;\r
+ }\r
+\r
+ setTestDefinition(data = null){\r
+ //new\r
+ if(data){\r
+ \r
+ this.ptd.setAll(data);\r
+ }else{\r
+ this.ptd.setAll(JSON.parse(JSON.stringify(this.formData)));\r
+ }\r
+\r
+ this.switchVersion();\r
+\r
+ //console.log(this.ptd);\r
+ \r
+ }\r
+\r
+ clearQueue(){\r
+ this.uploader.clearQueue();\r
+ if(this.scripts){\r
+ this.scripts.nativeElement.value = null;\r
+ }\r
+ }\r
+\r
+ switchVersion(versionName = null){\r
+ this.ptd.switchVersion(versionName);\r
+ this.checkTestDataTemplate();\r
+\r
+ this.clearQueue();\r
+ this.bpmnFileInput.nativeElement.value = null;\r
+\r
+ //Get bpmn file contents\r
+ this.fileTransfer.get(this.ptd.currentInstance.bpmnFileId).subscribe(\r
+ result => {\r
+ result = new Buffer(result as Buffer);\r
+ this.ptd.currentInstance.bpmnXml = result.toString();\r
+ this.loadDiagram();\r
+ }\r
+ );\r
+\r
+ //get info on resource file\r
+ if(this.ptd.currentInstance.resourceFileId){\r
+ this.fileService.get(this.ptd.currentInstance.resourceFileId).subscribe(\r
+ result => {\r
+ this.ptd.currentInstance.resourceFileName = result['filename'];\r
+ }\r
+ )\r
+ }\r
+\r
+ if(this.ptd.currentInstance.testHeads){\r
+ this.ptd.currentInstance.dataTestHeads = [];\r
+ this.ptd.currentInstance.testHeads.forEach((elem, val) => {\r
+ //Find test head info\r
+ const e = elem;\r
+ this.testHead.get(e.testHeadId).subscribe(\r
+ result => {\r
+ this.ptd.currentInstance.dataTestHeads.push({\r
+ testHeadId: e.testHeadId,\r
+ bpmnVthTaskId: e.bpmnVthTaskId,\r
+ testHead: JSON.parse(JSON.stringify(result))\r
+ });\r
+ },\r
+ err => {\r
+ this.ptd.currentInstance.dataTestHeads.push({\r
+ testHeadId: e.testHeadId,\r
+ bpmnVthTaskId: e.bpmnVthTaskId,\r
+ testHead: { _id: e.testHeadId, testHeadName: 'No Access' }\r
+ });\r
+ }\r
+ );\r
+ });\r
+ }\r
+ }\r
+\r
+ gatherTestDefinition(bpmnFile = null) {\r
+\r
+ if(bpmnFile){\r
+ this.ptd.currentInstance.bpmnFileId = bpmnFile._id;\r
+ }\r
+\r
+ this.ptd.currentInstance.testHeads = [];\r
+ this.ptd.currentInstance.dataTestHeads.forEach((elem, val) => {\r
+ this.ptd.currentInstance.testHeads.push({\r
+ testHeadId: elem.testHead._id,\r
+ bpmnVthTaskId: elem.bpmnVthTaskId\r
+ });\r
+ });\r
+\r
+ return this.ptd.getAll();\r
+ \r
+ }\r
+\r
+ saveDeploy() {\r
+ let version = JSON.parse(JSON.stringify(this.ptd.currentInstance.version));\r
+ console.log(version)\r
+ this.save().then(x => {\r
+ this.deploy(version);\r
+ });\r
+ }\r
+\r
+ updateDeploy() {\r
+ let version = JSON.parse(JSON.stringify(this.ptd.currentInstance.version));\r
+ this.update().then(x => {\r
+ this.deploy(version);\r
+ });\r
+ }S\r
+\r
+ handleResponse(result) {\r
+ this.successUpload = true;\r
+ this.processDefinitionKey = false;\r
+ //this.validateResponse = result;\r
+ if (result['body']['errors']) {\r
+\r
+\r
+ if (result['body']['errors']['processDefinitionKey']) {\r
+ this.openProcessDefinitionKeyModal();\r
+ this.pStatus = 'notUnique';\r
+ this.ptd.setProcessDefinitionKey(result['body'].errors.processDefinitionKey.key)\r
+ //this.td.processDefinitionKey = result['body']['errors']['processDefinitionKey']['key'];\r
+ this.processDefinitionKey = true;\r
+ }\r
+ if (result['body']['errors']['notFound']) {\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: { type: 'alert', message: result['body']['errors']['notFound']['error'] }\r
+ });\r
+ this.successUpload = false;\r
+ }\r
+ if (result['body']['errors']['startEvent']) {\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: { type: 'alert', message: result['body']['errors']['startEvent']['error'] }\r
+ });\r
+ this.successUpload = false;\r
+ }\r
+ if (result['body']['errors']['required']) {\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: { type: 'alert', message: result['body']['errors']['required']['error'] }\r
+ });\r
+ this.successUpload = false;\r
+ }\r
+ if (result['body']['errors']['permissions']) {\r
+ let mess = '';\r
+ result['body']['errors']['permissions'].forEach(elem => {\r
+ mess += elem.error + '\n';\r
+ })\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: { type: 'alert', message: mess }\r
+ });\r
+ this.successUpload = false;\r
+ }\r
+\r
+ }else{\r
+ this.markAsDirty();\r
+ }\r
+ // Update list of test heads\r
+ if (result['body']['bpmnVthTaskIds']) {\r
+ this.ptd.currentInstance.dataTestHeads = result['body'].bpmnVthTaskIds;\r
+ this.ptd.currentInstance.testHeads = [];\r
+ //this.definitionInstance.testHeads = result['body']['bpmnVthTaskIds'];\r
+ }\r
+\r
+ //Update plfos list\r
+ if(result['body']['bpmnPfloTaskIds']){\r
+ this.ptd.currentInstance.pflos = result['body'].bpmnPfloTaskIds;\r
+ }\r
+\r
+ if (result['body']['processDefinitionKey']) {\r
+ this.ptd.setProcessDefinitionKey(result['body'].processDefinitionKey);\r
+ //this.td.processDefinitionKey = result['body']['processDefinitionKey'];\r
+ this.checkProcessDefinitionKey()\r
+ }\r
+ }\r
+\r
+ markAsDirty() {\r
+ this.form.control.markAsDirty();\r
+ }\r
+\r
+ //returns promise for file object \r
+ saveBpmnFile() {\r
+ return new Promise((resolve, reject) => {\r
+\r
+ //check for bpmnXml\r
+ if (!this.ptd.currentInstance.bpmnXml) {\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: {\r
+ type: 'Alert',\r
+ message: 'No File found. Please select a file to upload'\r
+ }\r
+ });\r
+ reject();\r
+ }\r
+\r
+ if(this.ptd.currentInstance.bpmnHasChanged){\r
+ // Upload\r
+ console.log('validate save call')\r
+ this.testDefinition.validateSave(this.ptd).subscribe(\r
+ result => {\r
+ resolve(JSON.parse(result.toString())[0]);\r
+ }\r
+ );\r
+ }else{\r
+ //bpmn has not changed, so did not save it.\r
+ resolve(null);\r
+ }\r
+ });\r
+ }\r
+\r
+ saveVersion(data){\r
+ return new Promise((resolve, reject) => {\r
+\r
+ let newBpmnInsance = JSON.parse(JSON.stringify(data.bpmnInstances[0]));\r
+ delete data.bpmnInstances;\r
+ data['$push'] = {\r
+ bpmnInstances: newBpmnInsance\r
+ }\r
+\r
+ console.log(data)\r
+\r
+ this.testDefinition.patch(data).subscribe(\r
+ result => {\r
+ this.uploadResources(result).then(\r
+ res => {\r
+ resolve(res);\r
+ }\r
+ )\r
+ },\r
+ err => {\r
+ reject(err);\r
+ }\r
+ )\r
+ });\r
+ }\r
+\r
+ uploadResources(td){\r
+ return new Promise((resolve, reject) => {\r
+ if(this.uploader.queue.length > 0){\r
+ //console.log('has file');\r
+ this.uploader.uploadAll();\r
+ this.uploader.onCompleteItem = (item: FileItem, response: string, status: Number, headers: ParsedResponseHeaders) => {\r
+ this.scriptFiles.push(JSON.parse(response)[0]);\r
+ //console.log('in file')\r
+ }\r
+ this.uploader.onCompleteAll = () => {\r
+ //console.log('complete')\r
+ let scriptFilesId = [];\r
+ for (let i = 0; i < this.scriptFiles.length; i++) {\r
+ scriptFilesId.push(this.scriptFiles[i]['_id']);\r
+ }\r
+ td['bpmnInstances'][this.ptd.currentVersion]['resourceFileId'] = scriptFilesId[0];\r
+ //console.log(td);\r
+ this.testDefinition.patch(td).subscribe(\r
+ res => {\r
+ //console.log(res);\r
+ resolve(res);\r
+ },\r
+ err => {\r
+ reject(err);\r
+ }\r
+ );\r
+ }\r
+ }else{\r
+ resolve(td);\r
+ }\r
+ });\r
+ }\r
+\r
+ checkTestDataTemplate() {\r
+ if (this.ptd.currentInstance.testDataTemplate == null || this.ptd.currentInstance.testDataTemplate == '') {\r
+ delete this.ptd.currentInstance.testDataTemplate;\r
+ }\r
+ // if (this.definitionInstance.testDataTemplate == null || this.definitionInstance.testDataTemplate == '') {\r
+ // delete this.definitionInstance.testDataTemplate;\r
+ // }\r
+ }\r
+\r
+ async loadDiagram() {\r
+ if (this.ptd.currentInstance.bpmnXml) {\r
+ //render xml and display\r
+ this.viewer.setBpmnXml(this.ptd.currentInstance.bpmnXml);\r
+ // if (!this.viewer) {\r
+ // this.viewer = new Modeler({\r
+ // container: this.canvas.nativeElement\r
+ // });\r
+ // }\r
+\r
+ // this.viewer.importXML(this.ptd.currentInstance.bpmnXml, (err) => {\r
+ // if (!err) {\r
+ // this.viewer.get('canvas').zoom('fit-viewport');\r
+ // } else {\r
+ // //\r
+ // }\r
+ // });\r
+\r
+ }\r
+ }\r
+\r
+ enlargeBpmn(){\r
+ this.dialog.open(ViewWorkflowModalComponent, {\r
+ data: {\r
+ xml: this.ptd.currentInstance.bpmnXml\r
+ },\r
+ width: '100%',\r
+ height: '100%'\r
+ })\r
+ }\r
+\r
+ fetchFileContents(callback) {\r
+ var val = "x";\r
+ var fileToLoad = (document.getElementById('file'))['files'][0];\r
+ var fileReader = new FileReader();\r
+ if (!fileToLoad) {\r
+ return null;\r
+ }\r
+ fileReader.onload = function (event) {\r
+ //\r
+ val = event.target['result'] as string;\r
+\r
+ //\r
+ callback(val);\r
+ }\r
+ fileReader.readAsText(fileToLoad);\r
+ }\r
+\r
+ openProcessDefinitionKeyModal() {\r
+ const dialogRef = this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: { type: 'warning', message: 'You cannot use this process definition key. Please change it.' }\r
+ });\r
+ }\r
+\r
+ checkVersionUnique(){\r
+ let exists = false;\r
+ this.ptd.bpmnInstances.forEach(elem => {\r
+ if(elem != this.ptd.currentInstance && elem.version == this.ptd.currentInstance.version){\r
+ exists = true;\r
+ }\r
+ });\r
+\r
+ if(exists){\r
+ this.form.controls['version'].setErrors({error: 'Version Already Exists'});\r
+ }else{\r
+ this.form.controls['version'].setErrors(null);\r
+ }\r
+ }\r
+\r
+}
\ No newline at end of file