luck_remover 0.6.0 → 0.8.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 +3 -3
- data/app/models/luck_remover/goal.rb +1 -0
- data/app/models/luck_remover/reading.rb +17 -0
- data/app/models/luck_remover/standing.rb +17 -0
- data/app/views/luck_remover/goals/_form.html.erb +1 -0
- data/app/views/luck_remover/goals/index.html.erb +7 -4
- data/db/migrate/20261028142026_add_status_to_luck_remover_goals.rb +5 -0
- data/lib/luck_remover/version.rb +1 -1
- data/lib/luck_remover.rb +1 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 859d5f62571ed162fc9e8bc7753e3c436c25778e8d6258a0f08b46f1b11444c0
|
|
4
|
+
data.tar.gz: a760259b16892d3dd39561638d578ceeb55d649590a15d6161e7475687812a53
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1fad684b0accd4aebaab5c6ad5125797095594be8d117071e7f9bc139ecacdd7a9230e90c6b5fbc3cd91b8ca815c4cf4bbb2aa5b7a384da6ad18a63ae8450614
|
|
7
|
+
data.tar.gz: 22152fcc7bbb80f81f6582d366e9263a98eea550d3deed9fe744f938a49e23bbdf272ad8b62a30852addae64e010d0acb567216458937bf65b04a14f976c80f1
|
|
@@ -3,7 +3,7 @@ module LuckRemover
|
|
|
3
3
|
helper_method :page_query
|
|
4
4
|
|
|
5
5
|
def index
|
|
6
|
-
@
|
|
6
|
+
@readings = goals_in_area.order(:name).map { |goal| Reading.of(goal) }
|
|
7
7
|
@person_names = LuckRemover.people(current_goal_owner).to_h { |label, id| [ id, label ] }
|
|
8
8
|
end
|
|
9
9
|
|
|
@@ -50,7 +50,7 @@ module LuckRemover
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def goal_params
|
|
53
|
-
params.expect(goal: [ :name, :metric_key, :person_id, :target, :direction, :period ])
|
|
53
|
+
params.expect(goal: [ :name, :metric_key, :person_id, :target, :direction, :period, :status ])
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def goal_scope
|
|
@@ -62,7 +62,7 @@ module LuckRemover
|
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
def page_query
|
|
65
|
-
params.permit(:area, :return_to).to_h.compact_blank.symbolize_keys
|
|
65
|
+
params.permit(:area, :return_to, *LuckRemover.carried_params).to_h.compact_blank.symbolize_keys
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
def after_change_path
|
|
@@ -9,6 +9,7 @@ module LuckRemover
|
|
|
9
9
|
|
|
10
10
|
enum :direction, { at_least: "at_least", at_most: "at_most" }, validate: true
|
|
11
11
|
enum :period, { week: "week", month: "month" }, validate: true
|
|
12
|
+
enum :status, { draft: "draft", active: "active", achieved: "achieved", abandoned: "abandoned", paused: "paused" }, validate: true
|
|
12
13
|
|
|
13
14
|
validates :name, :target, presence: true
|
|
14
15
|
validate :metric_is_registered
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module LuckRemover
|
|
2
|
+
Reading = Data.define(:goal, :standing, :state) do
|
|
3
|
+
def self.of(goal, **inputs)
|
|
4
|
+
return new(goal: goal, standing: nil, state: :retired) unless LuckRemover.metrics.registered?(goal.metric_key.to_s)
|
|
5
|
+
return new(goal: goal, standing: nil, state: :untracked) unless goal.active? || goal.achieved?
|
|
6
|
+
|
|
7
|
+
new(goal: goal, standing: goal.standing(**inputs), state: :read)
|
|
8
|
+
rescue StandardError => error
|
|
9
|
+
Rails.error.report(error, context: { goal_metric: goal.metric_key })
|
|
10
|
+
new(goal: goal, standing: nil, state: :unread)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def retired? = state == :retired
|
|
14
|
+
|
|
15
|
+
def unread? = state == :unread
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -9,5 +9,22 @@ module LuckRemover
|
|
|
9
9
|
|
|
10
10
|
direction.to_s == "at_most" ? value <= target : value >= target
|
|
11
11
|
end
|
|
12
|
+
|
|
13
|
+
def progress
|
|
14
|
+
return unless measured?
|
|
15
|
+
return 100 if met?
|
|
16
|
+
|
|
17
|
+
at_most? ? percentage(target, value) : percentage(value, target)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def at_most?
|
|
23
|
+
direction.to_s == "at_most"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def percentage(part, whole)
|
|
27
|
+
(part * 100 / whole).floor
|
|
28
|
+
end
|
|
12
29
|
end
|
|
13
30
|
end
|
|
@@ -11,3 +11,4 @@
|
|
|
11
11
|
<%= ui_form_field(attribute: "goal[target]", label: "Target", type: :number, step: "any", required: true, value: goal.target, errors: goal.errors[:target]) %>
|
|
12
12
|
<%= ui_form_field(attribute: "goal[direction]", label: "Direction", type: :select, required: true, options: [["At least", "at_least"], ["At most", "at_most"]], value: goal.direction, errors: goal.errors[:direction]) %>
|
|
13
13
|
<%= ui_form_field(attribute: "goal[period]", label: "Period", type: :select, required: true, options: [["Week", "week"], ["Month", "month"]], value: goal.period, errors: goal.errors[:period]) %>
|
|
14
|
+
<%= ui_form_field(attribute: "goal[status]", label: "Status", type: :select, required: true, options: LuckRemover::Goal.statuses.keys.map { |status| [status.humanize, status] }, value: goal.status, errors: goal.errors[:status]) %>
|
|
@@ -6,18 +6,21 @@
|
|
|
6
6
|
<%= ui_button(label: "Add", href: new_goal_path) %>
|
|
7
7
|
<% end %>
|
|
8
8
|
<% end %>
|
|
9
|
-
<% rows = @
|
|
9
|
+
<% rows = @readings.map do |reading|
|
|
10
|
+
goal = reading.goal
|
|
10
11
|
{ name: goal.name,
|
|
11
12
|
edit_url: luck_remover.edit_goal_path(goal),
|
|
12
13
|
person: goal.person_id ? @person_names[goal.person_id] : "Whole business",
|
|
13
|
-
metric: LuckRemover.metric(goal.metric_key).title,
|
|
14
|
+
metric: reading.retired? ? "No metric" : LuckRemover.metric(goal.metric_key).title,
|
|
14
15
|
target: number_with_precision(goal.target, precision: 2, strip_insignificant_zeros: true),
|
|
15
16
|
direction: goal.direction.humanize,
|
|
16
|
-
period: goal.period.humanize
|
|
17
|
+
period: goal.period.humanize,
|
|
18
|
+
status: goal.status.humanize,
|
|
19
|
+
progress: reading.unread? ? "Could not be read" : number_to_percentage(reading.standing&.progress, precision: 0) }
|
|
17
20
|
end %>
|
|
18
21
|
<%= ui_data_table(
|
|
19
22
|
items: rows,
|
|
20
|
-
columns: [{ name: "Name" }, { person: "Person" }, { metric: "Metric" }, { target: "Target" }, { direction: "Direction" }, { period: "Period" }],
|
|
23
|
+
columns: [{ name: "Name" }, { person: "Person" }, { metric: "Metric" }, { target: "Target" }, { direction: "Direction" }, { period: "Period" }, { status: "Status" }, { progress: "Progress" }],
|
|
21
24
|
empty_message: "No goals yet."
|
|
22
25
|
) { |table| table.link(:name) { |row| row[:edit_url] } } %>
|
|
23
26
|
<% end %>
|
data/lib/luck_remover/version.rb
CHANGED
data/lib/luck_remover.rb
CHANGED
|
@@ -7,6 +7,7 @@ require "luck_remover/metric_registry"
|
|
|
7
7
|
module LuckRemover
|
|
8
8
|
mattr_accessor :parent_controller, default: "LuckRemover::ApplicationController"
|
|
9
9
|
mattr_accessor :current_owner_method, default: nil
|
|
10
|
+
mattr_accessor :carried_params, default: []
|
|
10
11
|
|
|
11
12
|
NO_PEOPLE = ->(_owner) { [] }
|
|
12
13
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: luck_remover
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tyler Schneider
|
|
@@ -84,6 +84,7 @@ files:
|
|
|
84
84
|
- app/mailers/luck_remover/application_mailer.rb
|
|
85
85
|
- app/models/luck_remover/application_record.rb
|
|
86
86
|
- app/models/luck_remover/goal.rb
|
|
87
|
+
- app/models/luck_remover/reading.rb
|
|
87
88
|
- app/models/luck_remover/standing.rb
|
|
88
89
|
- app/views/layouts/luck_remover/application.html.erb
|
|
89
90
|
- app/views/luck_remover/goals/_form.html.erb
|
|
@@ -93,6 +94,7 @@ files:
|
|
|
93
94
|
- config/routes.rb
|
|
94
95
|
- db/migrate/20261022212722_create_luck_remover_goals.rb
|
|
95
96
|
- db/migrate/20261023134729_add_person_id_to_luck_remover_goals.rb
|
|
97
|
+
- db/migrate/20261028142026_add_status_to_luck_remover_goals.rb
|
|
96
98
|
- lib/luck_remover.rb
|
|
97
99
|
- lib/luck_remover/engine.rb
|
|
98
100
|
- lib/luck_remover/metric_registry.rb
|