Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-09 20:02:54 +01:00
added a feature for importing and exporting wizards
Dieser Commit ist enthalten in:
Ursprung
eeba1d45d1
Commit
63fb0658e9
8 geänderte Dateien mit 207 neuen und 0 gelöschten Zeilen
103
assets/javascripts/discourse/controllers/admin-wizards-transfer.js.es6
Normale Datei
103
assets/javascripts/discourse/controllers/admin-wizards-transfer.js.es6
Normale Datei
|
@ -0,0 +1,103 @@
|
|||
import {ajax} from 'discourse/lib/ajax';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
init() {
|
||||
|
||||
this._super();
|
||||
this.set('selected', new Set());
|
||||
this.set('filePath', []);
|
||||
// this.setProperties({selected:[]})
|
||||
|
||||
},
|
||||
|
||||
|
||||
actions: {
|
||||
|
||||
checkChanged(event) {
|
||||
// return true;
|
||||
// console.log(event.target.checked)
|
||||
|
||||
let selected = this.get('selected')
|
||||
|
||||
|
||||
if (event.target.checked) {
|
||||
|
||||
|
||||
selected.add(event.target.id)
|
||||
|
||||
} else if (!event.target.checked) {
|
||||
selected.delete(event.target.id)
|
||||
}
|
||||
console.log(selected)
|
||||
this.set('selected', selected)
|
||||
|
||||
// console.log(this.get('selected'))
|
||||
|
||||
|
||||
},
|
||||
|
||||
|
||||
export() {
|
||||
let wizards = this.get('selected')
|
||||
let url = Discourse.BaseUrl
|
||||
let route = '/admin/wizards/transfer/export'
|
||||
url += route + '?'
|
||||
|
||||
wizards.forEach((wizard) => {
|
||||
let step = 'wizards[]=' + wizard;
|
||||
step += '&'
|
||||
url += step
|
||||
})
|
||||
|
||||
location.href = url;
|
||||
|
||||
console.log(url)
|
||||
// return ajax('/admin/wizards/transfer/export', {
|
||||
// type: "POST",
|
||||
// data: {
|
||||
// wizards: wizards
|
||||
// }
|
||||
//
|
||||
// })
|
||||
|
||||
|
||||
},
|
||||
|
||||
setFilePath(event) {
|
||||
console.log(event.target.files[0])
|
||||
|
||||
this.set('filePath', event.target.files[0])
|
||||
|
||||
}
|
||||
|
||||
,
|
||||
import() {
|
||||
let fileReader = new FileReader();
|
||||
fileReader.onload = function () {
|
||||
let upload = {'fileJson': fileReader.result};
|
||||
// ajax('admin/wizard/transfer/import');
|
||||
console.log(fileReader.result)
|
||||
//ajax call
|
||||
|
||||
ajax('/admin/wizards/transfer/import',{
|
||||
type: 'POST' ,
|
||||
data:upload ,
|
||||
|
||||
}).then(result=>{
|
||||
if(result.error){
|
||||
console.log(result.error)
|
||||
|
||||
}else{
|
||||
alert('wizards imported successfully')
|
||||
}
|
||||
})
|
||||
}
|
||||
fileReader.readAsText(this.get('filePath'))
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
|
@ -11,6 +11,10 @@ export default {
|
|||
this.route('adminWizardsApis', { path: '/apis', resetNamespace: true }, function() {
|
||||
this.route('adminWizardsApi', { path: '/:name', resetNamespace: true });
|
||||
});
|
||||
|
||||
this.route('adminWizardsTransfer',{path:'/transfer', resetNamespace:true});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
11
assets/javascripts/discourse/routes/admin-wizards-transfer.js.es6
Normale Datei
11
assets/javascripts/discourse/routes/admin-wizards-transfer.js.es6
Normale Datei
|
@ -0,0 +1,11 @@
|
|||
import CustomWizard from '../models/custom-wizard';
|
||||
export default Discourse.Route.extend({
|
||||
|
||||
model(){
|
||||
return CustomWizard.all()
|
||||
},
|
||||
isEmberized: true
|
||||
// isEmberized(){
|
||||
// return true;
|
||||
// }
|
||||
})
|
34
assets/javascripts/discourse/templates/admin-wizards-transfer.hbs
Normale Datei
34
assets/javascripts/discourse/templates/admin-wizards-transfer.hbs
Normale Datei
|
@ -0,0 +1,34 @@
|
|||
<h3>Select Wizards to export</h3>
|
||||
{{log this}}
|
||||
|
||||
<form {{action 'export' wizards on="submit"}} class="form">
|
||||
<ul>
|
||||
{{#each model as |w|}}
|
||||
|
||||
<li style="list-style-type: none;">
|
||||
{{input type="checkbox" id=(dasherize w.id) change=(action 'checkChanged')}}
|
||||
|
||||
{{#link-to "adminWizard" (dasherize w.id)}}{{w.name}}{{/link-to}}
|
||||
</li>
|
||||
{{/each}}
|
||||
|
||||
</ul>
|
||||
{{!-- <button type='submit' class='btn btn-primary'>--}}
|
||||
{{!-- {{ i18n 'admin.wizard.transfer.export' }}--}}
|
||||
{{!-- </button>--}}
|
||||
{{d-button label="admin.wizard.transfer.export" action=(action "export")}}
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
{{input id='file_url' type="file" change=(action "setFilePath")}}
|
||||
<br />
|
||||
<br />
|
||||
{{d-button label="admin.wizard.transfer.import" action=(action "import")}}
|
||||
|
||||
{{!--{{resumable-upload--}}
|
||||
{{!-- target="transfer/import"--}}
|
||||
{{!-- success=(action "jsonSuccess")--}}
|
||||
{{!-- error=(action "jsonError")--}}
|
||||
{{!-- uploadText="Import"--}}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
{{nav-item route='adminWizardsCustom' label='admin.wizard.custom_label'}}
|
||||
{{nav-item route='adminWizardsSubmissions' label='admin.wizard.submissions_label'}}
|
||||
{{nav-item route='adminWizardsApis' label='admin.wizard.api.nav_label'}}
|
||||
{{nav-item route='adminWizardsTransfer' label='admin.wizard.transfer.nav_label'}}
|
||||
{{/admin-nav}}
|
||||
|
||||
<div class="admin-container">
|
||||
|
|
|
@ -215,6 +215,11 @@ en:
|
|||
log:
|
||||
label: "Logs"
|
||||
|
||||
transfer:
|
||||
nav_label: "Transfer"
|
||||
export: "Export"
|
||||
import: "Import"
|
||||
|
||||
wizard_js:
|
||||
location:
|
||||
name:
|
||||
|
|
43
controllers/transfer.rb
Normale Datei
43
controllers/transfer.rb
Normale Datei
|
@ -0,0 +1,43 @@
|
|||
class CustomWizard::TransferController < ::ApplicationController
|
||||
before_action :ensure_logged_in
|
||||
before_action :ensure_admin
|
||||
|
||||
skip_before_action :check_xhr, :only => [:export]
|
||||
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
def export
|
||||
|
||||
wizards = params['wizards']
|
||||
wizard_objects = []
|
||||
wizards.each do
|
||||
|w|
|
||||
# p w
|
||||
|
||||
wizard_objects.push(PluginStore.get('custom_wizard',w.tr('-','_')))
|
||||
|
||||
end
|
||||
puts 'wizard_objects'
|
||||
p wizard_objects
|
||||
send_data wizard_objects.to_json ,type: "application/json", disposition:'attachment' ,filename: 'wizards.json'
|
||||
|
||||
end
|
||||
|
||||
def import
|
||||
json = params['fileJson']
|
||||
jsonObject = JSON.parse json
|
||||
puts 'json file'
|
||||
# p jsonObject
|
||||
jsonObject.each do |o|
|
||||
puts 'json entity'
|
||||
pluginStoreEntry = PluginStore.new 'custom_wizard'
|
||||
#plugin store detects the json object type and sets proper `type_name` for the entry
|
||||
pluginStoreEntry.set(o['id'],o)
|
||||
end
|
||||
end
|
||||
# admin/wizards/transfer/import
|
||||
|
||||
end
|
|
@ -75,6 +75,10 @@ after_initialize do
|
|||
delete 'admin/wizards/apis/logs/:name' => 'api#clearlogs'
|
||||
get 'admin/wizards/apis/:name/redirect' => 'api#redirect'
|
||||
get 'admin/wizards/apis/:name/authorize' => 'api#authorize'
|
||||
#transfer code
|
||||
get 'admin/wizards/transfer' =>'transfer#index'
|
||||
get 'admin/wizards/transfer/export' => 'transfer#export'
|
||||
post 'admin/wizards/transfer/import' => 'transfer#import'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -89,6 +93,8 @@ after_initialize do
|
|||
load File.expand_path('../controllers/wizard.rb', __FILE__)
|
||||
load File.expand_path('../controllers/steps.rb', __FILE__)
|
||||
load File.expand_path('../controllers/admin.rb', __FILE__)
|
||||
#transfer code
|
||||
load File.expand_path('../controllers/transfer.rb',__FILE__)
|
||||
|
||||
load File.expand_path('../jobs/refresh_api_access_token.rb', __FILE__)
|
||||
load File.expand_path('../lib/api/api.rb', __FILE__)
|
||||
|
|
Laden …
In neuem Issue referenzieren