luck_remover 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/luck_remover/goals_controller.rb +23 -5
- data/app/models/luck_remover/goal.rb +1 -0
- data/app/views/luck_remover/goals/edit.html.erb +2 -2
- data/app/views/luck_remover/goals/index.html.erb +3 -2
- data/app/views/luck_remover/goals/new.html.erb +1 -1
- data/lib/luck_remover/metric_registry.rb +7 -1
- data/lib/luck_remover/version.rb +1 -1
- data/lib/luck_remover.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aafbd78e90cb21bdd20ca01473fa1a1632c8306542c35cd6872fa84e7c999fd8
|
|
4
|
+
data.tar.gz: 041f0bee7cd3feb2c65196bbd39d15967af0e359ea858241b5898dbcc54fe7d8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fadad526b3e0c6289f5ea0c2534730e054695043da13f86b1820070569b6479fb7160749d75e1b103945659f85bd6ea5c8b307447fba2e75fdc5f5d3dc2900c1
|
|
7
|
+
data.tar.gz: 855c26cd1682e3f87c34d0206ed65876ecba06443dc05949a01992a50509b2d511c0ad66361cf76a1f04be67de3988f98aa3f03cfcc7953124180ddd542ce4b2
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
module LuckRemover
|
|
2
2
|
class GoalsController < LuckRemover.parent_controller.constantize
|
|
3
|
+
helper_method :page_query
|
|
4
|
+
|
|
3
5
|
def index
|
|
4
|
-
@goals =
|
|
6
|
+
@goals = goals_in_area.order(:name)
|
|
5
7
|
@person_names = LuckRemover.people(current_goal_owner).to_h { |label, id| [ id, label ] }
|
|
6
8
|
end
|
|
7
9
|
|
|
@@ -12,7 +14,7 @@ module LuckRemover
|
|
|
12
14
|
|
|
13
15
|
def create
|
|
14
16
|
@goal = goal_scope.new(goal_params)
|
|
15
|
-
return redirect_to
|
|
17
|
+
return redirect_to after_change_path if @goal.save
|
|
16
18
|
|
|
17
19
|
load_choices
|
|
18
20
|
render :new, status: :unprocessable_content
|
|
@@ -25,7 +27,7 @@ module LuckRemover
|
|
|
25
27
|
|
|
26
28
|
def update
|
|
27
29
|
@goal = goal_scope.find(params[:id])
|
|
28
|
-
return redirect_to
|
|
30
|
+
return redirect_to after_change_path if @goal.update(goal_params)
|
|
29
31
|
|
|
30
32
|
load_choices
|
|
31
33
|
render :edit, status: :unprocessable_content
|
|
@@ -33,13 +35,13 @@ module LuckRemover
|
|
|
33
35
|
|
|
34
36
|
def destroy
|
|
35
37
|
goal_scope.find(params[:id]).destroy!
|
|
36
|
-
redirect_to
|
|
38
|
+
redirect_to after_change_path
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
private
|
|
40
42
|
|
|
41
43
|
def load_choices
|
|
42
|
-
@metrics = LuckRemover.metrics.all
|
|
44
|
+
@metrics = area ? LuckRemover.metrics.in_area(area) : LuckRemover.metrics.all
|
|
43
45
|
@people = LuckRemover.people(current_goal_owner)
|
|
44
46
|
end
|
|
45
47
|
|
|
@@ -54,5 +56,21 @@ module LuckRemover
|
|
|
54
56
|
def goal_scope
|
|
55
57
|
Goal.for_owner(current_goal_owner)
|
|
56
58
|
end
|
|
59
|
+
|
|
60
|
+
def goals_in_area
|
|
61
|
+
area ? goal_scope.in_area(area) : goal_scope
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def page_query
|
|
65
|
+
params.permit(:area, :return_to).to_h.compact_blank.symbolize_keys
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def after_change_path
|
|
69
|
+
url_from(params[:return_to]) || goals_path
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def area
|
|
73
|
+
params[:area].presence
|
|
74
|
+
end
|
|
57
75
|
end
|
|
58
76
|
end
|
|
@@ -5,6 +5,7 @@ module LuckRemover
|
|
|
5
5
|
belongs_to :owner, polymorphic: true
|
|
6
6
|
|
|
7
7
|
scope :for_owner, ->(owner) { where(owner: owner) }
|
|
8
|
+
scope :in_area, ->(area) { where(metric_key: LuckRemover.metrics.in_area(area).map { |stat| stat.key.to_s }) }
|
|
8
9
|
|
|
9
10
|
enum :direction, { at_least: "at_least", at_most: "at_most" }, validate: true
|
|
10
11
|
enum :period, { week: "week", month: "month" }, validate: true
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<%= ui_form_page(title: "Edit", subtitle: @goal.name) %>
|
|
2
2
|
<%= ui_page(max_width: :md) do %>
|
|
3
|
-
<%= ui_form(action: luck_remover.goal_path(@goal), method: :patch) do %>
|
|
3
|
+
<%= ui_form(action: luck_remover.goal_path(@goal, **page_query), method: :patch) do %>
|
|
4
4
|
<%= render "luck_remover/goals/form", goal: @goal, metrics: @metrics, people: @people %>
|
|
5
5
|
<%= ui_button(label: "Save") %>
|
|
6
6
|
<% end %>
|
|
7
7
|
<%= ui_action_menu do %>
|
|
8
|
-
<%= ui_action_menu_item(label: "Delete", href: luck_remover.goal_path(@goal), method: :delete) %>
|
|
8
|
+
<%= ui_action_menu_item(label: "Delete", href: luck_remover.goal_path(@goal, **page_query), method: :delete) %>
|
|
9
9
|
<% end %>
|
|
10
10
|
<% end %>
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
<%= ui_show_page(title: "Goals") %>
|
|
2
|
+
<% new_goal_path = luck_remover.new_goal_path(area: params[:area].presence) %>
|
|
2
3
|
<%= ui_page(max_width: :xl) do %>
|
|
3
|
-
<%= ui_page_header(title: "Goals", action_url:
|
|
4
|
+
<%= ui_page_header(title: "Goals", action_url: new_goal_path, action_label: "Add") do |header| %>
|
|
4
5
|
<% header.action do %>
|
|
5
|
-
<%= ui_button(label: "Add", href:
|
|
6
|
+
<%= ui_button(label: "Add", href: new_goal_path) %>
|
|
6
7
|
<% end %>
|
|
7
8
|
<% end %>
|
|
8
9
|
<% rows = @goals.map do |goal|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%= ui_form_page(title: "Add goal") %>
|
|
2
2
|
<%= ui_page(max_width: :md) do %>
|
|
3
|
-
<%= ui_form(action: luck_remover.goals_path) do %>
|
|
3
|
+
<%= ui_form(action: luck_remover.goals_path(**page_query)) do %>
|
|
4
4
|
<%= render "luck_remover/goals/form", goal: @goal, metrics: @metrics, people: @people %>
|
|
5
5
|
<%= ui_button(label: "Create") %>
|
|
6
6
|
<% end %>
|
|
@@ -7,13 +7,15 @@ module LuckRemover
|
|
|
7
7
|
def initialize
|
|
8
8
|
@stats = {}
|
|
9
9
|
@per_person = Set.new
|
|
10
|
+
@areas = {}
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
def register(stat, per_person: false)
|
|
13
|
+
def register(stat, per_person: false, area: nil)
|
|
13
14
|
key = stat.key.to_sym
|
|
14
15
|
raise DuplicateMetricError, "A goal metric is already registered under #{key}" if registered?(key)
|
|
15
16
|
|
|
16
17
|
@per_person << key if per_person
|
|
18
|
+
@areas[key] = area.to_sym if area
|
|
17
19
|
@stats[key] = stat
|
|
18
20
|
end
|
|
19
21
|
|
|
@@ -29,6 +31,10 @@ module LuckRemover
|
|
|
29
31
|
@stats.values
|
|
30
32
|
end
|
|
31
33
|
|
|
34
|
+
def in_area(area)
|
|
35
|
+
@stats.values_at(*@areas.select { |_key, name| name == area.to_sym }.keys)
|
|
36
|
+
end
|
|
37
|
+
|
|
32
38
|
def fetch(key)
|
|
33
39
|
@stats.fetch(key.to_sym)
|
|
34
40
|
end
|
data/lib/luck_remover/version.rb
CHANGED
data/lib/luck_remover.rb
CHANGED
|
@@ -20,8 +20,8 @@ module LuckRemover
|
|
|
20
20
|
@metrics ||= MetricRegistry.new
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
def self.register_metric(stat, per_person: false)
|
|
24
|
-
metrics.register(stat, per_person: per_person)
|
|
23
|
+
def self.register_metric(stat, per_person: false, area: nil)
|
|
24
|
+
metrics.register(stat, per_person: per_person, area: area)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def self.metric(key)
|