diff --git a/app/components/forms/group/group-events-form.js b/app/components/forms/group/group-events-form.js index 7e3b79b4039..2c08cd0f651 100644 --- a/app/components/forms/group/group-events-form.js +++ b/app/components/forms/group/group-events-form.js @@ -4,6 +4,8 @@ import { action, computed } from '@ember/object'; import { inject as service } from '@ember/service'; import classic from 'ember-classic-decorator'; import FormMixin from 'open-event-frontend/mixins/form'; +import moment from 'moment'; +import { sortBy } from 'lodash-es'; @classic export default class GroupEventsForm extends Component.extend(FormMixin) { @@ -41,7 +43,17 @@ export default class GroupEventsForm extends Component.extend(FormMixin) { @computed('events.[]', 'group.events.[]') get remainingEvents() { - return this.events.toArray().filter(event => !this.group.events.toArray().includes(event)); + return sortBy(this.events.toArray().filter(event => !this.group.events.toArray().includes(event)), ['startsAt']).reverse(); + } + + @computed('events.[]', 'group.events.[]') + get pastEvents() { + return sortBy(this.events.toArray().filter(event => { return moment(event.endsAt) < moment()}), ['startsAt']).reverse(); + } + + @computed('events.[]', 'group.events.[]') + get upcomingEvents() { + return sortBy(this.events.toArray().filter(event => { return moment(event.endsAt) > moment()}), ['startsAt']).reverse(); } @action diff --git a/app/components/forms/group/group-view.js b/app/components/forms/group/group-view.js index 933f41cc166..14f9afd6c8f 100644 --- a/app/components/forms/group/group-view.js +++ b/app/components/forms/group/group-view.js @@ -1,10 +1,23 @@ import Component from '@ember/component'; -import { action } from '@ember/object'; +import { computed, action } from '@ember/object'; import classic from 'ember-classic-decorator'; import FormMixin from 'open-event-frontend/mixins/form'; +import moment from 'moment'; +import { sortBy } from 'lodash-es'; @classic export default class GroupView extends Component.extend(FormMixin) { + + @computed('events.[]', 'group.events.[]') + get pastEvents() { + return sortBy(this.group.events.toArray().filter(event => { return moment(event.endsAt) < moment()}), ['startsAt']).reverse(); + } + + @computed('events.[]', 'group.events.[]') + get upcomingEvents() { + return sortBy(this.group.events.toArray().filter(event => { return moment(event.endsAt) > moment()}), ['startsAt']).reverse(); + } + @action shareEvent() {} } diff --git a/app/templates/components/forms/group/group-events-form.hbs b/app/templates/components/forms/group/group-events-form.hbs index 3e09facdf9e..1baf671be28 100644 --- a/app/templates/components/forms/group/group-events-form.hbs +++ b/app/templates/components/forms/group/group-events-form.hbs @@ -30,12 +30,19 @@ {{/if}} -
{{#if this.remainingEvents}} -

{{t 'All Events'}}

+ +

{{t 'Upcoming Events'}}

+
+ {{#each this.upcomingEvents as |event|}} + + {{/each}} +
+ +

{{t 'Past Events'}}

- {{#each this.remainingEvents as |event|}} + {{#each this.pastEvents as |event|}} {{/each}}
diff --git a/app/templates/components/forms/group/group-view.hbs b/app/templates/components/forms/group/group-view.hbs index bc8ca89a4b0..aa67779668b 100644 --- a/app/templates/components/forms/group/group-view.hbs +++ b/app/templates/components/forms/group/group-view.hbs @@ -19,11 +19,22 @@ {{/if}} {{/each}}
-
- {{#each @group.events as |event|}} - - {{/each}} -
+ {{#if this.upcomingEvents}} +

{{t 'Upcoming Events'}}

+
+ {{#each this.upcomingEvents as |event|}} + + {{/each}} +
+ {{/if}} + {{#if this.pastEvents}} +

{{t 'Past Events'}}

+
+ {{#each this.pastEvents as |event|}} + + {{/each}} +
+ {{/if}} {{/if}}