sinatra-hexacta 0.3.5 → 0.3.10

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: dde8163291184a0486d85a908aac0803c8fcd82fd28a8d970e1b0696c7e8b654
4
- data.tar.gz: 6e654ceeefaff79b2d1566a9db49d19e71bc02eb119225b5bc22005252d7a1bd
3
+ metadata.gz: a30ba69a60abe8d2c4d4759c82edf7afd5d079a7dc4e1b9fa44f4de0ca9ec141
4
+ data.tar.gz: b818302b6ff34967f195d6e59d67b65feafa6e1de6ab41747b64cb6550cf30ea
5
5
  SHA512:
6
- metadata.gz: 6e54193cd5641d2daf0ad25019ca91ef1dab1f6a5898ab5baec12e6d828e86bb929a683377afb7334830ae6c0b7d83906aed2552a90507262e8a3093aa705977
7
- data.tar.gz: 5e8fd50c2dec2e8f2841cfb2a018efd9fb69ee58f70153c5a65b44194796584380ad1aef5e83eacc9a3ad79c3e0ffa37624bc600f93421b9ad441c4d3a320c96
6
+ metadata.gz: 0e45db2dad9dc2c44115290af7f7dc3d2edc9756f8ead2f7a3c3ede018ef779b61bcb911e49f4d760bdbc164b58506663c533dc15e79a1bcd77581c94bbd5752
7
+ data.tar.gz: 8f71f3b2d0fda29e8c26a48d45968e2ad2822d030d3549c11ada3201494bd4082458f91387253e4bb140e4582db413325cf4689c6c170578f60ef42cdd404ce5
@@ -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'
@@ -469,7 +469,7 @@ $(document).ready(function(){
469
469
  * Modal hide
470
470
  */
471
471
  $('.modal').bind('shown.bs.modal', function (e) {
472
- $(this).find(' type="submit"').attr("disabled",false);
472
+ $(this).find(':submit').attr("disabled",false);
473
473
  });
474
474
 
475
475
  });
@@ -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.5
4
+ version: 0.3.10
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