User profile editing and password

This commit is contained in:
2016-09-26 11:13:59 -04:00
parent 6789c1b3b5
commit 75b7c02979
54 changed files with 373 additions and 209 deletions
@@ -34,10 +34,6 @@
<HintPath>..\packages\AutoMapper.5.1.1\lib\net45\AutoMapper.dll</HintPath> <HintPath>..\packages\AutoMapper.5.1.1\lib\net45\AutoMapper.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Heroic.AutoMapper, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Heroic.AutoMapper.2.0.0\lib\net45\Heroic.AutoMapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath> <HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
<Private>True</Private> <Private>True</Private>
@@ -1,6 +1,5 @@
using System; using System;
using AutoMapper; using AutoMapper;
using Heroic.AutoMapper;
using InventoryTraker.Web.Core; using InventoryTraker.Web.Core;
using InventoryTraker.Web.Models; using InventoryTraker.Web.Models;
using NUnit.Framework; using NUnit.Framework;
@@ -1,6 +1,8 @@
using System.Web.Mvc; using System.Linq;
using System.Threading.Tasks;
using System.Web.Mvc;
using AutoMapper; using AutoMapper;
using InventoryTraker.Web.Core; using InventoryTraker.Web.Attributes;
using InventoryTraker.Web.Identity; using InventoryTraker.Web.Identity;
using InventoryTraker.Web.Models; using InventoryTraker.Web.Models;
using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity;
@@ -20,19 +22,44 @@ namespace InventoryTraker.Web.Controllers
public ActionResult Index() public ActionResult Index()
{ {
var user = _userManager.FindById(User.Identity.GetUserId()); return View();
var model = _mapper.Map<ProfileForm>(user);
return View(model);
} }
public JsonResult Update(ProfileForm form) public JsonResult Get()
{ {
var user = _userManager.FindById(User.Identity.GetUserId()); var user = _userManager.FindById(User.Identity.GetUserId());
user.Email = form.EmailAddress; var model = _mapper.Map<ProfileForm>(user);
user.UserName = form.FullName; return BetterJson(model);
_userManager.Update(user); }
return Json(true); [ActionLog]
public async Task<JsonResult> Update(ProfileForm form)
{
if (!ModelState.IsValid)
return GetModelStateErrorListJson();
var user = _userManager.FindById(User.Identity.GetUserId());
user.Email = form.Email;
user.UserName = form.UserName;
if (!string.IsNullOrEmpty(form.NewPassword))
{
if (string.IsNullOrEmpty(form.CurrentPassword))
return GetErrorListJson("Current password required");
var result =
await _userManager.ChangePasswordAsync(
user.Id, form.CurrentPassword, form.NewPassword);
if (!result.Succeeded)
return GetErrorListJson(result.Errors.ToArray());
}
var identityResult = _userManager.Update(user);
if (!identityResult.Succeeded)
return GetErrorListJson(identityResult.Errors.ToArray());
return BetterJson(_mapper.Map<ProfileForm>(user));
} }
} }
} }
@@ -74,8 +74,7 @@ namespace InventoryTraker.Web.Controllers
if (!string.IsNullOrEmpty(form.Password)) if (!string.IsNullOrEmpty(form.Password))
{ {
var resetToken = await _userManager.GeneratePasswordResetTokenAsync(user.Id); var resetResult = await _userManager.ChangePasswordAsync(user, form.Password);
var resetResult = await _userManager.ResetPasswordAsync(user.Id, resetToken, form.Password);
if (!resetResult.Succeeded) if (!resetResult.Succeeded)
return GetErrorListJson(resetResult.Errors.ToArray()); return GetErrorListJson(resetResult.Errors.ToArray());
} }
@@ -1,4 +1,5 @@
using System; using System;
using System.Threading.Tasks;
using InventoryTraker.Web.Core; using InventoryTraker.Web.Core;
using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin; using Microsoft.AspNet.Identity.Owin;
@@ -26,5 +27,11 @@ namespace InventoryTraker.Web.Identity
}; };
} }
} }
public async Task<IdentityResult> ChangePasswordAsync(User user, string newPassword)
{
var resetToken = await GeneratePasswordResetTokenAsync(user.Id);
return await ResetPasswordAsync(user.Id, resetToken, newPassword);
}
} }
} }
@@ -228,6 +228,8 @@
<Content Include="Global.asax" /> <Content Include="Global.asax" />
<Content Include="js\app.js" /> <Content Include="js\app.js" />
<Content Include="js\authentication\LoginController.js" /> <Content Include="js\authentication\LoginController.js" />
<Content Include="js\profile\profileSvc.js" />
<Content Include="js\profile\ProfileEditDirective.js" />
<Content Include="js\user\UserCreateDirective.js" /> <Content Include="js\user\UserCreateDirective.js" />
<Content Include="js\user\UserController.js" /> <Content Include="js\user\UserController.js" />
<Content Include="js\user\UserEditDirective.js" /> <Content Include="js\user\UserEditDirective.js" />
@@ -246,7 +248,7 @@
<Content Include="js\inventory\inventorySvc.js" /> <Content Include="js\inventory\inventorySvc.js" />
<Content Include="js\inventory\InventoryEditDirective.js" /> <Content Include="js\inventory\InventoryEditDirective.js" />
<Content Include="js\inventory\InventoryDistributeDirective.js" /> <Content Include="js\inventory\InventoryDistributeDirective.js" />
<Content Include="js\profile\EditProfileController.js" /> <Content Include="js\profile\ProfileController.js" />
<Content Include="js\report\MovementReportDirective.js" /> <Content Include="js\report\MovementReportDirective.js" />
<Content Include="js\report\MovementReportController.js" /> <Content Include="js\report\MovementReportController.js" />
<Content Include="js\report\DistributionReportDirective.js" /> <Content Include="js\report\DistributionReportDirective.js" />
@@ -313,6 +315,7 @@
<Content Include="js\user\templates\userCreate.tmpl.cshtml" /> <Content Include="js\user\templates\userCreate.tmpl.cshtml" />
<Content Include="js\user\templates\userEdit.tmpl.cshtml" /> <Content Include="js\user\templates\userEdit.tmpl.cshtml" />
<Content Include="js\user\templates\userList.tmpl.cshtml" /> <Content Include="js\user\templates\userList.tmpl.cshtml" />
<Content Include="js\profile\templates\profileEdit.tmpl.cshtml" />
<None Include="NLog.xsd"> <None Include="NLog.xsd">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</None> </None>
+24 -7
View File
@@ -6,19 +6,36 @@ namespace InventoryTraker.Web.Models
{ {
public class ProfileForm public class ProfileForm
{ {
[Required, Display(Name = "Full Name", Prompt = "Full Name (ex: John Doe)...")] [Required]
public string FullName { get; set; } [StringLength(128)]
[RegularExpression(@"[A-Za-z().]+(\s+[A-Za-z().]+)+", ErrorMessage = "Need complete name")]
public string UserName { get; set; }
[Required, DataType(DataType.EmailAddress), Display(Prompt = "your@email.com...")] [Required]
public string EmailAddress { get; set; } [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 CurrentPassword { get; set; }
[DataType(DataType.Password)]
public string NewPassword { get; set; }
[DataType(DataType.Password)]
[Compare("NewPassword")]
public string ConfirmPassword { get; set; }
public override string ToString()
{
return $"UserName: {UserName}, email: {Email}";
}
public class AutoMapperProfile : Profile public class AutoMapperProfile : Profile
{ {
public AutoMapperProfile() public AutoMapperProfile()
{ {
CreateMap<User, ProfileForm>() CreateMap<User, ProfileForm>();
.ForMember(d => d.FullName, opt => opt.MapFrom(s => s.UserName))
.ForMember(d => d.EmailAddress, opt => opt.MapFrom(s => s.Email));
} }
} }
} }
+6 -31
View File
@@ -1,38 +1,13 @@
@using InventoryTraker.Web.Helpers @model InventoryTraker.Web.Models.ProfileForm
@model InventoryTraker.Web.Models.ProfileForm
@{ @{
ViewBag.Title = "Your Profile"; ViewBag.Title = "Your Profile";
} }
<h1 class="page-header">Update @ViewBag.Title</h1> <h1 class="page-header">Update @ViewBag.Title</h1>
<form novalidate
name="vm.form"
ng-controller="EditProfileController as vm"
ng-submit="vm.form.$valid && vm.save()"
style="max-width: 500px;">
<fieldset ng-disabled="vm.saving">
<div class="alert alert-info" ng-show="vm.errorMessage == null && !vm.saving && !vm.success"> <div class="row" ng-controller="ProfileController as vm">
Make changes below. <div class="panel panel-default col-md-6">
</div> <profile-edit profile="vm.profile"></profile-edit>
<div class="alert alert-info" ng-show="vm.saving"> </div>
Saving changes... </div>
</div>
<div class="alert alert-success" ng-show="vm.success">
<span class="fa fa-check"></span>
Changes saved!
</div>
<div class="alert alert-danger" ng-show="vm.errorMessage != null">
{{vm.errorMessage}}
</div>
@Html.Angular().FormForModel("vm.profile")
<div class="form-group">
<button class="btn btn-success">Save Changes</button>
<a class="btn btn-warning" href="/">Cancel</a>
</div>
</fieldset>
</form>
@@ -36,13 +36,13 @@
<a href="@(Html.BuildUrlFromExpression<TransactionController>(c => c.Index()))"><i class="fa fa-fw fa-list"></i> Transaction History</a> <a href="@(Html.BuildUrlFromExpression<TransactionController>(c => c.Index()))"><i class="fa fa-fw fa-list"></i> Transaction History</a>
</li> </li>
<li> <li>
<a href="#"><i class="fa fa-file-o"></i> Reports</a> <a href="#"><i class="fa fa-fw fa-file-o"></i> Reports</a>
<ul> <ul>
<li> <li>
<a href="@(Html.BuildUrlFromExpression<ReportController>(c => c.Distribution()))"><i class="fa fa-file-o"></i> Distribution</a> <a href="@(Html.BuildUrlFromExpression<ReportController>(c => c.Distribution()))"><i class="fa fa-fw fa-file-o"></i> Distribution</a>
</li> </li>
<li> <li>
<a href="@(Html.BuildUrlFromExpression<ReportController>(c => c.Movement()))"><i class="fa fa-file-o"></i> Monthly Inventory</a> <a href="@(Html.BuildUrlFromExpression<ReportController>(c => c.Movement()))"><i class="fa fa-fw fa-file-o"></i> Monthly Inventory</a>
</li> </li>
</ul> </ul>
</li> </li>
@@ -1,7 +1,9 @@
(function () { (function() {
'use strict'; "use strict";
window.app.controller('LoginController', window.app.controller("LoginController",
[
"$window", "$http",
function($window, $http) { function($window, $http) {
var vm = this; var vm = this;
vm.errorMessage = null; vm.errorMessage = null;
@@ -24,5 +26,6 @@
vm.loggingIn = false; vm.loggingIn = false;
}); });
} }
}); }
]);
})(); })();
@@ -11,7 +11,6 @@
}); });
controller.$inject = ['$scope', 'inventorySvc', 'inventoryTypeSvc']; controller.$inject = ['$scope', 'inventorySvc', 'inventoryTypeSvc'];
function controller($scope, inventorySvc, inventoryTypeSvc) { function controller($scope, inventorySvc, inventoryTypeSvc) {
var vm = this; var vm = this;
@@ -1,7 +1,9 @@
(function() { (function() {
'use strict'; "use strict";
window.app.controller('InventoryListController', window.app.controller("InventoryListController",
[
"$uibModal", "inventorySvc", "downloadSvc",
function($uibModal, inventorySvc, downloadSvc) { function($uibModal, inventorySvc, downloadSvc) {
var vm = this; var vm = this;
@@ -9,15 +11,15 @@
vm.add = function() { vm.add = function() {
$uibModal.open({ $uibModal.open({
template: '<inventory-add />', template: "<inventory-add />",
backdrop: 'static' backdrop: "static"
}); });
}; };
vm.distribute = function() { vm.distribute = function() {
$uibModal.open({ $uibModal.open({
template: '<inventory-distribute />', template: "<inventory-distribute />",
backdrop: 'static' backdrop: "static"
}); });
}; };
@@ -25,5 +27,6 @@
inventorySvc.exportInventory() inventorySvc.exportInventory()
.success(downloadSvc.success); .success(downloadSvc.success);
}; };
}); }
]);
})(); })();
@@ -1,5 +1,7 @@
(function() { (function() {
window.app.factory('inventorySvc', window.app.factory("inventorySvc",
[
"$http", "$filter",
function($http, $filter) { function($http, $filter) {
var inventories = []; var inventories = [];
@@ -20,32 +22,32 @@
return svc; return svc;
function loadInventories() { function loadInventories() {
$http.post('/Inventory/All') $http.post("/Inventory/All")
.success(function(data) { .success(function(data) {
angular.copy(data, inventories); angular.copy(data, inventories);
}); });
} }
function exportInventory() { function exportInventory() {
return $http.post('/Inventory/Export', {}, { responseType: 'arraybuffer' }); return $http.post("/Inventory/Export", {}, { responseType: "arraybuffer" });
} }
function add(inventory) { function add(inventory) {
return $http.post('/Inventory/Add', inventory) return $http.post("/Inventory/Add", inventory)
.success(function(inventory) { .success(function(inventory) {
inventories.unshift(inventory); inventories.unshift(inventory);
}); });
} }
function distribute(distribution) { function distribute(distribution) {
return $http.post('/Inventory/Distribute', distribution) return $http.post("/Inventory/Distribute", distribution)
.success(function(data) { .success(function(data) {
angular.copy(data, inventories); angular.copy(data, inventories);
}); });
} }
function update(existingInventory, updatedInventory) { function update(existingInventory, updatedInventory) {
return $http.post('/Inventory/Update', updatedInventory) return $http.post("/Inventory/Update", updatedInventory)
.success(function(inventory) { .success(function(inventory) {
angular.extend(existingInventory, inventory); angular.extend(existingInventory, inventory);
}); });
@@ -54,14 +56,14 @@
// remove quantity from this inventory // remove quantity from this inventory
function remove(removeForm) { function remove(removeForm) {
var existingInventory = get(removeForm.inventoryId); var existingInventory = get(removeForm.inventoryId);
return $http.post('/Inventory/Remove', removeForm) return $http.post("/Inventory/Remove", removeForm)
.success(function(data) { .success(function(data) {
angular.copy(data, existingInventory); angular.copy(data, existingInventory);
}); });
} }
function get(id) { function get(id) {
var results = $filter('filter')(inventories, { id: id }); var results = $filter("filter")(inventories, { id: id });
if (results.length > 0) if (results.length > 0)
return results[0]; return results[0];
return null; return null;
@@ -79,7 +81,8 @@
} }
function find(id) { function find(id) {
return $http.post('/Inventory/Find', { id: id }); return $http.post("/Inventory/Find", { id: id });
} }
}); }
]);
})(); })();
@@ -85,7 +85,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-success">Add</button> <button class="btn btn-success" ng-disabled="vm.form.$invalid || vm.form.$pristine">Add</button>
<button type="button" class="btn" ng-click="$dismiss()">Cancel</button> <button type="button" class="btn" ng-click="$dismiss()">Cancel</button>
</div> </div>
@@ -55,7 +55,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-success">Save</button> <button class="btn btn-success" ng-disabled="vm.form.$invalid || vm.form.$pristine">Save</button>
<button type="button" class="btn" ng-click="$dismiss()">Cancel</button> <button type="button" class="btn" ng-click="$dismiss()">Cancel</button>
</div> </div>
@@ -15,7 +15,7 @@
<inventory-info inventory="inventory"></inventory-info> <inventory-info inventory="inventory"></inventory-info>
<div class="modal-footer"> <div class="modal-footer">
<button ng-click="vm.removeInventory()" class="btn btn-sm pull-left"><i class="fa fa-minus-circle"></i> Remove Inventory</button> <button ng-click="vm.removeInventory()" class="btn btn-sm pull-left"><i class="fa fa-minus-circle"></i> Remove Inventory</button>
<button class="btn btn-success">Save</button> <button class="btn btn-success" ng-disabled="vm.form.$invalid || vm.form.$pristine">Save</button>
<button type="button" class="btn" ng-click="$parent.$dismiss()">Cancel</button> <button type="button" class="btn" ng-click="$parent.$dismiss()">Cancel</button>
</div> </div>
@@ -18,7 +18,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr ng-repeat="inventory in vm.inventories"> <tr ng-repeat="inventory in vm.inventories | filter:{name: ''}">
<td> <td>
<a href="" ng-click="vm.edit(inventory)" title="Details"><i class="fa fa-edit"></i></a> <a href="" ng-click="vm.edit(inventory)" title="Details"><i class="fa fa-edit"></i></a>
</td> </td>
@@ -47,7 +47,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-success">Remove</button> <button class="btn btn-success" ng-disabled="vm.form.$invalid || vm.form.$pristine">Remove</button>
<button type="button" class="btn" ng-click="$parent.$dismiss()">Cancel</button> <button type="button" class="btn" ng-click="$parent.$dismiss()">Cancel</button>
</div> </div>
@@ -10,6 +10,7 @@
}; };
}); });
controller.$inject = ['$scope', 'inventoryTypeSvc'];
function controller($scope, inventoryTypeSvc){ function controller($scope, inventoryTypeSvc){
var vm = this; var vm = this;
@@ -1,7 +1,9 @@
(function() { (function() {
'use strict'; "use strict";
window.app.controller('InventoryTypeController', window.app.controller("InventoryTypeController",
[
"$uibModal", "inventoryTypeSvc", "downloadSvc",
function($uibModal, inventoryTypeSvc, downloadSvc) { function($uibModal, inventoryTypeSvc, downloadSvc) {
var vm = this; var vm = this;
@@ -9,14 +11,14 @@
vm.add = function() { vm.add = function() {
$uibModal.open({ $uibModal.open({
template: '<inventory-type-add />', template: "<inventory-type-add />",
backdrop: 'static' backdrop: "static"
}); });
} };
vm.export = function() { vm.export = function() {
inventoryTypeSvc.exportInventoryTypes() inventoryTypeSvc.exportInventoryTypes()
.success(downloadSvc.success); .success(downloadSvc.success);
} };
}); }
]);
})(); })();
@@ -13,6 +13,7 @@
} }
}); });
controller.$inject = ['$scope', 'inventoryTypeSvc'];
function controller($scope, inventoryTypeSvc) { function controller($scope, inventoryTypeSvc) {
var vm = this; var vm = this;
vm.inventoryType = angular.copy($scope.inventoryType); vm.inventoryType = angular.copy($scope.inventoryType);
@@ -11,6 +11,7 @@
} }
}); });
controller.$inject = ['$scope', '$uibModal'];
function controller($scope, $uibModal) { function controller($scope, $uibModal) {
var vm = this; var vm = this;
@@ -1,5 +1,7 @@
(function () { (function() {
window.app.factory('inventoryTypeSvc', window.app.factory("inventoryTypeSvc",
[
"$http",
function($http) { function($http) {
var inventoryTypes = []; var inventoryTypes = [];
@@ -15,28 +17,29 @@
return svc; return svc;
function loadInventoryTypes() { function loadInventoryTypes() {
$http.post('/InventoryType/All') $http.post("/InventoryType/All")
.success(function(data) { .success(function(data) {
inventoryTypes.addRange(data); inventoryTypes.addRange(data);
}); });
} }
function exportInventoryTypes() { function exportInventoryTypes() {
return $http.post('/InventoryType/Export', {}, { responseType: 'arraybuffer' }); return $http.post("/InventoryType/Export", {}, { responseType: "arraybuffer" });
} }
function add(inventoryType) { function add(inventoryType) {
return $http.post('/InventoryType/Add', inventoryType) return $http.post("/InventoryType/Add", inventoryType)
.success(function(inventoryType) { .success(function(inventoryType) {
inventoryTypes.unshift(inventoryType); inventoryTypes.unshift(inventoryType);
}); });
} }
function update(existingInventoryType, updatedInventoryType) { function update(existingInventoryType, updatedInventoryType) {
return $http.post('/InventoryType/Update', updatedInventoryType) return $http.post("/InventoryType/Update", updatedInventoryType)
.success(function(inventoryType) { .success(function(inventoryType) {
angular.extend(existingInventoryType, inventoryType); angular.extend(existingInventoryType, inventoryType);
}); });
} }
}); }
]);
})(); })();
@@ -19,7 +19,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-success">Add</button> <button class="btn btn-success" ng-disabled="vm.form.$invalid || vm.form.$pristine">Add</button>
<button type="button" class="btn" ng-click="$dismiss()">Cancel</button> <button type="button" class="btn" ng-click="$dismiss()">Cancel</button>
</div> </div>
@@ -19,7 +19,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-success">Save</button> <button class="btn btn-success" ng-disabled="vm.form.$invalid || vm.form.$pristine">Save</button>
<button type="button" class="btn" ng-click="$parent.$dismiss()">Cancel</button> <button type="button" class="btn" ng-click="$parent.$dismiss()">Cancel</button>
</div> </div>
@@ -1,28 +0,0 @@
(function() {
'use strict';
window.app.controller('EditProfileController',
function($http, model) {
var vm = this;
vm.profile = model;
vm.save = save;
function save() {
vm.saving = true;
vm.errorMessage = null;
vm.success = false;
$http.post("/Profile/Update", vm.profile)
.success(function() {
vm.success = true;
})
.error(function(msg) {
vm.errorMessage = msg;
})
.finally(function() {
vm.saving = false;
});
}
});
})();
@@ -0,0 +1,13 @@
(function() {
"use strict";
window.app.controller("ProfileController",
[
'$scope', 'profileSvc',
function ($scope, profileSvc) {
var vm = this;
vm.profile = profileSvc.profile;
}
]);
})();
@@ -0,0 +1,43 @@
(function() {
"use strict";
window.app.directive('profileEdit', function (){
return {
scope: {
profile: "="
},
templateUrl: '/profile/template/profileEdit.tmpl.cshtml',
controller: controller,
controllerAs: 'vm'
}
});
controller.$inject = ['$scope', 'profileSvc'];
function controller($scope, profileSvc) {
var vm = this;
vm.profile = $scope.profile;
vm.saving = false;
vm.success = false;
vm.errorMessages = [];
vm.save = save;
function save() {
vm.saving = true;
vm.success = false;
angular.copy([], vm.errorMessages);
profileSvc.update(vm.profile)
.success(function () {
vm.success = true;
vm.form.$setPristine();
})
.error(function (data) {
vm.errorMessages = angular.copy(data.errorMessages, vm.errorMessages);
})
.finally(function () {
vm.saving = false;
});
}
}
})();
@@ -0,0 +1,32 @@
(function() {
window.app.factory("profileSvc",
[
"$http",
function($http) {
var profile = {};
loadProfile();
var svc = {
update: update,
profile: profile
};
return svc;
function loadProfile() {
$http.post("/Profile/Get")
.success(function(data) {
angular.copy(data, profile);
});
}
function update(updatedProfile) {
return $http.post("/Profile/Update", updatedProfile)
.success(function(data) {
angular.copy(data, profile);
});
}
}
]);
})();
@@ -0,0 +1,28 @@
@using InventoryTraker.Web.Helpers
@model InventoryTraker.Web.Models.ProfileForm
<form novalidate
name="vm.form"
ng-submit="vm.form.$valid && vm.save()">
<fieldset ng-disabled="vm.saving">
<div class="panel">
<div class="panel-body">
<status-message message="vm.statusMessage"></status-message>
<error-list errors="vm.errorMessages"></error-list>
<div class="alert alert-success" ng-show="vm.success && vm.form.$pristine">
<span class="fa fa-check"></span>
Changes saved
</div>
@Html.Angular().FormForModel("vm.profile")
</div>
<div class="panel-footer">
<button class="btn btn-success" ng-disabled="vm.form.$invalid || vm.form.$pristine">Save</button>
<a class="btn btn-default" href="/">Cancel</a>
</div>
</div>
</fieldset>
</form>
@@ -1,7 +1,9 @@
(function () { (function() {
'use strict'; "use strict";
window.app.controller('DistributionReportController', window.app.controller("DistributionReportController",
[
"$scope", "reportSvc", "downloadSvc",
function($scope, reportSvc, downloadSvc) { function($scope, reportSvc, downloadSvc) {
var vm = this; var vm = this;
vm.loadData = reportSvc.loadDistributionReport; vm.loadData = reportSvc.loadDistributionReport;
@@ -10,6 +12,7 @@
vm.export = function(params) { vm.export = function(params) {
reportSvc.exportDistributionReport(params) reportSvc.exportDistributionReport(params)
.success(downloadSvc.success); .success(downloadSvc.success);
} };
}); }
]);
})(); })();
@@ -11,6 +11,7 @@
} }
}); });
controller.$inject = ['$scope'];
function controller($scope) { function controller($scope) {
var vm = this; var vm = this;
vm.distributionData = $scope.distributionData; vm.distributionData = $scope.distributionData;
@@ -1,7 +1,9 @@
(function () { (function() {
'use strict'; "use strict";
window.app.controller('MovementReportController', window.app.controller("MovementReportController",
[
"$scope", "reportSvc", "downloadSvc",
function($scope, reportSvc, downloadSvc) { function($scope, reportSvc, downloadSvc) {
var vm = this; var vm = this;
vm.loadData = reportSvc.loadMovementData; vm.loadData = reportSvc.loadMovementData;
@@ -9,6 +11,7 @@
vm.export = function(month) { vm.export = function(month) {
reportSvc.exportMovementData({ month: month }) reportSvc.exportMovementData({ month: month })
.success(downloadSvc.success); .success(downloadSvc.success);
} };
}); }
]);
})(); })();
@@ -11,6 +11,7 @@
} }
}); });
controller.$inject = ['$scope', '$uibModal', 'inventorySvc'];
function controller($scope, $uibModal, inventorySvc) { function controller($scope, $uibModal, inventorySvc) {
var vm = this; var vm = this;
vm.movementData = $scope.movementData; vm.movementData = $scope.movementData;
+10 -7
View File
@@ -1,5 +1,7 @@
(function () { (function() {
window.app.factory('reportSvc', window.app.factory("reportSvc",
[
"$http",
function($http) { function($http) {
var distributionData = []; var distributionData = [];
var distributionQuery = {}; var distributionQuery = {};
@@ -18,7 +20,7 @@
return svc; return svc;
function loadDistributionReport(query) { function loadDistributionReport(query) {
return $http.post('/Report/Distribution', query) return $http.post("/Report/Distribution", query)
.success(function(data) { .success(function(data) {
distributionQuery = angular.copy(query, distributionQuery); distributionQuery = angular.copy(query, distributionQuery);
angular.copy(data, distributionData); angular.copy(data, distributionData);
@@ -26,18 +28,19 @@
} }
function exportDistributionReport(query) { function exportDistributionReport(query) {
return $http.post('/Report/DistributionExcel', query, { responseType: 'arraybuffer' }); return $http.post("/Report/DistributionExcel", query, { responseType: "arraybuffer" });
} }
function loadMovementData(query) { function loadMovementData(query) {
return $http.post('/Report/Movement', query) return $http.post("/Report/Movement", query)
.success(function(data) { .success(function(data) {
angular.copy(data, movementData); angular.copy(data, movementData);
}); });
} }
function exportMovementData(query) { function exportMovementData(query) {
return $http.post('/Report/MovementExcel', query, { responseType: 'arraybuffer' }); return $http.post("/Report/MovementExcel", query, { responseType: "arraybuffer" });
} }
}); }
]);
})(); })();
@@ -1,7 +1,9 @@
(function() { (function() {
'use strict'; "use strict";
window.app.controller('TransactionController', window.app.controller("TransactionController",
[
"$scope", "$uibModal", "transactionSvc", "inventorySvc", "uiGridConstants",
function($scope, $uibModal, transactionSvc, inventorySvc, uiGridConstants) { function($scope, $uibModal, transactionSvc, inventorySvc, uiGridConstants) {
var vm = this; var vm = this;
@@ -20,27 +22,27 @@
enableSorting: false, enableSorting: false,
columnDefs: [ columnDefs: [
{ {
field: 'name', field: "name",
cellTooltip: function(row) { cellTooltip: function(row) {
return row.entity.name + "\r" + row.entity.unitsPerCase + " / " + row.entity.containerType; return row.entity.name + "\r" + row.entity.unitsPerCase + " / " + row.entity.containerType;
}, },
cellTemplate: '<div class="ui-grid-cell-contents" ' + cellTemplate: '<div class="ui-grid-cell-contents" ' +
'title="{{row.entity.name}}' + 'title="{{row.entity.name}}' +
'\r{{row.entity.unitsPerCase}} / {{row.entity.containerType}}' + "\r{{row.entity.unitsPerCase}} / {{row.entity.containerType}}" +
'\rExp Date: {{row.entity.expirationDate | date:\'shortDate\'}}' + "\rExp Date: {{row.entity.expirationDate | date:'shortDate'}}" +
'\rAdd Date: {{row.entity.addedDate | date:\'shortDate\'}}">' + '\rAdd Date: {{row.entity.addedDate | date:\'shortDate\'}}">' +
'<a href="" ng-click="grid.appScope.editInventory(row.entity.inventoryId)"><i class="fa fa-edit"></i></a> ' + '<a href="" ng-click="grid.appScope.editInventory(row.entity.inventoryId)"><i class="fa fa-edit"></i></a> ' +
'{{row.entity.name}}</div>', "{{row.entity.name}}</div>",
width: "20%" width: "20%"
}, },
{ field: 'transactionType', name: 'Type', width: "10%" }, { field: "transactionType", name: "Type", width: "10%" },
{ field: 'destination', cellTooltip: true, width: "10%" }, { field: "destination", cellTooltip: true, width: "10%" },
{ field: 'memo', cellTooltip: true, width: "15%" }, { field: "memo", cellTooltip: true, width: "15%" },
{ field: 'transactionDate', name: 'Transaction Date', cellFilter: "date:'shortDate'", width: "10%" }, { field: "transactionDate", name: "Transaction Date", cellFilter: "date:'shortDate'", width: "10%" },
{ field: 'previousQuantity', name: 'Prev Qty', width: "10%", enableSorting: false }, { field: "previousQuantity", name: "Prev Qty", width: "10%", enableSorting: false },
{ field: 'addedQuantity', name: 'Add Qty', width: "10%", enableSorting: false, cellFilter: "hideZero" }, { field: "addedQuantity", name: "Add Qty", width: "10%", enableSorting: false, cellFilter: "hideZero" },
{ field: 'removedQuantity', name: 'Remove Qty', width: "10%", enableSorting: false, cellFilter: "hideZero" }, { field: "removedQuantity", name: "Remove Qty", width: "10%", enableSorting: false, cellFilter: "hideZero" },
{ field: 'currentQuantity', name: 'Current Qty', width: "10%", enableSorting: false } { field: "currentQuantity", name: "Current Qty", width: "10%", enableSorting: false }
], ],
onRegisterApi: function(gridApi) { onRegisterApi: function(gridApi) {
vm.gridApi = gridApi; vm.gridApi = gridApi;
@@ -76,6 +78,7 @@
updateData(); updateData();
}); });
}); });
} };
}); }
]);
})(); })();
@@ -1,5 +1,6 @@
(function() { (function() {
window.app.factory('transactionSvc', window.app.factory('transactionSvc', [
'$http', 'inventorySvc',
function($http, inventorySvc) { function($http, inventorySvc) {
var svc = { var svc = {
@@ -31,5 +32,5 @@
inventorySvc.refresh(data.inventoryId); inventorySvc.refresh(data.inventoryId);
}); });
} }
}); }]);
})(); })();
+13 -12
View File
@@ -1,7 +1,9 @@
(function() { (function() {
'use strict'; "use strict";
window.app.controller('UserController', window.app.controller("UserController",
[
"$uibModal", "userSvc", "downloadSvc",
function($uibModal, userSvc, downloadSvc) { function($uibModal, userSvc, downloadSvc) {
var vm = this; var vm = this;
@@ -9,21 +11,20 @@
vm.create = function() { vm.create = function() {
$uibModal.open({ $uibModal.open({
template: '<user-create />', template: "<user-create />",
backdrop: 'static' backdrop: "static"
}); });
} };
vm.edit = function() { vm.edit = function() {
$uibModal.open({ $uibModal.open({
template: '<user-edit />', template: "<user-edit />",
backdrop: 'static' backdrop: "static"
}); });
} };
vm.export = function() { vm.export = function() {
userSvc.exportUsers() userSvc.exportUsers()
.success(downloadSvc.success); .success(downloadSvc.success);
} };
}); }
]);
})(); })();
@@ -9,6 +9,7 @@
} }
}); });
controller.$inject = ['$scope', 'userSvc'];
function controller($scope, userSvc){ function controller($scope, userSvc){
var vm = this; var vm = this;
@@ -12,6 +12,7 @@
} }
}); });
controller.$inject = ['$scope', 'userSvc'];
function controller($scope, userSvc) { function controller($scope, userSvc) {
var vm = this; var vm = this;
vm.user = angular.copy($scope.user); vm.user = angular.copy($scope.user);
@@ -19,7 +19,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-success">Create</button> <button class="btn btn-success" ng-disabled="vm.form.$invalid || vm.form.$pristine">Create</button>
<button type="button" class="btn" ng-click="$dismiss()">Cancel</button> <button type="button" class="btn" ng-click="$dismiss()">Cancel</button>
</div> </div>
@@ -19,7 +19,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-success">Save</button> <button class="btn btn-success" ng-disabled="vm.form.$invalid || vm.form.$pristine">Save</button>
<button type="button" class="btn" ng-click="$parent.$dismiss()">Cancel</button> <button type="button" class="btn" ng-click="$parent.$dismiss()">Cancel</button>
</div> </div>
+10 -7
View File
@@ -1,5 +1,7 @@
(function () { (function() {
window.app.factory('userSvc', window.app.factory("userSvc",
[
"$http",
function($http) { function($http) {
var users = []; var users = [];
@@ -15,28 +17,29 @@
return svc; return svc;
function loadUsers() { function loadUsers() {
$http.post('/User/All') $http.post("/User/All")
.success(function(data) { .success(function(data) {
users.addRange(data); users.addRange(data);
}); });
} }
function exportusers() { function exportusers() {
return $http.post('/User/Export', {}, { responseType: 'arraybuffer' }); return $http.post("/User/Export", {}, { responseType: "arraybuffer" });
} }
function create(user) { function create(user) {
return $http.post('/User/Create', user) return $http.post("/User/Create", user)
.success(function(user) { .success(function(user) {
users.unshift(user); users.unshift(user);
}); });
} }
function edit(existingUser, editedUser) { function edit(existingUser, editedUser) {
return $http.post('/User/Edit', editedUser) return $http.post("/User/Edit", editedUser)
.success(function(user) { .success(function(user) {
angular.copy(user, existingUser); angular.copy(user, existingUser);
}); });
} }
}); }
]);
})(); })();
@@ -13,6 +13,7 @@
} }
} }
controller.$inject = ['$scope'];
function controller($scope) { function controller($scope) {
var vm = this; var vm = this;
vm.query = {}; vm.query = {};
@@ -1,15 +1,17 @@
(function () { (function() {
window.app.factory('downloadSvc', window.app.factory("downloadSvc",
function($http) { [
function() {
var svc = { var svc = {
success: function(data, status, headers, config) { success: function(data, status, headers, config) {
var file = new Blob([data], { type: headers('Content-Type') }); var file = new Blob([data], { type: headers("Content-Type") });
var match = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(headers('Content-Disposition')); var match = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(headers("Content-Disposition"));
saveAs(file, match[1]); saveAs(file, match[1]);
} }
}; };
return svc; return svc;
}); }
]);
})(); })();
@@ -14,6 +14,7 @@
} }
}); });
controller.$inject = ['$scope'];
function controller($scope) { function controller($scope) {
var vm = this; var vm = this;
vm.errors = $scope.errors; vm.errors = $scope.errors;
@@ -23,6 +23,7 @@
} }
}); });
controller.$inject = ['$scope'];
function controller($scope) { function controller($scope) {
var vm = this; var vm = this;
@@ -1,11 +1,13 @@
(function() { (function() {
window.app.filter('formatCases', window.app.filter("formatCases",
[
function() { function() {
return function(qty) { return function(qty) {
if (qty === '' || !isFinite(qty)) if (qty === "" || !isFinite(qty))
return ''; return "";
return '(' + qty + ' cs)'; return "(" + qty + " cs)";
} };
}); }
]);
})(); })();
@@ -1,9 +1,11 @@
(function () { (function() {
window.app.filter('hideZero', window.app.filter("hideZero",
[
function() { function() {
return function(input) { return function(input) {
return input > 0 ? input : ""; return input > 0 ? input : "";
} };
}); }
]);
})(); })();
@@ -21,6 +21,7 @@
} }
}); });
controller.$inject = ['$scope'];
function controller($scope) { function controller($scope) {
var vm = this; var vm = this;
@@ -13,6 +13,7 @@
} }
}); });
controller.$inject = ['$scope'];
function controller($scope) { function controller($scope) {
var vm = this; var vm = this;
vm.query = {}; vm.query = {};
@@ -1,10 +1,12 @@
(function() { (function() {
window.app.filter("parseDate", window.app.filter("parseDate",
[
function() { function() {
return function(input) { 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))); return new Date(parseInt(input.substr(6)));
} };
}); }
]);
})(); })();
@@ -14,6 +14,7 @@
} }
}); });
controller.$inject = ['$scope'];
function controller($scope) { function controller($scope) {
} }
})(); })();
+5 -3
View File
@@ -1,12 +1,14 @@
(function() { (function() {
window.app.filter('toUnits', window.app.filter("toUnits",
[
function() { function() {
return function(caseQty, unitsPerCase) { return function(caseQty, unitsPerCase) {
if (caseQty === "" || !isFinite(caseQty) || !isFinite(unitsPerCase)) if (caseQty === "" || !isFinite(caseQty) || !isFinite(unitsPerCase))
return ""; return "";
return caseQty * unitsPerCase; return caseQty * unitsPerCase;
} };
}); }
]);
})(); })();