diff options
Diffstat (limited to 'client/components/boards/boardBody.js')
-rw-r--r-- | client/components/boards/boardBody.js | 216 |
1 files changed, 208 insertions, 8 deletions
diff --git a/client/components/boards/boardBody.js b/client/components/boards/boardBody.js index 456bf9b3..301c0742 100644 --- a/client/components/boards/boardBody.js +++ b/client/components/boards/boardBody.js @@ -1,5 +1,6 @@ const subManager = new SubsManager(); -const { calculateIndex } = Utils; +const { calculateIndex, enableClickOnTouch } = Utils; +const swimlaneWhileSortingHeight = 150; BlazeComponent.extendComponent({ onCreated() { @@ -35,6 +36,37 @@ BlazeComponent.extendComponent({ this._isDragging = false; // Used to set the overlay this.mouseHasEnterCardDetails = false; + + // fix swimlanes sort field if there are null values + const currentBoardData = Boards.findOne(Session.get('currentBoard')); + const nullSortSwimlanes = currentBoardData.nullSortSwimlanes(); + if (nullSortSwimlanes.count() > 0) { + const swimlanes = currentBoardData.swimlanes(); + let count = 0; + swimlanes.forEach((s) => { + Swimlanes.update(s._id, { + $set: { + sort: count, + }, + }); + count += 1; + }); + } + + // fix lists sort field if there are null values + const nullSortLists = currentBoardData.nullSortLists(); + if (nullSortLists.count() > 0) { + const lists = currentBoardData.lists(); + let count = 0; + lists.forEach((l) => { + Lists.update(l._id, { + $set: { + sort: count, + }, + }); + count += 1; + }); + } }, onRendered() { const boardComponent = this; @@ -43,21 +75,64 @@ BlazeComponent.extendComponent({ $swimlanesDom.sortable({ tolerance: 'pointer', appendTo: '.board-canvas', - helper: 'clone', + helper(evt, item) { + const helper = $(`<div class="swimlane" + style="flex-direction: column; + height: ${swimlaneWhileSortingHeight}px; + width: $(boardComponent.width)px; + overflow: hidden;"/>`); + helper.append(item.clone()); + // Also grab the list of lists of cards + const list = item.next(); + helper.append(list.clone()); + return helper; + }, handle: '.js-swimlane-header', - items: '.js-swimlane:not(.placeholder)', + items: '.swimlane:not(.placeholder)', placeholder: 'swimlane placeholder', distance: 7, start(evt, ui) { + const listDom = ui.placeholder.next('.js-swimlane'); + const parentOffset = ui.item.parent().offset(); + ui.placeholder.height(ui.helper.height()); EscapeActions.executeUpTo('popup-close'); + listDom.addClass('moving-swimlane'); boardComponent.setIsDragging(true); + + ui.placeholder.insertAfter(ui.placeholder.next()); + boardComponent.origPlaceholderIndex = ui.placeholder.index(); + + // resize all swimlanes + headers to be a total of 150 px per row + // this could be achieved by setIsDragging(true) but we want immediate + // result + ui.item.siblings('.js-swimlane').css('height', `${swimlaneWhileSortingHeight - 26}px`); + + // set the new scroll height after the resize and insertion of + // the placeholder. We want the element under the cursor to stay + // at the same place on the screen + ui.item.parent().get(0).scrollTop = ui.placeholder.get(0).offsetTop + parentOffset.top - evt.pageY; + }, + beforeStop(evt, ui) { + const parentOffset = ui.item.parent().offset(); + const siblings = ui.item.siblings('.js-swimlane'); + siblings.css('height', ''); + + // compute the new scroll height after the resize and removal of + // the placeholder + const scrollTop = ui.placeholder.get(0).offsetTop + parentOffset.top - evt.pageY; + + // then reset the original view of the swimlane + siblings.removeClass('moving-swimlane'); + + // and apply the computed scrollheight + ui.item.parent().get(0).scrollTop = scrollTop; }, 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. - const prevSwimlaneDom = ui.item.prev('.js-swimlane').get(0); - const nextSwimlaneDom = ui.item.next('.js-swimlane').get(0); + const prevSwimlaneDom = ui.item.prevAll('.js-swimlane').get(0); + const nextSwimlaneDom = ui.item.nextAll('.js-swimlane').get(0); const sortIndex = calculateIndex(prevSwimlaneDom, nextSwimlaneDom, 1); $swimlanesDom.sortable('cancel'); @@ -72,8 +147,35 @@ BlazeComponent.extendComponent({ boardComponent.setIsDragging(false); }, + sort(evt, ui) { + // get the mouse position in the sortable + const parentOffset = ui.item.parent().offset(); + const cursorY = evt.pageY - parentOffset.top + ui.item.parent().scrollTop(); + + // compute the intended index of the placeholder (we need to skip the + // slots between the headers and the list of cards) + const newplaceholderIndex = Math.floor(cursorY / swimlaneWhileSortingHeight); + let destPlaceholderIndex = (newplaceholderIndex + 1) * 2; + + // if we are scrolling far away from the bottom of the list + if (destPlaceholderIndex >= ui.item.parent().get(0).childElementCount) { + destPlaceholderIndex = ui.item.parent().get(0).childElementCount - 1; + } + + // update the placeholder position in the DOM tree + if (destPlaceholderIndex !== ui.placeholder.index()) { + if (destPlaceholderIndex < boardComponent.origPlaceholderIndex) { + ui.placeholder.insertBefore(ui.placeholder.siblings().slice(destPlaceholderIndex - 2, destPlaceholderIndex - 1)); + } else { + ui.placeholder.insertAfter(ui.placeholder.siblings().slice(destPlaceholderIndex - 1, destPlaceholderIndex)); + } + } + }, }); + // ugly touch event hotfix + enableClickOnTouch('.js-swimlane:not(.placeholder)'); + function userIsMember() { return Meteor.user() && Meteor.user().isBoardMember() && !Meteor.user().isCommentOnly(); } @@ -88,12 +190,20 @@ BlazeComponent.extendComponent({ isViewSwimlanes() { const currentUser = Meteor.user(); - return (currentUser.profile.boardView === 'board-view-swimlanes'); + if (!currentUser) return false; + return ((currentUser.profile || {}).boardView === 'board-view-swimlanes'); }, isViewLists() { const currentUser = Meteor.user(); - return (currentUser.profile.boardView === 'board-view-lists'); + if (!currentUser) return true; + return ((currentUser.profile || {}).boardView === 'board-view-lists'); + }, + + isViewCalendar() { + const currentUser = Meteor.user(); + if (!currentUser) return false; + return ((currentUser.profile || {}).boardView === 'board-view-cal'); }, openNewListForm() { @@ -105,7 +215,6 @@ BlazeComponent.extendComponent({ .childComponents('addListForm')[0].open(); } }, - events() { return [{ // XXX The board-overlay div should probably be moved to the parent @@ -137,4 +246,95 @@ BlazeComponent.extendComponent({ }); }, + scrollTop(position = 0) { + const swimlanes = this.$('.js-swimlanes'); + swimlanes && swimlanes.animate({ + scrollTop: position, + }); + }, + }).register('boardBody'); + +BlazeComponent.extendComponent({ + onRendered() { + this.autorun(function(){ + $('#calendar-view').fullCalendar('refetchEvents'); + }); + }, + calendarOptions() { + return { + id: 'calendar-view', + defaultView: 'agendaDay', + editable: true, + timezone: 'local', + header: { + left: 'title today prev,next', + center: 'agendaDay,listDay,timelineDay agendaWeek,listWeek,timelineWeek month,timelineMonth timelineYear', + right: '', + }, + // height: 'parent', nope, doesn't work as the parent might be small + height: 'auto', + /* TODO: lists as resources: https://fullcalendar.io/docs/vertical-resource-view */ + navLinks: true, + nowIndicator: true, + businessHours: { + // days of week. an array of zero-based day of week integers (0=Sunday) + dow: [ 1, 2, 3, 4, 5 ], // Monday - Friday + start: '8:00', + end: '18:00', + }, + locale: TAPi18n.getLanguage(), + events(start, end, timezone, callback) { + const currentBoard = Boards.findOne(Session.get('currentBoard')); + const events = []; + currentBoard.cardsInInterval(start.toDate(), end.toDate()).forEach(function(card){ + events.push({ + id: card._id, + title: card.title, + start: card.startAt, + end: card.endAt, + allDay: Math.abs(card.endAt.getTime() - card.startAt.getTime()) / 1000 === 24*3600, + url: FlowRouter.url('card', { + boardId: currentBoard._id, + slug: currentBoard.slug, + cardId: card._id, + }), + }); + }); + callback(events); + }, + eventResize(event, delta, revertFunc) { + let isOk = false; + const card = Cards.findOne(event.id); + + if (card) { + card.setEnd(event.end.toDate()); + isOk = true; + } + if (!isOk) { + revertFunc(); + } + }, + eventDrop(event, delta, revertFunc) { + let isOk = false; + const card = Cards.findOne(event.id); + if (card) { + // TODO: add a flag for allDay events + if (!event.allDay) { + card.setStart(event.start.toDate()); + card.setEnd(event.end.toDate()); + isOk = true; + } + } + if (!isOk) { + revertFunc(); + } + }, + }; + }, + isViewCalendar() { + const currentUser = Meteor.user(); + if (!currentUser) return false; + return ((currentUser.profile || {}).boardView === 'board-view-cal'); + }, +}).register('calendarView'); |