mirror of
https://github.com/wekan/wekan.git
synced 2026-01-25 10:46:09 +01:00
Manually merged fixes from seve12.
Thanks to seve12 ! Related https://github.com/wekan/wekan/pull/5967
This commit is contained in:
parent
fc3bb962f7
commit
ecfb0f0fdf
14 changed files with 457 additions and 20 deletions
|
|
@ -2107,6 +2107,28 @@ Cards.mutations({
|
|||
Cards.update(this._id, {
|
||||
$set: mutatedFields,
|
||||
});
|
||||
|
||||
// Ensure attachments follow the card to its new board/list/swimlane
|
||||
if (Meteor.isServer) {
|
||||
const updateMeta = {};
|
||||
if (mutatedFields.boardId !== undefined) updateMeta['meta.boardId'] = mutatedFields.boardId;
|
||||
if (mutatedFields.listId !== undefined) updateMeta['meta.listId'] = mutatedFields.listId;
|
||||
if (mutatedFields.swimlaneId !== undefined) updateMeta['meta.swimlaneId'] = mutatedFields.swimlaneId;
|
||||
|
||||
if (Object.keys(updateMeta).length > 0) {
|
||||
try {
|
||||
Attachments.collection.update(
|
||||
{ 'meta.cardId': this._id },
|
||||
{ $set: updateMeta },
|
||||
{ multi: true },
|
||||
);
|
||||
} catch (err) {
|
||||
// Do not block the move if attachment update fails
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Failed to update attachments metadata after moving card', this._id, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
addLabel(labelId) {
|
||||
|
|
|
|||
|
|
@ -76,6 +76,33 @@ export class WekanCreator {
|
|||
|
||||
// maps a wekanCardId to an array of wekanAttachments
|
||||
this.attachments = {};
|
||||
|
||||
// default swimlane id created during import if necessary
|
||||
this._defaultSwimlaneId = null;
|
||||
|
||||
// Normalize possible exported id fields: some exports may use `id` instead of `_id`.
|
||||
// Ensure every item we rely on has an `_id` so mappings work consistently.
|
||||
const normalizeIds = arr => {
|
||||
if (!arr) return;
|
||||
arr.forEach(item => {
|
||||
if (item && item.id && !item._id) {
|
||||
item._id = item.id;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
normalizeIds(data.lists);
|
||||
normalizeIds(data.cards);
|
||||
normalizeIds(data.swimlanes);
|
||||
normalizeIds(data.checklists);
|
||||
normalizeIds(data.checklistItems);
|
||||
normalizeIds(data.triggers);
|
||||
normalizeIds(data.actions);
|
||||
normalizeIds(data.labels);
|
||||
normalizeIds(data.customFields);
|
||||
normalizeIds(data.comments);
|
||||
normalizeIds(data.activities);
|
||||
normalizeIds(data.rules);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -348,7 +375,7 @@ export class WekanCreator {
|
|||
dateLastActivity: this._now(),
|
||||
description: card.description,
|
||||
listId: this.lists[card.listId],
|
||||
swimlaneId: this.swimlanes[card.swimlaneId],
|
||||
swimlaneId: this.swimlanes[card.swimlaneId] || this._defaultSwimlaneId,
|
||||
sort: card.sort,
|
||||
title: card.title,
|
||||
// we attribute the card to its creator if available
|
||||
|
|
@ -588,6 +615,25 @@ export class WekanCreator {
|
|||
}
|
||||
|
||||
createSwimlanes(wekanSwimlanes, boardId) {
|
||||
// If no swimlanes provided, create a default so cards still render
|
||||
if (!wekanSwimlanes || wekanSwimlanes.length === 0) {
|
||||
const swimlaneToCreate = {
|
||||
archived: false,
|
||||
boardId,
|
||||
createdAt: this._now(),
|
||||
title: 'Default',
|
||||
sort: 0,
|
||||
};
|
||||
const created = Swimlanes.direct.insert(swimlaneToCreate);
|
||||
Swimlanes.direct.update(created, {
|
||||
$set: {
|
||||
updatedAt: this._now(),
|
||||
},
|
||||
});
|
||||
this._defaultSwimlaneId = created;
|
||||
return;
|
||||
}
|
||||
|
||||
wekanSwimlanes.forEach((swimlane, swimlaneIndex) => {
|
||||
const swimlaneToCreate = {
|
||||
archived: swimlane.archived,
|
||||
|
|
@ -611,6 +657,9 @@ export class WekanCreator {
|
|||
},
|
||||
});
|
||||
this.swimlanes[swimlane._id] = swimlaneId;
|
||||
if (!this._defaultSwimlaneId) {
|
||||
this._defaultSwimlaneId = swimlaneId;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue