2023-01-16 23:00:10 +01:00
|
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
2021-07-10 10:55:54 +02:00
|
|
|
import { TAPi18n } from '/imports/i18n';
|
2026-03-08 11:01:21 +02:00
|
|
|
import Lists from '/models/lists';
|
|
|
|
|
import Swimlanes from '/models/swimlanes';
|
2021-07-10 10:55:54 +02:00
|
|
|
|
2021-12-08 06:53:22 +01:00
|
|
|
//archivedRequested = false;
|
2019-05-13 11:01:50 +02:00
|
|
|
const subManager = new SubsManager();
|
|
|
|
|
|
2026-03-08 11:01:21 +02:00
|
|
|
function getArchivedCards() {
|
|
|
|
|
const ret = ReactiveCache.getCards(
|
|
|
|
|
{
|
|
|
|
|
archived: true,
|
|
|
|
|
boardId: Session.get('currentBoard'),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sort: { archivedAt: -1, modifiedAt: -1 },
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getArchivedLists() {
|
|
|
|
|
return ReactiveCache.getLists(
|
|
|
|
|
{
|
|
|
|
|
archived: true,
|
|
|
|
|
boardId: Session.get('currentBoard'),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sort: { archivedAt: -1, modifiedAt: -1 },
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getArchivedSwimlanes() {
|
|
|
|
|
return ReactiveCache.getSwimlanes(
|
|
|
|
|
{
|
|
|
|
|
archived: true,
|
|
|
|
|
boardId: Session.get('currentBoard'),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sort: { archivedAt: -1, modifiedAt: -1 },
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Template.archivesSidebar.onCreated(function () {
|
|
|
|
|
this.isArchiveReady = new ReactiveVar(false);
|
|
|
|
|
|
|
|
|
|
// The pattern we use to manually handle data loading is described here:
|
|
|
|
|
// https://kadira.io/academy/meteor-routing-guide/content/subscriptions-and-data-management/using-subs-manager
|
|
|
|
|
// XXX The boardId should be readed from some sort the component "props",
|
|
|
|
|
// unfortunatly, Blaze doesn't have this notion.
|
|
|
|
|
this.autorun(() => {
|
|
|
|
|
const currentBoardId = Session.get('currentBoard');
|
|
|
|
|
if (!currentBoardId) return;
|
|
|
|
|
const handle = subManager.subscribe('board', currentBoardId, true);
|
|
|
|
|
//archivedRequested = true;
|
|
|
|
|
Tracker.nonreactive(() => {
|
|
|
|
|
Tracker.autorun(() => {
|
|
|
|
|
this.isArchiveReady.set(handle.ready());
|
2019-05-13 11:01:50 +02:00
|
|
|
});
|
|
|
|
|
});
|
2026-03-08 11:01:21 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Template.archivesSidebar.onRendered(function () {
|
|
|
|
|
// XXX We should support dragging a card from the sidebar to the board
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Template.archivesSidebar.helpers({
|
|
|
|
|
isArchiveReady() {
|
|
|
|
|
return Template.instance().isArchiveReady;
|
|
|
|
|
},
|
|
|
|
|
isBoardAdmin() {
|
|
|
|
|
return ReactiveCache.getCurrentUser().isBoardAdmin();
|
|
|
|
|
},
|
|
|
|
|
isWorker() {
|
|
|
|
|
const currentBoard = Utils.getCurrentBoard();
|
|
|
|
|
return (
|
|
|
|
|
!currentBoard.hasAdmin(this.userId) && currentBoard.hasWorker(this.userId)
|
|
|
|
|
);
|
2019-05-13 11:01:50 +02:00
|
|
|
},
|
|
|
|
|
|
2015-09-03 23:12:46 +02:00
|
|
|
tabs() {
|
2015-08-22 02:06:49 +02:00
|
|
|
return [
|
2015-09-01 14:38:07 +02:00
|
|
|
{ name: TAPi18n.__('cards'), slug: 'cards' },
|
2015-09-03 23:12:46 +02:00
|
|
|
{ name: TAPi18n.__('lists'), slug: 'lists' },
|
2018-02-01 14:23:27 -03:00
|
|
|
{ name: TAPi18n.__('swimlanes'), slug: 'swimlanes' },
|
2015-09-03 23:12:46 +02:00
|
|
|
];
|
2015-08-22 02:06:49 +02:00
|
|
|
},
|
|
|
|
|
|
2015-09-03 23:12:46 +02:00
|
|
|
archivedCards() {
|
2026-03-08 11:01:21 +02:00
|
|
|
return getArchivedCards();
|
2015-08-22 02:06:49 +02:00
|
|
|
},
|
|
|
|
|
|
2015-09-03 23:12:46 +02:00
|
|
|
archivedLists() {
|
2026-03-08 11:01:21 +02:00
|
|
|
return getArchivedLists();
|
2015-06-07 18:55:26 +02:00
|
|
|
},
|
|
|
|
|
|
2018-02-01 14:23:27 -03:00
|
|
|
archivedSwimlanes() {
|
2026-03-08 11:01:21 +02:00
|
|
|
return getArchivedSwimlanes();
|
2018-02-01 14:23:27 -03:00
|
|
|
},
|
|
|
|
|
|
2015-09-03 23:12:46 +02:00
|
|
|
cardIsInArchivedList() {
|
2026-03-08 11:01:21 +02:00
|
|
|
return Template.currentData().list().archived;
|
2015-08-20 23:48:34 +02:00
|
|
|
},
|
2026-03-08 11:01:21 +02:00
|
|
|
});
|
2015-08-20 23:48:34 +02:00
|
|
|
|
2026-03-08 11:01:21 +02:00
|
|
|
Template.archivesSidebar.events({
|
|
|
|
|
async 'click .js-restore-card'() {
|
|
|
|
|
const card = Template.currentData();
|
|
|
|
|
if (card.canBeRestored()) {
|
|
|
|
|
await card.restore();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
async 'click .js-restore-all-cards'() {
|
|
|
|
|
for (const card of getArchivedCards()) {
|
|
|
|
|
if (card.canBeRestored()) {
|
|
|
|
|
await card.restore();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-07 18:55:26 +02:00
|
|
|
},
|
|
|
|
|
|
2026-03-08 11:01:21 +02:00
|
|
|
'click .js-delete-card': Popup.afterConfirm('cardDelete', async function() {
|
|
|
|
|
const cardId = this._id;
|
|
|
|
|
await Cards.removeAsync(cardId);
|
|
|
|
|
Popup.back();
|
|
|
|
|
}),
|
|
|
|
|
'click .js-delete-all-cards': Popup.afterConfirm('cardDelete', async () => {
|
|
|
|
|
for (const card of getArchivedCards()) {
|
|
|
|
|
await Cards.removeAsync(card._id);
|
|
|
|
|
}
|
|
|
|
|
Popup.back();
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
async 'click .js-restore-list'() {
|
|
|
|
|
const data = Template.currentData();
|
|
|
|
|
const list = Lists.findOne(data._id) || data;
|
|
|
|
|
await list.restore();
|
|
|
|
|
},
|
|
|
|
|
async 'click .js-restore-all-lists'() {
|
|
|
|
|
for (const list of getArchivedLists()) {
|
|
|
|
|
await list.restore();
|
|
|
|
|
}
|
2015-09-03 23:12:46 +02:00
|
|
|
},
|
2020-01-05 21:28:14 +02:00
|
|
|
|
2026-03-08 11:01:21 +02:00
|
|
|
'click .js-delete-list': Popup.afterConfirm('listDelete', async function() {
|
|
|
|
|
const list = Lists.findOne(this._id);
|
|
|
|
|
if (list) await list.remove();
|
|
|
|
|
Popup.back();
|
|
|
|
|
}),
|
|
|
|
|
'click .js-delete-all-lists': Popup.afterConfirm('listDelete', async () => {
|
|
|
|
|
for (const list of getArchivedLists()) {
|
|
|
|
|
await list.remove();
|
|
|
|
|
}
|
|
|
|
|
Popup.back();
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
async 'click .js-restore-swimlane'() {
|
|
|
|
|
const data = Template.currentData();
|
|
|
|
|
const swimlane = Swimlanes.findOne(data._id) || data;
|
|
|
|
|
await swimlane.restore();
|
2020-12-17 21:27:02 +02:00
|
|
|
},
|
2026-03-08 11:01:21 +02:00
|
|
|
async 'click .js-restore-all-swimlanes'() {
|
|
|
|
|
for (const swimlane of getArchivedSwimlanes()) {
|
|
|
|
|
await swimlane.restore();
|
|
|
|
|
}
|
2020-01-05 21:28:14 +02:00
|
|
|
},
|
2026-03-08 11:01:21 +02:00
|
|
|
|
|
|
|
|
'click .js-delete-swimlane': Popup.afterConfirm(
|
|
|
|
|
'swimlaneDelete',
|
|
|
|
|
async function() {
|
|
|
|
|
const swimlane = Swimlanes.findOne(this._id);
|
|
|
|
|
if (swimlane) await swimlane.remove();
|
|
|
|
|
Popup.back();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
'click .js-delete-all-swimlanes': Popup.afterConfirm(
|
|
|
|
|
'swimlaneDelete',
|
|
|
|
|
async () => {
|
|
|
|
|
for (const swimlane of getArchivedSwimlanes()) {
|
|
|
|
|
await swimlane.remove();
|
|
|
|
|
}
|
|
|
|
|
Popup.back();
|
|
|
|
|
},
|
|
|
|
|
),
|
2020-01-05 21:28:14 +02:00
|
|
|
});
|