refactor {{poll-evaluation-chart}} and {{poll-evaluation-participants-table}} interfaces to make them less complex
This commit is contained in:
parent
96ec32aa3e
commit
1df562b352
5 changed files with 21 additions and 37 deletions
|
@ -20,17 +20,11 @@ const addArrays = function() {
|
|||
export default Component.extend({
|
||||
i18n: inject.service(),
|
||||
type: 'bar',
|
||||
data: computed('users.[]', 'dates.[]', 'dates.@each.formatted', 'pollOptions.[]', 'pollOptions.@each.title', 'i18n.locale', function() {
|
||||
let labels;
|
||||
if (this.get('isFindADate')) {
|
||||
labels = this.get('dates').map((date) => {
|
||||
return get(date, 'formatted');
|
||||
data: computed('users.[]', 'options.[]', 'options.@each.formatted', 'options.@each.title', 'i18n.locale', function() {
|
||||
let labels = this.get('options').map((option) => {
|
||||
let formatted = get(option, 'formatted');
|
||||
return isPresent(formatted) ? formatted : get(option, 'title');
|
||||
});
|
||||
} else {
|
||||
labels = this.get('pollOptions').map((pollOption) => {
|
||||
return get(pollOption, 'title');
|
||||
});
|
||||
}
|
||||
|
||||
let datasets = [];
|
||||
const participants = this.get('users.length');
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
{{/if}}
|
||||
<tr>
|
||||
<th> </th>
|
||||
{{#if isFindADate}}
|
||||
{{#each dates as |date|}}
|
||||
{{#each options as |option|}}
|
||||
<th>
|
||||
{{#if isFindADate}}
|
||||
{{#if hasTimes}}
|
||||
{{#if date.hasTime}}
|
||||
{{date.formattedTime}}
|
||||
|
@ -24,15 +24,11 @@
|
|||
{{else}}
|
||||
{{date.formatted}}
|
||||
{{/if}}
|
||||
</th>
|
||||
{{/each}}
|
||||
{{else}}
|
||||
{{#each options as |option|}}
|
||||
<th>
|
||||
{{option.title}}
|
||||
{{/if}}
|
||||
</th>
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
|
|
|
@ -4,9 +4,7 @@
|
|||
<h3>{{t 'poll.evaluation.overview'}}</h3>
|
||||
{{poll-evaluation-chart
|
||||
answerType=model.answerType
|
||||
dates=dates
|
||||
isFindADate=model.isFindADate
|
||||
pollOptions=model.options
|
||||
options=(if model.isFindADate dates model.options)
|
||||
users=model.users
|
||||
}}
|
||||
{{/if}}
|
||||
|
@ -14,10 +12,9 @@
|
|||
<h3>{{t 'poll.evaluation.participantTable'}}</h3>
|
||||
{{poll-evaluation-participants-table
|
||||
dateGroups=dateGroups
|
||||
dates=dates
|
||||
hasTimes=hasTimes
|
||||
isFindADate=model.isFindADate
|
||||
isFreeText=model.isFreeText
|
||||
options=model.options
|
||||
options=(if model.isFindADate dates model.options)
|
||||
sortedUsers=sortedUsers
|
||||
}}
|
||||
|
|
|
@ -11,7 +11,7 @@ moduleForComponent('poll-evaluation-chart', 'Integration | Component | poll eval
|
|||
});
|
||||
|
||||
test('it renders', function(assert) {
|
||||
this.set('dates', [
|
||||
this.set('options', [
|
||||
Ember.Object.create({
|
||||
formatted: 'Thursday, January 1, 2015',
|
||||
title: moment('2015-01-01'),
|
||||
|
@ -70,7 +70,6 @@ test('it renders', function(assert) {
|
|||
]
|
||||
})
|
||||
]);
|
||||
this.set('isFindADate', true);
|
||||
this.render(hbs`{{poll-evaluation-chart dates=dates answerType=answerType isFindADate=isFindADate users=users}}`);
|
||||
this.render(hbs`{{poll-evaluation-chart options=options answerType=answerType users=users}}`);
|
||||
assert.ok(this.$('canvas'), 'it renders a canvas element');
|
||||
});
|
||||
|
|
|
@ -24,7 +24,7 @@ moduleForComponent('poll-evaluation-chart', 'Unit | Component | poll evaluation
|
|||
});
|
||||
|
||||
test('data is a valid ChartJS dataset for FindADate', function(assert) {
|
||||
const dates = [
|
||||
let options = [
|
||||
Ember.Object.create({
|
||||
formatted: 'Thursday, January 1, 2015',
|
||||
title: moment('2015-01-01'),
|
||||
|
@ -48,8 +48,7 @@ test('data is a valid ChartJS dataset for FindADate', function(assert) {
|
|||
];
|
||||
let component = this.subject({
|
||||
answerType: 'YesNoMaybe',
|
||||
dates,
|
||||
isFindADate: true,
|
||||
options,
|
||||
users: [
|
||||
Ember.Object.create({
|
||||
id: 1,
|
||||
|
@ -90,8 +89,8 @@ test('data is a valid ChartJS dataset for FindADate', function(assert) {
|
|||
const data = component.get('data');
|
||||
assert.deepEqual(
|
||||
data.labels,
|
||||
dates.map((date) => {
|
||||
return date.hasTime ? date.title.format('LLLL') : date.title.format(
|
||||
options.map((date) => {
|
||||
return date.get('hasTime') ? date.get('title').format('LLLL') : date.get('title').format(
|
||||
moment.localeData()
|
||||
.longDateFormat('LLLL')
|
||||
.replace(
|
||||
|
@ -140,8 +139,7 @@ test('data is a valid ChartJS dataset for MakeAPoll', function(assert) {
|
|||
];
|
||||
let component = this.subject({
|
||||
answerType: 'YesNoMaybe',
|
||||
pollOptions: options,
|
||||
isFindADate: false,
|
||||
options,
|
||||
users: [
|
||||
Ember.Object.create({
|
||||
id: 1,
|
||||
|
|
Loading…
Reference in a new issue