-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from Freika/notifications
Notifications
- Loading branch information
Showing
34 changed files
with
608 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.8.2 | ||
0.8.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
class NotificationsController < ApplicationController | ||
before_action :authenticate_user! | ||
before_action :set_notification, only: %i[show destroy] | ||
|
||
def index | ||
@notifications = | ||
current_user.notifications.order(created_at: :desc).paginate(page: params[:page], per_page: 20) | ||
end | ||
|
||
def show; end | ||
|
||
def mark_as_read | ||
current_user.notifications.unread.update_all(read_at: Time.zone.now) | ||
|
||
redirect_to notifications_url, notice: 'All notifications marked as read.', status: :see_other | ||
end | ||
|
||
def destroy | ||
@notification.destroy! | ||
redirect_to notifications_url, notice: 'Notification was successfully destroyed.', status: :see_other | ||
end | ||
|
||
private | ||
|
||
def set_notification | ||
@notification = Notification.find(params[:id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Notification < ApplicationRecord | ||
belongs_to :user | ||
|
||
validates :title, :content, :kind, presence: true | ||
|
||
enum kind: { info: 0, warning: 1, error: 2 } | ||
|
||
scope :unread, -> { where(read_at: nil) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class Notifications::Create | ||
attr_reader :user, :kind, :title, :content | ||
|
||
def initialize(user:, kind:, title:, content:) | ||
@user = user | ||
@kind = kind | ||
@title = title | ||
@content = content | ||
end | ||
|
||
def call | ||
Notification.create!(user:, kind:, title:, content:) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div role="<%= notification.kind %>" class="<%= notification.kind %> shadow-lg p-5 flex justify-between items-center mb-4 rounded-lg bg-neutral" id="<%= dom_id notification %>"> | ||
<div class="flex-1"> | ||
<h3 class="font-bold text-xl"> | ||
<%= link_to notification.title, notification, class: 'link hover:no-underline text-blue-600' %> | ||
</h3> | ||
<div class="text-sm text-gray-500"><%= time_ago_in_words notification.created_at %> ago</div> | ||
|
||
<% if params[:action] == 'show' %> | ||
<div class="mt-2"> | ||
<%= notification.content %> | ||
<% if notification.error? %> | ||
<div class="mt-2"> | ||
Please, when reporting a bug to <a href="https://github.com/Freika/dawarich/issues" class="link hover:no-underline text-blue-600">Github Issues</a>, don't forget to include logs from <code>dawarich_app</code> and <code>dawarich_sidekiq</code> docker containers. Thank you! | ||
</div> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</div> | ||
<div class="badge badge-<%= notification.kind %> gap-2"> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<% content_for :title, "Notifications" %> | ||
<div class="flex flex-col items-center w-full"> | ||
<div class="text-center mb-6"> | ||
<h1 class="font-bold text-4xl mb-4">Notifications</h1> | ||
<div class="flex items-center justify-center mb-4"> | ||
<%= link_to "Mark all as read", mark_notifications_as_read_path, method: :post, data: { turbo_method: :post }, class: "btn btn-sm btn-primary" %> | ||
</div> | ||
<div class="mb-4"> | ||
<%= will_paginate @notifications %> | ||
</div> | ||
</div> | ||
<div id="notifications" class="w-full max-w-2xl"> | ||
<% @notifications.each do |notification| %> | ||
<%= render notification %> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div class="mx-auto md:w-2/3 w-full flex"> | ||
<div class="mx-auto"> | ||
<%= render @notification %> | ||
|
||
<div class='my-5'> | ||
<%= link_to "Back to notifications", notifications_path, class: "btn btn-small" %> | ||
<div class="inline-block ml-2"> | ||
<%= button_to "Destroy this notification", @notification, data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?", turbo_method: :delete }, method: :delete, class: "btn btn-small btn-warning" %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreateNotifications < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :notifications do |t| | ||
t.string :title, null: false | ||
t.text :content, null: false | ||
t.references :user, null: false, foreign_key: true | ||
t.integer :kind, null: false, default: 0 | ||
t.datetime :read_at | ||
|
||
t.timestamps | ||
end | ||
add_index :notifications, :kind | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.