Add sortDefault helper for sorting boards

This commit is contained in:
boeserwolf 2020-04-19 12:30:21 +03:00
parent 9f396e9038
commit 10fcc19b7f
10 changed files with 50 additions and 31 deletions

View file

@ -7,7 +7,7 @@ BlazeComponent.extendComponent({
return Boards.find(
{ archived: true },
{
sort: ['title'],
sort: { sort: 1 /* boards default sorting */ }
},
);
},

View file

@ -7,8 +7,8 @@ Template.boardListHeaderBar.events({
});
Template.boardListHeaderBar.helpers({
title(){
return FlowRouter.getRouteName() == 'home' ? 'my-boards' :'public';
title() {
return FlowRouter.getRouteName() == 'home' ? 'my-boards' : 'public';
},
templatesBoardId() {
return Meteor.user() && Meteor.user().getTemplatesBoardId();
@ -27,16 +27,12 @@ BlazeComponent.extendComponent({
let query = {
archived: false,
type: 'board',
}
};
if (FlowRouter.getRouteName() == 'home')
query['members.userId'] = Meteor.userId()
else
query.permission = 'public'
query['members.userId'] = Meteor.userId();
else query.permission = 'public';
return Boards.find(
query,
{ sort: ['title'] },
);
return Boards.find(query, { sort: { sort: 1 /* boards default sorting */ } });
},
isStarred() {
const user = Meteor.user();

View file

@ -727,7 +727,7 @@ BlazeComponent.extendComponent({
_id: { $ne: Meteor.user().getTemplatesBoardId() },
},
{
sort: ['title'],
sort: { sort: 1 /* boards default sorting */ },
},
);
return boards;
@ -903,7 +903,7 @@ BlazeComponent.extendComponent({
},
},
{
sort: ['title'],
sort: { sort: 1 /* boards default sorting */ },
},
);
return boards;
@ -974,7 +974,7 @@ BlazeComponent.extendComponent({
}
}
},
'click .js-delete': Popup.afterConfirm('cardDelete', function () {
'click .js-delete': Popup.afterConfirm('cardDelete', function() {
Popup.close();
Cards.remove(this._id);
Utils.goBoardId(this.boardId);

View file

@ -411,7 +411,7 @@ BlazeComponent.extendComponent({
type: 'board',
},
{
sort: ['title'],
sort: { sort: 1 /* boards default sorting */ },
},
);
return boards;
@ -597,7 +597,7 @@ BlazeComponent.extendComponent({
type: 'board',
},
{
sort: ['title'],
sort: { sort: 1 /* boards default sorting */ },
},
);
return boards;

View file

@ -11,7 +11,7 @@ BlazeComponent.extendComponent({
},
},
{
sort: ['title'],
sort: { sort: 1 /* boards default sorting */ },
},
);
return boards;

View file

@ -48,7 +48,7 @@ BlazeComponent.extendComponent({
'members.isAdmin': true,
},
{
sort: ['title'],
sort: { sort: 1 /* boards default sorting */ },
},
);
},

View file

@ -510,7 +510,7 @@ BlazeComponent.extendComponent({
'members.userId': Meteor.userId(),
},
{
sort: ['title'],
sort: { sort: 1 /* boards default sorting */ },
},
);
},
@ -589,7 +589,7 @@ BlazeComponent.extendComponent({
'subtext-with-parent',
'no-parent',
];
options.forEach(function (element) {
options.forEach(function(element) {
if (element !== value) {
$(`#${element} ${MCB}`).toggleClass(CKCLS, false);
$(`#${element}`).toggleClass(CKCLS, false);
@ -688,7 +688,7 @@ BlazeComponent.extendComponent({
'members.userId': Meteor.userId(),
},
{
sort: ['title'],
sort: { sort: 1 /* boards default sorting */ },
},
);
},

View file

@ -1474,7 +1474,7 @@ if (Meteor.isServer) {
'members.userId': paramUserId,
},
{
sort: ['title'],
sort: { sort: 1 /* boards default sorting */ },
},
).map(function(board) {
return {
@ -1504,7 +1504,12 @@ if (Meteor.isServer) {
Authentication.checkUserId(req.userId);
JsonRoutes.sendResult(res, {
code: 200,
data: Boards.find({ permission: 'public' }).map(function(doc) {
data: Boards.find(
{ permission: 'public' },
{
sort: { sort: 1 /* boards default sorting */ },
},
).map(function(doc) {
return {
_id: doc._id,
title: doc.title,

View file

@ -386,12 +386,20 @@ if (Meteor.isClient) {
Users.helpers({
boards() {
return Boards.find({ 'members.userId': this._id });
return Boards.find(
{ 'members.userId': this._id },
{ sort: { sort: 1 /* boards default sorting */ } },
);
},
starredBoards() {
const { starredBoards = [] } = this.profile || {};
return Boards.find({ archived: false, _id: { $in: starredBoards } });
return Boards.find(
{ archived: false, _id: { $in: starredBoards } },
{
sort: { sort: 1 /* boards default sorting */ },
},
);
},
hasStarred(boardId) {
@ -401,7 +409,12 @@ Users.helpers({
invitedBoards() {
const { invitedBoards = [] } = this.profile || {};
return Boards.find({ archived: false, _id: { $in: invitedBoards } });
return Boards.find(
{ archived: false, _id: { $in: invitedBoards } },
{
sort: { sort: 1 /* boards default sorting */ },
},
);
},
isInvitedTo(boardId) {
@ -1292,10 +1305,13 @@ if (Meteor.isServer) {
let data = Meteor.users.findOne({ _id: id });
if (data !== undefined) {
if (action === 'takeOwnership') {
data = Boards.find({
'members.userId': id,
'members.isAdmin': true,
}).map(function(board) {
data = Boards.find(
{
'members.userId': id,
'members.isAdmin': true,
},
{ sort: { sort: 1 /* boards default sorting */ } },
).map(function(board) {
if (board.hasMember(req.userId)) {
board.removeMember(req.userId);
}

View file

@ -36,6 +36,7 @@ Meteor.publish('boards', function() {
permission: 1,
type: 1,
},
sort: { sort: 1 /* boards default sorting */ },
},
);
});
@ -61,6 +62,7 @@ Meteor.publish('archivedBoards', function() {
slug: 1,
title: 1,
},
sort: { sort: 1 /* boards default sorting */ },
},
);
});
@ -90,7 +92,7 @@ Meteor.publishRelations('board', function(boardId, isArchived) {
$or,
// Sort required to ensure oplog usage
},
{ limit: 1, sort: { _id: 1 } },
{ limit: 1, sort: { sort: 1 /* boards default sorting */, _id: 1 } },
),
function(boardId, board) {
this.cursor(Lists.find({ boardId, archived: isArchived }));