Skip to content

Commit

Permalink
Update: Device Count Details
Browse files Browse the repository at this point in the history
More information about device membership in Batches, Profiles and
Models.
  • Loading branch information
garysharp committed Jul 25, 2013
1 parent ad6b1b1 commit 1950336
Show file tree
Hide file tree
Showing 27 changed files with 852 additions and 451 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public interface ConfigDeviceBatchShowModel : BaseUIModel
{
Disco.Models.Repository.DeviceBatch DeviceBatch { get; set; }
List<Disco.Models.Repository.DeviceModel> DeviceModels { get; set; }

List<ConfigDeviceBatchShowModelMembership> DeviceModelMembers { get; set; }

int DeviceCount { get; set; }
int DeviceDecommissionedCount { get; set; }
bool CanDelete { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Disco.Models.UI.Config.DeviceBatch
{
public interface ConfigDeviceBatchShowModelMembership : BaseUIModel
{
Disco.Models.Repository.DeviceModel DeviceModel { get; set; }
int DeviceCount { get; set; }
int DeviceDecommissionedCount { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public interface ConfigDeviceModelIndexModelItem
string Model { get; set; }
string ModelType { get; set; }
int DeviceCount { get; set; }
int DeviceDecommissionedCount { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public interface ConfigDeviceModelShowModel : BaseUIModel

ConfigDeviceModelComponentsModel DeviceComponentsModel { get; set; }

int DeviceCount { get; set; }
int DeviceDecommissionedCount { get; set; }

bool CanDelete { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public interface ConfigDeviceProfileShowModel : BaseUIModel
Disco.Models.Repository.DeviceProfile DeviceProfile { get; set; }
List<Disco.Models.BI.Config.OrganisationAddress> OrganisationAddresses { get; set; }

int DeviceCount { get; set; }
int DeviceDecommissionedCount { get; set; }

bool CanDelete { get; set; }
}
}
29 changes: 18 additions & 11 deletions Disco.Web/Areas/Config/Controllers/DeviceBatchController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,25 @@ public virtual ActionResult Index(int? id)

if (id.HasValue)
{
var m = new Models.DeviceBatch.ShowModel()
var m = dbContext.DeviceBatches.Where(db => db.Id == id.Value)
.Select(db => new Models.DeviceBatch.ShowModel()
{
DeviceBatch = db,
DeviceCount = db.Devices.Count(),
DeviceDecommissionedCount = db.Devices.Count(d => d.DecommissionedDate.HasValue)
}).FirstOrDefault();

if (m == null || m.DeviceBatch == null)
throw new ArgumentException("Invalid Device Batch Id", "id");

m.DeviceModelMembers = m.DeviceBatch.Devices.GroupBy(d => d.DeviceModel).Select(dG => new Models.DeviceBatch._ShowModelMembership()
{
DeviceBatch = dbContext.DeviceBatches.Find(id)
};
if (m.DeviceBatch == null)
{
return RedirectToAction(MVC.Config.DeviceBatch.Index(null));
}
m.CanDelete = m.DeviceBatch.CanDelete(dbContext);
DeviceModel = dG.Key,
DeviceCount = dG.Count(),
DeviceDecommissionedCount = dG.Count(d => d.DecommissionedDate.HasValue)
}).ToArray().Cast<ConfigDeviceBatchShowModelMembership>().ToList();

m.DeviceCount = m.DeviceBatch.Devices.Count();
m.DeviceDecommissionedCount = m.DeviceBatch.Devices.Count(d => d.DecommissionedDate.HasValue);
m.CanDelete = m.DeviceBatch.CanDelete(dbContext);

m.DeviceModels = dbContext.DeviceModels.ToList();

Expand All @@ -46,7 +53,7 @@ public virtual ActionResult Index(int? id)

// UI Extensions
UIExtensions.ExecuteExtensions<ConfigDeviceBatchIndexModel>(this.ControllerContext, m);

return View(m);
}
}
Expand Down
16 changes: 11 additions & 5 deletions Disco.Web/Areas/Config/Controllers/DeviceModelController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ public virtual ActionResult Index(int? id)
{
if (id.HasValue)
{
var m = new Models.DeviceModel.ShowModel()
var m = dbContext.DeviceModels.Include("DeviceComponents").Where(dm => dm.Id == id.Value).Select(dm => new Models.DeviceModel.ShowModel()
{
DeviceModel = dbContext.DeviceModels.Include("DeviceComponents.JobSubTypes").Where(dm => dm.Id == id.Value).FirstOrDefault(),
WarrantyProviders = Plugins.GetPluginFeatures(typeof(WarrantyProviderFeature))
};
DeviceModel = dm,
DeviceCount = dm.Devices.Count(),
DeviceDecommissionedCount = dm.Devices.Where(d => d.DecommissionedDate.HasValue).Count()
}).FirstOrDefault();

if (m == null || m.DeviceModel == null)
throw new ArgumentException("Invalid Device Model Id", "id");

m.WarrantyProviders = Plugins.GetPluginFeatures(typeof(WarrantyProviderFeature));

m.DeviceComponentsModel = new Models.DeviceModel.ComponentsModel()
{
DeviceModelId = m.DeviceModel.Id,
DeviceComponents = m.DeviceModel.DeviceComponents.ToList(),
DeviceComponents = dbContext.DeviceComponents.Include("JobSubTypes").Where(dc => dc.DeviceModelId == m.DeviceModel.Id).ToList(),
JobSubTypes = dbContext.JobSubTypes.Where(jst => jst.JobTypeId == Disco.Models.Repository.JobType.JobTypeIds.HNWar).ToList()
};

Expand Down
16 changes: 10 additions & 6 deletions Disco.Web/Areas/Config/Controllers/DeviceProfileController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ public virtual ActionResult Index(int? id)
{
if (id.HasValue)
{
var m = new Models.DeviceProfile.ShowModel()
var m = dbContext.DeviceProfiles.Where(dp => dp.Id == id.Value).Select(dp => new Models.DeviceProfile.ShowModel()
{
DeviceProfile = dbContext.DeviceProfiles.Find(id.Value),
OrganisationAddresses = dbContext.DiscoConfiguration.OrganisationAddresses.Addresses,
CertificateProviders = Plugins.GetPluginFeatures(typeof(CertificateProviderFeature))
};
DeviceProfile = dp,
DeviceCount = dp.Devices.Count(),
DeviceDecommissionedCount = dp.Devices.Where(d => d.DecommissionedDate.HasValue).Count()
}).FirstOrDefault();

//m.Devices = BI.DeviceBI.SelectDeviceSearchResultItem(dbContext.Devices.Where(d => d.DeviceProfileId == m.DeviceProfile.Id));
if (m == null || m.DeviceProfile == null)
throw new ArgumentException("Invalid Device Profile Id", "id");

m.OrganisationAddresses = dbContext.DiscoConfiguration.OrganisationAddresses.Addresses;
m.CertificateProviders = Plugins.GetPluginFeatures(typeof(CertificateProviderFeature));

var DistributionValues = Enum.GetValues(typeof(Disco.Models.Repository.DeviceProfile.DistributionTypes));
m.DeviceProfileDistributionTypes = new List<SelectListItem>();
Expand Down
1 change: 1 addition & 0 deletions Disco.Web/Areas/Config/Models/DeviceBatch/ShowModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ShowModel : ConfigDeviceBatchShowModel
{
public Disco.Models.Repository.DeviceBatch DeviceBatch { get; set; }
public List<Disco.Models.Repository.DeviceModel> DeviceModels { get; set; }
public List<ConfigDeviceBatchShowModelMembership> DeviceModelMembers { get; set; }
public int DeviceCount { get; set; }
public int DeviceDecommissionedCount { get; set; }
public bool CanDelete { get; set; }
Expand Down
15 changes: 15 additions & 0 deletions Disco.Web/Areas/Config/Models/DeviceBatch/_ShowModelMembership.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Disco.Models.UI.Config.DeviceBatch;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Disco.Web.Areas.Config.Models.DeviceBatch
{
public class _ShowModelMembership : ConfigDeviceBatchShowModelMembership
{
public Disco.Models.Repository.DeviceModel DeviceModel { get; set; }
public int DeviceCount { get; set; }
public int DeviceDecommissionedCount { get; set; }
}
}
3 changes: 2 additions & 1 deletion Disco.Web/Areas/Config/Models/DeviceModel/IndexModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public static IndexModel Build(DiscoDataContext dbContext)
Manufacturer = dm.Manufacturer,
Model = dm.Model,
ModelType = dm.ModelType,
DeviceCount = dm.Devices.Count
DeviceCount = dm.Devices.Count,
DeviceDecommissionedCount = dm.Devices.Count(d => d.DecommissionedDate.HasValue)
}).ToArray().Cast<ConfigDeviceModelIndexModelItem>().ToList();

return m;
Expand Down
3 changes: 3 additions & 0 deletions Disco.Web/Areas/Config/Models/DeviceModel/ShowModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class ShowModel : ConfigDeviceModelShowModel

public List<PluginFeatureManifest> WarrantyProviders { get; set; }

public int DeviceCount { get; set; }
public int DeviceDecommissionedCount { get; set; }

public bool CanDelete { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class _IndexModelItem : ConfigDeviceModelIndexModelItem
public string Model { get; set; }
public string ModelType { get; set; }
public int DeviceCount { get; set; }
public int DeviceDecommissionedCount { get; set; }

public override string ToString()
{
Expand Down
3 changes: 3 additions & 0 deletions Disco.Web/Areas/Config/Models/DeviceProfile/ShowModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class ShowModel : ConfigDeviceProfileShowModel

public List<PluginFeatureManifest> CertificateProviders { get; set; }

public int DeviceCount { get; set; }
public int DeviceDecommissionedCount { get; set; }

public bool CanDelete { get; set; }
}
}
4 changes: 2 additions & 2 deletions Disco.Web/Areas/Config/Views/DeviceBatch/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
}
@if (item.DeviceDecommissionedCount > 0)
{
<span class="smallMessage" title="@(item.DeviceDecommissionedCount) Decommissioned">
(@(item.DeviceDecommissionedCount))</span>
<span class="smallMessage" title="@(item.DeviceDecommissionedCount.ToString("n0")) Decommissioned">
(@(item.DeviceDecommissionedCount.ToString("n0")))</span>
}
</td>
</tr>
Expand Down
10 changes: 5 additions & 5 deletions Disco.Web/Areas/Config/Views/DeviceBatch/Index.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18033
// Runtime Version:4.0.30319.18051
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand Down Expand Up @@ -229,22 +229,22 @@ Device Count

WriteLiteral(" class=\"smallMessage\"");

WriteAttribute("title", Tuple.Create(" title=\"", 1775), Tuple.Create("\"", 1831)
WriteAttribute("title", Tuple.Create(" title=\"", 1775), Tuple.Create("\"", 1846)

#line 56 "..\..\Areas\Config\Views\DeviceBatch\Index.cshtml"
, Tuple.Create(Tuple.Create("", 1783), Tuple.Create<System.Object, System.Int32>(item.DeviceDecommissionedCount
, Tuple.Create(Tuple.Create("", 1783), Tuple.Create<System.Object, System.Int32>(item.DeviceDecommissionedCount.ToString("n0")

#line default
#line hidden
, 1783), false)
, Tuple.Create(Tuple.Create(" ", 1816), Tuple.Create("Decommissioned", 1817), true)
, Tuple.Create(Tuple.Create(" ", 1831), Tuple.Create("Decommissioned", 1832), true)
);

WriteLiteral(">\r\n (");


#line 57 "..\..\Areas\Config\Views\DeviceBatch\Index.cshtml"
Write(item.DeviceDecommissionedCount);
Write(item.DeviceDecommissionedCount.ToString("n0"));


#line default
Expand Down
Loading

0 comments on commit 1950336

Please sign in to comment.