From 7233fff1735bb9aacf7d970ddf286f38536d1be4 Mon Sep 17 00:00:00 2001 From: ori agranat Date: Mon, 9 Dec 2019 22:55:29 +0200 Subject: [PATCH] added regex test for camera name and pipe name --- chameleon-client/src/views/Camera.vue | 49 ++++++++++++++++++++------- 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/chameleon-client/src/views/Camera.vue b/chameleon-client/src/views/Camera.vue index 19ff1a24c..c07e33784 100644 --- a/chameleon-client/src/views/Camera.vue +++ b/chameleon-client/src/views/Camera.vue @@ -128,14 +128,16 @@ Pipeline Name - + - Save - Cancel + Save + + Cancel @@ -178,7 +180,7 @@ this.isCameraNameEdit = true; }, saveCameraNameChange() { - if (this.cameraNameError === "") { + if (this.checkCameraName === "") { this.handleInput("changeCameraName", this.newCameraName); this.discardCameraNameChange(); } @@ -198,12 +200,14 @@ this.namingDialog = true; }, savePipelineNameChange() { - if (this.isPipelineNameEdit) { - this.handleInput("changePipelineName", this.newPipelineName); - } else { - this.handleInput("addNewPipeline", this.newPipelineName); + if (this.checkPipelineName === "") { + if (this.isPipelineNameEdit) { + this.handleInput("changePipelineName", this.newPipelineName); + } else { + this.handleInput("addNewPipeline", this.newPipelineName); + } + this.discardPipelineNameChange(); } - this.discardPipelineNameChange(); }, discardPipelineNameChange() { this.namingDialog = false; @@ -262,11 +266,32 @@ }, computed: { checkCameraName() { + let re = new RegExp('^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$'); if (this.newCameraName !== this.cameraList[this.currentCameraIndex]) { - for (let cam in this.cameraList) { - if (this.newCameraName === this.cameraList[cam]) { - return "Camera by that name already Exists" + if (re.test(this.newCameraName)) { + for (let cam in this.cameraList) { + if (this.newCameraName === this.cameraList[cam]) { + return "Camera by that name already Exists" + } } + } else { + return "Camera name can only contain letters, numbers and spaces" + } + } + return "" + }, + checkPipelineName() { + let re = new RegExp('^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$'); + if (this.newPipelineName !== this.pipelineList[this.currentPipelineIndex - 1] || this.isPipelineNameEdit === false) { + if (re.test(this.newPipelineName)) { + for (let pipe in this.pipelineList) { + if (this.newPipelineName === this.pipelineList[pipe]) { + return "A pipeline with this name already exists" + } + } + + } else { + return "Pipeline name can only contain letters, numbers, and spaces" } } return ""