sinatra-hexacta 0.3.6 → 0.3.11

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: 7a000deb70fda181a659f558d0d74b2c0be710f5dfe699937b830122fb0a78dc
4
- data.tar.gz: bff227bfb84afefc6f86c16b7ae2cd5df112b7cc500c703f74d0a1420b7e7abf
3
+ metadata.gz: 2bc5e963847bbe5ea1241667df3c48dec7f6befb358424e26e57bdf19ad53fa8
4
+ data.tar.gz: 9cfac8d0ca834cc5370eac6011d9fa1dc0d0f78d268c0b32d2ac74e6309a23f9
5
5
  SHA512:
6
- metadata.gz: 7cd9ba877276c8ede2c9fdeee2d4dd1286444506f861f65adfa3f3bb039a6a5ca6b0cb2d669807a392cfc64c4ff4623a50c571f253d724313a132dca02051e8b
7
- data.tar.gz: dca6f0e88059d9104bacab702943edc43dd8628a101e3c29777f79d11a6025e434e80946ec5593b92c461263e43c032b43c2ae9a2190bf022979939ecb091162
6
+ metadata.gz: 91435e8036b49e137c24fc845a424044dd1a2e2bfc851c69f42872dbb14ca8e675b691e927afae746f42042336ef67b3c62cee12f0a86f821d34616191b1bedb
7
+ data.tar.gz: 6df3726e7cbbb75e7d8d7b5d7b5e20bbab32f762b2ab46e180ba372075409c0bb8e8f88c3a7ea2fe6992d4d4e6ba61783f14da39c1da26b726824937a1edab36
@@ -6,3 +6,4 @@ require_relative 'mailsender'
6
6
  require_relative 'mail'
7
7
  require_relative 'generalmail'
8
8
  require_relative 'mailbuilder'
9
+ #require_relative 'processmanager'
@@ -0,0 +1,106 @@
1
+ # encoding: utf-8
2
+
3
+ class AsyncProcess
4
+ include SuckerPunch::Job
5
+ attr_reader :handler
6
+ end
7
+
8
+ class ExampleProcess < AsyncProcess
9
+
10
+ attr_reader :log, :error, :interrupted, :name, :id
11
+
12
+ def self.name
13
+ "THE NAME"
14
+ end
15
+
16
+ def perform(handler, other_params)
17
+ @handler = handler
18
+ @handler.total = params[:ids].count
19
+ # loop
20
+ # if error @handler.log("error no falta", e.message)
21
+ # @handler.increase
22
+ #
23
+ end
24
+ end
25
+
26
+ class ProcessHandler
27
+
28
+ attr_reader :log, :error, :interrupted, :name, :id, :performed, :total, :clazz
29
+ attr_accessor :total
30
+
31
+ def initialize(id, name, clazz)
32
+ @id = id
33
+ @total = 0
34
+ @performed = 0
35
+ @log = []
36
+ @error = ""
37
+ @interrupted = false
38
+ @name = name
39
+ @clazz = clazz
40
+ end
41
+
42
+ def progress
43
+ return 0 if @total == 0
44
+ (@performed.to_f / @total.to_f)*100.0
45
+ end
46
+
47
+ def increase
48
+ @performed += 1
49
+ end
50
+
51
+ def log(severity, message)
52
+ @log << "[#{severity}] #{Time.now} #{message}"
53
+ end
54
+
55
+ def interrupt
56
+ @interrupted = true
57
+ end
58
+
59
+ def running?
60
+ @total != @performed
61
+ end
62
+ end
63
+
64
+ class ProcessManager
65
+ include Singleton
66
+
67
+ attr_reader :handlers
68
+
69
+ def initialize
70
+ @handlers = []
71
+ end
72
+
73
+ def find(clazz)
74
+ @handlers.find { |handler| handler.clazz == clazz }
75
+ end
76
+
77
+ def run(*args)
78
+ clean(args.first.to_s)
79
+ if !running?(args.first.to_s)
80
+ handler = ProcessHandler.new(rand(1..100000000), args.first.name, args.first.to_s)
81
+ clazz = args.first
82
+ args[0] = handler
83
+ clazz.perform_async(*args)
84
+ @handlers << handler
85
+ handler
86
+ else
87
+ find(args.first.to_s)
88
+ end
89
+ end
90
+
91
+ def finish(handler)
92
+ @handlers -= [handler]
93
+ end
94
+
95
+ def clean(clazz)
96
+ @handlers.select { |handler| !handler.running? }.each do |handler|
97
+ handler.interrupt
98
+ self.finish(handler)
99
+ end
100
+ end
101
+
102
+ def running?(clazz)
103
+ !@handlers.select { |handler| handler.clazz == clazz }.empty?;
104
+ end
105
+
106
+ end
@@ -2,4 +2,5 @@
2
2
  require_relative 'errors'
3
3
  require_relative 'notifications'
4
4
  require_relative 'params'
5
- require_relative 'reports'
5
+ require_relative 'reports'
6
+ #require_relative 'processes'
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ module Sinatra
3
+ module ProcessesHandler
4
+ extend Hexacta
5
+
6
+ def enable_processes
7
+ p "Enabling processes..."
8
+
9
+ get '/processes' do
10
+ return "" if ProcessManager.instance.find(params[:class]).nil?
11
+ content_type :json
12
+ return { "progress" => ProcessManager.instance.find(params[:class]).progress }.to_json
13
+ end
14
+
15
+ post '/processes/:id' do |id|
16
+ ProcessManager.instance.interrupt(id)
17
+ end
18
+
19
+ post '/process' do
20
+ a_handler = ProcessManager.instance.run(params)
21
+ a_handler.to_json
22
+ end
23
+ end
24
+
25
+ end
26
+ register ProcessesHandler
27
+ end
28
+
@@ -2,7 +2,6 @@
2
2
  require_relative 'libraries'
3
3
  require_relative 'inputs'
4
4
  require_relative 'charts'
5
- require_relative 'subscriptions'
6
5
  require_relative 'cas'
7
6
  require_relative 'schedule'
8
7
  require_relative 'alerts'
@@ -2,11 +2,13 @@
2
2
  - required = false
3
3
  - if !(defined? id) || id.blank?
4
4
  - id = "#{name}_#{rand(1000)}"
5
+ - unless defined? clazz
6
+ - clazz = nil
5
7
 
6
8
  .form-group.fg-float
7
9
  label #{title}
8
10
  .fg-line
9
11
  -if required
10
- input.form-control.date-picker.fg-input id="#{id}" type="text" name="#{name}" required="" value="#{value}"
12
+ input.form-control.date-picker.fg-input id="#{id}" type="text" name="#{name}" required="" class="#{clazz}" value="#{value}"
11
13
  -else
12
- input.form-control.date-picker.fg-input id="#{id}" type="text" name="#{name}" value="#{value}"
14
+ input.form-control.date-picker.fg-input id="#{id}" type="text" name="#{name}" class="#{clazz}" value="#{value}"
@@ -6,14 +6,25 @@
6
6
  - placeholder = "..."
7
7
  -unless defined? onkeyup
8
8
  -onkeyup = ''
9
+ -unless defined? readonly
10
+ -readonly = false
11
+ - unless defined? clazz
12
+ - clazz = nil
9
13
 
10
14
  -if required
11
15
  .form-group.has-feedback.has-success
12
16
  label #{title}
13
17
  .fg-line
14
- input.form-control.fg-input id="#{id}" type="#{type}" placeholder=("#{placeholder}") name="#{name}" required="" value="#{value}" onkeyup="#{onkeyup}"
18
+ -if readonly
19
+ input.form-control.fg-input id="#{id}" type="#{type}" placeholder="#{placeholder}" name="#{name}" required="" value="#{value}" class="#{clazz}" onkeyup="#{onkeyup}" readonly=''
20
+ -else
21
+ input.form-control.fg-input id="#{id}" type="#{type}" placeholder="#{placeholder}" name="#{name}" required="" value="#{value}" class="#{clazz}" onkeyup="#{onkeyup}"
22
+
15
23
  -else
16
24
  .form-group
17
25
  label #{title}
18
26
  .fg-line
19
- input.form-control.fg-input id="#{id}" type="#{type}" placeholder=("#{placeholder}") name="#{name}" value="#{value}" onkeyup="#{onkeyup}"
27
+ -if readonly
28
+ input.form-control.fg-input id="#{id}" type="#{type}" placeholder="#{placeholder}" name="#{name}" value="#{value}" onkeyup="#{onkeyup}" class="#{clazz}" readonly=''
29
+ -else
30
+ input.form-control.fg-input id="#{id}" type="#{type}" placeholder="#{placeholder}" name="#{name}" value="#{value}" onkeyup="#{onkeyup}" class="#{clazz}"
@@ -4,7 +4,8 @@
4
4
  - id = "#{name}_#{rand(1000)}"
5
5
  - unless defined? placeholder
6
6
  - placeholder = "Selecciona..."
7
-
7
+ - unless defined? clazz
8
+ - clazz = nil
8
9
  - unless defined? selected_elements
9
10
  - selected_elements = []
10
11
  - if selected_elements.nil?
@@ -14,7 +15,7 @@
14
15
  -if required
15
16
  .form-group.has-success
16
17
  label.fg-label #{placeholder}
17
- select.chosen id="#{id}" name="#{name}[]" data-placeholder=("#{placeholder}") chosen="" multiple="" style=("display: none;") required=""
18
+ select.chosen id="#{id}" class="#{clazz}" name="#{name}[]" data-placeholder=("#{placeholder}") chosen="" multiple="" style=("display: none;") required=""
18
19
  -for element in elements
19
20
  -if selected_elements.include?(element[:value].to_s)
20
21
  option value="#{element[:value]}" selected="" #{element[:text]}
@@ -6,12 +6,13 @@
6
6
  - placeholder = "Selecciona..."
7
7
  - unless defined? chosen
8
8
  - chosen = nil
9
-
9
+ - unless defined? clazz
10
+ - clazz = nil
10
11
 
11
12
  -if required
12
13
  .form-group.has-success
13
14
  label #{placeholder}
14
- select.chosen.form-control id="#{id}" name="#{name}" data-placeholder=("#{placeholder}") style=("display: none;") required=""
15
+ select.chosen.form-control id="#{id}" class="#{clazz}" name="#{name}" data-placeholder=("#{placeholder}") style=("display: none;") required=""
15
16
  -for element in elements
16
17
  -if chosen == element[:value]
17
18
  option value="#{element[:value]}" selected="" #{element[:text]}
@@ -21,7 +22,7 @@
21
22
  -else
22
23
  .form-group
23
24
  label #{placeholder}
24
- select.chosen id="#{id}" name="#{name}" data-placeholder=("#{placeholder}") style=("display: none;")
25
+ select.chosen id="#{id}" class="#{clazz}" name="#{name}" data-placeholder=("#{placeholder}") style=("display: none;")
25
26
  -for element in elements
26
27
  -if chosen == element[:value]
27
28
  option value="#{element[:value]}" selected="" #{element[:text]}
@@ -11,6 +11,6 @@
11
11
  .fg-line
12
12
  label.fg-label #{title}
13
13
  - if required
14
- textarea.form-control name="#{name}" placeholder=("#{placeholder}") rows="#{rows}" maxlength="#{length}" required="" #{value}
14
+ textarea.form-control id="#{id}" name="#{name}" placeholder=("#{placeholder}") rows="#{rows}" maxlength="#{length}" required="" #{value}
15
15
  - else
16
- textarea.form-control name="#{name}" placeholder=("#{placeholder}") rows="#{rows}" maxlength="#{length}" #{value}
16
+ textarea.form-control id="#{id}" name="#{name}" placeholder=("#{placeholder}") rows="#{rows}" maxlength="#{length}" #{value}
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: 0.3.6
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Zanger
@@ -67,10 +67,12 @@ files:
67
67
  - lib/sinatra/extensions/mailbuilder.rb
68
68
  - lib/sinatra/extensions/mailsender.rb
69
69
  - lib/sinatra/extensions/notification.rb
70
+ - lib/sinatra/extensions/processmanager.rb
70
71
  - lib/sinatra/handlers/errors.rb
71
72
  - lib/sinatra/handlers/init.rb
72
73
  - lib/sinatra/handlers/notifications.rb
73
74
  - lib/sinatra/handlers/params.rb
75
+ - lib/sinatra/handlers/processes.rb
74
76
  - lib/sinatra/handlers/reports.rb
75
77
  - lib/sinatra/helpers/alerts.rb
76
78
  - lib/sinatra/helpers/cas.rb
@@ -80,7 +82,6 @@ files:
80
82
  - lib/sinatra/helpers/libraries.rb
81
83
  - lib/sinatra/helpers/reports.rb
82
84
  - lib/sinatra/helpers/schedule.rb
83
- - lib/sinatra/helpers/subscriptions.rb
84
85
  - lib/sinatra/hexacta.rb
85
86
  - lib/sinatra/public/css/app.min.1.css
86
87
  - lib/sinatra/public/css/app.min.2.css
@@ -1,44 +0,0 @@
1
- # encoding: utf-8
2
- module Sinatra
3
- module SubscriptionHelper
4
-
5
- def notify_to(user,creator,title,message,label,link=nil)
6
- notification = Notification.find_or_create(:user_id => user.id,
7
- :creator_id => creator.id,
8
- :title => title,
9
- :message => message,
10
- :label => label,
11
- :link => link,
12
- :creation_date => Date.today)
13
- if link.nil?
14
- notification.link = "/notifications/#{notification.id}"
15
- notification.save
16
- end
17
- notification
18
- end
19
-
20
- def notify(creator,title,message,label,link=nil)
21
- Subscription.where(:label => label).all.each do |subscription|
22
- notification = notify_to(subscription.user,creator,title,message,label,link)
23
- end
24
- end
25
-
26
- def notify_error(creator,title,message)
27
- Subscription.where(:label => 'error').all.each do |subscription|
28
- creator = subscription.user if creator.nil?
29
- notification = Notification.find(:user_id => subscription.user_id,
30
- :creator_id => creator.id,
31
- :title => title,
32
- :message => message,
33
- :label => 'error',
34
- :read_date => nil)
35
- if notification.nil?
36
- notification = notify_to(subscription.user,creator,title,message,'error')
37
- end
38
- end
39
-
40
- end
41
- end
42
-
43
- helpers SubscriptionHelper
44
- end