projects
/
outofuni
/
tavern2.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3307c69
)
cleaups and content page refresh (in progress)
author
hackbard
<hackbard@hackdaworld.org>
Sat, 15 Oct 2016 17:31:29 +0000
(19:31 +0200)
committer
hackbard
<hackbard@hackdaworld.org>
Sat, 15 Oct 2016 17:31:29 +0000
(19:31 +0200)
lib/app_component.dart
patch
|
blob
|
history
lib/product_category.dart
patch
|
blob
|
history
lib/product_category_component.dart
patch
|
blob
|
history
lib/product_category_component.html
patch
|
blob
|
history
lib/product_category_service.dart
patch
|
blob
|
history
lib/product_component.dart
patch
|
blob
|
history
lib/product_component.html
patch
|
blob
|
history
lib/product_detail_component.css
patch
|
blob
|
history
lib/product_detail_component.html
patch
|
blob
|
history
lib/product_service.dart
patch
|
blob
|
history
diff --git
a/lib/app_component.dart
b/lib/app_component.dart
index
1f96314
..
2175bdf
100644
(file)
--- a/
lib/app_component.dart
+++ b/
lib/app_component.dart
@@
-6,7
+6,6
@@
import 'package:angular2_rbi/directives.dart';
import 'product_component.dart';
import 'product_category_component.dart';
import 'product_detail_component.dart';
import 'product_component.dart';
import 'product_category_component.dart';
import 'product_detail_component.dart';
-import 'product_category_detail_component.dart';
import 'product_service.dart';
import 'product_category_service.dart';
import 'product_service.dart';
import 'product_category_service.dart';
@@
-41,11
+40,6
@@
import 'product_category_service.dart';
path: '/product/:id',
name: 'ProductDetail',
component: ProductDetailComponent
path: '/product/:id',
name: 'ProductDetail',
component: ProductDetailComponent
- ),
- const Route(
- path: '/product_category/:id',
- name: 'ProductCategoryDetail',
- component: ProductCategoryDetailComponent
)
])
)
])
diff --git
a/lib/product_category.dart
b/lib/product_category.dart
index
3e99981
..
67ef684
100644
(file)
--- a/
lib/product_category.dart
+++ b/
lib/product_category.dart
@@
-1,9
+1,8
@@
class ProductCategory {
class ProductCategory {
- String doc_id;
- String name;
String id;
String id;
- String doc_type;
+ String name;
+ String type;
- ProductCategory(this.
doc_id,this.name,this.id,this.doc_
type);
+ ProductCategory(this.
id,this.name,this.
type);
}
}
diff --git
a/lib/product_category_component.dart
b/lib/product_category_component.dart
index
7b48a2a
..
b7d3bf1
100644
(file)
--- a/
lib/product_category_component.dart
+++ b/
lib/product_category_component.dart
@@
-22,42
+22,19
@@
import 'package:angular2_rbi/directives.dart';
class ProductCategoryComponent implements OnInit {
List<ProductCategory> product_categories;
ProductCategory selected_prod_category;
class ProductCategoryComponent implements OnInit {
List<ProductCategory> product_categories;
ProductCategory selected_prod_category;
- String new_prod_category_name;
- String new_prod_category_id;
+ String new_prod_category_name='';
final ProductCategoryService _prodcatSrv;
final Router _router;
final ProductCategoryService _prodcatSrv;
final Router _router;
- var docreate=false;
ProductCategoryComponent(this._prodcatSrv,this._router);
ProductCategoryComponent(this._prodcatSrv,this._router);
- Future<Null> getProductCategories() async {
- product_categories = await _prodcatSrv.getAll();
- }
-
Future<Null> createProductCategory() async {
Future<Null> createProductCategory() async {
- await _prodcatSrv.createProdCategory(
- new_prod_category_name,
- new_prod_category_id
- );
+ await _prodcatSrv.createProdCategory(new_prod_category_name);
+ await ngOnInit();
}
}
- void ngOnInit() {
- getProductCategories();
- }
-
- void checkInput() {
- if(new_prod_category_name=='' || new_prod_category_id=='') {
- docreate=false;
- }
- else {
- docreate=true;
- for(var cat in product_categories) {
- if(cat.id==new_prod_category_id) {
- docreate=false;
- break;
- }
- }
- }
+ Future<Null> ngOnInit() async {
+ product_categories = await _prodcatSrv.getAll();
}
choose(ProductCategory pt) {
}
choose(ProductCategory pt) {
diff --git
a/lib/product_category_component.html
b/lib/product_category_component.html
index
6fff730
..
7b1df92
100644
(file)
--- a/
lib/product_category_component.html
+++ b/
lib/product_category_component.html
@@
-17,20
+17,12
@@
<div class="mdl-textfield mdl-js-textfield
mdl-textfield--floating-label ain">
<input class="mdl-textfield__input" type=text id=ptn
<div class="mdl-textfield mdl-js-textfield
mdl-textfield--floating-label ain">
<input class="mdl-textfield__input" type=text id=ptn
- [(ngModel)]="new_prod_category_name"
- (keyup)="checkInput()">
+ [(ngModel)]="new_prod_category_name">
<label class="mdl-textfield__label" for=ptn>Name</label>
</div>
<label class="mdl-textfield__label" for=ptn>Name</label>
</div>
- <div class="mdl-textfield mdl-js-textfield
- mdl-textfield--floating-label ain">
- <input class="mdl-textfield__input" type=text id=pti
- [(ngModel)]="new_prod_category_id"
- (keyup)="checkInput()">
- <label class="mdl-textfield__label" for=pti>Identifier</label>
- </div>
<button class="mdl-button mdl-js-button mdl-button--raised abtn"
(click)="createProductCategory()"
<button class="mdl-button mdl-js-button mdl-button--raised abtn"
(click)="createProductCategory()"
- [disabled]="
!docreate
">
+ [disabled]="
new_prod_category_name==''
">
Create
</button>
</div>
Create
</button>
</div>
diff --git
a/lib/product_category_service.dart
b/lib/product_category_service.dart
index
c62e7ef
..
f246a71
100644
(file)
--- a/
lib/product_category_service.dart
+++ b/
lib/product_category_service.dart
@@
-11,9
+11,7
@@
class ProductCategoryService {
static const _server='http://10.8.0.1:5984';
static const _db='tavern';
static const _viewname='_design/product_categories/_view/byname';
static const _server='http://10.8.0.1:5984';
static const _db='tavern';
static const _viewname='_design/product_categories/_view/byname';
- static const _viewid='_design/product_categories/_view/byid';
static const _getnameurl=_server+'/'+_db+'/'+_viewname;
static const _getnameurl=_server+'/'+_db+'/'+_viewname;
- static const _getidurl=_server+'/'+_db+'/'+_viewid;
static const _posturl=_server+'/'+_db;
final BrowserClient _http;
static const _posturl=_server+'/'+_db;
final BrowserClient _http;
@@
-28,7
+26,6
@@
class ProductCategoryService {
prodcats.add(new ProductCategory(
item['id'],
item['value']['name'],
prodcats.add(new ProductCategory(
item['id'],
item['value']['name'],
- item['value']['id'],
item['value']['type']));
}
return prodcats;
item['value']['type']));
}
return prodcats;
@@
-38,14
+35,13
@@
class ProductCategoryService {
}
}
}
}
- Future<Null> createProdCategory(String name
,String id
) async {
+ Future<Null> createProdCategory(String name) async {
try {
await _http.post(
_posturl,
headers: {'Content-Type': 'application/json'},
body: JSON.encode({
'name': name,
try {
await _http.post(
_posturl,
headers: {'Content-Type': 'application/json'},
body: JSON.encode({
'name': name,
- 'id': id,
'type': 'product_category'
})
);
'type': 'product_category'
})
);
@@
-58,14
+54,13
@@
class ProductCategoryService {
Future<ProductCategory> getById(String id) async {
try {
ProductCategory prodcat;
Future<ProductCategory> getById(String id) async {
try {
ProductCategory prodcat;
- String url=_
getidurl+'?key="'+id+'"'
;
+ String url=_
server+'/'+_db+'/'+id
;
final response = await _http.get(url);
var item=JSON.decode(response.body);
prodcat = new ProductCategory(
final response = await _http.get(url);
var item=JSON.decode(response.body);
prodcat = new ProductCategory(
- item['rows'][0]['value']['_id'],
- item['rows'][0]['value']['name'],
- item['rows'][0]['value']['id'],
- item['rows'][0]['value']['type']
+ item['_id'],
+ item['name'],
+ item['type']
);
return prodcat;
}
);
return prodcat;
}
@@
-74,31
+69,26
@@
class ProductCategoryService {
}
}
}
}
- Future<Null> updateProdCategory(String oldid,String name,
- String id) async {
+ Future<Null> updateProdCategory(String id,String name) async {
try {
try {
- String url=_
getidurl+'?key="'+oldid+'"'
;
+ String url=_
server+'/'+_db+'/'+id
;
final response = await _http.get(url);
final response = await _http.get(url);
- print('Debug UPDATE GET URL: '+url);
- print('Debug UPDATE GET response: '+response.body);
var resbody=JSON.decode(response.body);
var resbody=JSON.decode(response.body);
- resbody['rows'][0]['value']['name']=name;
- resbody['rows'][0]['value']['id']=id;
- final response_put = await _http.put(
- _posturl+'/'+resbody['rows'][0]['id'],
+ resbody['name']=name;
+ await _http.put(
+ _posturl+'/'+id,
headers: {'Content-Type': 'application/json'},
headers: {'Content-Type': 'application/json'},
- body: JSON.encode(resbody
['rows'][0]['value']
)
+ body: JSON.encode(resbody)
);
);
- print('Debug UPDATE PUT response: '+response_put.body);
}
catch(e) {
throw _handleError(e);
}
}
}
catch(e) {
throw _handleError(e);
}
}
- Future<Null> deleteProdCategory(String
doc_
id) async {
+ Future<Null> deleteProdCategory(String id) async {
try {
try {
- var url=_server+'/'+_db+'/'+
doc_
id;
+ var url=_server+'/'+_db+'/'+id;
var response = await _http.get(url);
var reso=JSON.decode(response.body);
url=_server+'/'+_db+'/_purge/';
var response = await _http.get(url);
var reso=JSON.decode(response.body);
url=_server+'/'+_db+'/_purge/';
diff --git
a/lib/product_component.dart
b/lib/product_component.dart
index
ed08975
..
6fb5461
100644
(file)
--- a/
lib/product_component.dart
+++ b/
lib/product_component.dart
@@
-27,8
+27,9
@@
class ProductComponent implements OnInit {
final RouteParams _routeParams;
final Router _router;
final RouteParams _routeParams;
final Router _router;
- String
prod_category_
id;
+ String
cat
id;
String prod_category_name;
String prod_category_name;
+
String prod_name;
double prod_price;
int prodcnt;
String prod_name;
double prod_price;
int prodcnt;
@@
-39,67
+40,33
@@
class ProductComponent implements OnInit {
ProductComponent(this._prodSrv,this._prodcatSrv,
this._routeParams,this._router) {
prod_category_name='Category';
ProductComponent(this._prodSrv,this._prodcatSrv,
this._routeParams,this._router) {
prod_category_name='Category';
- prod_category_id='ID';
}
Future<Null> ngOnInit() async {
}
Future<Null> ngOnInit() async {
-
var
catid=_routeParams.get('id');
+ catid=_routeParams.get('id');
if(catid!=null) {
products = await (_prodSrv.getByCategory(catid));
prodcat = await (_prodcatSrv.getById(catid));
}
prod_category_name=prodcat.name;
if(catid!=null) {
products = await (_prodSrv.getByCategory(catid));
prodcat = await (_prodcatSrv.getById(catid));
}
prod_category_name=prodcat.name;
- prod_category_id=prodcat.id;
prodcnt=products.length;
}
Future<Null> updateProductCategory() async {
prodcnt=products.length;
}
Future<Null> updateProductCategory() async {
- bool doupdate=false;
- bool changecat=false;
- if(prodcat.id!=prod_category_id) {
- doupdate=true;
- changecat=true;
- }
if(prodcat.name!=prod_category_name) {
if(prodcat.name!=prod_category_name) {
- doupdate=true;
- }
- if(doupdate) {
- if(changecat) {
- for(Product prod in products) {
- print('Debug: change category of '+
- prod.name);
- await _prodSrv.updateProd(
- prod.id,
- prod.name,
- prod.price,
- prod_category_id
- );
- }
- }
- print('Debug: Updating product category '+
- prodcat.name+'/'+prodcat.id+' -> '+
- prod_category_name+'/'+prod_category_id);
await _prodcatSrv.updateProdCategory(
await _prodcatSrv.updateProdCategory(
- prodcat.id,
- prod_category_name,
- prod_category_id
+ catid,
+ prod_category_name
);
);
+ _router.navigate(['ProductCategories']);
}
}
Future<Null> deleteProductCategory() async {
}
}
Future<Null> deleteProductCategory() async {
- bool delete=false;
- if(products.length==0) {
- delete=true;
- }
- else {
- print('Debug: Not deleting anything!');
- }
- if(delete) {
- print('Debug: Deleting product category '+
- prodcat.name+'/'+prodcat.id);
- await _prodcatSrv.deleteProdCategory(prodcat.doc_id);
- }
+ print('Debug: Deleting product category '+
+ prodcat.name+'/'+prodcat.id);
+ await _prodcatSrv.deleteProdCategory(prodcat.id);
+ _router.navigate(['ProductCategories']);
}
Future<Null> createProduct() async {
}
Future<Null> createProduct() async {
@@
-107,9
+74,15
@@
class ProductComponent implements OnInit {
return;
print('Debug: Creating product '+prod_name+'/'+
prod_price.toString());
return;
print('Debug: Creating product '+prod_name+'/'+
prod_price.toString());
- await _prodSrv.createProduct(prod_name,
+
String id =
await _prodSrv.createProduct(prod_name,
double.parse(prod_price),
double.parse(prod_price),
- prod_category_id);
+ catid);
+ // instead of executing ngOnInit to 'reload' content
+ products.add(new Product(
+ id,prod_name,double.parse(prod_price),'product',catid
+ ));
+ prod_name='';
+ prod_price='';
}
choose(Product prod) {
}
choose(Product prod) {
diff --git
a/lib/product_component.html
b/lib/product_component.html
index
038eab1
..
6b79bea
100644
(file)
--- a/
lib/product_component.html
+++ b/
lib/product_component.html
@@
-47,16
+47,9
@@
[(ngModel)]="prod_category_name">
<label class="mdl-textfield__label" for="ptn">Name</label>
</div>
[(ngModel)]="prod_category_name">
<label class="mdl-textfield__label" for="ptn">Name</label>
</div>
- <div class="mdl-textfield mdl-js-textfield
- mdl-textfield--floating-label ain">
- <input class="mdl-textfield__input" type="text" id="pti"
- [(ngModel)]="prod_category_id">
- <label class="mdl-textfield__label" for="pti">
- Identifier (arbitrary but unique)
- </label>
- </div>
<button class="mdl-button mdl-js-button mdl-button--raised abtn"
<button class="mdl-button mdl-js-button mdl-button--raised abtn"
- (click)="updateProductCategory()">
+ (click)="updateProductCategory()"
+ [disabled]="prod_category_name==''">
Update
</button>
<button class="mdl-button mdl-js-button mdl-button--raised abtn"
Update
</button>
<button class="mdl-button mdl-js-button mdl-button--raised abtn"
diff --git
a/lib/product_detail_component.css
b/lib/product_detail_component.css
index
ff02e63
..
beab8b7
100644
(file)
--- a/
lib/product_detail_component.css
+++ b/
lib/product_detail_component.css
@@
-27,3
+27,7
@@
margin-left: 5%;
}
margin-left: 5%;
}
+.aseldesc {
+ font-size: 12px;
+ margin-bottom: 10px;
+}
diff --git
a/lib/product_detail_component.html
b/lib/product_detail_component.html
index
c51b1b1
..
7a61e37
100644
(file)
--- a/
lib/product_detail_component.html
+++ b/
lib/product_detail_component.html
@@
-29,7
+29,9
@@
</div>
</div>
<div class=asel>
</div>
</div>
<div class=asel>
- Product category<br><br>
+ <div class=aseldesc>
+ Product category
+ </div>
<select [(ngModel)]="prod_category" required>
<option *ngFor="let prodcat of prodcats"
[value]="prodcat.id">
<select [(ngModel)]="prod_category" required>
<option *ngFor="let prodcat of prodcats"
[value]="prodcat.id">
diff --git
a/lib/product_service.dart
b/lib/product_service.dart
index
41af5cb
..
0ffe964
100644
(file)
--- a/
lib/product_service.dart
+++ b/
lib/product_service.dart
@@
-60,7
+60,7
@@
class ProductService {
Future<Null> createProduct(String name,double price,String cat) async {
try {
var url=_server+'/'+_db;
Future<Null> createProduct(String name,double price,String cat) async {
try {
var url=_server+'/'+_db;
- await _http.post(
+
var response =
await _http.post(
url,
headers: {'Content-Type': 'application/json'},
body: JSON.encode({
url,
headers: {'Content-Type': 'application/json'},
body: JSON.encode({
@@
-70,6
+70,7
@@
class ProductService {
'category': cat
})
);
'category': cat
})
);
+ return(JSON.decode(response.body)['id']);
}
catch(e) {
throw _handleError(e);
}
catch(e) {
throw _handleError(e);