diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Cycle/list.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Cycle/list.js index 1c0a6d145c4f35428cc16c604a31f3d41f23f162..b53d992fbe685f67c8e359f5e933ff1d165fe93f 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/Cycle/list.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Cycle/list.js @@ -12,7 +12,7 @@ class CycleList extends Component{ this.state = { cyclelist: [], paths: [{ - "View": "/cycle", + "View": "/cycle/view", }], projectCategory: ['regular', 'user_shared_support'], periodCategory: ['long_term'], @@ -21,84 +21,91 @@ class CycleList extends Component{ id:"Cycle Code", start:"Start Date", stop: "End Date", - duration: "Duration", + duration: "Duration (Days)", totalProjects: 'No.of Projects', - longterm : 'LongTerm Projects', observingTime: 'Lofar Observing Time (Hrs)', processingTime: 'Lofar Processing Time (Hrs)', ltaResources: 'Lofar LTA Resources(TB)', support: 'Lofar Support (Hrs)', - + longterm : 'Long Term Projects' + } ], optionalcolumns : [{ - regularProjects: 'No.of Regular', + regularProjects: 'No.of Regular/Project', observingTimeDDT: 'Lofar Observing Time Commissioning (Hrs)', observingTimePrioA: 'Lofar Observing Time Prio A (Hrs)', observingTimePrioB: 'Lofar Observing Time Prio B (Hrs)' + }], columnclassname: [{ - "Cycle Code":"filter-input-50", - "Duration" : "filter-input-75", - "No.of Projects" : "filter-input-75", - "LongTerm Projects" : "filter-input-75", - "Lofar Observing Time (hr)" : "filter-input-75", - "Lofar Processing Time (hr)" : "filter-input-75", - "Lofar LTA Resources(TB)" : "filter-input-100", - "Lofar Support (hr)" : "filter-input-50", - "No.of Regular" : "filter-input-50", - "Lofar Observing Time Commissioning (hr)" : "filter-input-50", - "Lofar Observing Time Prio A (hr)" : "filter-input-50", - "Lofar Observing Time Prio B (hr)" : "filter-input-50" + "Cycle Code":"filter-input-75", + "Duration (Days)" : "filter-input-50", + "No.of Projects" : "filter-input-50", + "Lofar Observing Time (Hrs)" : "filter-input-50", + "Lofar Processing Time (Hrs)" : "filter-input-50", + "Lofar LTA Resources(TB)" : "filter-input-50", + "Lofar Support (Hrs)" : "filter-input-50", + "Long Term Projects" : "filter-input-50", + "No.of Regular/Project" : "filter-input-50", + "Lofar Observing Time Commissioning (Hrs)" : "filter-input-50", + "Lofar Observing Time Prio A (Hrs)" : "filter-input-50", + "Lofar Observing Time Prio B (Hrs)" : "filter-input-50" }], isprocessed: false, isLoading: true } } - conversion(d,type) { - const coversionType = this.state.resources.find(i => i.name === type).quantity_value; - return UnitConversion.getUIResourceUnit(coversionType,d) - } + conversion(d,type) { + const coversionType = this.state.resources.find(i => i.name === type).quantity_value; + return UnitConversion.getUIResourceUnit(coversionType,d) + } - componentDidMount(){ + getCycles(cycles = [], cycleQuota) { const { projectCategory} = this.state; const { periodCategory} = this.state; + const promises = []; + cycles.map(cycle => promises.push(CycleService.getCycleById(cycle.name))); + Promise.all(promises).then(responses => { + const results = cycles; + results.map(async (cycle, index) => { + const projects = responses[index]; + const regularProjects = projects.filter(project => projectCategory.includes(project.project_category_value)); + const longterm = projects.filter(project => periodCategory.includes(project.period_category_value)); + cycle.duration = UnitConversion.getUIResourceUnit('days', cycle.duration); + cycle.totalProjects = cycle.projects ? cycle.projects.length : 0; + cycle.id = cycle.name ; + cycle.regularProjects = regularProjects.length; + cycle.longterm = longterm.length; + cycle.observingTime = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time') || {value: 0}).value, 'observing_time') + cycle.processingTime = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'cep_processing_time') || {value: 0}).value, 'cep_processing_time') + cycle.ltaResources = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'lta_storage') || {value: 0}).value, 'lta_storage') + cycle.support = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'support_time') || {value: 0}).value, 'support_time') + cycle.observingTimeDDT = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time_commissioning') || {value: 0}).value, 'observing_time_commissioning') + cycle.observingTimePrioA = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time_prio_a') || {value: 0}).value, 'observing_time_prio_a') + cycle.observingTimePrioB = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time_prio_b') || {value: 0}).value, 'observing_time_prio_b') + cycle['actionpath'] = '/cycle/view'; + return cycle; + }); + this.setState({ + cyclelist : results, + isprocessed: true, + isLoading: false + }); + }); + } - const promises = [CycleService.getProjects(), CycleService.getCycleQuota(),CycleService.getResources()] + componentDidMount(){ + const promises = [CycleService.getCycleQuota(), CycleService.getResources()] Promise.all(promises).then(responses => { - const projects = responses[0]; - const cycleQuota = responses[1]; - this.setState({ resources: responses[2].data.results }); - CycleService.getAllCycles().then(cyclelist =>{ - const results = cyclelist || []; - results.map(cycle => { - const regularProjects = projects.data.results.filter(project => project.cycles_ids.includes(cycle.name) && projectCategory.includes(project.project_category_value)); - const longterm = projects.data.results.filter(project => project.cycles_ids.includes(cycle.name) && periodCategory.includes(project.period_category_value)); - const timediff = new Date(cycle.stop).getTime() - new Date(cycle.start).getTime(); - cycle.duration = timediff / (1000 * 3600 * 24); - cycle.totalProjects = cycle.projects ? cycle.projects.length : 0; - cycle.id = cycle.name ? cycle.name.split(' ').join('') : cycle.name; - cycle.regularProjects = regularProjects.length; - cycle.longterm = longterm.length; - cycle.observingTime = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time') || {value: 0}).value, 'observing_time') - cycle.processingTime = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'cep_processing_time') || {value: 0}).value, 'cep_processing_time') - cycle.ltaResources = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'lta_storage') || {value: 0}).value, 'lta_storage') - cycle.support = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'support_time') || {value: 0}).value, 'support_time') - cycle.observingTimeDDT = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time_commissioning') || {value: 0}).value, 'observing_time_commissioning') - cycle.observingTimePrioA = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time_prio_a') || {value: 0}).value, 'observing_time_prio_a') - cycle.observingTimePrioB = this.conversion((cycleQuota.data.results.find(quota => quota.cycle_id === cycle.name && quota.resource_type_id === 'observing_time_prio_b') || {value: 0}).value, 'observing_time_prio_b') - cycle.actionpath = "/cycle/view/{cycle_name}"; - return cycle; - }); - this.setState({ - cyclelist : results, - isprocessed: true, - isLoading: false - }); - }) - }) + const cycleQuota = responses[0]; + this.setState({ resources: responses[1].data.results }); + CycleService.getAllCycles().then(cyclelist => { + this.getCycles(cyclelist, cycleQuota) + }); + }); } render(){ @@ -132,10 +139,14 @@ class CycleList extends Component{ showaction="true" paths={this.state.paths} /> : <></> - } + } + + + </> ) } } export default CycleList + diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/Cycle/view.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/Cycle/view.js new file mode 100644 index 0000000000000000000000000000000000000000..a03ae5e6608bff3f31c50e1441bcc5fc8acca4c2 --- /dev/null +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/Cycle/view.js @@ -0,0 +1,17 @@ +import React, {Component} from 'react'; + + +export class CycleView extends Component { + + constructor(props){ + super(props) + console.log(this.props) + } + render() { + return ( + <h1>CycleView</h1> + ); + } +} + +export default CycleView; \ No newline at end of file diff --git a/SAS/TMSS/frontend/tmss_webapp/src/routes/index.js b/SAS/TMSS/frontend/tmss_webapp/src/routes/index.js index 036209b5d6c69d1213be28e1a08a2274ecf821e1..b1907ea2737c343f5783ea660847f7d31f6afefb 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/routes/index.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/routes/index.js @@ -12,6 +12,7 @@ import {Scheduling} from './Scheduling'; import {TaskEdit, TaskView} from './Task'; import ViewSchedulingUnit from './Scheduling/ViewSchedulingUnit' import CycleList from './Cycle/list'; +import CycleView from './Cycle/view'; export const routes = [ { @@ -71,6 +72,11 @@ export const routes = [ component: CycleList, name: 'Cycle List' }, + { + path: "/cycle/view", + component: CycleView, + name: 'Cycle View' + }, ]; export const RoutedContent = () => { diff --git a/SAS/TMSS/frontend/tmss_webapp/src/services/cycle.service.js b/SAS/TMSS/frontend/tmss_webapp/src/services/cycle.service.js index 1d78f83001f79aaa2502a279ef75995b6f02349d..49bf7ac47ce65a86f3114683d889d74cba7af1b3 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/services/cycle.service.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/services/cycle.service.js @@ -4,56 +4,46 @@ const axios = require('axios'); axios.defaults.headers.common['Authorization'] = 'Basic dGVzdDp0ZXN0'; const CycleService = { - getAllCycles: async function() { + getAllCycles: async function () { try { - const url = `/api/cycle`; - const response = await axios.get(url); - return response.data.results; + const url = `/api/cycle`; + const response = await axios.get(url); + return response.data.results; } catch (error) { - console.error(error); + console.error(error); } - }, - getCycle: async function(id) { + }, + getCycleById: async function (id) { try { - const url = `/api/cycle/${id}`; - const response = await axios.get(url); - return response.data.results; + const url = `/api/cycle/${id}/project`; + const response = await axios.get(url); + return response.data.results; } catch (error) { - console.error(error); + console.error(error); } - }, - - getProjects: async function() { - let res = []; - await axios.get('/api/project/') - .then(response => { - res= response; - }).catch(function(error) { - console.error('[cycle.services.project]',error); - }); - return res; }, - getCycleQuota: async function() { + + getCycleQuota: async function () { let res = []; await axios.get('/api/cycle_quota/') - .then(response => { - res= response; - }).catch(function(error) { - console.error('[cycle.services.cycle_quota]',error); - }); + .then(response => { + res = response; + }).catch(function (error) { + console.error('[cycle.services.cycle_quota]', error); + }); return res; }, - getResources: async function() { - let res = []; - await axios.get('/api/resource_type') - .then(response => { - res= response; - }).catch(function(error) { - console.error('[cycle.services.resource_type]',error); - }); - return res; + getResources: async function () { + let res = []; + await axios.get('/api/resource_type') + .then(response => { + res = response; + }).catch(function (error) { + console.error('[cycle.services.resource_type]', error); + }); + return res; -} + } } -export default CycleService; \ No newline at end of file +export default CycleService; 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 bd492544a3ef58793a6bfd24e996757d78d0e132..4a4e3cee4bb33b08618894fb8611bf0b99989b5e 100644 --- a/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js +++ b/SAS/TMSS/frontend/tmss_webapp/src/utils/unit.converter.js @@ -1,7 +1,8 @@ const UnitConverter = { resourceUnitMap: {'time':{display: 'Hours', conversionFactor: 3600, mode:'decimal', minFractionDigits:0, maxFractionDigits: 2 }, 'bytes': {display: 'TB', conversionFactor: (1024*1024*1024*1024), mode:'decimal', minFractionDigits:0, maxFractionDigits: 3}, - 'number': {display: 'Numbers', conversionFactor: 1, mode:'decimal', minFractionDigits:0, maxFractionDigits: 0}}, + 'number': {display: 'Numbers', conversionFactor: 1, mode:'decimal', minFractionDigits:0, maxFractionDigits: 0}, + 'days': {display: 'Days', conversionFactor: (3600*24), mode:'decimal', minFractionDigits:0, maxFractionDigits: 0}}, getDBResourceUnit: function() { @@ -20,4 +21,4 @@ const UnitConverter = { } }; -export default UnitConverter; \ No newline at end of file +export default UnitConverter;