1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-08-09 15:35:29 +02:00

#27 import labels

This commit is contained in:
Christoph Enne 2022-12-10 20:18:01 +01:00
parent 3270a0338e
commit d06c0c8b06

View file

@ -1,5 +1,17 @@
async function importFromTrello(inputs) { async function importFromTrello(inputs) {
const trelloToPlankaLabels = {};
const getTrelloLists = () => inputs.trelloBoard.lists.filter((list) => !list.closed); const getTrelloLists = () => inputs.trelloBoard.lists.filter((list) => !list.closed);
const getUsedTrelloLabels = () => {
const result = {};
inputs.trelloBoard.cards
.map((card) => card.labels)
.flat()
.forEach((label) => {
result[label.id] = label;
});
return Object.values(result);
};
const getTrelloCardsOfList = (listId) => const getTrelloCardsOfList = (listId) =>
inputs.trelloBoard.cards.filter((l) => l.idList === listId && !l.closed); inputs.trelloBoard.cards.filter((l) => l.idList === listId && !l.closed);
const getAllTrelloCheckItemsOfCard = (cardId) => const getAllTrelloCheckItemsOfCard = (cardId) =>
@ -15,6 +27,8 @@ async function importFromTrello(inputs) {
action.data.card && action.data.card &&
action.data.card.id === cardId, action.data.card.id === cardId,
); );
const getPlankaLabelColor = (trelloLabelColor) =>
Label.COLORS.find((c) => c.indexOf(trelloLabelColor) !== -1) || 'desert-sand';
const importComments = async (trelloCard, plankaCard) => { const importComments = async (trelloCard, plankaCard) => {
const trelloComments = getTrelloCommentsOfCard(trelloCard.id); const trelloComments = getTrelloCommentsOfCard(trelloCard.id);
@ -56,6 +70,18 @@ async function importFromTrello(inputs) {
); );
}; };
const importCardLabels = async (trelloCard, plankaCard) => {
return Promise.all(
trelloCard.labels.map(async (trelloLabel) => {
return sails.helpers.cardLabels.createOne(
trelloToPlankaLabels[trelloLabel.id],
plankaCard,
inputs.request,
);
}),
);
};
const importCards = async (trelloList, plankaList) => { const importCards = async (trelloList, plankaList) => {
return Promise.all( return Promise.all(
getTrelloCardsOfList(trelloList.id).map(async (trelloCard) => { getTrelloCardsOfList(trelloList.id).map(async (trelloCard) => {
@ -72,6 +98,7 @@ async function importFromTrello(inputs) {
inputs.request, inputs.request,
); );
await importCardLabels(trelloCard, plankaCard);
await importTasks(trelloCard, plankaCard); await importTasks(trelloCard, plankaCard);
await importComments(trelloCard, plankaCard); await importComments(trelloCard, plankaCard);
return plankaCard; return plankaCard;
@ -95,6 +122,23 @@ async function importFromTrello(inputs) {
); );
}; };
const importLabels = async () => {
return Promise.all(
getUsedTrelloLabels().map(async (trelloLabel) => {
const plankaLabel = await sails.helpers.labels.createOne(
{
name: trelloLabel.name || null,
color: getPlankaLabelColor(trelloLabel.color),
},
inputs.board,
inputs.request,
);
trelloToPlankaLabels[trelloLabel.id] = plankaLabel;
}),
);
};
await importLabels();
await importLists(); await importLists();
} }