Add module copy functionality - drag module whilst holding 'alt' to copy

This commit is contained in:
Cmdr McDonald
2016-12-18 21:37:21 +00:00
parent 5bf907809d
commit f82122f29f
7 changed files with 45 additions and 33 deletions

View File

@@ -12,20 +12,28 @@ export default class Module {
* @param {Object} params Module parameters. Either grp/id or template
*/
constructor(params) {
let properties = Object.assign({ grp: null, id: null, template: null, }, params);
let properties = Object.assign({ grp: null, id: null, template: null }, params);
let template;
if (properties.template == undefined) {
return ModuleUtils.findModule(properties.grp, properties.id);
if (properties.class != undefined) {
// We already have a fully-formed module; copy the data over
for (let p in properties) { this[p] = properties[p]; }
} else if (properties.template != undefined) {
// We have a template from coriolis-data; copy the data over
for (let p in properties.template) { this[p] = properties.template[p]; }
} else {
template = properties.template;
if (template) {
// Copy all properties from coriolis-data template
for (let p in template) { this[p] = template[p]; }
}
// We don't have a template; find it given the group and ID
return ModuleUtils.findModule(properties.grp, properties.id);
}
}
/**
* Clone an existing module
* @return {Object} A clone of the existing module
*/
clone() {
return new Module(JSON.parse(JSON.stringify(this)));
}
/**
* Get a value for a given modification
* @param {Number} name The name of the modification