luck_remover 0.7.0 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b522260163d988ea9f11d4a27a1b7d8b5975f48c82d2ad7bcbbe6c2d22dc576
4
- data.tar.gz: 7be40bd718c073d2f1f6a105046b76eb3a27c80d1e82a4fbbc55734306f89321
3
+ metadata.gz: ce01c50a6acd9c471ac05b2089f50b37cf5018b52ac8477e0d93e1cf4c55a7ca
4
+ data.tar.gz: b400f56a1f90c208ed3898aa3950d70e9b126e72e7469eb4d5c85bbf8bfc99bf
5
5
  SHA512:
6
- metadata.gz: 9dd956f8f2a381d3be6dd34bd383fd42fba4528804eff863d443872f0573a4ce4f589108392e19dd5007f27189b3aba448cecb53de3bf811aa9d861f0fa239a0
7
- data.tar.gz: b8dd19e535f7992d37db2812d851fbf160c3bb944166ba5009d9aa1b378aba9f94ab8b840994fc8bb05511d6b4a85f27d9cc39b7d60659ab20f94bc073bafc77
6
+ metadata.gz: 538b819d7c67047da6bd1982ff9c289c292e767f4c9c7f589574f55c304b74ae44bb89cd06e4e31ab12b5be6fed6f9028a67c3ac45983ae62ff36a440fce1f89
7
+ data.tar.gz: ab3b709e3421ad8c96694a08e00b33467ec72ea987258cae4cd19ae0fb2c4881d5df6660289b733382b3b30e3f8c92642667adffd36f4401efe69b499241623a
@@ -1,9 +1,9 @@
1
1
  module LuckRemover
2
2
  class GoalsController < LuckRemover.parent_controller.constantize
3
- helper_method :page_query
3
+ helper_method :page_query, :archived_list?
4
4
 
5
5
  def index
6
- @goals = goals_in_area.order(:name)
6
+ @readings = goals_in_area.where(archived: archived_list?).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, :archived ])
54
54
  end
55
55
 
56
56
  def goal_scope
@@ -69,6 +69,10 @@ module LuckRemover
69
69
  url_from(params[:return_to]) || goals_path
70
70
  end
71
71
 
72
+ def archived_list?
73
+ params[:archived] == "true"
74
+ end
75
+
72
76
  def area
73
77
  params[:area].presence
74
78
  end
@@ -5,15 +5,18 @@ module LuckRemover
5
5
  belongs_to :owner, polymorphic: true
6
6
 
7
7
  scope :for_owner, ->(owner) { where(owner: owner) }
8
+ scope :unarchived, -> { where(archived: false) }
8
9
  scope :in_area, ->(area) { where(metric_key: LuckRemover.metrics.in_area(area).map { |stat| stat.key.to_s }) }
9
10
 
10
11
  enum :direction, { at_least: "at_least", at_most: "at_most" }, validate: true
11
12
  enum :period, { week: "week", month: "month" }, validate: true
13
+ enum :status, { draft: "draft", active: "active", achieved: "achieved", abandoned: "abandoned", paused: "paused" }, validate: true
12
14
 
13
15
  validates :name, :target, presence: true
14
16
  validate :metric_is_registered
15
17
  validate :person_is_one_the_host_gives, if: :person_id
16
18
  validate :metric_is_readable_for_one_person, if: :person_id
19
+ validate :only_finished_goals_are_archived, if: :archived
17
20
 
18
21
  def standing(now: Time.current, **inputs)
19
22
  value = LuckRemover.metric(metric_key).read(range: current_period(now), **for_person, **inputs).value
@@ -43,6 +46,12 @@ module LuckRemover
43
46
  errors.add(:metric_key, "#{metric_key} cannot be read for one person")
44
47
  end
45
48
 
49
+ def only_finished_goals_are_archived
50
+ return if achieved? || abandoned?
51
+
52
+ errors.add(:base, "Only achieved or abandoned goals can be archived")
53
+ end
54
+
46
55
  def metric_is_registered
47
56
  return if LuckRemover.metrics.registered?(metric_key.to_s)
48
57
 
@@ -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
@@ -1,3 +1,6 @@
1
+ <% goal.errors[:base].each do |message| %>
2
+ <%= ui_alert(message: message, type: :error) %>
3
+ <% end %>
1
4
  <%= ui_form_field(attribute: "goal[name]", label: "Name", required: true, value: goal.name, errors: goal.errors[:name]) %>
2
5
 
3
6
  <% goal.errors[:metric_key].each do |message| %>
@@ -11,3 +14,4 @@
11
14
  <%= ui_form_field(attribute: "goal[target]", label: "Target", type: :number, step: "any", required: true, value: goal.target, errors: goal.errors[:target]) %>
12
15
  <%= 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
16
  <%= ui_form_field(attribute: "goal[period]", label: "Period", type: :select, required: true, options: [["Week", "week"], ["Month", "month"]], value: goal.period, errors: goal.errors[:period]) %>
17
+ <%= 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]) %>
@@ -5,6 +5,11 @@
5
5
  <%= ui_button(label: "Save") %>
6
6
  <% end %>
7
7
  <%= ui_action_menu do %>
8
+ <% if @goal.archived %>
9
+ <%= ui_action_menu_item(label: "Unarchive", href: luck_remover.goal_path(@goal, **page_query, goal: { archived: false }), method: :patch) %>
10
+ <% else %>
11
+ <%= ui_action_menu_item(label: "Archive", href: luck_remover.goal_path(@goal, **page_query, goal: { archived: true }), method: :patch) %>
12
+ <% end %>
8
13
  <%= ui_action_menu_item(label: "Delete", href: luck_remover.goal_path(@goal, **page_query), method: :delete) %>
9
14
  <% end %>
10
15
  <% end %>
@@ -3,21 +3,29 @@
3
3
  <%= ui_page(max_width: :xl) do %>
4
4
  <%= ui_page_header(title: "Goals", action_url: new_goal_path, action_label: "Add") do |header| %>
5
5
  <% header.action do %>
6
+ <% if archived_list? %>
7
+ <%= ui_button(label: "Show current", href: luck_remover.goals_path(**page_query), variant: :secondary) %>
8
+ <% else %>
9
+ <%= ui_button(label: "Show archived", href: luck_remover.goals_path(**page_query, archived: true), variant: :secondary) %>
10
+ <% end %>
6
11
  <%= ui_button(label: "Add", href: new_goal_path) %>
7
12
  <% end %>
8
13
  <% end %>
9
- <% rows = @goals.map do |goal|
14
+ <% rows = @readings.map do |reading|
15
+ goal = reading.goal
10
16
  { name: goal.name,
11
17
  edit_url: luck_remover.edit_goal_path(goal),
12
18
  person: goal.person_id ? @person_names[goal.person_id] : "Whole business",
13
- metric: LuckRemover.metric(goal.metric_key).title,
19
+ metric: reading.retired? ? "No metric" : LuckRemover.metric(goal.metric_key).title,
14
20
  target: number_with_precision(goal.target, precision: 2, strip_insignificant_zeros: true),
15
21
  direction: goal.direction.humanize,
16
- period: goal.period.humanize }
22
+ period: goal.period.humanize,
23
+ status: goal.status.humanize,
24
+ progress: reading.unread? ? "Could not be read" : number_to_percentage(reading.standing&.progress, precision: 0) }
17
25
  end %>
18
26
  <%= ui_data_table(
19
27
  items: rows,
20
- columns: [{ name: "Name" }, { person: "Person" }, { metric: "Metric" }, { target: "Target" }, { direction: "Direction" }, { period: "Period" }],
28
+ columns: [{ name: "Name" }, { person: "Person" }, { metric: "Metric" }, { target: "Target" }, { direction: "Direction" }, { period: "Period" }, { status: "Status" }, { progress: "Progress" }],
21
29
  empty_message: "No goals yet."
22
30
  ) { |table| table.link(:name) { |row| row[:edit_url] } } %>
23
31
  <% end %>
@@ -0,0 +1,5 @@
1
+ class AddStatusToLuckRemoverGoals < ActiveRecord::Migration[8.1]
2
+ def change
3
+ add_column :luck_remover_goals, :status, :string, null: false, default: "active"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddArchivedToLuckRemoverGoals < ActiveRecord::Migration[8.1]
2
+ def change
3
+ add_column :luck_remover_goals, :archived, :boolean, null: false, default: false
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module LuckRemover
2
- VERSION = "0.7.0"
2
+ VERSION = "0.9.0"
3
3
  end
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.7.0
4
+ version: 0.9.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,8 @@ 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
98
+ - db/migrate/20261028152059_add_archived_to_luck_remover_goals.rb
96
99
  - lib/luck_remover.rb
97
100
  - lib/luck_remover/engine.rb
98
101
  - lib/luck_remover/metric_registry.rb