Add user management

This commit is contained in:
2016-09-23 15:12:46 -04:00
parent 9f50a4635c
commit 0b5dde065a
53 changed files with 1046 additions and 690 deletions
@@ -1,5 +1,6 @@
using System.Web.Mvc;
using AutoMapper;
using InventoryTraker.Web.Core;
using InventoryTraker.Web.Identity;
using InventoryTraker.Web.Models;
using Microsoft.AspNet.Identity;
@@ -0,0 +1,94 @@
using System.Linq;
using System.Threading.Tasks;
using System.Web.Mvc;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using InventoryTraker.Web.Attributes;
using InventoryTraker.Web.Core;
using InventoryTraker.Web.Identity;
using InventoryTraker.Web.Models;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin.Security.DataProtection;
namespace InventoryTraker.Web.Controllers
{
public class UserController : ControllerBase
{
private readonly ApplicationUserManager _userManager;
public UserController(ApplicationUserManager userManager)
{
_userManager = userManager;
}
public ActionResult Index()
{
return View();
}
public JsonResult All()
{
var users =
_userManager
.Users
.ProjectTo<UserViewModel>()
.OrderBy(u => u.UserName);
return BetterJson(users);
}
[ActionLog]
[HttpPost]
public async Task<JsonResult> Create(UserEditForm form)
{
if (!ModelState.IsValid)
return GetModelStateErrorListJson();
var user =
new User
{
Email = form.Email,
UserName = form.UserName
};
var identityResult = await _userManager.CreateAsync(user, form.Password);
if (!identityResult.Succeeded)
return GetErrorListJson(identityResult.Errors.ToArray());
return BetterJson(Mapper.Map<UserViewModel>(user));
}
[ActionLog]
[HttpPost]
public async Task<JsonResult> Edit(UserEditForm form)
{
if (!ModelState.IsValid)
return GetModelStateErrorListJson();
var user = _userManager.FindByEmail(form.Email);
user.UserName = form.UserName;
user.Email = form.Email;
if (!string.IsNullOrEmpty(form.Password))
{
var provider = new DpapiDataProtectionProvider("Inventory Traker");
_userManager.UserTokenProvider = new DataProtectorTokenProvider<User>(
provider.Create("EmailConfirmation"));
var resetToken = await _userManager.GeneratePasswordResetTokenAsync(user.Id);
var resetResult = await _userManager.ResetPasswordAsync(user.Id, resetToken, form.Password);
if (!resetResult.Succeeded)
return GetErrorListJson(resetResult.Errors.ToArray());
}
var identityResult = _userManager.Update(user);
if (!identityResult.Succeeded)
return GetErrorListJson(identityResult.Errors.ToArray());
return BetterJson(Mapper.Map<UserViewModel>(user));
}
}
}
@@ -119,6 +119,9 @@ namespace InventoryTraker.Web.Helpers
if (metadata.DataTypeName == "EmailAddress")
input.Attr("type", "email");
if (metadata.DataTypeName == "Password")
input.Attr("type", "password");
if (metadata.ModelType == typeof(DateTime))
{
//input.Attr("type", "date");
+14 -1
View File
@@ -232,6 +232,11 @@
<Content Include="Global.asax" />
<Content Include="js\app.js" />
<Content Include="js\authentication\LoginController.js" />
<Content Include="js\user\UserCreateDirective.js" />
<Content Include="js\user\UserController.js" />
<Content Include="js\user\UserEditDirective.js" />
<Content Include="js\user\UserListDirective.js" />
<Content Include="js\user\userSvc.js" />
<Content Include="js\inventoryType\InventoryTypeAddDirective.js" />
<Content Include="js\inventoryType\InventoryTypeListDirective.js" />
<Content Include="js\inventoryType\InventoryTypeEditDirective.js" />
@@ -263,7 +268,6 @@
<Content Include="js\utility\FormGroupValidationDirective.js" />
<Content Include="js\utility\HideZeroFilter.js" />
<Content Include="js\utility\InputValidationIconsDirective.js" />
<Content Include="js\utility\MvcGridDirective.js" />
<Content Include="js\utility\ParseDateFilter.js" />
<Content Include="Scripts\angular-animate.js" />
<Content Include="Scripts\angular-animate.min.js" />
@@ -310,6 +314,9 @@
<Content Include="js\utility\templates\statusMessage.tmpl.cshtml" />
<Content Include="js\utility\templates\monthQuery.tmpl.cshtml" />
<Content Include="js\report\templates\movementReport.tmpl.cshtml" />
<Content Include="js\user\templates\userCreate.tmpl.cshtml" />
<Content Include="js\user\templates\userEdit.tmpl.cshtml" />
<Content Include="js\user\templates\userList.tmpl.cshtml" />
<None Include="NLog.xsd">
<SubType>Designer</SubType>
</None>
@@ -335,6 +342,7 @@
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Content Include="js\utility\DownloadService.js" />
<Compile Include="Controllers\UserController.cs" />
<Compile Include="Migrations\SeedData.cs" />
<Compile Include="App_Start\Startup.cs" />
<Compile Include="App_Start\StructureMapConfig.cs" />
@@ -370,6 +378,9 @@
<DependentUpon>201609201242047_Initial.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Models\UserEditForm.cs" />
<Compile Include="Models\UserViewModel.cs" />
<Compile Include="Models\UserCreateForm.cs" />
<Compile Include="Models\DateRangeQuery.cs" />
<Compile Include="Models\DistributionReport.cs" />
<Compile Include="Models\InventoryDistributeForm.cs" />
@@ -418,6 +429,7 @@
<Content Include="Views\InventoryType\Index.cshtml" />
<Content Include="Views\Report\Distribution.cshtml" />
<Content Include="Views\Report\Movement.cshtml" />
<Content Include="Views\User\Index.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
@@ -430,6 +442,7 @@
<DependentUpon>201609201242047_Initial.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup />
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
@@ -0,0 +1,31 @@
using System.ComponentModel.DataAnnotations;
namespace InventoryTraker.Web.Models
{
public class UserCreateForm
{
[Required]
[StringLength(128)]
[RegularExpression(@"[A-Za-z().]+(\s+[A-Za-z().]+)+", ErrorMessage = "Need complete name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
[RegularExpression(@"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}", ErrorMessage = "Must be an email address")]
public string Email { get; set; }
[Required]
[DataType(DataType.Password)]
public string Password { get; set; }
[Required(ErrorMessage = "Confirm Password is required")]
[DataType(DataType.Password)]
[Compare("Password")]
public string ConfirmPassword { get; set; }
public override string ToString()
{
return $"UserName: {UserName}, email: {Email}";
}
}
}
@@ -0,0 +1,29 @@
using System.ComponentModel.DataAnnotations;
namespace InventoryTraker.Web.Models
{
public class UserEditForm
{
[Required]
[StringLength(128)]
[RegularExpression(@"[A-Za-z().]+(\s+[A-Za-z().]+)+", ErrorMessage = "Need complete name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
[RegularExpression(@"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}", ErrorMessage = "Must be an email address")]
public string Email { get; set; }
[DataType(DataType.Password)]
public string Password { get; set; }
[DataType(DataType.Password)]
[Compare("Password")]
public string ConfirmPassword { get; set; }
public override string ToString()
{
return $"UserName: {UserName}, email: {Email}";
}
}
}
@@ -0,0 +1,24 @@
using System.ComponentModel.DataAnnotations;
using Heroic.AutoMapper;
using InventoryTraker.Web.Core;
namespace InventoryTraker.Web.Models
{
public class UserViewModel : IMapFrom<User>
{
[Required]
[StringLength(128)]
[RegularExpression(@"[A-Za-z().]+(\s+[A-Za-z().]+)+", ErrorMessage = "Need complete name")]
public string UserName { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
[RegularExpression(@"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}", ErrorMessage = "Must be an email address")]
public string Email { get; set; }
public override string ToString()
{
return $"UserName: {UserName}, email: {Email}";
}
}
}
@@ -4,7 +4,7 @@
<div ng-controller="InventoryListController as vm">
<h1 class="page-header">
<i class="fa fa-cubes"></i> Inventory
<i class="fa fa-cubes"></i> @ViewBag.Title
</h1>
<h4>Current inventory</h4>
<div class="pull-left">
@@ -1,12 +1,12 @@
@model dynamic
@{
ViewBag.Title = "Inventory";
ViewBag.Title = "Commodity Types";
}
<div ng-controller="InventoryTypeController as vm">
<h1 class="page-header">
<i class="fa fa-cube"></i> Commodity Types
<i class="fa fa-cube"></i> @ViewBag.Title
</h1>
<div class="pull-left">
<a class="btn btn-default" href="" ng-click="vm.add()"><i class="fa fa-plus-circle"></i> Add</a>
@@ -11,6 +11,9 @@
</div>
<!-- Top Menu Items -->
<ul class="nav navbar-right top-nav">
<li>
<a href="@(Html.BuildUrlFromExpression<UserController>(c => c.Index()))"><i class="fa fa-fw fa-users"></i> Users</a>
</li>
<li class="dropdown">
<a href="" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> @User.Identity.Name <b class="caret"></b></a>
<ul class="dropdown-menu">
@@ -0,0 +1,16 @@
@model dynamic
@{
ViewBag.Title = "Users";
}
<div ng-controller="UserController as vm">
<h1 class="page-header">
<i class="fa fa-users"></i> @ViewBag.Title
</h1>
<div class="pull-left">
<a class="btn btn-default" href="" ng-click="vm.create()"><i class="fa fa-plus-circle"></i> Create</a>
</div>
<user-list users="vm.users"></user-list>
</div>
@@ -1,10 +1,8 @@
(function () {
'use strict';
window.app.controller('LoginController', LoginController);
LoginController.$inject = ['$window', '$http'];
function LoginController($window, $http) {
window.app.controller('LoginController',
function($window, $http) {
var vm = this;
vm.errorMessage = null;
vm.loggingIn = false;
@@ -26,5 +24,5 @@
vm.loggingIn = false;
});
}
}
});
})();
@@ -1,15 +1,14 @@
(function() {
"use strict";
window.app.directive('inventoryAdd', inventoryAdd);
function inventoryAdd() {
window.app.directive('inventoryAdd',
function() {
return {
templateUrl: '/inventory/template/inventoryAdd.tmpl.cshtml',
controller: controller,
controllerAs: 'vm'
}
}
});
controller.$inject = ['$scope', 'inventorySvc', 'inventoryTypeSvc'];
@@ -1,15 +1,14 @@
(function() {
"use strict";
window.app.directive('inventoryDistribute', inventoryDistribute);
function inventoryDistribute() {
window.app.directive('inventoryDistribute',
function() {
return {
templateUrl: '/inventory/template/inventoryDistribute.tmpl.cshtml',
controller: controller,
controllerAs: 'vm'
}
}
});
controller.$inject = ['$scope', 'inventorySvc'];
function controller($scope, inventorySvc) {
@@ -1,9 +1,8 @@
(function() {
"use strict";
window.app.directive('editInventory', editInventory);
function editInventory() {
window.app.directive('editInventory',
function() {
return {
scope: {
inventory: "="
@@ -12,7 +11,7 @@
controller: controller,
controllerAs: 'vm'
}
}
});
controller.$inject = ['$scope', '$uibModal', 'inventorySvc', 'transactionSvc'];
function controller($scope, $uibModal, inventorySvc, transactionSvc) {
@@ -1,33 +1,29 @@
(function() {
'use strict';
window.app.controller('InventoryListController', InventoryListController);
InventoryListController.$inject = ['$uibModal', 'inventorySvc', 'downloadSvc'];
function InventoryListController($uibModal, inventorySvc, downloadSvc) {
window.app.controller('InventoryListController',
function($uibModal, inventorySvc, downloadSvc) {
var vm = this;
vm.add = add;
vm.distribute = distribute;
vm.inventories = inventorySvc.inventories;
function add() {
vm.add = function() {
$uibModal.open({
template: '<inventory-add />',
backdrop: 'static'
});
}
};
function distribute() {
vm.distribute = function() {
$uibModal.open({
template: '<inventory-distribute />',
backdrop: 'static'
});
}
};
vm.export = function () {
vm.export = function() {
inventorySvc.exportInventory()
.success(downloadSvc.success);
}
}
};
});
})();
@@ -1,15 +1,15 @@
(function() {
'use strict';
window.app.directive('inventoryList', inventoryList);
function inventoryList() {
window.app.directive('inventoryList',
function () {
return {
scope: {"inventories" : "="},
templateUrl: '/inventory/template/inventoryList.tmpl.cshtml',
controller: controller,
controllerAs: 'vm'
}
}
});
controller.$inject = ['$scope', '$uibModal'];
function controller($scope, $uibModal) {
@@ -1,16 +1,15 @@
(function() {
"use strict";
window.app.directive('inventoryInfo', inventoryInfo);
function inventoryInfo() {
window.app.directive('inventoryInfo',
function() {
return {
scope: { "inventory": "=" },
templateUrl: '/inventory/template/inventoryInfo.tmpl.cshtml',
controller: controller,
controllerAs: 'vm'
}
}
});
controller.$inject = ['$scope'];
function controller($scope) {
@@ -1,16 +1,15 @@
(function() {
"use strict";
window.app.directive('inventoryRemove', inventoryRemove);
function inventoryRemove() {
window.app.directive('inventoryRemove',
function() {
return {
scope: { "inventory": "=" },
templateUrl: '/inventory/template/inventoryRemove.tmpl.cshtml',
controller: controller,
controllerAs: 'vm'
}
}
});
controller.$inject = ['$scope', 'inventorySvc'];
function controller($scope, inventorySvc) {
@@ -1,8 +1,6 @@
(function() {
window.app.factory('inventorySvc', inventorySvc);
inventorySvc.$inject = ['$http', '$filter'];
function inventorySvc($http, $filter) {
window.app.factory('inventorySvc',
function($http, $filter) {
var inventories = [];
loadInventories();
@@ -41,7 +39,7 @@
function distribute(distribution) {
return $http.post('/Inventory/Distribute', distribution)
.success(function (data) {
.success(function(data) {
angular.copy(data, inventories);
});
}
@@ -83,5 +81,5 @@
function find(id) {
return $http.post('/Inventory/Find', { id: id });
}
}
});
})();
@@ -1,17 +1,15 @@
(function() {
"use strict";
window.app.directive('inventoryTypeAdd', inventoryTypeAdd);
function inventoryTypeAdd() {
window.app.directive("inventoryTypeAdd",
function() {
return {
templateUrl: '/inventoryType/template/inventoryTypeAdd.tmpl.cshtml',
templateUrl: "/inventoryType/template/inventoryTypeAdd.tmpl.cshtml",
controller: controller,
controllerAs: 'vm'
}
}
controllerAs: "vm"
};
});
controller.$inject = ['$scope', 'inventoryTypeSvc'];
function controller($scope, inventoryTypeSvc){
var vm = this;
@@ -1,33 +1,22 @@
(function() {
'use strict';
window.app.controller('InventoryTypeController', InventoryTypeController);
InventoryTypeController.$inject = ['$uibModal', 'inventoryTypeSvc', 'downloadSvc'];
function InventoryTypeController($uibModal, inventoryTypeSvc, downloadSvc) {
window.app.controller('InventoryTypeController',
function($uibModal, inventoryTypeSvc, downloadSvc) {
var vm = this;
vm.add = add;
vm.edit = edit;
vm.inventoryTypes = inventoryTypeSvc.inventoryTypes;
function add() {
vm.add = function() {
$uibModal.open({
template: '<inventory-type-add />',
backdrop: 'static'
});
}
function edit() {
$uibModal.open({
template: '<inventory-type-edit />',
backdrop: 'static'
});
}
vm.export = function () {
vm.export = function() {
inventoryTypeSvc.exportInventoryTypes()
.success(downloadSvc.success);
}
}
});
})();
@@ -1,9 +1,8 @@
(function() {
"use strict";
window.app.directive('editInventoryType', editInventory);
function editInventory() {
window.app.directive('editInventoryType',
function() {
return {
scope: {
inventoryType: "="
@@ -12,9 +11,8 @@
controller: controller,
controllerAs: 'vm'
}
}
});
controller.$inject = ['$scope', 'inventoryTypeSvc'];
function controller($scope, inventoryTypeSvc) {
var vm = this;
vm.inventoryType = angular.copy($scope.inventoryType);
@@ -1,28 +1,26 @@
(function() {
'use strict';
window.app.directive('inventoryTypeList', inventoryTypeList);
function inventoryTypeList() {
window.app.directive('inventoryTypeList',
function() {
return {
scope: { "inventoryTypes": "=" },
templateUrl: '/inventoryType/template/inventoryTypeList.tmpl.cshtml',
controller: controller,
controllerAs: 'vm'
}
}
});
controller.$inject = ['$scope', '$uibModal'];
function controller($scope, $uibModal) {
var vm = this;
vm.inventoryTypes = $scope.inventoryTypes;
vm.edit = edit;
function edit(inventoryType) {
vm.edit = function(inventoryType) {
$uibModal.open({
template: '<edit-inventory-type inventory-type="inventoryType" />',
scope: angular.extend($scope.$new(true), { inventoryType: inventoryType })
});
}
};
}
})();
@@ -1,8 +1,6 @@
(function () {
window.app.factory('inventoryTypeSvc', inventoryTypeSvc);
inventoryTypeSvc.$inject = ['$http'];
function inventoryTypeSvc($http) {
window.app.factory('inventoryTypeSvc',
function($http) {
var inventoryTypes = [];
loadInventoryTypes();
@@ -18,7 +16,7 @@
function loadInventoryTypes() {
$http.post('/InventoryType/All')
.success(function (data) {
.success(function(data) {
inventoryTypes.addRange(data);
});
}
@@ -29,16 +27,16 @@
function add(inventoryType) {
return $http.post('/InventoryType/Add', inventoryType)
.success(function (inventoryType) {
.success(function(inventoryType) {
inventoryTypes.unshift(inventoryType);
});
}
function update(existingInventoryType, updatedInventoryType) {
return $http.post('/InventoryType/Update', updatedInventoryType)
.success(function (inventoryType) {
.success(function(inventoryType) {
angular.extend(existingInventoryType, inventoryType);
});
}
}
});
})();
@@ -1,10 +1,8 @@
(function() {
'use strict';
window.app.controller('EditProfileController', EditProfileController);
EditProfileController.$inject = ['$http', 'editProfileConfig', 'model'];
function EditProfileController($http, editProfileConfig, model) {
window.app.controller('EditProfileController',
function($http, editProfileConfig, model) {
var vm = this;
vm.profile = model;
@@ -26,5 +24,5 @@
vm.saving = false;
});
}
}
});
})();
@@ -1,17 +1,15 @@
(function () {
'use strict';
window.app.controller('DistributionReportController', DistributionReportController);
DistributionReportController.$inject = ['$scope', 'reportSvc', 'downloadSvc'];
function DistributionReportController($scope, reportSvc, downloadSvc) {
window.app.controller('DistributionReportController',
function($scope, reportSvc, downloadSvc) {
var vm = this;
vm.loadData = reportSvc.loadDistributionReport;
vm.query = reportSvc.distributionQuery;
vm.distributionData = reportSvc.distributionData;
vm.export = function (params) {
vm.export = function(params) {
reportSvc.exportDistributionReport(params)
.success(downloadSvc.success);
}
}
});
})();
@@ -1,17 +1,16 @@
(function() {
'use strict';
window.app.directive('distributionReport', distributionReport);
function distributionReport() {
window.app.directive('distributionReport',
function () {
return {
scope: {distributionData: "="},
templateUrl: '/report/template/distributionReport.tmpl.cshtml',
controller: controller,
controllerAs: 'vm'
}
}
});
controller.$inject = ['$scope'];
function controller($scope) {
var vm = this;
vm.distributionData = $scope.distributionData;
@@ -1,16 +1,14 @@
(function () {
'use strict';
window.app.controller('MovementReportController', MovementReportController);
MovementReportController.$inject = ['$scope', 'reportSvc', 'downloadSvc'];
function MovementReportController($scope, reportSvc, downloadSvc) {
window.app.controller('MovementReportController',
function($scope, reportSvc, downloadSvc) {
var vm = this;
vm.loadData = reportSvc.loadMovementData;
vm.movementData = reportSvc.movementData;
vm.export = function(month) {
reportSvc.exportMovementData({month: month})
reportSvc.exportMovementData({ month: month })
.success(downloadSvc.success);
}
}
});
})();
@@ -1,17 +1,16 @@
(function() {
'use strict';
window.app.directive('movementReport', movementReport);
function movementReport() {
window.app.directive('movementReport',
function() {
return {
scope: { movementData: "=" },
templateUrl: '/report/template/movementReport.tmpl.cshtml',
controller: controller,
controllerAs: 'vm'
}
}
});
controller.$inject = ['$scope', '$uibModal', 'inventorySvc'];
function controller($scope, $uibModal, inventorySvc) {
var vm = this;
vm.movementData = $scope.movementData;
+5 -7
View File
@@ -1,8 +1,6 @@
(function () {
window.app.factory('reportSvc', reportSvc);
reportSvc.$inject = ['$http'];
function reportSvc($http) {
window.app.factory('reportSvc',
function($http) {
var distributionData = [];
var distributionQuery = {};
var movementData = {};
@@ -21,7 +19,7 @@
function loadDistributionReport(query) {
return $http.post('/Report/Distribution', query)
.success(function (data) {
.success(function(data) {
distributionQuery = angular.copy(query, distributionQuery);
angular.copy(data, distributionData);
});
@@ -33,7 +31,7 @@
function loadMovementData(query) {
return $http.post('/Report/Movement', query)
.success(function (data) {
.success(function(data) {
angular.copy(data, movementData);
});
}
@@ -41,5 +39,5 @@
function exportMovementData(query) {
return $http.post('/Report/MovementExcel', query, { responseType: 'arraybuffer' });
}
}
});
})();
@@ -1,16 +1,14 @@
(function() {
'use strict';
window.app.controller('TransactionController', TransactionController);
TransactionController.$inject = ['$scope', '$uibModal', 'transactionSvc', 'inventorySvc', 'uiGridConstants'];
function TransactionController($scope, $uibModal, transactionSvc, inventorySvc, uiGridConstants) {
window.app.controller('TransactionController',
function($scope, $uibModal, transactionSvc, inventorySvc, uiGridConstants) {
var vm = this;
var paginationOptions = {
pageNumber: 1,
pageSize: 20,
pageSizes: [20,50,100],
pageSizes: [20, 50, 100],
sort: null
};
@@ -47,7 +45,8 @@
onRegisterApi: function(gridApi) {
vm.gridApi = gridApi;
vm.gridApi.pagination
.on.paginationChanged($scope, function(pageNumber, pageSize) {
.on.paginationChanged($scope,
function(pageNumber, pageSize) {
paginationOptions.pageNumber = pageNumber;
paginationOptions.pageSize = pageSize;
updateData();
@@ -58,7 +57,7 @@
function updateData() {
transactionSvc
.filterByPage(paginationOptions.pageNumber, paginationOptions.pageSize)
.success(function (data) {
.success(function(data) {
vm.gridOptions.data = data.transactions;
vm.gridOptions.totalItems = data.totalItems;
});
@@ -66,7 +65,7 @@
updateData();
$scope.editInventory = function (inventoryId) {
$scope.editInventory = function(inventoryId) {
inventorySvc.find(inventoryId)
.success(function(inventory) {
$uibModal.open({
@@ -78,5 +77,5 @@
});
});
}
}
});
})();
@@ -1,8 +1,6 @@
(function() {
window.app.factory('transactionSvc', transactionSvc);
transactionSvc.$inject = ['$http', 'inventorySvc'];
function transactionSvc($http, inventorySvc) {
window.app.factory('transactionSvc',
function($http, inventorySvc) {
var svc = {
filterByPage: filterByPage,
@@ -23,15 +21,15 @@
function getTransactions(params) {
var url = '/Transaction/Get';
return $http.post(url, params)
.success(function (data) {
.success(function(data) {
});
}
function deleteTransaction(transactionId) {
return $http.post('/Transaction/Delete', { transactionId: transactionId })
.success(function (data) {
.success(function(data) {
inventorySvc.refresh(data.inventoryId);
});
}
}
});
})();
@@ -0,0 +1,29 @@
(function() {
'use strict';
window.app.controller('UserController',
function($uibModal, userSvc, downloadSvc) {
var vm = this;
vm.users = userSvc.users;
vm.create = function() {
$uibModal.open({
template: '<user-create />',
backdrop: 'static'
});
}
vm.edit = function() {
$uibModal.open({
template: '<user-edit />',
backdrop: 'static'
});
}
vm.export = function() {
userSvc.exportUsers()
.success(downloadSvc.success);
}
});
})();
@@ -0,0 +1,37 @@
(function() {
"use strict";
window.app.directive('userCreate', function() {
return {
templateUrl: '/user/template/userCreate.tmpl.cshtml',
controller: controller,
controllerAs: 'vm'
}
});
function controller($scope, userSvc){
var vm = this;
vm.saving = false;
vm.user = {};
vm.statusMessage = "Create a user";
vm.errorMessages = [];
vm.create = function() {
vm.statusMessage = null;
vm.saving = true;
userSvc.create(vm.user)
.success(function() {
//Close the modal
$scope.$close();
})
.error(function(data) {
vm.errorMessages = angular.copy(data.errorMessages, vm.errorMessages);
})
.finally(function() {
vm.saving = false;
});
};
}
})();
@@ -0,0 +1,42 @@
(function() {
"use strict";
window.app.directive('userEdit', function (){
return {
scope: {
user: "="
},
templateUrl: '/user/template/userEdit.tmpl.cshtml',
controller: controller,
controllerAs: 'vm'
}
});
function controller($scope, userSvc) {
var vm = this;
vm.user = angular.copy($scope.user);
vm.save = save;
vm.saving = false;
vm.userSvc = userSvc;
vm.statusMessage = "Edit this user";
vm.errorMessages = [];
function save() {
vm.statusMessage = null;
vm.saving = true;
userSvc.edit($scope.user, vm.user)
.success(function () {
//Close the modal
$scope.$parent.$close();
})
.error(function(data) {
vm.errorMessages = angular.copy(data.errorMessages, vm.errorMessages);
})
.finally(function() {
vm.saving = false;
});
}
}
})();
@@ -0,0 +1,27 @@
(function() {
'use strict';
window.app.directive('userList', function () {
return {
scope: { "users": "=" },
templateUrl: '/user/template/userList.tmpl.cshtml',
controller: controller,
controllerAs: 'vm'
}
});
controller.$inject = ['$scope', '$uibModal'];
function controller($scope, $uibModal) {
var vm = this;
vm.users = $scope.users;
vm.edit = edit;
function edit(user) {
$uibModal.open({
template: '<user-edit user="user" />',
scope: angular.extend($scope.$new(true), { user: user })
});
}
}
})();
@@ -0,0 +1,27 @@
@using InventoryTraker.Web.Helpers
@model InventoryTraker.Web.Models.UserEditForm
<form novalidate
name="vm.form"
ng-submit="vm.form.$valid && vm.create()">
<fieldset ng-disabled="vm.saving">
<div class="modal-header">
<h3 class="modal-title"><i class="fa fa-user"></i> Create User</h3>
</div>
<div class="modal-body">
<status-message message="vm.statusMessage"></status-message>
<error-list errors="vm.errorMessages"></error-list>
@Html.Angular().FormForModel("vm.user")
</div>
<div class="modal-footer">
<button class="btn btn-success">Create</button>
<button type="button" class="btn" ng-click="$dismiss()">Cancel</button>
</div>
</fieldset>
</form>
@@ -0,0 +1,27 @@
@using InventoryTraker.Web.Helpers
@model InventoryTraker.Web.Models.UserEditForm
<form novalidate
name="vm.form"
ng-submit="vm.form.$valid && vm.save()">
<fieldset ng-disabled="vm.saving">
<div class="modal-header">
<h3 class="modal-title"><i class="fa fa-user"></i> Edit User</h3>
</div>
<div class="modal-body">
<status-message message="vm.statusMessage"></status-message>
<error-list errors="vm.errorMessages"></error-list>
@Html.Angular().FormForModel("vm.user")
</div>
<div class="modal-footer">
<button class="btn btn-success">Save</button>
<button type="button" class="btn" ng-click="$parent.$dismiss()">Cancel</button>
</div>
</fieldset>
</form>
@@ -0,0 +1,16 @@
<table class="table table-striped">
<thead>
<tr>
<th class="control-column"></th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in vm.users | orderBy:'name'">
<td><a href="" ng-click="vm.edit(user)"><i class="fa fa-edit"></i></a></td>
<td>{{user.userName}}</td>
<td>{{user.email}}</td>
</tr>
</tbody>
</table>
+42
View File
@@ -0,0 +1,42 @@
(function () {
window.app.factory('userSvc',
function($http) {
var users = [];
loadUsers();
var svc = {
create: create,
edit: edit,
users: users,
exportusers: exportusers
};
return svc;
function loadUsers() {
$http.post('/User/All')
.success(function(data) {
users.addRange(data);
});
}
function exportusers() {
return $http.post('/User/Export', {}, { responseType: 'arraybuffer' });
}
function create(user) {
return $http.post('/User/Create', user)
.success(function(user) {
users.unshift(user);
});
}
function edit(existingUser, editedUser) {
return $http.post('/User/Edit', editedUser)
.success(function(user) {
angular.copy(user, existingUser);
});
}
});
})();
@@ -13,7 +13,6 @@
}
}
controller.$inject = ['$scope'];
function controller($scope) {
var vm = this;
vm.query = {};
@@ -1,11 +1,9 @@
(function () {
window.app.factory('downloadSvc', downloadSvc);
downloadSvc.$inject = ['$http'];
function downloadSvc($http) {
window.app.factory('downloadSvc',
function($http) {
var svc = {
success: function (data, status, headers, config) {
success: function(data, status, headers, config) {
var file = new Blob([data], { type: headers('Content-Type') });
var match = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(headers('Content-Disposition'));
saveAs(file, match[1]);
@@ -13,5 +11,5 @@
};
return svc;
}
});
})();
+3 -4
View File
@@ -1,8 +1,8 @@
(function() {
'use strict';
window.app.directive('errorList', errorList);
function errorList() {
window.app.directive('errorList',
function() {
return {
scope: {
errors: "=",
@@ -12,9 +12,8 @@
controller: controller,
controllerAs: 'vm'
}
}
});
controller.$inject = ['$scope'];
function controller($scope) {
var vm = this;
vm.errors = $scope.errors;
@@ -1,9 +1,8 @@
(function () {
'use strict';
window.app.directive('formGroupValidation', formGroupValidation);
function formGroupValidation() {
window.app.directive('formGroupValidation',
function() {
return {
require: '^form',
replace: true,
@@ -18,13 +17,12 @@
},
controller: controller,
controllerAs: 'vm',
link: function (scope, element, attrs, formCtrl) {
link: function(scope, element, attrs, formCtrl) {
scope.form = formCtrl;
}
}
}
});
controller.$inject = ['$scope'];
function controller($scope) {
var vm = this;
@@ -1,12 +1,11 @@
(function() {
window.app.filter('formatCases', formatCases);
function formatCases() {
return function (qty) {
window.app.filter('formatCases',
function() {
return function(qty) {
if (qty === '' || !isFinite(qty))
return '';
return '(' + qty + ' cs)';
}
}
});
})();
@@ -1,10 +1,9 @@
(function () {
window.app.filter('hideZero', hideZero);
window.app.filter('hideZero',
function() {
return function(input) {
function hideZero() {
return function (input) {
return input > 0 ? input : '';
}
return input > 0 ? input : "";
}
});
})();
@@ -1,9 +1,8 @@
(function () {
'use strict';
window.app.directive('inputValidationIcons', inputValidationIcons);
function inputValidationIcons() {
window.app.directive('inputValidationIcons',
function() {
return {
require: '^form',
scope: {
@@ -16,13 +15,12 @@
'class="fa fa-2x fa-exclamation-triangle form-control-feedback"></span>',
controller: controller,
controllerAs: 'vm',
link: function (scope, element, attrs, formCtrl) {
link: function(scope, element, attrs, formCtrl) {
scope.form = formCtrl;
}
}
}
});
controller.$inject = ['$scope'];
function controller($scope) {
var vm = this;
@@ -1,8 +1,8 @@
(function() {
'use strict';
window.app.directive('monthQuery', monthQuery);
function monthQuery() {
window.app.directive('monthQuery',
function() {
return {
scope: {
queryFn: '='
@@ -11,25 +11,24 @@
controller: controller,
controllerAs: 'vm'
}
}
});
controller.$inject = ['$scope'];
function controller($scope) {
var vm = this;
vm.query = {};
vm.submitting = false;
vm.errorMessages = [];
vm.submit = submit;
function submit() {
vm.submit =
function() {
vm.submitting = true;
$scope.queryFn({ month: vm.query })
.error(function (data) {
vm.errorMessages = angular.copy(data.errorMessages, vm.errorMessages);
.error(function(data) {
vm.errorMessages
= angular.copy(data.errorMessages, vm.errorMessages);
})
.finally(function () {
.finally(function() {
vm.submitting = false;
});
}
};
}
})();
@@ -1,46 +0,0 @@
(function () {
window.app.directive('mvcGrid', mvcGrid);
function mvcGrid() {
return {
scope: {
gridDataUrl: '@',
title: '@',
columns: '@?'
},
template:
'<div>' +
'<h4><i class="fa fa-pie-chart fa-fw"></i> {{vm.title}}</h4>' +
'<div>' +
'<p ng-if="vm.loading">Loading...</p>' +
'<div ng-if="!vm.loading" ui-grid="vm.gridOptions"></div>' +
'</div>' +
'</div>',
controllerAs: 'vm',
controller: controller
}
}
controller.$inject = ['$scope', '$http'];
function controller($scope, $http) {
var vm = this;
vm.gridOptions = {
enableHorizontalScrollbar: 0
}
vm.loading = true;
vm.title = $scope.title;
if ($scope.columns)
vm.gridOptions.columnDefs = angular.fromJson($scope.columns);
$http.post($scope.gridDataUrl)
.success(function (data) {
vm.gridOptions.data = data;
vm.loading = false;
});
}
})();
@@ -1,11 +1,10 @@
(function() {
window.app.filter('parseDate', parseDate);
function parseDate() {
window.app.filter("parseDate",
function() {
return function(input) {
if (typeof input != 'string' || input.indexOf('/Date') === -1) return input;
if (typeof input != 'string' || input.indexOf("/Date") === -1) return input;
return new Date(parseInt(input.substr(6)));
}
}
});
})();
@@ -1,8 +1,8 @@
(function() {
'use strict';
window.app.directive('statusMessage', statusMessage);
function statusMessage() {
window.app.directive('statusMessage',
function() {
return {
scope: {
message: "=",
@@ -12,9 +12,8 @@
controller: controller,
controllerAs: 'vm'
}
}
});
controller.$inject = ['$scope'];
function controller($scope) {
}
})();
+6 -7
View File
@@ -1,13 +1,12 @@
(function() {
window.app.filter('toUnits', toUnits);
function toUnits() {
return function (caseQty, unitsPerCase) {
if (caseQty === '' || !isFinite(caseQty) || !isFinite(unitsPerCase))
return '';
window.app.filter('toUnits',
function() {
return function(caseQty, unitsPerCase) {
if (caseQty === "" || !isFinite(caseQty) || !isFinite(unitsPerCase))
return "";
return caseQty * unitsPerCase;
}
}
});
})();