2023-07-08 18:33:48 +02:00
|
|
|
/*eslint no-console: "off"*/
|
2023-05-17 21:19:14 +02:00
|
|
|
/**
|
|
|
|
* Copy fields from one object to another
|
|
|
|
* @param {Object} target The target to move to
|
|
|
|
* @param {Object} source The source to move from
|
|
|
|
* @param {Array} fields The field names to copy
|
|
|
|
* @returns {Object} The map with strings loaded in
|
|
|
|
*/
|
|
|
|
export function objCopy(target,source,fields){
|
|
|
|
for(const ix in fields) {
|
|
|
|
const field = fields[ix];
|
|
|
|
target[field] = source[field];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transport items from one object to another
|
|
|
|
* @param {Object} target The target to move to
|
|
|
|
* @param {Object} source The source to move from
|
|
|
|
* @param {*} identifier The value used to match the item
|
|
|
|
* @param {string} param The field name to match on (default: 'value')
|
|
|
|
*/
|
|
|
|
export function transportItem(target,source,identifier,param){
|
|
|
|
if(!param){
|
|
|
|
param = 'value';
|
|
|
|
}
|
|
|
|
// find item
|
|
|
|
let item;
|
|
|
|
let itemindex;
|
|
|
|
for(const ix in source){
|
|
|
|
if(source[ix][param] == identifier){
|
|
|
|
item = source[ix];
|
|
|
|
itemindex = ix;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(item){
|
|
|
|
target.push(item);
|
|
|
|
source.splice(itemindex,1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do initial conversion on multiple studyplans
|
|
|
|
* @param {Array} studyplans The list of studyplans to load
|
|
|
|
* @returns {Array} List of updated studyplans
|
|
|
|
*/
|
|
|
|
export function ProcessStudyplans(studyplans){
|
|
|
|
// Unify object references to connections between items, so there are no duplicates
|
|
|
|
for(const isx in studyplans)
|
|
|
|
{
|
|
|
|
const studyplan = studyplans[isx];
|
|
|
|
ProcessStudyplan(studyplan);
|
|
|
|
}
|
|
|
|
|
|
|
|
return studyplans;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform initial processing on a downloaded studyplan
|
|
|
|
* Mainly used to create the proper references between items
|
|
|
|
* @param {Object} studyplan The studyplan to process
|
|
|
|
* @returns Processed studyplan
|
|
|
|
*/
|
|
|
|
export function ProcessStudyplan(studyplan){
|
|
|
|
let connections = {};
|
2023-07-28 23:43:11 +02:00
|
|
|
for(const ip in studyplan.pages){
|
|
|
|
const page = studyplan.pages[ip];
|
|
|
|
for(const il in page.studylines) {
|
|
|
|
const line = page.studylines[il];
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-07-28 23:43:11 +02:00
|
|
|
for(const is in line.slots ) {
|
|
|
|
const slot = line.slots[is];
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-08-28 11:26:14 +02:00
|
|
|
if(slot.courses !== undefined){
|
|
|
|
for(const ic in slot.courses){
|
|
|
|
const itm = slot.courses[ic];
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-07-28 23:43:11 +02:00
|
|
|
for(const idx in itm.connections.in) {
|
|
|
|
const conn = itm.connections.in[idx];
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-07-28 23:43:11 +02:00
|
|
|
if(conn.id in connections){
|
|
|
|
itm.connections[idx] = connections[conn.id];
|
|
|
|
} else {
|
|
|
|
connections[conn.id] = conn;
|
|
|
|
}
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
2023-07-28 23:43:11 +02:00
|
|
|
for(const idx in itm.connections.out) {
|
|
|
|
const conn = itm.connections.out[idx];
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-07-28 23:43:11 +02:00
|
|
|
if(conn.id in connections){
|
|
|
|
itm.connections[idx] = connections[conn.id];
|
|
|
|
} else {
|
|
|
|
connections[conn.id] = conn;
|
|
|
|
}
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-28 23:43:11 +02:00
|
|
|
if(slot.filters !== undefined){
|
|
|
|
for(const ix in slot.filters){
|
|
|
|
const itm = slot.filters[ix];
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-07-28 23:43:11 +02:00
|
|
|
for(const idx in itm.connections.in) {
|
|
|
|
const conn = itm.connections.in[idx];
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-07-28 23:43:11 +02:00
|
|
|
if(conn.id in connections){
|
|
|
|
itm.connections[idx] = connections[conn.id];
|
|
|
|
} else {
|
|
|
|
connections[conn.id] = conn;
|
|
|
|
}
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
2023-07-28 23:43:11 +02:00
|
|
|
for(const idx in itm.connections.out) {
|
|
|
|
const conn = itm.connections.out[idx];
|
2023-05-17 21:19:14 +02:00
|
|
|
|
2023-07-28 23:43:11 +02:00
|
|
|
if(conn.id in connections){
|
|
|
|
itm.connections[idx] = connections[conn.id];
|
|
|
|
} else {
|
|
|
|
connections[conn.id] = conn;
|
|
|
|
}
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return studyplan;
|
|
|
|
}
|