From c94738123ab48077c868132c7e2c8e98f021745f Mon Sep 17 00:00:00 2001 From: benji Date: Sat, 14 Jan 2017 23:12:45 +0100 Subject: [PATCH] Add card view for open outgoing requests --- app/controllers/pages_controller.rb | 7 ++++--- app/models/user.rb | 2 +- app/views/pages/_outgoing_requests.html.haml | 17 +++++++++++++++++ app/views/pages/landing.html.haml | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 app/views/pages/_outgoing_requests.html.haml diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index a1cf131..c9f0efd 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -3,9 +3,10 @@ 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) - @requests = current_user.incoming_requests.open.includes(:creditor).take(10) - @notifications = current_user.notifications.unread + @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) + @outgoing_requests = current_user.outgoing_requests.open.includes(:debtor).take(10) + @notifications = current_user.notifications.unread end def sign_in_page diff --git a/app/models/user.rb b/app/models/user.rb index df5aa07..a60aceb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -21,7 +21,7 @@ class User < ActiveRecord::Base has_many :incoming_requests, class_name: 'Request', foreign_key: 'debtor_id' has_many :outgoing_requests, - class_name: 'Request', foreign_key: 'debtor_id' + class_name: 'Request', foreign_key: 'creditor_id' has_many :notifications has_many :issued_transactions, as: :issuer, class_name: 'Transaction' diff --git a/app/views/pages/_outgoing_requests.html.haml b/app/views/pages/_outgoing_requests.html.haml new file mode 100644 index 0000000..83b85ff --- /dev/null +++ b/app/views/pages/_outgoing_requests.html.haml @@ -0,0 +1,17 @@ +.card-wrapper + - if @outgoing_requests.any? + .card + .padded + %h3 Outgoing Requests + - @outgoing_requests.each do |r| + .request.pure-g + .pure-u-2-3 + %h4= r.message + = r.debtor.name + .pure-u-1-3.actions + = euro_from_cents r.amount + .clear-both + - else + .card.padded + %span.info-message + You have no open outgoing requests at the moment. diff --git a/app/views/pages/landing.html.haml b/app/views/pages/landing.html.haml index 7458a5f..87db746 100644 --- a/app/views/pages/landing.html.haml +++ b/app/views/pages/landing.html.haml @@ -5,3 +5,4 @@ = render 'transaction_form' = render 'requests' = render 'notifications' + = render 'outgoing_requests'