Skip to content
Snippets Groups Projects
Commit f741270f authored by Auke Klazema's avatar Auke Klazema
Browse files

Merge branch 'TMSS-323' into 'master'

Resolves TMSS-323: Issues with updating task and angle conversion for pointing fields are fixed.

Closes TMSS-323

See merge request !205
parents 7f27ec32 5da0f5ed
No related branches found
No related tags found
1 merge request!205Resolves TMSS-323: Issues with updating task and angle conversion for pointing fields are fixed.
...@@ -13,12 +13,13 @@ const JSONEditor = require("@json-editor/json-editor").JSONEditor; ...@@ -13,12 +13,13 @@ const JSONEditor = require("@json-editor/json-editor").JSONEditor;
function Jeditor(props) { function Jeditor(props) {
// console.log("In JEditor"); // console.log("In JEditor");
const editorRef = useRef(null); const editorRef = useRef(null);
let pointingProps = useRef(null);
let editor = null; let editor = null;
useEffect(() => { useEffect(() => {
const element = document.getElementById('editor_holder'); const element = document.getElementById('editor_holder');
let schema = {}; let schema = {};
Object.assign(schema, props.schema?props.schema:{}); Object.assign(schema, props.schema?props.schema:{});
pointingProps = [];
// Customize the pointing property to capture angle1 and angle2 to specified format // Customize the pointing property to capture angle1 and angle2 to specified format
for (const definitionKey in schema.definitions) { for (const definitionKey in schema.definitions) {
if (definitionKey === 'pointing') { if (definitionKey === 'pointing') {
...@@ -42,7 +43,6 @@ function Jeditor(props) { ...@@ -42,7 +43,6 @@ function Jeditor(props) {
// Customize datatype of certain properties like subbands, duration, etc., // Customize datatype of certain properties like subbands, duration, etc.,
getCustomProperties(schema.properties); getCustomProperties(schema.properties);
schema.title = props.title; schema.title = props.title;
const subbandValidator = validateSubbandOutput; const subbandValidator = validateSubbandOutput;
const timeValidator = validateTime; const timeValidator = validateTime;
...@@ -89,6 +89,7 @@ function Jeditor(props) { ...@@ -89,6 +89,7 @@ function Jeditor(props) {
disable_edit_json: true, disable_edit_json: true,
disable_properties: true, disable_properties: true,
disable_collapse: true, disable_collapse: true,
show_errors: props.errorsOn?props.errorsOn:'change', // Can be 'interaction', 'change', 'always', 'never'
compact: true compact: true
}; };
// Set Initial value to the editor // Set Initial value to the editor
...@@ -290,6 +291,9 @@ function Jeditor(props) { ...@@ -290,6 +291,9 @@ function Jeditor(props) {
options.grid_columns = 9; options.grid_columns = 9;
propertyValue.options = options; propertyValue.options = options;
} }
if (propertyValue['$ref'] && propertyValue['$ref'].endsWith("/pointing")) {
pointingProps.push(propertyKey);
}
getCustomProperties(propertyValue); getCustomProperties(propertyValue);
} }
} }
...@@ -303,7 +307,7 @@ function Jeditor(props) { ...@@ -303,7 +307,7 @@ function Jeditor(props) {
for (const inputKey in editorInput) { for (const inputKey in editorInput) {
const inputValue = editorInput[inputKey]; const inputValue = editorInput[inputKey];
if (inputValue instanceof Object) { if (inputValue instanceof Object) {
if (inputKey.endsWith('pointing')) { if (_.indexOf(pointingProps, inputKey) >= 0) {
inputValue.angle1 = getAngleInput(inputValue.angle1); inputValue.angle1 = getAngleInput(inputValue.angle1);
inputValue.angle2 = getAngleInput(inputValue.angle2, true); inputValue.angle2 = getAngleInput(inputValue.angle2, true);
} else if (inputKey === 'subbands') { } else if (inputKey === 'subbands') {
...@@ -327,7 +331,7 @@ function Jeditor(props) { ...@@ -327,7 +331,7 @@ function Jeditor(props) {
for (const outputKey in editorOutput) { for (const outputKey in editorOutput) {
let outputValue = editorOutput[outputKey]; let outputValue = editorOutput[outputKey];
if (outputValue instanceof Object) { if (outputValue instanceof Object) {
if (outputKey.endsWith('pointing')) { if (_.indexOf(pointingProps, outputKey) >= 0) {
outputValue.angle1 = getAngleOutput(outputValue.angle1, false); outputValue.angle1 = getAngleOutput(outputValue.angle1, false);
outputValue.angle2 = getAngleOutput(outputValue.angle2, true); outputValue.angle2 = getAngleOutput(outputValue.angle2, true);
} else { } else {
...@@ -355,21 +359,11 @@ function Jeditor(props) { ...@@ -355,21 +359,11 @@ function Jeditor(props) {
const dd = Math.floor(prpInput * 180 / Math.PI); const dd = Math.floor(prpInput * 180 / Math.PI);
const mm = Math.floor((degrees-dd) * 60); const mm = Math.floor((degrees-dd) * 60);
const ss = +((degrees-dd-(mm/60)) * 3600).toFixed(0); 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}`); return (dd<10?`0${dd}`:`${dd}`) + ':' + (mm<10?`0${mm}`:`${mm}`) + ':' + (ss<10?`0${ss}`:`${ss}`);
} else { } else {
const hh = Math.floor(degrees/15); const hh = Math.floor(degrees/15);
const mm = Math.floor((degrees - (hh*15))/15 * 60 ); const mm = Math.floor((degrees - (hh*15))/15 * 60 );
const ss = +((degrees -(hh*15)-(mm*15/60))/15 * 3600).toFixed(0); 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}`); return (hh<10?`0${hh}`:`${hh}`) + ':' + (mm<10?`0${mm}`:`${mm}`) + ':' + (ss<10?`0${ss}`:`${ss}`);
} }
} }
...@@ -439,6 +433,9 @@ function Jeditor(props) { ...@@ -439,6 +433,9 @@ function Jeditor(props) {
if (splitOutput.length < 3) { if (splitOutput.length < 3) {
return false; return false;
} else { } 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]); const timeValue = parseInt(splitOutput[0]*60*60) + parseInt(splitOutput[1]*60) + parseInt(splitOutput[2]);
if (timeValue >= 86400) { if (timeValue >= 86400) {
return false; return false;
...@@ -456,6 +453,9 @@ function Jeditor(props) { ...@@ -456,6 +453,9 @@ function Jeditor(props) {
if (splitOutput.length < 3) { if (splitOutput.length < 3) {
return false; return false;
} else { } 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]); const timeValue = parseInt(splitOutput[0]*60*60) + parseInt(splitOutput[1]*60) + parseInt(splitOutput[2]);
if (timeValue > 324000) { if (timeValue > 324000) {
return false; return false;
......
...@@ -38,6 +38,7 @@ export class TaskEdit extends Component { ...@@ -38,6 +38,7 @@ export class TaskEdit extends Component {
name: {required: true, message: "Name can not be empty"}, name: {required: true, message: "Name can not be empty"},
description: {required: true, message: "Description 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.setEditorOutput = this.setEditorOutput.bind(this);
this.setTaskParams = this.setTaskParams.bind(this); this.setTaskParams = this.setTaskParams.bind(this);
this.changeTaskTemplate = this.changeTaskTemplate.bind(this); this.changeTaskTemplate = this.changeTaskTemplate.bind(this);
...@@ -126,16 +127,18 @@ export class TaskEdit extends Component { ...@@ -126,16 +127,18 @@ export class TaskEdit extends Component {
saveTask() { saveTask() {
let task = this.state.task; let task = this.state.task;
task.specifications_doc = this.templateOutput[task.specifications_template_id]; 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) TaskService.updateTask("draft", task)
.then( (taskDraft) => { .then( (taskDraft) => {
if (taskDraft) { if (taskDraft) {
this.setState({redirect: '/task/view'}); this.setState({redirect: '/task/view/draft/' + task.id});
} }
}); });
} }
cancelEdit() { cancelEdit() {
this.setState({redirect: '/task/view'}); this.setState({redirect: '/task/view/draft/' + this.state.task.id});
} }
componentDidMount() { componentDidMount() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment