Add more info to the landing page

This commit is contained in:
benji 2017-01-14 16:22:44 +01:00
parent af33a89790
commit c160188af5
17 changed files with 91 additions and 20 deletions

View file

@ -12,6 +12,7 @@
// //
//= require jquery //= require jquery
//= require jquery_ujs //= require jquery_ujs
//= require bootstrap-sprockets
//= require dataTables/jquery.dataTables //= require dataTables/jquery.dataTables
//= require dataTables/extras/dataTables.responsive //= require dataTables/extras/dataTables.responsive
//= require dataTables/jquery.dataTables //= require dataTables/jquery.dataTables

View file

@ -6,8 +6,12 @@
box-shadow: 0 1px 3px rgba(0,0,0, 0.12), 0 1px 2px rgba(0,0,0, 0.24); box-shadow: 0 1px 3px rgba(0,0,0, 0.12), 0 1px 2px rgba(0,0,0, 0.24);
border-radius: 2px; border-radius: 2px;
&.padded { h1, .h1, h2, .h2, h3, .h3 {
margin-top: 0;
}
}
}
.padded {
padding: 10px; padding: 10px;
} }
}
}

View file

@ -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;
}
}

View file

@ -1,3 +1,7 @@
#content { #content {
padding: 30px; padding: 30px;
} }
.info-message {
color: rgb(144, 148, 156);
}

View file

@ -10,7 +10,7 @@ class NotificationsController < ApplicationController
def read def read
@notification.read! @notification.read!
redirect_to user_notifications_path(@notification.user) redirect_to root_path
end end
private private

View file

@ -4,9 +4,11 @@ class PagesController < ApplicationController
def landing def landing
query = TransactionsQuery.new(current_user) 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 end
def sign_in def sign_in_page
@statistics = Statistics.new @statistics = Statistics.new
end end
end end

View file

@ -10,12 +10,12 @@ class RequestsController < ApplicationController
def confirm def confirm
@request.confirm! @request.confirm!
redirect_to user_requests_path(@request.debtor) redirect_to root_path
end end
def decline def decline
@request.decline! @request.decline!
redirect_to user_requests_path(@request.debtor) redirect_to root_path
end end
private private

View file

@ -1,6 +1,7 @@
module BaseTransaction module BaseTransaction
extend ActiveSupport::Concern extend ActiveSupport::Concern
include ActionView::Helpers::NumberHelper include ActionView::Helpers::NumberHelper
include ApplicationHelper
included do included do
belongs_to :debtor, class_name: 'User' belongs_to :debtor, class_name: 'User'

View file

@ -13,6 +13,8 @@
class Notification < ActiveRecord::Base class Notification < ActiveRecord::Base
belongs_to :user belongs_to :user
scope :unread, -> { where read: false }
def read! def read!
update_attributes read: true update_attributes read: true
end end

View file

@ -5,10 +5,10 @@
= link_to 'Transactions', current_user, class: 'menu-item' = link_to 'Transactions', current_user, class: 'menu-item'
= link_to user_requests_path(current_user), class: 'menu-item' do = link_to user_requests_path(current_user), class: 'menu-item' do
Requests 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 = link_to user_notifications_path(current_user), class: 'menu-item' do
Notifications Notifications
%span.badge= current_user.notifications.size %span.badge= current_user.notifications.unread.size
- if current_user.penning - if current_user.penning
= link_to 'Zeus', User.zeus, class: 'menu-item' = link_to 'Zeus', User.zeus, class: 'menu-item'
= link_to user_requests_path(User.zeus), class: 'menu-item' do = link_to user_requests_path(User.zeus), class: 'menu-item' do

View file

@ -0,0 +1,3 @@
= link_to user_requests_path(user), class: 'menu-item' do
Requests
%span.badge= user.incoming_requests.open.size

View file

@ -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.

View file

@ -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.

View file

@ -0,0 +1,3 @@
.card-wrapper
.card.padded
= react_component 'TransactionForm', user: current_user, peers: User.all.order(:name).pluck(:name)

View file

@ -2,13 +2,6 @@
.pure-u-7-12 .pure-u-7-12
= render 'transactions' = render 'transactions'
.pure-u-5-12 .pure-u-5-12
.card-wrapper = render 'transaction_form'
.card.padded = render 'requests'
= react_component 'TransactionForm', user: current_user, peers: User.all.order(:name).pluck(:name) = render 'notifications'
.card-wrapper
.card
requests
.card-wrapper
.card
notifications

View file

@ -7,7 +7,7 @@ Rails.application.routes.draw do
root 'pages#landing', as: :authenticated_root root 'pages#landing', as: :authenticated_root
end end
root to: 'pages#sign_in' root to: 'pages#sign_in_page'
resources :transactions, only: [:index, :create] resources :transactions, only: [:index, :create]
resources :users, only: [:index, :show] do resources :users, only: [:index, :show] do