/** * 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 = {}; for(const il in studyplan.studylines) { const line = studyplan.studylines[il]; for(const is in line.slots ) { const slot = line.slots[is]; if(slot.competencies !== undefined){ for(const ic in slot.competencies){ const itm = slot.competencies[ic]; for(const idx in itm.connections.in) { const conn = itm.connections.in[idx]; if(conn.id in connections){ itm.connections[idx] = connections[conn.id]; } else { connections[conn.id] = conn; } } for(const idx in itm.connections.out) { const conn = itm.connections.out[idx]; if(conn.id in connections){ itm.connections[idx] = connections[conn.id]; } else { connections[conn.id] = conn; } } } } if(slot.filters !== undefined){ for(const ix in slot.filters){ const itm = slot.filters[ix]; for(const idx in itm.connections.in) { const conn = itm.connections.in[idx]; if(conn.id in connections){ itm.connections[idx] = connections[conn.id]; } else { connections[conn.id] = conn; } } for(const idx in itm.connections.out) { const conn = itm.connections.out[idx]; if(conn.id in connections){ itm.connections[idx] = connections[conn.id]; } else { connections[conn.id] = conn; } } } } } } return studyplan; } /** * Update the line wrapper elements to properly display the lines between items */ export function fixLineWrappers(){ let elmLineWrappers = document.getElementsByClassName('l-leaderline-linewrapper'); //debug.info("Line wrappers",elmLineWrappers); for(let i =0; i < elmLineWrappers.length; i++){ const elm = elmLineWrappers[i]; elm.style.transform = ''; let rectWrapper = elm.getBoundingClientRect(); //debug.info("Line wrapper",elm,rectWrapper,[window.pageXOffset,window.pageYOffset]); // Move to the origin of coordinates as the document elm.style.transform = 'translate(' + ((rectWrapper.left + window.pageXOffset ) * -1) + 'px, ' + ((rectWrapper.top + window.pageYOffset ) * -1) + 'px)'; } }