Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
55 changes: 55 additions & 0 deletions app/components/events/event-import-section.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import $ from 'jquery';
import Component from '@ember/component';
import FormMixin from 'open-event-frontend/mixins/form';
import ENV from 'open-event-frontend/config/environment';

export default Component.extend(FormMixin, {
classNames: ['ui', 'stackable', 'centered', 'grid'],
Expand All @@ -26,9 +28,62 @@ export default Component.extend(FormMixin, {
}
};
},
importTask(url) {
let _this = this;
this.get('loader')
.load(url)
.then(data => {
if (data.state !== 'SUCCESS') {
$('#import_status').html(`<b>Status:</b> ${ data.state}`);
setTimeout(function() {
_this.importTask(url);
}, 3000);
} else {
$('#import_status').html(`<b>Status:</b> ${ data.state}`);
document.location = `/events/${ data.result.id}`;
}
})
.catch(e => {
$('#import_status').text('');
$('#btnImportEvent').prop('disabled', false);
$('#import_file').prop('disabled', false);
$('#import_error').text(e.message);
});
},
actions: {
submit() {
let _this = this;
this.onValid(() => {
var data = new FormData();
var endpoint = 'import/json';
$.each($('#file')[0].files, function(i, file) {
var ext = file.name.split('.');
ext = ext[ext.length - 1].toLowerCase();
if (ext === 'xml') {
endpoint = 'import/pentabarf';
} else if (ext === 'ical') {
endpoint = 'import/ical';
}
data.append('file', file);

$('#import_status').text('Uploading file.. Please don\'t close this window');
$('#import_error').text('');
$('#btnImportEvent').prop('disabled', true);
$('#file').prop('disabled', true);

_this.get('loader').post(
`${`${ENV.APP.apiHost}/${ENV.APP.apiNamespace}/events/`}${endpoint}`,
data,
{ isExternal: true, isFile: true }
).then(data => {
setTimeout(function() {
_this.importTask(`tasks/${data.task_url.split('/')[3]}`);
}, 1000);
}).catch(e => {
$('#import_status').text('');
$('#import_error').text(e);
});
});
});
}
}
Expand Down
9 changes: 9 additions & 0 deletions app/models/import-job.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import attr from 'ember-data/attr';
import ModelBase from 'open-event-frontend/models/base';

export default ModelBase.extend({
resultStatus : attr('string'),
result : attr('string'),
task : attr('string'),
startsAt : attr('moment', { readOnly: true })
});
9 changes: 9 additions & 0 deletions app/routes/events/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@ import Route from '@ember/routing/route';
export default Route.extend({
titleToken() {
return this.get('l10n').t('Import');
},
async model() {

const data = await this.get('store').findAll('importJob');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a valid query. There is no importJob model, please try importing the event yourself, and request a review when it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented the importJob model both in backend and fronted. Please check fossasia/open-event-server#5514.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested it locally, it works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YogeshSharma0201 Oh okay will check on the server.


return {
data,
objectType: 'importJob'
};
}
});
4 changes: 4 additions & 0 deletions app/services/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default Service.extend({
adapter : 'adapter:application',
isExternal : false,
isFormData : false,
isFile : false,
queryParams : {},
withoutPrefix : false,
replaceHeaders : false,
Expand Down Expand Up @@ -48,6 +49,9 @@ export default Service.extend({
} else {
if (config.isFormData) {
fetchOptions.body = objectToFormData(data);
} else if (config.isFile) {
fetchOptions.headers.Authorization = adapter.ajaxOptions().headers.Authorization;
fetchOptions.body = data;
} else {
fetchOptions.headers['Content-Type'] = 'application/json';
fetchOptions.body = JSON.stringify(data);
Expand Down
6 changes: 5 additions & 1 deletion app/templates/components/events/event-import-section.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
{{t 'Open Event compatible json package (.zip), PentabarfXML (.xml), iCalendar (.ical, .ics), XML Representation of iCalendar (.xcal)'}}
</span>
</div>
<button class="ui small primary button" type="submit">{{t 'Import Event'}}</button>
<button class="ui small primary button" id="btnImportEvent" type="submit">{{t 'Import Event'}}</button>
<div style="margin-top: 10px;">
<span id="import_status"></span>
<span id="import_error" class="red"></span>
</div>
</form>
</div>
14 changes: 7 additions & 7 deletions app/templates/components/events/imports-history-section.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
</tr>
</thead>
<tbody>
<tr>
<td>
<i class="check circle icon green"></i>{{t 'Success'}}
</td>
<td>{{t 'Check your event here'}}</td>
<td>{{t '8 days ago'}}</td>
</tr>
{{#each data as |job|}}
<tr>
<td>{{job.resultStatus}}</td>
<td>{{job.result}}</td>
<td>{{header-date job.startsAt}}</td>
</tr>
{{/each}}
</tbody>
<tfoot>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/events/import.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{events/event-import-section}}
<br><br>
{{events/imports-history-section}}
{{events/imports-history-section data=model.data}}