Skip to content
Snippets Groups Projects
Commit b022f52a authored by Farbod Zamani's avatar Farbod Zamani Committed by Jan-Hendrik Willms
Browse files

CW - More accurate unordered blocks checker

Closes #1852

Merge request studip/studip!1282
parent ff1b242d
No related branches found
No related tags found
No related merge requests found
...@@ -164,11 +164,15 @@ export default { ...@@ -164,11 +164,15 @@ export default {
const unallocated = new Set(this.blocks.map(({ id }) => id)); const unallocated = new Set(this.blocks.map(({ id }) => id));
sections.forEach(section => { for (let section of sections) {
section.locked = false; section.locked = false;
section.blocks = section.blocks.map((id) => view.blockById({id})).filter(Boolean); section.blocks = section.blocks.map((id) => view.blockById({id})).filter(Boolean);
section.blocks.forEach(({ id }) => unallocated.delete(id)); for (let sectionBlock of section.blocks) {
}); if (sectionBlock?.id && unallocated.has(sectionBlock.id)) {
unallocated.delete(sectionBlock.id);
}
}
}
if (unallocated.size > 0) { if (unallocated.size > 0) {
this.unallocatedBlocks = [...unallocated].map((id) => view.blockById({ id })); this.unallocatedBlocks = [...unallocated].map((id) => view.blockById({ id }));
...@@ -247,9 +251,11 @@ export default { ...@@ -247,9 +251,11 @@ export default {
} }
}, },
watch: { watch: {
blocks() { blocks(newBlocks, oldBlocks) {
if (!this.showEdit) { if (!this.showEdit && !this.checkSimpleArrayEquality(newBlocks, oldBlocks)) {
this.initCurrentData(); this.$nextTick(() => {
setTimeout(() => this.initCurrentData(), 250);
});
} }
} }
} }
......
...@@ -181,11 +181,15 @@ export default { ...@@ -181,11 +181,15 @@ export default {
const unallocated = new Set(this.blocks.map(({ id }) => id)); const unallocated = new Set(this.blocks.map(({ id }) => id));
sections.forEach(section => { for (let section of sections) {
section.locked = false; section.locked = false;
section.blocks = section.blocks.map((id) => view.blockById({id})).filter((a) => a); section.blocks = section.blocks.map((id) => view.blockById({id})).filter(Boolean);
section.blocks.forEach(({ id }) => unallocated.delete(id)); for (let sectionBlock of section.blocks) {
}); if (sectionBlock?.id && unallocated.has(sectionBlock.id)) {
unallocated.delete(sectionBlock.id);
}
}
}
if (unallocated.size > 0) { if (unallocated.size > 0) {
this.unallocatedBlocks = [...unallocated].map((id) => view.blockById({ id })); this.unallocatedBlocks = [...unallocated].map((id) => view.blockById({ id }));
...@@ -265,9 +269,11 @@ export default { ...@@ -265,9 +269,11 @@ export default {
} }
}, },
watch: { watch: {
blocks() { blocks(newBlocks, oldBlocks) {
if (!this.showEdit) { if (!this.showEdit && !this.checkSimpleArrayEquality(newBlocks, oldBlocks)) {
this.initCurrentData(); this.$nextTick(() => {
setTimeout(() => this.initCurrentData(), 250);
});
} }
} }
} }
......
...@@ -7,6 +7,13 @@ const containerMixin = { ...@@ -7,6 +7,13 @@ const containerMixin = {
created: function () { created: function () {
this.pluginManager.registerComponentsLocally(this); this.pluginManager.registerComponentsLocally(this);
}, },
methods: {
checkSimpleArrayEquality(firstSet, secondSet) {
return Array.isArray(firstSet) && Array.isArray(secondSet) &&
firstSet.length === secondSet.length &&
firstSet.every((val, index) => val === secondSet[index]);
}
}
}; };
export default containerMixin; export default containerMixin;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment