Skip to content
Snippets Groups Projects
Commit 0fd56511 authored by Farbod Zamani's avatar Farbod Zamani Committed by Ron Lucke
Browse files

Resolve "early disappearing of notification on insert - (shifting) in courseware", fixes #325

parent c6e0728a
No related branches found
No related tags found
No related merge requests found
...@@ -302,11 +302,33 @@ export default { ...@@ -302,11 +302,33 @@ export default {
selectChapter(target) { selectChapter(target) {
this.$emit('selectElement', target); this.$emit('selectElement', target);
}, },
validateSource(source) {
return (source === 'self' || source === 'remote' || source === 'own');
},
afterInsertCompletion() {
this.$nextTick(() => {
// will run after $emit is done
this.$store.dispatch('cwManagerFilingData', {});
setTimeout(() => {
this.insertingInProgress = false;
}, 250);
});
},
async insertElement(data) { async insertElement(data) {
if(!this.insertingInProgress) {
this.insertingInProgress = true;
let source = data.source; let source = data.source;
let element = data.element; let element = data.element;
if (!this.validateSource(source)) {
console.log('unreliable source:');
console.log(source);
console.log(element);
return;
}
if(!this.insertingInProgress) {
this.insertingInProgress = true;
if (source === 'self') { if (source === 'self') {
element.relationships.parent.data.id = this.filingData.parentItem.id; element.relationships.parent.data.id = this.filingData.parentItem.id;
element.attributes.position = this.childrenById(this.filingData.parentItem.id).length + 1; element.attributes.position = this.childrenById(this.filingData.parentItem.id).length + 1;
...@@ -318,7 +340,6 @@ export default { ...@@ -318,7 +340,6 @@ export default {
await this.unlockObject({ id: element.id, type: 'courseware-structural-elements' }); await this.unlockObject({ id: element.id, type: 'courseware-structural-elements' });
this.loadStructuralElement(this.currentElement.id); this.loadStructuralElement(this.currentElement.id);
this.$emit('reloadElement'); this.$emit('reloadElement');
this.$store.dispatch('cwManagerFilingData', {});
} else if(source === 'remote' || source === 'own') { } else if(source === 'remote' || source === 'own') {
//create Element //create Element
let parentId = this.filingData.parentItem.id; let parentId = this.filingData.parentItem.id;
...@@ -327,20 +348,22 @@ export default { ...@@ -327,20 +348,22 @@ export default {
element: element, element: element,
}); });
this.$emit('loadSelf', parentId); this.$emit('loadSelf', parentId);
this.$store.dispatch('cwManagerFilingData', {});
} else {
console.log('unreliable source:');
console.log(source);
console.log(element);
} }
this.insertingInProgress = false; this.afterInsertCompletion();
} }
}, },
async insertContainer(data) { async insertContainer(data) {
if(!this.insertingInProgress) {
this.insertingInProgress = true;
let source = data.source; let source = data.source;
let container = data.container; let container = data.container;
if (!this.validateSource(source)) {
console.log('unreliable source:');
console.log(source);
console.log(container);
return;
}
if(!this.insertingInProgress) {
this.insertingInProgress = true;
if (source === 'self') { if (source === 'self') {
container.relationships['structural-element'].data.id = this.filingData.parentItem.id; container.relationships['structural-element'].data.id = this.filingData.parentItem.id;
container.attributes.position = this.filingData.parentItem.relationships.containers.data.length + 1; container.attributes.position = this.filingData.parentItem.relationships.containers.data.length + 1;
...@@ -351,7 +374,6 @@ export default { ...@@ -351,7 +374,6 @@ export default {
}); });
await this.unlockObject({id: container.id, type: 'courseware-containers'}); await this.unlockObject({id: container.id, type: 'courseware-containers'});
this.$emit('reloadElement'); this.$emit('reloadElement');
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.copyContainer({ await this.copyContainer({
...@@ -359,21 +381,22 @@ export default { ...@@ -359,21 +381,22 @@ export default {
container: container, container: container,
}); });
this.$emit('loadSelf', parentId); this.$emit('loadSelf', parentId);
this.$store.dispatch('cwManagerFilingData', {});
} else {
console.log('unreliable source:');
console.log(source);
console.log(container);
} }
this.insertingInProgress = false; this.afterInsertCompletion();
} }
}, },
async insertBlock(data) { async insertBlock(data) {
if(!this.insertingInProgress) {
this.insertingInProgress = true;
let source = data.source; let source = data.source;
let block = data.block; let block = data.block;
if (!this.validateSource(source)) {
console.debug('unreliable source:', source, block);
return;
}
if(!this.insertingInProgress) {
this.insertingInProgress = true;
if (source === 'self') { if (source === 'self') {
let sourceContainer = await this.containerById({id: block.relationships.container.data.id}); let sourceContainer = await this.containerById({id: block.relationships.container.data.id});
sourceContainer.attributes.payload.sections.forEach(section => { sourceContainer.attributes.payload.sections.forEach(section => {
...@@ -409,7 +432,6 @@ export default { ...@@ -409,7 +432,6 @@ export default {
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', {});
} 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({
...@@ -418,11 +440,8 @@ export default { ...@@ -418,11 +440,8 @@ export default {
}); });
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', {});
} else {
console.debug('unreliable source:', source, block);
} }
this.insertingInProgress = false; this.afterInsertCompletion();
} }
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment