Skip to content
Snippets Groups Projects
Commit d1b87e8e authored by Jörn Künsemöller's avatar Jörn Künsemöller
Browse files

TMSS-146: cleanup a bit

parent 8f0d6983
No related branches found
No related tags found
1 merge request!104Resolve TMSS-146
......@@ -12,238 +12,6 @@ import Form from 'react-jsonschema-form-bs4'; // todo: use main line "react-json
// ...only supports latest out of the box, older schemas need to be passed to Form via this:
const additionalMetaSchemas = require("ajv/lib/refs/json-schema-draft-06.json");
// todo: read from referenced template
//const schema = {
// "$id": "http://example.com/example.json",
// "type": "object",
// "$schema": "http://json-schema.org/draft-06/schema#",
// "definitions": {
// "pointing": {
// "type": "object",
// "additionalProperties": false,
// "properties": {
// "direction_type": {
// "type": "string",
// "title": "Reference frame",
// "description": "",
// "default": "J2000",
// "enum": [
// "J2000",
// "SUN",
// "MOON",
// "MERCURY",
// "VENUS",
// "MARS",
// "JUPITER",
// "SATURN",
// "URANUS",
// "NEPTUNE",
// "PLUTO"
// ]
// },
// "angle1": {
// "type": "number",
// "title": "Angle 1",
// "description": "First angle (f.e. RA)",
// "default": 0
// },
// "angle2": {
// "type": "number",
// "title": "Angle 2",
// "description": "Second angle (f.e. DEC)",
// "default": 0
// }
// }
// }
// },
// "additionalProperties": false,
// "properties": {
// "stations": {
// "title": "Station list",
// "oneOf": [
// {
// "type": "array",
// "title": "Fixed list",
// "additionalItems": false,
// "additionalProperties": false,
// "items": {
// "type": "string",
// "enum": [
// "CS001",
// "CS002",
// "CS003",
// "CS004",
// "CS005",
// "CS006",
// "CS007",
// "CS011",
// "CS013",
// "CS017",
// "CS021",
// "CS024",
// "CS026",
// "CS028",
// "CS030",
// "CS031",
// "CS032",
// "CS101",
// "CS103",
// "CS201",
// "CS301",
// "CS302",
// "CS401",
// "CS501",
// "RS104",
// "RS106",
// "RS205",
// "RS208",
// "RS210",
// "RS305",
// "RS306",
// "RS307",
// "RS310",
// "RS406",
// "RS407",
// "RS409",
// "RS410",
// "RS503",
// "RS508",
// "RS509",
// "DE601",
// "DE602",
// "DE603",
// "DE604",
// "DE605",
// "FR606",
// "SE607",
// "UK608",
// "DE609",
// "PL610",
// "PL611",
// "PL612",
// "IE613",
// "LV614"
// ],
// "title": "Station",
// "description": ""
// },
// "minItems": 1,
// "uniqueItems": true
// },
// {
// "title": "Dynamic list",
// "type": "array",
// "additionalItems": false,
// "items": {
// "type": "object",
// "title": "Station set",
// "headerTemplate": "{{ self.group }}",
// "additionalProperties": false,
// "properties": {
// "group": {
// "type": "string",
// "title": "Group/station",
// "description": "Which (group of) station(s) to select from",
// "default": "ALL",
// "enum": [
// "ALL",
// "SUPERTERP",
// "CORE",
// "REMOTE",
// "DUTCH",
// "INTERNATIONAL"
// ]
// },
// "min_stations": {
// "type": "integer",
// "title": "Minimum nr of stations",
// "description": "Number of stations to use within group/station",
// "default": 1,
// "minimum": 0
// }
// }
// }
// }
// ]
// },
// "antenna_set": {
// "type": "string",
// "title": "Antenna set",
// "description": "Fields & antennas to use",
// "default": "HBA_DUAL",
// "enum": [
// "HBA_DUAL",
// "HBA_DUAL_INNER",
// "HBA_JOINED",
// "HBA_JOINED_INNER",
// "HBA_ONE",
// "HBA_ONE_INNER",
// "HBA_ZERO",
// "HBA_ZERO_INNER",
// "LBA_INNER",
// "LBA_OUTER",
// "LBA_SPARSE_EVEN",
// "LBA_SPARSE_ODD",
// "LBA_ALL"
// ]
// },
// "filter": {
// "type": "string",
// "title": "Band-pass filter",
// "description": "Must match antenna type",
// "default": "HBA_110_190",
// "enum": [
// "LBA_10_70",
// "LBA_30_70",
// "LBA_10_90",
// "LBA_30_90",
// "HBA_110_190",
// "HBA_210_250"
// ]
// },
// "analog_pointing": {
// "title": "Analog pointing",
// "description": "HBA only",
// "$ref": "#/definitions/pointing"
// },
// "beams": {
// "type": "array",
// "title": "Beams",
// "additionalItems": false,
// "items": {
// "title": "Beam",
// "headerTemplate": "{{ i0 }} - {{ self.name }}",
// "type": "object",
// "additionalProperties": false,
// "properties": {
// "name": {
// "type": "string",
// "title": "Name/target",
// "description": "Identifier for this beam",
// "default": ""
// },
// "digital_pointing": {
// "title": "Digital pointing",
// "$ref": "#/definitions/pointing"
// },
// "subbands": {
// "type": "array",
// "title": "Subband list",
// "additionalItems": false,
// "items": {
// "type": "integer",
// "title": "Subband",
// "minimum": 0,
// "maximum": 511
// }
// }
// }
// }
// }
// }
//};
// Procedures // todo: revise and put these somewhere so they can be shared by entire frontend
// todo: The BasicAuth should only be used for testing, remove once we serve from same webserver as api
// todo: add a check that we have an active session with the API, redirect offer login if not
......@@ -255,40 +23,33 @@ var api_url = 'http://localhost:8008/api/';
//var api_url = '/api/' // todo: use this again, once we serve this from same webserver as api
// todo: this is just a fixture for development. Handle schemas in individual states of task drafts.
// Procedures // todo: revise and put these somewhere so they can be shared by entire frontend
function tmssGetList(url, component){
console.log('Getting '+ url);
if(!url.startsWith('http')){
url = api_url+url;
}
fetch(url, {headers: headers})
.then(response => response.json())
.then(response => {console.log(response);
// React cannot handle deep states, so we have to stringify nested objects before setState()
.then(response => {// React cannot handle deep states, so we have to stringify nested objects before setState()
response.results.forEach(result => {result.specifications_doc = JSON.stringify(result.specifications_doc);});
component.setState({items:response.results});})
.catch(err => alert(err))
}
function tmssGet(url, component){
console.log('Getting '+ url);
if(!url.startsWith('http')){
url = api_url+url;
}
fetch(url, {headers: headers})
.then(response => response.json())
.then(response => {console.log(response);
component.setState(response);
.then(response => {component.setState(response);
component.updateSchema();
})
.catch(err => alert(err))
}
function tmssGetReferenceList(url, state_name, component){
console.log('Getting references '+ url);
if(!url.startsWith('http')){
url = api_url+url;
}
......@@ -296,14 +57,12 @@ function tmssGetReferenceList(url, state_name, component){
.then(response => {return response.json();})
.then(response => {
var references = response.results.map((reference) => {return reference.url});
console.log(references);
component.setState({
[state_name]: references
});
})}
function tmssPost(url, data, component){
console.log('Posting '+ url);
if(!url.startsWith('http')){
url = api_url+url;
}
......@@ -313,29 +72,24 @@ function tmssPost(url, data, component){
}
function tmssPut(url, data, component){
console.log('Putting '+ url);
if(!url.startsWith('http')){
url = api_url+url;
}
console.log(data);
fetch(url, {headers: headers, method: 'PUT', body: data})
.then(ReactDOM.render(<TaskDraftList />, document.getElementById('root')))
.catch(err => alert(err))
}
function tmssPatch(url, data, component){
console.log('Patching '+ url);
if(!url.startsWith('http')){
url = api_url+url;
}
console.log(data);
fetch(url, {headers: headers, method: 'PATCH', body: data})
.then(ReactDOM.render(<TaskDraftList />, document.getElementById('root')))
.catch(err => alert(err))
}
function tmssDelete(url){
console.log('Deleting '+ url);
if(!url.startsWith('http')){
url = api_url+url;
}
......@@ -448,20 +202,7 @@ class EditTaskDraft extends Component {
tmssGetReferenceList('task_template/', 'templates', this)
tmssGetReferenceList('scheduling_unit_draft/', 'drafts', this)
// fetch(api_url + "task_template/", {headers: headers})
// .then(response => {return response.json();})
// .then(response => {
// new_templates = response.results.map((template) => {return template.url});
// console.log(new_templates);
// this.setState({
// templates: new_templates
// });
// })
}
updateSchema(){
console.log('updateSchema')
fetch(this.state.specifications_template, {headers: headers})
.then(response => response.json())
.then(response => {
......@@ -516,8 +257,6 @@ class EditTaskDraft extends Component {
}
onSubmit(e) {
console.log('onSubmit');
console.log(e);
e.preventDefault();
const data = {
name: this.state.name,
......@@ -532,7 +271,6 @@ class EditTaskDraft extends Component {
produced_by: this.state.produced_by,
consumed_by: this.state.consumed_by
};
console.log(JSON.stringify(data));
if(this.state.isnew){
tmssPost('task_draft/', JSON.stringify(data), this);
}else{
......
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