Client and server-side fixes
Dieser Commit ist enthalten in:
Ursprung
ee71719793
Commit
922afdc1bd
5 geänderte Dateien mit 37 neuen und 30 gelöschten Zeilen
|
@ -79,7 +79,11 @@ export default Ember.Controller.extend({
|
|||
}
|
||||
|
||||
if (maxFileSize < event.target.files[0].size) {
|
||||
this.set('importMessage', I18n.t('admin.wizard.transfer.import.file_size_error'));
|
||||
this.setProperties({
|
||||
importMessage: I18n.t('admin.wizard.transfer.import.file_size_error'),
|
||||
filePath: null
|
||||
});
|
||||
$('#file-url').val('');
|
||||
} else {
|
||||
this.set('filePath', event.target.files[0]);
|
||||
}
|
||||
|
@ -99,7 +103,7 @@ export default Ember.Controller.extend({
|
|||
contentType: false,
|
||||
}).then(result => {
|
||||
if (result.error) {
|
||||
this.set('error', result.error);
|
||||
this.set('importMessage', result.error);
|
||||
} else {
|
||||
this.setProperties({
|
||||
successIds: result.success,
|
||||
|
|
|
@ -31,16 +31,17 @@
|
|||
|
||||
<div class="controls">
|
||||
{{input id='file-url' type="file" change=(action "setFilePath")}}
|
||||
{{d-button id="import-button"
|
||||
class="btn btn-primary side"
|
||||
label="admin.wizard.transfer.import.label"
|
||||
action=(action "import")}}
|
||||
|
||||
{{#if importMessage}}
|
||||
<div class="import-message">
|
||||
{{importMessage}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{d-button id="import-button"
|
||||
class="btn btn-primary side"
|
||||
label="admin.wizard.transfer.import.label"
|
||||
action=(action "import")}}
|
||||
</div>
|
||||
|
||||
{{#if hasLogs}}
|
||||
|
|
|
@ -500,6 +500,10 @@
|
|||
flex-direction: column;
|
||||
}
|
||||
|
||||
.import-message {
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.import-logs {
|
||||
margin-top: 20px;
|
||||
|
||||
|
|
|
@ -226,7 +226,7 @@ en:
|
|||
success: 'Wizard "{{id}}" saved successfully'
|
||||
failure: 'Wizard "{{id}}" could not be saved'
|
||||
no_file: "Please choose a file to import"
|
||||
file_size_error: "The file size is too big"
|
||||
file_size_error: "The file must be JSON and 512kb or less"
|
||||
|
||||
wizard_js:
|
||||
location:
|
||||
|
|
|
@ -19,15 +19,10 @@ class CustomWizard::TransferController < ::ApplicationController
|
|||
wizard_objects.push(PluginStore.get('custom_wizard', w.tr('-', '_')))
|
||||
end
|
||||
|
||||
send_data wizard_objects.to_json, type: "application/json", disposition: 'attachment', filename: 'wizards.json'
|
||||
end
|
||||
|
||||
def is_json(string)
|
||||
begin
|
||||
!!JSON.parse(string)
|
||||
rescue
|
||||
false
|
||||
end
|
||||
send_data wizard_objects.to_json,
|
||||
type: "application/json",
|
||||
disposition: 'attachment',
|
||||
filename: 'wizards.json'
|
||||
end
|
||||
|
||||
def import
|
||||
|
@ -46,22 +41,25 @@ class CustomWizard::TransferController < ::ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
unless is_json file
|
||||
begin
|
||||
jsonObject = JSON.parse file
|
||||
rescue JSON::ParserError
|
||||
render json: { error: I18n.t('wizard.import.error.invalid_json') }
|
||||
return
|
||||
end
|
||||
|
||||
jsonObject = JSON.parse file
|
||||
countValid = 0
|
||||
success_ids = []
|
||||
failed_ids = []
|
||||
|
||||
jsonObject.each do |o|
|
||||
# validate whether the given json is a valid "wizard"
|
||||
next unless CustomWizard::Template.new(o)
|
||||
if !CustomWizard::Template.new(o)
|
||||
failed_ids.push o['id']
|
||||
next
|
||||
end
|
||||
|
||||
countValid += 1
|
||||
pluginStoreEntry = PluginStore.new 'custom_wizard'
|
||||
#plugin store detects the json object type and sets proper `type_name` for the entry
|
||||
# this condition helps us avoid updating an existing wizard instead of adding a new one
|
||||
saved = pluginStoreEntry.set(o['id'], o) unless pluginStoreEntry.get(o['id'])
|
||||
success_ids.push o['id'] if !!saved
|
||||
failed_ids.push o['id'] if !saved
|
||||
|
|
Laden …
In neuem Issue referenzieren