mirror of
https://github.com/wekan/wekan.git
synced 2025-04-23 13:37:09 -04:00
Allow list creation from template
This commit is contained in:
parent
044126188d
commit
f888cfd565
8 changed files with 121 additions and 26 deletions
|
@ -57,7 +57,7 @@ template(name="addCardForm")
|
|||
span.quiet
|
||||
|
|
||||
| /
|
||||
a.js-search-template {{_ 'template'}}
|
||||
a.js-card-template {{_ 'template'}}
|
||||
|
||||
template(name="autocompleteLabelLine")
|
||||
.minicard-label(class="card-label-{{colorName}}" title=labelName)
|
||||
|
@ -104,5 +104,12 @@ template(name="searchCardPopup")
|
|||
.list-body.js-perfect-scrollbar.search-card-results
|
||||
.minicards.clearfix.js-minicards
|
||||
each results
|
||||
a.minicard-wrapper.js-minicard
|
||||
+minicard(this)
|
||||
if isListTemplateSearch
|
||||
a.minicard-wrapper.js-minicard
|
||||
+minilist(this)
|
||||
if isSwimlaneTemplateSearch
|
||||
a.minicard-wrapper.js-minicard
|
||||
+miniswimlane(this)
|
||||
unless isTemplateSearch
|
||||
a.minicard-wrapper.js-minicard
|
||||
+minicard(this)
|
||||
|
|
|
@ -524,7 +524,10 @@ BlazeComponent.extendComponent({
|
|||
},
|
||||
|
||||
onCreated() {
|
||||
this.isTemplateSearch = $(Popup._getTopStack().openerElement).hasClass('js-search-template');
|
||||
this.isCardTemplateSearch = $(Popup._getTopStack().openerElement).hasClass('js-card-template');
|
||||
this.isListTemplateSearch = $(Popup._getTopStack().openerElement).hasClass('js-list-template');
|
||||
this.isSwimlaneTemplateSearch = $(Popup._getTopStack().openerElement).hasClass('js-swimlane-template');
|
||||
this.isTemplateSearch = this.isCardTemplateSearch || this.isListTemplateSearch || this.isSwimlaneTemplateSearch;
|
||||
let board = {};
|
||||
if (this.isTemplateSearch) {
|
||||
board = Boards.findOne(Meteor.user().profile.templatesBoardId);
|
||||
|
@ -579,7 +582,15 @@ BlazeComponent.extendComponent({
|
|||
return [];
|
||||
}
|
||||
const board = Boards.findOne(this.selectedBoardId.get());
|
||||
return board.searchCards(this.term.get(), false);
|
||||
if (!this.isTemplateSearch || this.isCardTemplateSearch) {
|
||||
return board.searchCards(this.term.get(), false);
|
||||
} else if (this.isListTemplateSearch) {
|
||||
return board.searchLists(this.term.get());
|
||||
} else if (this.isSwimlaneTemplateSearch) {
|
||||
return board.searchSwimlanes(this.term.get());
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
|
||||
events() {
|
||||
|
@ -593,25 +604,38 @@ BlazeComponent.extendComponent({
|
|||
this.term.set(evt.target.searchTerm.value);
|
||||
},
|
||||
'click .js-minicard'(evt) {
|
||||
let card = Blaze.getData(evt.currentTarget);
|
||||
// 0. Common
|
||||
let element = Blaze.getData(evt.currentTarget);
|
||||
console.log(element);
|
||||
element.boardId = this.boardId;
|
||||
let _id = '';
|
||||
// Common
|
||||
card.listId = this.listId;
|
||||
card.swimlaneId = this.swimlaneId;
|
||||
card.boardId = this.boardId;
|
||||
card.sort = Lists.findOne(this.listId).cards().count();
|
||||
// From template
|
||||
if (this.isTemplateSearch) {
|
||||
card.type = 'cardType-card';
|
||||
card.linkedId = '';
|
||||
_id = card.copy();
|
||||
} else { // Linked
|
||||
card._id = null;
|
||||
card.type = 'cardType-linkedCard';
|
||||
card.linkedId = card.linkedId || card._id;
|
||||
_id = Cards.insert(card);
|
||||
if (!this.isTemplateSearch || this.isCardTemplateSearch) {
|
||||
// Card insertion
|
||||
// 1. Common
|
||||
element.listId = this.listId;
|
||||
element.swimlaneId = this.swimlaneId;
|
||||
element.sort = Lists.findOne(this.listId).cards().count();
|
||||
// 1.A From template
|
||||
if (this.isTemplateSearch) {
|
||||
element.type = 'cardType-card';
|
||||
element.linkedId = '';
|
||||
_id = element.copy();
|
||||
// 1.B Linked card
|
||||
} else {
|
||||
element._id = null;
|
||||
element.type = 'cardType-linkedCard';
|
||||
element.linkedId = element.linkedId || element._id;
|
||||
_id = Cards.insert(element);
|
||||
}
|
||||
Filter.addException(_id);
|
||||
// List insertion
|
||||
} else if (this.isListTemplateSearch) {
|
||||
element.swimlaneId = '';
|
||||
element.sort = Swimlanes.findOne(this.swimlaneId).lists().count();
|
||||
element.type = 'list';
|
||||
element.swimlaneId = this.swimlaneId;
|
||||
_id = element.copy();
|
||||
}
|
||||
Filter.addException(_id);
|
||||
Popup.close();
|
||||
},
|
||||
}];
|
||||
|
|
8
client/components/lists/minilist.jade
Normal file
8
client/components/lists/minilist.jade
Normal file
|
@ -0,0 +1,8 @@
|
|||
template(name="minilist")
|
||||
.minicard(
|
||||
class="minicard-{{colorClass}}")
|
||||
.minicard-title
|
||||
.handle
|
||||
.fa.fa-arrows
|
||||
+viewer
|
||||
= title
|
8
client/components/swimlanes/miniswimlane.jade
Normal file
8
client/components/swimlanes/miniswimlane.jade
Normal file
|
@ -0,0 +1,8 @@
|
|||
template(name="miniswimlane")
|
||||
.minicard(
|
||||
class="minicard-{{colorClass}}")
|
||||
.minicard-title
|
||||
.handle
|
||||
.fa.fa-arrows
|
||||
+viewer
|
||||
= title
|
|
@ -51,7 +51,11 @@ template(name="addListForm")
|
|||
autocomplete="off" autofocus)
|
||||
.edit-controls.clearfix
|
||||
button.primary.confirm(type="submit") {{_ 'save'}}
|
||||
a.fa.fa-times-thin.js-close-inlined-form
|
||||
unless currentBoard.isTemplatesBoard
|
||||
unless currentBoard.isTemplateBoard
|
||||
span.quiet
|
||||
| {{_ 'or'}}
|
||||
a.js-list-template {{_ 'template'}}
|
||||
else
|
||||
a.open-list-composer.js-open-inlined-form
|
||||
i.fa.fa-plus
|
||||
|
|
|
@ -154,6 +154,8 @@ BlazeComponent.extendComponent({
|
|||
|
||||
BlazeComponent.extendComponent({
|
||||
onCreated() {
|
||||
currentBoard = Boards.findOne(Session.get('currentBoard'));
|
||||
this.isListTemplatesSwimlane = currentBoard.isTemplatesBoard() && this.currentData().isListTemplatesSwimlane();
|
||||
this.currentSwimlane = this.currentData();
|
||||
},
|
||||
|
||||
|
@ -169,19 +171,19 @@ BlazeComponent.extendComponent({
|
|||
const titleInput = this.find('.list-name-input');
|
||||
const title = titleInput.value.trim();
|
||||
if (title) {
|
||||
const listType = (this.currentSwimlane.isListTemplatesSwimlane())?'template-list':'list';
|
||||
Lists.insert({
|
||||
title,
|
||||
boardId: Session.get('currentBoard'),
|
||||
sort: $('.list').length,
|
||||
type: listType,
|
||||
swimlaneId: this.currentSwimlane._id,
|
||||
type: (this.isListTemplatesSwimlane)?'template-list':'list',
|
||||
swimlaneId: (this.isListTemplatesSwimlane)?this.currentSwimlane._id:'',
|
||||
});
|
||||
|
||||
titleInput.value = '';
|
||||
titleInput.focus();
|
||||
}
|
||||
},
|
||||
'click .js-list-template': Popup.open('searchCard'),
|
||||
}];
|
||||
},
|
||||
}).register('addListForm');
|
||||
|
|
|
@ -463,6 +463,30 @@ Boards.helpers({
|
|||
return _id;
|
||||
},
|
||||
|
||||
searchLists(term) {
|
||||
check(term, Match.OneOf(String, null, undefined));
|
||||
|
||||
const query = { boardId: this._id };
|
||||
if (this.isTemplatesBoard()) {
|
||||
query.type = 'template-list';
|
||||
query.archived = false;
|
||||
} else {
|
||||
query.type = {$nin: ['template-list']};
|
||||
}
|
||||
const projection = { limit: 10, sort: { createdAt: -1 } };
|
||||
|
||||
if (term) {
|
||||
const regex = new RegExp(term, 'i');
|
||||
|
||||
query.$or = [
|
||||
{ title: regex },
|
||||
{ description: regex },
|
||||
];
|
||||
}
|
||||
|
||||
return Lists.find(query, projection);
|
||||
},
|
||||
|
||||
searchCards(term, excludeLinked) {
|
||||
check(term, Match.OneOf(String, null, undefined));
|
||||
|
||||
|
|
|
@ -137,6 +137,24 @@ Lists.allow({
|
|||
});
|
||||
|
||||
Lists.helpers({
|
||||
copy() {
|
||||
const oldId = this._id;
|
||||
this._id = null;
|
||||
const _id = Lists.insert(this);
|
||||
|
||||
// Copy all cards in list
|
||||
Cards.find({
|
||||
listId: oldId,
|
||||
archived: false,
|
||||
}).forEach((card) => {
|
||||
card.type = 'cardType-card';
|
||||
card.listId = _id;
|
||||
card.boardId = this.boardId;
|
||||
card.swimlaneId = this.swimlaneId;
|
||||
card.copy();
|
||||
});
|
||||
},
|
||||
|
||||
cards(swimlaneId) {
|
||||
const selector = {
|
||||
listId: this._id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue