Update: Plugin UI Extensions

Add additional Results; Implemented UI Extensions on Device, Job and
User Controllers
This commit is contained in:
Gary Sharp
2013-02-28 17:13:15 +11:00
parent 15e2c2a501
commit 989f08a24d
43 changed files with 1108 additions and 705 deletions
+124 -114
View File
@@ -1,114 +1,124 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Disco.BI;
using Disco.BI.Extensions;
using Disco.Data.Repository;
using Disco.Models.Repository;
using System.Data.Objects.SqlClient;
using Disco.Web.Extensions;
namespace Disco.Web.Controllers
{
public partial class DeviceController : dbAdminController
{
#region Index
public virtual ActionResult Index()
{
return View();
}
#endregion
#region Add Offline
public virtual ActionResult AddOffline()
{
var m = new Models.Device.AddOfflineModel()
{
DefaultDeviceProfileId = dbContext.DiscoConfiguration.DeviceProfiles.DefaultAddDeviceOfflineDeviceProfileId
};
m.DeviceBatches = dbContext.DeviceBatches.ToSelectListItems();
m.DeviceProfiles = dbContext.DeviceProfiles.ToList();
if (m.DefaultDeviceProfileId == 0)
{
m.DeviceProfiles.Insert(0, new DeviceProfile() { Id = 0, Name = "Select a Device Profile" });
}
return View(m);
}
[HttpPost]
public virtual ActionResult AddOffline(Models.Device.AddOfflineModel m)
{
// Trim Serial Number & Error Check
m.Device.SerialNumber = m.Device.SerialNumber.Trim();
if (string.IsNullOrEmpty(m.Device.SerialNumber))
{
ModelState.AddModelError("Device.SerialNumber", "The Serial Number is Required");
}
else
{
// Ensure Existing Device Doesn't Exist
if (!string.IsNullOrEmpty(m.Device.SerialNumber) && dbContext.Devices.Count(d => d.SerialNumber == m.Device.SerialNumber) > 0)
ModelState.AddModelError("Device.SerialNumber", "A Device what this Serial Number already exists");
}
if (ModelState.IsValid)
{
var d = m.Device.AddOffline(dbContext);
dbContext.SaveChanges();
return RedirectToAction(MVC.Device.Show(d.SerialNumber));
}
return AddOffline();
}
#endregion
#region Show
public virtual ActionResult Show(string id)
{
var m = new Models.Device.ShowModel();
dbContext.Configuration.LazyLoadingEnabled = true;
m.Device = dbContext.Devices
.Where(d => d.SerialNumber == id)
.FirstOrDefault();
if (m.Device == null)
throw new ArgumentException(string.Format("Unknown Device: [{0}]", id), "id");
// Removed 2012-07-03 G#
// Deferred to Ajax call - improve load performance
// Update Device LastNetworkLogonDate
//if (m.Device.UpdateLastNetworkLogonDate())
// dbContext.SaveChanges();
// No Necessary - Yet...
//if (!string.IsNullOrWhiteSpace(m.Device.ComputerName))
//{
// var adMachineAccount = BI.Interop.ActiveDirectory.ActiveDirectory.GetMachineAccount(m.Device.ComputerName);
// if (adMachineAccount != null)
// {
// m.OrganisationUnit = adMachineAccount.ParentDistinguishedName;
// }
//}
m.DeviceProfiles = dbContext.DeviceProfiles.ToList();
m.DeviceBatches = dbContext.DeviceBatches.ToSelectListItems(m.Device.DeviceBatchId);
m.Jobs = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true, ShowDevice = false, IsSmallTable = true, HideClosedJobs = true };
m.Jobs.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.DeviceSerialNumber == m.Device.SerialNumber));
m.Certificates = dbContext.DeviceCertificates.Where(c => c.DeviceSerialNumber == m.Device.SerialNumber).ToList();
//m.AttachmentTypes = dbContext.AttachmentTypes.Where(at => at.Scope == AttachmentType.AttachmentTypeScopes.Device).ToList();
m.DocumentTemplates = m.Device.AvailableDocumentTemplates(dbContext, DiscoApplication.CurrentUser, DateTime.Now);
return View(m);
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Disco.BI;
using Disco.BI.Extensions;
using Disco.Data.Repository;
using Disco.Models.Repository;
using System.Data.Objects.SqlClient;
using Disco.Web.Extensions;
using Disco.Services.Plugins.Features.UIExtension;
using Disco.Models.UI.Device;
namespace Disco.Web.Controllers
{
public partial class DeviceController : dbAdminController
{
#region Index
public virtual ActionResult Index()
{
Models.Device.IndexModel m = new Models.Device.IndexModel();
// UI Extensions
UIExtensions.ExecuteExtensions<DeviceIndexModel>(this.ControllerContext, m);
return View();
}
#endregion
#region Add Offline
public virtual ActionResult AddOffline()
{
var m = new Models.Device.AddOfflineModel()
{
DefaultDeviceProfileId = dbContext.DiscoConfiguration.DeviceProfiles.DefaultAddDeviceOfflineDeviceProfileId
};
m.DeviceBatches = dbContext.DeviceBatches.ToSelectListItems();
m.DeviceProfiles = dbContext.DeviceProfiles.ToList();
if (m.DefaultDeviceProfileId == 0)
{
m.DeviceProfiles.Insert(0, new DeviceProfile() { Id = 0, Name = "Select a Device Profile" });
}
return View(m);
}
[HttpPost]
public virtual ActionResult AddOffline(Models.Device.AddOfflineModel m)
{
// Trim Serial Number & Error Check
m.Device.SerialNumber = m.Device.SerialNumber.Trim();
if (string.IsNullOrEmpty(m.Device.SerialNumber))
{
ModelState.AddModelError("Device.SerialNumber", "The Serial Number is Required");
}
else
{
// Ensure Existing Device Doesn't Exist
if (!string.IsNullOrEmpty(m.Device.SerialNumber) && dbContext.Devices.Count(d => d.SerialNumber == m.Device.SerialNumber) > 0)
ModelState.AddModelError("Device.SerialNumber", "A Device what this Serial Number already exists");
}
if (ModelState.IsValid)
{
var d = m.Device.AddOffline(dbContext);
dbContext.SaveChanges();
return RedirectToAction(MVC.Device.Show(d.SerialNumber));
}
return AddOffline();
}
#endregion
#region Show
public virtual ActionResult Show(string id)
{
var m = new Models.Device.ShowModel();
dbContext.Configuration.LazyLoadingEnabled = true;
m.Device = dbContext.Devices
.Where(d => d.SerialNumber == id)
.FirstOrDefault();
if (m.Device == null)
throw new ArgumentException(string.Format("Unknown Device: [{0}]", id), "id");
// Removed 2012-07-03 G#
// Deferred to Ajax call - improve load performance
// Update Device LastNetworkLogonDate
//if (m.Device.UpdateLastNetworkLogonDate())
// dbContext.SaveChanges();
// No Necessary - Yet...
//if (!string.IsNullOrWhiteSpace(m.Device.ComputerName))
//{
// var adMachineAccount = BI.Interop.ActiveDirectory.ActiveDirectory.GetMachineAccount(m.Device.ComputerName);
// if (adMachineAccount != null)
// {
// m.OrganisationUnit = adMachineAccount.ParentDistinguishedName;
// }
//}
m.DeviceProfiles = dbContext.DeviceProfiles.ToList();
m.DeviceBatches = dbContext.DeviceBatches.ToList();
m.Jobs = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true, ShowDevice = false, IsSmallTable = true, HideClosedJobs = true };
m.Jobs.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.DeviceSerialNumber == m.Device.SerialNumber));
m.Certificates = dbContext.DeviceCertificates.Where(c => c.DeviceSerialNumber == m.Device.SerialNumber).ToList();
//m.AttachmentTypes = dbContext.AttachmentTypes.Where(at => at.Scope == AttachmentType.AttachmentTypeScopes.Device).ToList();
m.DocumentTemplates = m.Device.AvailableDocumentTemplates(dbContext, DiscoApplication.CurrentUser, DateTime.Now);
// UI Extensions
UIExtensions.ExecuteExtensions<DeviceShowModel>(this.ControllerContext, m);
return View(m);
}
#endregion
}
}
+54 -1
View File
@@ -10,8 +10,8 @@ using Disco.Models.Repository;
using System.Web.Script.Serialization;
using Disco.Services.Plugins.Features.WarrantyProvider;
using Disco.Services.Plugins;
using Disco.Services.UIExtensions;
using Disco.Models.UI.Job;
using Disco.Services.Plugins.Features.UIExtension;
namespace Disco.Web.Controllers
{
@@ -64,6 +64,10 @@ namespace Disco.Web.Controllers
// closedThreshold = closedThreshold.AddDays(-1);
//m.RecentlyClosedJobs = new Disco.Models.BI.Job.JobTableModel();
//m.RecentlyClosedJobs.Fill(BI.JobTableModelBI.BuildQuery(dbContext).Where(j => j.ClosedDate > closedThreshold));
// UI Extensions
UIExtensions.ExecuteExtensions<JobIndexModel>(this.ControllerContext, m);
return View(m);
}
#endregion
@@ -75,6 +79,10 @@ namespace Disco.Web.Controllers
var m = new Models.Job.ListModel() { Title = "All Open Jobs" };
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null).OrderBy(j => j.Id));
// UI Extensions
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
return View(Views.List, m);
}
public virtual ActionResult DevicesReadyForReturn()
@@ -86,6 +94,10 @@ namespace Disco.Web.Controllers
&& j.DeviceHeld != null && j.DeviceReturnedDate == null && j.DeviceReadyForReturn != null &&
((!j.JobMetaNonWarranty.AccountingChargeRequiredDate.HasValue && !j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue) || j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue)
&& j.ClosedDate == null).OrderBy(j => j.Id));
// UI Extensions
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
return View(Views.List, m);
}
public virtual ActionResult DevicesAwaitingRepair()
@@ -98,6 +110,10 @@ namespace Disco.Web.Controllers
(j.JobMetaNonWarranty.RepairerLoggedDate != null && j.JobMetaNonWarranty.RepairerCompletedDate == null) ||
(j.JobMetaWarranty.ExternalLoggedDate != null && j.JobMetaWarranty.ExternalCompletedDate == null)
)).OrderBy(j => j.Id));
// UI Extensions
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
return View(Views.List, m);
}
@@ -114,6 +130,10 @@ namespace Disco.Web.Controllers
(j.JobTypeId == JobType.JobTypeIds.HNWar && (!j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue || !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue)) ||
(j.JobTypeId == JobType.JobTypeIds.UMgmt && (long)Job.UserManagementFlags.Infringement_BreachFinancialAgreement == (j.Flags & (long)Job.UserManagementFlags.Infringement_BreachFinancialAgreement))
)));
// UI Extensions
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
return View(Views.List, m);
}
@@ -126,6 +146,9 @@ namespace Disco.Web.Controllers
(j.JobTypeId == JobType.JobTypeIds.HNWar && (j.JobMetaNonWarranty.AccountingChargeRequiredDate.HasValue && (!j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue && !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue)))
).OrderBy(j => j.Id));
// UI Extensions
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
return View(Views.List, m);
}
public virtual ActionResult AwaitingFinancePayment()
@@ -136,6 +159,10 @@ namespace Disco.Web.Controllers
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
(j.JobTypeId == JobType.JobTypeIds.HNWar && (!j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue || !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue))
).OrderBy(j => j.Id));
// UI Extensions
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
return View(Views.List, m);
}
public virtual ActionResult AwaitingFinanceInsuranceProcessing()
@@ -146,6 +173,10 @@ namespace Disco.Web.Controllers
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
(j.JobTypeId == JobType.JobTypeIds.HNWar && (j.JobMetaNonWarranty.IsInsuranceClaim && !j.JobMetaInsurance.ClaimFormSentDate.HasValue))
).OrderBy(j => j.Id));
// UI Extensions
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
return View(Views.List, m);
}
public virtual ActionResult AwaitingFinanceAgreementBreach()
@@ -156,6 +187,10 @@ namespace Disco.Web.Controllers
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
(j.JobTypeId == JobType.JobTypeIds.UMgmt && (long)Job.UserManagementFlags.Infringement_BreachFinancialAgreement == (j.Flags & (long)Job.UserManagementFlags.Infringement_BreachFinancialAgreement))
).OrderBy(j => j.Id));
// UI Extensions
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
return View(Views.List, m);
}
@@ -168,6 +203,10 @@ namespace Disco.Web.Controllers
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => (j.WaitingForUserAction.HasValue || (j.JobMetaNonWarranty.AccountingChargeAddedDate != null && j.JobMetaNonWarranty.AccountingChargePaidDate == null))
&& j.ClosedDate == null).OrderBy(j => j.Id));
// UI Extensions
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
return View(Views.List, m);
}
public virtual ActionResult RecentlyClosed()
@@ -183,6 +222,10 @@ namespace Disco.Web.Controllers
if (dateTimeNow.DayOfWeek == DayOfWeek.Tuesday)
closedThreshold = closedThreshold.AddDays(-1);
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate > closedThreshold).OrderBy(j => j.Id));
// UI Extensions
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
return View(Views.List, m);
}
public virtual ActionResult Locations()
@@ -191,6 +234,10 @@ namespace Disco.Web.Controllers
var m = new Models.Job.ListModel() { Title = "Held Device Locations" };
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true, ShowLocation = true, ShowTechnician = false, ShowType = false };
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null && j.DeviceHeld.HasValue && !j.DeviceReturnedDate.HasValue).OrderBy(j => j.DeviceHeldLocation));
// UI Extensions
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
return View(Views.List, m);
}
@@ -232,6 +279,9 @@ namespace Disco.Web.Controllers
};
m.UpdateModel(dbContext);
// UI Extensions
UIExtensions.ExecuteExtensions<JobCreateModel>(this.ControllerContext, m);
return View(m);
}
[HttpPost]
@@ -241,6 +291,9 @@ namespace Disco.Web.Controllers
if (!ModelState.IsValid)
{
// UI Extensions
UIExtensions.ExecuteExtensions<JobCreateModel>(this.ControllerContext, m);
return View(m);
}
else
+61 -51
View File
@@ -1,51 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Disco.Models.Repository;
using Disco.BI.Extensions;
namespace Disco.Web.Controllers
{
public partial class UserController : dbAdminController
{
#region Index
public virtual ActionResult Index()
{
return View();
}
#endregion
#region Show
public virtual ActionResult Show(string id)
{
var m = new Models.User.ShowModel();
dbContext.Configuration.LazyLoadingEnabled = true;
// Update User Cache
// Do this first so the Database is updated if necessary
try
{
Disco.BI.UserBI.UserCache.GetUser(id, dbContext, true);
}
catch (ArgumentException)
{
// Ignore if User not in Active Directory anymore
}
m.User = dbContext.Users.Where(um => um.Id == id).FirstOrDefault();
m.Jobs = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true, ShowDevice = true, ShowUser = false, IsSmallTable = true, HideClosedJobs = true };
m.Jobs.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.UserId == id));
m.DocumentTemplates = m.User.AvailableDocumentTemplates(dbContext, DiscoApplication.CurrentUser, DateTime.Now);
return View(m);
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Disco.Models.Repository;
using Disco.BI.Extensions;
using Disco.Services.Plugins.Features.UIExtension;
using Disco.Models.UI.User;
namespace Disco.Web.Controllers
{
public partial class UserController : dbAdminController
{
#region Index
public virtual ActionResult Index()
{
var m = new Models.User.IndexModel();
// UI Extensions
UIExtensions.ExecuteExtensions<UserIndexModel>(this.ControllerContext, m);
return View();
}
#endregion
#region Show
public virtual ActionResult Show(string id)
{
var m = new Models.User.ShowModel();
dbContext.Configuration.LazyLoadingEnabled = true;
// Update User Cache
// Do this first so the Database is updated if necessary
try
{
Disco.BI.UserBI.UserCache.GetUser(id, dbContext, true);
}
catch (ArgumentException)
{
// Ignore if User not in Active Directory anymore
}
m.User = dbContext.Users.Where(um => um.Id == id).FirstOrDefault();
m.Jobs = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true, ShowDevice = true, ShowUser = false, IsSmallTable = true, HideClosedJobs = true };
m.Jobs.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.UserId == id));
m.DocumentTemplates = m.User.AvailableDocumentTemplates(dbContext, DiscoApplication.CurrentUser, DateTime.Now);
// UI Extensions
UIExtensions.ExecuteExtensions<UserShowModel>(this.ControllerContext, m);
return View(m);
}
#endregion
}
}