Select Git revision
common.utils.js
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