Added ability to change card's parent.

This commit is contained in:
Nicu Tofan 2018-06-26 17:39:31 +03:00
parent 439d7c3dbc
commit b7d508e8c4
No known key found for this signature in database
GPG key ID: 7EE66E95E64FD0B7
5 changed files with 157 additions and 31 deletions

View file

@ -283,10 +283,37 @@ template(name="cardMorePopup")
button.js-copy-card-link-to-clipboard(class="btn") {{_ 'copy-card-link-to-clipboard'}} button.js-copy-card-link-to-clipboard(class="btn") {{_ 'copy-card-link-to-clipboard'}}
span.clearfix span.clearfix
br br
h2 {{_ 'change-card-parent'}}
label {{_ 'source-board'}}:
select.js-field-parent-board
each boards
if isParentBoard
option(value="{{_id}}" selected) {{title}}
else
option(value="{{_id}}") {{title}}
if isTopLevel
option(value="none" selected) {{_ 'custom-field-dropdown-none'}}
else
option(value="none") {{_ 'custom-field-dropdown-none'}}
label {{_ 'parent-card'}}:
select.js-field-parent-card
if isTopLevel
option(value="none" selected) {{_ 'custom-field-dropdown-none'}}
else
each cards
if isParentCard
option(value="{{_id}}" selected) {{title}}
else
option(value="{{_id}}") {{title}}
option(value="none") {{_ 'custom-field-dropdown-none'}}
br
| {{_ 'added'}} | {{_ 'added'}}
span.date(title=card.createdAt) {{ moment createdAt 'LLL' }} span.date(title=card.createdAt) {{ moment createdAt 'LLL' }}
a.js-delete(title="{{_ 'card-delete-notice'}}") {{_ 'delete'}} a.js-delete(title="{{_ 'card-delete-notice'}}") {{_ 'delete'}}
template(name="cardDeletePopup") template(name="cardDeletePopup")
p {{_ "card-delete-pop"}} p {{_ "card-delete-pop"}}
unless archived unless archived

View file

@ -390,7 +390,6 @@ Template.moveCardPopup.events({
Popup.close(); Popup.close();
}, },
}); });
BlazeComponent.extendComponent({ BlazeComponent.extendComponent({
onCreated() { onCreated() {
subManager.subscribe('board', Session.get('currentBoard')); subManager.subscribe('board', Session.get('currentBoard'));
@ -427,6 +426,7 @@ BlazeComponent.extendComponent({
}, },
}).register('boardsAndLists'); }).register('boardsAndLists');
function cloneCheckList(_id, checklist) { function cloneCheckList(_id, checklist) {
'use strict'; 'use strict';
const checklistId = checklist._id; const checklistId = checklist._id;
@ -558,36 +558,119 @@ Template.copyChecklistToManyCardsPopup.events({
}, },
}); });
BlazeComponent.extendComponent({
Template.cardMorePopup.events({ onCreated() {
'click .js-copy-card-link-to-clipboard' () { this.currentCard = this.currentData();
// Clipboard code from: this.parentCard = this.currentCard.parentCard();
// https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser if (this.parentCard) {
const StringToCopyElement = document.getElementById('cardURL'); this.parentBoard = this.parentCard.board();
StringToCopyElement.select();
if (document.execCommand('copy')) {
StringToCopyElement.blur();
} else { } else {
document.getElementById('cardURL').selectionStart = 0; this.parentBoard = null;
document.getElementById('cardURL').selectionEnd = 999;
document.execCommand('copy');
if (window.getSelection) {
if (window.getSelection().empty) { // Chrome
window.getSelection().empty();
} else if (window.getSelection().removeAllRanges) { // Firefox
window.getSelection().removeAllRanges();
}
} else if (document.selection) { // IE?
document.selection.empty();
}
} }
}, },
'click .js-delete': Popup.afterConfirm('cardDelete', function () {
Popup.close(); boards() {
Cards.remove(this._id); const boards = Boards.find({
Utils.goBoardId(this.boardId); archived: false,
}), 'members.userId': Meteor.userId(),
}); }, {
sort: ['title'],
});
return boards;
},
cards() {
if (this.parentBoard) {
return this.parentBoard.cards();
} else {
return [];
}
},
isParentBoard() {
const board = this.currentData();
if (this.parentBoard) {
return board._id === this.parentBoard;
}
return false;
},
isParentCard() {
const card = this.currentData();
if (this.parentCard) {
return card._id === this.parentCard;
}
return false;
},
setParentCardId(cardId) {
if (cardId === 'null') {
cardId = null;
this.parentCard = null;
} else {
this.parentCard = Cards.findOne(cardId);
}
this.currentCard.setParentId(cardId);
},
events() {
return [{
'click .js-copy-card-link-to-clipboard' () {
// Clipboard code from:
// https://stackoverflow.com/questions/6300213/copy-selected-text-to-the-clipboard-without-using-flash-must-be-cross-browser
const StringToCopyElement = document.getElementById('cardURL');
StringToCopyElement.select();
if (document.execCommand('copy')) {
StringToCopyElement.blur();
} else {
document.getElementById('cardURL').selectionStart = 0;
document.getElementById('cardURL').selectionEnd = 999;
document.execCommand('copy');
if (window.getSelection) {
if (window.getSelection().empty) { // Chrome
window.getSelection().empty();
} else if (window.getSelection().removeAllRanges) { // Firefox
window.getSelection().removeAllRanges();
}
} else if (document.selection) { // IE?
document.selection.empty();
}
}
},
'click .js-delete': Popup.afterConfirm('cardDelete', function () {
Popup.close();
Cards.remove(this._id);
Utils.goBoardId(this.boardId);
}),
'change .js-field-parent-board'(evt) {
const selection = $(evt.currentTarget).val();
const list = $('.js-field-parent-card');
list.empty();
if (selection === 'none') {
this.parentBoard = null;
list.prop('disabled', true);
} else {
this.parentBoard = Boards.findOne(selection);
this.parentBoard.cards().forEach(function(card) {
list.append(
$('<option></option>').val(card._id).html(card.title)
);
});
list.prop('disabled', false);
}
list.append(
`<option value='none' selected='selected'>${TAPi18n.__('custom-field-dropdown-none')}</option>`
);
this.setParentCardId('null');
},
'change .js-field-parent-card'(evt) {
const selection = $(evt.currentTarget).val();
this.setParentCardId(selection);
},
}];
},
}).register('cardMorePopup');
// Close the card details pane by pressing escape // Close the card details pane by pressing escape
EscapeActions.register('detailsPane', EscapeActions.register('detailsPane',

View file

@ -493,6 +493,9 @@
"prefix-with-parent": "Prefix with parent", "prefix-with-parent": "Prefix with parent",
"subtext-with-full-path": "Subtext with full path", "subtext-with-full-path": "Subtext with full path",
"subtext-with-parent": "Subtext with parent", "subtext-with-parent": "Subtext with parent",
"change-card-parent": "Change card's parent",
"parent-card": "Parent card",
"source-board": "Source board",
"no-parent": "Don't show parent" "no-parent": "Don't show parent"
} }

View file

@ -220,6 +220,10 @@ Boards.helpers({
return Swimlanes.find({ boardId: this._id, archived: false }, { sort: { sort: 1 } }); return Swimlanes.find({ boardId: this._id, archived: false }, { sort: { sort: 1 } });
}, },
cards() {
return Cards.find({ boardId: this._id, archived: false }, { sort: { sort: 1 } });
},
hasOvertimeCards(){ hasOvertimeCards(){
const card = Cards.findOne({isOvertime: true, boardId: this._id, archived: false} ); const card = Cards.findOne({isOvertime: true, boardId: this._id, archived: false} );
return card !== undefined; return card !== undefined;

View file

@ -327,10 +327,14 @@ Cards.helpers({
}, },
parentCardName() { parentCardName() {
if (this.parentId === '') { let result = '';
return ''; if (this.parentId !== '') {
const card = Cards.findOne(this.parentId);
if (card) {
result = card.title;
}
} }
return Cards.findOne(this.parentId).title; return result;
}, },
parentListId() { parentListId() {
@ -541,6 +545,11 @@ Cards.mutations({
unsetSpentTime() { unsetSpentTime() {
return {$unset: {spentTime: '', isOvertime: false}}; return {$unset: {spentTime: '', isOvertime: false}};
}, },
setParentId(parentId) {
return {$set: {parentId}};
},
}); });