Select Git revision
t_tmssapp_scheduling_REST_API.py
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
common.utils.js 5.24 KiB
import _ from 'lodash';
import ScheduleService from '../../services/schedule.service';
import WorkflowService from '../../services/workflow.service';
/**
* Class with common functions used by both Timeline View and Week Overview components.
*/
class TimelineCommonUtils {
constructor() {
this.STATUS_BEFORE_SCHEDULED = ['defining', 'defined', 'schedulable']; // Statuses before scheduled to get station_group
this.loadMainStationGroups();
this.loadSUWorkflowTasks();
}
/**
* To group the stations under CS,RS,IS to show the count in Popover
*/
async loadMainStationGroups() {
this.mainStationGroups = await ScheduleService.getMainGroupStations();
}
/**
* TO get the main station groups (Core, Remote, International)
* @returns Array - main station groups
*/
getMainStationGroups() {
return this.mainStationGroups;
}
/**
* Function to fetch all Workflow processes and tasks to get the workflow status column
* in the SU List table.
*/
async loadSUWorkflowTasks() {
this.worflowProcesses = await WorkflowService.getWorkflowProcesses();
this.workflowTasks = await WorkflowService.getWorkflowTasks();
}
/**
* Get all stations of the SU bleprint from the observation task or subtask based on the SU status.
* @param {Object} suBlueprint
*/
getSUStations(suBlueprint) {
let stations = [];
/* Get all observation tasks */
const observationTasks = _.filter(suBlueprint.tasks, (task) => { return task.task_type.toLowerCase() === "observation" });
for (const observationTask of observationTasks) {
/** If the status of SU is before scheduled, get all stations from the station_groups from the task specification_docs */
if (this.STATUS_BEFORE_SCHEDULED.indexOf(suBlueprint.status.toLowerCase()) >= 0
&& observationTask.specifications_doc.station_groups) {
for (const grpStations of _.map(observationTask.specifications_doc.station_groups, "stations")) {
stations = _.concat(stations, grpStations);
}
} else if (this.STATUS_BEFORE_SCHEDULED.indexOf(suBlueprint.status.toLowerCase()) < 0
&& observationTask.subtasks) {
/** If the status of SU is scheduled or after get the stations from the subtask specification tasks */
for (const subtask of observationTask.subtasks) {
if (subtask.specifications_doc.stations) {
stations = _.concat(stations, subtask.specifications_doc.stations.station_list);
}
}
}
}
return _.uniq(stations);
}
/**
* Group the SU stations to main groups Core, Remote, International
* @param {Object} stationList
*/
groupSUStations(stationList) {
let suStationGroups = {};
for (const group in this.mainStationGroups) {
suStationGroups[group] = _.intersection(this.mainStationGroups[group], stationList);
}
return suStationGroups;
}
/**
* This funtion gets the stations involved in a SUB, group them to the majour groups,
* gets the count of stations in each group and format to 'CS/RS/IS' & their counts '12/13/14'
* to display in SU list and SU block mouse over popup.
* @param {Object} itemSU - SU Blueprint object
* @returns Object - A JSON object with station groups and count as proerpty with formatted string to display
*/
getSUStationGroupCount(itemSU) {
const itemStations = this.getSUStations(itemSU);
const itemStationGroups = this.groupSUStations(itemStations);
let suStationGroupCount = { groups: "", counts: "" };
for (const stationgroup of _.keys(itemStationGroups)) {
let groups = suStationGroupCount.groups;
let counts = suStationGroupCount.counts;
if (groups) {
groups = groups.concat("/");
counts = counts.concat("/");
}
// Get station group 1st character and append 'S' to get CS,RS,IS
groups = groups.concat(stationgroup.substring(0, 1).concat('S'));
counts = counts.concat(itemStationGroups[stationgroup].length);
suStationGroupCount.groups = groups;
suStationGroupCount.counts = counts;
}
return suStationGroupCount;
}
/**
* To get the workflow status of the Scheduling Unit Blueprint
* @param {Object} suBlueprint
* @returns String - Status (Latest workflow task)
*/
getWorkflowStatus(suBlueprint) {
let status = null;
let suWorflowProcess = _.find(this.worflowProcesses, ['su', suBlueprint.id]);
if (suWorflowProcess) {
let suWorkflowLastTasks = _.filter(this.workflowTasks, {'process': suWorflowProcess.id});
status = (_.orderBy(suWorkflowLastTasks, ['id'], ['desc']))[0].flow_task;
if (status.toLowerCase() === "wait processed") {
status = "Scheduled";
} else if (status.toLowerCase === "end") {
status = "Done";
}
}
return status
}
}
export default TimelineCommonUtils;