From 016f03166450a8376d0fa9d9c4449234ee501936 Mon Sep 17 00:00:00 2001 From: James Kolpack Date: Mon, 29 Aug 2016 14:43:26 -0400 Subject: [PATCH] Add transaction list --- .../Models/InventoryAddForm.cs | 1 - InventoryTraker.Web/App_Start/SeedData.cs | 5 +- .../Controllers/TransactionController.cs | 14 ++++ InventoryTraker.Web/Helpers/GridTag.cs | 8 +- .../InventoryTraker.Web.csproj | 1 + .../Models/TransactionViewModel.cs | 6 ++ .../Views/Transaction/Index.cshtml | 15 +--- InventoryTraker.Web/css/layout.css | 4 + InventoryTraker.Web/js/app.js | 2 +- .../js/transaction/TransactionController.js | 79 +++++++++++++++++++ .../js/transaction/transactionSvc.js | 15 ++-- 11 files changed, 124 insertions(+), 26 deletions(-) create mode 100644 InventoryTraker.Web/js/transaction/TransactionController.js diff --git a/InventoryTraker.Web.Tests/Models/InventoryAddForm.cs b/InventoryTraker.Web.Tests/Models/InventoryAddForm.cs index 05a4beb..14da51a 100644 --- a/InventoryTraker.Web.Tests/Models/InventoryAddForm.cs +++ b/InventoryTraker.Web.Tests/Models/InventoryAddForm.cs @@ -1,7 +1,6 @@ using System; using AutoMapper; using Heroic.AutoMapper; -using InventoryTraker.Web.Controllers; using InventoryTraker.Web.Core; using InventoryTraker.Web.Models; using NUnit.Framework; diff --git a/InventoryTraker.Web/App_Start/SeedData.cs b/InventoryTraker.Web/App_Start/SeedData.cs index bd23c3f..a0ad325 100644 --- a/InventoryTraker.Web/App_Start/SeedData.cs +++ b/InventoryTraker.Web/App_Start/SeedData.cs @@ -75,6 +75,7 @@ namespace InventoryTraker.Web { var r = new Random(1); var inventoryTypes = context.InventoryTypes.ToList(); + var cityNames = new List {"Maryville", "Wartburg", "Clinton", "Oak Ridge", "Alcoa", "Jellico"}; for (int i = 0; i < 100; i++) { @@ -109,12 +110,14 @@ namespace InventoryTraker.Web if (quantityRemoved > previousTransaction.CurrentQuantity) quantityRemoved = previousTransaction.CurrentQuantity; + var destCity = cityNames.ElementAt(r.Next(0, cityNames.Count)); + var transaction = new Transaction { RemovedQuantity = quantityRemoved, CurrentQuantity = previousTransaction.CurrentQuantity - quantityRemoved, Inventory = inventory, - Memo = "Distributed", + Memo = $"Distributed to {destCity}", TransactionDate = transactionDate, Timestamp = transactionDate }; diff --git a/InventoryTraker.Web/Controllers/TransactionController.cs b/InventoryTraker.Web/Controllers/TransactionController.cs index fb08545..2f13e53 100644 --- a/InventoryTraker.Web/Controllers/TransactionController.cs +++ b/InventoryTraker.Web/Controllers/TransactionController.cs @@ -34,5 +34,19 @@ namespace InventoryTraker.Web.Controllers return BetterJson(viewModels); } + + public JsonResult GetTransactions(int pageNumber, int pageSize) + { + var viewModels = + _context.Transactions + .OrderByDescending(t => t.Timestamp) + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ProjectTo() + .ToArray(); + + var count = _context.Transactions.Count(); + return BetterJson(new {totalItems = count, transactions = viewModels}); + } } } \ No newline at end of file diff --git a/InventoryTraker.Web/Helpers/GridTag.cs b/InventoryTraker.Web/Helpers/GridTag.cs index 13db44b..7b4c7da 100644 --- a/InventoryTraker.Web/Helpers/GridTag.cs +++ b/InventoryTraker.Web/Helpers/GridTag.cs @@ -21,13 +21,15 @@ namespace InventoryTraker.Web.Helpers public void Add(Expression> property, string columnHeader = null, - string cellFilter = null) + string cellFilter = null, + bool cellToolTipContents = false) { _tag._columns.Add(new ColumnDefinition { Field = property.ToCamelCaseName(), Name = columnHeader, - CellFilter = cellFilter + CellFilter = cellFilter, + CellToolTip = cellToolTipContents }); } } @@ -39,6 +41,8 @@ namespace InventoryTraker.Web.Helpers public string Name { get; set; } public string CellFilter { get; set; } + + public bool CellToolTip { get; set; } } private readonly List _columns = new List(); diff --git a/InventoryTraker.Web/InventoryTraker.Web.csproj b/InventoryTraker.Web/InventoryTraker.Web.csproj index 1c0b473..87b6f49 100644 --- a/InventoryTraker.Web/InventoryTraker.Web.csproj +++ b/InventoryTraker.Web/InventoryTraker.Web.csproj @@ -232,6 +232,7 @@ + diff --git a/InventoryTraker.Web/Models/TransactionViewModel.cs b/InventoryTraker.Web/Models/TransactionViewModel.cs index f2760f7..500f134 100644 --- a/InventoryTraker.Web/Models/TransactionViewModel.cs +++ b/InventoryTraker.Web/Models/TransactionViewModel.cs @@ -14,6 +14,8 @@ namespace InventoryTraker.Web.Models public string Name { get; set; } public int UnitsPerCase { get; set; } public string ContainerType { get; set; } + public DateTime ExpirationDate { get; set; } + public DateTime AddedDate { get; set; } [Required] public int AddedQuantity { get; set; } @@ -37,6 +39,10 @@ namespace InventoryTraker.Web.Models configuration.CreateMap() .ForMember(d => d.Name, opt => opt.MapFrom(s => s.Inventory.InventoryType.Name)) + .ForMember(d => d.ExpirationDate, + opt => opt.MapFrom(s => s.Inventory.ExpirationDate)) + .ForMember(d => d.AddedDate, + opt => opt.MapFrom(s => s.Inventory.AddedDate)) .ForMember(d => d.UnitsPerCase, opt => opt.MapFrom(s => s.Inventory.InventoryType.UnitsPerCase)) .ForMember(d => d.ContainerType, diff --git a/InventoryTraker.Web/Views/Transaction/Index.cshtml b/InventoryTraker.Web/Views/Transaction/Index.cshtml index fef592c..4b8537b 100644 --- a/InventoryTraker.Web/Views/Transaction/Index.cshtml +++ b/InventoryTraker.Web/Views/Transaction/Index.cshtml @@ -6,7 +6,7 @@ ViewBag.Title = "Inventory"; } -
+

Transactions

@@ -15,15 +15,6 @@ Distribute*@
- @(Html.Angular().GridFor(c => c.All()) - .Title("Transactions") - .Columns(config => - { - config.Add(x => x.Name); - config.Add(x => x.Memo); - config.Add(x => x.TransactionDate, "Transaction Date", "date: 'MM/dd/yyyy'"); - config.Add(x => x.AddedQuantity, "Add Qty"); - config.Add(x => x.RemovedQuantity, "Remove Qty"); - config.Add(x => x.CurrentQuantity); - })) +
+
\ No newline at end of file diff --git a/InventoryTraker.Web/css/layout.css b/InventoryTraker.Web/css/layout.css index abd50c2..f027360 100644 --- a/InventoryTraker.Web/css/layout.css +++ b/InventoryTraker.Web/css/layout.css @@ -97,6 +97,10 @@ textarea { border-radius: 50%; } +.grid-fullpage { + height: 70vh; +} + /*.has-feedback ng-transclude ~ input-validation-icons .form-control-feedback { top: 26px; }*/ \ No newline at end of file diff --git a/InventoryTraker.Web/js/app.js b/InventoryTraker.Web/js/app.js index aa30ed9..8bfad5f 100644 --- a/InventoryTraker.Web/js/app.js +++ b/InventoryTraker.Web/js/app.js @@ -1,5 +1,5 @@ (function() { 'use strict'; - window.app = angular.module('InventoryTraker', ['ngAnimate', 'ui.bootstrap', 'ui.grid', 'mgcrea.ngStrap']); + window.app = angular.module('InventoryTraker', ['ngAnimate', 'ui.bootstrap', 'ui.grid', 'ui.grid.pagination', 'mgcrea.ngStrap']); })(); \ No newline at end of file diff --git a/InventoryTraker.Web/js/transaction/TransactionController.js b/InventoryTraker.Web/js/transaction/TransactionController.js new file mode 100644 index 0000000..69c4bc7 --- /dev/null +++ b/InventoryTraker.Web/js/transaction/TransactionController.js @@ -0,0 +1,79 @@ +(function() { + 'use strict'; + + window.app.controller('TransactionController', TransactionController); + + TransactionController.$inject = ['$scope', '$uibModal', 'transactionSvc', 'uiGridConstants']; + function TransactionController($scope, $uibModal, transactionSvc, uiGridConstants) { + var vm = this; + + var paginationOptions = { + pageNumber: 1, + pageSize: 20, + sort: null + }; + + vm.gridOptions = { + enablePaginationControls: true, + paginationPageSize: paginationOptions.pageSize, + paginationPageSizes: [20,50,100], + useExternalPagination: true, + enableSorting: false, + columnDefs: [ + { + field: 'name', + cellTooltip: function(row) { + return row.entity.name + "\r" + row.entity.unitsPerCase + " / " + row.entity.containerType; + }, + cellTemplate: '' + }, + { field: 'memo', cellTooltip: true }, + { field: 'transactionDate', name: 'Transaction Date', cellFilter: "date:MM/dd/yyyy", width: "15%" }, + { field: 'addedQuantity', name: 'Add Qty', width: "10%", enableSorting: false }, + { field: 'removedQuantity', name: 'Remove Qty', width: "10%", enableSorting: false }, + { field: 'currentQuantity', name: 'Current Qty', width: "15%", enableSorting: false } + ], + onRegisterApi: function(gridApi) { + vm.gridApi = gridApi; + //vm.gridApi.core.on.sortChanged($scope, + // function(grid, sortColumns) { + // if (sortColumns.length == 0) { + // paginationOptions.sort = null; + // } else { + // paginationOptions.sort = sortColumns[0].sort.direction; + // } + // getPage(); + // }); + vm.gridApi.pagination.on.paginationChanged($scope, + function(newPage, pageSize) { + paginationOptions.pageNumber = newPage; + paginationOptions.pageSize = pageSize; + updateData(); + }); + } + }; + + var updateData = function () { + transactionSvc + .getTransactions(paginationOptions.pageNumber, paginationOptions.pageSize) + .then(function(data) { + vm.gridOptions.totalItems = data.totalItems; + vm.gridOptions.data = data.transactions; + }); + }; + + updateData(); + + function del() { + $uibModal.open({ + template: '', + backdrop: 'static' + }); + } + } +})(); \ No newline at end of file diff --git a/InventoryTraker.Web/js/transaction/transactionSvc.js b/InventoryTraker.Web/js/transaction/transactionSvc.js index 7e5dfca..d0f63f0 100644 --- a/InventoryTraker.Web/js/transaction/transactionSvc.js +++ b/InventoryTraker.Web/js/transaction/transactionSvc.js @@ -3,23 +3,20 @@ transactionSvc.$inject = ['$http']; function transactionSvc($http) { - var transactions = []; - - loadTransactions(); var svc = { - add: add, update: update, - transactions: transactions, + getTransactions: getTransactions, getTransaction: getTransaction }; return svc; - function loadTransactions() { - $http.post('/Transaction/All') - .success(function(data) { - angular.copy(data, transactions); + function getTransactions(pageNumber, pageSize) { + var url = '/Transaction/GetTransactions'; + return $http.post(url, {pageNumber: pageNumber, pageSize: pageSize}) + .then(function(data) { + return data.data; }); }