Class: Decidim::TimeTracker::Activity
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::TimeTracker::Activity
- Includes:
- Loggable, Decidim::Traceable
- Defined in:
- app/models/decidim/time_tracker/activity.rb
Overview
The data store for a Activity in the Decidim::TimeTracker component. It stores a description and other useful information related to an activity.
Class Method Summary collapse
Instance Method Summary collapse
- #allow_answers_for?(user) ⇒ Boolean
- #answered_by?(user) ⇒ Boolean
- #assignation_accepted?(user) ⇒ Boolean
- #assignation_pending?(user) ⇒ Boolean
- #assignation_rejected?(user) ⇒ Boolean
- #counter_active_for?(user) ⇒ Boolean
- #has_assignation?(user) ⇒ Boolean
- #has_questions? ⇒ Boolean
-
#remaining_seconds_for_today ⇒ Object
Returns how many seconds are available for this task in the current day this can be less than the activity is allowed due the change of date.
-
#session_token(user) ⇒ Object
used as a unique idenfier when answering the task associated questionnaire.
-
#status ⇒ Object
Returns a identificative (I18n) string about the current status of activity Returns: :open if user can track time :finished if current date is passed end date :not_started if current date has not reach start date :inactive if current status is inactive.
-
#user_remaining_for_date(user, date) ⇒ Object
how many seconds ara available for this task and user for the current day.
- #user_remaining_for_today(user) ⇒ Object
-
#user_seconds_elapsed(user) ⇒ Object
Total number of seconds spent by the user and counting any possible running counters.
-
#user_total_seconds(user) ⇒ Object
total number of seconds spent by the user not counting current counters.
- #user_total_seconds_for_date(user, date) ⇒ Object
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
124 125 126 |
# File 'app/models/decidim/time_tracker/activity.rb', line 124 def self.log_presenter_class_for(_log) Decidim::TimeTracker::AdminLog::ActivityPresenter end |
Instance Method Details
#allow_answers_for?(user) ⇒ Boolean
93 94 95 96 97 98 99 |
# File 'app/models/decidim/time_tracker/activity.rb', line 93 def allow_answers_for?(user) return false if status == :inactive return false unless has_questions? assignation_accepted?(user) end |
#answered_by?(user) ⇒ Boolean
101 102 103 |
# File 'app/models/decidim/time_tracker/activity.rb', line 101 def answered_by?(user) questionnaire.answered_by? session_token(user) end |
#assignation_accepted?(user) ⇒ Boolean
77 78 79 |
# File 'app/models/decidim/time_tracker/activity.rb', line 77 def assignation_accepted?(user) assignations.accepted.where(user: user).count.positive? end |
#assignation_pending?(user) ⇒ Boolean
73 74 75 |
# File 'app/models/decidim/time_tracker/activity.rb', line 73 def assignation_pending?(user) assignations.pending.where(user: user).count.positive? end |
#assignation_rejected?(user) ⇒ Boolean
81 82 83 |
# File 'app/models/decidim/time_tracker/activity.rb', line 81 def assignation_rejected?(user) assignations.rejected.where(user: user).count.positive? end |
#counter_active_for?(user) ⇒ Boolean
48 49 50 51 52 |
# File 'app/models/decidim/time_tracker/activity.rb', line 48 def counter_active_for?(user) return false unless last_event_for(user) !last_event_for(user).stopped? end |
#has_assignation?(user) ⇒ Boolean
85 86 87 |
# File 'app/models/decidim/time_tracker/activity.rb', line 85 def has_assignation?(user) assignations.where(user: user).count.positive? end |
#has_questions? ⇒ Boolean
89 90 91 |
# File 'app/models/decidim/time_tracker/activity.rb', line 89 def has_questions? questionnaire.questions.any? end |
#remaining_seconds_for_today ⇒ Object
Returns how many seconds are available for this task in the current day this can be less than the activity is allowed due the change of date
56 57 58 |
# File 'app/models/decidim/time_tracker/activity.rb', line 56 def remaining_seconds_for_today @remaining_seconds_for_today ||= [max_minutes_per_day * 60, (Time.current.end_of_day - Time.current).to_i].min end |
#session_token(user) ⇒ Object
used as a unique idenfier when answering the task associated questionnaire
106 107 108 |
# File 'app/models/decidim/time_tracker/activity.rb', line 106 def session_token(user) "#{Digest::SHA1.hexdigest(user.id.to_s)}-#{id}" end |
#status ⇒ Object
Returns a identificative (I18n) string about the current status of activity Returns: :open if user can track time :finished if current date is passed end date :not_started if current date has not reach start date :inactive if current status is inactive
116 117 118 119 120 121 122 |
# File 'app/models/decidim/time_tracker/activity.rb', line 116 def status return :inactive unless active? return :not_started if start_date > Time.current.beginning_of_day return :finished if end_date < Time.current.beginning_of_day :open end |
#user_remaining_for_date(user, date) ⇒ Object
how many seconds ara available for this task and user for the current day
61 62 63 64 65 66 67 |
# File 'app/models/decidim/time_tracker/activity.rb', line 61 def user_remaining_for_date(user, date) total_seconds = user_total_seconds_for_date(user, date) remaining = max_minutes_per_day * 60 remaining = remaining_seconds_for_today if date.beginning_of_day == Date.current [remaining - total_seconds, 0].max end |
#user_remaining_for_today(user) ⇒ Object
69 70 71 |
# File 'app/models/decidim/time_tracker/activity.rb', line 69 def user_remaining_for_today(user) user_remaining_for_date(user, Date.current) end |
#user_seconds_elapsed(user) ⇒ Object
Total number of seconds spent by the user and counting any possible running counters
42 43 44 45 46 |
# File 'app/models/decidim/time_tracker/activity.rb', line 42 def user_seconds_elapsed(user) total = user_total_seconds(user) total += last_event_for(user).seconds_elapsed if last_event_for(user) total end |
#user_total_seconds(user) ⇒ Object
total number of seconds spent by the user not counting current counters
32 33 34 |
# File 'app/models/decidim/time_tracker/activity.rb', line 32 def user_total_seconds(user) time_events.where(user: user).sum(&:total_seconds).to_i end |
#user_total_seconds_for_date(user, date) ⇒ Object
36 37 38 |
# File 'app/models/decidim/time_tracker/activity.rb', line 36 def user_total_seconds_for_date(user, date) time_events.started_between(date.beginning_of_day, date.end_of_day).where(user: user).sum(&:total_seconds).to_i end |