Adjustments to item history

This commit is contained in:
Thomas Hounsell 2017-04-16 23:22:48 +01:00
parent 6b82e15d10
commit 1a89be223d
7 changed files with 82 additions and 68 deletions

View File

@ -4,7 +4,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
using System.Web.Mvc;
using BuildFeed.Local; using BuildFeed.Local;
using HtmlAgilityPack; using HtmlAgilityPack;
using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Attributes;
@ -14,7 +13,7 @@ namespace BuildFeed.Model
{ {
[DataObject] [DataObject]
[BsonIgnoreExtraElements] [BsonIgnoreExtraElements]
public class Build public class Build : BuildDetails
{ {
[Key] [Key]
[BsonId] [BsonId]
@ -22,29 +21,6 @@ public class Build
public long? LegacyId { get; set; } public long? LegacyId { get; set; }
[@Required]
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_MajorVersion))]
public uint MajorVersion { get; set; }
[@Required]
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_MinorVersion))]
public uint MinorVersion { get; set; }
[@Required]
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_BuildNumber))]
public uint Number { get; set; }
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Revision))]
[DisplayFormat(ConvertEmptyStringToNull = true)]
public uint? Revision { get; set; }
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_LabString))]
public string Lab { get; set; }
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_BuildTime))]
[DisplayFormat(ConvertEmptyStringToNull = true, ApplyFormatInEditMode = true, DataFormatString = "{0:yyMMdd-HHmm}")]
public DateTime? BuildTime { get; set; }
[@Required] [@Required]
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Added))] [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Added))]
public DateTime Added { get; set; } public DateTime Added { get; set; }
@ -53,19 +29,6 @@ public class Build
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Modified))] [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Modified))]
public DateTime Modified { get; set; } public DateTime Modified { get; set; }
[@Required]
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_SourceType))]
[EnumDataType(typeof(TypeOfSource))]
public TypeOfSource SourceType { get; set; }
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_SourceDetails))]
[AllowHtml]
public string SourceDetails { get; set; }
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_LeakDate))]
[DisplayFormat(ConvertEmptyStringToNull = true, ApplyFormatInEditMode = true)]
public DateTime? LeakDate { get; set; }
public string LabUrl { get; private set; } public string LabUrl { get; private set; }
public bool IsLeaked => SourceType == TypeOfSource.PublicRelease || SourceType == TypeOfSource.InternalLeak || SourceType == TypeOfSource.UpdateGDR; public bool IsLeaked => SourceType == TypeOfSource.PublicRelease || SourceType == TypeOfSource.InternalLeak || SourceType == TypeOfSource.UpdateGDR;
@ -74,7 +37,7 @@ public class Build
public string AlternateBuildString { get; private set; } public string AlternateBuildString { get; private set; }
public List<ItemHistory<Build>> History { get; set; } public List<ItemHistory<BuildDetails>> History { get; set; }
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Search_Version))] [Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Search_Version))]
public ProjectFamily Family public ProjectFamily Family

View File

@ -0,0 +1,49 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using BuildFeed.Local;
using MongoDB.Bson.Serialization.Attributes;
namespace BuildFeed.Model
{
[BsonIgnoreExtraElements]
public class BuildDetails
{
[Required]
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_MajorVersion))]
public uint MajorVersion { get; set; }
[Required]
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_MinorVersion))]
public uint MinorVersion { get; set; }
[Required]
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_BuildNumber))]
public uint Number { get; set; }
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Revision))]
[DisplayFormat(ConvertEmptyStringToNull = true)]
public uint? Revision { get; set; }
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_LabString))]
public string Lab { get; set; }
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_BuildTime))]
[DisplayFormat(ConvertEmptyStringToNull = true, ApplyFormatInEditMode = true,
DataFormatString = "{0:yyMMdd-HHmm}")]
public DateTime? BuildTime { get; set; }
[Required]
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_SourceType))]
[EnumDataType(typeof(TypeOfSource))]
public TypeOfSource SourceType { get; set; }
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_SourceDetails))]
[AllowHtml]
public string SourceDetails { get; set; }
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_LeakDate))]
[DisplayFormat(ConvertEmptyStringToNull = true, ApplyFormatInEditMode = true)]
public DateTime? LeakDate { get; set; }
}
}

View File

@ -91,6 +91,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="Api\NewBuild.cs" /> <Compile Include="Api\NewBuild.cs" />
<Compile Include="Api\SearchResult.cs" /> <Compile Include="Api\SearchResult.cs" />
<Compile Include="BuildDetails.cs" />
<Compile Include="BuildRepository-Group.cs" /> <Compile Include="BuildRepository-Group.cs" />
<Compile Include="BuildRepository-Lab.cs" /> <Compile Include="BuildRepository-Lab.cs" />
<Compile Include="BuildRepository-Source.cs" /> <Compile Include="BuildRepository-Source.cs" />

View File

@ -316,7 +316,7 @@ public async Task MigrateAddedModifiedToHistory()
List<Build> builds = await Select(); List<Build> builds = await Select();
foreach (Build bd in builds) foreach (Build bd in builds)
{ {
Build item = new Build BuildDetails item = new BuildDetails
{ {
MajorVersion = bd.MajorVersion, MajorVersion = bd.MajorVersion,
MinorVersion = bd.MinorVersion, MinorVersion = bd.MinorVersion,
@ -326,18 +326,17 @@ public async Task MigrateAddedModifiedToHistory()
BuildTime = bd.BuildTime, BuildTime = bd.BuildTime,
SourceType = bd.SourceType, SourceType = bd.SourceType,
LeakDate = bd.LeakDate, LeakDate = bd.LeakDate,
History = null SourceDetails = bd.SourceDetails
}; };
item.RegenerateCachedProperties();
if (bd.Added == DateTime.MinValue) if (bd.Added == DateTime.MinValue)
{ {
continue; continue;
} }
bd.History = new List<ItemHistory<Build>> bd.History = new List<ItemHistory<BuildDetails>>
{ {
new ItemHistory<Build> new ItemHistory<BuildDetails>
{ {
Type = ItemHistoryType.Added, Type = ItemHistoryType.Added,
Time = bd.Added, Time = bd.Added,
@ -350,7 +349,7 @@ public async Task MigrateAddedModifiedToHistory()
if (bd.Modified != DateTime.MinValue && bd.Added != bd.Modified) if (bd.Modified != DateTime.MinValue && bd.Added != bd.Modified)
{ {
bd.History.Add(new ItemHistory<Build> bd.History.Add(new ItemHistory<BuildDetails>
{ {
Type = ItemHistoryType.Edited, Type = ItemHistoryType.Edited,
Time = bd.Modified, Time = bd.Modified,

View File

@ -74,9 +74,9 @@ public async Task<bool> AddWin10Builds(NewBuildPost apiModel)
} }
if (Membership.ValidateUser(apiModel.Username, apiModel.Password) && (Roles.IsUserInRole(apiModel.Username, "Editors") || Roles.IsUserInRole(apiModel.Username, "Administrators"))) if (Membership.ValidateUser(apiModel.Username, apiModel.Password) && (Roles.IsUserInRole(apiModel.Username, "Editors") || Roles.IsUserInRole(apiModel.Username, "Administrators")))
{ {
var generateOldItem = new Func<NewBuild, Build>(nb => var generateOldItem = new Func<NewBuild, BuildDetails>(nb =>
{ {
Build bi = new Build BuildDetails bi = new BuildDetails
{ {
MajorVersion = nb.MajorVersion, MajorVersion = nb.MajorVersion,
MinorVersion = nb.MinorVersion, MinorVersion = nb.MinorVersion,
@ -85,11 +85,10 @@ public async Task<bool> AddWin10Builds(NewBuildPost apiModel)
Lab = nb.Lab, Lab = nb.Lab,
BuildTime = nb.BuildTime.HasValue BuildTime = nb.BuildTime.HasValue
? DateTime.SpecifyKind(nb.BuildTime.Value, DateTimeKind.Utc) ? DateTime.SpecifyKind(nb.BuildTime.Value, DateTimeKind.Utc)
: null as DateTime? : null as DateTime?,
SourceType = TypeOfSource.PrivateLeak
}; };
bi.RegenerateCachedProperties();
return bi; return bi;
}); });
@ -107,9 +106,9 @@ public async Task<bool> AddWin10Builds(NewBuildPost apiModel)
Modified = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), Modified = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc),
SourceType = TypeOfSource.PrivateLeak, SourceType = TypeOfSource.PrivateLeak,
History = new List<ItemHistory<Build>> History = new List<ItemHistory<BuildDetails>>
{ {
new ItemHistory<Build> new ItemHistory<BuildDetails>
{ {
Type = ItemHistoryType.Added, Type = ItemHistoryType.Added,
Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc),

View File

@ -413,7 +413,7 @@ public async Task<ActionResult> AddBuild(Build build)
build.RegenerateCachedProperties(); build.RegenerateCachedProperties();
Build bi = new Build BuildDetails bi = new BuildDetails
{ {
MajorVersion = build.MajorVersion, MajorVersion = build.MajorVersion,
MinorVersion = build.MinorVersion, MinorVersion = build.MinorVersion,
@ -422,13 +422,14 @@ public async Task<ActionResult> AddBuild(Build build)
Lab = build.Lab, Lab = build.Lab,
BuildTime = build.BuildTime.HasValue BuildTime = build.BuildTime.HasValue
? DateTime.SpecifyKind(build.BuildTime.Value, DateTimeKind.Utc) ? DateTime.SpecifyKind(build.BuildTime.Value, DateTimeKind.Utc)
: null as DateTime? : null as DateTime?,
SourceType = build.SourceType,
SourceDetails = build.SourceDetails
}; };
bi.RegenerateCachedProperties();
build.History = new List<ItemHistory<Build>> build.History = new List<ItemHistory<BuildDetails>>
{ {
new ItemHistory<Build> new ItemHistory<BuildDetails>
{ {
Type = ItemHistoryType.Added, Type = ItemHistoryType.Added,
Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc),
@ -505,7 +506,7 @@ public async Task<ActionResult> AddBulk(FormCollection values)
}; };
b.RegenerateCachedProperties(); b.RegenerateCachedProperties();
Build bi = new Build BuildDetails bi = new BuildDetails
{ {
MajorVersion = b.MajorVersion, MajorVersion = b.MajorVersion,
MinorVersion = b.MinorVersion, MinorVersion = b.MinorVersion,
@ -514,13 +515,14 @@ public async Task<ActionResult> AddBulk(FormCollection values)
Lab = b.Lab, Lab = b.Lab,
BuildTime = b.BuildTime.HasValue BuildTime = b.BuildTime.HasValue
? DateTime.SpecifyKind(b.BuildTime.Value, DateTimeKind.Utc) ? DateTime.SpecifyKind(b.BuildTime.Value, DateTimeKind.Utc)
: null as DateTime? : null as DateTime?,
SourceType = b.SourceType,
SourceDetails = b.SourceDetails
}; };
bi.RegenerateCachedProperties();
b.History = new List<ItemHistory<Build>> b.History = new List<ItemHistory<BuildDetails>>
{ {
new ItemHistory<Build> new ItemHistory<BuildDetails>
{ {
Type = ItemHistoryType.Added, Type = ItemHistoryType.Added,
Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc),
@ -593,7 +595,7 @@ public async Task<ActionResult> EditBuild(Guid id, Build build)
build.LeakDate = DateTime.SpecifyKind(build.LeakDate.Value, DateTimeKind.Utc); build.LeakDate = DateTime.SpecifyKind(build.LeakDate.Value, DateTimeKind.Utc);
} }
Build bi = new Build BuildDetails bi = new BuildDetails
{ {
MajorVersion = build.MajorVersion, MajorVersion = build.MajorVersion,
MinorVersion = build.MinorVersion, MinorVersion = build.MinorVersion,
@ -602,17 +604,18 @@ public async Task<ActionResult> EditBuild(Guid id, Build build)
Lab = build.Lab, Lab = build.Lab,
BuildTime = build.BuildTime.HasValue BuildTime = build.BuildTime.HasValue
? DateTime.SpecifyKind(build.BuildTime.Value, DateTimeKind.Utc) ? DateTime.SpecifyKind(build.BuildTime.Value, DateTimeKind.Utc)
: null as DateTime? : null as DateTime?,
SourceType = build.SourceType,
SourceDetails = build.SourceDetails
}; };
bi.RegenerateCachedProperties();
build.History = b.History; build.History = b.History;
if (build.History == null || build.History.Count == 0) if (build.History == null || build.History.Count == 0)
{ {
build.History = new List<ItemHistory<Build>>(); build.History = new List<ItemHistory<BuildDetails>>();
} }
build.History.Add(new ItemHistory<Build> build.History.Add(new ItemHistory<BuildDetails>
{ {
Type = ItemHistoryType.Edited, Type = ItemHistoryType.Edited,
Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc), Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc),

View File

@ -109,7 +109,7 @@ else
<div class="form-group"> <div class="form-group">
<label></label> <label></label>
<div> <div>
<input type="submit" value="@((string)ViewContext.RouteData.Values["action"] == "addBuild" <input type="submit" value="@((string)ViewContext.RouteData.Values["action"] == nameof(FrontController.AddBuild)
? VariantTerms.Common_AddBuild ? VariantTerms.Common_AddBuild
: VariantTerms.Front_EditBuild)" class="btn btn-primary" /> : VariantTerms.Front_EditBuild)" class="btn btn-primary" />
&ensp; &ensp;