2017-11-20 23:24:27 +07:00
|
|
|
const subManager = new SubsManager();
|
2020-04-27 01:15:10 +02:00
|
|
|
const { calculateIndex, enableClickOnTouch } = Utils;
|
2017-11-20 23:24:27 +07:00
|
|
|
|
2019-02-22 22:59:19 +01:00
|
|
|
Template.boardListHeaderBar.events({
|
|
|
|
'click .js-open-archived-board'() {
|
|
|
|
Modal.open('archivedBoards');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Template.boardListHeaderBar.helpers({
|
2020-04-19 12:30:21 +03:00
|
|
|
title() {
|
2020-04-21 17:06:39 +02:00
|
|
|
return FlowRouter.getRouteName() === 'home' ? 'my-boards' : 'public';
|
2020-04-12 00:56:35 +02:00
|
|
|
},
|
2019-02-22 22:59:19 +01:00
|
|
|
templatesBoardId() {
|
2019-08-08 14:54:22 -05:00
|
|
|
return Meteor.user() && Meteor.user().getTemplatesBoardId();
|
2019-02-22 22:59:19 +01:00
|
|
|
},
|
|
|
|
templatesBoardSlug() {
|
2019-08-08 14:54:22 -05:00
|
|
|
return Meteor.user() && Meteor.user().getTemplatesBoardSlug();
|
2019-02-22 22:59:19 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2015-05-27 17:17:00 +02:00
|
|
|
BlazeComponent.extendComponent({
|
2017-11-29 11:23:49 +02:00
|
|
|
onCreated() {
|
|
|
|
Meteor.subscribe('setting');
|
|
|
|
},
|
|
|
|
|
2020-04-19 12:45:04 +03:00
|
|
|
onRendered() {
|
|
|
|
const itemsSelector = '.js-board:not(.placeholder)';
|
|
|
|
|
|
|
|
const $boards = this.$('.js-boards');
|
|
|
|
$boards.sortable({
|
|
|
|
connectWith: '.js-boards',
|
|
|
|
tolerance: 'pointer',
|
|
|
|
appendTo: '.board-list',
|
|
|
|
helper: 'clone',
|
|
|
|
distance: 7,
|
|
|
|
items: itemsSelector,
|
|
|
|
placeholder: 'board-wrapper placeholder',
|
|
|
|
start(evt, ui) {
|
|
|
|
ui.helper.css('z-index', 1000);
|
|
|
|
ui.placeholder.height(ui.helper.height());
|
|
|
|
EscapeActions.executeUpTo('popup-close');
|
|
|
|
},
|
|
|
|
stop(evt, ui) {
|
|
|
|
// To attribute the new index number, we need to get the DOM element
|
|
|
|
// of the previous and the following card -- if any.
|
2020-04-19 15:52:43 +03:00
|
|
|
const prevBoardDom = ui.item.prev('.js-board').get(0);
|
|
|
|
const nextBoardBom = ui.item.next('.js-board').get(0);
|
|
|
|
const sortIndex = calculateIndex(prevBoardDom, nextBoardBom, 1);
|
2020-04-19 12:45:04 +03:00
|
|
|
|
|
|
|
const boardDomElement = ui.item.get(0);
|
|
|
|
const board = Blaze.getData(boardDomElement);
|
|
|
|
// Normally the jquery-ui sortable library moves the dragged DOM element
|
|
|
|
// to its new position, which disrupts Blaze reactive updates mechanism
|
|
|
|
// (especially when we move the last card of a list, or when multiple
|
|
|
|
// users move some cards at the same time). To prevent these UX glitches
|
|
|
|
// we ask sortable to gracefully cancel the move, and to put back the
|
|
|
|
// DOM in its initial state. The card move is then handled reactively by
|
|
|
|
// Blaze with the below query.
|
|
|
|
$boards.sortable('cancel');
|
|
|
|
|
|
|
|
board.move(sortIndex.base);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-04-27 01:15:10 +02:00
|
|
|
// ugly touch event hotfix
|
|
|
|
enableClickOnTouch(itemsSelector);
|
|
|
|
|
2020-04-19 12:45:04 +03:00
|
|
|
// Disable drag-dropping if the current user is not a board member or is comment only
|
|
|
|
this.autorun(() => {
|
2020-05-16 03:15:14 +03:00
|
|
|
if (Utils.isMiniScreen()) {
|
2020-05-16 03:08:05 +03:00
|
|
|
$boards.sortable({
|
|
|
|
handle: '.board-handle',
|
|
|
|
});
|
|
|
|
}
|
2020-04-19 12:45:04 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-09-03 23:12:46 +02:00
|
|
|
boards() {
|
2020-05-03 00:33:15 +02:00
|
|
|
const query = {
|
2020-04-12 00:56:35 +02:00
|
|
|
archived: false,
|
|
|
|
type: 'board',
|
2020-04-19 12:30:21 +03:00
|
|
|
};
|
2020-04-21 17:06:39 +02:00
|
|
|
if (FlowRouter.getRouteName() === 'home')
|
2020-04-19 12:30:21 +03:00
|
|
|
query['members.userId'] = Meteor.userId();
|
|
|
|
else query.permission = 'public';
|
2020-04-12 00:56:35 +02:00
|
|
|
|
2020-04-22 21:00:31 +03:00
|
|
|
return Boards.find(query, {
|
|
|
|
sort: { sort: 1 /* boards default sorting */ },
|
|
|
|
});
|
2015-05-27 17:17:00 +02:00
|
|
|
},
|
2015-09-03 23:12:46 +02:00
|
|
|
isStarred() {
|
|
|
|
const user = Meteor.user();
|
2015-08-23 22:00:02 +02:00
|
|
|
return user && user.hasStarred(this.currentData()._id);
|
2015-05-27 17:17:00 +02:00
|
|
|
},
|
2020-04-13 15:46:29 +02:00
|
|
|
isAdministrable() {
|
|
|
|
const user = Meteor.user();
|
|
|
|
return user && user.isBoardAdmin(this.currentData()._id);
|
|
|
|
},
|
2015-05-27 17:17:00 +02:00
|
|
|
|
2017-11-20 23:24:27 +07:00
|
|
|
hasOvertimeCards() {
|
2019-05-13 11:01:50 +02:00
|
|
|
subManager.subscribe('board', this.currentData()._id, false);
|
2017-11-20 23:24:27 +07:00
|
|
|
return this.currentData().hasOvertimeCards();
|
|
|
|
},
|
|
|
|
|
|
|
|
hasSpentTimeCards() {
|
2019-05-13 11:01:50 +02:00
|
|
|
subManager.subscribe('board', this.currentData()._id, false);
|
2017-11-20 23:24:27 +07:00
|
|
|
return this.currentData().hasSpentTimeCards();
|
|
|
|
},
|
|
|
|
|
2015-12-07 11:15:57 +08:00
|
|
|
isInvited() {
|
|
|
|
const user = Meteor.user();
|
|
|
|
return user && user.isInvitedTo(this.currentData()._id);
|
|
|
|
},
|
|
|
|
|
2015-09-03 23:12:46 +02:00
|
|
|
events() {
|
2019-06-28 12:52:09 -05:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
'click .js-add-board': Popup.open('createBoard'),
|
|
|
|
'click .js-star-board'(evt) {
|
|
|
|
const boardId = this.currentData()._id;
|
|
|
|
Meteor.user().toggleBoardStar(boardId);
|
|
|
|
evt.preventDefault();
|
|
|
|
},
|
|
|
|
'click .js-clone-board'(evt) {
|
|
|
|
Meteor.call(
|
2021-01-22 14:24:39 +02:00
|
|
|
'copyBoard',
|
2019-06-28 12:52:09 -05:00
|
|
|
this.currentData()._id,
|
2021-01-22 14:24:39 +02:00
|
|
|
{
|
|
|
|
sort: Boards.find({ archived: false }).count(),
|
|
|
|
type: 'board',
|
2021-01-28 18:21:56 +02:00
|
|
|
title: Boards.findOne(this.currentData()._id).title,
|
2021-01-22 14:24:39 +02:00
|
|
|
},
|
2019-06-28 12:52:09 -05:00
|
|
|
(err, res) => {
|
|
|
|
if (err) {
|
|
|
|
this.setError(err.error);
|
|
|
|
} else {
|
|
|
|
Session.set('fromBoard', null);
|
|
|
|
Utils.goBoardId(res);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
evt.preventDefault();
|
|
|
|
},
|
|
|
|
'click .js-archive-board'(evt) {
|
|
|
|
const boardId = this.currentData()._id;
|
|
|
|
Meteor.call('archiveBoard', boardId);
|
|
|
|
evt.preventDefault();
|
|
|
|
},
|
|
|
|
'click .js-accept-invite'() {
|
|
|
|
const boardId = this.currentData()._id;
|
2019-07-18 13:06:25 -05:00
|
|
|
Meteor.call('acceptInvite', boardId);
|
2019-06-28 12:52:09 -05:00
|
|
|
},
|
|
|
|
'click .js-decline-invite'() {
|
|
|
|
const boardId = this.currentData()._id;
|
|
|
|
Meteor.call('quitBoard', boardId, (err, ret) => {
|
|
|
|
if (!err && ret) {
|
2019-07-18 13:06:25 -05:00
|
|
|
Meteor.call('acceptInvite', boardId);
|
2019-06-28 12:52:09 -05:00
|
|
|
FlowRouter.go('home');
|
2019-02-12 23:40:12 +01:00
|
|
|
}
|
2019-06-28 12:52:09 -05:00
|
|
|
});
|
|
|
|
},
|
2015-12-07 11:15:57 +08:00
|
|
|
},
|
2019-06-28 12:52:09 -05:00
|
|
|
];
|
2015-09-03 23:12:46 +02:00
|
|
|
},
|
2015-05-27 17:17:00 +02:00
|
|
|
}).register('boardList');
|