Trello custom field import basically working

This commit is contained in:
John R. Supplee 2021-01-18 23:56:08 +02:00
parent c89a0eb694
commit b793716e85
5 changed files with 59 additions and 23 deletions

View file

@ -55,13 +55,21 @@ template(name="cardCustomField-number")
template(name="cardCustomField-checkbox") template(name="cardCustomField-checkbox")
if canModifyCard if canModifyCard
+inlinedForm(classNames="js-card-customfield-checkbox") +inlinedForm(classNames="js-card-customfield-checkbox")
input(type="checkbox" value=data.value) input.materialCheckBox(type="checkbox" checked=data.value)
.edit-controls.clearfix .edit-controls.clearfix
button.primary(type="submit") {{_ 'save'}} button.primary(type="submit") {{_ 'save'}}
a.fa.fa-times-thin.js-close-inlined-form a.fa.fa-times-thin.js-close-inlined-form
else
a.js-open-inlined-form.checkbox-display
if value
i.fa.fa-check-square
else
i.fa.fa-square
else else
if value if value
= value i.fa.fa-check-square
else
i.fa.fa-square
template(name="cardCustomField-currency") template(name="cardCustomField-currency")
if canModifyCard if canModifyCard

View file

@ -78,7 +78,7 @@ CardCustomField.register('cardCustomField');
}, },
]; ];
} }
}.register('cardCustomField-checkbox')); }.register('cardCustomField-number'));
// cardCustomField-checkbox // cardCustomField-checkbox
(class extends CardCustomField { (class extends CardCustomField {
@ -86,12 +86,16 @@ CardCustomField.register('cardCustomField');
super.onCreated(); super.onCreated();
} }
isNull() {
return !this.data().value;
}
events() { events() {
return [ return [
{ {
'submit .js-card-customfield-checkbox'(event) { 'submit .js-card-customfield-checkbox'(event) {
event.preventDefault(); event.preventDefault();
const value = this.find('input').value !== ''; const value = this.find('input').checked;
this.card.setCustomField(this.customFieldId, value); this.card.setCustomField(this.customFieldId, value);
}, },
}, },

View file

@ -77,6 +77,8 @@ template(name="minicard")
if $eq definition.type "currency" if $eq definition.type "currency"
+viewer +viewer
= formattedCurrencyCustomFieldValue(definition) = formattedCurrencyCustomFieldValue(definition)
else if $eq definition.type "checkbox"
i.fa.fa-check-square
else else
+viewer +viewer
= trueValue = trueValue

View file

@ -242,11 +242,11 @@ textarea
margin: 3px 4px margin: 3px 4px
// Material Design checkboxes // Material Design checkboxes
[type="checkbox"]:not(:checked), //[type="checkbox"]:not(:checked),
[type="checkbox"]:checked //[type="checkbox"]:checked
position: absolute // position: absolute
left: -9999px // left: -9999px
visibility: hidden // visibility: hidden
.materialCheckBox .materialCheckBox
position: relative position: relative

View file

@ -219,19 +219,6 @@ export class TrelloCreator {
this.labels[label.id] = labelToCreate._id; this.labels[label.id] = labelToCreate._id;
boardToCreate.labels.push(labelToCreate); boardToCreate.labels.push(labelToCreate);
}); });
trelloBoard.customFields.forEach(field => {
const fieldToCreate = {
_id: Random.id(6),
trelloId: field.id,
name: field.name,
showOnCard: field.display.cardFront,
type: field.type,
};
// We need to remember them by Trello ID, as this is the only ref we have
// when importing cards.
this.customFields[field.id] = fieldToCreate._id;
boardToCreate.customFields.push(fieldToCreate);
});
const boardId = Boards.direct.insert(boardToCreate); const boardId = Boards.direct.insert(boardToCreate);
Boards.direct.update(boardId, { $set: { modifiedAt: this._now() } }); Boards.direct.update(boardId, { $set: { modifiedAt: this._now() } });
// log activity // log activity
@ -248,6 +235,24 @@ export class TrelloCreator {
// not the author from the original object. // not the author from the original object.
userId: this._user(), userId: this._user(),
}); });
if (trelloBoard.customFields) {
trelloBoard.customFields.forEach(field => {
const fieldToCreate = {
// trelloId: field.id,
name: field.name,
showOnCard: field.display.cardFront,
showLabelOnMiniCard: field.display.cardFront,
automaticallyOnCard: true,
type: field.type,
boardIds: [boardId],
settings: {},
};
// We need to remember them by Trello ID, as this is the only ref we have
// when importing cards.
this.customFields[field.id] = CustomFields.direct.insert(fieldToCreate);
});
}
return boardId; return boardId;
} }
@ -326,7 +331,24 @@ export class TrelloCreator {
} }
if (card.customFieldItems) { if (card.customFieldItems) {
card.customFieldItems.forEach(item => {}); cardToCreate.customFields = [];
card.customFieldItems.forEach(item => {
const custom = {
_id: this.customFields[item.idCustomField],
};
if (item.value.hasOwnProperty('checked')) {
custom.value = item.value.checked === 'true';
} else if (item.value.hasOwnProperty('text')) {
custom.value = item.value.text;
} else if (item.value.hasOwnProperty('date')) {
custom.value = item.value.date;
} else if (item.value.hasOwnProperty('number')) {
custom.value = item.value.number;
} else if (item.value.hasOwnProperty('dropdown')) {
custom.value = item.value.dropdown;
}
cardToCreate.customFields.push(custom);
});
} }
// insert card // insert card