Permalink
Browse files

Stock page and initial styles.

  • Loading branch information...
1 parent fb4e6e4 commit 789956e66c3473661c039ec75742332cfae7d606 @huljas committed Mar 30, 2012
@@ -17,7 +17,7 @@
private static final Logger logger = LoggerFactory.getLogger(Index.class);
@Autowired
- private StockHelper stockHelper;
+ private StockViewHelper stockViewHelper;
@Autowired
private StockRepository stockRepository;
@@ -28,7 +28,7 @@ public String show(Model model) {
List<Stock> stocks = stockRepository.findAllStocks();
model.addAttribute("stocks", stocks);
- model.addAttribute("stockHelper", stockHelper);
+ model.addAttribute("helper", stockViewHelper);
return "index";
}
@@ -0,0 +1,31 @@
+package com.sukyky.controller;
+
+import com.sukyky.model.Stock;
+import com.sukyky.repository.StockRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * @author huljas
+ */
+@Controller
+public class StockDetails {
+
+ @Autowired
+ private StockRepository stockRepository;
+
+ @Autowired
+ private StockViewHelper stockViewHelper;
+
+ @RequestMapping("/stock/{id}")
+ public String stockPage(@PathVariable("id") Long id, Model model) {
+ Stock stock = stockRepository.getStock(id);
+ model.addAttribute("stock", stock);
+ model.addAttribute("helper", stockViewHelper);
+ return "stockDetails";
+ }
+
+}
@@ -13,12 +13,12 @@
* @author huljas
*/
@Component
-public class StockHelper {
+public class StockViewHelper {
@Autowired
private StockRepository stockRepository;
- public StockHelper() {
+ public StockViewHelper() {
}
public String getLastPrice(Stock stock) {
@@ -39,4 +39,36 @@ public String getChangePercent(Stock stock) {
TradeOrder previous = stockRepository.getLastTradeSince(stock, since);
return String.format("%.2f", (last.priceA - previous.priceA) * 100f / previous.priceA);
}
+
+ public String getChangeCss(Stock stock) {
+ if (getLastPrice(stock).startsWith("-")) {
+ return "down";
+ } else {
+ return "up";
+ }
+ }
+
+ public String getYearHigh(Stock stock) {
+ return "yh";
+ }
+
+ public String getYearLow(Stock stock) {
+ return "yl";
+ }
+
+ public String getWeekHigh(Stock stock) {
+ return "wh";
+ }
+
+ public String getWeekLow(Stock stock) {
+ return "wl";
+ }
+
+ public String getDayHigh(Stock stock) {
+ return "dh";
+ }
+
+ public String getDayLow(Stock stock) {
+ return "dl";
+ }
}
@@ -7,7 +7,7 @@
<meta name="description" content="">
<meta name="author" content="">
- <link href="css/screen.css" rel="stylesheet">
+ <link href="/css/screen.css" rel="stylesheet">
<link rel="shortcut icon" href="images/favicon.ico">
</head>
@@ -31,7 +31,10 @@
<tbody>
<#list stocks as stock>
<tr>
- <td>${stock.name}</td><td>${stockHelper.getLastPrice(stock)}</td><td>${stockHelper.getChange(stock)}</td><td>${stockHelper.getChangePercent(stock)}</td></li>
+ <td><a href="/stock/${stock.id}">${stock.name}</a></td>
+ <td>${helper.getLastPrice(stock)}</td>
+ <td>${helper.getChange(stock)}</td>
+ <td>${helper.getChangePercent(stock)}</td>
</tr>
</#list>
</tbody>
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>Stock Borkers Unlimited</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <meta name="description" content="">
+ <meta name="author" content="">
+
+ <link href="/css/screen.css" rel="stylesheet">
+ <link rel="shortcut icon" href="images/favicon.ico">
+</head>
+
+<body>
+
+<div class="navbar navbar-fixed-top">
+ <div class="navbar-inner">
+ <div class="container">
+ <a class="brand" href="/">Stock Borkers Unlimited</a>
+ </div>
+ </div>
+</div>
+
+<div class="container">
+
+ <div class="content-big">
+ <h1>${stock.name}</h1>
+ <div>
+ <span class="pr">${helper.getLastPrice(stock)}</span>
+ <div class="price-change">
+ <span class="${helper.getChangeCss(stock)}">${helper.getChange(stock)}</span>
+ <span class="${helper.getChangeCss(stock)}">${helper.getChangePercent(stock)}</span>
+ </div>
+ <div class="statistics">
+ <table class="statistics-table">
+ <tbody>
+ <tr><th>Year high:</th><td>${helper.getYearHigh(stock)}</td></tr>
+ <tr><th>Year low:</th><td>${helper.getYearLow(stock)}</td></tr>
+ <tr><th>Week high:</th><td>${helper.getWeekHigh(stock)}</td></tr>
+ <tr><th>Week low:</th><td>${helper.getWeekLow(stock)}</td></tr>
+ <tr><th>Days high:</th><td>${helper.getDayHigh(stock)}</td></tr>
+ <tr><th>Days low:</th><td>${helper.getDayLow(stock)}</td></tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ <div>
+ </div>
+ </div>
+
+ <hr>
+
+ <footer>
+ <p>&copy; 2012</p>
+ </footer>
+
+</div>
+
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
+
+</body>
+</html>
@@ -0,0 +1,16 @@
+body {
+ color:#000000;
+ font-family:Arial, sans-serif;
+ font-size:110%;
+}
+
+
+a {
+ color:#1155CC;
+ font-family:Arial, sans-serif;
+ font-weight:normal;
+ text-decoration:none;
+ outline-color:initial;
+ outline-style:none;
+ outline-width:initial;
+}

0 comments on commit 789956e

Please sign in to comment.