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,
78 lines
2.5 KiB
JavaScript
78 lines
2.5 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import CardTextNotes from '/models/cardTextNotes';
|
|
|
|
// GitHub issue #595: "Markdown textfile attachment" - an attachable text
|
|
// NOTE (separate from the card's own description) with markdown support,
|
|
// editable in a popup, so a card can carry several distinct text blocks
|
|
// instead of cramming everything into one description field.
|
|
//
|
|
// The edit popup reuses the exact same `editor`/`viewer` templates the card
|
|
// description already uses (client/components/main/editor.jade) - no new
|
|
// markdown editing widget is written here.
|
|
|
|
Template.cardTextNotes.helpers({
|
|
textNotes() {
|
|
return ReactiveCache.getCardTextNotes(
|
|
{ cardId: this._id },
|
|
{ sort: { createdAt: 1 } },
|
|
);
|
|
},
|
|
});
|
|
|
|
Template.cardTextNotes.events({
|
|
// "Add text note" is clicked with the CARD as data context (cardTextNotes'
|
|
// own context), so the popup receives {_id: <cardId>} and no cardId/text of
|
|
// its own - it is an editor with nothing pre-filled yet.
|
|
'click .js-add-text-note': Popup.open('cardTextNoteEdit'),
|
|
// "Edit"/"Delete" are clicked inside `each textNotes`, so the popup instead
|
|
// receives the note itself (which has its own cardId).
|
|
'click .js-edit-text-note': Popup.open('cardTextNoteEdit'),
|
|
'click .js-delete-text-note': Popup.open('cardTextNoteDelete'),
|
|
});
|
|
|
|
Template.cardTextNoteEditPopup.events({
|
|
'submit .js-card-text-note-edit-form'(event, tpl) {
|
|
event.preventDefault();
|
|
const title = tpl.$('.js-card-text-note-title-input').val().trim();
|
|
const text = tpl.currentComponent
|
|
? tpl.currentComponent().getValue()
|
|
: tpl.$('.js-card-text-note-text-input').val();
|
|
|
|
// A note being edited carries its own cardId; the "add" popup's context
|
|
// is the card itself, so cardId is absent and _id is the CARD's id.
|
|
const isExistingNote = !!this.cardId;
|
|
if (isExistingNote) {
|
|
CardTextNotes.update(this._id, {
|
|
$set: { title, text },
|
|
});
|
|
} else {
|
|
const cardId = this._id;
|
|
const card = ReactiveCache.getCard(cardId);
|
|
CardTextNotes.insert({
|
|
cardId,
|
|
boardId: card && card.boardId,
|
|
title,
|
|
text,
|
|
});
|
|
}
|
|
Popup.back();
|
|
},
|
|
'click .js-delete-text-note-from-popup'(event) {
|
|
event.preventDefault();
|
|
if (this.cardId) {
|
|
CardTextNotes.remove(this._id);
|
|
}
|
|
Popup.back();
|
|
},
|
|
});
|
|
|
|
Template.cardTextNoteDeletePopup.events({
|
|
'submit'(event) {
|
|
event.preventDefault();
|
|
if (this.cardId) {
|
|
CardTextNotes.remove(this._id);
|
|
}
|
|
Popup.back();
|
|
},
|
|
});
|