Skip to content

Commit

Permalink
Fix(Notification routes): Remove unused
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisma committed Mar 25, 2019
1 parent 694b03a commit 2f4bd89
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 70 deletions.
52 changes: 15 additions & 37 deletions app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,62 +1,40 @@
# frozen_string_literal: true

class NotificationsController < ApplicationController
before_action :set_notification, only: %i[show edit update destroy mark_as_read mark_as_read_and_redirect]
before_action :set_notification, only: %i[destroy mark_as_read mark_as_read_and_redirect]

# GET /notifications
# GET /notifications.json
def index
@notifications = Notification.where(user: current_user)
end

# GET /notifications/new
def new
@notification = Notification.new
end

# POST /notifications
# POST /notifications.json
def create
@notification = Notification.new(notification_params)
@notification.user_id = current_user.id
@notification.read = false

respond_to do |format|
if @notification.save
format.html { redirect_to notifications_path }
else
format.html { render :new }
end
end
end

# DELETE /notifications/1
# DELETE /notifications/1.json
def destroy
@notification.destroy
respond_to do |format|
format.html { redirect_back fallback_location: notifications_url }
format.json { head :no_content }
if @notification.destroy
notice = 'Notification was successfully deleted.'
else
alert = 'Error while deleting notification.'
end
redirect_back fallback_location: notifications_path, notice: notice, alert: alert
end


# GET /notifications/1/mark_as_read_and_redirect
def mark_as_read_and_redirect
@notification.update(read: true) unless @notification.read
if @notification.link.present?
redirect_to @notification.link
else
redirect_back fallback_location: notifications_url
redirect_back fallback_location: notifications_path
end
end


# GET /notifications/1/mark_as_read
def mark_as_read
@notification.read = true
respond_to do |format|
if @notification.save
format.html { redirect_back fallback_location: notifications_path }
else
format.html { redirect_back fallback_location: notifications_path, alert: 'Something went wrong.' }
end
if @notification.save
redirect_back fallback_location: notifications_path
else
redirect_back fallback_location: notifications_path, alert: 'Something went wrong.'
end
end

Expand Down
27 changes: 0 additions & 27 deletions app/views/notifications/_form.html.erb

This file was deleted.

3 changes: 3 additions & 0 deletions app/views/notifications/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
<% @notifications.each do |notification| %>
<div class="card mb-3 <%= "bg-primary-light" if not notification.read %>">
<div class="card-body">
<%# Delete link %>
<%= link_to fa_icon('trash lg'), notification_path(notification),
method: :delete,
title: 'Delete',
data: { toggle: 'tooltip', placement: 'top',
confirm: 'Are you sure you want to delete this notification?' },
class: "float-right" %>
<%# Mark as read link %>
<%= link_to fa_icon('check lg'), mark_as_read_notification_path(notification),
title: 'Mark as read',
data: { toggle: 'tooltip', placement: 'top'},
class: "float-right mr-2" unless notification.read %>
<%# Notification title %>
<h5 class="card-title">
<%= link_to notification.title, mark_as_read_and_redirect_notification_path(notification) %>
<br>
Expand Down
5 changes: 0 additions & 5 deletions app/views/notifications/new.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
resources :hosts, only: %i[index show], constraints: { id: /.*/ }

# '/notifications/...'
resources :notifications, only: %i[index new create destroy] do
resources :notifications, only: %i[index destroy] do
member do
get :mark_as_read
get :mark_as_read_and_redirect
Expand Down

0 comments on commit 2f4bd89

Please sign in to comment.