Class: Clevic::FilterCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/clevic/filter_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_view, message = nil, &filter_block) ⇒ FilterCommand

filter_block will be passed a Dataset to filter. filter_message will be displayed.



5
6
7
8
9
# File 'lib/clevic/filter_command.rb', line 5

def initialize( table_view, message = nil, &filter_block )
  @table_view = table_view
  @message = message || 'filtered'
  @filter_block = filter_block
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



11
12
13
# File 'lib/clevic/filter_command.rb', line 11

def message
  @message
end

Instance Method Details

#doitObject

Do the filtering. Return true if successful, false otherwise.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/clevic/filter_command.rb', line 14

def doit
  # store current dataset
  @previous_dataset = @table_view.model.cache_table.dataset

  # store auto_new
  @auto_new = @table_view.model.auto_new

  # reload cache table with new conditions
  @table_view.model.auto_new = false
  @table_view.model.reload_data( &@filter_block )
  true
rescue Exception => e
  puts
  puts e.message
  puts e.backtrace
  false
end

#undoObject



32
33
34
35
36
37
38
# File 'lib/clevic/filter_command.rb', line 32

def undo
  # restore auto_new
  @table_view.model.auto_new = @auto_new

  # reload cache table with stored AR conditions
  @table_view.model.reload_data( @previous_dataset )
end