[TASK] add on webadmin adding goods
This commit is contained in:
parent
6e9fdfd59e
commit
73038ca70a
|
@ -37,7 +37,12 @@ func addGood(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var obj models.Good
|
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
|
obj.ProductID = id
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,13 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Function to read data from a http request via json format (input)
|
// Function to read data from a http request via json format (input)
|
||||||
func Read(r *http.Request, to interface{}) (err error) {
|
func Read(r *http.Request, to interface{}) (err error) {
|
||||||
if r.Header.Get("Content-Type") != "application/json" {
|
if !strings.Contains(r.Header.Get("Content-Type"), "application/json") {
|
||||||
err = errors.New("no json data recived")
|
err = errors.New("no json request recieved")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = json.NewDecoder(r.Body).Decode(to)
|
err = json.NewDecoder(r.Body).Decode(to)
|
||||||
|
|
|
@ -12,19 +12,19 @@ import (
|
||||||
|
|
||||||
// Goods managed in this stock microservice
|
// Goods managed in this stock microservice
|
||||||
type Good struct {
|
type Good struct {
|
||||||
ID int64
|
ID int64 `json:"id"`
|
||||||
ProductID int64
|
ProductID int64 `json:"product_id"`
|
||||||
Position string
|
Position string `json:"position"`
|
||||||
Comment string
|
Comment string `json:"comment"`
|
||||||
FouledAt *time.Time
|
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
|
// Make it temporary unusable
|
||||||
LockedAt *time.Time
|
LockedAt *time.Time `json:"-"`
|
||||||
LockedSecret string `json:"-"`
|
LockedSecret string `json:"-"`
|
||||||
// Make it unusable
|
// Make it unusable
|
||||||
DeletedAt *time.Time
|
DeletedAt *time.Time `json:"-"`
|
||||||
Sended bool
|
Sended bool `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to enerate a database and select locked goods with a filter
|
// Function to enerate a database and select locked goods with a filter
|
||||||
|
|
|
@ -9,11 +9,16 @@
|
||||||
<title>Stock Admin</title>
|
<title>Stock Admin</title>
|
||||||
</head>
|
</head>
|
||||||
<body ng-app="microStock">
|
<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="ui container">
|
||||||
<div class="header item">Stock Admin</div>
|
<div class="header item">Stock Admin</div>
|
||||||
<a class="item" ui-sref="list" ui-active="active">List</a>
|
<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>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
@ -30,6 +35,8 @@
|
||||||
<script src="/node_modules/angular-loading-bar/build/loading-bar.min.js"></script>
|
<script src="/node_modules/angular-loading-bar/build/loading-bar.min.js"></script>
|
||||||
<script src="/static/js/main.js"></script>
|
<script src="/static/js/main.js"></script>
|
||||||
<script src="/static/js/item.controller.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/list.controller.js"></script>
|
||||||
<script src="/static/js/statistics.controller.js"></script>
|
<script src="/static/js/statistics.controller.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -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">
|
<table class="ui table very basic">
|
||||||
<tr>
|
<tr>
|
||||||
<td>Count</td>
|
<td>Product ID</td>
|
||||||
<td>Time of Delevery</td>
|
<td>{{obj.id}}</td>
|
||||||
<td>Status of Freshness</td>
|
|
||||||
<td>< /td>
|
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
|
<td>Count</td>
|
||||||
<td>{{list.length}}</td>
|
<td>{{list.length}}</td>
|
||||||
<td>#</td>
|
|
||||||
<td><img class="icon" src="/api/good/freshness"/></td>
|
|
||||||
<td><i class="trash icon"></i></td>
|
|
||||||
|
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
<h2>Goods of this product</h2>
|
||||||
<table class="ui table list" ng-if="list.length > 0">
|
<table class="ui table list" ng-if="list.length > 0">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
|
<th>Location</th>
|
||||||
|
<th>Comment</th>
|
||||||
|
<th>Time of Delivery</th>
|
||||||
|
<th>Status of Freshness</th>
|
||||||
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr ng-repeat="item in list">
|
<tr ng-repeat="item in list">
|
||||||
<td>{{item.id}}</td>
|
<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>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
<table class="ui very compact table">
|
<table class="ui very compact table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th class="two wide">#</th>
|
||||||
<th>Productname</th>
|
<th class="twelve wide">Productname</th>
|
||||||
<th>Amount</th>
|
<th class="one wide">Amount</th>
|
||||||
|
<th class="one wide"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -12,7 +13,10 @@
|
||||||
<td>{{item.id}}</td>
|
<td>{{item.id}}</td>
|
||||||
<td><a ui-sref="item({productid: item.id})">{{item.title}}</a></td>
|
<td><a ui-sref="item({productid: item.id})">{{item.title}}</a></td>
|
||||||
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -11,4 +11,9 @@ angular.module('microStock')
|
||||||
$http.get(config.store.goods.productById.replace("%d",$stateParams.productid)).then(function(res) {
|
$http.get(config.store.goods.productById.replace("%d",$stateParams.productid)).then(function(res) {
|
||||||
$scope.list = res.data
|
$scope.list = res.data
|
||||||
});
|
});
|
||||||
|
$scope.delete = function(){
|
||||||
|
$http.delete(config.store.goods.productById.replace("%d",$stateParams.productid)).then(function(res) {
|
||||||
|
$scope.list = res.data
|
||||||
|
});
|
||||||
|
}
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -19,6 +19,11 @@ angular.module('microStock', [
|
||||||
templateUrl: '/static/html/item.html',
|
templateUrl: '/static/html/item.html',
|
||||||
controller: 'ItemCtrl'
|
controller: 'ItemCtrl'
|
||||||
})
|
})
|
||||||
|
.state('item-add', {
|
||||||
|
url: '/product/:productid/add',
|
||||||
|
templateUrl: '/static/html/item-add.html',
|
||||||
|
controller: 'ItemAddCtrl'
|
||||||
|
})
|
||||||
.state('statistics', {
|
.state('statistics', {
|
||||||
url: '/statistics',
|
url: '/statistics',
|
||||||
templateUrl: '/static/html/statistics.html',
|
templateUrl: '/static/html/statistics.html',
|
||||||
|
|
Reference in New Issue