Created
March 27, 2015 21:32
-
-
Save astemborskim/4673d024d5a78347fae8 to your computer and use it in GitHub Desktop.
Defining Controllers and Services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('warehouseApp', ['ngResource']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends layout | |
block navigation | |
div#navbar.navbar.navbar-default | |
ul.nav.nav-pills | |
li | |
a(href='/home') Home | |
li | |
a(href='/search') Product Search | |
li.active | |
a(href='/addProd') Add Inventory | |
li#signout | |
a(href="/signout") Sign Out | |
block heading | |
script(text="text/javascript", src="../js/controllers/test-controller.js") | |
script(text="text/javascript", src="../js/services/editProduct-service.js") | |
block content | |
div#outerForm.panel.panel-primary(ng-controller="testController") | |
h4#mainHeading.panel.panel-heading | |
| Edit Product | |
div#innerForm.panel.panel-info | |
div#prodForm.column | |
form#SKUSearch(class='form' autocomplete='off' ng-init="getEditProduct()") | |
label SKU: | |
input(type='text', ng-model='prod.SKU', name='SKU', class='form-control', placeholder='SKU', ng-change="showList()", ng-click="showList()") | |
label Product Name: | |
input(type='text', ng-model="prod.PN" name='prodName', class='form-control nomargin', placeholder='Product Name') | |
label Product Description: | |
textarea#desc(type='text', ng-model="prod.PD" name='prodDesc', class='form-control', placeholder='Product Description') | |
label Quantity Available: | |
input(type='text', ng-model="prod.Q" name='quantity', class='form-control', placeholder='Quantity Available') | |
label Location: | |
input(type='text', ng-model="prod.PL" name='location', class='form-control', placeholder='Location') | |
button(class='btn btn-lg btn-primary btn-block', type='submit') Submit Changes | |
button#editProdButton.btn.btn-primary | |
a#editProdLink(ng-click='getEditProduct()') Get Product | |
span.clearfix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.factory('editProductService', function(){ | |
var productForEdit;; | |
return { | |
saveProductForEdit:function (data) { | |
productForEdit = data; | |
console.log(data); | |
}, | |
getProductForEdit:function () { | |
return productForEdit; | |
} | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docutype | |
html(ng-app='warehouseApp') | |
head | |
script( src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js") | |
script( src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular-resource.js") | |
script( text='text/javascript' src="/app.js") | |
link( rel="stylesheet" href="/css/style.css" type="text/css" media="Screen") | |
link( rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css") | |
title Acme Warehouse - #{title} | |
block navigation | |
body.container-fluid | |
div | |
block heading | |
block content | |
footer | |
block footer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.controller('productController', ['$scope', '$resource', 'editProductService', function ($scope, $resource, editProductService) { | |
$scope.prod={}; | |
var Inventory = $resource('/api/inventory', {}); | |
getInventory = function(req, res){ | |
Inventory.query(function (results){ | |
$scope.inventory=results; | |
//console.log(user); | |
})} | |
$scope.getProductBySKU = function (product){ | |
$scope.prod.searchSKU.SKU = product.SKU; | |
$scope.prod.NameBySKU = product.Product_Name; | |
$scope.prod.DescBySKU = product.Product_Description; | |
$scope.prod.quantityBySKU = product.Quantity; | |
$scope.prod.locationBySKU = product.Product_Location; | |
$scope.prod.hideList = true; | |
} | |
$scope.getProductByName = function (product){ | |
$scope.prod.searchName.Product_Name = product.Product_Name; | |
$scope.prod.SKUByName = product.SKU; | |
$scope.prod.DescByName = product.Product_Description; | |
$scope.prod.quantityByName = product.Quantity; | |
$scope.prod.locationByName = product.Product_Location; | |
$scope.prod.hideList = true; | |
} | |
$scope.setEditProduct = function (product){ | |
editProductService.saveProductForEdit(product); | |
console.log(product); | |
} | |
$scope.showList = function(){ | |
$scope.prod.hideList = false; | |
} | |
$scope.orderBySKU = 'SKU'; | |
$scope.orderByName = 'Product_Name'; | |
getInventory(); | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends layout | |
block navigation | |
div#navbar.navbar.navbar-default | |
ul.nav.nav-pills | |
li | |
a(href='/home') Home | |
li.active | |
a(href='/search') Product Search | |
li | |
a(href='/addProd') Add Inventory | |
li#user | |
| Signed in as: #{username} | |
li#signout | |
a(href="/signout") Sign Out | |
block heading | |
script(text="text/javascript", src="../js/controllers/product-controller.js") | |
script(text="text/javascript", src="../js/services/editProduct-service.js") | |
block content | |
div#outerForm.panel.panel-primary(ng-controller="productController") | |
h4#mainHeading.panel.panel-heading | |
| Product Search | |
ul.nav.nav-tabs | |
li(ng-class="{active:Search===SKU}") | |
a(ng-click="Search = SKU; loadSKUSearch()") SKU | |
li(ng-class="{active:Search===!SKU}") | |
a(ng-click="Search = ! SKU; loadNameSearch()") Product Name | |
div#innerForm.panel.panel-info(ng-show='Search === SKU') | |
h4.panel.panel-heading | |
| Search by SKU: | |
div#formContainer.container-fluid | |
div#prodImg.column | |
img#productpic(class='thumbnail', src='./img/StockPhoto.jpg') | |
button#editProdButton.btn.btn-primary | |
a#editProdLink(ng-click='setEditProduct(prod)' href="/editProd" ) Set Product | |
button#editProdButton.btn.btn-primary | |
a#editProdLink(ng-click='getEditProduct()') Get Product | |
div#prodForm.column | |
form#SKUSearch(class='form' autocomplete='off') | |
label SKU: | |
input(type='text', name='SKU', class='form-control', placeholder='SKU', ng-model='prod.searchSKU.SKU', ng-change="showList()", ng-click="showList()", required, autofocus) | |
div(ng-hide= "prod.searchSKU.SKU == null || prod.hideList == true") | |
div#prodList | |
table | |
tr | |
th SKU | |
th Product Name | |
tr(ng-repeat="prod in inventory | orderBy: orderBySKU | filter: prod.searchSKU") | |
td | |
a(href="" ng-click="getProductBySKU(prod)") {{prod.SKU}} | |
td {{prod.Product_Name}} | |
label Product Name: | |
input(type='text', ng-model="prod.NameBySKU" name='prodName', class='form-control nomargin', placeholder='Product Name', readonly) | |
label Product Description: | |
textarea#desc(type='text', ng-model="prod.DescBySKU" name='prodDesc', class='form-control', placeholder='Product Description',readonly) | |
label Quantity Available: | |
input(type='text', ng-model="prod.quantityBySKU" name='quantity', class='form-control', placeholder='Quantity Available',readonly) | |
label Location: | |
input(type='text', ng-model="prod.locationBySKU" name='location', class='form-control', placeholder='Location',readonly) | |
//- button(class='btn btn-lg btn-primary btn-block', type='submit') Search | |
span.clearfix | |
div#searchNameForm.panel.panel-info(ng-show="Search === ! SKU") | |
h4.panel.panel-heading | |
| Search by Produt Name: | |
div#formContainer.container-fluid | |
div#prodImg.column | |
img#productpic(class='thumbnail', src='./img/StockPhoto.jpg') | |
button#editProdButton.btn.btn-primary | |
a#editProdLink(href='/home') Edit Item | |
div#prodForm | |
form#NameSearch(class='form' autocomplete='off') | |
label Product Name: | |
input(type='text', name='prodName', class='form-control', placeholder='Product Name', ng-model="prod.searchName.Product_Name", ng-change="showList()", ng-click="showList()", required, autofocus) | |
div(ng-hide="prod.searchName.Product_Name == null || prod.hideList == true") | |
div#prodList | |
table | |
tr | |
th SKU | |
th Product Name | |
tr(ng-repeat="prod in inventory | orderBy: orderByName | filter: prod.searchName") | |
td | |
a(href="" ng-click="getProductByName(prod)") {{prod.SKU}} | |
td {{prod.Product_Name}} | |
label SKU: | |
input(type='text', ng-model="prod.SKUByName" name='SKU', class='form-control', placeholder='SKU',required, readonly) | |
label Product Description: | |
textarea#desc(type='text', ng-model="prod.DescByName" name='prodDesc', class='form-control', placeholder='Product Description',readonly) | |
label Quantity Available: | |
input(type='text', ng-model="prod.quantityByName" name='quantity', class='form-control', placeholder='Quantity Available',readonly) | |
label Location: | |
input(type='text', ng-model="prod.locationByName" name='location', class='form-control', placeholder='Location',readonly) | |
//- button(class='btn btn-lg btn-primary btn-block', type='submit') Search | |
span.clearfix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.controller('testController', ['$scope', '$resource', 'editProductService', | |
function ($scope, $resource, editProductService) { | |
$scope.editProd={}; | |
$scope.getEditProduct = function (){ | |
$scope.editProd = editProductService.getProductForEdit(); | |
// $scope.edit.SKU = $scope.edit.editSKU | |
// $scope.edit.PN = $scope.edit.editProductName | |
// $scope.edit.PD = $scope.edit.editProductDescription | |
// $scope.edit.Q = $scope.edit.editQuantity | |
// $scope.prod.PL =$scope.edit.editProductLocation | |
// console.log('LOADED'); | |
console.log($scope.editProd); | |
} | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment