mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
A card's own description was the only place to put markdown text, so anything
beyond a single block had to be crammed into it. This adds CardTextNotes: a
small collection of named markdown notes per card, modeled on Checklists (a
denormalized boardId, the same publish/allow/deny shape, the same
GHSA-gv8h-5p3p-6hx7 cross-board-move guard).
Each note renders as a tile with its title and a markdown-rendered preview
(the `viewer` template). "Add text note" and a note's "Edit" open a popup
that reuses the description's own `editor`/`viewer` widgets verbatim - no new
markdown editor was written. "Delete" removes the note, scoped to its own
_id.
Wired into the reactive cache (getCardTextNote/getCardTextNotes, matching the
CardComments pattern), the board/linked-card/lazy-window/single-card
publications, and server/permissions/cardTextNotes.js.
tests/cardTextNotes.test.cjs pins: the model's cardId/boardId scoping, the
allow/deny permission shape, the popup's reuse of `editor`/`viewer` (positive:
+editor is used; negative: exactly one `editor` and one `viewer` template is
declared anywhere under client/components/{cards,main} - the whole tree, not
just the new files, so a competing widget cannot be introduced elsewhere
either), and that add/edit/delete are scoped calls rather than broad
selectors.
Thanks to Lapin0t and xet7 !
Closes #595,
114 lines
2.8 KiB
JavaScript
114 lines
2.8 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { Mongo } from 'meteor/mongo';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
const { SimpleSchema } = require('/imports/simpleSchema');
|
|
|
|
const CardTextNotes = new Mongo.Collection('card_text_notes');
|
|
|
|
/**
|
|
* A markdown text note attached to a card (GitHub issue #595): a small,
|
|
* separate, editable block of markdown text a card can carry in addition to
|
|
* its own description, so a card is not limited to a single description
|
|
* field for everything it needs to say. Modeled on Checklists - a per-card
|
|
* collection of small named sub-documents - rather than on Attachments,
|
|
* because a text note is edited in place, not uploaded/downloaded.
|
|
*/
|
|
CardTextNotes.attachSchema(
|
|
new SimpleSchema({
|
|
boardId: {
|
|
/**
|
|
* the board ID, denormalized from the card so the board publication
|
|
* can publish text notes with a single reactive cursor filtered by
|
|
* boardId, the same pattern used by Checklists/CardComments/Attachments.
|
|
*/
|
|
type: String,
|
|
},
|
|
cardId: {
|
|
/**
|
|
* the ID of the card the text note is on
|
|
*/
|
|
type: String,
|
|
},
|
|
title: {
|
|
/**
|
|
* the title of the text note
|
|
*/
|
|
type: String,
|
|
defaultValue: '',
|
|
},
|
|
text: {
|
|
/**
|
|
* the markdown text of the note
|
|
*/
|
|
type: String,
|
|
optional: true,
|
|
defaultValue: '',
|
|
},
|
|
createdAt: {
|
|
/**
|
|
* creation date of the text note
|
|
*/
|
|
type: Date,
|
|
// eslint-disable-next-line consistent-return
|
|
autoValue() {
|
|
if (this.isInsert) {
|
|
return new Date();
|
|
} else if (this.isUpsert) {
|
|
return { $setOnInsert: new Date() };
|
|
} else {
|
|
this.unset();
|
|
}
|
|
},
|
|
},
|
|
modifiedAt: {
|
|
type: Date,
|
|
// eslint-disable-next-line consistent-return
|
|
autoValue() {
|
|
if (this.isInsert || this.isUpsert || this.isUpdate) {
|
|
return new Date();
|
|
} else {
|
|
this.unset();
|
|
}
|
|
},
|
|
},
|
|
userId: {
|
|
/**
|
|
* the ID of the user who created the text note
|
|
*/
|
|
type: String,
|
|
// eslint-disable-next-line consistent-return
|
|
autoValue() {
|
|
if (this.isInsert && !this.isSet) {
|
|
return this.userId;
|
|
}
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
|
|
CardTextNotes.helpers({
|
|
card() {
|
|
return ReactiveCache.getCard(this.cardId);
|
|
},
|
|
user() {
|
|
return ReactiveCache.getUser(this.userId);
|
|
},
|
|
});
|
|
|
|
CardTextNotes.before.insert((userId, doc) => {
|
|
doc.createdAt = new Date();
|
|
if (!doc.userId) {
|
|
doc.userId = userId;
|
|
}
|
|
});
|
|
|
|
if (Meteor.isServer) {
|
|
const { ensureIndex } = require('/server/lib/mongoStartup');
|
|
Meteor.startup(async () => {
|
|
await ensureIndex(CardTextNotes, { cardId: 1, createdAt: 1 });
|
|
await ensureIndex(CardTextNotes, { boardId: 1 });
|
|
});
|
|
}
|
|
|
|
export default CardTextNotes;
|