initial commit
This commit is contained in:
266
Core/UI/MainUI/Ledger/Common/Auctions.lua
Normal file
266
Core/UI/MainUI/Ledger/Common/Auctions.lua
Normal file
@@ -0,0 +1,266 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local Auctions = TSM.MainUI.Ledger.Common:NewPackage("Auctions")
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
local Table = TSM.Include("Util.Table")
|
||||
local String = TSM.Include("Util.String")
|
||||
local Theme = TSM.Include("Util.Theme")
|
||||
local ItemInfo = TSM.Include("Service.ItemInfo")
|
||||
local Settings = TSM.Include("Service.Settings")
|
||||
local UIElements = TSM.Include("UI.UIElements")
|
||||
local SECONDS_PER_DAY = 24 * 60 * 60
|
||||
local private = {
|
||||
settings = nil,
|
||||
query = nil,
|
||||
characters = {},
|
||||
characterFilter = {},
|
||||
searchFilter = "",
|
||||
groupFilter = {},
|
||||
rarityList = {},
|
||||
rarityFilter = {},
|
||||
timeFrameFilter = 30 * SECONDS_PER_DAY,
|
||||
type = nil
|
||||
}
|
||||
do
|
||||
for i = 1, 4 do
|
||||
tinsert(private.rarityList, _G[format("ITEM_QUALITY%d_DESC", i)])
|
||||
private.rarityFilter[i] = true
|
||||
end
|
||||
end
|
||||
local TIME_LIST = { L["All Time"], L["Last 3 Days"], L["Last 7 Days"], L["Last 14 Days"], L["Last 30 Days"], L["Last 60 Days"] }
|
||||
local TIME_KEYS = { 0, 3 * SECONDS_PER_DAY, 7 * SECONDS_PER_DAY, 14 * SECONDS_PER_DAY, 30 * SECONDS_PER_DAY, 60 * SECONDS_PER_DAY }
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Module Functions
|
||||
-- ============================================================================
|
||||
|
||||
function Auctions.OnInitialize()
|
||||
private.settings = Settings.NewView()
|
||||
:AddKey("global", "mainUIContext", "ledgerAuctionsScrollingTable")
|
||||
TSM.MainUI.Ledger.FailedAuctions.RegisterPage(L["Expired"], private.DrawExpiredPage)
|
||||
TSM.MainUI.Ledger.FailedAuctions.RegisterPage(L["Cancelled"], private.DrawCancelledPage)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Auctions UIs
|
||||
-- ============================================================================
|
||||
|
||||
function private.DrawExpiredPage()
|
||||
TSM.UI.AnalyticsRecordPathChange("main", "ledger", "failed_auctions", "expired")
|
||||
private.type = "expire"
|
||||
return private.DrawAuctionsPage()
|
||||
end
|
||||
|
||||
function private.DrawCancelledPage()
|
||||
TSM.UI.AnalyticsRecordPathChange("main", "ledger", "failed_auctions", "cancelled")
|
||||
private.type = "cancel"
|
||||
return private.DrawAuctionsPage()
|
||||
end
|
||||
|
||||
function private.DrawAuctionsPage()
|
||||
private.query = private.query or TSM.Accounting.Auctions.CreateQuery()
|
||||
|
||||
private.query:Reset()
|
||||
:Equal("type", "cancel")
|
||||
:Distinct("player")
|
||||
:Select("player")
|
||||
wipe(private.characters)
|
||||
for _, character in private.query:Iterator() do
|
||||
tinsert(private.characters, character)
|
||||
private.characterFilter[character] = true
|
||||
end
|
||||
|
||||
private.query:Reset()
|
||||
:InnerJoin(ItemInfo.GetDBForJoin(), "itemString")
|
||||
:LeftJoin(TSM.Groups.GetItemDBForJoin(), "itemString")
|
||||
:OrderBy("time", false)
|
||||
private.UpdateQuery()
|
||||
|
||||
return UIElements.New("Frame", "content")
|
||||
:SetLayout("VERTICAL")
|
||||
:AddChild(UIElements.New("Frame", "row1")
|
||||
:SetLayout("HORIZONTAL")
|
||||
:SetHeight(24)
|
||||
:SetMargin(8)
|
||||
:AddChild(UIElements.New("Input", "filter")
|
||||
:SetMargin(0, 8, 0, 0)
|
||||
:SetIconTexture("iconPack.18x18/Search")
|
||||
:SetClearButtonEnabled(true)
|
||||
:AllowItemInsert()
|
||||
:SetHintText(L["Filter by keyword"])
|
||||
:SetValue(private.searchFilter)
|
||||
:SetScript("OnValueChanged", private.SearchFilterChanged)
|
||||
)
|
||||
:AddChild(UIElements.New("GroupSelector", "group")
|
||||
:SetWidth(240)
|
||||
:SetHintText(L["Filter by groups"])
|
||||
:SetScript("OnSelectionChanged", private.GroupFilterChanged)
|
||||
)
|
||||
)
|
||||
:AddChild(UIElements.New("Frame", "row2")
|
||||
:SetLayout("HORIZONTAL")
|
||||
:SetHeight(24)
|
||||
:SetMargin(8, 8, 0, 8)
|
||||
:AddChild(UIElements.New("MultiselectionDropdown", "rarity")
|
||||
:SetMargin(0, 8, 0, 0)
|
||||
:SetItems(private.rarityList)
|
||||
:SetSettingInfo(private, "rarityFilter")
|
||||
:SetSelectionText(L["No Rarities"], L["%d Rarities"], L["All Rarites"])
|
||||
:SetScript("OnSelectionChanged", private.DropdownCommonOnSelectionChanged)
|
||||
)
|
||||
:AddChild(UIElements.New("MultiselectionDropdown", "character")
|
||||
:SetMargin(0, 8, 0, 0)
|
||||
:SetItems(private.characters, private.characters)
|
||||
:SetSettingInfo(private, "characterFilter")
|
||||
:SetSelectionText(L["No Characters"], L["%d Characters"], L["All Characters"])
|
||||
:SetScript("OnSelectionChanged", private.DropdownCommonOnSelectionChanged)
|
||||
)
|
||||
:AddChild(UIElements.New("SelectionDropdown", "time")
|
||||
:SetItems(TIME_LIST, TIME_KEYS)
|
||||
:SetSelectedItemByKey(private.timeFrameFilter)
|
||||
:SetSettingInfo(private, "timeFrameFilter")
|
||||
:SetScript("OnSelectionChanged", private.DropdownCommonOnSelectionChanged)
|
||||
)
|
||||
)
|
||||
:AddChild(UIElements.New("QueryScrollingTable", "scrollingTable")
|
||||
:SetSettingsContext(private.settings, "ledgerAuctionsScrollingTable")
|
||||
:GetScrollingTableInfo()
|
||||
:NewColumn("item")
|
||||
:SetTitle(L["Item"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("LEFT")
|
||||
:SetTextInfo("itemString", TSM.UI.GetColoredItemName)
|
||||
:SetTooltipInfo("itemString")
|
||||
:SetSortInfo("name")
|
||||
:DisableHiding()
|
||||
:Commit()
|
||||
:NewColumn("player")
|
||||
:SetTitle(PLAYER)
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("LEFT")
|
||||
:SetTextInfo("player")
|
||||
:SetSortInfo("player")
|
||||
:Commit()
|
||||
:NewColumn("stackSize")
|
||||
:SetTitle(L["Stack"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("RIGHT")
|
||||
:SetTextInfo("stackSize")
|
||||
:SetSortInfo("stackSize")
|
||||
:Commit()
|
||||
:NewColumn("quantity")
|
||||
:SetTitle(L["Auctions"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("RIGHT")
|
||||
:SetTextInfo(nil, private.FormatAuctions)
|
||||
:SetSortInfo("quantity")
|
||||
:Commit()
|
||||
:NewColumn("time")
|
||||
:SetTitle(L["Time Frame"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("RIGHT")
|
||||
:SetTextInfo("time", private.TableGetTimeframeText)
|
||||
:SetSortInfo("time")
|
||||
:Commit()
|
||||
:Commit()
|
||||
:SetQuery(private.query)
|
||||
:SetScript("OnRowClick", private.TableSelectionChanged)
|
||||
)
|
||||
:AddChild(UIElements.New("Texture", "line")
|
||||
:SetHeight(2)
|
||||
:SetTexture("ACTIVE_BG")
|
||||
)
|
||||
:AddChild(UIElements.New("Frame", "footer")
|
||||
:SetLayout("HORIZONTAL")
|
||||
:SetHeight(40)
|
||||
:SetPadding(8)
|
||||
:SetBackgroundColor("PRIMARY_BG")
|
||||
:AddChild(UIElements.New("Text", "num")
|
||||
:SetWidth("AUTO")
|
||||
:SetFont("BODY_BODY2_MEDIUM")
|
||||
:SetText(format(private.type == "expire" and L["%s Items Expired"] or L["%s Items Cancelled"], Theme.GetColor("INDICATOR"):ColorText(FormatLargeNumber(private.query:Sum("quantity") or 0))))
|
||||
)
|
||||
:AddChild(UIElements.New("Spacer", "spacer"))
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Scrolling Table Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.TableGetTimeframeText(record)
|
||||
return SecondsToTime(time() - record)
|
||||
end
|
||||
|
||||
function private.FormatAuctions(row)
|
||||
return row:GetField("quantity") / row:GetField("stackSize")
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Local Script Handlers
|
||||
-- ============================================================================
|
||||
|
||||
function private.DropdownCommonOnSelectionChanged(dropdown)
|
||||
private.UpdateQuery()
|
||||
dropdown:GetElement("__parent.__parent.scrollingTable")
|
||||
:UpdateData(true)
|
||||
local footer = dropdown:GetElement("__parent.__parent.footer")
|
||||
footer:GetElement("num"):SetText(format(private.type == "expire" and L["%s Items Expired"] or L["%s Items Cancelled"], Theme.GetColor("INDICATOR"):ColorText(FormatLargeNumber(private.query:Sum("quantity") or 0))))
|
||||
footer:Draw()
|
||||
end
|
||||
|
||||
function private.SearchFilterChanged(input)
|
||||
private.searchFilter = input:GetValue()
|
||||
private.DropdownCommonOnSelectionChanged(input)
|
||||
end
|
||||
|
||||
function private.GroupFilterChanged(groupSelector)
|
||||
wipe(private.groupFilter)
|
||||
for groupPath in groupSelector:SelectedGroupIterator() do
|
||||
private.groupFilter[groupPath] = true
|
||||
end
|
||||
private.DropdownCommonOnSelectionChanged(groupSelector)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.UpdateQuery()
|
||||
private.query:ResetFilters()
|
||||
:Equal("type", private.type)
|
||||
if private.searchFilter ~= "" then
|
||||
private.query:Matches("name", String.Escape(private.searchFilter))
|
||||
end
|
||||
if Table.Count(private.rarityFilter) ~= #private.rarityList then
|
||||
private.query:InTable("quality", private.rarityFilter)
|
||||
end
|
||||
if Table.Count(private.characterFilter) ~= #private.characters then
|
||||
private.query:InTable("player", private.characterFilter)
|
||||
end
|
||||
if private.timeFrameFilter ~= 0 then
|
||||
private.query:GreaterThanOrEqual("time", time() - private.timeFrameFilter)
|
||||
end
|
||||
if next(private.groupFilter) then
|
||||
private.query:InTable("groupPath", private.groupFilter)
|
||||
end
|
||||
end
|
||||
|
||||
function private.TableSelectionChanged(scrollingTable, row)
|
||||
TSM.MainUI.Ledger.ShowItemDetail(scrollingTable:GetParentElement():GetParentElement(), row:GetField("itemString"), "sale")
|
||||
end
|
||||
8
Core/UI/MainUI/Ledger/Common/Core.lua
Normal file
8
Core/UI/MainUI/Ledger/Common/Core.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
TSM.MainUI.Ledger:NewPackage("Common")
|
||||
208
Core/UI/MainUI/Ledger/Common/Other.lua
Normal file
208
Core/UI/MainUI/Ledger/Common/Other.lua
Normal file
@@ -0,0 +1,208 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local Other = TSM.MainUI.Ledger.Common:NewPackage("Other")
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
local Table = TSM.Include("Util.Table")
|
||||
local Money = TSM.Include("Util.Money")
|
||||
local Settings = TSM.Include("Service.Settings")
|
||||
local UIElements = TSM.Include("UI.UIElements")
|
||||
local SECONDS_PER_DAY = 24 * 60 * 60
|
||||
local private = {
|
||||
settings = nil,
|
||||
query = nil,
|
||||
characters = {},
|
||||
characterFilter = {},
|
||||
typeFilter = {},
|
||||
recordType = nil,
|
||||
timeFrameFilter = 30 * SECONDS_PER_DAY,
|
||||
}
|
||||
local TIME_LIST = { L["All Time"], L["Last 3 Days"], L["Last 7 Days"], L["Last 14 Days"], L["Last 30 Days"], L["Last 60 Days"] }
|
||||
local TIME_KEYS = { 0, 3 * SECONDS_PER_DAY, 7 * SECONDS_PER_DAY, 14 * SECONDS_PER_DAY, 30 * SECONDS_PER_DAY, 60 * SECONDS_PER_DAY }
|
||||
local TYPE_LIST = {
|
||||
expense = { L["Money Transfer"], L["Postage"], L["Repair Bill"] },
|
||||
income = { L["Money Transfer"], L["Garrison"] },
|
||||
}
|
||||
local TYPE_KEYS = {
|
||||
expense = { "Money Transfer", "Postage", "Repair Bill" },
|
||||
income = { "Money Transfer", "Garrison" },
|
||||
}
|
||||
local TYPE_STR_LOOKUP = {}
|
||||
do
|
||||
-- populate lookup table
|
||||
assert(#TYPE_LIST.expense == #TYPE_KEYS.expense)
|
||||
for i = 1, #TYPE_LIST.expense do
|
||||
TYPE_STR_LOOKUP[TYPE_KEYS.expense[i]] = TYPE_LIST.expense[i]
|
||||
end
|
||||
assert(#TYPE_LIST.income == #TYPE_KEYS.income)
|
||||
for i = 1, #TYPE_LIST.income do
|
||||
TYPE_STR_LOOKUP[TYPE_KEYS.income[i]] = TYPE_LIST.income[i]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Module Functions
|
||||
-- ============================================================================
|
||||
|
||||
function Other.OnInitialize()
|
||||
private.settings = Settings.NewView()
|
||||
:AddKey("global", "mainUIContext", "ledgerOtherScrollingTable")
|
||||
TSM.MainUI.Ledger.Expenses.RegisterPage(OTHER, private.DrawOtherExpensesPage)
|
||||
TSM.MainUI.Ledger.Revenue.RegisterPage(OTHER, private.DrawOtherRevenuePage)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Other UIs
|
||||
-- ============================================================================
|
||||
|
||||
function private.DrawOtherExpensesPage()
|
||||
TSM.UI.AnalyticsRecordPathChange("main", "ledger", "expenses", "other")
|
||||
return private.DrawOtherPage("expense")
|
||||
end
|
||||
|
||||
function private.DrawOtherRevenuePage()
|
||||
TSM.UI.AnalyticsRecordPathChange("main", "ledger", "revenue", "other")
|
||||
return private.DrawOtherPage("income")
|
||||
end
|
||||
|
||||
function private.DrawOtherPage(recordType)
|
||||
wipe(private.characters)
|
||||
for _, character in TSM.Accounting.Money.CharacterIterator(recordType) do
|
||||
tinsert(private.characters, character)
|
||||
private.characterFilter[character] = true
|
||||
end
|
||||
wipe(private.typeFilter)
|
||||
for _, key in ipairs(TYPE_KEYS[recordType]) do
|
||||
private.typeFilter[key] = true
|
||||
end
|
||||
|
||||
if not private.query then
|
||||
private.query = TSM.Accounting.Money.CreateQuery()
|
||||
:OrderBy("time", false)
|
||||
end
|
||||
private.recordType = recordType
|
||||
private.UpdateQuery()
|
||||
|
||||
return UIElements.New("Frame", "content")
|
||||
:SetLayout("VERTICAL")
|
||||
:AddChild(UIElements.New("Frame", "row2")
|
||||
:SetLayout("HORIZONTAL")
|
||||
:SetHeight(24)
|
||||
:SetMargin(8)
|
||||
:AddChild(UIElements.New("MultiselectionDropdown", "type")
|
||||
:SetMargin(0, 8, 0, 0)
|
||||
:SetItems(TYPE_LIST[recordType], TYPE_KEYS[recordType])
|
||||
:SetSettingInfo(private, "typeFilter")
|
||||
:SetSelectionText(L["No Types"], L["%d Types"], L["All Types"])
|
||||
:SetScript("OnSelectionChanged", private.DropdownChangedCommon)
|
||||
)
|
||||
:AddChild(UIElements.New("MultiselectionDropdown", "character")
|
||||
:SetMargin(0, 8, 0, 0)
|
||||
:SetItems(private.characters, private.characters)
|
||||
:SetSettingInfo(private, "characterFilter")
|
||||
:SetSelectionText(L["No Characters"], L["%d Characters"], L["All Characters"])
|
||||
:SetScript("OnSelectionChanged", private.DropdownChangedCommon)
|
||||
)
|
||||
:AddChild(UIElements.New("SelectionDropdown", "time")
|
||||
:SetItems(TIME_LIST, TIME_KEYS)
|
||||
:SetSelectedItemByKey(private.timeFrameFilter)
|
||||
:SetSettingInfo(private, "timeFrameFilter")
|
||||
:SetScript("OnSelectionChanged", private.DropdownChangedCommon)
|
||||
)
|
||||
)
|
||||
:AddChild(UIElements.New("QueryScrollingTable", "table")
|
||||
:SetSettingsContext(private.settings, "ledgerOtherScrollingTable")
|
||||
:GetScrollingTableInfo()
|
||||
:NewColumn("type")
|
||||
:SetTitle(L["Type"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("LEFT")
|
||||
:SetTextInfo("type", private.TableGetTypeText)
|
||||
:SetSortInfo("type")
|
||||
:Commit()
|
||||
:NewColumn("character")
|
||||
:SetTitle(L["Character"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("LEFT")
|
||||
:SetTextInfo("player")
|
||||
:SetSortInfo("player")
|
||||
:Commit()
|
||||
:NewColumn("otherCharacter")
|
||||
:SetTitle(L["Other Character"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("LEFT")
|
||||
:SetTextInfo("otherPlayer")
|
||||
:SetSortInfo("otherPlayer")
|
||||
:Commit()
|
||||
:NewColumn("amount")
|
||||
:SetTitle(L["Amount"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("RIGHT")
|
||||
:SetTextInfo("amount", Money.ToString)
|
||||
:SetSortInfo("amount")
|
||||
:Commit()
|
||||
:NewColumn("time")
|
||||
:SetTitle(L["Time Frame"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("LEFT")
|
||||
:SetTextInfo("time", private.TableGetTimeText)
|
||||
:SetSortInfo("time")
|
||||
:Commit()
|
||||
:Commit()
|
||||
:SetQuery(private.query)
|
||||
:SetSelectionDisabled(true)
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Scrolling Table Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.TableGetTypeText(typeValue)
|
||||
return TYPE_STR_LOOKUP[typeValue]
|
||||
end
|
||||
|
||||
function private.TableGetTimeText(timevalue)
|
||||
return SecondsToTime(time() - timevalue)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Local Script Handlers
|
||||
-- ============================================================================
|
||||
|
||||
function private.DropdownChangedCommon(dropdown)
|
||||
private.UpdateQuery()
|
||||
dropdown:GetElement("__parent.__parent.table"):UpdateData(true)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.UpdateQuery()
|
||||
private.query:ResetFilters()
|
||||
:Equal("recordType", private.recordType)
|
||||
if Table.Count(private.typeFilter) ~= #TYPE_KEYS[private.recordType] then
|
||||
private.query:InTable("type", private.typeFilter)
|
||||
end
|
||||
if Table.Count(private.characterFilter) ~= #private.characters then
|
||||
private.query:InTable("player", private.characterFilter)
|
||||
end
|
||||
if private.timeFrameFilter ~= 0 then
|
||||
private.query:GreaterThan("time", time() - private.timeFrameFilter)
|
||||
end
|
||||
end
|
||||
329
Core/UI/MainUI/Ledger/Common/Transactions.lua
Normal file
329
Core/UI/MainUI/Ledger/Common/Transactions.lua
Normal file
@@ -0,0 +1,329 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local Transactions = TSM.MainUI.Ledger.Common:NewPackage("Transactions")
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
local Money = TSM.Include("Util.Money")
|
||||
local String = TSM.Include("Util.String")
|
||||
local Table = TSM.Include("Util.Table")
|
||||
local Theme = TSM.Include("Util.Theme")
|
||||
local ItemInfo = TSM.Include("Service.ItemInfo")
|
||||
local Settings = TSM.Include("Service.Settings")
|
||||
local UIElements = TSM.Include("UI.UIElements")
|
||||
local SECONDS_PER_DAY = 24 * 60 * 60
|
||||
local private = {
|
||||
settings = nil,
|
||||
query = nil,
|
||||
characters = {},
|
||||
characterFilter = {},
|
||||
typeFilter = {},
|
||||
searchFilter = "",
|
||||
groupFilter = {},
|
||||
rarityList = {},
|
||||
rarityFilter = {},
|
||||
timeFrameFilter = 30 * SECONDS_PER_DAY,
|
||||
type = nil
|
||||
}
|
||||
local TYPE_LIST = { L["Auction"], COD, TRADE, L["Vendor"] }
|
||||
local TYPE_KEYS = { "Auction", "COD", "Trade", "Vendor" }
|
||||
do
|
||||
for _, key in ipairs(TYPE_KEYS) do
|
||||
private.typeFilter[key] = true
|
||||
end
|
||||
for i = 1, 4 do
|
||||
tinsert(private.rarityList, _G[format("ITEM_QUALITY%d_DESC", i)])
|
||||
private.rarityFilter[i] = true
|
||||
end
|
||||
end
|
||||
local TIME_LIST = { L["All Time"], L["Last 3 Days"], L["Last 7 Days"], L["Last 14 Days"], L["Last 30 Days"], L["Last 60 Days"] }
|
||||
local TIME_KEYS = { 0, 3 * SECONDS_PER_DAY, 7 * SECONDS_PER_DAY, 14 * SECONDS_PER_DAY, 30 * SECONDS_PER_DAY, 60 * SECONDS_PER_DAY }
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Module Functions
|
||||
-- ============================================================================
|
||||
|
||||
function Transactions.OnInitialize()
|
||||
private.settings = Settings.NewView()
|
||||
:AddKey("global", "mainUIContext", "ledgerTransactionsScrollingTable")
|
||||
TSM.MainUI.Ledger.Expenses.RegisterPage(L["Purchases"], private.DrawPurchasesPage)
|
||||
TSM.MainUI.Ledger.Revenue.RegisterPage(L["Sales"], private.DrawSalesPage)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Transactions UIs
|
||||
-- ============================================================================
|
||||
|
||||
function private.DrawPurchasesPage()
|
||||
TSM.UI.AnalyticsRecordPathChange("main", "ledger", "expenses", "purchases")
|
||||
private.type = "buy"
|
||||
return private.DrawTransactionPage()
|
||||
end
|
||||
|
||||
function private.DrawSalesPage()
|
||||
TSM.UI.AnalyticsRecordPathChange("main", "ledger", "revenue", "sales")
|
||||
private.type = "sale"
|
||||
return private.DrawTransactionPage()
|
||||
end
|
||||
|
||||
function private.DrawTransactionPage()
|
||||
private.query = private.query or TSM.Accounting.Transactions.CreateQuery()
|
||||
|
||||
private.query:Reset()
|
||||
:Equal("type", private.type)
|
||||
:Distinct("player")
|
||||
:Select("player")
|
||||
wipe(private.characters)
|
||||
for _, character in private.query:Iterator() do
|
||||
tinsert(private.characters, character)
|
||||
private.characterFilter[character] = true
|
||||
end
|
||||
|
||||
private.query:Reset()
|
||||
:InnerJoin(ItemInfo.GetDBForJoin(), "itemString")
|
||||
:LeftJoin(TSM.Groups.GetItemDBForJoin(), "itemString")
|
||||
:VirtualField("total", "number", private.GetTotal)
|
||||
:VirtualField("auctions", "number", private.GetAuctions)
|
||||
:OrderBy("time", false)
|
||||
private.UpdateQuery()
|
||||
local numItems = private.query:Sum("quantity") or 0
|
||||
local total = private.query:Sum("total") or 0
|
||||
|
||||
return UIElements.New("Frame", "content")
|
||||
:SetLayout("VERTICAL")
|
||||
:AddChild(UIElements.New("Frame", "row1")
|
||||
:SetLayout("HORIZONTAL")
|
||||
:SetHeight(24)
|
||||
:SetMargin(8)
|
||||
:AddChild(UIElements.New("Input", "filter")
|
||||
:SetMargin(0, 8, 0, 0)
|
||||
:SetIconTexture("iconPack.18x18/Search")
|
||||
:SetClearButtonEnabled(true)
|
||||
:AllowItemInsert()
|
||||
:SetHintText(L["Filter by keyword"])
|
||||
:SetValue(private.searchFilter)
|
||||
:SetScript("OnValueChanged", private.SearchFilterChanged)
|
||||
)
|
||||
:AddChild(UIElements.New("GroupSelector", "group")
|
||||
:SetWidth(240)
|
||||
:SetHintText(L["Filter by groups"])
|
||||
:SetScript("OnSelectionChanged", private.GroupFilterChanged)
|
||||
)
|
||||
)
|
||||
:AddChild(UIElements.New("Frame", "row2")
|
||||
:SetLayout("HORIZONTAL")
|
||||
:SetHeight(24)
|
||||
:SetMargin(8, 8, 0, 8)
|
||||
:AddChild(UIElements.New("MultiselectionDropdown", "type")
|
||||
:SetMargin(0, 8, 0, 0)
|
||||
:SetItems(TYPE_LIST, TYPE_KEYS)
|
||||
:SetSettingInfo(private, "typeFilter")
|
||||
:SetSelectionText(L["No Types"], L["%d Types"], L["All Types"])
|
||||
:SetScript("OnSelectionChanged", private.DropdownCommonOnSelectionChanged)
|
||||
)
|
||||
:AddChild(UIElements.New("MultiselectionDropdown", "rarity")
|
||||
:SetMargin(0, 8, 0, 0)
|
||||
:SetItems(private.rarityList)
|
||||
:SetSettingInfo(private, "rarityFilter")
|
||||
:SetSelectionText(L["No Rarities"], L["%d Rarities"], L["All Rarities"])
|
||||
:SetScript("OnSelectionChanged", private.DropdownCommonOnSelectionChanged)
|
||||
)
|
||||
:AddChild(UIElements.New("MultiselectionDropdown", "character")
|
||||
:SetMargin(0, 8, 0, 0)
|
||||
:SetItems(private.characters, private.characters)
|
||||
:SetSettingInfo(private, "characterFilter")
|
||||
:SetSelectionText(L["No Characters"], L["%d Characters"], L["All Characters"])
|
||||
:SetScript("OnSelectionChanged", private.DropdownCommonOnSelectionChanged)
|
||||
)
|
||||
:AddChild(UIElements.New("SelectionDropdown", "time")
|
||||
:SetItems(TIME_LIST, TIME_KEYS)
|
||||
:SetSelectedItemByKey(private.timeFrameFilter)
|
||||
:SetSettingInfo(private, "timeFrameFilter")
|
||||
:SetScript("OnSelectionChanged", private.DropdownCommonOnSelectionChanged)
|
||||
)
|
||||
)
|
||||
:AddChild(UIElements.New("QueryScrollingTable", "scrollingTable")
|
||||
:SetSettingsContext(private.settings, "ledgerTransactionsScrollingTable")
|
||||
:GetScrollingTableInfo()
|
||||
:NewColumn("item")
|
||||
:SetTitle(L["Item"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("LEFT")
|
||||
:SetTextInfo("itemString", TSM.UI.GetColoredItemName)
|
||||
:SetTooltipInfo("itemString")
|
||||
:SetSortInfo("name")
|
||||
:DisableHiding()
|
||||
:Commit()
|
||||
:NewColumn("player")
|
||||
:SetTitle(PLAYER)
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("LEFT")
|
||||
:SetTextInfo("otherPlayer")
|
||||
:SetSortInfo("otherPlayer")
|
||||
:Commit()
|
||||
:NewColumn("type")
|
||||
:SetTitle(L["Type"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("LEFT")
|
||||
:SetTextInfo("source")
|
||||
:SetSortInfo("source")
|
||||
:Commit()
|
||||
:NewColumn("stack")
|
||||
:SetTitle(L["Stack"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("RIGHT")
|
||||
:SetTextInfo("stackSize")
|
||||
:SetSortInfo("stackSize")
|
||||
:Commit()
|
||||
:NewColumn("auctions")
|
||||
:SetTitle(L["Auctions"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("RIGHT")
|
||||
:SetTextInfo("auctions")
|
||||
:SetSortInfo("auctions")
|
||||
:Commit()
|
||||
:NewColumn("perItem")
|
||||
:SetTitle(L["Per Item"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("RIGHT")
|
||||
:SetTextInfo("price", private.TableGetPriceText)
|
||||
:SetSortInfo("price")
|
||||
:Commit()
|
||||
:NewColumn("total")
|
||||
:SetTitle(L["Total"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("RIGHT")
|
||||
:SetTextInfo("total", private.TableGetPriceText)
|
||||
:SetSortInfo("total")
|
||||
:Commit()
|
||||
:NewColumn("time")
|
||||
:SetTitle(L["Time Frame"])
|
||||
:SetFont("ITEM_BODY3")
|
||||
:SetJustifyH("RIGHT")
|
||||
:SetTextInfo("time", private.TableGetTimeframeText)
|
||||
:SetSortInfo("time")
|
||||
:Commit()
|
||||
:Commit()
|
||||
:SetQuery(private.query)
|
||||
:SetScript("OnRowClick", private.TableSelectionChanged)
|
||||
)
|
||||
:AddChild(UIElements.New("Texture", "line")
|
||||
:SetHeight(2)
|
||||
:SetTexture("ACTIVE_BG")
|
||||
)
|
||||
:AddChild(UIElements.New("Frame", "footer")
|
||||
:SetLayout("HORIZONTAL")
|
||||
:SetHeight(40)
|
||||
:SetPadding(8)
|
||||
:SetBackgroundColor("PRIMARY_BG")
|
||||
:AddChild(UIElements.New("Text", "num")
|
||||
:SetWidth("AUTO")
|
||||
:SetFont("BODY_BODY2_MEDIUM")
|
||||
:SetText(format(private.type == "sale" and L["%s Items Sold"] or L["%s Items Bought"], Theme.GetColor("INDICATOR"):ColorText(FormatLargeNumber(numItems))))
|
||||
)
|
||||
:AddChild(UIElements.New("Texture", "line")
|
||||
:SetMargin(4, 8, 0, 0)
|
||||
:SetWidth(2)
|
||||
:SetTexture("ACTIVE_BG")
|
||||
)
|
||||
:AddChild(UIElements.New("Text", "profit")
|
||||
:SetWidth("AUTO")
|
||||
:SetFont("BODY_BODY2_MEDIUM")
|
||||
:SetText(format(L["%s Total"], Money.ToString(total)))
|
||||
)
|
||||
:AddChild(UIElements.New("Spacer", "spacer"))
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Scrolling Table Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.TableGetPriceText(price)
|
||||
return Money.ToString(price)
|
||||
end
|
||||
|
||||
function private.TableGetTimeframeText(record)
|
||||
return SecondsToTime(time() - record)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Local Script Handlers
|
||||
-- ============================================================================
|
||||
|
||||
function private.DropdownCommonOnSelectionChanged(dropdown)
|
||||
private.UpdateQuery()
|
||||
local numItems = private.query:Sum("quantity") or 0
|
||||
local total = private.query:Sum("total") or 0
|
||||
dropdown:GetElement("__parent.__parent.scrollingTable")
|
||||
:UpdateData(true)
|
||||
local footer = dropdown:GetElement("__parent.__parent.footer")
|
||||
footer:GetElement("num"):SetText(format(private.type == "sale" and L["%s Items Sold"] or L["%s Items Bought"], Theme.GetColor("INDICATOR"):ColorText(FormatLargeNumber(numItems))))
|
||||
footer:GetElement("profit"):SetText(format(L["%s Total"], Money.ToString(total)))
|
||||
footer:Draw()
|
||||
end
|
||||
|
||||
function private.SearchFilterChanged(input)
|
||||
private.searchFilter = input:GetValue()
|
||||
private.DropdownCommonOnSelectionChanged(input)
|
||||
end
|
||||
|
||||
function private.GroupFilterChanged(groupSelector)
|
||||
wipe(private.groupFilter)
|
||||
for groupPath in groupSelector:SelectedGroupIterator() do
|
||||
private.groupFilter[groupPath] = true
|
||||
end
|
||||
private.DropdownCommonOnSelectionChanged(groupSelector)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.GetTotal(row)
|
||||
return row:GetField("price") * row:GetField("quantity")
|
||||
end
|
||||
|
||||
function private.GetAuctions(row)
|
||||
return row:GetField("quantity") / row:GetField("stackSize")
|
||||
end
|
||||
|
||||
function private.UpdateQuery()
|
||||
private.query:ResetFilters()
|
||||
:Equal("type", private.type)
|
||||
if private.searchFilter ~= "" then
|
||||
private.query:Matches("name", String.Escape(private.searchFilter))
|
||||
end
|
||||
if Table.Count(private.typeFilter) ~= #TYPE_KEYS then
|
||||
private.query:InTable("source", private.typeFilter)
|
||||
end
|
||||
if Table.Count(private.rarityFilter) ~= #private.rarityList then
|
||||
private.query:InTable("quality", private.rarityFilter)
|
||||
end
|
||||
if Table.Count(private.characterFilter) ~= #private.characters then
|
||||
private.query:InTable("player", private.characterFilter)
|
||||
end
|
||||
if private.timeFrameFilter ~= 0 then
|
||||
private.query:GreaterThan("time", time() - private.timeFrameFilter)
|
||||
end
|
||||
if next(private.groupFilter) then
|
||||
private.query:InTable("groupPath", private.groupFilter)
|
||||
end
|
||||
end
|
||||
|
||||
function private.TableSelectionChanged(scrollingTable, row)
|
||||
TSM.MainUI.Ledger.ShowItemDetail(scrollingTable:GetParentElement():GetParentElement(), row:GetField("itemString"), private.type)
|
||||
end
|
||||
Reference in New Issue
Block a user