Skip to content

Commit c8e9b9a

Browse files
committedMar 28, 2016
fixed
1 parent 9bfb37d commit c8e9b9a

17 files changed

+281
-21
lines changed
 

‎SelfHosting.Nancy/Api/Products.cs

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Nancy;
7+
using Nancy.Responses;
8+
9+
namespace SelfHosting.Nancy.Api
10+
{
11+
public class Products:NancyModule
12+
{
13+
public Products():base(@"api/products")
14+
{
15+
Get["/"] = param => new JsonResponse(GetAll(), new DefaultJsonSerializer());
16+
17+
Get["/{productId}"]= param=> new JsonResponse(GetAll().FirstOrDefault(i=> i.ProductId== param.ProductId), new DefaultJsonSerializer());
18+
}
19+
20+
private IEnumerable<Product> GetAll()
21+
{
22+
yield return new Product
23+
{
24+
ProductId=1,
25+
Cost=12.33m,
26+
ImageUrl= @"http://www.clipartpictures.net/pictures/Fruits%20and%20Vegetables/g0800752.png",
27+
Price=14.89m,
28+
ProductName="Strawberry",
29+
Tags=new List<string> { "Fruits", "expensive","rare"}
30+
31+
};
32+
33+
34+
yield return new Product
35+
{
36+
ProductId = 2,
37+
Cost = 12.33m,
38+
ImageUrl = @"http://www.clipartpictures.net/pictures/Fruits%20and%20Vegetables/g0800753.png",
39+
Price = 14.89m,
40+
ProductName = "Star fruit",
41+
Tags = new List<string> { "Fruits", "expensive", "rare" }
42+
43+
};
44+
45+
46+
yield return new Product
47+
{
48+
ProductId = 3,
49+
Cost = 12.33m,
50+
ImageUrl = @"http://www.clipartpictures.net/pictures/Fruits%20and%20Vegetables/g0800755.png",
51+
Price = 14.89m,
52+
ProductName = "Raspberry",
53+
Tags = new List<string> { "Fruits", "expensive", "rare" }
54+
55+
};
56+
57+
58+
59+
}
60+
}
61+
62+
63+
64+
public class Product
65+
{
66+
public int ProductId { get; set; }
67+
public string ProductName { get; set; }
68+
public decimal Price { get; set; }
69+
public decimal Cost { get; set; }
70+
public string ImageUrl { get; set; }
71+
public IEnumerable<string> Tags { get; set; }
72+
}
73+
}

‎SelfHosting.Nancy/SelfHosting.Nancy.csproj

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<Reference Include="System.Xml" />
5959
</ItemGroup>
6060
<ItemGroup>
61+
<Compile Include="Api\Products.cs" />
6162
<Compile Include="Bootstrapper.cs" />
6263
<Compile Include="HomeModule.cs" />
6364
<Compile Include="Program.cs" />
@@ -263,6 +264,13 @@
263264
<EmbeddedResource Include="Views\content\public\app\controllers\productEditCtrl.js" />
264265
<EmbeddedResource Include="Views\content\public\app\controllers\productDetailView.html" />
265266
<EmbeddedResource Include="Views\content\public\app\controllers\productDetailCtrl.js" />
267+
<EmbeddedResource Include="Views\content\public\vendor\angular-charts.min.js" />
268+
<EmbeddedResource Include="Views\content\public\vendor\d3.min.js" />
269+
<EmbeddedResource Include="Views\content\public\app\controllers\priceAnalyticsCtrl.js" />
270+
<EmbeddedResource Include="Views\content\public\app\controllers\priceAnalyticsView.html" />
271+
<EmbeddedResource Include="Views\content\public\app\controllers\productEditInfoView.html" />
272+
<EmbeddedResource Include="Views\content\public\app\controllers\productEditPriceView.html" />
273+
<EmbeddedResource Include="Views\content\public\app\controllers\productEditTagsView.html" />
266274
<Content Include="Views\content\vendor\angular\angular-ui\.gitignore" />
267275
<Content Include="Views\content\vendor\angular\angular-ui\build\angular-ui-ieshiv.js" />
268276
<EmbeddedResource Include="Views\content\vendor\angular\angular-ui\build\angular-ui-ieshiv.min.js" />

‎SelfHosting.Nancy/Views/MasterPage.html

+7-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
<script src="content/vendor/jquery/dist/jquery.min.js"></script>
2020
<script src="content/vendor/angular/angular.min.js"></script>
21-
<script src="content/vendor/angular-ui/build/angular-ui-ieshiv.min.js"></script>
21+
<!--<script src="content/vendor/angular-ui/build/angular-ui-ieshiv.min.js"></script>-->
2222
<script src="content/vendor/angular-ui/build/angular-ui.min.js"></script>
2323
<script src="content/vendor/bootstrap/dist/js/bootstrap.min.js"></script>
24+
<script src="content/public/vendor/d3.min.js"></script>
25+
<script src="content/public/vendor/angular-charts.min.js"></script>
2426
<script src="content/public/vendor/angular-resource.min.js"></script>
2527
<script src="content/public/vendor/angular-mocks.js"></script>
2628
<script src="content/public/vendor/angular-ui-router.min.js"></script>
@@ -32,7 +34,8 @@
3234
<script src="content/public/app/common/services/productresuource.js"></script>
3335

3436
<script src="content/public/app/controllers/producteditctrl.js"></script>
35-
<script src="content/public/app/controllers/productdetailctrl.js"></script>
37+
<script src="content/public/app/controllers/productdetailctrl.js"></script>
38+
<script src="content/public/app/controllers/priceanalyticsctrl.js"></script>
3639
<!--<div class="navbar navbar-inverse">
3740
<div class="container">
3841
<a class="navbar-brand">Product management</a>
@@ -71,7 +74,8 @@
7174
<li><a data-ui-sref="productList">Product List</a></li>
7275

7376
<li><a data-ui-sref="productEdit({productId:0})"><i class="glyphicon glyphicon-plus"></i>Add product list</a></li>
74-
77+
78+
<li><a data-ui-sref="priceAnalytics">Analytics</a></li>
7579
</ul>
7680

7781
</div>

‎SelfHosting.Nancy/Views/content/public/app/app.js

+43-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
"use strict";
44

5-
var app = angular.module("productManagement", ["common.services", "ui.router", "productResourceMock"]);
5+
var app = angular.module("productManagement", ["common.services", "ui.router"]);
66

77

88
app.config(["$stateProvider", "$urlRouterProvider", function ($stateProvider, $urlRouterProvider) {
@@ -20,14 +20,54 @@
2020
controller: "ProductListCtrl as vm"
2121
})
2222
.state("productEdit", {
23+
abstract:true,
2324
url: "/products/edit/:productId",
2425
templateUrl: "content/public/app/controllers/productEditView.html",
25-
controller: "ProductEditCtrl as vm"
26+
controller: "ProductEditCtrl as vm",
27+
resolve: {
28+
productResource: "productResource",
29+
product: function (productResource, $stateParams) {
30+
var productId = $stateParams.productId;
31+
return productResource.get({ productId: productId }).$promise;
32+
}
33+
}
34+
35+
36+
})
37+
.state("productEdit.info", {
38+
url: "/info",
39+
templateUrl: "content/public/app/controllers/productEditInfoView.html"
2640
})
41+
.state("productEdit.price", {
42+
url: "/price",
43+
templateUrl: "content/public/app/controllers/productEditPriceView.html"
44+
})
45+
.state("productEdit.tags", {
46+
url: "/tags",
47+
templateUrl: "content/public/app/controllers/productEditTagsView.html"
48+
})
2749
.state("productDetail", {
2850
url: "/products/:productId",
2951
templateUrl: "content/public/app/controllers/productDetailView.html",
30-
controller: "ProductDetailCtrl as vm"
52+
controller: "ProductDetailCtrl as vm",
53+
resolve: {
54+
productResource: "productResource",
55+
product: function (productResource, $stateParams) {
56+
var productId = $stateParams.productId;
57+
return productResource.get({ productId: productId }).$promise;
58+
}
59+
}
60+
})
61+
.state("priceAnalytics", {
62+
url: "/priceAnalytics",
63+
templateUrl: "content/public/app/controllers/priceAnalyticsView.html",
64+
controller: "PriceAnalyticsCtrl",
65+
resolve: {
66+
productResource: "productResource",
67+
products: function (productResource, $stateParams) {
68+
return productResource.query().$promise;
69+
}
70+
}
3171
});
3272

3373
}]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
(function() {
2+
3+
"use strict";
4+
angular.module("productManagement").controller("PriceAnalyticsCtrl", ["$scope","products", priceAnalyticsCtrl]);
5+
6+
function priceAnalyticsCtrl($scope,products) {
7+
8+
9+
$scope.title = "Price analytics ";
10+
11+
var chartDataAmount = [];
12+
13+
for (var i = 0; i < products.length; i++) {
14+
15+
var margin =Math.abs (
16+
products[i].cost - products[i].price);
17+
18+
chartDataAmount.push({
19+
x: products[i].productName,
20+
y: [products[i].cost, products[i].price,margin]
21+
});
22+
}
23+
24+
25+
26+
$scope.dataAmount = {
27+
series: ["cost", "price", "margin amount"],
28+
data: chartDataAmount
29+
};
30+
31+
$scope.configAmount = {
32+
title: "top margin product",
33+
tooltips: true,
34+
labels: false,
35+
mouseover:function() {
36+
},
37+
mouseout: function () { },
38+
click: function () { },
39+
legend:{display:true,position:"right"}
40+
};
41+
42+
}
43+
}())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+

2+
3+
<div class="content">
4+
<div class="panel panel-primary">
5+
<div class="panel-heading" style="font-size: large;">
6+
{{title}}
7+
</div>
8+
9+
<div class="panel-body">
10+
11+
<div class="col-md-12">
12+
13+
<div ac-chart="'bar'"
14+
ac-data="dataAmount"
15+
ac-config="configAmount"
16+
class="chart"
17+
></div>
18+
19+
</div>
20+
21+
22+
</div>
23+
</div>
24+
</div>

‎SelfHosting.Nancy/Views/content/public/app/controllers/productDetailCtrl.js

+3-10
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,13 @@
22

33
"use strict";
44

5-
angular.module("productManagement").controller("ProductDetailCtrl", productDetailCtrl);
5+
angular.module("productManagement").controller("ProductDetailCtrl",["product", productDetailCtrl]);
66

7-
function productDetailCtrl() {
7+
function productDetailCtrl(product) {
88

99
var vm = this;
1010

11-
vm.product = {
12-
"productId": 1,
13-
"productName": "Sample product 1",
14-
"price": 19.89,
15-
"cost": 9.0,
16-
"imageUrl": "http://",
17-
tags: ["leaf", "tool"]
18-
};
11+
vm.product = product;
1912

2013
vm.title = "Product Details: " + vm.product.productName;
2114

‎SelfHosting.Nancy/Views/content/public/app/controllers/productDetailView.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55

66
<div class="panel-body">
77
<div class="row">
8+
<div class="col-md-4">Name</div>
9+
<div class="col-md-6">{{vm.product.productName}}</div>
10+
</div>
811

12+
<div class="col-md-6">
13+
<img
14+
ng-src="{{vm.product.imageUrl}}"
15+
style="width: 50px; margin: 2px;" title="{{vm.product.productName}}"/>
916
</div>
1017
</div>
1118

1219
<div class="panel-footer">
1320
<a class="btn btn-default" data-ui-sref="productList"><i class="glyphicon glyphicon-chevron-left"></i>Back</a>
14-
<a class="btn btn-primary" data-ui-sref="productEdit({productId:vm.product.productId})">Edit</a>
21+
<a class="btn btn-primary" data-ui-sref="productEdit.info({productId:vm.product.productId})">Edit</a>
1522
</div>
1623
</div>

‎SelfHosting.Nancy/Views/content/public/app/controllers/productEditCtrl.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22
"user strict";
33

44
angular.module("productManagement")
5-
.controller("ProductEditCtrl", ["productResource", productEditCtrl]);
5+
.controller("ProductEditCtrl", ["product", productEditCtrl]);
66

7-
function productEditCtrl(productResource) {
7+
function productEditCtrl(product) {
88
var vm = this;
9+
10+
vm.product = product;
911

12+
if (vm.product && vm.product.id > 0) {
13+
vm.title = "Edit product " + vm.product.productName;
14+
} else {
15+
vm.title = "Add new product";
16+
}
1017
}
1118

1219

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+

2+
3+
<form name="productForm">
4+
<fieldset>
5+
<legend>Basic Product Information</legend>
6+
7+
<div>
8+
<label for="inputProductName">Product Name</label>
9+
<input id="inputProductName" type="text" placeholder="Product name" ng-model="vm.product.productName" />
10+
</div>
11+
</fieldset>
12+
</form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+

2+
price
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+

2+
tags
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-

1+

2+
3+
<div class="pane panel-primary">
4+
<div class="panel-heading">{{vm.title}}</div>
5+
6+
<div class="panel-body">
7+
<div class="wizard">
8+
<a ui-sref=".info" ui-sref-active="active">Basic Information</a>
9+
<a ui-sref=".price" ui-sref-active="active">Price </a>
10+
<a ui-sref=".tags" ui-sref-active="active">Tags</a>
11+
</div>
12+
13+
<div ui-view></div>
14+
</div>
15+
16+
</div>

‎SelfHosting.Nancy/Views/content/public/app/controllers/productListView.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
style="width: 50px; margin: 2px;" title="{{product.productName}}"/>
3333
</td>
3434
<td>
35-
<a class="btn btn-primary" data-ui-sref="productEdit({productId:product.productId})">Edit</a>
35+
<a class="btn btn-primary" data-ui-sref="productEdit.info({productId:product.productId})">Edit</a>
3636
</td>
3737
</tr>
3838
</tbody>

‎SelfHosting.Nancy/Views/content/public/css/default.css

+24
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,28 @@ textarea {
3131
.carousel-caption {
3232
z-index: 10 !important;
3333
}
34+
}
35+
36+
.chart {
37+
width: 100%;
38+
height: 300px;
39+
}
40+
41+
.wizard a {
42+
background: #efefef;
43+
display: inline-block;
44+
margin-right: 5px;
45+
min-width: 150px;
46+
outline: none;
47+
padding: 10px 40px 10px;
48+
position: relative;
49+
text-decoration: none;
50+
51+
52+
}
53+
54+
.wizard .active {
55+
background: #007ACC;
56+
color: #fff;
57+
3458
}

‎SelfHosting.Nancy/Views/content/public/vendor/angular-charts.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎SelfHosting.Nancy/Views/content/public/vendor/d3.min.js

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.