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.Globalization;
using System.Text;
using System.Web.Mvc;
using BuildFeed.Local;
using HtmlAgilityPack;
using MongoDB.Bson.Serialization.Attributes;
@ -14,7 +13,7 @@ namespace BuildFeed.Model
{
[DataObject]
[BsonIgnoreExtraElements]
public class Build
public class Build : BuildDetails
{
[Key]
[BsonId]
@ -22,29 +21,6 @@ public class Build
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]
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Added))]
public DateTime Added { get; set; }
@ -53,19 +29,6 @@ public class Build
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Model_Modified))]
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 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 List<ItemHistory<Build>> History { get; set; }
public List<ItemHistory<BuildDetails>> History { get; set; }
[Display(ResourceType = typeof(VariantTerms), Name = nameof(VariantTerms.Search_Version))]
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>
<Compile Include="Api\NewBuild.cs" />
<Compile Include="Api\SearchResult.cs" />
<Compile Include="BuildDetails.cs" />
<Compile Include="BuildRepository-Group.cs" />
<Compile Include="BuildRepository-Lab.cs" />
<Compile Include="BuildRepository-Source.cs" />

View File

@ -316,7 +316,7 @@ public async Task MigrateAddedModifiedToHistory()
List<Build> builds = await Select();
foreach (Build bd in builds)
{
Build item = new Build
BuildDetails item = new BuildDetails
{
MajorVersion = bd.MajorVersion,
MinorVersion = bd.MinorVersion,
@ -326,18 +326,17 @@ public async Task MigrateAddedModifiedToHistory()
BuildTime = bd.BuildTime,
SourceType = bd.SourceType,
LeakDate = bd.LeakDate,
History = null
SourceDetails = bd.SourceDetails
};
item.RegenerateCachedProperties();
if (bd.Added == DateTime.MinValue)
{
continue;
}
bd.History = new List<ItemHistory<Build>>
bd.History = new List<ItemHistory<BuildDetails>>
{
new ItemHistory<Build>
new ItemHistory<BuildDetails>
{
Type = ItemHistoryType.Added,
Time = bd.Added,
@ -350,7 +349,7 @@ public async Task MigrateAddedModifiedToHistory()
if (bd.Modified != DateTime.MinValue && bd.Added != bd.Modified)
{
bd.History.Add(new ItemHistory<Build>
bd.History.Add(new ItemHistory<BuildDetails>
{
Type = ItemHistoryType.Edited,
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")))
{
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,
MinorVersion = nb.MinorVersion,
@ -85,11 +85,10 @@ public async Task<bool> AddWin10Builds(NewBuildPost apiModel)
Lab = nb.Lab,
BuildTime = nb.BuildTime.HasValue
? DateTime.SpecifyKind(nb.BuildTime.Value, DateTimeKind.Utc)
: null as DateTime?
: null as DateTime?,
SourceType = TypeOfSource.PrivateLeak
};
bi.RegenerateCachedProperties();
return bi;
});
@ -107,9 +106,9 @@ public async Task<bool> AddWin10Builds(NewBuildPost apiModel)
Modified = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc),
SourceType = TypeOfSource.PrivateLeak,
History = new List<ItemHistory<Build>>
History = new List<ItemHistory<BuildDetails>>
{
new ItemHistory<Build>
new ItemHistory<BuildDetails>
{
Type = ItemHistoryType.Added,
Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc),

View File

@ -413,7 +413,7 @@ public async Task<ActionResult> AddBuild(Build build)
build.RegenerateCachedProperties();
Build bi = new Build
BuildDetails bi = new BuildDetails
{
MajorVersion = build.MajorVersion,
MinorVersion = build.MinorVersion,
@ -422,13 +422,14 @@ public async Task<ActionResult> AddBuild(Build build)
Lab = build.Lab,
BuildTime = build.BuildTime.HasValue
? 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,
Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc),
@ -505,7 +506,7 @@ public async Task<ActionResult> AddBulk(FormCollection values)
};
b.RegenerateCachedProperties();
Build bi = new Build
BuildDetails bi = new BuildDetails
{
MajorVersion = b.MajorVersion,
MinorVersion = b.MinorVersion,
@ -514,13 +515,14 @@ public async Task<ActionResult> AddBulk(FormCollection values)
Lab = b.Lab,
BuildTime = b.BuildTime.HasValue
? 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,
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 bi = new Build
BuildDetails bi = new BuildDetails
{
MajorVersion = build.MajorVersion,
MinorVersion = build.MinorVersion,
@ -602,17 +604,18 @@ public async Task<ActionResult> EditBuild(Guid id, Build build)
Lab = build.Lab,
BuildTime = build.BuildTime.HasValue
? 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;
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,
Time = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc),

View File

@ -109,7 +109,7 @@ else
<div class="form-group">
<label></label>
<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.Front_EditBuild)" class="btn btn-primary" />
&ensp;