2023-10-15 20:37:03 +02:00
|
|
|
import Component from '@glimmer/component';
|
2023-10-29 19:16:33 +01:00
|
|
|
import type Poll from 'croodle/models/poll';
|
2023-10-15 20:37:03 +02:00
|
|
|
import { DateTime } from 'luxon';
|
2015-11-12 15:52:14 +01:00
|
|
|
|
2023-10-29 19:16:33 +01:00
|
|
|
export interface PollEvaluationParticipantsTableSignature {
|
|
|
|
Args: {
|
|
|
|
poll: Poll;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class PollEvaluationParticipantsTable extends Component<PollEvaluationParticipantsTableSignature> {
|
2023-10-15 17:32:11 +02:00
|
|
|
get optionsPerDay() {
|
|
|
|
const { poll } = this.args;
|
2020-01-18 10:13:50 +01:00
|
|
|
|
2023-10-15 17:32:11 +02:00
|
|
|
const optionsPerDay = new Map();
|
2023-10-28 19:15:06 +02:00
|
|
|
for (const option of poll.options) {
|
2023-10-15 17:32:11 +02:00
|
|
|
optionsPerDay.set(
|
|
|
|
option.day,
|
2023-10-17 10:44:45 +02:00
|
|
|
optionsPerDay.has(option.day) ? optionsPerDay.get(option.day) + 1 : 0,
|
2023-10-15 17:32:11 +02:00
|
|
|
);
|
|
|
|
}
|
2020-01-18 10:13:50 +01:00
|
|
|
|
2023-10-15 17:32:11 +02:00
|
|
|
return new Map(
|
|
|
|
Array.from(optionsPerDay.entries()).map(([dayString, count]) => [
|
|
|
|
DateTime.fromISO(dayString).toJSDate(),
|
|
|
|
count,
|
2023-10-17 10:44:45 +02:00
|
|
|
]),
|
2023-10-15 17:32:11 +02:00
|
|
|
);
|
|
|
|
}
|
2020-01-18 10:13:50 +01:00
|
|
|
|
2023-10-15 17:32:11 +02:00
|
|
|
get usersSorted() {
|
|
|
|
const { poll } = this.args;
|
2023-10-28 19:15:06 +02:00
|
|
|
return Array.from(poll.users).sort((a, b) =>
|
|
|
|
a.creationDate > b.creationDate ? 1 : -1,
|
|
|
|
);
|
2023-10-15 17:32:11 +02:00
|
|
|
}
|
2020-01-18 10:13:50 +01:00
|
|
|
}
|