Commits vergleichen
3 Commits
main
...
item-choos
Autor | SHA1 | Datum | |
---|---|---|---|
|
1e7521f006 | ||
|
883d3e6078 | ||
|
aca36ee24c |
10 geänderte Dateien mit 88 neuen und 1 gelöschten Zeilen
|
@ -95,6 +95,7 @@
|
|||
//= require discourse/app/components/date-time-input
|
||||
//= require discourse/app/components/text-field
|
||||
//= require discourse/app/components/d-textarea
|
||||
//= require discourse/app/components/topic-list
|
||||
|
||||
//= require discourse/app/templates/components/conditional-loading-spinner
|
||||
//= require discourse/app/templates/components/d-button
|
||||
|
|
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
|
||||
time: Time
|
||||
date_time: Date & Time
|
||||
item_chooser: Item Chooser
|
||||
|
||||
connector:
|
||||
and: "and"
|
||||
|
|
|
@ -4,6 +4,7 @@ CustomWizard::Engine.routes.draw do
|
|||
get ':wizard_id/steps' => 'wizard#index'
|
||||
get ':wizard_id/steps/:step_id' => 'wizard#index'
|
||||
put ':wizard_id/steps/:step_id' => 'steps#update'
|
||||
get 'items/search' => 'items#search'
|
||||
end
|
||||
|
||||
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,
|
||||
content: nil
|
||||
},
|
||||
user_selector: {}
|
||||
user_selector: {},
|
||||
item_chooser: {}
|
||||
}
|
||||
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/steps.rb
|
||||
../controllers/custom_wizard/transfer.rb
|
||||
../controllers/custom_wizard/item.rb
|
||||
../jobs/clear_after_time_wizard.rb
|
||||
../jobs/refresh_api_access_token.rb
|
||||
../jobs/set_after_time_wizard.rb
|
||||
|
@ -61,6 +62,7 @@ after_initialize do
|
|||
../lib/custom_wizard/builder.rb
|
||||
../lib/custom_wizard/field.rb
|
||||
../lib/custom_wizard/mapper.rb
|
||||
../lib/custom_wizard/item.rb
|
||||
../lib/custom_wizard/log.rb
|
||||
../lib/custom_wizard/step_updater.rb
|
||||
../lib/custom_wizard/validator.rb
|
||||
|
|
Laden …
In neuem Issue referenzieren