diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index bacf92d..1de917d 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,6 +12,7 @@ // //= require jquery //= require jquery_ujs +//= require bootstrap-sprockets //= require dataTables/jquery.dataTables //= require dataTables/extras/dataTables.responsive //= require dataTables/jquery.dataTables diff --git a/app/assets/stylesheets/card.scss b/app/assets/stylesheets/card.scss index c345473..4f3f737 100644 --- a/app/assets/stylesheets/card.scss +++ b/app/assets/stylesheets/card.scss @@ -6,8 +6,12 @@ box-shadow: 0 1px 3px rgba(0,0,0, 0.12), 0 1px 2px rgba(0,0,0, 0.24); border-radius: 2px; - &.padded { - padding: 10px; + h1, .h1, h2, .h2, h3, .h3 { + margin-top: 0; } } } + +.padded { + padding: 10px; +} diff --git a/app/assets/stylesheets/landing.css.scss b/app/assets/stylesheets/landing.css.scss index d0c35e8..48f0550 100644 --- a/app/assets/stylesheets/landing.css.scss +++ b/app/assets/stylesheets/landing.css.scss @@ -90,3 +90,22 @@ a.login-button { } } } + +.request { + h4 { + margin: 0; + color: #0072ae; + font-size: 1em; + text-transform: uppercase; + } + +} + +.notification ,.request { + border-top: 1px solid #c7d0d5; + padding: 15px 10px; + + .actions { + text-align: right; + } +} diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 7fb1360..12fe2ec 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -1,3 +1,7 @@ #content { padding: 30px; } + +.info-message { + color: rgb(144, 148, 156); +} diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 9f86424..8978823 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -10,7 +10,7 @@ class NotificationsController < ApplicationController def read @notification.read! - redirect_to user_notifications_path(@notification.user) + redirect_to root_path end private diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 2b811fc..a1cf131 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -3,10 +3,12 @@ class PagesController < ApplicationController def landing query = TransactionsQuery.new(current_user) - @transactions = ActiveRecord::Base.connection.exec_query(query.query.order(query.arel_table[:time].desc).take(10).project(Arel.star).to_sql) + @transactions = ActiveRecord::Base.connection.exec_query(query.query.order(query.arel_table[:time].desc).take(10).project(Arel.star).to_sql) + @requests = current_user.incoming_requests.open.includes(:creditor).take(10) + @notifications = current_user.notifications.unread end - def sign_in + def sign_in_page @statistics = Statistics.new end end diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index 57d68ad..f2c5ac5 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -10,12 +10,12 @@ class RequestsController < ApplicationController def confirm @request.confirm! - redirect_to user_requests_path(@request.debtor) + redirect_to root_path end def decline @request.decline! - redirect_to user_requests_path(@request.debtor) + redirect_to root_path end private diff --git a/app/models/concerns/base_transaction.rb b/app/models/concerns/base_transaction.rb index d9ee12a..ece8add 100644 --- a/app/models/concerns/base_transaction.rb +++ b/app/models/concerns/base_transaction.rb @@ -1,6 +1,7 @@ module BaseTransaction extend ActiveSupport::Concern include ActionView::Helpers::NumberHelper + include ApplicationHelper included do belongs_to :debtor, class_name: 'User' diff --git a/app/models/notification.rb b/app/models/notification.rb index a926d62..aed0e88 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -13,6 +13,8 @@ class Notification < ActiveRecord::Base belongs_to :user + scope :unread, -> { where read: false } + def read! update_attributes read: true end diff --git a/app/views/application/_menu.html.haml b/app/views/application/_menu.html.haml index 19cfb9b..820f8f6 100644 --- a/app/views/application/_menu.html.haml +++ b/app/views/application/_menu.html.haml @@ -5,10 +5,10 @@ = link_to 'Transactions', current_user, class: 'menu-item' = link_to user_requests_path(current_user), class: 'menu-item' do Requests - %span.badge= current_user.incoming_requests.size + %span.badge= current_user.incoming_requests.open.size = link_to user_notifications_path(current_user), class: 'menu-item' do Notifications - %span.badge= current_user.notifications.size + %span.badge= current_user.notifications.unread.size - if current_user.penning = link_to 'Zeus', User.zeus, class: 'menu-item' = link_to user_requests_path(User.zeus), class: 'menu-item' do diff --git a/app/views/application/_menu_requests.html.haml b/app/views/application/_menu_requests.html.haml new file mode 100644 index 0000000..a84a92c --- /dev/null +++ b/app/views/application/_menu_requests.html.haml @@ -0,0 +1,3 @@ += link_to user_requests_path(user), class: 'menu-item' do + Requests + %span.badge= user.incoming_requests.open.size diff --git a/app/views/pages/_notifications.html.haml b/app/views/pages/_notifications.html.haml new file mode 100644 index 0000000..a3943a6 --- /dev/null +++ b/app/views/pages/_notifications.html.haml @@ -0,0 +1,16 @@ +.card-wrapper + - if @notifications.any? + .card + .padded + %h3 Notifications + - @notifications.each do |n| + .notification.pure-g + .pure-u-11-12 + = n.message + .pure-u-1-12.actions + = link_to notification_read_path(n), method: :post do + %span.glyphicon.glyphicon-eye-open + - else + .card.padded + %span.info-message + You have no unread notifications. diff --git a/app/views/pages/_requests.html.haml b/app/views/pages/_requests.html.haml new file mode 100644 index 0000000..87f61b9 --- /dev/null +++ b/app/views/pages/_requests.html.haml @@ -0,0 +1,23 @@ +.card-wrapper + - if @requests.any? + .card + .padded + %h3 Requests + - @requests.each do |r| + .request.pure-g + .pure-u-1-3 + %h4= r.message + = r.creditor.name + .pure-u-1-3 + = euro_from_cents r.amount + .pure-u-1-3.actions + .btn-group + = link_to request_confirm_path(r), method: :post, class: 'btn btn-default btn-success' do + %span.glyphicon.glyphicon-ok + = link_to request_decline_path(r), method: :post, class: 'btn btn-default btn-danger' do + %span.glyphicon.glyphicon-remove + .clear-both + - else + .card.padded + %span.info-message + You have no open requests at the moment. diff --git a/app/views/pages/_transaction_form.html.haml b/app/views/pages/_transaction_form.html.haml new file mode 100644 index 0000000..2da34ad --- /dev/null +++ b/app/views/pages/_transaction_form.html.haml @@ -0,0 +1,3 @@ +.card-wrapper + .card.padded + = react_component 'TransactionForm', user: current_user, peers: User.all.order(:name).pluck(:name) diff --git a/app/views/pages/landing.html.haml b/app/views/pages/landing.html.haml index 34ca1c9..7458a5f 100644 --- a/app/views/pages/landing.html.haml +++ b/app/views/pages/landing.html.haml @@ -2,13 +2,6 @@ .pure-u-7-12 = render 'transactions' .pure-u-5-12 - .card-wrapper - .card.padded - = react_component 'TransactionForm', user: current_user, peers: User.all.order(:name).pluck(:name) - .card-wrapper - .card - requests - .card-wrapper - .card - notifications - + = render 'transaction_form' + = render 'requests' + = render 'notifications' diff --git a/app/views/pages/sign_in.html.haml b/app/views/pages/sign_in_page.html.haml similarity index 100% rename from app/views/pages/sign_in.html.haml rename to app/views/pages/sign_in_page.html.haml diff --git a/config/routes.rb b/config/routes.rb index dbbf27c..c515e96 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,7 +7,7 @@ Rails.application.routes.draw do root 'pages#landing', as: :authenticated_root end - root to: 'pages#sign_in' + root to: 'pages#sign_in_page' resources :transactions, only: [:index, :create] resources :users, only: [:index, :show] do