Module: ThinkFeelDoEngine::Coach::GroupDashboardHelper

Defined in:
app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb

Overview

Displays navigational information in the form of breadcrumbs rubocop:disable Metrics/ModuleLength

Instance Method Summary collapse

Instance Method Details

#activity_status(activity) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 118

def activity_status(activity)
  if activity.monitored?
    "monitored"
  elsif activity.planned?
    "planned"
  elsif activity.reviewed_and_complete?
    "reviewed and complete"
  elsif activity.reviewed_and_incomplete?
    "reviewed and incomplete"
  end
end

#comment_count(shared_item) ⇒ Object



29
30
31
32
33
34
35
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 29

def comment_count(shared_item)
  comment_count = 0
  SocialNetworking::SharedItem.where(item: shared_item).each do |item|
    comment_count += SocialNetworking::Comment.where(item: item).count
  end
  comment_count
end

#comment_item_description(comment) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 49

def comment_item_description(comment)
  case comment.item_type
  when "SocialNetworking::OnTheMindStatement"
    "OnTheMindStatement: "\
    "#{SocialNetworking::
        OnTheMindStatement.find(comment.item_id).description}"
  when "SocialNetworking::SharedItem"
    comment_shared_item_description(comment)
  else
    "Unknown Item Type, Item ID:#{comment.item_id},"\
    " Item Type: #{comment.item_type}"
  end
end

#comment_shared_item_description(comment) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 82

def comment_shared_item_description(comment)
  if comment.item
    case comment.item.item_type
    when "Activity"
      activity = Activity.find(comment.item.item_id)
      "Activity: #{activity.participant.study_id},"\
        " #{activity.activity_type.title}, #{comment.item.action_type}"
    when "SocialNetworking::Profile"
      "ProfileCreation: #{comment.participant.study_id}"
    when "SocialNetworking::Goal"
      goal = SocialNetworking::Goal.find(comment.item.item_id)
      "Goal: #{goal.participant.study_id}, #{goal.description}"
    when "Thought"
      thought = Thought.find(comment.item.item_id)
      "Thought: #{thought.participant.study_id}, #{thought.description}"
    else
      "Unknown SharedItem Type, Item ID:#{comment.item_id},"\
      " Item Type: #{comment.item_type}"
    end
  else
    "Comment was made for an unknown item."
  end
end

#day_in_study(date, membership) ⇒ Object



45
46
47
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 45

def day_in_study(date, membership)
  date.to_date - membership.start_date + 1
end

#goal_like_count(goal) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 134

def goal_like_count(goal)
  like_total = 0
  goal_shared_items =
    SocialNetworking::SharedItem
    .where(item_type: "SocialNetworking::Goal", item_id: goal.id)
  goal_shared_items.each do |item|
    like_total +=
      SocialNetworking::Like
      .where(item_type: "SocialNetworking::SharedItem",
             item_id: item.id).count
  end
  like_total
end

#like_count(shared_item) ⇒ Object



21
22
23
24
25
26
27
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 21

def like_count(shared_item)
  like_count = 0
  SocialNetworking::SharedItem.where(item: shared_item).each do |item|
    like_count += SocialNetworking::Like.where(item: item).count
  end
  like_count
end

#list_participant_names(group, participants) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 69

def list_participant_names(group, participants)
  participant_list = "<ul>"
  participants.each do |participant|
    participant_list +=
      "<li>#{link_to participant.display_name,
                     coach_group_patient_dashboard_path(
                       group, participant
                     )}</li>" if participant
  end
  participant_list += "</ul>"
  participant_list
end

#membership_comments(membership) ⇒ Object



110
111
112
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 110

def membership_comments(membership)
  SocialNetworking::Comment.where(participant: membership.participant)
end

#membership_goals(membership) ⇒ Object



106
107
108
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 106

def membership_goals(membership)
  SocialNetworking::Goal.where(participant: membership.participant)
end

#membership_likes(membership) ⇒ Object



114
115
116
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 114

def membership_likes(membership)
  SocialNetworking::Like.where(participant: membership.participant)
end

#not_nil_and_populated_string(string_to_check) ⇒ Object



130
131
132
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 130

def not_nil_and_populated_string(string_to_check)
  string_to_check && !string_to_check.empty?
end

#participants_that_read_lesson(task) ⇒ Object



63
64
65
66
67
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 63

def participants_that_read_lesson(task)
  render partial: "think_feel_do_engine/coach/group_dashboard/"\
                  "lesson_completion_breakdown",
         locals: { task: task }
end

#social_likes_and_comments_column_headersObject



7
8
9
10
11
12
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 7

def social_likes_and_comments_column_headers
  if social_features?
    (:th, "Likes") +
      (:th, "Comments")
  end
end

#social_likes_and_comments_count_rows(shared_item) ⇒ Object



14
15
16
17
18
19
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 14

def social_likes_and_comments_count_rows(shared_item)
  if social_features?
    (:td, like_count(shared_item)) +
      (:td, comment_count(shared_item))
  end
end

#week_in_study(date, membership) ⇒ Object



37
38
39
40
41
42
43
# File 'app/helpers/think_feel_do_engine/coach/group_dashboard_helper.rb', line 37

def week_in_study(date, membership)
  if (day_in_study(date, membership) / 7.0).ceil == 0
    1
  else
    (day_in_study(date, membership) / 7.0).ceil
  end
end