mirror of
https://github.com/wekan/wekan.git
synced 2025-12-17 16:00:13 +01:00
adding ReactiveCache to other source code
This commit is contained in:
parent
30d154724a
commit
3f3b4746a9
4 changed files with 184 additions and 17 deletions
|
|
@ -43,12 +43,12 @@ Utils = {
|
||||||
},
|
},
|
||||||
getCurrentCard(ignorePopupCard) {
|
getCurrentCard(ignorePopupCard) {
|
||||||
const cardId = Utils.getCurrentCardId(ignorePopupCard);
|
const cardId = Utils.getCurrentCardId(ignorePopupCard);
|
||||||
const ret = Cards.findOne(cardId);
|
const ret = ReactiveCache.getCard(cardId);
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
getPopupCard() {
|
getPopupCard() {
|
||||||
const cardId = Utils.getPopupCardId();
|
const cardId = Utils.getPopupCardId();
|
||||||
const ret = Cards.findOne(cardId);
|
const ret = ReactiveCache.getCard(cardId);
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
canModifyCard() {
|
canModifyCard() {
|
||||||
|
|
|
||||||
30
imports/jsons.js
Normal file
30
imports/jsons.js
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
Jsons = {
|
||||||
|
stringify(value) {
|
||||||
|
const ret = JSON.stringify(value, this.replacer, 2);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
|
||||||
|
parse(value) {
|
||||||
|
const ret = JSON.parse(value, this.reviver);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/12075927/serialization-of-regexp/33416684#33416684
|
||||||
|
replacer(key, value) {
|
||||||
|
if (value instanceof RegExp)
|
||||||
|
return ("___REGEXP___ " + value.toString());
|
||||||
|
else
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/12075927/serialization-of-regexp/33416684#33416684
|
||||||
|
reviver(key, value) {
|
||||||
|
if (value?.toString()?.indexOf("___REGEXP___ ") == 0) {
|
||||||
|
const m = value.split("___REGEXP___ ")[1].match(/\/(.*)\/(.*)?/);
|
||||||
|
return new RegExp(m[1], m[2] || "");
|
||||||
|
} else
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Jsons }
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { DataCache } from 'meteor-reactive-cache';
|
import { DataCache } from 'meteor-reactive-cache';
|
||||||
|
import { Jsons } from './jsons';
|
||||||
|
|
||||||
// Server isn't reactive, so search for the data always.
|
// Server isn't reactive, so search for the data always.
|
||||||
ReactiveCacheServer = {
|
ReactiveCacheServer = {
|
||||||
|
|
@ -6,6 +7,30 @@ ReactiveCacheServer = {
|
||||||
const ret = Boards.findOne(id);
|
const ret = Boards.findOne(id);
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
|
getList(id) {
|
||||||
|
const ret = Lists.findOne(id);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getSwimlane(id) {
|
||||||
|
const ret = Swimlanes.findOne(id);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getChecklist(id) {
|
||||||
|
const ret = Checklists.findOne(id);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getCard(id) {
|
||||||
|
const ret = Cards.findOne(id);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getCustomField(id) {
|
||||||
|
const ret = CustomFields.findOne(id);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getCustomFields(selector) {
|
||||||
|
const ret = CustomFields.find(selector).fetch();
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// only the Client is reactive
|
// only the Client is reactive
|
||||||
|
|
@ -21,6 +46,66 @@ ReactiveCacheClient = {
|
||||||
}
|
}
|
||||||
const ret = this.__board.get(id);
|
const ret = this.__board.get(id);
|
||||||
return ret;
|
return ret;
|
||||||
|
},
|
||||||
|
getList(id) {
|
||||||
|
if (!this.__list) {
|
||||||
|
this.__list = new DataCache(listId => {
|
||||||
|
const _ret = Lists.findOne(listId);
|
||||||
|
return _ret;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const ret = this.__list.get(id);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getSwimlane(id) {
|
||||||
|
if (!this.__swimlane) {
|
||||||
|
this.__swimlane = new DataCache(swimlaneId => {
|
||||||
|
const _ret = Swimlanes.findOne(swimlaneId);
|
||||||
|
return _ret;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const ret = this.__swimlane.get(id);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getChecklist(id) {
|
||||||
|
if (!this.__checklist) {
|
||||||
|
this.__checklist = new DataCache(checklistId => {
|
||||||
|
const _ret = Checklists.findOne(checklistId);
|
||||||
|
return _ret;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const ret = this.__checklist.get(id);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getCard(id) {
|
||||||
|
if (!this.__card) {
|
||||||
|
this.__card = new DataCache(cardId => {
|
||||||
|
const _ret = Cards.findOne(cardId);
|
||||||
|
return _ret;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const ret = this.__card.get(id);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getCustomField(id) {
|
||||||
|
if (!this.__customField) {
|
||||||
|
this.__customField = new DataCache(customFieldId => {
|
||||||
|
const _ret = CustomFields.findOne(customFieldId);
|
||||||
|
return _ret;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const ret = this.__customField.get(id);
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getCustomFields(selector) {
|
||||||
|
if (!this.__customFields) {
|
||||||
|
this.__customFields = new DataCache(sel => {
|
||||||
|
const _ret = CustomFields.find(Jsons.parse(sel)).fetch();
|
||||||
|
return _ret;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const ret = this.__customFields.get(Jsons.stringify(selector));
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,6 +125,60 @@ ReactiveCache = {
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
|
getList(id) {
|
||||||
|
let ret;
|
||||||
|
if (Meteor.isServer) {
|
||||||
|
ret = ReactiveCacheServer.getList(id);
|
||||||
|
} else {
|
||||||
|
ret = ReactiveCacheClient.getList(id);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getSwimlane(id) {
|
||||||
|
let ret;
|
||||||
|
if (Meteor.isServer) {
|
||||||
|
ret = ReactiveCacheServer.getSwimlane(id);
|
||||||
|
} else {
|
||||||
|
ret = ReactiveCacheClient.getSwimlane(id);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getChecklist(id) {
|
||||||
|
let ret;
|
||||||
|
if (Meteor.isServer) {
|
||||||
|
ret = ReactiveCacheServer.getChecklist(id);
|
||||||
|
} else {
|
||||||
|
ret = ReactiveCacheClient.getChecklist(id);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getCard(id) {
|
||||||
|
let ret;
|
||||||
|
if (Meteor.isServer) {
|
||||||
|
ret = ReactiveCacheServer.getCard(id);
|
||||||
|
} else {
|
||||||
|
ret = ReactiveCacheClient.getCard(id);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getCustomField(id) {
|
||||||
|
let ret;
|
||||||
|
if (Meteor.isServer) {
|
||||||
|
ret = ReactiveCacheServer.getCustomField(id);
|
||||||
|
} else {
|
||||||
|
ret = ReactiveCacheClient.getCustomField(id);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
getCustomFields(selector) {
|
||||||
|
let ret;
|
||||||
|
if (Meteor.isServer) {
|
||||||
|
ret = ReactiveCacheServer.getCustomFields(selector);
|
||||||
|
} else {
|
||||||
|
ret = ReactiveCacheClient.getCustomFields(selector);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export { ReactiveCache };
|
export { ReactiveCache };
|
||||||
|
|
|
||||||
|
|
@ -554,7 +554,7 @@ Cards.helpers({
|
||||||
// we must only copy the labels and custom fields if the target board
|
// we must only copy the labels and custom fields if the target board
|
||||||
// differs from the source board
|
// differs from the source board
|
||||||
if (this.boardId !== boardId) {
|
if (this.boardId !== boardId) {
|
||||||
const oldBoard = Boards.findOne(this.boardId);
|
const oldBoard = ReactiveCache.getBoard(this.boardId);
|
||||||
const oldBoardLabels = oldBoard.labels;
|
const oldBoardLabels = oldBoard.labels;
|
||||||
|
|
||||||
// Get old label names
|
// Get old label names
|
||||||
|
|
@ -565,7 +565,7 @@ Cards.helpers({
|
||||||
'name',
|
'name',
|
||||||
);
|
);
|
||||||
|
|
||||||
const newBoard = Boards.findOne(boardId);
|
const newBoard = ReactiveCache.getBoard(boardId);
|
||||||
const newBoardLabels = newBoard.labels;
|
const newBoardLabels = newBoard.labels;
|
||||||
const newCardLabels = _.pluck(
|
const newCardLabels = _.pluck(
|
||||||
_.filter(newBoardLabels, label => {
|
_.filter(newBoardLabels, label => {
|
||||||
|
|
@ -582,7 +582,7 @@ Cards.helpers({
|
||||||
|
|
||||||
delete this._id;
|
delete this._id;
|
||||||
this.boardId = boardId;
|
this.boardId = boardId;
|
||||||
this.cardNumber = Boards.findOne(boardId).getNextCardNumber();
|
this.cardNumber = ReactiveCache.getBoard(boardId).getNextCardNumber();
|
||||||
this.swimlaneId = swimlaneId;
|
this.swimlaneId = swimlaneId;
|
||||||
this.listId = listId;
|
this.listId = listId;
|
||||||
const _id = Cards.insert(this);
|
const _id = Cards.insert(this);
|
||||||
|
|
@ -632,11 +632,11 @@ Cards.helpers({
|
||||||
},
|
},
|
||||||
|
|
||||||
list() {
|
list() {
|
||||||
return Lists.findOne(this.listId);
|
return ReactiveCache.getList(this.listId);
|
||||||
},
|
},
|
||||||
|
|
||||||
swimlane() {
|
swimlane() {
|
||||||
return Swimlanes.findOne(this.swimlaneId);
|
return ReactiveCache.getSwimlane(this.swimlaneId);
|
||||||
},
|
},
|
||||||
|
|
||||||
board() {
|
board() {
|
||||||
|
|
@ -917,9 +917,9 @@ Cards.helpers({
|
||||||
// customFields with definitions
|
// customFields with definitions
|
||||||
customFieldsWD() {
|
customFieldsWD() {
|
||||||
// get all definitions
|
// get all definitions
|
||||||
const definitions = CustomFields.find({
|
const definitions = ReactiveCache.getCustomFields({
|
||||||
boardIds: { $in: [this.boardId] },
|
boardIds: { $in: [this.boardId] },
|
||||||
}).fetch();
|
});
|
||||||
if (!definitions) {
|
if (!definitions) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
@ -986,9 +986,7 @@ Cards.helpers({
|
||||||
},
|
},
|
||||||
|
|
||||||
canBeRestored() {
|
canBeRestored() {
|
||||||
const list = Lists.findOne({
|
const list = ReactiveCache.getList(this.listId);
|
||||||
_id: this.listId,
|
|
||||||
});
|
|
||||||
if (
|
if (
|
||||||
!list.getWipLimit('soft') &&
|
!list.getWipLimit('soft') &&
|
||||||
list.getWipLimit('enabled') &&
|
list.getWipLimit('enabled') &&
|
||||||
|
|
@ -1009,7 +1007,7 @@ Cards.helpers({
|
||||||
parentCardName() {
|
parentCardName() {
|
||||||
let result = '';
|
let result = '';
|
||||||
if (this.parentId !== '') {
|
if (this.parentId !== '') {
|
||||||
const card = Cards.findOne(this.parentId);
|
const card = ReactiveCache.getCard(this.parentId);
|
||||||
if (card) {
|
if (card) {
|
||||||
result = card.title;
|
result = card.title;
|
||||||
}
|
}
|
||||||
|
|
@ -2724,7 +2722,7 @@ function cardMove(
|
||||||
userId,
|
userId,
|
||||||
oldListId,
|
oldListId,
|
||||||
activityType: 'moveCard',
|
activityType: 'moveCard',
|
||||||
listName: Lists.findOne(doc.listId).title,
|
listName: ReactiveCache.getList(doc.listId).title,
|
||||||
listId: doc.listId,
|
listId: doc.listId,
|
||||||
boardId: doc.boardId,
|
boardId: doc.boardId,
|
||||||
cardId: doc._id,
|
cardId: doc._id,
|
||||||
|
|
@ -2742,7 +2740,7 @@ function cardState(userId, doc, fieldNames) {
|
||||||
Activities.insert({
|
Activities.insert({
|
||||||
userId,
|
userId,
|
||||||
activityType: 'archivedCard',
|
activityType: 'archivedCard',
|
||||||
listName: Lists.findOne(doc.listId).title,
|
listName: ReactiveCache.getList(doc.listId).title,
|
||||||
boardId: doc.boardId,
|
boardId: doc.boardId,
|
||||||
listId: doc.listId,
|
listId: doc.listId,
|
||||||
cardId: doc._id,
|
cardId: doc._id,
|
||||||
|
|
@ -2753,7 +2751,7 @@ function cardState(userId, doc, fieldNames) {
|
||||||
userId,
|
userId,
|
||||||
activityType: 'restoredCard',
|
activityType: 'restoredCard',
|
||||||
boardId: doc.boardId,
|
boardId: doc.boardId,
|
||||||
listName: Lists.findOne(doc.listId).title,
|
listName: ReactiveCache.getList(doc.listId).title,
|
||||||
listId: doc.listId,
|
listId: doc.listId,
|
||||||
cardId: doc._id,
|
cardId: doc._id,
|
||||||
swimlaneId: doc.swimlaneId,
|
swimlaneId: doc.swimlaneId,
|
||||||
|
|
@ -2937,7 +2935,7 @@ function cardCreation(userId, doc) {
|
||||||
userId,
|
userId,
|
||||||
activityType: 'createCard',
|
activityType: 'createCard',
|
||||||
boardId: doc.boardId,
|
boardId: doc.boardId,
|
||||||
listName: Lists.findOne(doc.listId).title,
|
listName: ReactiveCache.getList(doc.listId).title,
|
||||||
listId: doc.listId,
|
listId: doc.listId,
|
||||||
cardId: doc._id,
|
cardId: doc._id,
|
||||||
cardTitle: doc.title,
|
cardTitle: doc.title,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue