5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/pult/panel/app/injector.rb', line 5
def self.inject! hash, panel, app
hash.instance_eval <<-STR
def _app
"#{app}"
end
def _panel
->{ ObjectSpace._id2ref(#{panel.object_id}) }.call
end
STR
hash.instance_eval do
def app?
true
end
def _to_flat param=self, prefix=nil
hash = param.each_pair.reduce({}) do |a, (k, v)|
v.is_a?(Hash) && ! SYS_KEYS.include?(k) ?
a.merge(_to_flat(v, "#{prefix}#{k}."))
: a.merge("#{prefix}#{k}" => v)
end
Pult::Panel::App.to_app! hash, _panel, _app
end
def _config
_panel[_app].config
end
def _actions
keys - SYS_KEYS
end
def _translated_actions
_actions.map{ |action| _action_title(action) }
end
def _ui_actions order: :az_ui
resproc = proc { |action| [action, _action_title(action)] }
tacts = _translated_actions
case order
when :config
_actions.map(&resproc)
when :config_ui
_actions.map(&resproc).sort_by{|arr| tacts.index(arr[1]) }
when :az
_actions.sort.map(&resproc)
when :az_ui
_actions.map(&resproc).sort_by{|arr| arr[1] }
end
end
def _action_title action
_action_translate(action) || action
end
def _action_translate action
self&.config&.ui&.ru&.action&.send(:[], action)
end
end
end
|