wekan/client/components/sidebar/sidebarArchives.js

160 lines
4.2 KiB
JavaScript
Raw Normal View History

archivedRequested = false;
const subManager = new SubsManager();
2015-06-07 18:55:26 +02:00
BlazeComponent.extendComponent({
onCreated() {
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');
2019-06-28 12:52:09 -05:00
if (!currentBoardId) return;
const handle = subManager.subscribe('board', currentBoardId, true);
archivedRequested = true;
Tracker.nonreactive(() => {
Tracker.autorun(() => {
2019-06-28 12:52:09 -05:00
this.isArchiveReady.set(handle.ready());
});
});
});
},
tabs() {
2015-08-22 02:06:49 +02:00
return [
2015-09-01 14:38:07 +02:00
{ name: TAPi18n.__('cards'), slug: 'cards' },
{ name: TAPi18n.__('lists'), slug: 'lists' },
2018-02-01 14:23:27 -03:00
{ name: TAPi18n.__('swimlanes'), slug: 'swimlanes' },
];
2015-08-22 02:06:49 +02:00
},
archivedCards() {
return Cards.find({
archived: true,
boardId: Session.get('currentBoard'),
}, {
sort: { archivedAt: -1, modifiedAt: -1 },
});
2015-08-22 02:06:49 +02:00
},
archivedLists() {
return Lists.find({
archived: true,
boardId: Session.get('currentBoard'),
}, {
sort: { archivedAt: -1, modifiedAt: -1 },
});
2015-06-07 18:55:26 +02:00
},
2018-02-01 14:23:27 -03:00
archivedSwimlanes() {
return Swimlanes.find({
archived: true,
boardId: Session.get('currentBoard'),
}, {
sort: { archivedAt: -1, modifiedAt: -1 },
2018-02-01 14:23:27 -03:00
});
},
cardIsInArchivedList() {
return this.currentData().list().archived;
},
onRendered() {
// XXX We should support dragging a card from the sidebar to the board
2015-06-07 18:55:26 +02:00
},
events() {
2019-06-28 12:52:09 -05:00
return [
{
'click .js-restore-card'() {
const card = this.currentData();
if (card.canBeRestored()) {
2019-04-23 18:00:09 +02:00
card.restore();
}
2019-06-28 12:52:09 -05:00
},
'click .js-restore-all-cards'() {
this.archivedCards().forEach(card => {
if (card.canBeRestored()) {
card.restore();
}
});
},
2019-04-23 18:00:09 +02:00
2019-06-28 12:52:09 -05:00
'click .js-delete-card': Popup.afterConfirm('cardDelete', function() {
const cardId = this._id;
Cards.remove(cardId);
Popup.close();
}),
'click .js-delete-all-cards': Popup.afterConfirm('cardDelete', () => {
this.archivedCards().forEach(card => {
Cards.remove(card._id);
});
Popup.close();
}),
2019-04-23 18:00:09 +02:00
2019-06-28 12:52:09 -05:00
'click .js-restore-list'() {
const list = this.currentData();
2019-04-23 18:00:09 +02:00
list.restore();
2019-06-28 12:52:09 -05:00
},
'click .js-restore-all-lists'() {
this.archivedLists().forEach(list => {
list.restore();
});
},
2019-04-23 18:00:09 +02:00
2019-06-28 12:52:09 -05:00
'click .js-delete-list': Popup.afterConfirm('listDelete', function() {
this.remove();
Popup.close();
}),
'click .js-delete-all-lists': Popup.afterConfirm('listDelete', () => {
this.archivedLists().forEach(list => {
list.remove();
});
Popup.close();
}),
2019-04-23 18:00:09 +02:00
2019-06-28 12:52:09 -05:00
'click .js-restore-swimlane'() {
const swimlane = this.currentData();
2019-04-23 18:00:09 +02:00
swimlane.restore();
2019-06-28 12:52:09 -05:00
},
'click .js-restore-all-swimlanes'() {
this.archivedSwimlanes().forEach(swimlane => {
swimlane.restore();
});
},
2019-04-23 18:00:09 +02:00
2019-06-28 12:52:09 -05:00
'click .js-delete-swimlane': Popup.afterConfirm(
'swimlaneDelete',
function() {
this.remove();
Popup.close();
},
),
'click .js-delete-all-swimlanes': Popup.afterConfirm(
'swimlaneDelete',
() => {
this.archivedSwimlanes().forEach(swimlane => {
swimlane.remove();
});
Popup.close();
},
),
},
];
},
2015-06-07 18:55:26 +02:00
}).register('archivesSidebar');
Template.archivesSidebar.helpers({
isBoardAdmin() {
return Meteor.user().isBoardAdmin();
},
isWorker() {
const currentBoard = Boards.findOne(Session.get('currentBoard'));
return (
!currentBoard.hasAdmin(this.userId) && currentBoard.hasWorker(this.userId)
);
},
});