various
Dieser Commit ist enthalten in:
Ursprung
a3f9135698
Commit
3fa2735c63
13 geänderte Dateien mit 160 neuen und 29 gelöschten Zeilen
22
app/controllers/steps.rb
Normale Datei
22
app/controllers/steps.rb
Normale Datei
|
@ -0,0 +1,22 @@
|
||||||
|
class StepsController < ApplicationController
|
||||||
|
before_filter :ensure_logged_in
|
||||||
|
|
||||||
|
def update
|
||||||
|
wizard = CustomWizard::Builder.new(current_user, params[:wizard_id]).build
|
||||||
|
updater = wizard.create_updater(params[:id], params[:fields])
|
||||||
|
updater.update
|
||||||
|
|
||||||
|
if updater.success?
|
||||||
|
result = { success: 'OK' }
|
||||||
|
result[:refresh_required] = true if updater.refresh_required?
|
||||||
|
render json: result
|
||||||
|
else
|
||||||
|
errors = []
|
||||||
|
updater.errors.messages.each do |field, msg|
|
||||||
|
errors << { field: field, description: msg.join }
|
||||||
|
end
|
||||||
|
render json: { errors: errors }, status: 422
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -1,8 +1,12 @@
|
||||||
class CustomWizard::StepsController < ::ApplicationController
|
class CustomWizard::WizardController < ::ApplicationController
|
||||||
def all
|
def set_layout
|
||||||
|
File.expand_path('../../views/layouts/custom_wizard.html.erb', __FILE__)
|
||||||
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
wizard = CustomWizard::Builder.new(current_user, params[:wizard_id]).build
|
wizard = CustomWizard::Builder.new(current_user, params[:name]).build
|
||||||
render_serialized(wizard, WizardSerializer)
|
render_serialized(wizard, WizardSerializer)
|
||||||
end
|
end
|
||||||
format.html {}
|
format.html {}
|
29
app/views/layouts/custom_wizard.html.erb
Normale Datei
29
app/views/layouts/custom_wizard.html.erb
Normale Datei
|
@ -0,0 +1,29 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<%= discourse_stylesheet_link_tag :wizard, theme_key: nil %>
|
||||||
|
<%= preload_script "ember_jquery" %>
|
||||||
|
<%= preload_script "wizard-vendor" %>
|
||||||
|
<%= preload_script "wizard-application" %>
|
||||||
|
<%= preload_script "wizard-custom" %>
|
||||||
|
<%= preload_script "locales/#{I18n.locale}" %>
|
||||||
|
<%= render partial: "common/special_font_face" %>
|
||||||
|
<script src="<%= Discourse.base_uri %>/extra-locales/wizard"></script>
|
||||||
|
<%= csrf_meta_tags %>
|
||||||
|
|
||||||
|
<meta name="discourse-base-uri" content="<%= Discourse.base_uri %>">
|
||||||
|
|
||||||
|
<%= render partial: "layouts/head" %>
|
||||||
|
<title><%= t 'custom_wizard.title' %></title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class='wizard'>
|
||||||
|
<div id='wizard-main'></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(function() {
|
||||||
|
var wizard = require('wizard/wizard').default.create();
|
||||||
|
wizard.start();
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -9,7 +9,7 @@ export default Discourse.Route.extend({
|
||||||
|
|
||||||
this.set('new', false);
|
this.set('new', false);
|
||||||
|
|
||||||
const wizard = this.modelFor('admin-wizards-custom').findBy('dasherizedName', params.name );
|
const wizard = this.modelFor('admin-wizards-custom').findBy('dasherizedName', params.name);
|
||||||
|
|
||||||
if (!wizard) return this.transitionTo('adminWizardsCustom.index');
|
if (!wizard) return this.transitionTo('adminWizardsCustom.index');
|
||||||
|
|
||||||
|
|
3
assets/javascripts/wizard-custom.js
Normale Datei
3
assets/javascripts/wizard-custom.js
Normale Datei
|
@ -0,0 +1,3 @@
|
||||||
|
//= require_tree ./wizard/initializers
|
||||||
|
//= require_tree ./wizard/models
|
||||||
|
//= require_tree ./wizard/routes
|
13
assets/javascripts/wizard/initializers/custom.js.es6
Normale Datei
13
assets/javascripts/wizard/initializers/custom.js.es6
Normale Datei
|
@ -0,0 +1,13 @@
|
||||||
|
import Router from 'wizard/router';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'custom-routes',
|
||||||
|
|
||||||
|
initialize() {
|
||||||
|
Router.map(function() {
|
||||||
|
this.route('custom', { path: '/custom/:name' }, function() {
|
||||||
|
this.route('step', { path: '/steps/:step_id' });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
22
assets/javascripts/wizard/models/custom-wizard.js.es6
Normale Datei
22
assets/javascripts/wizard/models/custom-wizard.js.es6
Normale Datei
|
@ -0,0 +1,22 @@
|
||||||
|
import Step from 'wizard/models/step';
|
||||||
|
import WizardField from 'wizard/models/wizard-field';
|
||||||
|
import { ajax } from 'wizard/lib/ajax';
|
||||||
|
import computed from 'ember-addons/ember-computed-decorators';
|
||||||
|
|
||||||
|
const CustomWizard = Ember.Object.extend({
|
||||||
|
@computed('steps.length')
|
||||||
|
totalSteps: length => length
|
||||||
|
});
|
||||||
|
|
||||||
|
export function findCustomWizard(name) {
|
||||||
|
return ajax({ url: `/wizard/custom/${name}.json` }).then(response => {
|
||||||
|
const wizard = response.wizard;
|
||||||
|
wizard.steps = wizard.steps.map(step => {
|
||||||
|
const stepObj = Step.create(step);
|
||||||
|
stepObj.fields = stepObj.fields.map(f => WizardField.create(f));
|
||||||
|
return stepObj;
|
||||||
|
});
|
||||||
|
|
||||||
|
return CustomWizard.create(wizard);
|
||||||
|
});
|
||||||
|
}
|
7
assets/javascripts/wizard/routes/application.js.es6
Normale Datei
7
assets/javascripts/wizard/routes/application.js.es6
Normale Datei
|
@ -0,0 +1,7 @@
|
||||||
|
import { findCustomWizard } from '../models/custom-wizard';
|
||||||
|
|
||||||
|
export default Ember.Route.extend({
|
||||||
|
model(params) {
|
||||||
|
return findCustomWizard(params.name);
|
||||||
|
}
|
||||||
|
});
|
11
assets/javascripts/wizard/routes/custom.js.es6
Normale Datei
11
assets/javascripts/wizard/routes/custom.js.es6
Normale Datei
|
@ -0,0 +1,11 @@
|
||||||
|
import { findCustomWizard } from '../models/custom-wizard';
|
||||||
|
|
||||||
|
export default Ember.Route.extend({
|
||||||
|
model(params) {
|
||||||
|
return findCustomWizard(params.name);
|
||||||
|
},
|
||||||
|
|
||||||
|
afterModel(model) {
|
||||||
|
this.replaceWith('step', model.start);
|
||||||
|
}
|
||||||
|
});
|
3
config/locales/server.en.yml
Normale Datei
3
config/locales/server.en.yml
Normale Datei
|
@ -0,0 +1,3 @@
|
||||||
|
en:
|
||||||
|
wizard:
|
||||||
|
title: "Wizard"
|
|
@ -1,23 +1,30 @@
|
||||||
class CustomWizard::Builder
|
class CustomWizard::Builder
|
||||||
def initialize(user, wizard_id)
|
def initialize(user, wizard_name)
|
||||||
|
rows = PluginStoreRow.where(plugin_name: 'custom_wizards')
|
||||||
|
return if !rows
|
||||||
|
|
||||||
|
[*rows].each do |r|
|
||||||
|
wizard = CustomWizard::Wizard.new(r.value)
|
||||||
|
@template = wizard if wizard.name.dasherize.downcase == wizard_name
|
||||||
|
end
|
||||||
|
|
||||||
@wizard = Wizard.new(user)
|
@wizard = Wizard.new(user)
|
||||||
@template = PluginStore.get('custom_wizard', wizard_id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def build
|
def build
|
||||||
@template.each do |s|
|
@template.steps.each do |s|
|
||||||
@wizard.append_step(s.title) do |step|
|
@wizard.append_step(s['title']) do |step|
|
||||||
|
|
||||||
step.banner = s.banner if s.banner
|
step.banner = s['banner'] if s['banner']
|
||||||
|
|
||||||
s.fields.each do |f|
|
s['fields'].each do |f|
|
||||||
field = step.add_field(id: f.id,
|
field = step.add_field(id: f['id'],
|
||||||
type: f.type,
|
type: f['type'],
|
||||||
required: f.required,
|
required: f['required'],
|
||||||
value: f.value)
|
value: f['value'])
|
||||||
|
|
||||||
if f.type == 'dropdown'
|
if f['type'] == 'dropdown'
|
||||||
f.choices.each do |c|
|
f['choices'].each do |c|
|
||||||
field.add_choice(c)
|
field.add_choice(c)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
36
plugin.rb
36
plugin.rb
|
@ -5,6 +5,9 @@
|
||||||
|
|
||||||
register_asset 'stylesheets/custom-wizard.scss'
|
register_asset 'stylesheets/custom-wizard.scss'
|
||||||
|
|
||||||
|
config = Rails.application.config
|
||||||
|
config.assets.paths << Rails.root.join("plugins", "discourse-custom-wizard", "assets", "javascripts")
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
require_dependency "application_controller"
|
require_dependency "application_controller"
|
||||||
module ::CustomWizard
|
module ::CustomWizard
|
||||||
|
@ -14,25 +17,32 @@ after_initialize do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
load File.expand_path('../lib/builder.rb', __FILE__)
|
||||||
|
load File.expand_path('../lib/wizard.rb', __FILE__)
|
||||||
|
load File.expand_path('../app/controllers/wizard.rb', __FILE__)
|
||||||
|
load File.expand_path('../app/controllers/steps.rb', __FILE__)
|
||||||
|
load File.expand_path('../app/controllers/admin.rb', __FILE__)
|
||||||
|
|
||||||
CustomWizard::Engine.routes.draw do
|
CustomWizard::Engine.routes.draw do
|
||||||
get 'custom' => 'admin#index'
|
get ':name' => 'wizard#index'
|
||||||
get 'custom/new' => 'admin#index'
|
get ':name/steps' => 'steps#index'
|
||||||
get 'custom/all' => "admin#all"
|
get ':name/steps/:id' => 'wizard#index'
|
||||||
get 'custom/:id' => "admin#find"
|
put ':name/steps/:id' => 'steps#update'
|
||||||
put 'custom/save' => "admin#save"
|
|
||||||
delete 'custom/remove' => "admin#remove"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require_dependency 'admin_constraint'
|
require_dependency 'admin_constraint'
|
||||||
Discourse::Application.routes.append do
|
Discourse::Application.routes.append do
|
||||||
|
namespace :wizard do
|
||||||
|
mount ::CustomWizard::Engine, at: 'custom'
|
||||||
|
end
|
||||||
|
|
||||||
namespace :admin, constraints: AdminConstraint.new do
|
scope module: 'custom_wizard', constraints: AdminConstraint.new do
|
||||||
mount ::CustomWizard::Engine, at: 'wizards'
|
get 'admin/wizards/custom' => 'admin#index'
|
||||||
|
get 'admin/wizards/custom/new' => 'admin#index'
|
||||||
|
get 'admin/wizards/custom/all' => 'admin#all'
|
||||||
|
get 'admin/wizards/custom/:id' => 'admin#find'
|
||||||
|
put 'admin/wizards/custom/save' => 'admin#save'
|
||||||
|
delete 'admin/wizards/custom/remove' => 'admin#remove'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
load File.expand_path('../lib/builder.rb', __FILE__)
|
|
||||||
load File.expand_path('../lib/wizard.rb', __FILE__)
|
|
||||||
load File.expand_path('../controllers/steps.rb', __FILE__)
|
|
||||||
load File.expand_path('../controllers/admin.rb', __FILE__)
|
|
||||||
end
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren