Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions app/components/events/event-import-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export default Component.extend(FormMixin, {
},
actions: {
submit() {
let _this = this;
this.onValid(() => {
_this.sendAction('uploadFile', event.target.getElementsByTagName('input')[0].files);
});
}
}
Expand Down
65 changes: 65 additions & 0 deletions app/controllers/events/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import Controller from '@ember/controller';
import { run } from '@ember/runloop';
import ENV from 'open-event-frontend/config/environment';

export default Controller.extend({
importStatus : 'Importing',
importError : 'Import Error',
btnImportEvent : false,
file : false,
fileName : '',
importTask(taskUrl) {
let _this = this;
run.later(() => {
this.get('loader')
.load(taskUrl)
.then(data => {
if (data.state !== 'SUCCESS') {
this.set('importStatus', `Status: ${ data.state}`);
_this.importTask(taskUrl);
} else {
this.set('importStatus', `Status: ${ data.state}`);
document.location = `/events/${ data.result.id}`;
}
})
.catch(e => {
this.set('');
this.set('importError', e.message);
this.set('btnImportEvent', false);
this.set('file', false);
});
}, 3000);
},
actions: {
uploadFile(files) {
let _this = this;
let [file] = files;
var data = new FormData();
var endpoint = 'import/json';
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);

this.set('importStatus', 'Uploading file.. Please don\'t close this window');
this.set('importError', '');
this.set('btnImportEvent', true);
this.set('file', true);

this.get('loader').post(
`${`${ENV.APP.apiHost}/${ENV.APP.apiNamespace}/events/`}${endpoint}`,
data,
{ isExternal: true, isFile: true }
).then(data => {
_this.importTask(`tasks/${data.task_url.split('/')[3]}`);
}).catch(e => {
this.set('');
this.set('importError', e.message);
});
}
}
});
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
8 changes: 6 additions & 2 deletions app/templates/components/events/event-import-section.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
<form class="ui form" {{action 'submit' on='submit'}}>
<div class="field {{if device.isMobile 'sixteen' 'five'}} wide column">
<label class="required" for="file"> {{t 'Select event source file to import'}}</label>
{{input type='file' id='file'}}
{{input type='file' disabled=file}}
</div>
<div class="field {{if device.isMobile 'sixteen' 'five'}} wide column">
<span class="text muted">
<b>{{t 'Supported formats:'}}</b>
{{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" disabled={{btnImportEvent}}>{{t 'Import Event'}}</button>
<div style="margin-top: 10px;">
<span>{{importStatus}}</span>
<span class="red">{{importError}}</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
4 changes: 2 additions & 2 deletions app/templates/events/import.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{events/event-import-section}}
{{events/event-import-section uploadFile=(action 'uploadFile') importStatus=importStatus importError=importError btnImportEvent=btnImportEvent file=file}}
<br><br>
{{events/imports-history-section}}
{{events/imports-history-section data=model.data}}