mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-10-12 15:04:04 +00:00
reaply TagHelper from 77417 to fix adding tags without reloading stv studentlist
This commit is contained in:
@@ -6,18 +6,9 @@ export function addTagInTable(addedTag, rows, matchKey, tagsKey = "tags")
|
||||
rows.forEach(row =>
|
||||
{
|
||||
const rowData = row.getData();
|
||||
|
||||
//add save check if String or Array and avoid same reference later for mutations
|
||||
let raw = rowData[tagsKey];
|
||||
let tags = typeof raw === "string"
|
||||
? JSON.parse(raw || "[]")
|
||||
: Array.isArray(raw)
|
||||
? [...raw]
|
||||
: [];
|
||||
|
||||
let updated = false;
|
||||
|
||||
for (const tag of addedTag.response)
|
||||
addedTag.response.forEach(tag =>
|
||||
{
|
||||
if (rowData[matchKey] !== tag[matchKey])
|
||||
return;
|
||||
@@ -52,16 +43,10 @@ export function addTagInTable(addedTag, rows, matchKey, tagsKey = "tags")
|
||||
});
|
||||
rowData[tagsKey] = JSON.stringify(tags);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
if (updated)
|
||||
{
|
||||
row.update({
|
||||
[tagsKey]: JSON.stringify(tags)
|
||||
});
|
||||
|
||||
row.reformat();
|
||||
}
|
||||
if (updated)
|
||||
row.update(rowData);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -75,10 +60,8 @@ export function deleteTagInTable(deletedTag, rows, tagsKeys = ['tags'])
|
||||
let updates = {};
|
||||
let changed = false;
|
||||
|
||||
for (const key of tagsKeys) {
|
||||
let raw = rowData[key];
|
||||
|
||||
let tags = [];
|
||||
tagsKeys.forEach(key => {
|
||||
let tags;
|
||||
|
||||
try {
|
||||
let initialTags = rowData[key] || "[]";
|
||||
@@ -92,15 +75,15 @@ export function deleteTagInTable(deletedTag, rows, tagsKeys = ['tags'])
|
||||
}
|
||||
|
||||
if (!Array.isArray(tags))
|
||||
continue;
|
||||
return;
|
||||
|
||||
let filtered = tags.filter(tag => tag?.id !== deletedTag);
|
||||
|
||||
if (filtered.length !== tags.length) {
|
||||
if (filtered.length !== tags.length)
|
||||
{
|
||||
updates[key] = JSON.stringify(filtered);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (changed) {
|
||||
row.update(updates);
|
||||
@@ -109,6 +92,7 @@ export function deleteTagInTable(deletedTag, rows, tagsKeys = ['tags'])
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function updateTagInTable(updatedTag, rows, fields = ['tags'])
|
||||
{
|
||||
if (!Array.isArray(fields))
|
||||
|
||||
Reference in New Issue
Block a user