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

CW - More accurate unordered blocks checker

Closes #1852

Merge request studip/studip!1282
parent 0dbc82bb
No related branches found
No related tags found
No related merge requests found
......@@ -191,11 +191,15 @@ export default {
const unallocated = new Set(this.blocks.map(({ id }) => id));
sections.forEach(section => {
for (let section of sections) {
section.locked = false;
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) {
this.unallocatedBlocks = [...unallocated].map((id) => view.blockById({ id }));
......@@ -374,9 +378,11 @@ export default {
}
},
watch: {
blocks() {
if (!this.showEdit) {
this.initCurrentData();
blocks(newBlocks, oldBlocks) {
if (!this.showEdit && !this.checkSimpleArrayEquality(newBlocks, oldBlocks)) {
this.$nextTick(() => {
setTimeout(() => this.initCurrentData(), 250);
});
}
},
currentSections: {
......
......@@ -198,11 +198,15 @@ export default {
const unallocated = new Set(this.blocks.map(({ id }) => id));
sections.forEach(section => {
for (let section of sections) {
section.locked = false;
section.blocks = section.blocks.map((id) => view.blockById({id})).filter((a) => a);
section.blocks.forEach(({ id }) => unallocated.delete(id));
});
section.blocks = section.blocks.map((id) => view.blockById({id})).filter(Boolean);
for (let sectionBlock of section.blocks) {
if (sectionBlock?.id && unallocated.has(sectionBlock.id)) {
unallocated.delete(sectionBlock.id);
}
}
}
if (unallocated.size > 0) {
this.unallocatedBlocks = [...unallocated].map((id) => view.blockById({ id }));
......@@ -374,9 +378,11 @@ export default {
}
},
watch: {
blocks() {
if (!this.showEdit) {
this.initCurrentData();
blocks(newBlocks, oldBlocks) {
if (!this.showEdit && !this.checkSimpleArrayEquality(newBlocks, oldBlocks)) {
this.$nextTick(() => {
setTimeout(() => this.initCurrentData(), 250);
});
}
},
currentSections: {
......
......@@ -73,6 +73,11 @@ const containerMixin = {
this.loadContainer({id : data.originContainerId });
this.loadContainer({id : data.targetContainerId });
},
checkSimpleArrayEquality(firstSet, secondSet) {
return Array.isArray(firstSet) && Array.isArray(secondSet) &&
firstSet.length === secondSet.length &&
firstSet.every((val, index) => val === secondSet[index]);
}
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment