Add transactions view

This commit is contained in:
benji 2017-01-11 21:18:23 +01:00
parent d388226d32
commit 546d918700
11 changed files with 108 additions and 35 deletions

View file

@ -20,3 +20,7 @@
*/ */
@import "bootstrap-sprockets"; @import "bootstrap-sprockets";
@import "bootstrap"; @import "bootstrap";
.clear-both {
clear: both;
}

View file

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

View file

@ -42,3 +42,51 @@ a.login-button {
.shame-percentage { .shame-percentage {
text-align: right 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;
}
}
}

View file

@ -0,0 +1,3 @@
#content {
padding: 30px;
}

View file

@ -22,6 +22,7 @@ $color: #777;
.menu-heading { .menu-heading {
font-weight: bold; font-weight: bold;
font-size: 20px;
} }
.menu-list { .menu-list {

View file

@ -1,8 +1,12 @@
class PagesController < ApplicationController class PagesController < ApplicationController
require 'statistics' require 'statistics'
def landing 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 @statistics = Statistics.new
end end
end end

View file

@ -18,7 +18,7 @@ module BaseTransaction
end end
def amount_f def amount_f
number_to_currency amount/100.0, unit: '€' euro_from_cents amount
end end
private private

View file

@ -10,6 +10,6 @@
%body %body
.pure-g .pure-g
= render 'menu' if current_user = render 'menu' if current_user
.pure-u-1 #content.pure-u-1
= render 'flash' = render 'flash'
= yield = yield

View file

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

View file

@ -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-g
.pure-u-1.pure-u-md-1-2.landing-column .pure-u-7-12
%h3.columns-title Pie of Shame = render 'transactions'
= pie_chart @statistics.shamehash .pure-u-5-12
%h3.columns-title Table of Shame .card-wrapper
%table.pure-table.full-table .card
%thead nieuwe transactie
%th Shame on .card-wrapper
%th Contribution to Zeus' lack of money .card
%tbody requests
- @statistics.shameful_users.each do |user| .card-wrapper
%tr .card
%td.shameful-person= user.name notifications
// 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

View file

@ -3,7 +3,11 @@ Rails.application.routes.draw do
omniauth_callbacks: 'callbacks' 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 :transactions, only: [:index, :create]
resources :users, only: [:index, :show] do resources :users, only: [:index, :show] do