card.js, clean up redudant code

This commit is contained in:
Martin Filser 2022-12-09 11:55:39 +01:00
parent 43d11af631
commit 384d80a647
2 changed files with 38 additions and 52 deletions

View file

@ -95,7 +95,7 @@ template(name="linkCardPopup")
label {{_ 'cards'}}: label {{_ 'cards'}}:
select.js-select-cards select.js-select-cards
each cards each cards
option(value="{{getId}}") {{getTitle}} option(value="{{getRealId}}") {{getTitle}}
.edit-controls.clearfix .edit-controls.clearfix
input.primary.confirm.js-done(type="button" value="{{_ 'link'}}") input.primary.confirm.js-done(type="button" value="{{_ 'link'}}")

View file

@ -642,6 +642,17 @@ Cards.helpers({
return Boards.findOne(this.boardId); return Boards.findOne(this.boardId);
}, },
getRealId() {
if (!this.__id) {
if (this.isLinkedCard()) {
this.__id = this.linkedId;
} else {
this.__id = this._id;
}
}
return this.__id;
},
getList() { getList() {
const list = this.list(); const list = this.list();
if (!list) { if (!list) {
@ -753,47 +764,37 @@ Cards.helpers({
}, },
activities() { activities() {
if (this.isLinkedCard()) { let ret;
return Activities.find( if (this.isLinkedBoard()) {
{ cardId: this.linkedId }, ret = Activities.find(
{ sort: { createdAt: -1 } },
);
} else if (this.isLinkedBoard()) {
return Activities.find(
{ boardId: this.linkedId }, { boardId: this.linkedId },
{ sort: { createdAt: -1 } }, { sort: { createdAt: -1 } },
); );
} else { } else {
return Activities.find({ cardId: this._id }, { sort: { createdAt: -1 } }); ret = Activities.find({ cardId: this.getRealId() }, { sort: { createdAt: -1 } });
} }
return ret;
}, },
comments() { comments() {
if (this.isLinkedCard()) { let ret
return CardComments.find( if (this.isLinkedBoard()) {
{ cardId: this.linkedId }, ret = CardComments.find(
{ sort: { createdAt: -1 } },
);
} else if (this.isLinkedBoard()) {
return CardComments.find(
{ boardId: this.linkedId }, { boardId: this.linkedId },
{ sort: { createdAt: -1 } }, { sort: { createdAt: -1 } },
); );
} else { } else {
return CardComments.find( ret = CardComments.find(
{ cardId: this._id }, { cardId: this.getRealId() },
{ sort: { createdAt: -1 } }, { sort: { createdAt: -1 } },
); );
} }
return ret;
}, },
attachments() { attachments() {
let id = this._id; const ret = Attachments.find(
if (this.isLinkedCard()) { { 'meta.cardId': this.getRealId() },
id = this.linkedId;
}
let ret = Attachments.find(
{ 'meta.cardId': id },
{ sort: { uploadedAt: -1 } }, { sort: { uploadedAt: -1 } },
).each(); ).each();
return ret; return ret;
@ -809,11 +810,7 @@ Cards.helpers({
checklists() { checklists() {
if (!this._checklists) { if (!this._checklists) {
let id = this._id; this._checklists = new DataCache(() => Checklists.find({ cardId: this.getRealId() }, { sort: { sort: 1 } }).fetch(), 1000);
if (this.isLinkedCard()) {
id = this.linkedId;
}
this._checklists = new DataCache(() => Checklists.find({ cardId: id }, { sort: { sort: 1 } }).fetch(), 1000);
} }
return this._checklists.get(); return this._checklists.get();
}, },
@ -832,24 +829,26 @@ Cards.helpers({
checklistItemCount() { checklistItemCount() {
const checklists = this.checklists(); const checklists = this.checklists();
return checklists const ret = checklists
.map(checklist => { .map(checklist => {
return checklist.itemCount(); return checklist.itemCount();
}) })
.reduce((prev, next) => { .reduce((prev, next) => {
return prev + next; return prev + next;
}, 0); }, 0);
return ret;
}, },
checklistFinishedCount() { checklistFinishedCount() {
const checklists = this.checklists(); const checklists = this.checklists();
return checklists const ret = checklists
.map(checklist => { .map(checklist => {
return checklist.finishedCount(); return checklist.finishedCount();
}) })
.reduce((prev, next) => { .reduce((prev, next) => {
return prev + next; return prev + next;
}, 0); }, 0);
return ret;
}, },
checklistFinished() { checklistFinished() {
@ -1081,12 +1080,10 @@ Cards.helpers({
}, },
setDescription(description) { setDescription(description) {
if (this.isLinkedCard()) { if (this.isLinkedBoard()) {
return Cards.update({ _id: this.linkedId }, { $set: { description } });
} else if (this.isLinkedBoard()) {
return Boards.update({ _id: this.linkedId }, { $set: { description } }); return Boards.update({ _id: this.linkedId }, { $set: { description } });
} else { } else {
return Cards.update({ _id: this._id }, { $set: { description } }); return Cards.update({ _id: this.getRealId() }, { $set: { description } });
} }
}, },
@ -1151,20 +1148,17 @@ Cards.helpers({
}, },
assignMember(memberId) { assignMember(memberId) {
if (this.isLinkedCard()) { let ret;
return Cards.update( if (this.isLinkedBoard()) {
{ _id: this.linkedId },
{ $addToSet: { members: memberId } },
);
} else if (this.isLinkedBoard()) {
const board = Boards.findOne({ _id: this.linkedId }); const board = Boards.findOne({ _id: this.linkedId });
return board.addMember(memberId); ret = board.addMember(memberId);
} else { } else {
return Cards.update( ret = Cards.update(
{ _id: this._id }, { _id: this.getRealId() },
{ $addToSet: { members: memberId } }, { $addToSet: { members: memberId } },
); );
} }
return ret;
}, },
assignAssignee(assigneeId) { assignAssignee(assigneeId) {
@ -1708,14 +1702,6 @@ Cards.helpers({
return null; return null;
}, },
getId() {
if (this.isLinked()) {
return this.linkedId;
} else {
return this._id;
}
},
getTitle() { getTitle() {
if (this.isLinkedCard()) { if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId }); const card = Cards.findOne({ _id: this.linkedId });