genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0

[TASK] add on webadmin adding goods

This commit is contained in:
Martin Geno 2017-05-12 10:17:27 +02:00
parent 6e9fdfd59e
commit 73038ca70a
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
8 changed files with 70 additions and 34 deletions

View File

@ -37,7 +37,12 @@ func addGood(w http.ResponseWriter, r *http.Request) {
}
var obj models.Good
lib.Read(r, &obj)
err = lib.Read(r, &obj)
if err != nil {
log.Warn(err.Error())
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
obj.ProductID = id

View File

@ -5,12 +5,13 @@ import (
"encoding/json"
"errors"
"net/http"
"strings"
)
// Function to read data from a http request via json format (input)
func Read(r *http.Request, to interface{}) (err error) {
if r.Header.Get("Content-Type") != "application/json" {
err = errors.New("no json data recived")
if !strings.Contains(r.Header.Get("Content-Type"), "application/json") {
err = errors.New("no json request recieved")
return
}
err = json.NewDecoder(r.Body).Decode(to)

View File

@ -12,19 +12,19 @@ import (
// Goods managed in this stock microservice
type Good struct {
ID int64
ProductID int64
Position string
Comment string
FouledAt *time.Time
ID int64 `json:"id"`
ProductID int64 `json:"product_id"`
Position string `json:"position"`
Comment string `json:"comment"`
FouledAt *time.Time `json:"fouled_at"`
RecievedAt *time.Time `sql:"default:current_timestamp"`
RecievedAt *time.Time `sql:"default:current_timestamp" json:"recieved_at"`
// Make it temporary unusable
LockedAt *time.Time
LockedAt *time.Time `json:"-"`
LockedSecret string `json:"-"`
// Make it unusable
DeletedAt *time.Time
Sended bool
DeletedAt *time.Time `json:"-"`
Sended bool `json:"-"`
}
// Function to enerate a database and select locked goods with a filter

View File

@ -9,11 +9,16 @@
<title>Stock Admin</title>
</head>
<body ng-app="microStock">
<nav class="ui stackable inverted menu">
<nav class="ui stackable inverted menu" ng-controller="GlobalCtrl">
<div class="ui container">
<div class="header item">Stock Admin</div>
<a class="item" ui-sref="list" ui-active="active">List</a>
<a class="item" ui-sref="statistics">Statistics</a><
<a class="item" ui-sref="statistics" ui-active="active">Statistics</a><
<div class="right menu">
<a class="ui item" ng-click="login()">
<i class="icon" ng-class="{'unlock':loggedIn,'lock':!loggedIn}"></i>
</a>
</div>
</div>
</nav>
@ -30,6 +35,8 @@
<script src="/node_modules/angular-loading-bar/build/loading-bar.min.js"></script>
<script src="/static/js/main.js"></script>
<script src="/static/js/item.controller.js"></script>
<script src="/static/js/item-add.controller.js"></script>
<script src="/static/js/global.js"></script>
<script src="/static/js/list.controller.js"></script>
<script src="/static/js/statistics.controller.js"></script>
</body>

View File

@ -1,32 +1,41 @@
<h1>{{obj.title}} <img class="icon" src="/api/good/availablity/{{obj.id}}"/></h1>
<h1>
{{obj.title}}
<img class="icon" src="/api/good/availablity/{{obj.id}}"/>
<a class="ui icon button mini right floated" ui-sref="item-add({productid: obj.id})"><i class="icon plus"></i></a>
</h1>
<table class="ui table very basic">
<tr>
<td>Count</td>
<td>Time of Delevery</td>
<td>Status of Freshness</td>
<td>< /td>
<td>Product ID</td>
<td>{{obj.id}}</td>
</tr>
<tr>
<td>Count</td>
<td>{{list.length}}</td>
<td>#</td>
<td><img class="icon" src="/api/good/freshness"/></td>
<td><i class="trash icon"></i></td>
</tr>
</table>
<h2>Goods of this product</h2>
<table class="ui table list" ng-if="list.length > 0">
<thead>
<tr>
<th>#</th>
<th>Location</th>
<th>Comment</th>
<th>Time of Delivery</th>
<th>Status of Freshness</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in list">
<td>{{item.id}}</td>
<td>{{item.position}}</td>
<td>{{item.comment}}</td>
<td></td>
<td>
<img class="icon" ng-src="/api/good/freshness/{{item.id}}"/>
{{item.fouled_at|date:"shortDate"}}
</td>
<td><i class="trash icon" ng-click="delete(item.id)"></i></td>
</tr>
</tbody>
</table>

View File

@ -2,9 +2,10 @@
<table class="ui very compact table">
<thead>
<tr>
<th>#</th>
<th>Productname</th>
<th>Amount</th>
<th class="two wide">#</th>
<th class="twelve wide">Productname</th>
<th class="one wide">Amount</th>
<th class="one wide"></th>
</tr>
</thead>
<tbody>
@ -12,7 +13,10 @@
<td>{{item.id}}</td>
<td><a ui-sref="item({productid: item.id})">{{item.title}}</a></td>
<td>
<img class="icon" src="/api/good/availablity/{{item.id}}"/>
<img class="icon" ng-src="/api/good/availablity/{{item.id}}"/>
</td>
<td>
<a class="ui icon button" ui-sref="item-add({productid: item.id})"><i class="icon plus"></i></a>
</td>
</tr>
</tbody>

View File

@ -11,4 +11,9 @@ angular.module('microStock')
$http.get(config.store.goods.productById.replace("%d",$stateParams.productid)).then(function(res) {
$scope.list = res.data
});
$scope.delete = function(){
$http.delete(config.store.goods.productById.replace("%d",$stateParams.productid)).then(function(res) {
$scope.list = res.data
});
}
}]);

View File

@ -19,6 +19,11 @@ angular.module('microStock', [
templateUrl: '/static/html/item.html',
controller: 'ItemCtrl'
})
.state('item-add', {
url: '/product/:productid/add',
templateUrl: '/static/html/item-add.html',
controller: 'ItemAddCtrl'
})
.state('statistics', {
url: '/statistics',
templateUrl: '/static/html/statistics.html',