0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-26 02:50:28 +01:00

Fixed code formatting, tweaked css, moved remaining hardcoded strings to translations and removed all console.log calls

Dieser Commit ist enthalten in:
Faizaan Gagan 2019-08-06 16:38:05 +05:30
Ursprung e4de1d4145
Commit 25792f92e4
7 geänderte Dateien mit 70 neuen und 77 gelöschten Zeilen

Datei anzeigen

@ -1,4 +1,4 @@
import {ajax} from 'discourse/lib/ajax'; import { ajax } from 'discourse/lib/ajax';
export default Ember.Controller.extend({ export default Ember.Controller.extend({
init() { init() {
@ -7,16 +7,15 @@ export default Ember.Controller.extend({
this.set('filePath', Ember.A()); this.set('filePath', Ember.A());
}, },
actions: { actions: {
checkChanged(event) { checkChanged(event) {
this.set('noneSelected','')
let selected = this.get('selected'); let selected = this.get('selected');
if (event.target.checked) { if (event.target.checked) {
selected.addObject(event.target.id) selected.addObject(event.target.id)
} else if (!event.target.checked) { } else if (!event.target.checked) {
selected.removeObject(event.target.id) selected.removeObject(event.target.id)
} }
console.log(selected);
this.set('selected', selected) this.set('selected', selected)
}, },
@ -26,7 +25,7 @@ export default Ember.Controller.extend({
let route = '/admin/wizards/transfer/export'; let route = '/admin/wizards/transfer/export';
url += route + '?'; url += route + '?';
if (!wizards.length) { if (!wizards.length) {
this.set('noneSelected', "Please select atleast one wizard") this.set('noneSelected', I18n.t("admin.wizard.transfer.export.noneSelected"))
} else { } else {
this.set('noneSelected', '') this.set('noneSelected', '')
wizards.forEach((wizard) => { wizards.forEach((wizard) => {
@ -39,6 +38,7 @@ export default Ember.Controller.extend({
}, },
setFilePath(event) { setFilePath(event) {
this.set('noFile', '')
// 512 kb is the max file size // 512 kb is the max file size
let maxFileSize = 512 * 1024; let maxFileSize = 512 * 1024;
if (event.target.files[0] === undefined) { if (event.target.files[0] === undefined) {
@ -46,24 +46,22 @@ export default Ember.Controller.extend({
return return
} }
if (maxFileSize < event.target.files[0].size) { if (maxFileSize < event.target.files[0].size) {
this.set('fileError', 'The file size is too big') this.set('fileSizeError', I18n.t('admin.wizard.transfer.import.fileSizeError'))
} else { } else {
this.set('fileSizeError', '')
// emptying the array as we allow only one file upload at a time // emptying the array as we allow only one file upload at a time
this.get('filePath').length = 0 this.get('filePath').length = 0
// interestingly, this.get gives us the actual reference to the object so modifying it // interestingly, this.get gives us the actual reference to the object so modifying it
// actually modifies the actual value // actually modifies the actual value
this.get('filePath').addObject(event.target.files[0]) this.get('filePath').addObject(event.target.files[0])
console.log(this.get('filePath'))
} }
}, },
import() { import() {
let $formData = new FormData(); let $formData = new FormData();
console.log(this.get('filePath'))
if (this.get('filePath').length) { if (this.get('filePath').length) {
this.set('noFile', '') this.set('noFile', '')
$formData.append('file', this.get('filePath')[0]); $formData.append('file', this.get('filePath')[0]);
console.log($formData);
ajax('/admin/wizards/transfer/import', { ajax('/admin/wizards/transfer/import', {
type: 'POST', type: 'POST',
data: $formData, data: $formData,
@ -78,7 +76,7 @@ export default Ember.Controller.extend({
} }
}) })
} else { } else {
this.set('noFile', 'Please choose a file to export') this.set('noFile',I18n.t("admin.wizard.transfer.import.noFile"))
} }
} }
} }

Datei anzeigen

@ -1,55 +1,44 @@
<h2>Export</h2> <div class="container export">
<h2>{{i18n 'admin.wizard.transfer.export.label'}}</h2>
<ul class="wizard-list-select"> <ul class="wizard-list-select">
{{#each model as |w|}} {{#each model as |w|}}
<li>
<li style="list-style-type: none;">
{{input type="checkbox" id=(dasherize w.id) change=(action 'checkChanged')}} {{input type="checkbox" id=(dasherize w.id) change=(action 'checkChanged')}}
{{#link-to "adminWizard" (dasherize w.id)}}{{w.name}}{{/link-to}} {{#link-to "adminWizard" (dasherize w.id)}}{{w.name}}{{/link-to}}
</li> </li>
{{/each}} {{/each}}
</ul> </ul>
{{d-button id="export-button" class="btn btn-primary side" label="admin.wizard.transfer.export.label" action=(action "export")}}
{{#if this.noneSelected}}
<p>{{this.noneSelected}}</p>
{{/if}}
</div>
{{d-button id="export-button" class="btn btn-primary side" label="admin.wizard.transfer.export" <div class="container import">
action=(action "export")}} <h2>{{i18n 'admin.wizard.transfer.import.label'}}</h2>
<h2>Import</h2>
{{input id='file_url' type="file" change=(action "setFilePath")}} {{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 this.noFile}}
<p>{{this.noFile}}</p>
{{/if}}
{{#if this.fileSizeError}}
<p>{{this.fileSizeError}}</p>
{{/if}}
{{#if this.success_ids}}
{{#each this.success_ids as |id|}}
<p>{{i18n "admin.wizard.transfer.import.success"}}</p>
{{/each}}
{{/if}}
{{d-button id="import-button" class="btn btn-primary side" label="admin.wizard.transfer.import" {{#if this.failure_ids}}
action=(action "import")}} {{#each this.failure_ids as |id|}}
<p>{{i18n "admin.wizard.transfer.import.failure" id=id}}</p>
{{#if this.noneSelected}} {{/each}}
<p>{{this.noneSelected}}</p> {{/if}}
{{/if}} </div>
{{!-- server side error--}}
{{#if this.noFile}}
<p>{{this.noFile}}</p>
{{/if}}
{{#if this.fileError}}
<p>{{this.fileError}}</p>
{{/if}}
{{#if this.error}} {{#if this.error}}
<p>{{this.error}}</p> <p>{{this.error}}</p>
{{/if}} {{/if}}
{{#if this.success_ids}}
{{#each this.success_ids as |id|}}
<p>Wizard: {{id}} saved successfully</p>
{{/each}}
{{/if}}
{{#if this.failure_ids}}
{{#each this.failure_ids as |id|}}
<p>Wizard: {{id}} could not be saved</p>
{{/each}}
{{/if}}

Datei anzeigen

@ -1,19 +0,0 @@
#export-button{
margin-left: 30px;
}
#import-button{
margin-left: 15px;
}
#file_url {
display: inline;
}
.wizard-list-select {
display: inline-block;
}
.wizard-action-buttons{
display: inline-flex;
flex-direction: column;
}

Datei anzeigen

@ -480,3 +480,22 @@
.wizard-step-contents{ .wizard-step-contents{
height: unset !important; height: unset !important;
} }
// Tansfer tab
#file_url {
display: block;
margin-bottom: 10px;
}
.wizard-list-select {
list-style-type: none;
}
.wizard-action-buttons{
flex-direction: column;
}
.container{
margin-bottom: 20px;
}

Datei anzeigen

@ -217,8 +217,15 @@ en:
transfer: transfer:
nav_label: "Transfer" nav_label: "Transfer"
export: "Export" export:
import: "Import" label: "Export"
noneSelected: "Please select atleast one wizard"
import:
label: "Import"
success: "Wizard: {{id}} saved successfully"
failure: "Wizard: {{id}} could not be saved"
noFile: "Please choose a file to import"
fileSizeError: "The file size is too big"
wizard_js: wizard_js:
location: location:

Datei anzeigen

@ -9,6 +9,7 @@ class CustomWizard::TransferController < ::ApplicationController
def export def export
wizards = params['wizards'] wizards = params['wizards']
wizard_objects = [] wizard_objects = []
if wizards.nil? if wizards.nil?
render json: {error: I18n.t('wizard.export.error.select_one')} render json: {error: I18n.t('wizard.export.error.select_one')}
return return
@ -19,7 +20,6 @@ class CustomWizard::TransferController < ::ApplicationController
end end
send_data wizard_objects.to_json, type: "application/json", disposition: 'attachment', filename: 'wizards.json' send_data wizard_objects.to_json, type: "application/json", disposition: 'attachment', filename: 'wizards.json'
end end
def is_json(string) def is_json(string)
@ -32,12 +32,15 @@ class CustomWizard::TransferController < ::ApplicationController
def import def import
file = File.read(params['file'].tempfile) file = File.read(params['file'].tempfile)
if file.nil? if file.nil?
render json: {error: I18n.t('wizard.import.error.no_file')} render json: {error: I18n.t('wizard.import.error.no_file')}
return return
end end
fileSize = file.size fileSize = file.size
maxFileSize = 512 * 1024 maxFileSize = 512 * 1024
if maxFileSize < fileSize if maxFileSize < fileSize
render json: {error: I18n.t('wizard.import.error.file_large')} render json: {error: I18n.t('wizard.import.error.file_large')}
return return
@ -49,7 +52,6 @@ class CustomWizard::TransferController < ::ApplicationController
end end
jsonObject = JSON.parse file jsonObject = JSON.parse file
countValid = 0 countValid = 0
success_ids = [] success_ids = []
failed_ids = [] failed_ids = []
@ -71,6 +73,4 @@ class CustomWizard::TransferController < ::ApplicationController
render json: {success: success_ids, failed: failed_ids} render json: {success: success_ids, failed: failed_ids}
end end
end end
end end

Datei anzeigen

@ -5,7 +5,6 @@
# url: https://github.com/angusmcleod/discourse-custom-wizard # url: https://github.com/angusmcleod/discourse-custom-wizard
register_asset 'stylesheets/wizard_custom_admin.scss' register_asset 'stylesheets/wizard_custom_admin.scss'
register_asset 'stylesheets/wizard/wizard_transfer.scss'
register_asset 'lib/jquery.timepicker.min.js' register_asset 'lib/jquery.timepicker.min.js'
register_asset 'lib/jquery.timepicker.scss' register_asset 'lib/jquery.timepicker.scss'