Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions app/controllers/admin/sales/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Controller from '@ember/controller';
import AdminSalesMixin from 'open-event-frontend/mixins/admin-sales';
import { or } from '@ember/object/computed';
import { action } from '@ember/object';
import { run } from '@ember/runloop';
import EmberTableControllerMixin from 'open-event-frontend/mixins/ember-table-controller';

export default class IndexController extends Controller.extend(AdminSalesMixin, EmberTableControllerMixin) {
Expand Down Expand Up @@ -94,4 +96,62 @@ get columns() {
}
];
}

@action
export(status) {
this.set('isLoading', true);
const payload = {
status
};
this.loader
.post('/admin/export/sales/csv', payload)
.then(exportJobInfo => {
this.requestLoop(exportJobInfo);
})
.catch(e => {
console.error('Error while exporting', e);
this.set('isLoading', false);
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
{
id: 'sales_unexp_error'
});
});
}

requestLoop(exportJobInfo) {
run.later(() => {
this.loader
.load(exportJobInfo.task_url, { withoutPrefix: true })
.then(exportJobStatus => {
if (exportJobStatus.state === 'SUCCESS') {
window.location = exportJobStatus.result.download_url;
this.notify.success(this.l10n.t('Download Ready'),
{
id: 'download_ready'
});
} else if (exportJobStatus.state === 'WAITING') {
this.requestLoop(exportJobInfo);
this.notify.alert(this.l10n.t('Task is going on.'),
{
id: 'task_going'
});
} else {
this.notify.error(this.l10n.t('CSV Export has failed.'),
{
id: 'csv_fail'
});
}
})
.catch(() => {
this.notify.error(this.l10n.t('CSV Export has failed.'),
{
id: 'csv_export_fail'
});
})
.finally(() => {
this.set('isLoading', false);
});
}, 3000);
}

}
66 changes: 33 additions & 33 deletions app/controllers/events/view/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class extends Controller {
return SESSION_STATES;
}

@action
@action
export(status) {
this.set('isLoading', true);
const payload = {
Expand All @@ -39,40 +39,40 @@ export default class extends Controller {
}


requestLoop(exportJobInfo) {
run.later(() => {
this.loader
.load(exportJobInfo.task_url, { withoutPrefix: true })
.then(exportJobStatus => {
if (exportJobStatus.state === 'SUCCESS') {
window.location = exportJobStatus.result.download_url;
this.notify.success(this.l10n.t('Download Ready'),
{
id: 'download_ready'
});
} else if (exportJobStatus.state === 'WAITING') {
this.requestLoop(exportJobInfo);
this.notify.alert(this.l10n.t('Task is going on.'),
{
id: 'task_going'
});
} else {
this.notify.error(this.l10n.t('CSV Export has failed.'),
{
id: 'csv_fail'
});
}
})
.catch(() => {
requestLoop(exportJobInfo) {
run.later(() => {
this.loader
.load(exportJobInfo.task_url, { withoutPrefix: true })
.then(exportJobStatus => {
if (exportJobStatus.state === 'SUCCESS') {
window.location = exportJobStatus.result.download_url;
this.notify.success(this.l10n.t('Download Ready'),
{
id: 'download_ready'
});
} else if (exportJobStatus.state === 'WAITING') {
this.requestLoop(exportJobInfo);
this.notify.alert(this.l10n.t('Task is going on.'),
{
id: 'task_going'
});
} else {
this.notify.error(this.l10n.t('CSV Export has failed.'),
{
id: 'csv_export_fail'
id: 'csv_fail'
});
})
.finally(() => {
this.set('isLoading', false);
});
}, 3000);
}
}
})
.catch(() => {
this.notify.error(this.l10n.t('CSV Export has failed.'),
{
id: 'csv_export_fail'
});
})
.finally(() => {
this.set('isLoading', false);
});
}, 3000);
}
}

1 change: 1 addition & 0 deletions app/templates/admin/sales/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<h2 class="ui header column">{{t 'Tickets Summary'}}</h2>
</div>
<div class="ten wide column right aligned">
<button class="ui blue button right-floated {{if this.isLoading 'loading'}}" {{action 'export' this.router.currentRoute.params.event_status}} >{{t 'Export as CSV'}}</button>
<UiDropdown class="labeled icon button mb-2 mr-2">
<i class="sort amount down icon"></i>
<span class="default text" style="text-transform: capitalize">{{this.router.currentRoute.params.event_status}}</span>
Expand Down