circuit_switch 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +21 -1
- data/app/controllers/circuit_switch/application_controller.rb +5 -0
- data/app/controllers/circuit_switch/circuit_switch_controller.rb +40 -0
- data/app/views/circuit_switch/circuit_switch/edit.html.erb +129 -0
- data/app/views/circuit_switch/circuit_switch/index.html.erb +83 -0
- data/app/views/layouts/circuit_switch/application.html.erb +16 -0
- data/circuit_switch.png +0 -0
- data/config/routes.rb +4 -0
- data/lib/circuit_switch/engine.rb +9 -0
- data/lib/circuit_switch/version.rb +1 -1
- data/lib/circuit_switch.rb +1 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5700c391d205790305cce8ed4d213f694deeaa8883d10d6b8e48a47de7d8f7e
|
4
|
+
data.tar.gz: acee1e59d6da803a085f399c39ef72099dc3d70a49f270fcb1dd1d0c49c1cf40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7cfad2c3e41054235f8546f68d01945c387b196b0f1bb11290eb4f3a61da6477c422f347aee3ac87645fe6d841c585052a8cbe1ec3c835a97d683509ea77933
|
7
|
+
data.tar.gz: 92a77c9ae39c41ba59fb4cfd021b359169cbbc0d0b604ab00a258cad7fcd7fae0348b0bd9d9ac51b7e199fb33d8b17f39314a030cd6e70b89fa300e57a818162
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
## 0.5.0
|
2
|
+
|
3
|
+
### New features
|
4
|
+
|
5
|
+
* GUI has been released!
|
6
|
+
If you are on Rails, add the following to your `config/routes.rb` and access `/circuit_switch`.
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
Rails.application.routes.draw do
|
10
|
+
mount CircuitSwitch::Engine => 'circuit_switch'
|
11
|
+
end
|
12
|
+
```
|
13
|
+
|
1
14
|
## 0.4.1
|
2
15
|
|
3
16
|
* Fix bug `if` `stop_report_if_reach_limit` options don't receive `false`.
|
data/README.md
CHANGED
@@ -180,7 +180,27 @@ By default, due_date is 10 days after today. To modify, set `due_date` to initia
|
|
180
180
|
|
181
181
|
## GUI to manage switches
|
182
182
|
|
183
|
-
|
183
|
+
![GUI](circuit_switch.png)
|
184
|
+
|
185
|
+
GUI is now only for Rails.
|
186
|
+
Add the following to your `config/routes.rb` and access `/circuit_switch`.
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
Rails.application.routes.draw do
|
190
|
+
mount CircuitSwitch::Engine => 'circuit_switch'
|
191
|
+
end
|
192
|
+
```
|
193
|
+
|
194
|
+
### Authentication
|
195
|
+
|
196
|
+
In production, you may need access protection.
|
197
|
+
With Devise, code goes like:
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
authenticate :user, lambda { |user| user.admin? } do
|
201
|
+
mount CircuitSwitch::Engine => 'circuit_switch'
|
202
|
+
end
|
203
|
+
```
|
184
204
|
|
185
205
|
## Contributing
|
186
206
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_dependency 'circuit_switch/application_controller'
|
2
|
+
|
3
|
+
module CircuitSwitch
|
4
|
+
class CircuitSwitchController < ::CircuitSwitch::ApplicationController
|
5
|
+
def index
|
6
|
+
@circuit_switches = ::CircuitSwitch::CircuitSwitch.all.order(order_by)
|
7
|
+
end
|
8
|
+
|
9
|
+
def edit
|
10
|
+
@circuit_switch = ::CircuitSwitch::CircuitSwitch.find(params[:id])
|
11
|
+
end
|
12
|
+
|
13
|
+
def update
|
14
|
+
@circuit_switch = ::CircuitSwitch::CircuitSwitch.find(params[:id])
|
15
|
+
if @circuit_switch.update circuit_switch_params
|
16
|
+
flash[:success] = "Switch for `#{@circuit_switch.key}` is successfully updated."
|
17
|
+
redirect_to circuit_switch_index_path
|
18
|
+
else
|
19
|
+
render :edit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def destroy
|
24
|
+
@circuit_switch = ::CircuitSwitch::CircuitSwitch.find(params[:id])
|
25
|
+
@circuit_switch.destroy!
|
26
|
+
flash[:success] = "Switch for `#{@circuit_switch.key}` is successfully destroyed."
|
27
|
+
redirect_to circuit_switch_index_path
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def order_by
|
33
|
+
params[:order_by].in?(%w[id due_date]) ? params[:order_by] : 'id'
|
34
|
+
end
|
35
|
+
|
36
|
+
def circuit_switch_params
|
37
|
+
params.require(:circuit_switch).permit(:key, :caller, :run_count, :run_limit_count, :run_is_terminated, :report_count, :report_limit_count, :report_is_terminated, :due_date)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
<h1 class="p-3 fw-light">Edit switch</h1>
|
2
|
+
|
3
|
+
<div class="container">
|
4
|
+
<% if @circuit_switch.errors.any? %>
|
5
|
+
<div class="alert alert-danger">
|
6
|
+
<ul class="mb-0">
|
7
|
+
<% @circuit_switch.errors.full_messages.each do |message| %>
|
8
|
+
<li><%= message %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<%= form_with(model: @circuit_switch, local: true) do |form| %>
|
15
|
+
<div class="fw-light">
|
16
|
+
<div class="py-1 row">
|
17
|
+
<div class="col-10 mt-auto">
|
18
|
+
id: <%= @circuit_switch.id %>
|
19
|
+
<span class="px-4 text-muted">
|
20
|
+
created_at: <%= @circuit_switch.created_at %> /
|
21
|
+
updated_at: <%= @circuit_switch.updated_at %>
|
22
|
+
</span>
|
23
|
+
</div>
|
24
|
+
<div class="col-2 text-end">
|
25
|
+
<%= link_to 'Back', circuit_switch_index_path, class: 'btn btn-outline-dark' %>
|
26
|
+
</div>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div class="py-1">
|
30
|
+
<div class="py-1">
|
31
|
+
<%= form.label :key, 'key:', class: 'form-label' %>
|
32
|
+
<%= form.text_area :key, class: 'form-control font-monospace' %>
|
33
|
+
</div>
|
34
|
+
<div class="py-1">
|
35
|
+
<%= form.label :caller, 'caller:', class: 'form-label' %>
|
36
|
+
<%= form.text_area :caller, class: 'form-control font-monospace' %>
|
37
|
+
</div>
|
38
|
+
</div>
|
39
|
+
|
40
|
+
<div class="py-1">
|
41
|
+
<div class="py-2 row">
|
42
|
+
<%= form.label :run_is_terminated, 'run_mode:', class: 'col-sm-2 col-form-label' %>
|
43
|
+
<div class="col-sm-2">
|
44
|
+
<%= form.select :run_is_terminated, { open: false, closed: true }, { selected: @circuit_switch.run_is_terminated }, { class: ['form-select', (@circuit_switch.run_is_terminated ? 'alert-dark' : 'alert-primary')] } %>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
<div class="py-2 row">
|
48
|
+
<div class="col-sm-2">
|
49
|
+
<%= form.label :run_count, 'run_count:', class: 'col-form-label' %>
|
50
|
+
<i class="fas fa-info-circle text-black-50 align-baseline px-1" data-bs-toggle="tooltip" data-bs-placement="top" title="Increment only when run_mode is open"></i>
|
51
|
+
</div>
|
52
|
+
<div class="col-sm-2">
|
53
|
+
<%= form.text_field :run_count, class: 'form-control' %>
|
54
|
+
</div>
|
55
|
+
</div>
|
56
|
+
<div class="py-2 row">
|
57
|
+
<div class="col-sm-2">
|
58
|
+
<%= form.label :run_limit_count, 'run_limit_count:', class: 'col-form-label' %>
|
59
|
+
<i class="fas fa-info-circle text-black-50 align-baseline px-1" data-bs-toggle="tooltip" data-bs-placement="top" title="Reference only when call with `close_if_reach_limit` true"></i>
|
60
|
+
</div>
|
61
|
+
<div class="col-sm-2">
|
62
|
+
<%= form.text_field :run_limit_count, class: 'form-control' %>
|
63
|
+
</div>
|
64
|
+
</div>
|
65
|
+
<div class="py-2 row">
|
66
|
+
<%= form.label :report_is_terminated, 'report_mode:', class: 'col-sm-2 col-sm-2 col-form-label' %>
|
67
|
+
<div class="col-sm-2">
|
68
|
+
<%= form.select :report_is_terminated, { reporting: false, terminated: true }, { selected: @circuit_switch.report_is_terminated }, { class: ['form-select', (@circuit_switch.report_is_terminated ? 'alert-dark' : 'alert-primary')] } %>
|
69
|
+
</div>
|
70
|
+
</div>
|
71
|
+
<div class="py-2 row">
|
72
|
+
<div class="col-sm-2">
|
73
|
+
<%= form.label :report_count, 'report_count:', class: 'col-form-label' %>
|
74
|
+
<i class="fas fa-info-circle text-black-50 align-baseline px-1" data-bs-toggle="tooltip" data-bs-placement="top" title="Increment only when report_mode is reporting"></i>
|
75
|
+
</div>
|
76
|
+
<div class="col-sm-2">
|
77
|
+
<%= form.text_field :report_count, class: 'form-control' %>
|
78
|
+
</div>
|
79
|
+
</div>
|
80
|
+
<div class="py-2 row">
|
81
|
+
<div class="col-sm-2">
|
82
|
+
<%= form.label :report_limit_count, 'report_limit_count:', class: 'col-form-label' %>
|
83
|
+
<i class="fas fa-info-circle text-black-50 align-baseline px-1" data-bs-toggle="tooltip" data-bs-placement="top" title="Reference only when call with `stop_report_if_reach_limit` true"></i>
|
84
|
+
</div>
|
85
|
+
<div class="col-sm-2">
|
86
|
+
<%= form.text_field :report_limit_count, class: 'form-control' %>
|
87
|
+
</div>
|
88
|
+
</div>
|
89
|
+
</div>
|
90
|
+
|
91
|
+
<div class="py-1">
|
92
|
+
<div class="py-2 row">
|
93
|
+
<div class="col-sm-2">
|
94
|
+
<%= form.label :due_date, 'due_date:', class: 'col-form-label' %>
|
95
|
+
<i class="fas fa-info-circle text-black-50 align-baseline px-1" data-bs-toggle="tooltip" data-bs-placement="top" title="Date to remove switch"></i>
|
96
|
+
</div>
|
97
|
+
<div class="col-sm-2">
|
98
|
+
<%= form.text_field :due_date, class: 'form-control' %>
|
99
|
+
</div>
|
100
|
+
</div>
|
101
|
+
</div>
|
102
|
+
|
103
|
+
<div class="py-2">
|
104
|
+
<%= form.submit 'update', class: 'btn btn-dark' %>
|
105
|
+
</div>
|
106
|
+
</div>
|
107
|
+
<% end %>
|
108
|
+
|
109
|
+
<%= button_to 'delete', circuit_switch_path(@circuit_switch), method: :delete, class: 'btn btn-danger btn-destroy' %>
|
110
|
+
</div>
|
111
|
+
|
112
|
+
<script>
|
113
|
+
$('select').on('change', function() {
|
114
|
+
style = $(this).val() == 'true' ? 'alert-dark' : 'alert-primary'
|
115
|
+
$(this).removeClass('alert-primary alert-dark')
|
116
|
+
$(this).addClass(style)
|
117
|
+
})
|
118
|
+
|
119
|
+
$('.btn-destroy').on('click', function (event) {
|
120
|
+
if (!window.confirm('Are you sure to destroy?')) {
|
121
|
+
event.preventDefault()
|
122
|
+
}
|
123
|
+
})
|
124
|
+
|
125
|
+
tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
|
126
|
+
tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
|
127
|
+
return new bootstrap.Tooltip(tooltipTriggerEl)
|
128
|
+
})
|
129
|
+
</script>
|
@@ -0,0 +1,83 @@
|
|
1
|
+
<h1 class="p-3 fw-light">
|
2
|
+
circuit_switch <i class="fas fa-xs fa-toggle-on text-warning"></i>
|
3
|
+
</h1>
|
4
|
+
|
5
|
+
<div class="container">
|
6
|
+
<% if flash[:success].present? %>
|
7
|
+
<div class="alert alert-info"><%= flash[:success] %></div>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<div class="dropdown py-2 text-end">
|
11
|
+
<a class="btn btn-sm btn-outline-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-bs-toggle="dropdown" aria-expanded="false">
|
12
|
+
<%= params[:order_by] == 'due_date' ? 'due date ordered' : 'id ordered' %>
|
13
|
+
</a>
|
14
|
+
|
15
|
+
<ul class="dropdown-menu" aria-labelledby="dropdownMenuLink">
|
16
|
+
<li><%= link_to 'id ordered', circuit_switch_index_path(order_by: :id), class: 'dropdown-item' %></li>
|
17
|
+
<li><%= link_to 'due date ordered', circuit_switch_index_path(order_by: :due_date), class: 'dropdown-item' %></li>
|
18
|
+
</ul>
|
19
|
+
</div>
|
20
|
+
|
21
|
+
<table class="table table-striped table-hover striped-primary table-bordered border fw-light">
|
22
|
+
<thead class="table-dark border border-dark">
|
23
|
+
<tr>
|
24
|
+
<th scope="col" class="px-3 py-4 fw-light text-center">id</th>
|
25
|
+
<th scope="col" class="px-3 py-4 fw-light">key</th>
|
26
|
+
<th scope="col" class="px-3 py-4 fw-light">caller</th>
|
27
|
+
<th scope="col" class="px-1 py-4 fw-light">due_date</th>
|
28
|
+
<th scope="col" class="px-3 py-4 fw-light text-center">run</th>
|
29
|
+
<th scope="col" class="px-3 py-4 fw-light text-center">report</th>
|
30
|
+
<th scope="col" class="px-3 py-4 fw-light text-center">show/edit</th>
|
31
|
+
<th scope="col" class="px-3 py-4 fw-light text-center">destroy</th>
|
32
|
+
</tr>
|
33
|
+
</thead>
|
34
|
+
|
35
|
+
<tbody>
|
36
|
+
<% @circuit_switches.each do |circuit_switch| %>
|
37
|
+
<tr>
|
38
|
+
<td class="text-center align-middle"><%= circuit_switch.id %></td>
|
39
|
+
<td class="text-break small font-monospace"><%= circuit_switch.key %></td>
|
40
|
+
<td class="text-break small font-monospace"><%= circuit_switch.caller %></td>
|
41
|
+
<td class="text-nowrap"><%= circuit_switch.due_date %></td>
|
42
|
+
<td class="text-center align-middle">
|
43
|
+
<% if circuit_switch.run_is_terminated %>
|
44
|
+
<i class="fas fa-lg fa-ban text-muted" data-bs-toggle="tooltip" data-bs-placement="top" title="closed mode"></i>
|
45
|
+
<% else %>
|
46
|
+
<i class="fas fa-lg fa-walking " data-bs-toggle="tooltip" data-bs-placement="top" title="opened mode"></i>
|
47
|
+
<% end %>
|
48
|
+
</td>
|
49
|
+
<td class="text-center align-middle">
|
50
|
+
<% if circuit_switch.report_is_terminated %>
|
51
|
+
<i class="fas fa-lg fa-ban text-muted" data-bs-toggle="tooltip" data-bs-placement="top" title="terminated mode"></i>
|
52
|
+
<% else %>
|
53
|
+
<i class="fas fa-lg fa-bullhorn " data-bs-toggle="tooltip" data-bs-placement="top" title="reporting mode"></i>
|
54
|
+
<% end %>
|
55
|
+
</td>
|
56
|
+
<td class="text-center align-middle py-3">
|
57
|
+
<%= button_to edit_circuit_switch_path(circuit_switch), method: :get, class: 'btn btn-outline-dark' do %>
|
58
|
+
<i class="fas fa-edit"></i>
|
59
|
+
<% end %>
|
60
|
+
</td>
|
61
|
+
<td class="text-center align-middle py-3">
|
62
|
+
<%= button_to circuit_switch_path(circuit_switch), method: :delete, class: 'btn btn-danger btn-destroy' do %>
|
63
|
+
<i class="fas fa-broom"></i>
|
64
|
+
<% end %>
|
65
|
+
</td>
|
66
|
+
</tr>
|
67
|
+
<% end %>
|
68
|
+
</tbody>
|
69
|
+
</table>
|
70
|
+
</div>
|
71
|
+
|
72
|
+
<script>
|
73
|
+
$('.btn-destroy').on('click', function (event) {
|
74
|
+
if (!window.confirm('Are you sure to destroy?')) {
|
75
|
+
event.preventDefault()
|
76
|
+
}
|
77
|
+
})
|
78
|
+
|
79
|
+
tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
|
80
|
+
tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
|
81
|
+
return new bootstrap.Tooltip(tooltipTriggerEl)
|
82
|
+
})
|
83
|
+
</script>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset='utf-8'>
|
5
|
+
<title>circuit_switch</title>
|
6
|
+
<%= csrf_meta_tags %>
|
7
|
+
<%= csp_meta_tag %>
|
8
|
+
<%= javascript_include_tag 'https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js', integrity: 'sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW', crossorigin: 'anonymous' %>
|
9
|
+
<%= javascript_include_tag 'https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js' %>
|
10
|
+
<%= javascript_include_tag 'https://kit.fontawesome.com/3e20336786.js', crossorigin: 'anonymous' %>
|
11
|
+
<%= stylesheet_link_tag 'https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css', media: 'all', integrity: 'sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1', crossorigin: 'anonymous' %>
|
12
|
+
</head>
|
13
|
+
<body>
|
14
|
+
<%= yield %>
|
15
|
+
</body>
|
16
|
+
</html>
|
data/circuit_switch.png
ADDED
Binary file
|
data/config/routes.rb
ADDED
data/lib/circuit_switch.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative 'circuit_switch/configuration'
|
2
2
|
require_relative 'circuit_switch/builder'
|
3
3
|
require_relative 'circuit_switch/orm/active_record/circuit_switch'
|
4
|
+
require_relative 'circuit_switch/engine' if defined?(Rails)
|
4
5
|
require_relative 'circuit_switch/railtie' if defined?(Rails::Railtie)
|
5
6
|
require_relative 'circuit_switch/version'
|
6
7
|
require_relative 'circuit_switch/workers/due_date_notifier'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circuit_switch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- makicamel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -124,13 +124,21 @@ files:
|
|
124
124
|
- LICENSE.txt
|
125
125
|
- README.md
|
126
126
|
- Rakefile
|
127
|
+
- app/controllers/circuit_switch/application_controller.rb
|
128
|
+
- app/controllers/circuit_switch/circuit_switch_controller.rb
|
129
|
+
- app/views/circuit_switch/circuit_switch/edit.html.erb
|
130
|
+
- app/views/circuit_switch/circuit_switch/index.html.erb
|
131
|
+
- app/views/layouts/circuit_switch/application.html.erb
|
127
132
|
- bin/console
|
128
133
|
- bin/setup
|
129
134
|
- circuit_switch.gemspec
|
135
|
+
- circuit_switch.png
|
136
|
+
- config/routes.rb
|
130
137
|
- lib/circuit_switch.rb
|
131
138
|
- lib/circuit_switch/builder.rb
|
132
139
|
- lib/circuit_switch/configuration.rb
|
133
140
|
- lib/circuit_switch/core.rb
|
141
|
+
- lib/circuit_switch/engine.rb
|
134
142
|
- lib/circuit_switch/notification.rb
|
135
143
|
- lib/circuit_switch/orm/active_record/circuit_switch.rb
|
136
144
|
- lib/circuit_switch/railtie.rb
|