Skip to content

Commit 14b1158

Browse files
authored
feat: optimize code for manage events table (#3304)
1 parent 7c2231c commit 14b1158

File tree

5 files changed

+25
-49
lines changed

5 files changed

+25
-49
lines changed

app/controllers/events/list.js

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
99
return [
1010
{
1111
name : 'Name',
12-
valuePath : 'name',
12+
valuePath : 'identifier',
1313
width : 150,
1414
isSortable : true,
15-
extraValuePaths : ['startsAt', 'endAt'],
15+
extraValuePaths : ['name', 'logoUrl'],
1616
headerComponent : 'tables/headers/sort',
1717
cellComponent : 'ui-table/cell/cell-event-general',
1818
options : {
@@ -27,65 +27,43 @@ export default class extends Controller.extend(EmberTableControllerMixin) {
2727
{
2828
name : 'Date',
2929
valuePath : 'startsAt',
30+
extraValuePaths : ['endsAt'],
3031
isSortable : true,
3132
headerComponent : 'tables/headers/sort',
3233
cellComponent : 'ui-table/cell/cell-event-date'
3334

3435
},
3536
{
36-
name : 'Roles',
37-
valuePath : 'roles',
38-
width : 180,
39-
cellComponent : 'ui-table/cell/cell-roles',
40-
isSortable : false
37+
name : 'Roles',
38+
valuePath : 'owner',
39+
extraValuePaths : ['organizers', 'coorganizers', 'trackOrganizers', 'registrars', 'moderators'],
40+
width : 180,
41+
cellComponent : 'ui-table/cell/cell-roles'
4142
},
4243
{
4344
name : 'Sessions',
44-
valuePath : 'sessions',
45-
isSortable : false,
45+
valuePath : 'eventStatisticsGeneral',
4646
cellComponent : 'ui-table/cell/cell-sessions-dashboard'
4747
},
4848
{
4949
name : 'Speakers',
50-
valuePath : 'speakers',
51-
cellComponent : 'ui-table/cell/cell-speakers-dashboard',
52-
isSortable : false
53-
50+
valuePath : 'eventStatisticsGeneral',
51+
cellComponent : 'ui-table/cell/cell-speakers-dashboard'
5452
},
5553
{
5654
name : 'Tickets',
5755
valuePath : 'tickets',
58-
cellComponent : 'ui-table/cell/cell-tickets',
59-
isSortable : false
60-
56+
cellComponent : 'ui-table/cell/cell-tickets'
6157
},
6258
{
6359
name : 'Public URL',
6460
valuePath : 'url',
6561
width : 250,
66-
cellComponent : 'ui-table/cell/cell-link',
67-
isSortable : false
62+
cellComponent : 'ui-table/cell/cell-link'
6863
}
6964
];
7065
}
7166

72-
@computed('model.data')
73-
get rows() {
74-
const rows = [];
75-
this.model.data.forEach(row => {
76-
rows.pushObject({
77-
name : row,
78-
startsAt : row,
79-
roles : row,
80-
sessions : row,
81-
speakers : row,
82-
tickets : row,
83-
url : row
84-
});
85-
});
86-
return rows;
87-
}
88-
8967
@action
9068
moveToPublic(id) {
9169
this.transitionToRoute('public', id);

app/routes/events/list.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ export default class extends Route.extend(EmberTableRouteMixin) {
8989
'page[number]' : params.page || 4
9090
};
9191
queryString = this.applySortFilters(queryString, params);
92-
93-
return {
94-
data: await this.authManager.currentUser.query('events', queryString)
95-
};
96-
92+
return this.asArray(this.authManager.currentUser.query('events', queryString));
9793
}
9894

9995
@action
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<div class="ui header weight-400">
2-
<img src="{{if record.logoUrl record.logoUrl '/images/placeholders/Other.jpg'}}" alt="Event Logo" class="ui image"> <br> {{record.name}}
2+
<img src="{{if extraRecords.logoUrl extraRecords.logoUrl '/images/placeholders/Other.jpg'}}" alt="Event Logo" class="ui image"> <br> {{extraRecords.name}}
33
</div>
44
<div class="ui horizontal large basic buttons">
5-
{{#ui-popup tagName='a' click=(action props.actions.moveToDetails record.identifier) content=(t 'Event Dashboard') class='ui icon button' position='top center'}}
5+
{{#ui-popup tagName='a' click=(action props.actions.moveToDetails record) content=(t 'Event Dashboard') class='ui icon button' position='top center'}}
66
<i class="tasks icon"></i>
77
{{/ui-popup}}
8-
{{#ui-popup tagName='a' click=(action props.actions.moveToPublic record.identifier) content=(t 'View') class='ui icon button' position='top center'}}
8+
{{#ui-popup tagName='a' click=(action props.actions.moveToPublic record) content=(t 'View') class='ui icon button' position='top center'}}
99
<i class="unhide icon"></i>
1010
{{/ui-popup}}
11-
{{#ui-popup content=(t 'Edit') click=(action props.actions.editEvent record.identifier) class='ui icon button' position='top center'}}
11+
{{#ui-popup content=(t 'Edit') click=(action props.actions.editEvent record) class='ui icon button' position='top center'}}
1212
<i class="edit icon"></i>
1313
{{/ui-popup}}
1414
</div>

app/templates/events/list.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{{tables/default columns=columns
2-
rows=rows
2+
rows=model.data
33
currentPage=page
44
pageSize=per_page
55
searchQuery=search
66
sortBy=sort_by
77
sortDir=sort_dir
8-
metaData=model.data.meta
8+
metaData=model.meta
99
filterOptions=filterOptions
1010
widthConstraint="eq-container"
1111
resizeMode="fluid"

tests/integration/components/ui-table/cell/cell-event-general-test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { render } from '@ember/test-helpers';
66
module('Integration | Component | ui table/cell/cell event general', function(hooks) {
77
setupIntegrationTest(hooks);
88

9-
const record = { name: 'Event', image: 'url' };
9+
const extraRecords = { name: 'Event', logoUrl: 'url' };
10+
const record = 'abc215f';
1011

1112
const props = {
1213
actions: {
@@ -20,10 +21,11 @@ module('Integration | Component | ui table/cell/cell event general', function(ho
2021

2122
this.setProperties({
2223
record,
23-
props
24+
props,
25+
extraRecords
2426
});
2527

26-
await render(hbs`{{ui-table/cell/cell-event-general record=record props=props}}`);
28+
await render(hbs`{{ui-table/cell/cell-event-general extraRecords=extraRecords record=record props=props}}`);
2729
assert.ok(this.element.textContent.trim().includes('Event'));
2830
});
2931
});

0 commit comments

Comments
 (0)