From 1deb97c3e668781f55487553f59a8bf0fc8f188f Mon Sep 17 00:00:00 2001 From: Rei Date: Wed, 22 Jan 2014 13:43:00 +0800 Subject: [PATCH] Notifcation index page --- app/assets/stylesheets/application.css.scss | 1 + app/assets/stylesheets/campo.css.scss | 11 +++++--- app/assets/stylesheets/notifications.css.scss | 25 +++++++++++++++++++ app/controllers/notifications_controller.rb | 7 ++++++ app/helpers/notifications_helper.rb | 2 ++ app/views/layouts/application.html.slim | 4 +++ app/views/notifications/index.html.slim | 15 +++++++++++ config/routes.rb | 2 ++ .../notifications_controller_test.rb | 10 ++++++++ test/factories/notifications.rb | 1 - test/helpers/notifications_helper_test.rb | 4 +++ 11 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 app/assets/stylesheets/notifications.css.scss create mode 100644 app/controllers/notifications_controller.rb create mode 100644 app/helpers/notifications_helper.rb create mode 100644 app/views/notifications/index.html.slim create mode 100644 test/controllers/notifications_controller_test.rb create mode 100644 test/helpers/notifications_helper_test.rb diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 7aa541f..a1a450e 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -12,6 +12,7 @@ $nav-link-hover-bg: transparent; @import "topics"; @import "posts"; @import "post_votes"; +@import "notifications"; body { background: #eee; diff --git a/app/assets/stylesheets/campo.css.scss b/app/assets/stylesheets/campo.css.scss index 629113f..3d5672e 100644 --- a/app/assets/stylesheets/campo.css.scss +++ b/app/assets/stylesheets/campo.css.scss @@ -7,11 +7,14 @@ background-color: #ccc; } - a { - color: #555; + li { + a { + color: #555; - &:hover { - color: #333; + &:hover { + color: #333; + background-color: #f9f9f9; + } } } } diff --git a/app/assets/stylesheets/notifications.css.scss b/app/assets/stylesheets/notifications.css.scss new file mode 100644 index 0000000..6d3f64e --- /dev/null +++ b/app/assets/stylesheets/notifications.css.scss @@ -0,0 +1,25 @@ +.notifications { + position: relative; + + .badge { + background: $brand-primary; + position: absolute; + top: 5px; + right: 5px; + } +} + +.list-group-notification { + margin: 0 -16px; + padding: 0; + list-style: none; +} + +.list-group-item-notification { + padding: 16px; + border-bottom: 1px solid #eee; + + &:first-child { + border-top: 1px solid #eee; + } +} diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb new file mode 100644 index 0000000..d599555 --- /dev/null +++ b/app/controllers/notifications_controller.rb @@ -0,0 +1,7 @@ +class NotificationsController < ApplicationController + before_filter :require_logined + + def index + @notifications = current_user.notifications.page(params[:page]) + end +end diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb new file mode 100644 index 0000000..7342393 --- /dev/null +++ b/app/helpers/notifications_helper.rb @@ -0,0 +1,2 @@ +module NotificationsHelper +end diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index 67b68fc..93b4869 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -27,6 +27,10 @@ html #navbar.collapse.navbar-collapse ul.nav.navbar-nav.navbar-right - if logined? + li + a.notifications href=notifications_path + i.fa.fa-bell-o + .badge 1 li.dropdown a.dropdown-toggle data-toggle="dropdown" href='#' = current_user.name diff --git a/app/views/notifications/index.html.slim b/app/views/notifications/index.html.slim new file mode 100644 index 0000000..e35a484 --- /dev/null +++ b/app/views/notifications/index.html.slim @@ -0,0 +1,15 @@ +.row + .col-md-9 + .panel.panel-campo + .panel-heading.clearfix + .pull-right + = paginate @notifications, theme: 'campo', left: 1, right: 1, window: 2 + h3.panel-title Notifications + .panel-body + ul.list-group-notification + - @notifications.each do |notification| + - begin + = render "notification/#{notification.name}" + - rescue + .list-group-item-notification + = "##{notification.id} Missing template for #{notification.name} notification." diff --git a/config/routes.rb b/config/routes.rb index e6c3758..904f2f8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,6 +26,8 @@ Rails.application.routes.draw do end end + resources :notifications, only: [:index] + if Rails.env.development? get 'qunit', to: 'qunit#index' end diff --git a/test/controllers/notifications_controller_test.rb b/test/controllers/notifications_controller_test.rb new file mode 100644 index 0000000..7217a08 --- /dev/null +++ b/test/controllers/notifications_controller_test.rb @@ -0,0 +1,10 @@ +require 'test_helper' + +class NotificationsControllerTest < ActionController::TestCase + test "should get index" do + assert_require_logined do + get :index + end + assert_response :success, @response.body + end +end diff --git a/test/factories/notifications.rb b/test/factories/notifications.rb index 277adea..4f41a97 100644 --- a/test/factories/notifications.rb +++ b/test/factories/notifications.rb @@ -3,7 +3,6 @@ FactoryGirl.define do factory :notification do user - subject name "name_type" end end diff --git a/test/helpers/notifications_helper_test.rb b/test/helpers/notifications_helper_test.rb new file mode 100644 index 0000000..6183800 --- /dev/null +++ b/test/helpers/notifications_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class NotificationsHelperTest < ActionView::TestCase +end