help_center 0.0.4 → 0.0.5

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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +12 -12
  3. data/.gitignore +10 -10
  4. data/CHANGELOG.md +1 -1
  5. data/CODE_OF_CONDUCT.md +74 -74
  6. data/Gemfile +6 -6
  7. data/LICENSE.txt +21 -21
  8. data/README.md +164 -155
  9. data/Rakefile +10 -10
  10. data/app/assets/stylesheets/help_center.scss +139 -119
  11. data/app/controllers/help_center/application_controller.rb +37 -37
  12. data/app/controllers/help_center/notifications_controller.rb +19 -19
  13. data/app/controllers/help_center/support_categories_controller.rb +58 -17
  14. data/app/controllers/help_center/support_posts_controller.rb +72 -72
  15. data/app/controllers/help_center/support_threads_controller.rb +16 -6
  16. data/app/helpers/help_center/support_posts_helper.rb +29 -29
  17. data/app/helpers/help_center/support_threads_helper.rb +28 -28
  18. data/app/jobs/help_center/support_post_notification_job.rb +42 -42
  19. data/app/jobs/help_center/support_thread_notification_job.rb +40 -40
  20. data/app/mailers/help_center/user_mailer.rb +28 -28
  21. data/app/models/support_category.rb +13 -13
  22. data/app/models/support_post.rb +15 -15
  23. data/app/models/support_subscription.rb +19 -19
  24. data/app/models/support_thread.rb +85 -85
  25. data/app/views/help_center/support_categories/_form.html.erb +35 -0
  26. data/app/views/help_center/support_categories/_support_thread.html.erb +25 -0
  27. data/app/views/help_center/support_categories/edit.html.erb +7 -0
  28. data/app/views/help_center/support_categories/index.html.erb +19 -0
  29. data/app/views/help_center/support_categories/new.html.erb +5 -0
  30. data/app/views/help_center/support_categories/show.html.erb +20 -0
  31. data/app/views/help_center/support_threads/_form.html.erb +6 -4
  32. data/app/views/help_center/support_threads/edit.html.erb +7 -7
  33. data/app/views/help_center/support_threads/index.html.erb +1 -1
  34. data/app/views/help_center/support_threads/new.html.erb +5 -5
  35. data/app/views/help_center/support_threads/show.html.erb +42 -1
  36. data/app/views/layouts/help_center.html.erb +37 -13
  37. data/app/views/shared/_spacer.html.erb +1 -1
  38. data/bin/console +14 -14
  39. data/bin/setup +8 -8
  40. data/config/locales/en.yml +55 -52
  41. data/config/routes.rb +24 -24
  42. data/db/migrate/20170417012930_create_support_categories.rb +19 -19
  43. data/db/migrate/20170417012931_create_support_threads.rb +18 -18
  44. data/db/migrate/20170417012932_create_support_posts.rb +12 -12
  45. data/db/migrate/20170417012933_create_support_subscriptions.rb +11 -11
  46. data/help_center.gemspec +29 -29
  47. data/lib/generators/help_center/controllers_generator.rb +13 -13
  48. data/lib/generators/help_center/helpers_generator.rb +13 -13
  49. data/lib/generators/help_center/views_generator.rb +13 -13
  50. data/lib/help_center.rb +23 -24
  51. data/lib/help_center/engine.rb +10 -10
  52. data/lib/help_center/slack.rb +22 -22
  53. data/lib/help_center/support_user.rb +10 -10
  54. data/lib/help_center/version.rb +3 -3
  55. metadata +11 -8
  56. data/.travis.yml +0 -5
  57. data/app/views/help_center/support_threads/_article.html.erb +0 -32
  58. data/lib/help_center/will_paginate.rb +0 -53
@@ -1,28 +1,28 @@
1
- class HelpCenter::UserMailer < ApplicationMailer
2
- # You can set the default `from` address in ApplicationMailer
3
-
4
- helper HelpCenter::SupportPostsHelper
5
- helper HelpCenter::Engine.routes.url_helpers
6
-
7
- def new_thread(support_thread, recipient)
8
- @support_thread = support_thread
9
- @support_post = support_thread.support_posts.first
10
- @recipient = recipient
11
-
12
- mail(
13
- to: "#{@recipient.name} <#{@recipient.email}>",
14
- subject: @support_thread.title
15
- )
16
- end
17
-
18
- def new_post(support_post, recipient)
19
- @support_post = support_post
20
- @support_thread = support_post.support_thread
21
- @recipient = recipient
22
-
23
- mail(
24
- to: "#{@recipient.name} <#{@recipient.email}>",
25
- subject: "New post in #{@support_thread.title}"
26
- )
27
- end
28
- end
1
+ class HelpCenter::UserMailer < ApplicationMailer
2
+ # You can set the default `from` address in ApplicationMailer
3
+
4
+ helper HelpCenter::SupportPostsHelper
5
+ helper HelpCenter::Engine.routes.url_helpers
6
+
7
+ def new_thread(support_thread, recipient)
8
+ @support_thread = support_thread
9
+ @support_post = support_thread.support_posts.first
10
+ @recipient = recipient
11
+
12
+ mail(
13
+ to: "#{@recipient.name} <#{@recipient.email}>",
14
+ subject: @support_thread.title
15
+ )
16
+ end
17
+
18
+ def new_post(support_post, recipient)
19
+ @support_post = support_post
20
+ @support_thread = support_post.support_thread
21
+ @recipient = recipient
22
+
23
+ mail(
24
+ to: "#{@recipient.name} <#{@recipient.email}>",
25
+ subject: "New post in #{@support_thread.title}"
26
+ )
27
+ end
28
+ end
@@ -1,13 +1,13 @@
1
- class SupportCategory < ApplicationRecord
2
- extend FriendlyId
3
- friendly_id :name, use: :slugged
4
-
5
- scope :sorted, ->{ order(position: :asc) }
6
-
7
- validates :name, :slug, :color, presence: true
8
-
9
- def color
10
- colour = super
11
- colour.start_with?("#") ? colour : "##{colour}"
12
- end
13
- end
1
+ class SupportCategory < ApplicationRecord
2
+ extend FriendlyId
3
+ friendly_id :name, use: :slugged
4
+
5
+ scope :sorted, ->{ order(position: :asc) }
6
+
7
+ validates :name, :slug, :color, presence: true
8
+
9
+ def color
10
+ colour = super
11
+ colour.start_with?("#") ? colour : "##{colour}"
12
+ end
13
+ end
@@ -1,15 +1,15 @@
1
- class SupportPost < ApplicationRecord
2
- belongs_to :support_thread, counter_cache: true, touch: true
3
- belongs_to :user
4
- has_many :reactions, as: :reactable
5
-
6
- validates :user_id, :body, presence: true
7
-
8
- scope :sorted, ->{ order(:created_at) }
9
-
10
- after_update :solve_support_thread, if: :solved?
11
-
12
- def solve_support_thread
13
- support_thread.update(solved: true)
14
- end
15
- end
1
+ class SupportPost < ApplicationRecord
2
+ belongs_to :support_thread, counter_cache: true, touch: true
3
+ belongs_to :user
4
+ has_many :reactions, as: :reactable
5
+
6
+ validates :user_id, :body, presence: true
7
+
8
+ scope :sorted, ->{ order(:created_at) }
9
+
10
+ after_update :solve_support_thread, if: :solved?
11
+
12
+ def solve_support_thread
13
+ support_thread.update(solved: true)
14
+ end
15
+ end
@@ -1,19 +1,19 @@
1
- class SupportSubscription < ApplicationRecord
2
- belongs_to :support_thread
3
- belongs_to :user
4
-
5
- scope :optin, ->{ where(subscription_type: :optin) }
6
- scope :optout, ->{ where(subscription_type: :optout) }
7
-
8
- validates :subscription_type, presence: true, inclusion: { in: %w{ optin optout } }
9
- validates :user_id, uniqueness: { scope: :support_thread_id }
10
-
11
- def toggle!
12
- case subscription_type
13
- when "optin"
14
- update(subscription_type: "optout")
15
- when "optout"
16
- update(subscription_type: "optin")
17
- end
18
- end
19
- end
1
+ class SupportSubscription < ApplicationRecord
2
+ belongs_to :support_thread
3
+ belongs_to :user
4
+
5
+ scope :optin, ->{ where(subscription_type: :optin) }
6
+ scope :optout, ->{ where(subscription_type: :optout) }
7
+
8
+ validates :subscription_type, presence: true, inclusion: { in: %w{ optin optout } }
9
+ validates :user_id, uniqueness: { scope: :support_thread_id }
10
+
11
+ def toggle!
12
+ case subscription_type
13
+ when "optin"
14
+ update(subscription_type: "optout")
15
+ when "optout"
16
+ update(subscription_type: "optin")
17
+ end
18
+ end
19
+ end
@@ -1,85 +1,85 @@
1
- class SupportThread < ApplicationRecord
2
- extend FriendlyId
3
- friendly_id :title, use: :slugged
4
-
5
- belongs_to :support_category
6
- belongs_to :user
7
- has_many :support_posts
8
- has_many :support_subscriptions
9
- has_many :optin_subscribers, ->{ where(support_subscriptions: { subscription_type: :optin }) }, through: :support_subscriptions, source: :user
10
- has_many :optout_subscribers, ->{ where(support_subscriptions: { subscription_type: :optout }) }, through: :support_subscriptions, source: :user
11
- has_many :users, through: :support_posts
12
-
13
- has_rich_text :content
14
-
15
- accepts_nested_attributes_for :support_posts
16
-
17
- validates :support_category, presence: true
18
- validates :user_id, :title, presence: true
19
- validates_associated :support_posts
20
-
21
- scope :pinned_first, ->{ order(pinned: :desc) }
22
- scope :solved, ->{ where(solved: true) }
23
- scope :sorted, ->{ order(position: :asc) }
24
- scope :unpinned, ->{ where.not(pinned: true) }
25
- scope :unsolved, ->{ where.not(solved: true) }
26
-
27
- def subscribed_users
28
- (users + optin_subscribers).uniq - optout_subscribers
29
- end
30
-
31
- def subscription_for(user)
32
- return nil if user.nil?
33
- support_subscriptions.find_by(user_id: user.id)
34
- end
35
-
36
- def subscribed?(user)
37
- return false if user.nil?
38
-
39
- subscription = subscription_for(user)
40
-
41
- if subscription.present?
42
- subscription.subscription_type == "optin"
43
- else
44
- support_posts.where(user_id: user.id).any?
45
- end
46
- end
47
-
48
- def toggle_subscription(user)
49
- subscription = subscription_for(user)
50
-
51
- if subscription.present?
52
- subscription.toggle!
53
- elsif support_posts.where(user_id: user.id).any?
54
- support_subscriptions.create(user: user, subscription_type: "optout")
55
- else
56
- support_subscriptions.create(user: user, subscription_type: "optin")
57
- end
58
- end
59
-
60
- def subscribed_reason(user)
61
- return I18n.t('.not_receiving_notifications') if user.nil?
62
-
63
- subscription = subscription_for(user)
64
-
65
- if subscription.present?
66
- if subscription.subscription_type == "optout"
67
- I18n.t('.ignoring_thread')
68
- elsif subscription.subscription_type == "optin"
69
- I18n.t('.receiving_notifications_because_subscribed')
70
- end
71
- elsif support_posts.where(user_id: user.id).any?
72
- I18n.t('.receiving_notifications_because_posted')
73
- else
74
- I18n.t('.not_receiving_notifications')
75
- end
76
- end
77
-
78
- # These are the users to notify on a new thread. Currently this does nothing,
79
- # but you can override this to provide whatever functionality you like here.
80
- #
81
- # For example: You might use this to send all moderators an email of new threads.
82
- def notify_users
83
- []
84
- end
85
- end
1
+ class SupportThread < ApplicationRecord
2
+ extend FriendlyId
3
+ friendly_id :title, use: :slugged
4
+
5
+ belongs_to :support_category
6
+ belongs_to :user
7
+ has_many :support_posts
8
+ has_many :support_subscriptions
9
+ has_many :optin_subscribers, ->{ where(support_subscriptions: { subscription_type: :optin }) }, through: :support_subscriptions, source: :user
10
+ has_many :optout_subscribers, ->{ where(support_subscriptions: { subscription_type: :optout }) }, through: :support_subscriptions, source: :user
11
+ has_many :users, through: :support_posts
12
+
13
+ has_rich_text :content
14
+
15
+ accepts_nested_attributes_for :support_posts
16
+
17
+ validates :support_category, presence: true
18
+ validates :user_id, :title, presence: true
19
+ validates_associated :support_posts
20
+
21
+ scope :pinned_first, ->{ order(pinned: :desc) }
22
+ scope :solved, ->{ where(solved: true) }
23
+ scope :sorted, ->{ order(position: :asc) }
24
+ scope :unpinned, ->{ where.not(pinned: true) }
25
+ scope :unsolved, ->{ where.not(solved: true) }
26
+
27
+ def subscribed_users
28
+ (users + optin_subscribers).uniq - optout_subscribers
29
+ end
30
+
31
+ def subscription_for(user)
32
+ return nil if user.nil?
33
+ support_subscriptions.find_by(user_id: user.id)
34
+ end
35
+
36
+ def subscribed?(user)
37
+ return false if user.nil?
38
+
39
+ subscription = subscription_for(user)
40
+
41
+ if subscription.present?
42
+ subscription.subscription_type == "optin"
43
+ else
44
+ support_posts.where(user_id: user.id).any?
45
+ end
46
+ end
47
+
48
+ def toggle_subscription(user)
49
+ subscription = subscription_for(user)
50
+
51
+ if subscription.present?
52
+ subscription.toggle!
53
+ elsif support_posts.where(user_id: user.id).any?
54
+ support_subscriptions.create(user: user, subscription_type: "optout")
55
+ else
56
+ support_subscriptions.create(user: user, subscription_type: "optin")
57
+ end
58
+ end
59
+
60
+ def subscribed_reason(user)
61
+ return I18n.t('.not_receiving_notifications') if user.nil?
62
+
63
+ subscription = subscription_for(user)
64
+
65
+ if subscription.present?
66
+ if subscription.subscription_type == "optout"
67
+ I18n.t('.ignoring_thread')
68
+ elsif subscription.subscription_type == "optin"
69
+ I18n.t('.receiving_notifications_because_subscribed')
70
+ end
71
+ elsif support_posts.where(user_id: user.id).any?
72
+ I18n.t('.receiving_notifications_because_posted')
73
+ else
74
+ I18n.t('.not_receiving_notifications')
75
+ end
76
+ end
77
+
78
+ # These are the users to notify on a new thread. Currently this does nothing,
79
+ # but you can override this to provide whatever functionality you like here.
80
+ #
81
+ # For example: You might use this to send all moderators an email of new threads.
82
+ def notify_users
83
+ []
84
+ end
85
+ end
@@ -0,0 +1,35 @@
1
+ <%= form_for @category,
2
+ url: (@category.persisted? ? help_center.support_category_path(@category) : help_center.support_categories_path),
3
+ html: { data: {behavior: "comment-form"} } do |f| %>
4
+ <% if @category.errors.any? %>
5
+ <div id="error_explanation">
6
+ <h2><%= pluralize(@category.errors.count, "error") %> prohibited this support_thread from being saved:</h2>
7
+ <ul>
8
+ <% @category.errors.full_messages.each do |message| %>
9
+ <li><%= message %></li>
10
+ <% end %>
11
+ </ul>
12
+ </div>
13
+ <% end %>
14
+ <div class="mb-4">
15
+ <%= f.label t('title') %>
16
+ <%= f.text_field :name, placeholder: t('how_do_i'), class: "form-control form-input" %>
17
+ </div>
18
+ <div class="mb-4">
19
+ <%= f.label t('position') %>
20
+ <%= f.text_field :position, class: "form-control form-input" %>
21
+ </div>
22
+ <div class="mb-4">
23
+ <%= f.label t('color') %>
24
+ <%= f.color_field :color, class: "form-control form-input" %>
25
+ </div>
26
+ <div class="flex justify-between mb-4 text-right">
27
+ <% if f.object.new_record? %>
28
+ <%= f.button t('add'), class: "btn btn-primary", data: {disable_with: "<i class='fa fa-spinner fa-spin'></i> #{t('saving')}"} %>
29
+ <% else %>
30
+ <%= f.button t('update'), class: "btn btn-primary", data: {disable_with: "<i class='fa fa-spinner fa-spin'></i> #{t('saving')}"} %>
31
+ <% end %>
32
+
33
+ <%= link_to "Cancel", :back, class: "btn btn-link" %>
34
+ </div>
35
+ <% end %>
@@ -0,0 +1,25 @@
1
+ <%= cache support_thread do %>
2
+ <div class="support-thread">
3
+ <div class="flex flex-wrap">
4
+ <div class="flex-grow mb-2">
5
+ <%= link_to help_center.support_thread_path(support_thread) do %>
6
+ <h4>
7
+ <%= support_thread.title %>
8
+ </h4>
9
+ <p class="text-gray-500 hover:text-gray-700"><%= truncate(support_thread.content.to_plain_text, length: 200) %></p>
10
+ <div class="thread-details mt-2">
11
+ <%= t('content_updated_at', update_time: time_ago_in_words(support_thread.created_at)) %>
12
+ </div>
13
+ <% end %>
14
+ </div>
15
+ <% if HelpCenter.enable_comments %>
16
+ <div class="sm:w-1/6 pr-4 pl-4 text-center">
17
+ <%= link_to help_center.support_thread_path(support_thread), class: "thread-posts-count" do %>
18
+ <span class="count"><%= support_thread.support_posts_count %></span>
19
+ <small><%= t("post", count: support_thread.support_posts_count) %></small>
20
+ <% end %>
21
+ </div>
22
+ <% end %>
23
+ </div>
24
+ </div>
25
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <%= content_for :title, "Edit Category" %>
2
+
3
+ <h1 class="mb-4 font-bold"><%= t('edit_category') %></h1>
4
+
5
+ <div class="support_category">
6
+ <%= render 'form', posts: false %>
7
+ </div>
@@ -0,0 +1,19 @@
1
+ <% if @support_threads.none? %>
2
+ <div><%= t('search_not_found') %>. <%= t('check_out') %> <%= link_to t('latest_questions'), help_center.support_threads_path %> <%= t('instead') %> </div>
3
+ <% else %>
4
+ <div class="container mx-auto">
5
+ <% if request.url.include?('category') %>
6
+ <%# If category, list all articles %>
7
+ <div class="w-1/62 text-left p-0">
8
+ <h3> <%= @support_threads.first.support_category.name %></h3>
9
+ </div>
10
+ <hr>
11
+ <%= render partial: "help_center/support_threads/support_thread", collection: @support_threads, spacer_template: "shared/spacer" %>
12
+ <div class="support-threads-nav text-center">
13
+ <%== pagy_nav(@pagy) %>
14
+ </div>
15
+ <% else %>
16
+ <%# Set default index here %>
17
+ <% end %>
18
+ </div>
19
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <h1 class="mb-4 font-bold"><%= t('add_an_article') %></h1>
2
+
3
+ <div class="support_post">
4
+ <%= render 'form' %>
5
+ </div>
@@ -0,0 +1,20 @@
1
+ <div class="flex flex-wrap mb-8">
2
+ <% if is_moderator_or_owner?(@category) %>
3
+ <div class="mb-4 bg-purple-600 flex w-full px-4 py-2 text-sm pr-4 pl-4 justify-end">
4
+ <span class="mr-4 text-gray-200"><i class="far fa-sort-amount-down"></i> <%= @category.position %> </span>
5
+ <%= link_to icon("fas","pencil") + " Edit", help_center.edit_support_category_path(@category),
6
+ class: "text-gray-200",
7
+ data: { toggle: "tooltip", placement: "left" },
8
+ title: t('edit_this_thread') %>
9
+ <%= link_to icon("fas","trash") + " Delete", help_center.support_category_path(@category),
10
+ method: :delete,
11
+ class: "text-gray-200 ml-4",
12
+ data: { toggle: "tooltip", placement: "left", confirm: "Are you sure?" },
13
+ title: t('delete_category') %>
14
+ </div>
15
+ <% end %>
16
+ <div class="md:w-full pr-4 pl-41">
17
+ <h1 class="mb-4 font-bold"> <%= @category.name %></h1>
18
+ </div>
19
+
20
+ </div>