rawbotz 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -5
  3. data/Gemfile +2 -0
  4. data/README.md +60 -6
  5. data/Rakefile +3 -2
  6. data/agpl-3.0.txt +661 -0
  7. data/exe/bcrypt_pw +10 -0
  8. data/exe/rawbotz_abort_orders +28 -0
  9. data/exe/rawbotz_process_order_queue +12 -8
  10. data/exe/rawbotz_stock_update +10 -1
  11. data/exe/rawbotz_update_local_products +11 -3
  12. data/exe/rawbotz_update_remote_products +27 -4
  13. data/lib/rawbotz.rb +13 -5
  14. data/lib/rawbotz/app.rb +36 -2
  15. data/lib/rawbotz/cli/order_result_table.rb +13 -0
  16. data/lib/rawbotz/helpers/format_helper.rb +14 -0
  17. data/lib/rawbotz/helpers/icon_helper.rb +108 -22
  18. data/lib/rawbotz/helpers/order_item_color_helper.rb +17 -0
  19. data/lib/rawbotz/helpers/resource_link_helper.rb +3 -0
  20. data/lib/rawbotz/mail_template.rb +42 -7
  21. data/lib/rawbotz/models/sales.rb +21 -0
  22. data/lib/rawbotz/models/stock.rb +25 -0
  23. data/lib/rawbotz/models/stock_product.rb +146 -0
  24. data/lib/rawbotz/models/stock_product_factory.rb +64 -0
  25. data/lib/rawbotz/processors/order_linker.rb +50 -0
  26. data/lib/rawbotz/{order_processor.rb → processors/order_processor.rb} +14 -3
  27. data/lib/rawbotz/processors/organic_product_deliveries_csv.rb +47 -0
  28. data/lib/rawbotz/{product_updater.rb → processors/product_updater.rb} +71 -6
  29. data/lib/rawbotz/processors/stock_processor.rb +67 -0
  30. data/lib/rawbotz/public/rawbotz.css +35 -1
  31. data/lib/rawbotz/public/rawbotz.js +0 -1
  32. data/lib/rawbotz/remote_shop.rb +3 -0
  33. data/lib/rawbotz/routes.rb +3 -0
  34. data/lib/rawbotz/routes/non_remote_orders.rb +129 -29
  35. data/lib/rawbotz/routes/orders.rb +55 -4
  36. data/lib/rawbotz/routes/orders/stock.rb +75 -0
  37. data/lib/rawbotz/routes/product_links.rb +1 -1
  38. data/lib/rawbotz/routes/products.rb +19 -22
  39. data/lib/rawbotz/routes/remote_shop.rb +1 -1
  40. data/lib/rawbotz/routes/stock.rb +58 -0
  41. data/lib/rawbotz/routes/suppliers.rb +9 -4
  42. data/lib/rawbotz/sales_data.rb +13 -0
  43. data/lib/rawbotz/version.rb +1 -1
  44. data/lib/rawbotz/views/_hide_unhide_button.haml +1 -1
  45. data/lib/rawbotz/views/_menu.haml +9 -0
  46. data/lib/rawbotz/views/index.haml +1 -1
  47. data/lib/rawbotz/views/layout.haml +0 -1
  48. data/lib/rawbotz/views/order/_head.haml +64 -19
  49. data/lib/rawbotz/views/order/_item_table.haml +19 -3
  50. data/lib/rawbotz/views/order/_order_actions.haml +26 -0
  51. data/lib/rawbotz/views/order/link_to_remote.haml +30 -0
  52. data/lib/rawbotz/views/order/non_remote.haml +120 -26
  53. data/lib/rawbotz/views/order/packlist.haml +62 -5
  54. data/lib/rawbotz/views/order/packlist.pdf.haml +35 -0
  55. data/lib/rawbotz/views/order/stock.haml +116 -0
  56. data/lib/rawbotz/views/order/view.haml +41 -21
  57. data/lib/rawbotz/views/orders/_order_table.haml +82 -0
  58. data/lib/rawbotz/views/orders/index.haml +41 -28
  59. data/lib/rawbotz/views/orders/menu.haml +2 -2
  60. data/lib/rawbotz/views/orders/non_remotes.haml +14 -3
  61. data/lib/rawbotz/views/pdf_layout.haml +44 -0
  62. data/lib/rawbotz/views/product/view.haml +64 -11
  63. data/lib/rawbotz/views/products/index.haml +1 -1
  64. data/lib/rawbotz/views/products/table.haml +5 -1
  65. data/lib/rawbotz/views/remote_cart/index.haml +10 -0
  66. data/lib/rawbotz/views/remote_order/view.haml +6 -4
  67. data/lib/rawbotz/views/remote_orders/index.haml +16 -13
  68. data/lib/rawbotz/views/stock/index.haml +119 -0
  69. data/lib/rawbotz/views/stock/menu.haml +20 -0
  70. data/lib/rawbotz/views/stock_product/_value_table_line.haml +22 -0
  71. data/lib/rawbotz/views/stock_product/value_table.haml +28 -0
  72. data/lib/rawbotz/views/stockexplorer/stockexplorer.haml +157 -0
  73. data/lib/rawbotz/views/supplier/orders/table.haml +26 -0
  74. data/lib/rawbotz/views/supplier/view.haml +56 -10
  75. data/rawbotz.gemspec +13 -9
  76. metadata +86 -17
  77. data/lib/rawbotz/views/order/new.haml +0 -22
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bcrypt'
4
+
5
+ if ARGV.length != 1
6
+ STDERR.puts "Please provide an argument to #{$PROGRAMNAME}"
7
+ exit 1
8
+ end
9
+
10
+ puts BCrypt::Password.create ARGV[0]
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rawbotz"
4
+ require "rawbotz/option_parser"
5
+
6
+ optparse = Rawbotz::OptionParser.new do |opts, options|
7
+ opts.banner = "Usage: #{$PROGRAM_NAME} [OPTIONS]"
8
+ opts.separator ""
9
+ end
10
+
11
+ optparse.parse!
12
+ options = optparse.options
13
+
14
+ logger = Logger.new(STDOUT)
15
+ logger.level = optparse.options[:verbose] ? Logger::DEBUG : Logger::INFO
16
+
17
+ logger.debug "#{$PROGRAM_NAME} #{Rawbotz::VERSION}"
18
+
19
+ logger.info("Setting all orders in processing state in 'aborted' state")
20
+
21
+ orders = RawgentoModels::Order.where(state: 'processing')
22
+ logger.info("Found #{orders.count} orders")
23
+
24
+ orders.update_all(state: 'aborted')
25
+
26
+ logger.info("done")
27
+
28
+ exit 0
@@ -8,7 +8,6 @@ require "rawbotz"
8
8
  require 'rawbotz/option_parser'
9
9
  require 'rawbotz/cli/order_result_table'
10
10
 
11
-
12
11
  optparse = Rawbotz::OptionParser.new do |opts, options|
13
12
  opts.banner = "Usage: #{$PROGRAM_NAME} [OPTIONS] ORDER_ID"
14
13
  opts.separator ""
@@ -22,6 +21,8 @@ options = optparse.options
22
21
 
23
22
  include RawgentoModels
24
23
 
24
+ STDOUT.sync = true # helps in shell redirection logging situations
25
+
25
26
  def main options
26
27
  logger = Logger.new(STDOUT)
27
28
  logger.level = options[:verbose] ? Logger::DEBUG : Logger::INFO
@@ -49,13 +50,14 @@ def main options
49
50
 
50
51
  logger.info ("#{order.order_items.processible.count} products to order.")
51
52
 
52
- mech = Rawbotz.new_mech
53
- mech.login
54
-
55
- order_processor = Rawbotz::OrderProcessor.new(order, logger)
56
- order_processor.process!
57
-
58
- order.update(state: :ordered)
53
+ begin
54
+ order_processor = Rawbotz::OrderProcessor.new(order, logger)
55
+ order_processor.process!
56
+ order.update(state: :ordered)
57
+ rescue
58
+ logger.error("Hit error during order")
59
+ order.update(state: :error)
60
+ end
59
61
 
60
62
  logger.info("Finished order")
61
63
 
@@ -66,6 +68,8 @@ def main options
66
68
  diff_table = Rawbotz::CLI::OrderResultTable.tables diffs
67
69
  puts diff_table
68
70
 
71
+ order.update(order_result: diff_table)
72
+
69
73
  if options[:mail]
70
74
  logger.debug("Sending mail")
71
75
  mail = Rawbotz::mail("rawbotz order finished",
@@ -22,6 +22,10 @@ optparse = OptionParser.new do |opts|
22
22
  options[:config] = c
23
23
  end
24
24
 
25
+ opts.on("-f", "--fake VALUE", 'Fake value. If quantity is higher than 0.9*VALUE, subtract VALUE.') do |f|
26
+ options[:fake_value] = f
27
+ end
28
+
25
29
  opts.separator ""
26
30
  opts.separator "Output options"
27
31
  opts.on("-v", "--verbose", 'print debug output (WARNING: including PASSWORD)') do |v|
@@ -73,7 +77,12 @@ def main options
73
77
  if product.nil?
74
78
  logger.info("No such product #{s.product_id}")
75
79
  else
76
- product.stock_items.create(qty: s.qty, date: now)
80
+ qty = s.qty
81
+ if options[:fake_value].to_i > 0 && options[:fake_value].to_i * 0.9 < s.qty.to_i
82
+ qty = qty - options[:fake_value].to_i
83
+ logger.info("Fake value (#{options[:fake_value]}) applies for product_id #{product.product_id}: #{s.qty}")
84
+ end
85
+ product.stock_items.create(qty: qty, date: now)
77
86
  logger.info("Updated stock for #{s.product_id}")
78
87
  end
79
88
  end
@@ -11,6 +11,10 @@ optparse = Rawbotz::OptionParser.new do |opts, options|
11
11
  "send mail with result") do |v|
12
12
  options[:mail] = v
13
13
  end
14
+ opts.on("-d", "--[no-]dry-run",
15
+ "simulate, log potential changes but do not save them") do |d|
16
+ options[:dry_run] = d
17
+ end
14
18
  end
15
19
  optparse.parse!
16
20
  options = optparse.options
@@ -34,7 +38,7 @@ end
34
38
  product_count = RawgentoModels::LocalProduct.unscoped.count
35
39
 
36
40
  updater = Rawbotz::ProductUpdater.new logger
37
- updater.sync
41
+ updater.sync(options[:dry_run])
38
42
 
39
43
  logger.info("Finished updating local products.")
40
44
 
@@ -42,8 +46,12 @@ logger.info("Found #{RawgentoModels::LocalProduct.unscoped.count - product_count
42
46
 
43
47
  if options[:mail]
44
48
  logger.debug("Sending mail")
45
- Rawbotz::mail("rawbotz local product update",
46
- "Found #{RawgentoModels::LocalProduct.unscoped.count - product_count} new local products")
49
+ if updater.change_text.present?
50
+ Rawbotz::mail("rawbotz local product update",
51
+ "Found #{RawgentoModels::LocalProduct.unscoped.count - product_count} new local products\n\nOther changes:\n#{updater.change_text}")
52
+ else
53
+ Rawbotz::mail("rawbotz local product update: no changes", "Nothing changed in magento")
54
+ end
47
55
  end
48
56
 
49
57
  exit 0
@@ -5,6 +5,7 @@ require "rawbotz"
5
5
  require 'magento_remote'
6
6
 
7
7
  require 'optparse'
8
+ STDOUT.sync = true
8
9
 
9
10
  options = { sleep_time: 1,
10
11
  start_pid: 0,
@@ -29,6 +30,7 @@ optparse = OptionParser.new do |opts|
29
30
  opts.separator "Configuration file (remote shop info, local db info)"
30
31
  opts.on("-c", "--config FILE", 'file path to YAML config file.') do |c|
31
32
  options[:config] = c
33
+ Rawbotz.conf_file_path = c
32
34
  end
33
35
  opts.separator ""
34
36
  opts.separator "Parsing/scraping options"
@@ -52,9 +54,9 @@ optparse = OptionParser.new do |opts|
52
54
  "try LIMIT products #{options.print_default(:limit)}") do |v|
53
55
  options[:limit] = v
54
56
  end
55
- opts.on("-n", "--check-new", Integer,
57
+ opts.on("-n", "--[no-]check-new",
56
58
  "check only for new products") do |v|
57
- options[:check_new] = true
59
+ options[:check_new] = v
58
60
  end
59
61
 
60
62
  opts.separator ""
@@ -77,6 +79,8 @@ optparse = OptionParser.new do |opts|
77
79
  end
78
80
  optparse.parse!
79
81
 
82
+ STDOUT.sync = true
83
+
80
84
  if options[:check_new] && options[:start_pid] != 0
81
85
  STDERR.puts "Cannot define both check-new and start-pid options"
82
86
  exit 1
@@ -91,6 +95,7 @@ def main options
91
95
 
92
96
  mech_config = (YAML.load_file options[:config])["remote_shop"]
93
97
  logger.debug(mech_config)
98
+
94
99
  mech = MagentoMech.from_config(mech_config)
95
100
  mech.log_to! logger
96
101
 
@@ -104,6 +109,7 @@ def main options
104
109
  number_dead = 0
105
110
  product_count = RawgentoModels::RemoteProduct.count
106
111
 
112
+ changes = []
107
113
 
108
114
  current_pid = options[:start_pid]
109
115
  if options[:check_new]
@@ -120,8 +126,24 @@ def main options
120
126
  p = mech.scrape_products(current_pid, 1, options[:sleep_time])
121
127
  if !p.empty?
122
128
  logger.info "Found #{p[0].inspect}"
129
+
123
130
  product_db = RawgentoModels::RemoteProduct.find_or_initialize_by(product_id: p[0][1].to_i, supplier: supplier)
124
- product_db.update!(name: p[0][0], product_id: p[0][1].to_i, supplier: supplier)
131
+ product_db.name = p[0][0]
132
+ product_db.product_id = p[0][1].to_i
133
+ product_db.supplier = supplier
134
+
135
+ if product_db.persisted?
136
+ logger.debug "Product #{product_db.product_id} already existed"
137
+ else
138
+ logger.debug "Product #{product_db.product_id} is new!"
139
+ end
140
+
141
+ if product_db.changed?
142
+ change_line = "Changes for #{product_db.product_id} (#{product_db.name}): #{product_db.changes}"
143
+ logger.info(change_line)
144
+ changes << change_line
145
+ end
146
+
125
147
  product_db.save!
126
148
  number_dead = 0
127
149
  else
@@ -151,7 +173,8 @@ def main options
151
173
  if options[:mail]
152
174
  logger.debug("Sending mail")
153
175
  Rawbotz::mail("rawbotz remote product update",
154
- "Found #{RawgentoModels::RemoteProduct.count - product_count} remote products")
176
+ "Found #{RawgentoModels::RemoteProduct.count - product_count} new remote products\n"\
177
+ "#{changes.join('\n')}")
155
178
  end
156
179
  end
157
180
 
@@ -1,15 +1,23 @@
1
+ require 'rawgento_models'
2
+ require 'rawgento_db'
3
+
1
4
  require "rawbotz/version"
2
5
  require "rawbotz/remote_shop"
3
6
  require "rawbotz/local_shop"
4
- require "rawbotz/order_processor"
7
+ require "rawbotz/processors/stock_processor"
8
+ require "rawbotz/processors/order_processor"
9
+ require "rawbotz/processors/order_linker"
10
+ require "rawbotz/processors/organic_product_deliveries_csv"
5
11
  require "rawbotz/datapolate"
12
+ require "rawbotz/sales_data"
13
+ require "rawbotz/models/sales"
14
+ require "rawbotz/models/stock"
15
+ require "rawbotz/models/stock_product"
16
+ require "rawbotz/models/stock_product_factory"
6
17
  require "rawbotz/chart_month_dataset"
7
- require "rawbotz/product_updater"
18
+ require "rawbotz/processors/product_updater"
8
19
  require "rawbotz/mail_template"
9
20
 
10
- require 'rawgento_models'
11
- require 'rawgento_db'
12
-
13
21
  require "rawbotz/routes"
14
22
 
15
23
  require 'ostruct'
@@ -4,9 +4,13 @@ require 'action_view' # Workaround https://github.com/haml/haml/issues/695
4
4
  require 'haml'
5
5
  require 'rawbotz/helpers/icon_helper'
6
6
  require 'rawbotz/helpers/flash_helper'
7
+ require 'rawbotz/helpers/format_helper'
7
8
  require 'rawbotz/helpers/resource_link_helper'
9
+ require 'rawbotz/helpers/order_item_color_helper'
8
10
  require 'tilt/haml'
9
11
 
12
+ require 'bcrypt'
13
+
10
14
  class RawbotzApp < Sinatra::Base
11
15
  include RawgentoModels
12
16
 
@@ -29,24 +33,44 @@ class RawbotzApp < Sinatra::Base
29
33
  set :supplier, Supplier.find_by(name:
30
34
  conf["supplier_name"])
31
35
  set :conf, conf
36
+
37
+ if conf["authentication"] && !conf["authentication"].empty?
38
+ use Rack::Auth::Basic, "Protected Area, no robots allowed" do |username, password|
39
+ if username.nil? || password.nil? || conf["authentication"][username].nil?
40
+ nil
41
+ else
42
+ BCrypt::Password.new(conf["authentication"][username]) == password
43
+ end
44
+ end
45
+ end
32
46
  end
33
47
 
34
48
  helpers do ; end
35
49
  helpers Rawbotz::Helpers::IconHelper
36
50
  helpers Rawbotz::Helpers::FlashHelper
51
+ helpers Rawbotz::Helpers::FormatHelper
37
52
  helpers Rawbotz::Helpers::ResourceLinkHelper
53
+ helpers Rawbotz::Helpers::OrderItemColorHelper
38
54
 
39
55
  get '/' do
40
56
  haml :index
41
57
  end
42
58
 
59
+ # routes:
43
60
  # get '/orders'
44
61
  # get '/order/new'
45
62
  # get '/order/:id'
46
63
  # post '/order/:id/'
47
64
  # get '/order/:id/packlist'
65
+ # get '/order/:id/packlist/pdf'
48
66
  register Rawbotz::RawbotzApp::Routing::Orders
49
67
 
68
+ # get '/order/:id/stock
69
+ # post '/order/:id/stock'
70
+ # get '/order/:id/link_to_remote'
71
+ # post '/order/:id/link_to_remote'
72
+ register Rawbotz::RawbotzApp::Routing::Orders::Stock
73
+
50
74
  # get '/products'
51
75
  # post '/products/search'
52
76
  # get '/product/:id'
@@ -74,9 +98,19 @@ class RawbotzApp < Sinatra::Base
74
98
  # post '/supplier/:id'
75
99
  register Rawbotz::RawbotzApp::Routing::Suppliers
76
100
 
101
+ # get '/suppliers/orders'
102
+ # get '/suppliers/orders.csv'
103
+ register Rawbotz::RawbotzApp::Routing::Suppliers::Orders
104
+
105
+ # get '/stock'
106
+ # get '/stock/alerts'
107
+ # get '/stock/warnings'
108
+ register Rawbotz::RawbotzApp::Routing::Stock
109
+
77
110
  # get '/orders/non_remote'
78
- # get '/order/non_remote/:supplier_id'
79
- # post '/order/non_remote/:supplier_id'
111
+ # get '/order/non_remote/:order_id'
112
+ # post '/order/non_remote/:order_id'
113
+ # get '/order/non_remote/:supplier_id/new'
80
114
  register Rawbotz::RawbotzApp::Routing::NonRemoteOrders
81
115
 
82
116
  get '/maintenance' do
@@ -2,6 +2,17 @@ module Rawbotz::CLI
2
2
  module OrderResultTable
3
3
  def self.tables diffs
4
4
  out = ""
5
+ if !diffs[:error].empty?
6
+ error_items = diffs[:error].map do |p|
7
+ [p[0][0..35]]
8
+ end
9
+ out << Terminal::Table.new(title: "With error",
10
+ headings: ['Product'],
11
+ rows: error_items,
12
+ style: {width: 60}).to_s
13
+ out << "\n\n"
14
+ end
15
+
5
16
  if !diffs[:perfect].empty?
6
17
  perfect_items = diffs[:perfect].map do |p, q|
7
18
  [p.local_product.remote_product.name[0..35], q]
@@ -55,6 +66,8 @@ module Rawbotz::CLI
55
66
  rows: extra_items,
56
67
  style: {width:60}).to_s
57
68
  end
69
+
70
+ out
58
71
  end
59
72
  end
60
73
  end
@@ -0,0 +1,14 @@
1
+ module Rawbotz
2
+ module Helpers
3
+ module FormatHelper
4
+ # makes 1.7923 -> 1.79
5
+ # 200.00 -> 200
6
+ def friendly_float value
7
+ if value.nil?
8
+ return nil
9
+ end
10
+ "%g" % ("%.2f" % value )
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,38 +1,124 @@
1
1
  module Rawbotz
2
2
  module Helpers
3
3
  module IconHelper
4
- def error_icon
5
- '<i class="fa fa-flash"></i>'
4
+ def add_icon tooltip_text: nil
5
+ icon "plus", tooltip_text: tooltip_text
6
6
  end
7
- def index_icon
8
- '<i class="fa fa-th-list"></i>'
7
+ def delete_icon tooltip_text: nil
8
+ icon "remove", tooltip_text: tooltip_text
9
9
  end
10
- def info_icon
11
- '<i class="fa fa-info-circle"></i>'
10
+ def error_icon tooltip_text: nil
11
+ icon "flash", tooltip_text: tooltip_text
12
12
  end
13
- def link_icon
14
- '<i class="fa fa-link"></i>'
13
+ def external_link_icon tooltip_text: nil
14
+ icon "external-link", tooltip_text: tooltip_text
15
15
  end
16
- def order_icon
17
- '<i class="fa fa-shopping-cart"></i>'
16
+ def false_icon tooltip_text: nil
17
+ icon "close", tooltip_text: tooltip_text
18
18
  end
19
- def product_icon
20
- '<i class="fa fa-cube"></i>'
19
+ def index_icon tooltip_text: nil
20
+ icon "th-list", tooltip_text: tooltip_text
21
21
  end
22
- def products_icon
23
- '<i class="fa fa-cubes"></i>'
22
+ def info_icon tooltip_text: nil
23
+ icon "info-circle", tooltip_text: tooltip_text
24
24
  end
25
- def remote_icon
26
- '<i class="fa fa-globe"></i>'
25
+ def link_icon tooltip_text: nil
26
+ icon "info-link", tooltip_text: tooltip_text
27
27
  end
28
- def settings_icon
29
- '<i class="fa fa-wrench"></i>'
28
+ def mail_icon tooltip_text: nil
29
+ icon "envelope-o", tooltip_text: tooltip_text
30
30
  end
31
- def success_icon
32
- '<i class="fa fa-smile-o"></i>'
31
+ def order_icon tooltip_text: nil
32
+ icon "shopping-cart", tooltip_text: tooltip_text
33
33
  end
34
- def warning_icon
35
- '<i class="fa fa-warning"></i>'
34
+ def pack_icon tooltip_text: nil
35
+ icon "square-o", tooltip_text: tooltip_text
36
+ end
37
+ def packlist_icon tooltip_text: nil
38
+ icon "paperclip", tooltip_text: tooltip_text
39
+ end
40
+ def packsize_icon tooltip_text: nil
41
+ icon "cube", tooltip_text: tooltip_text
42
+ end
43
+ def product_icon tooltip_text: nil
44
+ icon "cube", tooltip_text: tooltip_text
45
+ end
46
+ def products_icon tooltip_text: nil
47
+ icon "cubes", tooltip_text: tooltip_text
48
+ end
49
+ def remote_icon tooltip_text: nil
50
+ icon "globe", tooltip_text: tooltip_text
51
+ end
52
+ def sales_icon tooltip_text: nil
53
+ icon "shopping-cart", tooltip_text: tooltip_text
54
+ end
55
+ def save_icon tooltip_text: nil
56
+ icon "envelope", tooltip_text: tooltip_text
57
+ end
58
+ def settings_icon tooltip_text: nil
59
+ icon "wrench", tooltip_text: tooltip_text
60
+ end
61
+ def shelve_icon tooltip_text: nil
62
+ icon "map-signs", tooltip_text: tooltip_text
63
+ end
64
+ def stock_empty_icon tooltip_text: nil
65
+ icon "battery-0", tooltip_text: tooltip_text
66
+ end
67
+ def stock_icon tooltip_text: nil
68
+ icon "battery-2", tooltip_text: tooltip_text
69
+ end
70
+ def stock_full_icon tooltip_text: nil
71
+ icon "battery-4", tooltip_text: tooltip_text
72
+ end
73
+ def success_icon tooltip_text: nil
74
+ icon "smile-o", tooltip_text: tooltip_text
75
+ end
76
+ def supplier_icon tooltip_text: nil
77
+ icon "truck", tooltip_text: tooltip_text
78
+ end
79
+ def true_icon tooltip_text: nil
80
+ icon "check-circle-o", tooltip_text: tooltip_text
81
+ end
82
+ def view_icon tooltip_text: nil
83
+ icon "eye", tooltip_text: tooltip_text
84
+ end
85
+ def warning_icon tooltip_text: nil
86
+ icon "warning", tooltip_text: tooltip_text
87
+ end
88
+
89
+ def bool_icon attr
90
+ if attr
91
+ true_icon
92
+ else
93
+ false_icon
94
+ end
95
+ end
96
+
97
+ def order_state_icon order
98
+ case order.state
99
+ when 'new'
100
+ icon "star"
101
+ when 'mailed'
102
+ icon "envelope-o"
103
+ when 'ordered'
104
+ icon "arrow-right"
105
+ when 'deleted'
106
+ icon "remove"
107
+ when 'stocked'
108
+ icon "thumbs-o-up"
109
+ else
110
+ icon "question"
111
+ end
112
+ end
113
+
114
+ private
115
+ def icon fa_name, tooltip_text: nil
116
+ "<i class=\"fa fa-#{fa_name}\"%s></i>" % tooltip(tooltip_text)
117
+ end
118
+ def tooltip tooltip_text
119
+ if tooltip_text
120
+ " title=\"#{tooltip_text}\""
121
+ end
36
122
  end
37
123
  end
38
124
  end