Class: XmlConv::State::Transactions

Inherits:
Global
  • Object
show all
Defined in:
lib/xmlconv/state/transactions.rb

Defined Under Namespace

Classes: PageFacade

Constant Summary collapse

DIRECT_EVENT =
:home
PAGE_SIZE =
20
PAGER_SIZE =
10
REVERSE_MAP =
{
	:commit_time => true,
}
VIEW =
View::Transactions

Instance Method Summary collapse

Methods inherited from Global

#home, #logout, #transaction

Instance Method Details

#compare_entries(a, b) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/xmlconv/state/transactions.rb', line 51

def compare_entries(a, b)
	@sortby.each { |sortby|
		aval, bval = nil
		begin
			aval = a.send(sortby)
			bval = b.send(sortby)
		rescue
			next
		end
		res = if(aval.nil? && bval.nil?)
			0
		elsif(aval.nil?)
			1
		elsif(bval.nil?)
			-1
		else
			aval <=> bval
		end
		return res unless(res == 0)
	}
	0
end

#get_sortby!Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/xmlconv/state/transactions.rb', line 73

def get_sortby!
	@sortby ||= []
	sortvalue = @session.user_input(:sortvalue)
	if(sortvalue.is_a? String)
		sortvalue = sortvalue.intern
	end
	if(@sortby.first == sortvalue)
		@sort_reverse = !@sort_reverse
	else
		@sort_reverse = self.class::REVERSE_MAP[sortvalue]
	end
	@sortby.delete_if { |sortby|
		sortby == sortvalue
	}
	@sortby.unshift(sortvalue)
end

#initObject



42
43
44
45
46
47
48
49
50
# File 'lib/xmlconv/state/transactions.rb', line 42

def init
	@transactions = @model
	@model = @transactions.reverse
	setup_pages
	@filter = Proc.new { 
		page
	}
	super
end

#pageObject



89
90
91
92
93
94
95
# File 'lib/xmlconv/state/transactions.rb', line 89

def page
	if(pge = @session.user_input(:page))
		@page = @pages[pge.to_i]
	else
		@page ||= @pages.first
	end
end

#page_sizeObject



96
97
98
# File 'lib/xmlconv/state/transactions.rb', line 96

def page_size
	self::class::PAGE_SIZE
end

#selfObject



99
100
101
# File 'lib/xmlconv/state/transactions.rb', line 99

def self
	self
end

#setup_pagesObject



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/xmlconv/state/transactions.rb', line 102

def setup_pages
	@pages = []
	@page = nil
	pages = [(@model.size / PAGE_SIZE.to_f).ceil, 1].max
	pages.times { |pnum|
		page = PageFacade.new(pnum)
		page.model = @model[pnum * PAGE_SIZE, PAGE_SIZE]
		page.pages = @pages
		@pages.push(page)
	}
end

#sizeObject



113
114
115
# File 'lib/xmlconv/state/transactions.rb', line 113

def size
	@model.size
end

#sortObject



116
117
118
119
120
121
122
123
124
# File 'lib/xmlconv/state/transactions.rb', line 116

def sort
	return self unless @model.is_a? Array
	get_sortby!
	@model = @transactions.dup
	@model.sort! { |a, b| compare_entries(a, b) }
	@model.reverse! if(@sort_reverse)
	setup_pages
	self
end

#transactionsObject



125
126
127
# File 'lib/xmlconv/state/transactions.rb', line 125

def transactions
	self
end