sinatra-hexacta 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 235207ce86479d51ab5c1852a286ab92d5b4de8fbd159d584bc79234bcafd5dc
4
- data.tar.gz: 933097a5eca58c05479cb29e93543c9e9ca292eb45c61b940be4ab9c4cf80f9c
3
+ metadata.gz: b8db700323222cf195e1fc968c6ed3d0d69e2b8e988fb14a0ea05edfaa066efb
4
+ data.tar.gz: 648716c0e7d0adf003cc9d04a1fffc6cacb0c41789902af1217780e7df600bf2
5
5
  SHA512:
6
- metadata.gz: c57ec64f35c7f71a043278ffc15e8e131f53cc8a29dfcb353475baa4763a27b09e323eacb16c0f652b209eb44d22383f8e91096403e42e35cfd73f08c5ec10ef
7
- data.tar.gz: 2bfb5b976a50e30124bce1b534953b68e4c95f7398b4d34dace6afee55204b32adaec6bf67ac892f2cd33554a048a4f98be171a0ad17ac72581ef19aa32b8e5e
6
+ metadata.gz: dea149aa1379c39b280c0aad1946cfabea46fa798e90632a9f767adf71bc134eaf7a6980c65c8e772df01da3ee1b744db42f0cca9191a406cb12d9aae5e8a942
7
+ data.tar.gz: 9aafab704a4ff92c917082ab6ddd159b581cdf376073de7d21280c7504bde6d0af5561b159bcaeceaa39ba63f94e438c50286be05dbfff869a660534558c7ddb
@@ -3,6 +3,7 @@
3
3
  class AsyncProcess
4
4
  include SuckerPunch::Job
5
5
  attr_reader :handler
6
+ attr_reader :user_id
6
7
  end
7
8
 
8
9
  class ExampleProcess < AsyncProcess
@@ -25,10 +26,10 @@ end
25
26
 
26
27
  class ProcessHandler
27
28
 
28
- attr_reader :log, :error, :interrupted, :name, :id, :performed, :total, :clazz
29
+ attr_reader :log, :error, :interrupted, :name, :id, :performed, :total, :clazz, :user_id
29
30
  attr_accessor :total
30
31
 
31
- def initialize(id, name, clazz)
32
+ def initialize(id, name, clazz, user_id)
32
33
  @id = id
33
34
  @total = 0
34
35
  @performed = 0
@@ -37,6 +38,7 @@ class ProcessHandler
37
38
  @interrupted = false
38
39
  @name = name
39
40
  @clazz = clazz
41
+ @user_id = user_id
40
42
  end
41
43
 
42
44
  def progress
@@ -74,21 +76,22 @@ class ProcessManager
74
76
  @handlers = []
75
77
  end
76
78
 
77
- def find(clazz)
78
- @handlers.find { |handler| handler.clazz == clazz }
79
+ def find(clazz,user_id)
80
+ @handlers.find { |handler| handler.clazz == clazz && handler.user_id == user_id }
79
81
  end
80
82
 
81
83
  def run(*args)
82
- clean(args.first.to_s)
83
- if !running?(args.first.to_s)
84
- handler = ProcessHandler.new(rand(1..100000000), args.first.name, args.first.to_s)
84
+ user_id = args[1][:user_id]
85
+ clean(args.first.to_s,user_id)
86
+ if !running?(args.first.to_s,user_id)
87
+ handler = ProcessHandler.new(rand(1..100000000), args.first.name, args.first.to_s, user_id)
85
88
  clazz = args.first
86
89
  args[0] = handler
87
90
  clazz.perform_async(*args)
88
91
  @handlers << handler
89
92
  handler
90
93
  else
91
- find(args.first.to_s)
94
+ find(args.first.to_s,user_id)
92
95
  end
93
96
  end
94
97
 
@@ -96,15 +99,15 @@ class ProcessManager
96
99
  @handlers -= [handler]
97
100
  end
98
101
 
99
- def clean(clazz)
100
- @handlers.select { |handler| handler.clazz == clazz }.each do |handler|
102
+ def clean(clazz,user_id)
103
+ @handlers.select { |handler| handler.clazz == clazz && handler.user_id == user_id }.each do |handler|
101
104
  handler.interrupt
102
105
  self.finish(handler)
103
106
  end
104
107
  end
105
108
 
106
- def running?(clazz)
107
- !@handlers.select { |handler| handler.clazz == clazz }.empty?
109
+ def running?(clazz,user_id)
110
+ !@handlers.select { |handler| handler.clazz == clazz && handler.user_id == user_id }.empty?
108
111
  end
109
112
 
110
113
  end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ module Sinatra
3
+ module ConstantHandler
4
+ extend Hexacta
5
+
6
+ def enable_constants
7
+ p "Enabling constants..."
8
+ ConstantHandler.setup_dir("/app/views/#{Hexacta::GEM_FILE_DIR}/constants")
9
+ ConstantHandler.copy_all_files("/lib/sinatra/views/constants","/app/views/#{Hexacta::GEM_FILE_DIR}/constants")
10
+
11
+ before '/constant*' do
12
+ error(403) if authenticated(User).permissions.empty? && authenticated(User).recruiter.nil?
13
+ end
14
+
15
+ get '/constants' do
16
+ params[:format] = 'group' if params[:format].nil?
17
+ query = Constant.where(:kind => Constant.descendants.collect { |constant_class| constant_class.to_s })
18
+ slim :"#{Hexacta::GEM_FILE_DIR}/constants/#{params[:format]}", locals: { :constants => query.order(:kind,:value).all, :total => query.count, :filters => params, :query => query }
19
+ end
20
+
21
+ post '/constant' do
22
+ attributes = params.select { |attribute| Constant.columns.include?(attribute.to_sym) }
23
+ if params[:values].nil?
24
+ constant = Constant.create(attributes)
25
+ else
26
+ for value in params[:values].split(',')
27
+ attributes[:value] = value
28
+ constant = Constant.find_or_create(attributes)
29
+ end
30
+ end
31
+ redirect back
32
+ end
33
+
34
+ post '/constants/:id' do |id|
35
+ constant = Constant.find(:id => id.to_i)
36
+ constant.update_fields(params, Constant.columns, :missing=>:skip)
37
+ constant.save #This is import to force before save
38
+ redirect back
39
+ end
40
+
41
+ delete '/constants/:id' do |id|
42
+ constant = Constant.find(:id => id.to_i)
43
+ constant.destroy.to_hash.to_json
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ register ConstantHandler
51
+ end
@@ -4,3 +4,4 @@ require_relative 'notifications'
4
4
  require_relative 'params'
5
5
  require_relative 'reports'
6
6
  require_relative 'processes'
7
+ require_relative 'constants'
@@ -7,17 +7,19 @@ module Sinatra
7
7
  p "Enabling processes..."
8
8
 
9
9
  get '/processes' do
10
- return "" if ProcessManager.instance.find(params[:class]).nil?
10
+ return "" if ProcessManager.instance.find(params[:class],authenticated(User).id).nil?
11
11
  content_type :json
12
- return { 'name' => ProcessManager.instance.find(params[:class]).name, 'progress' => ProcessManager.instance.find(params[:class]).progress }.to_json
12
+ process = ProcessManager.instance.find(params[:class],authenticated(User).id)
13
+ return { 'name' => process.name, 'progress' => process.progress }.to_json
13
14
  end
14
15
 
15
16
  post '/processes/:clazz' do |clazz|
16
- ProcessManager.instance.clean(clazz)
17
+ ProcessManager.instance.clean(clazz,authenticated(User).id)
17
18
  200
18
19
  end
19
20
 
20
21
  post '/process' do
22
+ params[:user_id] = authenticated(User).id
21
23
  klass = Object.const_get("#{params[:class]}")
22
24
  a_handler = ProcessManager.instance.run(klass,params)
23
25
  a_handler.to_json
@@ -1,56 +1,59 @@
1
- .ct-chart.bar-chart id="#{id}"
1
+ -if labels.empty? || series.empty?
2
+ == empty_alert({ :title => "Sin datos suficientes", :message => "No hay suficientes datos para mostrar esta información."})
3
+ -else
4
+ .ct-chart.bar-chart id="#{id}"
2
5
 
3
- .table-responsive.chart-table
4
- table.table.table-striped
5
- tbody
6
- tr
7
- -for label in labels
8
- th #{label}
9
- -for serie in series
6
+ .table-responsive.chart-table
7
+ table.table.table-striped
8
+ tbody
10
9
  tr
11
- -for element in serie
12
- td #{element}
10
+ -for label in labels
11
+ th #{label}
12
+ -for serie in series
13
+ tr
14
+ -for element in serie
15
+ td #{element}
13
16
 
14
17
 
15
- javascript:
16
- var labels = #{{labels}};
17
- var series = #{{series}};
18
+ javascript:
19
+ var labels = #{{labels}};
20
+ var series = #{{series}};
18
21
 
19
- var options = {
20
- seriesBarDistance: 30,
21
- fullWidth: true,
22
- chartPadding: {
23
- right: 40
24
- },
25
- height: '300px',
26
- showLabel: true,
27
- plugins: [
28
- Chartist.plugins.legend({
29
- legendNames: #{{names}},
30
- })
31
- ]
32
- };
22
+ var options = {
23
+ seriesBarDistance: 30,
24
+ fullWidth: true,
25
+ chartPadding: {
26
+ right: 40
27
+ },
28
+ height: '300px',
29
+ showLabel: true,
30
+ plugins: [
31
+ Chartist.plugins.legend({
32
+ legendNames: #{{names}},
33
+ })
34
+ ]
35
+ };
33
36
 
34
- var responsiveOptions = [
35
- ['screen and (max-width: 640px)', {
36
- seriesBarDistance: 5,
37
- axisX: {
38
- labelInterpolationFnc: function (value) {
39
- return value[0];
37
+ var responsiveOptions = [
38
+ ['screen and (max-width: 640px)', {
39
+ seriesBarDistance: 5,
40
+ axisX: {
41
+ labelInterpolationFnc: function (value) {
42
+ return value[0];
43
+ }
40
44
  }
41
- }
42
- }]
43
- ];
45
+ }]
46
+ ];
44
47
 
45
- new Chartist.Bar("##{id}", {
46
- labels: labels,
47
- series: series
48
- },
49
- options,
50
- responsiveOptions
51
- );
48
+ new Chartist.Bar("##{id}", {
49
+ labels: labels,
50
+ series: series
51
+ },
52
+ options,
53
+ responsiveOptions
54
+ );
52
55
 
53
- css:
54
- ##{{id}} .ct-bar {
55
- stroke-width: #{{100/(labels.count*series.count)}}%
56
- }
56
+ css:
57
+ ##{{id}} .ct-bar {
58
+ stroke-width: #{{100/(labels.count*series.count)}}%
59
+ }
@@ -9,6 +9,10 @@
9
9
  tr
10
10
  -for element in serie
11
11
  td #{element}
12
+ tr
13
+ -total = [1,serie.reduce(:+)].max
14
+ -for element in serie
15
+ td #{(element.to_f*100/total).round(0)}%
12
16
 
13
17
  javascript:
14
18
  var labels = #{{labels}};
@@ -25,7 +29,7 @@ javascript:
25
29
  Chartist.plugins.legend()
26
30
  ]
27
31
  }
28
- );
32
+ );
29
33
 
30
34
  css:
31
35
  .pie .ct-legend.ct-legend-inside {
@@ -18,8 +18,8 @@ javascript:
18
18
  var series = #{{series}};
19
19
 
20
20
  new Chartist.Bar("##{id}", {
21
- labels: labels,
22
- series: series
21
+ labels: labels,
22
+ series: series
23
23
  }, {
24
24
  stackBars: true,
25
25
  axisY: {
@@ -0,0 +1,59 @@
1
+ .block-header
2
+ h2
3
+ | Constantes
4
+
5
+ -grouped_constants = constants.group_by { |constant| constant.kind }
6
+ -for kind in grouped_constants.keys
7
+ .card.m-b-5
8
+ .card-header style="padding: 20px;"
9
+ .media
10
+ .media-body.m-t-0
11
+ .row
12
+ .col-md-3
13
+ h2
14
+ small.m-0 Tipo de constante
15
+ h5.m-0 #{grouped_constants[kind].first.name}
16
+ small.m-0 #{grouped_constants[kind].count} valores
17
+ .col-md-9
18
+ -for constant in grouped_constants[kind]
19
+ a.btn.btn-link.bgm-lightgray.m-5.c-gray onclick="editConstant(#{constant.id},'#{constant.kind}','#{constant.value}')"
20
+ .di-block.v-middle #{constant.value}
21
+
22
+ .footer-text
23
+ a.text.btn.bgm-white.c-gray data-toggle="modal" data-target="#new-constant" Nueva constante
24
+
25
+ a.btn.btn-float.bgm-blue.m-btn.waves-effect.waves-circle.waves-float data-toggle="modal" data-target="#new-constant"
26
+ i.zmdi.zmdi-plus
27
+
28
+ == slim :'sinatra-hexacta/constants/new'
29
+
30
+
31
+ .modal.fade id="edit-constant" tabindex="-1" role="dialog" aria-labelledby="editConstant"
32
+ .modal-dialog
33
+ form.modal-content method="POST" data-toggle="validator"
34
+ .modal-content
35
+ .modal-header
36
+ h4.modal-title Editar constante
37
+ .modal-body
38
+ .row
39
+ .col-sm-12
40
+ == select_input({ :id => 'edit_kind', :name => "kind", :elements => [{ :value => nil, :text => 'Elige tipo de constante' }] + (Constant.descendants).collect { |constant_class| { :value => constant_class, :text => constant_class.new.name } }.uniq, :placeholder => "Tipo de constante", :chosen => nil, :required => true })
41
+ .col-sm-12
42
+ == input({ :id => 'edit_value', :name => "value", :title => "Valor", :type => 'text', :value => nil, :required => true })
43
+ .modal-footer
44
+ a.btn.waves-effect.bgm-red#delete.pull-left.c-white Borrar
45
+ button.btn.btn-link.waves-effect data-dismiss="modal" type="button" Cerrar
46
+ button.btn.btn-link.waves-effect type="submit" Actualizar
47
+
48
+
49
+ javascript:
50
+ function editConstant(constant_id,kind,value) {
51
+ $('#edit-constant .action').attr('action', '/constants/' + constant_id);
52
+
53
+ $('#edit-constant #edit_kind').val(kind);
54
+ $('#edit-constant #edit_value').val(value);
55
+
56
+ $('#edit-constant #edit_kind').trigger("chosen:updated");
57
+ $('#edit-constant #delete').attr("onclick","rm_object('constants','"+ constant_id +"')");
58
+ $('#edit-constant').modal('show');
59
+ }
@@ -0,0 +1,35 @@
1
+ .modal.fade id="new-constant" tabindex="-1" role="dialog" aria-labelledby="newConstant"
2
+ .modal-dialog.modal-lg
3
+ .row
4
+ .col-xs-4
5
+ form.modal-content action="/constant" method="POST" data-toggle="validator"
6
+ .modal-content
7
+ .modal-header
8
+ h4.modal-title Nueva constante
9
+ .modal-body
10
+ .row
11
+ .col-sm-12
12
+ == select_input({ :name => "kind", :elements => [{ :value => nil, :text => 'Elige tipo de constante' }] + (Constant.descendants).collect { |constant_class| { :value => constant_class, :text => constant_class.new.name } }.uniq, :placeholder => "Tipo de constante", :selected_elements => nil, :required => true })
13
+ .col-sm-12
14
+ == input({:name => "value", :title => "Valor", :type => 'text', :value => '', :required => true })
15
+ .modal-footer
16
+ button.btn.btn-link.waves-effect data-dismiss="modal" type="button" Cerrar
17
+ button.btn.btn-link.waves-effect type="submit" Crear
18
+
19
+ .col-xs-8
20
+ form.modal-content action="/constant" method="POST" data-toggle="validator"
21
+ .modal-content
22
+ .modal-header
23
+ h4.modal-title Nuevas constantes
24
+ .modal-body
25
+ .row
26
+ .col-sm-12
27
+ == select_input({ :name => "kind", :elements => [{ :value => nil, :text => 'Elige tipo de constante' }] + (Constant.descendants).collect { |constant_class| { :value => constant_class, :text => constant_class.new.name } }.uniq, :placeholder => "Tipo de constante", :selected_elements => nil, :required => true })
28
+ .col-sm-12
29
+ == input({:name => "values", :title => "Valores separados por coma", :type => 'text', :value => '', :required => true })
30
+ .modal-footer
31
+ button.btn.btn-link.waves-effect data-dismiss="modal" type="button" Cerrar
32
+ button.btn.btn-link.waves-effect type="submit" Crear
33
+ br
34
+ .modal-content
35
+ == slim info_alert({ :title => 'Creación masiva', :message => "Separa por coma los valores para crear multiples constantes de una sola vez."})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-hexacta
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Zanger
@@ -83,6 +83,7 @@ files:
83
83
  - lib/sinatra/extensions/menu.rb
84
84
  - lib/sinatra/extensions/notification.rb
85
85
  - lib/sinatra/extensions/processmanager.rb
86
+ - lib/sinatra/handlers/constants.rb
86
87
  - lib/sinatra/handlers/errors.rb
87
88
  - lib/sinatra/handlers/init.rb
88
89
  - lib/sinatra/handlers/notifications.rb
@@ -185,6 +186,8 @@ files:
185
186
  - lib/sinatra/views/charts/line.slim
186
187
  - lib/sinatra/views/charts/pie.slim
187
188
  - lib/sinatra/views/charts/stacked_bar.slim
189
+ - lib/sinatra/views/constants/group.slim
190
+ - lib/sinatra/views/constants/new.slim
188
191
  - lib/sinatra/views/errors/403.slim
189
192
  - lib/sinatra/views/errors/404.slim
190
193
  - lib/sinatra/views/errors/500.slim