2017-06-02 16:19:49 +02:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
2017-06-21 15:25:18 +02:00
|
|
|
<meta charset="utf-8"/>
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
|
|
<link href="/node_modules/semantic-ui-css/semantic.min.css" rel="stylesheet"/>
|
|
|
|
<link href="/static/css/main.css" rel="stylesheet"/>
|
|
|
|
<title>microStock Dummy Cart</title>
|
2017-06-02 16:19:49 +02:00
|
|
|
</head>
|
2017-06-09 09:42:39 +02:00
|
|
|
<body ng-app="microStockDummieCare" ng-controller="MainCtrl">
|
2017-06-21 15:25:18 +02:00
|
|
|
<nav class="ui stackable inverted menu">
|
|
|
|
<div class="ui container">
|
|
|
|
<div class="header item">Dummy Cart</div>
|
|
|
|
<div class="right menu">
|
|
|
|
<a class="ui item" ng-click="reset()">
|
|
|
|
<i class="undo icon"></i>
|
|
|
|
Reset
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
<div class="ui container">
|
|
|
|
<form class="ui form" ng-submit="add()">
|
|
|
|
<div class="three fields">
|
|
|
|
<div class="field">
|
|
|
|
<div class="ui fluid search selection dropdown">
|
|
|
|
<input name="country" type="hidden">
|
|
|
|
<i class="dropdown icon"></i>
|
|
|
|
<div class="default text">Select Product</div>
|
|
|
|
<div class="menu">
|
|
|
|
<div class="item" ng-repeat="item in products" data-value="{{item.id}}"><img class="icon"
|
2017-06-23 17:09:03 +02:00
|
|
|
ng-src="{{'/api/good/availablity/'+item.id| reloadSrc}}"/>{{item.name}}
|
2017-06-21 15:25:18 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
|
|
|
<input placeholder="Count" type="number" min="1" max="50" ng-model="goods.count">
|
|
|
|
</div>
|
|
|
|
<div class="field">
|
|
|
|
<button type="submit" class="ui button" tabindex="0">Add</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<table class="ui table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Count</th>
|
|
|
|
<th>Product</th>
|
|
|
|
<th></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr ng-repeat="item in cart">
|
|
|
|
<td>{{item.count}}</td>
|
2017-06-23 17:09:03 +02:00
|
|
|
<td>{{getProduct(item.product_id).name}}</td>
|
2017-06-21 15:25:18 +02:00
|
|
|
<td>
|
|
|
|
<div class="ui button icon" ng-click="del(item)"><i class="icon trash"></i></div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2017-06-23 17:09:03 +02:00
|
|
|
<button class="ui icon button" tabindex="0" ng-click="buy()"><i class="icon shop"></i>Buy</button>
|
2017-06-21 15:25:18 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<footer class="ui vertical footer segment">
|
2017-06-02 16:19:49 +02:00
|
|
|
<div class="ui center aligned container">
|
2017-06-21 15:25:18 +02:00
|
|
|
<p>© 2017 MM / Go - Team</p>
|
2017-06-02 16:19:49 +02:00
|
|
|
</div>
|
2017-06-21 15:25:18 +02:00
|
|
|
</footer>
|
|
|
|
<script src="/node_modules/jquery/dist/jquery.min.js"></script>
|
|
|
|
<script src="/node_modules/semantic-ui-css/semantic.min.js"></script>
|
|
|
|
<script src="/node_modules/angular/angular.min.js"></script>
|
|
|
|
<script src="/node_modules/angular-animate/angular-animate.min.js"></script>
|
|
|
|
<script src="/node_modules/angular-ui-router/release/angular-ui-router.min.js"></script>
|
|
|
|
<script src="/node_modules/angular-loading-bar/build/loading-bar.min.js"></script>
|
|
|
|
<script>
|
2017-06-02 16:19:49 +02:00
|
|
|
var config = {
|
2017-06-05 23:27:27 +02:00
|
|
|
'microservice_dependencies': {
|
2017-06-23 12:29:30 +02:00
|
|
|
'products': 'http://localhost:8080/products.json',
|
|
|
|
'productById': 'http://localhost:8080/products/%d.json',
|
2017-06-05 14:30:31 +02:00
|
|
|
'lockGoods': '/api/goods/locking',
|
2017-06-23 17:09:03 +02:00
|
|
|
'unlockGoods': '/api/goods/locking',
|
|
|
|
'buyGoods': '/api/goods/locking',
|
2017-06-02 16:19:49 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let selectedProduct = null;
|
|
|
|
$(".dropdown").dropdown().dropdown('setting', {
|
|
|
|
onChange: function (value) {
|
|
|
|
selectedProduct = parseInt(value, 10);
|
|
|
|
console.log('changed product', selectedProduct);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function createUUID () {
|
|
|
|
let digit = new Date().getTime();
|
|
|
|
|
|
|
|
// Use high-precision timer if available
|
|
|
|
/* eslint-disable */
|
|
|
|
if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
|
|
|
|
digit += performance.now();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (char) => {
|
|
|
|
const result = (digit + Math.random() * 16) % 16 | 0;
|
|
|
|
|
|
|
|
digit = Math.floor(digit / 16);
|
|
|
|
|
|
|
|
return (char === 'x'
|
|
|
|
? result
|
|
|
|
: result & 0x3 | 0x8).toString(16);
|
|
|
|
});
|
|
|
|
/* eslint-enable*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
angular.module('microStockDummieCare', [
|
|
|
|
'angular-loading-bar',
|
|
|
|
'ngAnimate'
|
|
|
|
])
|
|
|
|
.filter('reloadSrc', function () {
|
|
|
|
return function (input) {
|
|
|
|
if (input)
|
|
|
|
return input + '?v=' + new Date().getTime();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.controller('MainCtrl',['$scope', '$http',function($scope, $http) {
|
|
|
|
$scope.products = [];
|
2017-06-23 17:09:03 +02:00
|
|
|
$scope.goods = {count: 1};
|
2017-06-02 16:19:49 +02:00
|
|
|
$scope.cart = [];
|
2017-06-23 17:09:03 +02:00
|
|
|
let secret = createUUID();
|
2017-06-02 16:19:49 +02:00
|
|
|
|
|
|
|
$http.get(config.microservice_dependencies.products).then(function(res) {
|
|
|
|
$scope.products = res.data;
|
|
|
|
});
|
|
|
|
|
|
|
|
function load() {
|
|
|
|
const tmp = JSON.parse(localStorage.getItem("cart"));
|
2017-06-23 17:09:03 +02:00
|
|
|
const secretTmp = JSON.parse(localStorage.getItem("cart"));
|
2017-06-02 16:19:49 +02:00
|
|
|
if(tmp) {
|
|
|
|
$scope.cart = tmp.map((item) => {
|
|
|
|
delete item.$$hashKey
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
}
|
2017-06-23 17:09:03 +02:00
|
|
|
if(secretTmp && secretTmp === "") {
|
|
|
|
secret = secretTmp;
|
|
|
|
}
|
2017-06-02 16:19:49 +02:00
|
|
|
}
|
2017-06-23 17:09:03 +02:00
|
|
|
function save() {
|
|
|
|
localStorage.setItem("cart", JSON.stringify($scope.cart));
|
|
|
|
localStorage.setItem("secret", secret);
|
2017-06-02 16:19:49 +02:00
|
|
|
}
|
|
|
|
load();
|
|
|
|
|
2017-06-23 17:09:03 +02:00
|
|
|
$scope.getProduct = function getProduct(id) {
|
2017-06-02 16:19:49 +02:00
|
|
|
if(id) {
|
|
|
|
return $scope.products.filter((item) => item.id === id)[0];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.add = function add() {
|
|
|
|
$scope.goods.product_id = selectedProduct;
|
2017-06-05 14:30:31 +02:00
|
|
|
$http({
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'secret': secret
|
|
|
|
},
|
|
|
|
url: config.microservice_dependencies.lockGoods,
|
|
|
|
data: [$scope.goods]
|
|
|
|
}).then(function(res) {
|
2017-06-02 16:19:49 +02:00
|
|
|
console.log('add', $scope.goods);
|
|
|
|
$scope.cart.push($scope.goods);
|
|
|
|
save();
|
2017-06-23 17:09:03 +02:00
|
|
|
$scope.goods = {count: 1};
|
2017-06-02 16:19:49 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.del = function del(entry) {
|
2017-06-05 14:30:31 +02:00
|
|
|
$http({
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: {
|
2017-06-23 17:09:03 +02:00
|
|
|
'secret': secret,
|
|
|
|
'Content-Type': 'application/json',
|
2017-06-05 14:30:31 +02:00
|
|
|
},
|
2017-06-23 17:09:03 +02:00
|
|
|
url: config.microservice_dependencies.unlockGoods,
|
|
|
|
data: [entry]
|
2017-06-05 14:30:31 +02:00
|
|
|
}).then(function(res) {
|
2017-06-02 16:19:49 +02:00
|
|
|
console.log('del', entry);
|
|
|
|
$scope.cart = $scope.cart.filter((item) => item !== entry);
|
|
|
|
save();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-06-23 17:09:03 +02:00
|
|
|
$scope.buy = function buy() {
|
|
|
|
$http({
|
|
|
|
method: 'PUT',
|
|
|
|
headers: {
|
|
|
|
'secret': secret
|
|
|
|
},
|
|
|
|
url: config.microservice_dependencies.buyGoods,
|
|
|
|
}).then(function(res) {
|
|
|
|
console.log('buy');
|
|
|
|
$scope.reset();
|
|
|
|
},function(err) {
|
|
|
|
console.warn('buy', err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-06-09 09:42:39 +02:00
|
|
|
$scope.reset = function reset() {
|
|
|
|
console.log("reset");
|
2017-06-23 17:09:03 +02:00
|
|
|
localStorage.setItem("cart", "[]");
|
|
|
|
localStorage.setItem("secret", createUUID());
|
2017-06-09 09:42:39 +02:00
|
|
|
load();
|
|
|
|
};
|
|
|
|
|
2017-06-02 16:19:49 +02:00
|
|
|
}]);
|
2017-06-21 15:25:18 +02:00
|
|
|
|
|
|
|
</script>
|
2017-06-02 16:19:49 +02:00
|
|
|
</body>
|
|
|
|
</html>
|