From 7ea40adbba8cc4564c5480e82df8480ad8541bf9 Mon Sep 17 00:00:00 2001 From: unknown <n.santhanam@redkarma.eu> Date: Wed, 17 Feb 2021 10:26:55 +0530 Subject: [PATCH] TMSS-494 Milliseconds updated on SU --- .../src/components/JSONEditor/JEditor.js | 14 +++---- .../tmss_webapp/src/utils/unit.converter.js | 41 ++++++++++++++----- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js b/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js index bb9f251c614..31430018464 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js @@ -5,12 +5,10 @@ /* eslint-disable react-hooks/exhaustive-deps */ import React, {useEffect, useRef} from 'react'; import _ from 'lodash'; -import flatpickr from 'flatpickr'; import UnitConverter from '../../utils/unit.converter' import $RefParser from "@apidevtools/json-schema-ref-parser"; import "@fortawesome/fontawesome-free/css/all.css"; import "flatpickr/dist/flatpickr.css"; -import UtilService from '../../services/util.service'; const JSONEditor = require("@json-editor/json-editor").JSONEditor; function Jeditor(props) { @@ -267,7 +265,7 @@ function Jeditor(props) { "cleave": { numericOnly: true, blocks: [2, 2, 2, 4], - delimiters: [':', ':','.'], + delimiters: isDegree ? [':', ':','.'] : [':', ':', ':'], delimiterLazyShow: true } } @@ -442,15 +440,15 @@ function Jeditor(props) { */ function validateTime(prpOutput) { const splitOutput = prpOutput.split(':'); - const isMilliSecondsPresent = prpOutput.split('.'); - if (splitOutput.length < 3 || isMilliSecondsPresent.length === 1 || isMilliSecondsPresent[1].length !== 4) { + const isMilliSecondsPresent = splitOutput[3]; + if (splitOutput.length < 3 || (isMilliSecondsPresent[1] && isMilliSecondsPresent[1].length > 4)) { // if (splitOutput.length < 3) { return false; } else { - if (parseInt(splitOutput[0]) > 23 || parseInt(splitOutput[1])>59 || parseInt(splitOutput[2])>59 || parseInt(splitOutput[3])>999) { + if (parseInt(splitOutput[0]) > 23 || parseInt(splitOutput[1])>59 || parseInt(splitOutput[2])>59) { return false; } - const timeValue = parseInt(splitOutput[0]*60*60) + parseInt(splitOutput[1]*60) + parseInt(splitOutput[2]*1000 + parseInt(splitOutput[3])); + const timeValue = parseInt(splitOutput[0]*60*60) + parseInt(splitOutput[1]*60) + parseInt(splitOutput[2]*1000); if (timeValue >= 86400) { return false; } @@ -465,7 +463,7 @@ function Jeditor(props) { function validateAngle(prpOutput) { const splitOutput = prpOutput.split(':'); const isMilliSecondsPresent = prpOutput.split('.'); - if (splitOutput.length < 3 || isMilliSecondsPresent.length === 1 || isMilliSecondsPresent[1].length !== 4) { + if (splitOutput.length < 3 || isMilliSecondsPresent[1].length > 4) { //if (splitOutput.length < 3) { return false; } else { diff --git a/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js b/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js index 082610cd832..4b848390ed0 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js @@ -64,22 +64,34 @@ const UnitConverter = { * Function to convert Angle 1 & 2 input value for UI. */ getAngleInput(prpInput, isDegree) { - if(prpInput){ + if (prpInput){ const degrees = prpInput * 180 / Math.PI; if (isDegree) { const dd = Math.floor(prpInput * 180 / Math.PI); const mm = Math.floor((degrees-dd) * 60); const ss = +((degrees-dd-(mm/60)) * 3600).toFixed(0); - const ssss = round(((degrees - dd - (mm/60) - (ss/3600)) * 3600000), 4) - return (dd<10?`0${dd}`:`${dd}`) + ':' + (mm<10?`0${mm}`:`${mm}`) + ':' + (ss<10?`0${ss}`:`${ss}`) + '.' + (ssss<10?`0${ssss}`:`${ssss}`); + const ssss = round(((degrees - dd - (mm/60) - (ss/3600)) * 36000000), 4); + let milliSeconds = (ssss * 10000).toString().substr(0,4); + if (milliSeconds < 1) { + milliSeconds = this.padDigits(milliSeconds.substr(1), 4); + } else { + milliSeconds = this.padDigits(milliSeconds, 4); + } + return (dd<10?`0${dd}`:`${dd}`) + ':' + (mm<10?`0${mm}`:`${mm}`) + ':' + (ss<10?`0${ss}`:`${ss}`) + '.' + milliSeconds; } else { const hh = Math.floor(degrees/15); const mm = Math.floor((degrees - (hh*15))/15 * 60 ); const ss = +((degrees -(hh*15)-(mm*15/60))/15 * 3600).toFixed(0); - const ssss = round(((degrees - (hh*15) - (mm/4) - (ss/240)) *240000),4); - return (hh<10?`0${hh}`:`${hh}`) + ':' + (mm<10?`0${mm}`:`${mm}`) + ':' + (ss<10?`0${ss}`:`${ss}`) + ':' + (ssss<10?`0${ssss}`:`${ssss}`); + const ssss = round(((degrees - (hh*15) - (mm/4) - (ss/240)) *2400000),4); + let milliSeconds = (ssss * 10000).toString().substr(0,4); + if (milliSeconds < 1) { + milliSeconds = this.padDigits(milliSeconds.substr(1), 4); + } else { + milliSeconds = this.padDigits(milliSeconds, 4); + } + return (hh<10?`0${hh}`:`${hh}`) + ':' + (mm<10?`0${mm}`:`${mm}`) + ':' + (ss<10?`0${ss}`:`${ss}`) + ':' + milliSeconds; } - }else{ + } else { return "00:00:00"; } }, @@ -90,16 +102,25 @@ const UnitConverter = { getAngleOutput(prpOutput, isDegree) { if(prpOutput){ const splitOutput = prpOutput.split(':'); + const milliSeconds = prpOutput.split('.')[1] || '0000'; if (isDegree) { - return ((splitOutput[0]*1 + splitOutput[1]/60 + splitOutput[2]/3600 + splitOutput[3]/3600000)*Math.PI/180); + return ((splitOutput[0]*1 + splitOutput[1]/60 + splitOutput[2].split('.')[0]/3600 + milliSeconds/36000000)*Math.PI/180); } else { - return ((splitOutput[0]*15 + splitOutput[1]/4 + splitOutput[2]/240 + splitOutput[3]/240000)*Math.PI/180); + return ((splitOutput[0]*15 + splitOutput[1]/4 + splitOutput[2]/240 + splitOutput[3]/2400000)*Math.PI/180); } }else{ return "00:00:00.0000"; } - + }, + + /** + * Function to add leading zeros in end + * @param {*} number + * @param {*} digits + */ + padDigits(number, digits) { + return number + Array(Math.max(digits - String(number).length + 1, 0)).join(0); } }; -export default UnitConverter; +export default UnitConverter; \ No newline at end of file -- GitLab