From 546d918700cbc177f4d818445f1033df635026d6 Mon Sep 17 00:00:00 2001 From: benji Date: Wed, 11 Jan 2017 21:18:23 +0100 Subject: [PATCH] Add transactions view --- app/assets/stylesheets/application.css.scss | 4 ++ app/assets/stylesheets/card.scss | 9 ++++ app/assets/stylesheets/landing.css.scss | 48 +++++++++++++++++++++ app/assets/stylesheets/layout.scss | 3 ++ app/assets/stylesheets/menu.scss | 1 + app/controllers/pages_controller.rb | 6 ++- app/models/concerns/base_transaction.rb | 2 +- app/views/layouts/application.html.haml | 2 +- app/views/pages/_transactions.html.haml | 18 ++++++++ app/views/pages/landing.html.haml | 44 ++++++------------- config/routes.rb | 6 ++- 11 files changed, 108 insertions(+), 35 deletions(-) create mode 100644 app/assets/stylesheets/card.scss create mode 100644 app/assets/stylesheets/layout.scss create mode 100644 app/views/pages/_transactions.html.haml diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 594e084..fd2bfd5 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -20,3 +20,7 @@ */ @import "bootstrap-sprockets"; @import "bootstrap"; + +.clear-both { + clear: both; +} diff --git a/app/assets/stylesheets/card.scss b/app/assets/stylesheets/card.scss new file mode 100644 index 0000000..3de7a88 --- /dev/null +++ b/app/assets/stylesheets/card.scss @@ -0,0 +1,9 @@ +.card-wrapper { + padding: 0 20px; + margin-bottom: 10px; + + .card { + box-shadow: 0 1px 3px rgba(0,0,0, 0.12), 0 1px 2px rgba(0,0,0, 0.24); + border-radius: 2px; + } +} diff --git a/app/assets/stylesheets/landing.css.scss b/app/assets/stylesheets/landing.css.scss index e33c853..d0c35e8 100644 --- a/app/assets/stylesheets/landing.css.scss +++ b/app/assets/stylesheets/landing.css.scss @@ -42,3 +42,51 @@ a.login-button { .shame-percentage { text-align: right } + +.transaction { + border-bottom: 1px solid #c7d0d5; + padding: 15px 10px; + font-size: 16px; + color: rgb(45, 54, 59); + + .transaction-calendar { + float: left; + text-align: center; + color: #adbac2; + line-height: 1.1; + margin-top: 0.125em; + + .transaction-day { + font-size: 1.125em; + display: block; + } + + .transaction-month { + font-size: 0.750em; + text-transform: uppercase; + display: block; + } + } + + .transaction-block { + padding-left: 3.500em; + + .transaction-block-l { + width: 75%; + float: left; + + .transaction-message { + margin: 0; + color: #0072ae; + font-size: 1em; + text-transform: uppercase; + } + } + + .transaction-block-r { + width: 25%; + float: left; + text-align: right; + } + } +} diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss new file mode 100644 index 0000000..7fb1360 --- /dev/null +++ b/app/assets/stylesheets/layout.scss @@ -0,0 +1,3 @@ +#content { + padding: 30px; +} diff --git a/app/assets/stylesheets/menu.scss b/app/assets/stylesheets/menu.scss index a401ae6..a53535a 100644 --- a/app/assets/stylesheets/menu.scss +++ b/app/assets/stylesheets/menu.scss @@ -22,6 +22,7 @@ $color: #777; .menu-heading { font-weight: bold; + font-size: 20px; } .menu-list { diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 42b9a09..2b811fc 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,8 +1,12 @@ class PagesController < ApplicationController - require 'statistics' 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) + end + + def sign_in @statistics = Statistics.new end end diff --git a/app/models/concerns/base_transaction.rb b/app/models/concerns/base_transaction.rb index 31c11dc..d9ee12a 100644 --- a/app/models/concerns/base_transaction.rb +++ b/app/models/concerns/base_transaction.rb @@ -18,7 +18,7 @@ module BaseTransaction end def amount_f - number_to_currency amount/100.0, unit: '€' + euro_from_cents amount end private diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 3be4dee..2c9e782 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -10,6 +10,6 @@ %body .pure-g = render 'menu' if current_user - .pure-u-1 + #content.pure-u-1 = render 'flash' = yield diff --git a/app/views/pages/_transactions.html.haml b/app/views/pages/_transactions.html.haml new file mode 100644 index 0000000..2c58fe1 --- /dev/null +++ b/app/views/pages/_transactions.html.haml @@ -0,0 +1,18 @@ +.card-wrapper + .card + - @transactions.each do |t| + - t.symbolize_keys! + - date = Date.parse t[:time] + .transaction + .transaction-calendar + %span.transaction-day= date.strftime('%d') + %span.transaction-month= Date::MONTHNAMES[date.month][0..2] + .transaction-block + .transaction-block-l + %h4.transaction-message + = t[:message] + .transaction-peer + = t[:peer] + .transaction-block-r + = euro_from_cents t[:amount] + .clear-both diff --git a/app/views/pages/landing.html.haml b/app/views/pages/landing.html.haml index 780cfff..e6408f6 100644 --- a/app/views/pages/landing.html.haml +++ b/app/views/pages/landing.html.haml @@ -1,32 +1,14 @@ -%h1.columns-title Tab -= javascript_include_tag "//www.google.com/jsapi", "chartkick" -%h2.columns-title Cute Little Statistics .pure-g - .pure-u-1.pure-u-md-1-2.landing-column - %h3.columns-title Pie of Shame - = pie_chart @statistics.shamehash - %h3.columns-title Table of Shame - %table.pure-table.full-table - %thead - %th Shame on - %th Contribution to Zeus' lack of money - %tbody - - @statistics.shameful_users.each do |user| - %tr - %td.shameful-person= user.name - // Won't divide by zero because there won't be any users with - // a shameful debt if the total debt is zero. - %td.shame-percentage= "#{-100 * user.balance / @statistics.total_debt}%" - .pure-u-1.pure-u-md-1-2.landing-column - %h3.columns-title Distribution of Debt Sources - = pie_chart @statistics.by_issuer - %h3.columns-title Top Debt Creators - %table.pure-table.full-table - %thead - %th Issuer - %th Number of Transactions issued - %tbody - - @statistics.creation_counts.each do |name, count| - %tr - %td.shameful-person= name - %td.shame-percentage= count + .pure-u-7-12 + = render 'transactions' + .pure-u-5-12 + .card-wrapper + .card + nieuwe transactie + .card-wrapper + .card + requests + .card-wrapper + .card + notifications + diff --git a/config/routes.rb b/config/routes.rb index bf9a17a..dbbf27c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,11 @@ Rails.application.routes.draw do omniauth_callbacks: 'callbacks' } - root to: 'pages#landing' + authenticated :user do + root 'pages#landing', as: :authenticated_root + end + + root to: 'pages#sign_in' resources :transactions, only: [:index, :create] resources :users, only: [:index, :show] do