Skip to content

Commit

Permalink
UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
antweiss committed Dec 2, 2016
1 parent 53546a1 commit 293f4e1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 48 deletions.
65 changes: 32 additions & 33 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function Poduct(name, price) {
exports.index = function(req, res){
prod_url = "http://" + process.env.PRODUCT_SERVICE_HOST + ":" + process.env.PRODUCT_SERVICE_PORT + "/product"
order_url = "http://" + process.env.ORDER_SERVICE_HOST + ":" + process.env.ORDER_SERVICE_PORT + "/orders"

console.log(prod_url)
var products = []
var orders = []
Expand All @@ -23,23 +23,20 @@ exports.index = function(req, res){
{
console.log(body)
products = JSON.parse(body)._items
// res.render( 'index', {
// title : 'Products',
// products : JSON.parse(body)._items,
//orders : orders
// });
}})
request(order_url, function (error, response, body) {
if (!error && response.statusCode == 200)
{
console.log(body)
res.render( 'index', {
title : 'Orders',
products : products,
orders : JSON.parse(body)._embedded.orders
});
request(order_url, function (error, response, body) {
if (!error && response.statusCode == 200)
{
console.log(body)
res.render( 'index', {
title : 'Orders',
products : products,
orders : JSON.parse(body)._embedded.orders
});
}})
}})

};

exports.register = function ( req, res ){
console.log(req.body);
prod_url = "http://" + process.env.PRODUCT_SERVICE_HOST + ":" + process.env.PRODUCT_SERVICE_PORT + "/product"
Expand All @@ -48,6 +45,7 @@ exports.register = function ( req, res ){
json: {"name": req.body.Product_name, "price": req.body.price, "stock": 0 }}, res.redirect('/'))

};

exports.order = function ( req, res ){
console.log(req.body);
var prod_url = "http://" + process.env.PRODUCT_SERVICE_HOST + ":" + process.env.PRODUCT_SERVICE_PORT + "/product"
Expand All @@ -61,31 +59,32 @@ exports.order = function ( req, res ){

var prod_id = "";
var total = 0;
console.log("starting to iterate on prods");
for (var prod of products) {
console.log(prod.name);
if ( prod.name == req.body.chosen )
{
prod_id = prod._id;
total = prod.price * req.body.amount[0];
order_url = "http://" + process.env.ORDER_SERVICE_HOST + ":" + process.env.ORDER_SERVICE_PORT + "/order"
order_url = "http://" + process.env.ORDER_SERVICE_HOST + ":" + process.env.ORDER_SERVICE_PORT + "/orders"
console.log(prod_id + " amount" + req.body.amount[0] + " totalSum " + total);
request({ url: order_url,
method: 'POST',
json: {"id": prod_id, "amount": req.body.amount, "totalSum": total }}, function(error, response, body){
if (!error && response.statusCode == 200)
{
console.log(body);
res.redirect('/')
}
else
{
console.log("error" + body);
res.redirect('/')
})
json: {"productId": prod_id, "amount": req.body.amount[0], "totalSum": total }},
function(error, response, body){
if (!error && response.statusCode == 200)
{
console.log(body);
res.redirect('/')
}
else
{
console.log("error " + body);
res.redirect('/')
}})

}
}
}


})

}
})
};
34 changes: 19 additions & 15 deletions views/index.jade
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
extends layout

block content
h1= title
p Welcome to #{title}
p Register products:
form(name="register", action="/register", method="post")
span.label productName
span.label productName
input(type="text", name="Product_name", id="pname")
span.label Price
input(type="number", name="price", id="price")
span.label Price
input(type="number", name="price", id="price" step="0.01")
input(type="submit", name="register", value="register")
div

br
= '\n'
p Choose product:
form(action="/order", method="post")
if products
each product in products
input(type='radio', name='chosen', value=product.name)
| #{product.name} #{product.price}
span.label Desired Amount
input(type="number", name="amount", id="amount", value=0)
br
input(type='radio', name='chosen', value=product.name)
| #{product.name} #{product.price}
br
br
span.label Insert Desired Amount:
input(type="number", name="amount", id="amount", value=0)
input(type="submit", name="order", value="order now")

= '\n'
p Your orders:
ul
each order in orders
li= order.id + ':' + order.amount + ':' + order.totalSum

- var prodname = "undef"
each product in products
if product._id == order.productId
- prodname = product.name
li= "Product: " + prodname + '| amount :' + order.amount + '| total :' + order.totalSum + "| link :" + order._links.self.href

0 comments on commit 293f4e1

Please sign in to comment.