summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorSam X. Chen <sam.xi.chen@gmail.com>2019-10-18 16:44:09 -0400
committerSam X. Chen <sam.xi.chen@gmail.com>2019-10-18 16:44:09 -0400
commitbc2a20f04e32607f8488a9cecd815647fb43e40e (patch)
tree1f6105203b71fb5220591f057bf3ed63aac79521 /models
parent2737d6b23f3a0fd2314236a85fbdee536df745a2 (diff)
downloadwekan-bc2a20f04e32607f8488a9cecd815647fb43e40e.tar.gz
wekan-bc2a20f04e32607f8488a9cecd815647fb43e40e.tar.bz2
wekan-bc2a20f04e32607f8488a9cecd815647fb43e40e.zip
Add Feature: allow user to sort Lists in Board by his own preference, boardadmin can star list
Diffstat (limited to 'models')
-rw-r--r--models/boards.js8
-rw-r--r--models/cards.js6
-rw-r--r--models/lists.js22
-rw-r--r--models/swimlanes.js6
-rw-r--r--models/users.js58
5 files changed, 91 insertions, 9 deletions
diff --git a/models/boards.js b/models/boards.js
index c7f93022..85a7558c 100644
--- a/models/boards.js
+++ b/models/boards.js
@@ -409,18 +409,20 @@ Boards.helpers({
},
lists() {
- const enabled = Meteor.user().hasShowDesktopDragHandles();
- return enabled ? this.draggableLists() : this.newestLists();
+ const enabled = Meteor.user().hasSortBy();
+ return enabled ? this.newestLists() : this.draggableLists();
},
newestLists() {
// sorted lists from newest to the oldest, by its creation date or its cards' last modification date
+ const value = Meteor.user()._getListSortBy();
+ const sortKey = { starred: -1, [value[0]]: value[1] }; // [["starred",-1],value];
return Lists.find(
{
boardId: this._id,
archived: false,
},
- { sort: { updatedAt: -1 } },
+ { sort: sortKey },
);
},
draggableLists() {
diff --git a/models/cards.js b/models/cards.js
index 35d596d6..27dda0ee 100644
--- a/models/cards.js
+++ b/models/cards.js
@@ -1696,9 +1696,11 @@ if (Meteor.isServer) {
const activityType = `a-${action}`;
const card = Cards.findOne(doc._id);
const list = card.list();
- if (list) {
+ if (list && action === 'endAt') {
// change list modifiedAt
- const modifiedAt = new Date();
+ const modifiedAt = new Date(
+ new Date(value).getTime() - 365 * 24 * 3600 * 1e3,
+ ); // set it as 1 year before
const boardId = list.boardId;
Lists.direct.update(
{
diff --git a/models/lists.js b/models/lists.js
index 9136c337..16ad434c 100644
--- a/models/lists.js
+++ b/models/lists.js
@@ -11,6 +11,15 @@ Lists.attachSchema(
*/
type: String,
},
+ starred: {
+ /**
+ * if a list is stared
+ * then we put it on the top
+ */
+ type: Boolean,
+ optional: true,
+ defaultValue: false,
+ },
archived: {
/**
* is the list archived
@@ -81,10 +90,14 @@ Lists.attachSchema(
denyUpdate: false,
// eslint-disable-next-line consistent-return
autoValue() {
- if (this.isInsert || this.isUpsert || this.isUpdate) {
+ // this is redundant with updatedAt
+ /*if (this.isInsert || this.isUpsert || this.isUpdate) {
return new Date();
} else {
this.unset();
+ }*/
+ if (!this.isSet) {
+ return new Date();
}
},
},
@@ -252,6 +265,10 @@ Lists.helpers({
return this.type === 'template-list';
},
+ isStarred() {
+ return this.starred === true;
+ },
+
remove() {
Lists.remove({ _id: this._id });
},
@@ -261,6 +278,9 @@ Lists.mutations({
rename(title) {
return { $set: { title } };
},
+ star(enable = true) {
+ return { $set: { starred: !!enable } };
+ },
archive() {
if (this.isTemplateList()) {
diff --git a/models/swimlanes.js b/models/swimlanes.js
index 4cd35574..831f1eff 100644
--- a/models/swimlanes.js
+++ b/models/swimlanes.js
@@ -174,8 +174,8 @@ Swimlanes.helpers({
},
lists() {
- const enabled = Meteor.user().hasShowDesktopDragHandles();
- return enabled ? this.draggableLists() : this.newestLists();
+ const enabled = Meteor.user().hasSortBy();
+ return enabled ? this.newestLists() : this.draggableLists();
},
newestLists() {
// sorted lists from newest to the oldest, by its creation date or its cards' last modification date
@@ -185,7 +185,7 @@ Swimlanes.helpers({
swimlaneId: { $in: [this._id, ''] },
archived: false,
},
- { sort: { updatedAt: -1 } },
+ { sort: { modifiedAt: -1 } },
);
},
draggableLists() {
diff --git a/models/users.js b/models/users.js
index 93fb409e..83a224ba 100644
--- a/models/users.js
+++ b/models/users.js
@@ -4,6 +4,16 @@ const isSandstorm =
Meteor.settings && Meteor.settings.public && Meteor.settings.public.sandstorm;
Users = Meteor.users;
+const allowedSortValues = [
+ '-modifiedAt',
+ 'modifiedAt',
+ '-title',
+ 'title',
+ '-sort',
+ 'sort',
+];
+const defaultSortBy = allowedSortValues[0];
+
/**
* A User in wekan
*/
@@ -191,6 +201,15 @@ Users.attachSchema(
'board-view-cal',
],
},
+ 'profile.listSortBy': {
+ /**
+ * default sort list for user
+ */
+ type: String,
+ optional: true,
+ defaultValue: defaultSortBy,
+ allowedValues: allowedSortValues,
+ },
'profile.templatesBoardId': {
/**
* Reference to the templates board
@@ -365,6 +384,31 @@ Users.helpers({
return _.contains(invitedBoards, boardId);
},
+ _getListSortBy() {
+ const profile = this.profile || {};
+ const sortBy = profile.listSortBy || defaultSortBy;
+ const keyPattern = /^(-{0,1})(.*$)/;
+ const ret = [];
+ if (keyPattern.exec(sortBy)) {
+ ret[0] = RegExp.$2;
+ ret[1] = RegExp.$1 ? -1 : 1;
+ }
+ return ret;
+ },
+ hasSortBy() {
+ // if use doesn't have dragHandle, then we can let user to choose sort list by different order
+ return !this.hasShowDesktopDragHandles();
+ },
+ getListSortBy() {
+ return this._getListSortBy()[0];
+ },
+ getListSortTypes() {
+ return allowedSortValues;
+ },
+ getListSortByDirection() {
+ return this._getListSortBy()[1];
+ },
+
hasTag(tag) {
const { tags = [] } = this.profile || {};
return _.contains(tags, tag);
@@ -485,6 +529,13 @@ Users.mutations({
else this.addTag(tag);
},
+ setListSortBy(value) {
+ return {
+ $set: {
+ 'profile.listSortBy': value,
+ },
+ };
+ },
toggleDesktopHandles(value = false) {
return {
$set: {
@@ -569,6 +620,10 @@ Meteor.methods({
Users.update(userId, { $set: { username } });
}
},
+ setListSortBy(value) {
+ check(value, String);
+ Meteor.user().setListSortBy(value);
+ },
toggleDesktopDragHandles() {
const user = Meteor.user();
user.toggleDesktopHandles(user.hasShowDesktopDragHandles());
@@ -800,6 +855,9 @@ if (Meteor.isServer) {
if (Meteor.isServer) {
// Let mongoDB ensure username unicity
Meteor.startup(() => {
+ allowedSortValues.forEach(value => {
+ Lists._collection._ensureIndex(value);
+ });
Users._collection._ensureIndex({ modifiedAt: -1 });
Users._collection._ensureIndex(
{