Skip to content
Snippets Groups Projects
Commit e139d87a authored by Ron Lucke's avatar Ron Lucke Committed by Elmar Ludwig
Browse files

fixes #26

parent f4e4b5b5
No related branches found
No related tags found
No related merge requests found
...@@ -150,6 +150,7 @@ export default { ...@@ -150,6 +150,7 @@ export default {
discardStateArrayChildren: [], discardStateArrayChildren: [],
sortArrayContainers: [], sortArrayContainers: [],
discardStateArrayContainers: [], discardStateArrayContainers: [],
insertingInProgress: false,
}; };
}, },
computed: { computed: {
...@@ -300,115 +301,126 @@ export default { ...@@ -300,115 +301,126 @@ export default {
this.$emit('selectElement', target); this.$emit('selectElement', target);
}, },
async insertElement(data) { async insertElement(data) {
let source = data.source; if(!this.insertingInProgress) {
let element = data.element; this.insertingInProgress = true;
if (source === 'self') { let source = data.source;
element.relationships.parent.data.id = this.filingData.parentItem.id; let element = data.element;
element.attributes.position = this.filingData.parentItem.relationships.children.data.length; if (source === 'self') {
await this.lockObject({ id: element.id, type: 'courseware-structural-elements' }); element.relationships.parent.data.id = this.filingData.parentItem.id;
await this.updateStructuralElement({ element.attributes.position = this.filingData.parentItem.relationships.children.data.length;
element: element, await this.lockObject({ id: element.id, type: 'courseware-structural-elements' });
id: element.id, await this.updateStructuralElement({
}); element: element,
await this.unlockObject({ id: element.id, type: 'courseware-structural-elements' }); id: element.id,
this.loadStructuralElement(this.currentElement.id); });
this.$emit('reloadElement'); await this.unlockObject({ id: element.id, type: 'courseware-structural-elements' });
this.$store.dispatch('cwManagerFilingData', {}); this.loadStructuralElement(this.currentElement.id);
} else if(source === 'remote' || source === 'own') { this.$emit('reloadElement');
//create Element this.$store.dispatch('cwManagerFilingData', {});
let parentId = this.filingData.parentItem.id; } else if(source === 'remote' || source === 'own') {
await this.copyStructuralElement({ //create Element
parentId: parentId, let parentId = this.filingData.parentItem.id;
element: element, await this.copyStructuralElement({
}); parentId: parentId,
this.$emit('loadSelf', parentId); element: element,
this.$store.dispatch('cwManagerFilingData', {}); });
} else { this.$emit('loadSelf', parentId);
console.log('unreliable source:'); this.$store.dispatch('cwManagerFilingData', {});
console.log(source); } else {
console.log(element); console.log('unreliable source:');
console.log(source);
console.log(element);
}
this.insertingInProgress = false;
} }
}, },
async insertContainer(data) { async insertContainer(data) {
let source = data.source; if(!this.insertingInProgress) {
let container = data.container; this.insertingInProgress = true;
if (source === 'self') { let source = data.source;
container.relationships['structural-element'].data.id = this.filingData.parentItem.id; let container = data.container;
container.attributes.position = this.filingData.parentItem.relationships.containers.data.length; if (source === 'self') {
await this.lockObject({id: container.id, type: 'courseware-containers'}); container.relationships['structural-element'].data.id = this.filingData.parentItem.id;
await this.updateContainer({ container.attributes.position = this.filingData.parentItem.relationships.containers.data.length;
container: container, await this.lockObject({id: container.id, type: 'courseware-containers'});
structuralElementId: this.currentElement.id await this.updateContainer({
}); container: container,
await this.unlockObject({id: container.id, type: 'courseware-containers'}); structuralElementId: this.currentElement.id
this.$emit('reloadElement'); });
this.$store.dispatch('cwManagerFilingData', {}); await this.unlockObject({id: container.id, type: 'courseware-containers'});
} else if (source === 'remote' || source === 'own') { this.$emit('reloadElement');
let parentId = this.filingData.parentItem.id; this.$store.dispatch('cwManagerFilingData', {});
await this.copyContainer({ } else if (source === 'remote' || source === 'own') {
parentId: parentId, let parentId = this.filingData.parentItem.id;
container: container, await this.copyContainer({
}); parentId: parentId,
this.$emit('loadSelf', parentId); container: container,
this.$store.dispatch('cwManagerFilingData', {}); });
} else { this.$emit('loadSelf', parentId);
console.log('unreliable source:'); this.$store.dispatch('cwManagerFilingData', {});
console.log(source); } else {
console.log(container); console.log('unreliable source:');
console.log(source);
console.log(container);
}
this.insertingInProgress = false;
} }
}, },
async insertBlock(data) { async insertBlock(data) {
let source = data.source; if(!this.insertingInProgress) {
let block = data.block; this.insertingInProgress = true;
if (source === 'self') { let source = data.source;
let sourceContainer = await this.containerById({id: block.relationships.container.data.id}); let block = data.block;
sourceContainer.attributes.payload.sections.forEach(section => { if (source === 'self') {
let index = section.blocks.indexOf(block.id); let sourceContainer = await this.containerById({id: block.relationships.container.data.id});
if(index !== -1) { sourceContainer.attributes.payload.sections.forEach(section => {
section.blocks.splice(index, 1); let index = section.blocks.indexOf(block.id);
} if(index !== -1) {
}); section.blocks.splice(index, 1);
await this.lockObject({id: sourceContainer.id, type: 'courseware-containers'}); }
await this.updateContainer({ });
container: sourceContainer, await this.lockObject({id: sourceContainer.id, type: 'courseware-containers'});
structuralElementId: sourceContainer.relationships['structural-element'].data.id await this.updateContainer({
}); container: sourceContainer,
await this.unlockObject({id: sourceContainer.id, type: 'courseware-containers'}); structuralElementId: sourceContainer.relationships['structural-element'].data.id
});
await this.unlockObject({id: sourceContainer.id, type: 'courseware-containers'});
let destinationContainer = await this.containerById({id: this.filingData.parentItem.id}); let destinationContainer = await this.containerById({id: this.filingData.parentItem.id});
destinationContainer.attributes.payload.sections[destinationContainer.attributes.payload.sections.length-1].blocks.push(block.id); destinationContainer.attributes.payload.sections[destinationContainer.attributes.payload.sections.length-1].blocks.push(block.id);
await this.lockObject({id: destinationContainer.id, type: 'courseware-containers'}); await this.lockObject({id: destinationContainer.id, type: 'courseware-containers'});
await this.updateContainer({ await this.updateContainer({
container: destinationContainer, container: destinationContainer,
structuralElementId: destinationContainer.relationships['structural-element'].data.id structuralElementId: destinationContainer.relationships['structural-element'].data.id
}); });
await this.unlockObject({id: destinationContainer.id, type: 'courseware-containers'}); await this.unlockObject({id: destinationContainer.id, type: 'courseware-containers'});
block.relationships.container.data.id = this.filingData.parentItem.id; block.relationships.container.data.id = this.filingData.parentItem.id;
block.attributes.position = this.filingData.parentItem.relationships.blocks.data.length; block.attributes.position = this.filingData.parentItem.relationships.blocks.data.length;
await this.lockObject({id: block.id, type: 'courseware-blocks'}); await this.lockObject({id: block.id, type: 'courseware-blocks'});
await this.updateBlock({ await this.updateBlock({
block: block, block: block,
containerId: this.filingData.parentItem.id containerId: this.filingData.parentItem.id
}); });
await this.unlockObject({id: block.id, type: 'courseware-blocks'}); await this.unlockObject({id: block.id, type: 'courseware-blocks'});
await this.loadContainer(sourceContainer.id); await this.loadContainer(sourceContainer.id);
await this.loadContainer(destinationContainer.id); await this.loadContainer(destinationContainer.id);
this.$emit('reloadElement'); this.$emit('reloadElement');
this.$store.dispatch('cwManagerFilingData', {}); this.$store.dispatch('cwManagerFilingData', {});
} else if (source === 'remote' || source === 'own') { } else if (source === 'remote' || source === 'own') {
let parentId = this.filingData.parentItem.id; let parentId = this.filingData.parentItem.id;
await this.copyBlock({ await this.copyBlock({
parentId: parentId, parentId: parentId,
block: block, block: block,
}); });
await this.loadContainer(parentId); await this.loadContainer(parentId);
this.$emit('loadSelf',this.filingData.parentItem.relationships['structural-element'].data.id); this.$emit('loadSelf',this.filingData.parentItem.relationships['structural-element'].data.id);
this.$store.dispatch('cwManagerFilingData', {}); this.$store.dispatch('cwManagerFilingData', {});
} else { } else {
console.debug('unreliable source:', source, block); console.debug('unreliable source:', source, block);
}
this.insertingInProgress = false;
} }
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment