Skip to content

Commit

Permalink
Changed manage time to first be a user selection. This helps improve …
Browse files Browse the repository at this point in the history
…on the issue Trello is having where it doesnt always allow for scrolling to take place when it overflows
  • Loading branch information
danniehansen committed Oct 28, 2024
1 parent 98c4cca commit d46ba93
Showing 1 changed file with 81 additions and 59 deletions.
140 changes: 81 additions & 59 deletions src/capabilities/card-buttons/callbacks/ManageTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,83 @@ function openManuallyAdd(
});
}

async function manageTimeForMember(t: Trello.PowerUp.IFrame, memberId: string) {
const board = await t.board('members');
const member = board.members.find((member) => member.id === memberId);

return t.popup({
title: `Manage time: ${member?.fullName ?? 'N/A'}`,
items: async function (t) {
const card = await Card.getFromContext(t);
const timers = await card.getTimers();
const ranges = await card.getRanges();

const items: Trello.PowerUp.PopupOptionsItem[] = [];

const memberRanges = ranges.items.filter((range) => {
return range.memberId === memberId;
});

const timer = timers.getByMemberId(memberId);

if (memberRanges.length > 0 || timer) {
memberRanges.forEach((range) => {
items.push(getManageRow(card, ranges, range));
});

if (timer) {
items.push({
text: `Running: ${formatDate(
new Date(timer.start * 1000)
)} (${formatTime(timer.timeInSecond, true)})`,
callback: function (t) {
return t.popup({
title: 'Active timer',
items: async function () {
return [
{
text: 'Stop time tracking',
callback: async (t) => {
return t.popup({
type: 'confirm',
title: 'Stop time tracking',
message:
"You're about to stop a time tracking. Are you sure?",
confirmText: 'Yes, stop timer',
onConfirm: async (t) => {
await card.stopTrackingByMemberId(memberId, t);
return t.closePopup();
},
confirmStyle: 'danger',
cancelText: 'No, cancel'
});
}
}
];
}
});
}
});
}

const timeSpent =
memberRanges.reduce((a, b) => a + b.diff, 0) +
(timer ? timer.timeInSecond : 0);

items.push({
text: '--------'
});

items.push({
text: `Time spent: ${formatTime(timeSpent)}`
});
}

return items;
}
});
}

export async function manageTimeCallback(t: Trello.PowerUp.IFrame) {
return t.popup({
title: 'Manage time',
Expand Down Expand Up @@ -231,59 +308,13 @@ export async function manageTimeCallback(t: Trello.PowerUp.IFrame) {
const timer = timers.getByMemberId(member.id);

if (memberRanges.length > 0 || timer) {
items.push({
text: formatMemberName(member) + ':'
});

memberRanges.forEach((range) => {
items.push(getManageRow(card, ranges, range));
});

if (timer) {
items.push({
text: `Running: ${formatDate(
new Date(timer.start * 1000)
)} (${formatTime(timer.timeInSecond, true)})`,
callback: function (t) {
return t.popup({
title: 'Active timer',
items: async function () {
return [
{
text: 'Stop time tracking',
callback: async (t) => {
return t.popup({
type: 'confirm',
title: 'Stop time tracking',
message:
"You're about to stop a time tracking. Are you sure?",
confirmText: 'Yes, stop timer',
onConfirm: async (t) => {
await card.stopTrackingByMemberId(member.id, t);
return t.closePopup();
},
confirmStyle: 'danger',
cancelText: 'No, cancel'
});
}
}
];
}
});
}
});
}

const timeSpent =
memberRanges.reduce((a, b) => a + b.diff, 0) +
(timer ? timer.timeInSecond : 0);

items.push({
text: `Time spent: ${formatTime(timeSpent)}`
});

items.push({
text: '--------'
text: `${formatMemberName(member)}: ${formatTime(timeSpent)}`,
callback: (t) => manageTimeForMember(t, member.id)
});
}
});
Expand All @@ -292,20 +323,11 @@ export async function manageTimeCallback(t: Trello.PowerUp.IFrame) {
.filter((range) => memberIds.indexOf(range.memberId) === -1)
.forEach((range) => {
items.push({
text: 'N/A:'
});

items.push(getManageRow(card, ranges, range));

items.push({
text: '--------'
text: 'N/A:',
callback: (t) => manageTimeForMember(t, range.memberId)
});
});

if (items.length > 0) {
items.splice(items.length - 1, 1);
}

if (items.length > 0) {
items.push({
text: '--------'
Expand Down

0 comments on commit d46ba93

Please sign in to comment.