FEATURE: Added a new field type Item Chooser
Dieser Commit ist enthalten in:
Ursprung
883d3e6078
Commit
1e7521f006
9 geänderte Dateien mit 87 neuen und 1 gelöschten Zeilen
36
assets/javascripts/wizard/components/item-chooser.js.es6
Normale Datei
36
assets/javascripts/wizard/components/item-chooser.js.es6
Normale Datei
|
@ -0,0 +1,36 @@
|
||||||
|
import MiniTagChooser from "select-kit/components/mini-tag-chooser";
|
||||||
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
import { observes } from "discourse-common/utils/decorators";
|
||||||
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
|
|
||||||
|
export default MiniTagChooser.extend({
|
||||||
|
searchTags(url, data, callback){
|
||||||
|
return ajax(url, {
|
||||||
|
data: {
|
||||||
|
name: data.name,
|
||||||
|
value: data.q,
|
||||||
|
}
|
||||||
|
}).then(result => callback(this, result))
|
||||||
|
.catch(popupAjaxError);
|
||||||
|
},
|
||||||
|
|
||||||
|
search(filter){
|
||||||
|
const data = {
|
||||||
|
q: filter,
|
||||||
|
name: this.get('item')
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.searchTags('/w/items/search', data, this._transformJson );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
_transformJson(obj, result){
|
||||||
|
let x = result.map(item => {
|
||||||
|
return { id: item, name: item }
|
||||||
|
})
|
||||||
|
|
||||||
|
return x ;
|
||||||
|
},
|
||||||
|
|
||||||
|
});
|
|
@ -0,0 +1,14 @@
|
||||||
|
import Component from "@ember/component";
|
||||||
|
import discourseComputed, { observes } from 'discourse-common/utils/decorators';
|
||||||
|
|
||||||
|
export default Component.extend({
|
||||||
|
@observes('value')
|
||||||
|
updateValue(){
|
||||||
|
this.set('field.value', this.value.join(','));
|
||||||
|
},
|
||||||
|
|
||||||
|
@discourseComputed('field.label')
|
||||||
|
itemName(label){
|
||||||
|
return label.replace(/(<([^>]+)>)/gi, "");
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1 @@
|
||||||
|
{{item-chooser value=value item=itemName}}
|
|
@ -171,6 +171,7 @@ en:
|
||||||
date: Date
|
date: Date
|
||||||
time: Time
|
time: Time
|
||||||
date_time: Date & Time
|
date_time: Date & Time
|
||||||
|
item_chooser: Item Chooser
|
||||||
|
|
||||||
connector:
|
connector:
|
||||||
and: "and"
|
and: "and"
|
||||||
|
|
|
@ -4,6 +4,7 @@ CustomWizard::Engine.routes.draw do
|
||||||
get ':wizard_id/steps' => 'wizard#index'
|
get ':wizard_id/steps' => 'wizard#index'
|
||||||
get ':wizard_id/steps/:step_id' => 'wizard#index'
|
get ':wizard_id/steps/:step_id' => 'wizard#index'
|
||||||
put ':wizard_id/steps/:step_id' => 'steps#update'
|
put ':wizard_id/steps/:step_id' => 'steps#update'
|
||||||
|
get 'items/search' => 'items#search'
|
||||||
end
|
end
|
||||||
|
|
||||||
Discourse::Application.routes.append do
|
Discourse::Application.routes.append do
|
||||||
|
|
12
controllers/custom_wizard/item.rb
Normale Datei
12
controllers/custom_wizard/item.rb
Normale Datei
|
@ -0,0 +1,12 @@
|
||||||
|
class CustomWizard::ItemsController < ::ApplicationController
|
||||||
|
def search
|
||||||
|
search_params = {
|
||||||
|
name: params[:name],
|
||||||
|
value: params[:value] || '',
|
||||||
|
limit: params[:limit] || 5
|
||||||
|
}
|
||||||
|
items = CustomWizard::Item.search(search_params)
|
||||||
|
|
||||||
|
render json: MultiJson.dump(items)
|
||||||
|
end
|
||||||
|
end
|
|
@ -49,7 +49,8 @@ class CustomWizard::Field
|
||||||
prefill: nil,
|
prefill: nil,
|
||||||
content: nil
|
content: nil
|
||||||
},
|
},
|
||||||
user_selector: {}
|
user_selector: {},
|
||||||
|
item_chooser: {}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
18
lib/custom_wizard/item.rb
Normale Datei
18
lib/custom_wizard/item.rb
Normale Datei
|
@ -0,0 +1,18 @@
|
||||||
|
class CustomWizard::Item
|
||||||
|
WIZARD_ITEM = 'wizard_item'.freeze
|
||||||
|
|
||||||
|
def initialize(name, value)
|
||||||
|
@name = name
|
||||||
|
@value = value
|
||||||
|
end
|
||||||
|
|
||||||
|
def save
|
||||||
|
PluginStore.set(WIZARD_ITEM, @name, @value)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.search(params)
|
||||||
|
items = PluginStore.get(WIZARD_ITEM, params[:name])
|
||||||
|
items ? items.filter{ |string| string.downcase.include?(params[:value].downcase) }.take(params[:limit] || 5)
|
||||||
|
: []
|
||||||
|
end
|
||||||
|
end
|
|
@ -53,6 +53,7 @@ after_initialize do
|
||||||
../controllers/custom_wizard/wizard.rb
|
../controllers/custom_wizard/wizard.rb
|
||||||
../controllers/custom_wizard/steps.rb
|
../controllers/custom_wizard/steps.rb
|
||||||
../controllers/custom_wizard/transfer.rb
|
../controllers/custom_wizard/transfer.rb
|
||||||
|
../controllers/custom_wizard/item.rb
|
||||||
../jobs/clear_after_time_wizard.rb
|
../jobs/clear_after_time_wizard.rb
|
||||||
../jobs/refresh_api_access_token.rb
|
../jobs/refresh_api_access_token.rb
|
||||||
../jobs/set_after_time_wizard.rb
|
../jobs/set_after_time_wizard.rb
|
||||||
|
@ -61,6 +62,7 @@ after_initialize do
|
||||||
../lib/custom_wizard/builder.rb
|
../lib/custom_wizard/builder.rb
|
||||||
../lib/custom_wizard/field.rb
|
../lib/custom_wizard/field.rb
|
||||||
../lib/custom_wizard/mapper.rb
|
../lib/custom_wizard/mapper.rb
|
||||||
|
../lib/custom_wizard/item.rb
|
||||||
../lib/custom_wizard/log.rb
|
../lib/custom_wizard/log.rb
|
||||||
../lib/custom_wizard/step_updater.rb
|
../lib/custom_wizard/step_updater.rb
|
||||||
../lib/custom_wizard/validator.rb
|
../lib/custom_wizard/validator.rb
|
||||||
|
|
Laden …
In neuem Issue referenzieren