mirror of
https://gitlab.com/buildfeed/BuildFeed.git
synced 2024-03-22 21:10:34 +08:00
More amends, inc a bit of Localisation
This commit is contained in:
parent
d2521cdc8d
commit
b17e622280
|
@ -1,4 +1,5 @@
|
|||
using BuildFeed.Models;
|
||||
using BuildFeed.Local;
|
||||
using BuildFeed.Models;
|
||||
using BuildFeed.Models.ApiModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -10,17 +11,23 @@ namespace BuildFeed.Controllers
|
|||
{
|
||||
public class apiController : ApiController
|
||||
{
|
||||
private Build bModel;
|
||||
|
||||
public apiController() : base()
|
||||
{
|
||||
bModel = new Build();
|
||||
}
|
||||
|
||||
public IEnumerable<BuildModel> GetBuilds()
|
||||
{
|
||||
return new Build().SelectInBuildOrder();
|
||||
return bModel.SelectInBuildOrder();
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetWin10Labs()
|
||||
{
|
||||
Build b = new Build();
|
||||
List<string> labs = new List<string>();
|
||||
labs.AddRange(b.SelectBuildLabs(6, 4));
|
||||
labs.AddRange(b.SelectBuildLabs(10, 0));
|
||||
labs.AddRange(bModel.SelectBuildLabs(6, 4));
|
||||
labs.AddRange(bModel.SelectBuildLabs(10, 0));
|
||||
|
||||
return labs.GroupBy(l => l).Select(l => l.Key).Where(l => l.All(c => c != '(')).ToArray();
|
||||
}
|
||||
|
@ -34,7 +41,7 @@ public bool AddWin10Builds(NewBuild apiModel)
|
|||
}
|
||||
if (Membership.ValidateUser(apiModel.Username, apiModel.Password))
|
||||
{
|
||||
new Build().InsertAll(apiModel.NewBuilds.Select(nb => new BuildModel()
|
||||
bModel.InsertAll(apiModel.NewBuilds.Select(nb => new BuildModel()
|
||||
{
|
||||
MajorVersion = nb.MajorVersion,
|
||||
MinorVersion = nb.MinorVersion,
|
||||
|
@ -69,13 +76,13 @@ orderby s.Text.ToLower().IndexOf(query.ToLower(), StringComparison.Ordinal) asce
|
|||
Url = Url.Route("Source Root", new { controller = "front", action = "viewSource", source = s.Value }),
|
||||
Label = s.Text.Replace(query, "<strong>" + query + "</strong>"),
|
||||
Title = s.Text,
|
||||
Group = "Source"
|
||||
Group = Common.SearchSource
|
||||
};
|
||||
|
||||
results.AddRange(sourceResults);
|
||||
|
||||
|
||||
var versionResults = from v in new Build().SelectBuildVersions()
|
||||
var versionResults = from v in bModel.SelectBuildVersions()
|
||||
where $"{v.Major}.{v.Minor}".StartsWith(query)
|
||||
orderby v.Major descending, v.Minor descending
|
||||
select new SearchResult()
|
||||
|
@ -83,13 +90,13 @@ orderby s.Text.ToLower().IndexOf(query.ToLower(), StringComparison.Ordinal) asce
|
|||
Url = Url.Route("Version Root", new { controller = "front", action = "viewVersion", major = v.Major, minor = v.Minor }),
|
||||
Label = $"{v.Major}.{v.Minor}".Replace(query, "<strong>" + query + "</strong>"),
|
||||
Title = "",
|
||||
Group = "Version"
|
||||
Group = Common.SearchVersion
|
||||
};
|
||||
|
||||
results.AddRange(versionResults);
|
||||
|
||||
|
||||
var yearResults = from y in new Build().SelectBuildYears()
|
||||
var yearResults = from y in bModel.SelectBuildYears()
|
||||
where y.ToString().Contains(query)
|
||||
orderby y descending
|
||||
select new SearchResult()
|
||||
|
@ -97,36 +104,36 @@ orderby y descending
|
|||
Url = Url.Route("Year Root", new { controller = "front", action = "viewYear", year = y }),
|
||||
Label = y.ToString().Replace(query, "<strong>" + query + "</strong>"),
|
||||
Title = "",
|
||||
Group = "Year"
|
||||
Group = Common.SearchYear
|
||||
};
|
||||
|
||||
results.AddRange(yearResults);
|
||||
|
||||
|
||||
var labResults = from l in new Build().SelectBuildLabs()
|
||||
where l.ToLower().Contains(query.ToLower())
|
||||
orderby l.ToLower().IndexOf(query.ToLower(), StringComparison.Ordinal) ascending
|
||||
var labResults = from l in bModel.SearchBuildLabs(query)
|
||||
orderby l.IndexOf(query.ToLower()) ascending,
|
||||
l.Length ascending
|
||||
select new SearchResult()
|
||||
{
|
||||
Url = Url.Route("Lab Root", new { controller = "front", action = "viewLab", lab = l }),
|
||||
Label = l.Replace(query, "<strong>" + query + "</strong>"),
|
||||
Label = l.Replace(query, $"<strong>{query}</strong>"),
|
||||
Title = l,
|
||||
Group = "Lab"
|
||||
Group = Common.SearchLab
|
||||
};
|
||||
|
||||
results.AddRange(labResults);
|
||||
|
||||
|
||||
var buildResults = from b in new Build().Select()
|
||||
var buildResults = from b in bModel.Select()
|
||||
where b.FullBuildString.ToLower().Contains(query.ToLower())
|
||||
orderby b.FullBuildString.ToLower().IndexOf(query.ToLower(), StringComparison.Ordinal) ascending,
|
||||
b.BuildTime descending
|
||||
select new SearchResult()
|
||||
{
|
||||
Url = Url.Route("Build", new { controller = "front", action = "viewBuild", id = b.Id }),
|
||||
Label = b.FullBuildString.Replace(query, "<strong>" + query + "</strong>"),
|
||||
Label = b.FullBuildString.Replace(query, $"<strong>{query}</strong>"),
|
||||
Title = b.FullBuildString,
|
||||
Group = "Build"
|
||||
Group = Common.SearchBuild
|
||||
};
|
||||
|
||||
results.AddRange(buildResults);
|
||||
|
@ -137,7 +144,7 @@ b.BuildTime descending
|
|||
results.Add(new SearchResult()
|
||||
{
|
||||
Url = "/",
|
||||
Label = "No Results found",
|
||||
Label = Common.SearchEmpty,
|
||||
Group = ""
|
||||
});
|
||||
}
|
||||
|
|
54
BuildFeed/Local/Common.Designer.cs
generated
54
BuildFeed/Local/Common.Designer.cs
generated
|
@ -159,6 +159,15 @@ public static string Search {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Build.
|
||||
/// </summary>
|
||||
public static string SearchBuild {
|
||||
get {
|
||||
return ResourceManager.GetString("SearchBuild", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Search BuildFeed....
|
||||
/// </summary>
|
||||
|
@ -168,6 +177,24 @@ public static string SearchBuildFeed {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to No results found.
|
||||
/// </summary>
|
||||
public static string SearchEmpty {
|
||||
get {
|
||||
return ResourceManager.GetString("SearchEmpty", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Lab.
|
||||
/// </summary>
|
||||
public static string SearchLab {
|
||||
get {
|
||||
return ResourceManager.GetString("SearchLab", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Search query.
|
||||
/// </summary>
|
||||
|
@ -177,6 +204,33 @@ public static string SearchQuery {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Source.
|
||||
/// </summary>
|
||||
public static string SearchSource {
|
||||
get {
|
||||
return ResourceManager.GetString("SearchSource", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Version.
|
||||
/// </summary>
|
||||
public static string SearchVersion {
|
||||
get {
|
||||
return ResourceManager.GetString("SearchVersion", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Year.
|
||||
/// </summary>
|
||||
public static string SearchYear {
|
||||
get {
|
||||
return ResourceManager.GetString("SearchYear", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Sitemap.
|
||||
/// </summary>
|
||||
|
|
|
@ -174,4 +174,22 @@
|
|||
<data name="PageTitleSegment" xml:space="preserve">
|
||||
<value>[!!! | Þáϱè {0} !!!]</value>
|
||||
</data>
|
||||
<data name="SearchBuild" xml:space="preserve">
|
||||
<value>[!!! ßúïℓδ ℓ !!!]</value>
|
||||
</data>
|
||||
<data name="SearchEmpty" xml:space="preserve">
|
||||
<value>[!!! Nô řèƨúℓƭƨ ƒôúñδ ℓôřè !!!]</value>
|
||||
</data>
|
||||
<data name="SearchLab" xml:space="preserve">
|
||||
<value>[!!! £áβ !!!]</value>
|
||||
</data>
|
||||
<data name="SearchSource" xml:space="preserve">
|
||||
<value>[!!! §ôúrçè l !!!]</value>
|
||||
</data>
|
||||
<data name="SearchVersion" xml:space="preserve">
|
||||
<value>[!!! Vèřƨïôñ ℓ !!!]</value>
|
||||
</data>
|
||||
<data name="SearchYear" xml:space="preserve">
|
||||
<value>[!!! Ýèář !!!]</value>
|
||||
</data>
|
||||
</root>
|
|
@ -174,4 +174,22 @@
|
|||
<data name="PageTitleSegment" xml:space="preserve">
|
||||
<value>| Page {0}</value>
|
||||
</data>
|
||||
<data name="SearchBuild" xml:space="preserve">
|
||||
<value>Build</value>
|
||||
</data>
|
||||
<data name="SearchEmpty" xml:space="preserve">
|
||||
<value>No results found</value>
|
||||
</data>
|
||||
<data name="SearchLab" xml:space="preserve">
|
||||
<value>Lab</value>
|
||||
</data>
|
||||
<data name="SearchSource" xml:space="preserve">
|
||||
<value>Source</value>
|
||||
</data>
|
||||
<data name="SearchVersion" xml:space="preserve">
|
||||
<value>Version</value>
|
||||
</data>
|
||||
<data name="SearchYear" xml:space="preserve">
|
||||
<value>Year</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1,4 +1,5 @@
|
|||
using BuildFeed.Local;
|
||||
using BuildFeed.Models.ApiModel;
|
||||
using BuildFeed.Models.ViewModel.Front;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
|
@ -350,45 +351,97 @@ public long SelectVersionCount(int major, int minor)
|
|||
}
|
||||
|
||||
[DataObjectMethod(DataObjectMethodType.Select, false)]
|
||||
public IEnumerable<BuildVersion> SelectBuildVersions()
|
||||
public List<BuildVersion> SelectBuildVersions()
|
||||
{
|
||||
var task = _buildCollection.DistinctAsync(b => new BuildVersion() { Major = b.MajorVersion, Minor = b.MinorVersion }, b => true);
|
||||
var task = _buildCollection.Aggregate()
|
||||
.Group(b => new BuildVersion()
|
||||
{
|
||||
Major = b.MajorVersion,
|
||||
Minor = b.MinorVersion,
|
||||
},
|
||||
// incoming bullshit hack
|
||||
bg => new Tuple<BuildVersion>(bg.Key))
|
||||
.SortByDescending(b => b.Item1.Major)
|
||||
.ThenByDescending(b => b.Item1.Minor)
|
||||
.ToListAsync();
|
||||
|
||||
task.Wait();
|
||||
var outTask = task.Result.ToListAsync();
|
||||
outTask.Wait();
|
||||
return outTask.Result
|
||||
.OrderByDescending(y => y.Major)
|
||||
.ThenByDescending(y => y.Minor);
|
||||
|
||||
// work ourselves out of aforementioned bullshit hack
|
||||
return task.Result.Select(b => b.Item1).ToList();
|
||||
}
|
||||
|
||||
[DataObjectMethod(DataObjectMethodType.Select, false)]
|
||||
public IEnumerable<int> SelectBuildYears()
|
||||
{
|
||||
var task = _buildCollection.DistinctAsync(b => b.BuildTime.Value.Year, b => b.BuildTime.HasValue);
|
||||
var task = _buildCollection.Aggregate()
|
||||
.Match(b => b.BuildTime != null)
|
||||
.Group(b => ((DateTime)b.BuildTime).Year,
|
||||
// incoming bullshit hack
|
||||
bg => new Tuple<int>(bg.Key))
|
||||
.SortByDescending(b => b.Item1)
|
||||
.ToListAsync();
|
||||
|
||||
task.Wait();
|
||||
var outTask = task.Result.ToListAsync();
|
||||
outTask.Wait();
|
||||
return outTask.Result.OrderBy(b => b);
|
||||
|
||||
// work ourselves out of aforementioned bullshit hack
|
||||
return task.Result.Select(b => b.Item1).ToList();
|
||||
}
|
||||
|
||||
[DataObjectMethod(DataObjectMethodType.Select, false)]
|
||||
public List<string> SearchBuildLabs(string query)
|
||||
{
|
||||
var task = _buildCollection.Aggregate()
|
||||
.Match(b => b.Lab != null)
|
||||
.Match(b => b.Lab != "")
|
||||
.Match(b => b.Lab.ToLower().Contains(query.ToLower()))
|
||||
.Group(b => b.Lab.ToLower(),
|
||||
// incoming bullshit hack
|
||||
bg => new Tuple<string>(bg.Key))
|
||||
.ToListAsync();
|
||||
|
||||
task.Wait();
|
||||
|
||||
// work ourselves out of aforementioned bullshit hack
|
||||
return task.Result.Select(b => b.Item1).ToList();
|
||||
}
|
||||
|
||||
[DataObjectMethod(DataObjectMethodType.Select, false)]
|
||||
public IEnumerable<string> SelectBuildLabs()
|
||||
{
|
||||
var task = _buildCollection.DistinctAsync(b => b.Lab.ToLower(), b => !string.IsNullOrWhiteSpace(b.Lab));
|
||||
var task = _buildCollection.Aggregate()
|
||||
.Match(b => b.Lab != null)
|
||||
.Match(b => b.Lab != "")
|
||||
.Group(b => b.Lab.ToLower(),
|
||||
// incoming bullshit hack
|
||||
bg => new Tuple<string>(bg.Key))
|
||||
.SortBy(b => b.Item1)
|
||||
.ToListAsync();
|
||||
|
||||
task.Wait();
|
||||
var outTask = task.Result.ToListAsync();
|
||||
outTask.Wait();
|
||||
return outTask.Result.OrderBy(b => b);
|
||||
|
||||
// work ourselves out of aforementioned bullshit hack
|
||||
return task.Result.Select(b => b.Item1).ToList();
|
||||
}
|
||||
|
||||
[DataObjectMethod(DataObjectMethodType.Select, false)]
|
||||
public IEnumerable<string> SelectBuildLabs(byte major, byte minor)
|
||||
{
|
||||
var task = _buildCollection.DistinctAsync(b => b.Lab.ToLower(), b => !string.IsNullOrWhiteSpace(b.Lab) && b.MajorVersion == major && b.MinorVersion == minor);
|
||||
var task = _buildCollection.Aggregate()
|
||||
.Match(b => b.MajorVersion == major)
|
||||
.Match(b => b.MinorVersion == minor)
|
||||
.Match(b => b.Lab != null)
|
||||
.Match(b => b.Lab != "")
|
||||
.Group(b => b.Lab.ToLower(),
|
||||
// incoming bullshit hack
|
||||
bg => new Tuple<string>(bg.Key))
|
||||
.SortBy(b => b.Item1)
|
||||
.ToListAsync();
|
||||
|
||||
task.Wait();
|
||||
var outTask = task.Result.ToListAsync();
|
||||
outTask.Wait();
|
||||
return outTask.Result.OrderBy(b => b);
|
||||
|
||||
// work ourselves out of aforementioned bullshit hack
|
||||
return task.Result.Select(b => b.Item1).ToList();
|
||||
}
|
||||
|
||||
[DataObjectMethod(DataObjectMethodType.Insert, true)]
|
||||
|
@ -470,11 +523,21 @@ public enum LevelOfFlight
|
|||
High = 3
|
||||
}
|
||||
|
||||
public struct BuildVersion
|
||||
public class BuildVersion
|
||||
{
|
||||
public byte Major { get; set; }
|
||||
public byte Minor { get; set; }
|
||||
|
||||
public BuildVersion()
|
||||
{
|
||||
}
|
||||
|
||||
public BuildVersion(byte major, byte minor)
|
||||
{
|
||||
Major = major;
|
||||
Minor = minor;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Major}.{Minor}";
|
||||
|
|
Loading…
Reference in New Issue
Block a user