forcast 0.0.110
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/COPYRIGHTS +11 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +166 -0
- data/PENDIENTES +39 -0
- data/README.md +35 -0
- data/Rakefile +7 -0
- data/VERSION +1 -0
- data/bin/console +14 -0
- data/bin/rake +28 -0
- data/bin/setup +8 -0
- data/forcast.gemspec +73 -0
- data/lib/forcast.rb +5 -0
- data/lib/forcast/controllers/all.rb +2 -0
- data/lib/forcast/controllers/application/all.rb +12 -0
- data/lib/forcast/controllers/application/crud.rb +91 -0
- data/lib/forcast/controllers/application/database.rb +34 -0
- data/lib/forcast/controllers/application/error.rb +18 -0
- data/lib/forcast/controllers/application/exception_handler.rb +25 -0
- data/lib/forcast/controllers/application/json.rb +83 -0
- data/lib/forcast/controllers/application/locale.rb +30 -0
- data/lib/forcast/controllers/application/log.rb +22 -0
- data/lib/forcast/controllers/application/login.rb +41 -0
- data/lib/forcast/controllers/application/meta.rb +61 -0
- data/lib/forcast/controllers/application/model.rb +17 -0
- data/lib/forcast/controllers/application/permitirtodo.rb +27 -0
- data/lib/forcast/controllers/application/utils.rb +28 -0
- data/lib/forcast/controllers/controller/all.rb +8 -0
- data/lib/forcast/controllers/controller/asociar.rb +121 -0
- data/lib/forcast/controllers/controller/busqueda.rb +151 -0
- data/lib/forcast/controllers/controller/definitor/definitor.rb +322 -0
- data/lib/forcast/controllers/controller/definitor/definitor_page.rb +40 -0
- data/lib/forcast/controllers/controller/definitor_all.rb +2 -0
- data/lib/forcast/controllers/controller/filtro.rb +48 -0
- data/lib/forcast/controllers/controller/login/controllers/base_controller.rb +135 -0
- data/lib/forcast/controllers/controller/login/controllers/login_controller.rb +38 -0
- data/lib/forcast/controllers/controller/login/login.rb +71 -0
- data/lib/forcast/controllers/controller/login_all.rb +1 -0
- data/lib/forcast/controllers/controller/paper_trail/paper_trail.rb +21 -0
- data/lib/forcast/controllers/controller/paper_trail_all.rb +1 -0
- data/lib/forcast/controllers/controller/relacion.rb +157 -0
- data/lib/forcast/controllers/controller/rule_engine/action_engine.rb +92 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/action_logs_controller.rb +12 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/actions_controller.rb +10 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/pollings_controller.rb +13 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/rule_logs_controller.rb +12 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/rules_controller.rb +19 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/webhooks_controller.rb +27 -0
- data/lib/forcast/controllers/controller/rule_engine/polling_engine.rb +76 -0
- data/lib/forcast/controllers/controller/rule_engine/rule_controller.rb +27 -0
- data/lib/forcast/controllers/controller/rule_engine/rule_engine.rb +88 -0
- data/lib/forcast/controllers/controller/rule_engine/webhook_engine.rb +38 -0
- data/lib/forcast/controllers/controller/rule_engine_all.rb +5 -0
- data/lib/forcast/jobs/all.rb +2 -0
- data/lib/forcast/jobs/jobs_assets.rb +25 -0
- data/lib/forcast/jobs/jobs_wrapper.rb +25 -0
- data/lib/forcast/jobs/rule_engine/jobs_actions.rb +73 -0
- data/lib/forcast/jobs/rule_engine/jobs_pollings.rb +77 -0
- data/lib/forcast/jobs/rule_engine/jobs_webhooks.rb +54 -0
- data/lib/forcast/migrations/0_migracion_general.rb +44 -0
- data/lib/forcast/migrations/paper_trail/versions.rb +61 -0
- data/lib/forcast/migrations/rule_engine/action_logs.rb +15 -0
- data/lib/forcast/migrations/rule_engine/actions.rb +15 -0
- data/lib/forcast/migrations/rule_engine/pollings.rb +26 -0
- data/lib/forcast/migrations/rule_engine/rule_logs.rb +22 -0
- data/lib/forcast/migrations/rule_engine/rules.rb +27 -0
- data/lib/forcast/migrations/rule_engine/webhooks.rb +25 -0
- data/lib/forcast/models/all.rb +8 -0
- data/lib/forcast/models/asociar.rb +74 -0
- data/lib/forcast/models/busqueda.rb +17 -0
- data/lib/forcast/models/login/authorization.rb +37 -0
- data/lib/forcast/models/login/json_web_token.rb +15 -0
- data/lib/forcast/models/login/login.rb +26 -0
- data/lib/forcast/models/login_all.rb +2 -0
- data/lib/forcast/models/meta.rb +19 -0
- data/lib/forcast/models/modelo.rb +125 -0
- data/lib/forcast/models/models/meta.rb +6 -0
- data/lib/forcast/models/paper_trail/paper_trail.rb +13 -0
- data/lib/forcast/models/paper_trail_all.rb +1 -0
- data/lib/forcast/models/permitirtodo.rb +57 -0
- data/lib/forcast/models/rule_engine/action_engine.rb +19 -0
- data/lib/forcast/models/rule_engine/models/action.rb +41 -0
- data/lib/forcast/models/rule_engine/models/action_log.rb +40 -0
- data/lib/forcast/models/rule_engine/models/polling.rb +43 -0
- data/lib/forcast/models/rule_engine/models/rule.rb +44 -0
- data/lib/forcast/models/rule_engine/models/rule_log.rb +39 -0
- data/lib/forcast/models/rule_engine/models/webhook.rb +43 -0
- data/lib/forcast/models/rule_engine/polling_engine.rb +113 -0
- data/lib/forcast/models/rule_engine/rule.rb +62 -0
- data/lib/forcast/models/rule_engine/rule_engine.rb +137 -0
- data/lib/forcast/models/rule_engine/rule_scope.rb +35 -0
- data/lib/forcast/models/rule_engine/webhook_engine.rb +55 -0
- data/lib/forcast/models/rule_engine_all.rb +6 -0
- data/lib/forcast/routes/concerns/asociar.rb +15 -0
- data/lib/forcast/routes/concerns/buscar.rb +6 -0
- data/lib/forcast/routes/concerns/definitor.rb +3 -0
- data/lib/forcast/routes/concerns/modelo.rb +6 -0
- data/lib/forcast/routes/database.rb +4 -0
- data/lib/forcast/routes/login.rb +4 -0
- data/lib/forcast/routes/paper_trail/paper_trail.rb +3 -0
- data/lib/forcast/routes/rule_engine/rule.rb +5 -0
- data/lib/forcast/tasks/.giosaveZr0hbs +21 -0
- data/lib/forcast/tasks/.keep +0 -0
- data/lib/forcast/tasks/all.rb +16 -0
- data/lib/forcast/tasks/diagramas.rake +32 -0
- data/lib/forcast/tasks/documentation/documentation.rb +100 -0
- data/lib/forcast/tasks/env.rake +10 -0
- data/lib/forcast/tasks/git.rake +22 -0
- data/lib/forcast/tasks/indy/indy.rb +28 -0
- data/lib/forcast/tasks/logs.rake +13 -0
- data/lib/forcast/tasks/process.rake +18 -0
- data/lib/forcast/tasks/schema.rake +17 -0
- data/lib/forcast/tasks/schema/recips/action.rb +18 -0
- data/lib/forcast/tasks/schema/recips/controller.rb +29 -0
- data/lib/forcast/tasks/schema/recips/definitor.rb +38 -0
- data/lib/forcast/tasks/schema/recips/model.rb +43 -0
- data/lib/forcast/tasks/schema/recips/project.rb +19 -0
- data/lib/forcast/tasks/schema/recips/route.rb +9 -0
- data/lib/forcast/tasks/schema/recips/tmp/controller.rb +0 -0
- data/lib/forcast/tasks/schema/recips/tmp/model.rb +0 -0
- data/lib/forcast/tasks/schema/recips/tmp/model/.keep +0 -0
- data/lib/forcast/tasks/schema/rule_engine/rule_engine.rb +98 -0
- data/lib/forcast/tasks/schema/schema.rb +346 -0
- data/lib/forcast/tasks/test.rake +129 -0
- data/lib/forcast/tasks/utils.rake +68 -0
- data/lib/forcast/tasks/yard.rake +18 -0
- data/lib/forcast/utils/all.rb +4 -0
- data/lib/forcast/utils/email.rb +49 -0
- data/lib/forcast/utils/email/forcast/utils/email/layout/default.html.erb +3 -0
- data/lib/forcast/utils/email/forcast/utils/email/layout/default.text.erb +5 -0
- data/lib/forcast/utils/firebase.rb +60 -0
- data/lib/forcast/utils/firebase_database.rb +117 -0
- data/lib/forcast/utils/measure.rb +44 -0
- data/lib/forcast/utils/qvo.rb +141 -0
- data/lib/forcast/utils/server.rb +296 -0
- data/lib/forcast/utils/telegram.rb +82 -0
- data/lib/forcast/utils/thing.rb +180 -0
- data/lib/forcast/version.rb +15 -0
- data/lib/lib/backup.rb +42 -0
- data/lib/lib/deploy.sh +40 -0
- data/lib/lib/forcast_servidor_rails.sh +11 -0
- data/lib/lib/pg_generator.sh +10 -0
- data/lib/lib/production.rb +66 -0
- data/lib/lib/production/production.rb +30 -0
- data/lib/lib/systemctl_maker.rb +88 -0
- data/lib/lib/update.rb +100 -0
- data/production.rb +31 -0
- metadata +301 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
module Forcast
|
2
|
+
module Application
|
3
|
+
module Utils
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def limit_query
|
8
|
+
|
9
|
+
@limit = nil
|
10
|
+
@limit = params[:limit] if params[:limit].present?
|
11
|
+
@limit_nested = nil
|
12
|
+
@limit_nested = params[:limit_nested] if params[:limit_nested].present?
|
13
|
+
end
|
14
|
+
|
15
|
+
def params_present? (param)
|
16
|
+
true if params[param].present?
|
17
|
+
end
|
18
|
+
|
19
|
+
def abstract_controller (model)
|
20
|
+
|
21
|
+
controller_path.tableize.gsub!(controller_name, model+ "s_controller").classify.constantize
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require "forcast/controllers/controller/asociar"
|
2
|
+
require "forcast/controllers/controller/busqueda"
|
3
|
+
require "forcast/controllers/controller/filtro"
|
4
|
+
require "forcast/controllers/controller/relacion"
|
5
|
+
require "forcast/controllers/controller/definitor_all"
|
6
|
+
require "forcast/controllers/controller/rule_engine_all"
|
7
|
+
require "forcast/controllers/controller/paper_trail_all"
|
8
|
+
require "forcast/controllers/controller/login_all"
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module Forcast
|
4
|
+
module Controller
|
5
|
+
module Asociar
|
6
|
+
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
|
11
|
+
before_action :raise_error_asociar, only: [:ver_no_asociados_a, :ver_asociado_a, :asociar_a, :desasociar_de]
|
12
|
+
before_action :raise_error_agregar, only: [:agregar_asociado, :quitar_asociado]
|
13
|
+
## Sobre escribre todos los metodos anteriores.... hay que buscar una forma de arreglarlo
|
14
|
+
## Solucion por ahora es cambiar el nombre a los metodos
|
15
|
+
before_action :set_model_id_asociar, only: [:ver_asociado_a, :asociar_a, :agregar_asociado, :desasociar_de, :quitar_asociado]
|
16
|
+
end
|
17
|
+
#Collection
|
18
|
+
def ver_no_asociados_a
|
19
|
+
|
20
|
+
@response = model.no_asociados_a(@modelo + "_id")
|
21
|
+
json_response(@response.select(*params_permitidos_enviar),t("ok"))
|
22
|
+
|
23
|
+
end
|
24
|
+
#Member
|
25
|
+
def ver_asociado_a
|
26
|
+
|
27
|
+
@response = @model_id.ver_asociado(@modelo)
|
28
|
+
params_permitidos_enviar = abstract_controller(@modelo).new.send (:params_permitidos_enviar)
|
29
|
+
json_response(@response.select(*params_permitidos_enviar),t("ok"))
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def asociar_a
|
34
|
+
|
35
|
+
raise Application::Error::General.new(t("error_relation_already_taken", param: params[:modelo])) unless @model_id.asociado_a?(@modelo+'_id', @modelo_id)
|
36
|
+
raise Application::Error::General.new(t("error_relation_model_id_doesnt_exist", param: params[:modelo])) unless @model_id.asociado_existe?(@modelo, @modelo_id)
|
37
|
+
@model_id.asociar_a(@modelo+'_id', @modelo_id)
|
38
|
+
json_response(@model_id.attributes.slice(*params_permitidos_enviar),t("ok"))
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def desasociar_de
|
43
|
+
|
44
|
+
@model_id.desasociar_de(@modelo+'_id')
|
45
|
+
json_response(@model_id.attributes.slice(*params_permitidos_enviar),t("ok"))
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def agregar_asociado
|
50
|
+
|
51
|
+
@response = []
|
52
|
+
@modelo_id.is_a?(Array) ? @modelo_id : @modelo_id = [@modelo_id]
|
53
|
+
@modelo_id.each do |modelo_id|
|
54
|
+
#raise Application::Error::General.new(t("error_relation_already_taken", param: [params[:modelo],modelo_id])) unless @model_id.agregar_asociado_a?(@modelo, modelo_id)
|
55
|
+
raise Application::Error::General.new(t("error_relation_model_id_doesnt_exist", param: [params[:modelo],modelo_id])) unless @model_id.asociado_existe?(@modelo,modelo_id)
|
56
|
+
@model_id.agregar_asociado(@modelo, modelo_id)
|
57
|
+
paso = c_to_m(@modelo).find(modelo_id)
|
58
|
+
params_permitidos_enviar = abstract_controller(@modelo).new.send (:params_permitidos_enviar)
|
59
|
+
@response.push(paso.attributes.slice(*params_permitidos_enviar))
|
60
|
+
end
|
61
|
+
json_response(@response,t("ok"))
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
def quitar_asociado
|
66
|
+
|
67
|
+
@response = []
|
68
|
+
@modelo_id.is_a?(Array) ? @modelo_id : @modelo_id = [@modelo_id]
|
69
|
+
@modelo_id.each do |modelo_id|
|
70
|
+
#raise Application::Error::General.new(t("error_relation_already_taken", param: [params[:modelo],modelo_id])) unless @model_id.agregar_asociado_a?(@modelo, modelo_id)
|
71
|
+
raise Application::Error::General.new(t("error_relation_model_id_doesnt_exist", param: [params[:modelo],modelo_id])) unless @model_id.asociado_existe?(@modelo,modelo_id)
|
72
|
+
@model_id.quitar_asociado(@modelo, modelo_id)
|
73
|
+
paso = c_to_m(@modelo).find(modelo_id)
|
74
|
+
params_permitidos_enviar = abstract_controller(@modelo).new.send (:params_permitidos_enviar)
|
75
|
+
@response.push(paso.attributes.slice(*params_permitidos_enviar))
|
76
|
+
end
|
77
|
+
json_response(@response,t("ok"))
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def modelo_db
|
83
|
+
|
84
|
+
n = []
|
85
|
+
nn = []
|
86
|
+
model.reflect_on_all_associations(:has_many).each do |x|
|
87
|
+
n = n.push(x.name.to_s.classify)
|
88
|
+
end
|
89
|
+
model.reflect_on_all_associations(:belongs_to).each do |x|
|
90
|
+
nn = nn.push(x.name.to_s.classify)
|
91
|
+
end
|
92
|
+
rep = {model:model.name,belongs_to: nn, has_many: n}
|
93
|
+
json_response(rep,t("ok"))
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def raise_error_asociar
|
99
|
+
|
100
|
+
raise Application::Error::General.new(t("error_relation", param: params[:modelo])) unless comprobar_relacion(:belongs_to, @modelo)
|
101
|
+
raise Application::Error::General.new(t("error_relation_not_permitted", param: params[:modelo])) unless model.params_permitidos_asociar.include?(@modelo+'_id')
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
def raise_error_agregar
|
106
|
+
|
107
|
+
raise Application::Error::General.new(t("error_relation", param: params[:modelo])) unless comprobar_relacion(:has_many, @modelo)
|
108
|
+
raise Application::Error::General.new(t("error_relation_not_permitted", param: params[:modelo])) unless model.params_permitidos_agregar.include?(@modelo+'_id')
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
def set_model_id_asociar
|
113
|
+
|
114
|
+
@model_id ||= model.find(params[:id])
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
module Forcast
|
2
|
+
module Controller
|
3
|
+
module Busqueda
|
4
|
+
|
5
|
+
def index
|
6
|
+
params[:dato] = true if params[:dato] == 'true'
|
7
|
+
params[:dato] = false if params[:dato] == 'false'
|
8
|
+
params[:contiene] = true if params[:dato] == 'true'
|
9
|
+
params[:contiene] = false if params[:dato] == 'false'
|
10
|
+
|
11
|
+
buscar_relaciones if params_present?('relacion') && !params_present?('buscar_por') && !params_present?('dato')
|
12
|
+
es_array_buscar_por_parametro_exacto if params_present?('buscar_por') && params_present?('dato')
|
13
|
+
es_array_buscar_por_parametro_contiene if params_present?('buscar_por') && params_present?('contiene')
|
14
|
+
|
15
|
+
super()
|
16
|
+
end
|
17
|
+
|
18
|
+
def show
|
19
|
+
buscar_relaciones if params_present?('relacion') && !params_present?('buscar_por') && !params_present?('dato')
|
20
|
+
super()
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def es_array_buscar_por_parametro_exacto
|
26
|
+
|
27
|
+
buscar_por = params[:buscar_por]
|
28
|
+
dato = params[:dato]
|
29
|
+
buscar_por.is_a?(Array) ? array_buscar_por_parametro_exacto(buscar_por,dato) : buscar_por_parametro_exacto(buscar_por,dato)
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def es_array_buscar_por_parametro_contiene
|
34
|
+
|
35
|
+
buscar_por = params[:buscar_por]
|
36
|
+
contiene = params[:contiene]
|
37
|
+
buscar_por.is_a?(Array) ? array_buscar_por_parametro_contiene(buscar_por,contiene) : buscar_por_parametro_contiene(buscar_por,contiene)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def array_buscar_por_parametro_exacto (buscar_por, dato)
|
42
|
+
raise Application::Error::General.new(t("error_same_length_array")) unless buscar_por.length == dato.length
|
43
|
+
response = []
|
44
|
+
buscar_por.each_with_index do |b,index|
|
45
|
+
response[index] = buscar_por_parametro_exacto(b,dato[index])
|
46
|
+
end
|
47
|
+
paso = []
|
48
|
+
response = response.inject(:&) if params[:join].to_s == 'false'
|
49
|
+
response = [response] unless response.is_a?(Array)
|
50
|
+
response.each_with_index do |rr,index|
|
51
|
+
rr = [rr] unless rr.is_a?(Array)
|
52
|
+
rr.each do |r|
|
53
|
+
paso.push(r)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
@response = paso.uniq
|
57
|
+
end
|
58
|
+
|
59
|
+
def array_buscar_por_parametro_contiene (buscar_por, contiene)
|
60
|
+
raise Application::Error::General.new(t("error_same_length_array")) unless buscar_por.length == contiene.length
|
61
|
+
response = []
|
62
|
+
buscar_por.each_with_index do |b,index|
|
63
|
+
response[index] = buscar_por_parametro_contiene(b,contiene[index])
|
64
|
+
end
|
65
|
+
paso = []
|
66
|
+
response = response.inject(:&) if params[:join].to_s == 'false'
|
67
|
+
response = [response] unless response.is_a?(Array)
|
68
|
+
response.each do |rr|
|
69
|
+
rr = [rr] unless rr.is_a?(Array)
|
70
|
+
rr.each do |r|
|
71
|
+
paso.push(r)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
@response = paso.uniq
|
75
|
+
end
|
76
|
+
|
77
|
+
def buscar_por_parametro_exacto (buscar_por, dato)
|
78
|
+
raise Application::Error::General.new(t("error_search_param", param: buscar_por)) unless params_permitidos_buscar.include?(buscar_por)
|
79
|
+
raise Application::Error::General.new(t("error_find_param", param: buscar_por)) unless @model.parametro_existe?(buscar_por,dato)
|
80
|
+
resp = @model.buscar_parametro_exacto_scope(buscar_por,dato).limit(@limit).order('id desc').select(*params_permitidos_enviar)
|
81
|
+
params_present?('relacion') ? @response = buscar_relacion(resp,params[:relacion]) : @response = resp
|
82
|
+
end
|
83
|
+
|
84
|
+
def buscar_por_parametro_contiene (buscar_por, contiene)
|
85
|
+
raise Application::Error::General.new(t("error_search_param", param: buscar_por)) unless params_permitidos_buscar.include?(buscar_por)
|
86
|
+
resp = @model.buscar_parametro_contiene_scope(buscar_por,contiene).limit(@limit).order('id desc').select(*params_permitidos_enviar)
|
87
|
+
params_present?('relacion') ? @response = buscar_relacion(resp,params[:relacion]) : @response = resp
|
88
|
+
end
|
89
|
+
|
90
|
+
def buscar_relaciones
|
91
|
+
resp = @model.all if @model
|
92
|
+
resp = [@model_id] if @model_id
|
93
|
+
@response = buscar_relacion(resp,params[:relacion])
|
94
|
+
end
|
95
|
+
|
96
|
+
#Ver si es posible mejorar este metodo, se podria realizar una unica consulta
|
97
|
+
#a la DB para tener todos los registro de toda la tabla
|
98
|
+
def buscar_relacion(resp,rel)
|
99
|
+
return buscar_relacion_array(resp,rel) if rel.is_a?(Array)
|
100
|
+
#p Api::CamarasController.name.tableize.gsub!('camaras', 'hubs').classify
|
101
|
+
comprobar_relacion_buscar(rel)
|
102
|
+
array = []
|
103
|
+
|
104
|
+
resp.each do |x|
|
105
|
+
array.push(
|
106
|
+
{
|
107
|
+
controller_name.classify => [x.attributes.slice(*params_permitidos_enviar)],
|
108
|
+
rel.classify => x.send(rel).limit(@limit_nested).select(*@params_permitidos_enviar)
|
109
|
+
}
|
110
|
+
)
|
111
|
+
end
|
112
|
+
return array
|
113
|
+
end
|
114
|
+
|
115
|
+
def buscar_relacion_array(resp,rels)
|
116
|
+
|
117
|
+
array = [Hash.new]
|
118
|
+
rels.each do |rel|
|
119
|
+
i = 0
|
120
|
+
comprobar_relacion_buscar(rel)
|
121
|
+
resp.each_with_index do |x,index|
|
122
|
+
array[index] = {} if array[index].nil?
|
123
|
+
array[index].merge!({controller_name.classify => [x.attributes.slice(*params_permitidos_enviar)]}) if i == 0
|
124
|
+
array[index].merge!({
|
125
|
+
rel.classify => x.send(rel)
|
126
|
+
.limit(@limit_nested)
|
127
|
+
.select(*@params_permitidos_enviar)
|
128
|
+
})
|
129
|
+
|
130
|
+
end
|
131
|
+
i += 1
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
return array
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
def comprobar_relacion_buscar (rel)
|
140
|
+
begin
|
141
|
+
@params_permitidos_enviar = abstract_controller(rel).new.send (:params_permitidos_enviar)
|
142
|
+
rescue NameError => e
|
143
|
+
raise Application::Error::General.new(t("error_relation_param", param: rel))
|
144
|
+
end
|
145
|
+
raise Application::Error::General.new(t("error_relation_param", param: rel)) unless comprobar_relacion(:has_many, rel)
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,322 @@
|
|
1
|
+
module Forcast
|
2
|
+
module Controller
|
3
|
+
module Definitor
|
4
|
+
def definitor
|
5
|
+
raise Application::Error::General.new(t("operation_notValid")) unless permitted_definition.include?(@operation)
|
6
|
+
if @operation == 'put' || @operation == 'patch' || @operation == 'edit'
|
7
|
+
@operation = 'put_or_patch'
|
8
|
+
end
|
9
|
+
@response = send("#{@operation}_view_definitor")
|
10
|
+
json_response(@response, 'ok')
|
11
|
+
end
|
12
|
+
|
13
|
+
def permitted_definition
|
14
|
+
%w[create show put patch edit delete wizard info info_table card association webhook]
|
15
|
+
end
|
16
|
+
|
17
|
+
def selected_definitions(*selected)
|
18
|
+
all_definitions.slice(*selected)
|
19
|
+
end
|
20
|
+
|
21
|
+
def excluded_definitions(*selected)
|
22
|
+
all_definitions.except(*selected)
|
23
|
+
end
|
24
|
+
|
25
|
+
def selected_serializer_definitions(*selected)
|
26
|
+
serializer(all_definitions.slice(*selected))
|
27
|
+
end
|
28
|
+
|
29
|
+
def selected_serializer_definitions_mongo(*selected)
|
30
|
+
serializer_mongo(all_definitions.slice(*selected))
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def excluded_serializer_definitions(*selected)
|
35
|
+
serializer(all_definitions.except(*selected))
|
36
|
+
end
|
37
|
+
|
38
|
+
def all_serializer_definitions
|
39
|
+
serializer(all_definitions)
|
40
|
+
end
|
41
|
+
|
42
|
+
def all_definitions(name_controller = nil)
|
43
|
+
name_controller = controller_name if name_controller.nil?
|
44
|
+
model = name_controller.classify.constantize
|
45
|
+
attrs = model.attribute_names.map { |n| [n.to_sym, model.type_for_attribute(n).type] }.to_h
|
46
|
+
model.reflect_on_all_associations(:belongs_to).each do |relation|
|
47
|
+
relation = relation.name.to_s + '_id'
|
48
|
+
attrs[relation.to_sym] = 'relation'
|
49
|
+
end
|
50
|
+
attrs
|
51
|
+
end
|
52
|
+
|
53
|
+
def selected_info_serializer_definitions(*selected)
|
54
|
+
serializer_info(all_definitions.slice(*selected))
|
55
|
+
end
|
56
|
+
|
57
|
+
def serializer_info(object)
|
58
|
+
definitor = []
|
59
|
+
keys = object.keys
|
60
|
+
keys.each do |key|
|
61
|
+
type = object[key]
|
62
|
+
result = send("definitor_#{type}", key.to_s, type)
|
63
|
+
sender = {key: key, type: result[:typeAttribute], label: result[:label]}
|
64
|
+
definitor.push(sender)
|
65
|
+
end
|
66
|
+
definitor
|
67
|
+
end
|
68
|
+
|
69
|
+
def selected_association_serializer_definitions(*selected)
|
70
|
+
serializer_association(all_definitions.slice(*selected))
|
71
|
+
end
|
72
|
+
|
73
|
+
def serializer_association(object)
|
74
|
+
definitor = []
|
75
|
+
keys = object.keys.map {|e| e.to_s.gsub('_id', 's')}
|
76
|
+
sender = {type: "select", label: "Resource",
|
77
|
+
name: "resource", required: false, disabled: false,
|
78
|
+
options: keys
|
79
|
+
}
|
80
|
+
definitor.push(sender)
|
81
|
+
keys.each do |key|
|
82
|
+
model = key[0...-1].classify.constantize
|
83
|
+
args =[:id]
|
84
|
+
if model.attribute_names.include?('name')
|
85
|
+
args.push(:name)
|
86
|
+
elsif model.attribute_names.include?('serie')
|
87
|
+
args.push(:serie)
|
88
|
+
elsif model.attribute_names.include?('model')
|
89
|
+
args.push(:model)
|
90
|
+
end
|
91
|
+
options = model.all.pluck(*args).map { |e| e.size == 2 ? {id: e[0], label: e[1]} : {id: e} }
|
92
|
+
sender = {type: "dataselect", label: "ID",
|
93
|
+
name: key[0...-1]+'_id', required: false, disabled: true,
|
94
|
+
options: options
|
95
|
+
}
|
96
|
+
definitor.push(sender)
|
97
|
+
end
|
98
|
+
definitor
|
99
|
+
end
|
100
|
+
|
101
|
+
def selected_association_serializer_definitions_mongo(*selected)
|
102
|
+
serializer_association_mongo(all_definitions.slice(*selected))
|
103
|
+
end
|
104
|
+
|
105
|
+
def serializer_association_mongo(object)
|
106
|
+
definitor = []
|
107
|
+
keys = object.keys.map {|e| e.to_s.gsub('_id', 's')}
|
108
|
+
sender = {type: "select", label: "Resource",
|
109
|
+
name: "resource", required: false, disabled: false,
|
110
|
+
options: keys
|
111
|
+
}
|
112
|
+
definitor.push(sender)
|
113
|
+
keys.each do |key|
|
114
|
+
model = (key[0...-1]+'_mongo').classify.constantize
|
115
|
+
args =[:_id]
|
116
|
+
if model.attribute_names.include?('name')
|
117
|
+
args.push(:name)
|
118
|
+
elsif model.attribute_names.include?('serie')
|
119
|
+
args.push(:serie)
|
120
|
+
elsif model.attribute_names.include?('model')
|
121
|
+
args.push(:model)
|
122
|
+
end
|
123
|
+
options = model.all.pluck(*args).map { |e| e.is_a?(Array) ? {id: e[0].to_s, label: e[0].to_s.last(5)+' - '+e[1].to_s} : {id: e.to_s, label: e.to_s.last(5)+' - '+model.to_s } }
|
124
|
+
sender = {type: "dataselect", label: "ID",
|
125
|
+
name: key[0...-1]+'_id', required: false, disabled: true,
|
126
|
+
options: options
|
127
|
+
}
|
128
|
+
definitor.push(sender)
|
129
|
+
end
|
130
|
+
definitor
|
131
|
+
end
|
132
|
+
|
133
|
+
def serializer(object)
|
134
|
+
definitor = []
|
135
|
+
object.delete(:id) if params[:operation] == 'create'
|
136
|
+
keys = object.keys
|
137
|
+
keys.each do |key|
|
138
|
+
type = object[key]
|
139
|
+
result = send("definitor_#{type}", key.to_s, type)
|
140
|
+
definitor.push(result)
|
141
|
+
end
|
142
|
+
definitor
|
143
|
+
end
|
144
|
+
|
145
|
+
def serializer_mongo(object)
|
146
|
+
definitor = []
|
147
|
+
object.delete(:id) if params[:operation] == 'create'
|
148
|
+
keys = object.keys
|
149
|
+
keys.each do |key|
|
150
|
+
type = object[key]
|
151
|
+
result = send("definitor_#{type}", key.to_s, type)
|
152
|
+
result = send("definitor_#{type}_mongo", key.to_s, type) if type == 'relation'
|
153
|
+
definitor.push(result)
|
154
|
+
end
|
155
|
+
definitor
|
156
|
+
end
|
157
|
+
|
158
|
+
def constructor(key, type)
|
159
|
+
result = Hash.new
|
160
|
+
result[:label] = key.titleize
|
161
|
+
result[:typeAttribute] = type
|
162
|
+
result[:name] = key
|
163
|
+
result[:required] = model.parametros_necesario_create.include?(key)
|
164
|
+
yield(result)
|
165
|
+
result
|
166
|
+
end
|
167
|
+
|
168
|
+
def definitor_datetime(key, type)
|
169
|
+
constructor(key, type) do |result|
|
170
|
+
result[:type] = 'date'
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def definitor_decimal(key, type)
|
175
|
+
constructor(key, type) do |result|
|
176
|
+
result[:type] = 'input'
|
177
|
+
result[:inputType] = 'number'
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def definitor_relation(key, type)
|
182
|
+
constructor(key, type) do |result|
|
183
|
+
controller_name = key.gsub('_id', '')
|
184
|
+
model = controller_name.singularize.classify.constantize
|
185
|
+
args =[:id]
|
186
|
+
if model.attribute_names.include?('name')
|
187
|
+
args.push(:name)
|
188
|
+
elsif model.attribute_names.include?('serie')
|
189
|
+
args.push(:serie)
|
190
|
+
elsif model.attribute_names.include?('model')
|
191
|
+
args.push(:model)
|
192
|
+
end
|
193
|
+
options = model.all.pluck(*args).map { |e| e.size == 2 ? {id: e[0], label: e[1]} : {id: e, label: controller_name.singularize.classify } }
|
194
|
+
result[:type] = "dataselect"
|
195
|
+
result[:label] = controller_name.singularize.classify
|
196
|
+
result[:disabled] = true
|
197
|
+
result[:options] = options
|
198
|
+
result[:typeAttribute] = "string"
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def definitor_relation_mongo(key, type)
|
203
|
+
constructor(key, type) do |result|
|
204
|
+
controller_name = key.gsub('_id', '') + '_mongo'
|
205
|
+
model = (controller_name).singularize.classify.constantize
|
206
|
+
args =[:id]
|
207
|
+
if model.attribute_names.include?('name')
|
208
|
+
args.push(:name)
|
209
|
+
elsif model.attribute_names.include?('serie')
|
210
|
+
args.push(:serie)
|
211
|
+
elsif model.attribute_names.include?('model')
|
212
|
+
args.push(:model)
|
213
|
+
end
|
214
|
+
options = model.all.pluck(*args).map { |e| e.is_a?(Array) ? {id: e[0].to_s, label: e[0].to_s.last(5)+' - '+e[1].to_s} : {id: e.to_s, label: e.to_s.last(5)+' - '+model.to_s } }
|
215
|
+
result[:type] = "dataselect"
|
216
|
+
result[:label] = key.singularize.classify
|
217
|
+
result[:disabled] = true
|
218
|
+
result[:options] = options
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def definitor_integer(key, type)
|
223
|
+
constructor(key, type) do |result|
|
224
|
+
result[:type] = 'input'
|
225
|
+
result[:inputType] = 'number'
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def definitor_password(key, type)
|
230
|
+
constructor(key, type) do |result|
|
231
|
+
result[:type] = 'input'
|
232
|
+
result[:inputType] = 'password'
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def definitor_random_string(key, type)
|
237
|
+
constructor(key, type) do |result|
|
238
|
+
random_string_type(result)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def definitor_string(key, type)
|
243
|
+
constructor(key, type) do |result|
|
244
|
+
input_type(result)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
def definitor_text(key, type)
|
249
|
+
constructor(key, type) do |result|
|
250
|
+
input_type(result)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
def definitor_boolean(key, type)
|
255
|
+
constructor(key, type) do |result|
|
256
|
+
result[:type] = 'checkbutton'
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def definitor_json(key, type)
|
261
|
+
constructor(key, type) do |result|
|
262
|
+
result[:key] = key
|
263
|
+
result[:type] = 'json'
|
264
|
+
result[:inputType] = 'text'
|
265
|
+
result[:label] = key.classify
|
266
|
+
result[:typeAttribute] = 'string'
|
267
|
+
result[:name] = key.to_s
|
268
|
+
result[:meta] = {
|
269
|
+
selectItem: {
|
270
|
+
type: 'select',
|
271
|
+
label: key.classify,
|
272
|
+
name: key.to_s+'Key',
|
273
|
+
required: false,
|
274
|
+
options: []
|
275
|
+
},
|
276
|
+
areaItem: {
|
277
|
+
type: 'input',
|
278
|
+
inputType: 'text',
|
279
|
+
label: key.classify,
|
280
|
+
typeAttribute: 'string',
|
281
|
+
name: key.to_s+'Value',
|
282
|
+
required: false,
|
283
|
+
}
|
284
|
+
}
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def definitor_with_options(type, object, array, value)
|
289
|
+
object = all_definitions.slice(object)
|
290
|
+
key = object.keys.first.to_s
|
291
|
+
definition_result = constructor(key, object[key]) do |result|
|
292
|
+
send("#{type}_type", result, array, value)
|
293
|
+
end
|
294
|
+
[definition_result]
|
295
|
+
end
|
296
|
+
|
297
|
+
def random_string_type(result)
|
298
|
+
list = ['radiobutton','input','select']
|
299
|
+
number = rand(0...3)
|
300
|
+
type = list[number]
|
301
|
+
send("#{type}_type", result, ['Opt1', 'Opt2'], 'Opt1')
|
302
|
+
end
|
303
|
+
|
304
|
+
def select_type(result, array, value)
|
305
|
+
result[:type] = 'select'
|
306
|
+
result[:options] = array
|
307
|
+
result[:value] = value
|
308
|
+
end
|
309
|
+
|
310
|
+
def input_type(result, array='', value='')
|
311
|
+
result[:type] = 'input'
|
312
|
+
result[:inputType] = 'text'
|
313
|
+
end
|
314
|
+
|
315
|
+
def radiobutton_type(result, array, value)
|
316
|
+
result[:type] = 'radiobutton'
|
317
|
+
result[:options] = array
|
318
|
+
result[:value] = value
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|