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 db176a3dec57157b173ab4491ecc03722c2a2200..80552d80e7059f28dee4491223c79ab6484e9bdc 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/components/JSONEditor/JEditor.js @@ -13,12 +13,13 @@ const JSONEditor = require("@json-editor/json-editor").JSONEditor; function Jeditor(props) { // console.log("In JEditor"); const editorRef = useRef(null); + let pointingProps = useRef(null); let editor = null; useEffect(() => { const element = document.getElementById('editor_holder'); let schema = {}; Object.assign(schema, props.schema?props.schema:{}); - + pointingProps = []; // Customize the pointing property to capture angle1 and angle2 to specified format for (const definitionKey in schema.definitions) { if (definitionKey === 'pointing') { @@ -42,7 +43,6 @@ function Jeditor(props) { // Customize datatype of certain properties like subbands, duration, etc., getCustomProperties(schema.properties); - schema.title = props.title; const subbandValidator = validateSubbandOutput; const timeValidator = validateTime; @@ -89,6 +89,7 @@ function Jeditor(props) { disable_edit_json: true, disable_properties: true, disable_collapse: true, + show_errors: props.errorsOn?props.errorsOn:'change', // Can be 'interaction', 'change', 'always', 'never' compact: true }; // Set Initial value to the editor @@ -290,6 +291,9 @@ function Jeditor(props) { options.grid_columns = 9; propertyValue.options = options; } + if (propertyValue['$ref'] && propertyValue['$ref'].endsWith("/pointing")) { + pointingProps.push(propertyKey); + } getCustomProperties(propertyValue); } } @@ -303,7 +307,7 @@ function Jeditor(props) { for (const inputKey in editorInput) { const inputValue = editorInput[inputKey]; if (inputValue instanceof Object) { - if (inputKey.endsWith('pointing')) { + if (_.indexOf(pointingProps, inputKey) >= 0) { inputValue.angle1 = getAngleInput(inputValue.angle1); inputValue.angle2 = getAngleInput(inputValue.angle2, true); } else if (inputKey === 'subbands') { @@ -327,7 +331,7 @@ function Jeditor(props) { for (const outputKey in editorOutput) { let outputValue = editorOutput[outputKey]; if (outputValue instanceof Object) { - if (outputKey.endsWith('pointing')) { + if (_.indexOf(pointingProps, outputKey) >= 0) { outputValue.angle1 = getAngleOutput(outputValue.angle1, false); outputValue.angle2 = getAngleOutput(outputValue.angle2, true); } else { @@ -355,21 +359,11 @@ function Jeditor(props) { const dd = Math.floor(prpInput * 180 / Math.PI); const mm = Math.floor((degrees-dd) * 60); const ss = +((degrees-dd-(mm/60)) * 3600).toFixed(0); - /*return { - dd: dd, - mm: mm, - ss: ss - }*/ return (dd<10?`0${dd}`:`${dd}`) + ':' + (mm<10?`0${mm}`:`${mm}`) + ':' + (ss<10?`0${ss}`:`${ss}`); } 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); - /*return { - hh: hh, - mm: mm, - ss: ss - }*/ return (hh<10?`0${hh}`:`${hh}`) + ':' + (mm<10?`0${mm}`:`${mm}`) + ':' + (ss<10?`0${ss}`:`${ss}`); } } @@ -439,6 +433,9 @@ function Jeditor(props) { if (splitOutput.length < 3) { return false; } else { + 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]); if (timeValue >= 86400) { return false; @@ -456,6 +453,9 @@ function Jeditor(props) { if (splitOutput.length < 3) { return false; } else { + if (parseInt(splitOutput[0]) > 90 || parseInt(splitOutput[1])>59 || parseInt(splitOutput[2])>59) { + return false; + } const timeValue = parseInt(splitOutput[0]*60*60) + parseInt(splitOutput[1]*60) + parseInt(splitOutput[2]); if (timeValue > 324000) { return false; diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Task/edit.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Task/edit.js index 90ad6359847a5a18718b005ddb73608d9188a08a..f978f5907620d28130f89f5893c110d3344ca6ba 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Task/edit.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Task/edit.js @@ -38,6 +38,7 @@ export class TaskEdit extends Component { name: {required: true, message: "Name can not be empty"}, description: {required: true, message: "Description can not be empty"} }; + this.readOnlyProperties = ['duration', 'relative_start_time', 'relative_stop_time']; this.setEditorOutput = this.setEditorOutput.bind(this); this.setTaskParams = this.setTaskParams.bind(this); this.changeTaskTemplate = this.changeTaskTemplate.bind(this); @@ -126,16 +127,18 @@ export class TaskEdit extends Component { saveTask() { let task = this.state.task; task.specifications_doc = this.templateOutput[task.specifications_template_id]; + // Remove read only properties from the object before sending to API + this.readOnlyProperties.forEach(property => { delete task[property]}); TaskService.updateTask("draft", task) .then( (taskDraft) => { if (taskDraft) { - this.setState({redirect: '/task/view'}); + this.setState({redirect: '/task/view/draft/' + task.id}); } }); } cancelEdit() { - this.setState({redirect: '/task/view'}); + this.setState({redirect: '/task/view/draft/' + this.state.task.id}); } componentDidMount() {