From e39510b309f1a71f06d9ada1e5b2fb984c91921d Mon Sep 17 00:00:00 2001
From: Adrian Hinz
Date: Thu, 30 Nov 2017 15:17:34 +0100
Subject: [PATCH] viewsy
---
app/assets/stylesheets/application.css | 7 +++++++
app/controllers/home_controller.rb | 12 +++++++++++
app/views/home/get_trades.js.erb | 2 ++
app/views/home/index.html.erb | 23 ++++++++++++++-------
app/views/home/partials/_bb_trades.html.erb | 22 ++++++++++++++++++++
app/views/home/partials/_left_menu.html.erb | 7 +++++++
app/views/layouts/application.html.erb | 3 ++-
config/routes.rb | 1 +
8 files changed, 68 insertions(+), 9 deletions(-)
create mode 100644 app/views/home/get_trades.js.erb
create mode 100644 app/views/home/partials/_bb_trades.html.erb
create mode 100644 app/views/home/partials/_left_menu.html.erb
diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css
index 60f289d..ac442dd 100644
--- a/app/assets/stylesheets/application.css
+++ b/app/assets/stylesheets/application.css
@@ -23,6 +23,10 @@
/* Margin bottom by footer height */
margin-bottom: 60px;
}
+ .starter {
+ padding-left: 0.2em;
+ padding-right: 0.2em;
+ }
.footer {
position: absolute;
bottom: 0;
@@ -31,4 +35,7 @@
height: 60px;
line-height: 60px; /* Vertically center the text there */
background-color: #f5f5f5;
+ }
+ .li_active {
+ color: #0923ff;
}
\ No newline at end of file
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index aaec5e0..1ccd1a8 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -1,6 +1,8 @@
class HomeController < ApplicationController
def index
@currencies = Currency.all
+ @curr_id = Currency.first.id
+ bbt
end
def seed
@@ -18,4 +20,14 @@ class HomeController < ApplicationController
end
end
end
+
+ def get_trades
+ @currencies = Currency.all
+ @curr_id = params[:curr_id]
+ bbt
+ end
+
+ def bbt
+ @bbt = BitBayTrade.where('currency_id = ?', @curr_id).order('cast(tid as unsigned) DESC').limit(20)
+ end
end
diff --git a/app/views/home/get_trades.js.erb b/app/views/home/get_trades.js.erb
new file mode 100644
index 0000000..497255e
--- /dev/null
+++ b/app/views/home/get_trades.js.erb
@@ -0,0 +1,2 @@
+$("#bbt_ajax").html("<%= escape_javascript(render('/home/partials/bb_trades')) %>");
+$("#left_menu").html("<%= escape_javascript(render('/home/partials/left_menu')) %>");
\ No newline at end of file
diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb
index b6c8c97..33b0e9f 100644
--- a/app/views/home/index.html.erb
+++ b/app/views/home/index.html.erb
@@ -1,8 +1,15 @@
-Currencies
-
-
-<% for curr in @currencies %>
-- <%= curr.name %> (<%= curr.description %>)
-<% end %>
-
-
+
+
+
+
+ <%= render :partial => '/home/partials/bb_trades'%>
+
+
+
diff --git a/app/views/home/partials/_bb_trades.html.erb b/app/views/home/partials/_bb_trades.html.erb
new file mode 100644
index 0000000..533def8
--- /dev/null
+++ b/app/views/home/partials/_bb_trades.html.erb
@@ -0,0 +1,22 @@
+
+
+
+ | tid |
+ Data |
+ Cena |
+ Ilość |
+ Koszt transakcji |
+
+
+
+ <% for bbt in @bbt %>
+
+ | <%= bbt.tid %> |
+ <%= bbt.date %> |
+ <%= '%.2f' % bbt.price %> |
+ <%= bbt.amount %> |
+ <%= '%.2f' % (bbt.price * bbt.amount) %> |
+
+ <% end %>
+
+
\ No newline at end of file
diff --git a/app/views/home/partials/_left_menu.html.erb b/app/views/home/partials/_left_menu.html.erb
new file mode 100644
index 0000000..2db5c1d
--- /dev/null
+++ b/app/views/home/partials/_left_menu.html.erb
@@ -0,0 +1,7 @@
+<% for curr in @currencies %>
+ <% if @curr_id.to_i == curr.id %>
+ <%= link_to "#{curr.name} (#{curr.description})", {controller: :home, action: :get_trades, curr_id: curr.id}, remote: true, class: "btn btn-primary btn-md btn-block active", role: "button", 'aria-pressed' => true %>
+ <% else %>
+ <%= link_to "#{curr.name} (#{curr.description})", {controller: :home, action: :get_trades, curr_id: curr.id}, remote: true, class: "btn btn-primary btn-md btn-block", role: "button" %>
+ <% end%>
+<% end %>
\ No newline at end of file
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 673a4a9..e8d677d 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -41,8 +41,9 @@
-
+
<%= yield %>
+