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 +4 -4
- data/lib/sinatra/extensions/init.rb +1 -0
- data/lib/sinatra/extensions/processmanager.rb +106 -0
- data/lib/sinatra/handlers/init.rb +2 -1
- data/lib/sinatra/handlers/processes.rb +28 -0
- data/lib/sinatra/helpers/init.rb +0 -1
- data/lib/sinatra/public/js/app.js +1 -1
- data/lib/sinatra/views/inputs/input.slim +13 -2
- data/lib/sinatra/views/inputs/multiple_select.slim +3 -2
- data/lib/sinatra/views/inputs/select.slim +4 -3
- data/lib/sinatra/views/inputs/textarea.slim +2 -2
- metadata +3 -2
- data/lib/sinatra/helpers/subscriptions.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a30ba69a60abe8d2c4d4759c82edf7afd5d079a7dc4e1b9fa44f4de0ca9ec141
|
4
|
+
data.tar.gz: b818302b6ff34967f195d6e59d67b65feafa6e1de6ab41747b64cb6550cf30ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e45db2dad9dc2c44115290af7f7dc3d2edc9756f8ead2f7a3c3ede018ef779b61bcb911e49f4d760bdbc164b58506663c533dc15e79a1bcd77581c94bbd5752
|
7
|
+
data.tar.gz: 8f71f3b2d0fda29e8c26a48d45968e2ad2822d030d3549c11ada3201494bd4082458f91387253e4bb140e4582db413325cf4689c6c170578f60ef42cdd404ce5
|
@@ -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
|
@@ -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
|
+
|
data/lib/sinatra/helpers/init.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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.
|
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
|