better handling of some corner cases in the filter form
This commit is contained in:
+25
-15
@@ -1,6 +1,6 @@
|
||||
local m, public, private = aux.module'search_tab'
|
||||
|
||||
function private.get_form()
|
||||
function private.get_form_query()
|
||||
local query_string = ''
|
||||
|
||||
local function add(part)
|
||||
@@ -12,7 +12,7 @@ function private.get_form()
|
||||
add(name)
|
||||
|
||||
if m.exact_checkbox:GetChecked() then
|
||||
add('exact')
|
||||
add((name == '' and '/' or '')..'exact')
|
||||
end
|
||||
|
||||
local min_level = m.blizzard_level(m.min_level_input:GetText())
|
||||
@@ -65,7 +65,9 @@ function private.set_form(components)
|
||||
end
|
||||
m.name_input:SetText(aux.filter.unquote(filter[2]))
|
||||
elseif filter[1] == 'exact' then
|
||||
m.exact_checkbox:SetChecked(true)
|
||||
if not m.exact_checkbox:GetChecked() then
|
||||
m.exact_checkbox:Click()
|
||||
end
|
||||
elseif filter[1] == 'min_level' then
|
||||
m.min_level_input:SetText(tonumber(filter[2]))
|
||||
elseif filter[1] == 'max_level' then
|
||||
@@ -94,7 +96,9 @@ end
|
||||
function private.clear_form()
|
||||
m.name_input:SetText('')
|
||||
m.name_input:ClearFocus()
|
||||
m.exact_checkbox:SetChecked(nil)
|
||||
if m.exact_checkbox:GetChecked() then
|
||||
m.exact_checkbox:Click()
|
||||
end
|
||||
m.min_level_input:SetText('')
|
||||
m.min_level_input:ClearFocus()
|
||||
m.max_level_input:SetText('')
|
||||
@@ -120,7 +124,7 @@ function private.import_query_string()
|
||||
end
|
||||
|
||||
function private.export_query_string()
|
||||
local components, error = aux.filter.parse_query_string(m.get_form())
|
||||
local components, error = aux.filter.parse_query_string(m.get_form_query())
|
||||
if components then
|
||||
m.search_box:SetText(aux.filter.query_string({blizzard=components.blizzard, post=m.post_filter}))
|
||||
m.filter_input:ClearFocus()
|
||||
@@ -312,18 +316,24 @@ function private.initialize_class_dropdown()
|
||||
end
|
||||
end
|
||||
|
||||
UIDropDownMenu_AddButton{
|
||||
text = ALL,
|
||||
value = 0,
|
||||
func = on_click,
|
||||
}
|
||||
if not m.exact_checkbox:GetChecked() then
|
||||
m.class_dropdown.button:Enable()
|
||||
|
||||
for i, class in { GetAuctionItemClasses() } do
|
||||
UIDropDownMenu_AddButton{
|
||||
text = class,
|
||||
value = i,
|
||||
text = ALL,
|
||||
value = 0,
|
||||
func = on_click,
|
||||
}
|
||||
|
||||
for i, class in { GetAuctionItemClasses() } do
|
||||
UIDropDownMenu_AddButton{
|
||||
text = class,
|
||||
value = i,
|
||||
func = on_click,
|
||||
}
|
||||
end
|
||||
else
|
||||
m.class_dropdown.button:Disable()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -340,7 +350,7 @@ function private.initialize_subclass_dropdown()
|
||||
|
||||
local class_index = UIDropDownMenu_GetSelectedValue(m.class_dropdown)
|
||||
|
||||
if class_index and GetAuctionItemSubClasses(class_index) then
|
||||
if class_index and GetAuctionItemSubClasses(class_index) and not m.exact_checkbox:GetChecked() then
|
||||
m.subclass_dropdown.button:Enable()
|
||||
|
||||
UIDropDownMenu_AddButton{
|
||||
@@ -370,7 +380,7 @@ function private.initialize_slot_dropdown()
|
||||
local class_index = UIDropDownMenu_GetSelectedValue(m.class_dropdown)
|
||||
local subclass_index = UIDropDownMenu_GetSelectedValue(m.subclass_dropdown)
|
||||
|
||||
if class_index and subclass_index and GetAuctionInvTypes(class_index, subclass_index) then
|
||||
if class_index and subclass_index and GetAuctionInvTypes(class_index, subclass_index) and not m.exact_checkbox:GetChecked() then
|
||||
m.slot_dropdown.button:Enable()
|
||||
|
||||
UIDropDownMenu_AddButton{
|
||||
|
||||
+10
-2
@@ -273,7 +273,7 @@ function private.create_frames()
|
||||
btn:SetPoint('TOPLEFT', m.saved_searches_button, 'TOPRIGHT', 5, 0)
|
||||
btn:SetWidth(243)
|
||||
btn:SetHeight(22)
|
||||
btn:SetText('New Filter')
|
||||
btn:SetText('Filter Builder')
|
||||
btn:SetScript('OnClick', function() m.update_tab(m.FILTER) end)
|
||||
private.new_filter_button = btn
|
||||
end
|
||||
@@ -381,6 +381,14 @@ function private.create_frames()
|
||||
do
|
||||
local checkbox = aux.gui.checkbox(m.frame.filter)
|
||||
checkbox:SetPoint('TOPLEFT', m.name_input, 'TOPRIGHT', 16, 0)
|
||||
checkbox:SetScript('OnClick', function()
|
||||
UIDropDownMenu_ClearAll(m.class_dropdown)
|
||||
UIDropDownMenu_Initialize(m.class_dropdown, m.initialize_class_dropdown)
|
||||
UIDropDownMenu_ClearAll(m.subclass_dropdown)
|
||||
UIDropDownMenu_Initialize(m.subclass_dropdown, m.initialize_subclass_dropdown)
|
||||
UIDropDownMenu_ClearAll(m.slot_dropdown)
|
||||
UIDropDownMenu_Initialize(m.slot_dropdown, m.initialize_slot_dropdown)
|
||||
end)
|
||||
local label = aux.gui.label(checkbox, aux.gui.config.small_font_size)
|
||||
label:SetPoint('BOTTOMLEFT', checkbox, 'TOPLEFT', -2, 1)
|
||||
label:SetText('Exact')
|
||||
@@ -434,6 +442,7 @@ function private.create_frames()
|
||||
end
|
||||
do
|
||||
local dropdown = aux.gui.dropdown(m.frame.filter)
|
||||
private.class_dropdown = dropdown
|
||||
dropdown:SetPoint('TOPLEFT', m.min_level_input, 'BOTTOMLEFT', 0, -24)
|
||||
dropdown:SetWidth(300)
|
||||
local label = aux.gui.label(dropdown, aux.gui.config.small_font_size)
|
||||
@@ -443,7 +452,6 @@ function private.create_frames()
|
||||
dropdown:SetScript('OnShow', function()
|
||||
UIDropDownMenu_Initialize(this, m.initialize_class_dropdown)
|
||||
end)
|
||||
private.class_dropdown = dropdown
|
||||
end
|
||||
do
|
||||
local dropdown = aux.gui.dropdown(m.frame.filter)
|
||||
|
||||
+13
-14
@@ -510,28 +510,27 @@ function private.suggestions(components)
|
||||
end
|
||||
|
||||
function public.query_string(components)
|
||||
local prettified = m.query_builder()
|
||||
local query_builder = m.query_builder()
|
||||
|
||||
local blizzard_filters = {}
|
||||
for _, filter in components.blizzard do
|
||||
prettified.append((filter[2] or filter[1]))
|
||||
query_builder.append((filter[2] or filter[1]))
|
||||
end
|
||||
|
||||
for _, component in components.post do
|
||||
if component[1] == 'operator' then
|
||||
prettified.append(component[2]..(component[2] ~= 'not' and tonumber(component[3]) or ''))
|
||||
query_builder.append(component[2]..(component[2] ~= 'not' and tonumber(component[3]) or ''))
|
||||
elseif component[1] == 'filter' then
|
||||
prettified.append(component[2])
|
||||
query_builder.append(component[2])
|
||||
for _, parameter in {component[3]} do
|
||||
if aux.filter.filters[component[2]].input_type == 'money' then
|
||||
parameter = aux.money.to_string(aux.money.from_string(parameter), nil, true, nil, nil, true)
|
||||
end
|
||||
prettified.append(parameter)
|
||||
query_builder.append(parameter)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return prettified.get()
|
||||
return query_builder.get()
|
||||
end
|
||||
|
||||
function private.prettified_query_string(components)
|
||||
@@ -662,23 +661,23 @@ function private.validator(components)
|
||||
end
|
||||
end
|
||||
|
||||
function public.query_builder(str)
|
||||
local filter = str or ''
|
||||
function public.query_builder()
|
||||
local filter
|
||||
return {
|
||||
appended = function(part)
|
||||
return m.query_builder(filter == '' and part or filter..'/'..part)
|
||||
return m.query_builder(not filter and part or filter..'/'..part)
|
||||
end,
|
||||
prepended = function(part)
|
||||
return m.query_builder(filter == '' and part or part..'/'..filter)
|
||||
return m.query_builder(not filter and part or part..'/'..filter)
|
||||
end,
|
||||
append = function(part)
|
||||
filter = filter == '' and part or filter..'/'..part
|
||||
filter = not filter and part or filter..'/'..part
|
||||
end,
|
||||
prepend = function(part)
|
||||
filter = filter == '' and part or part..'/'..filter
|
||||
filter = not filter and part or part..'/'..filter
|
||||
end,
|
||||
get = function()
|
||||
return filter
|
||||
return filter or ''
|
||||
end
|
||||
}
|
||||
end
|
||||
Reference in New Issue
Block a user