big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-21 06:17:53 +02:00
parent e94eaac52c
commit 40753f2ac5
31 changed files with 709 additions and 742 deletions
+41 -55
View File
@@ -1,61 +1,58 @@
aux.module 'auctions_tab'
aux.tab(3, 'Auctions')
g.aux.tab(3, 'Auctions')
auction_records = nil
function m.LOAD()
m.create_frames()
function LOAD()
create_frames()
end
function m.OPEN()
m.frame:Show()
m.scan_auctions()
function OPEN()
frame:Show()
scan_auctions()
end
function m.CLOSE()
m.frame:Hide()
function CLOSE()
frame:Hide()
end
function update_listing()
if not m:ACTIVE() then
return
end
m.listing:SetDatabase(m.auction_records)
if not ACTIVE then return end
listing:SetDatabase(auction_records)
end
function public.scan_auctions()
m.status_bar:update_status(0,0)
m.status_bar:set_text('Scanning auctions...')
status_bar:update_status(0,0)
status_bar:set_text('Scanning auctions...')
m.auction_records = {}
m.update_listing()
aux.scan.start{
auction_records = {}
update_listing()
scan.start{
type = 'owner',
queries = {{ blizzard_query = {} }},
on_page_loaded = function(page, total_pages)
m.status_bar:update_status(100 * (page - 1) / total_pages, 0)
m.status_bar:set_text(format('Scanning (Page %d / %d)', page, total_pages))
status_bar:update_status(100 * (page - 1) / total_pages, 0)
status_bar:set_text(format('Scanning (Page %d / %d)', page, total_pages))
end,
on_auction = function(auction_record)
tinsert(m.auction_records, auction_record)
tinsert(auction_records, auction_record)
end,
on_complete = function()
m.status_bar:update_status(100, 100)
m.status_bar:set_text('Scan complete')
m.update_listing()
status_bar:update_status(100, 100)
status_bar:set_text('Scan complete')
update_listing()
end,
on_abort = function()
m.status_bar:update_status(100, 100)
m.status_bar:set_text('Scan aborted')
status_bar:update_status(100, 100)
status_bar:set_text('Scan aborted')
end,
}
end
function test(record)
return function(index)
local auction_info = aux.info.auction(index, 'owner')
local auction_info = info.auction(index, 'owner')
return auction_info and auction_info.search_signature == record.search_signature
end
end
@@ -67,55 +64,44 @@ do
local found_index
function find_auction(record)
if not m.listing:ContainsRecord(record) then
return
end
if not listing:ContainsRecord(record) then return end
aux.scan.abort(scan_id)
scan.abort(scan_id)
state = SEARCHING
scan_id = aux.scan_util.find(
scan_id = scan_util.find(
record,
m.status_bar,
function()
state = IDLE
end,
function()
state = IDLE
m.listing:RemoveAuctionRecord(record)
end,
status_bar,
function() state = IDLE end,
function() state = IDLE; listing:RemoveAuctionRecord(record) end,
function(index)
state = FOUND
found_index = index
m.cancel_button:SetScript('OnClick', function()
if m.test(record)(index) and m.listing:ContainsRecord(record) then
aux.cancel_auction(index, L(m.listing.RemoveAuctionRecord, m.listing, record))
cancel_button:SetScript('OnClick', function()
if test(record)(index) and listing:ContainsRecord(record) then
cancel_auction(index, L(listing.RemoveAuctionRecord, listing, record))
end
end)
m.cancel_button:Enable()
cancel_button:Enable()
end
)
end
function on_update()
if state == IDLE or state == SEARCHING then
m.cancel_button:Disable()
cancel_button:Disable()
end
if state == SEARCHING then
return
end
if state == SEARCHING then return end
local selection = m.listing:GetSelection()
local selection = listing:GetSelection()
if not selection then
state = IDLE
elseif selection and state == IDLE then
m.find_auction(selection.record)
elseif state == FOUND and not m.test(selection.record)(found_index) then
m.cancel_button:Disable()
if not aux.cancel_in_progress() then
state = IDLE
end
find_auction(selection.record)
elseif state == FOUND and not test(selection.record)(found_index) then
cancel_button:Disable()
if not cancel_in_progress then state = IDLE end
end
end
end