search view fixed
This commit is contained in:
parent
58f77a06ea
commit
95600facf4
10 changed files with 45 additions and 67 deletions
|
|
@ -27,7 +27,7 @@ namespace isnd.Controllers
|
||||||
[HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration + "/{id}/{lower}.json")]
|
[HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration + "/{id}/{lower}.json")]
|
||||||
public IActionResult CatalogRegistration(string apiVersion, string id, string lower)
|
public IActionResult CatalogRegistration(string apiVersion, string id, string lower)
|
||||||
{
|
{
|
||||||
if (lower.Equals("index", System.StringComparison.OrdinalIgnoreCase))
|
if (lower.Equals("index", System.StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
var query = new Data.Catalog.RegistrationPageIndexQuery
|
var query = new Data.Catalog.RegistrationPageIndexQuery
|
||||||
{
|
{
|
||||||
|
|
@ -39,8 +39,8 @@ namespace isnd.Controllers
|
||||||
// query.TotalHits = result.Items.Select(i=>i.Items.Length).Aggregate((a,b)=>a+b);
|
// query.TotalHits = result.Items.Select(i=>i.Items.Length).Aggregate((a,b)=>a+b);
|
||||||
return Ok(index);
|
return Ok(index);
|
||||||
}
|
}
|
||||||
var leaf = packageManager.SearchById(id,lower,null);
|
var leaf = packageManager.SearchById(id, lower, null);
|
||||||
if (leaf.Count()==0) return NotFound(new { id, lower });
|
if (leaf.Count() == 0) return NotFound(new { id, lower });
|
||||||
return Ok(leaf.First());
|
return Ok(leaf.First());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace isnd.Controllers
|
||||||
public async Task<IActionResult> Index(RegistrationPageIndexQuery model)
|
public async Task<IActionResult> Index(RegistrationPageIndexQuery model)
|
||||||
{
|
{
|
||||||
return View(new RegistrationPageIndexQueryAndResult{Query = model,
|
return View(new RegistrationPageIndexQueryAndResult{Query = model,
|
||||||
Result = packageManager.GetPackageRegistrationIndex(model)});
|
Result = packageManager.SearchPackage(model)});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IActionResult> Details(string pkgid)
|
public async Task<IActionResult> Details(string pkgid)
|
||||||
|
|
@ -34,7 +34,7 @@ namespace isnd.Controllers
|
||||||
.OrderByDescending(p => p)
|
.OrderByDescending(p => p)
|
||||||
;
|
;
|
||||||
|
|
||||||
if (packageVersion == null)
|
if (packageVersion.Count() == 0)
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,11 @@ namespace isnd.Data.Catalog
|
||||||
[JsonRequired]
|
[JsonRequired]
|
||||||
public string Id { get; protected set;}
|
public string Id { get; protected set;}
|
||||||
|
|
||||||
|
private string pkgid;
|
||||||
private List<PackageVersion> items;
|
private List<PackageVersion> items;
|
||||||
|
|
||||||
protected string Bid { get ; private set; }
|
protected string Bid { get ; private set; }
|
||||||
public string DlBase { get; }
|
protected string DlBase { get; }
|
||||||
|
|
||||||
public RegistrationPage (string bid, string dlBase)
|
public RegistrationPage (string bid, string dlBase)
|
||||||
{
|
{
|
||||||
|
|
@ -31,13 +32,14 @@ namespace isnd.Data.Catalog
|
||||||
Parent = Bid + "/index.json";
|
Parent = Bid + "/index.json";
|
||||||
DlBase = dlBase;
|
DlBase = dlBase;
|
||||||
this.items = new List<PackageVersion>(items);
|
this.items = new List<PackageVersion>(items);
|
||||||
SetPackageId(pkgid);
|
this.Id = Bid + "/" + pkgid + "/index.json";
|
||||||
|
this.pkgid = pkgid;
|
||||||
UpdateCompact();
|
UpdateCompact();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void SetPackageId(string pkgid)
|
public string GetPackageId()
|
||||||
{
|
{
|
||||||
this.Id = Bid + "/" + pkgid + "/index.json";
|
return pkgid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateCompact()
|
private void UpdateCompact()
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,12 @@ namespace isnd.Data.Catalog
|
||||||
[JsonProperty("@id")]
|
[JsonProperty("@id")]
|
||||||
public string Id { get; protected set; }
|
public string Id { get; protected set; }
|
||||||
|
|
||||||
public RegistrationPageIndex(string bid, string id)
|
public RegistrationPageIndex()
|
||||||
{
|
{
|
||||||
Id = bid + "/" + id + "/index.json";
|
|
||||||
Items = new List<RegistrationPage>();
|
Items = new List<RegistrationPage>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RegistrationPageIndex(string bid, string id, string dlBase, IEnumerable<Package> pkgs) : this(bid, id)
|
public RegistrationPageIndex(string bid, string id, string dlBase, IEnumerable<Package> pkgs)
|
||||||
{
|
{
|
||||||
// leaves;
|
// leaves;
|
||||||
this.Items = new List<RegistrationPage>
|
this.Items = new List<RegistrationPage>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ namespace isnd.Data.Catalog
|
||||||
{
|
{
|
||||||
public class RegistrationPageIndexQuery
|
public class RegistrationPageIndexQuery
|
||||||
{
|
{
|
||||||
|
|
||||||
public RegistrationPageIndexQuery()
|
public RegistrationPageIndexQuery()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -22,7 +21,5 @@ namespace isnd.Data.Catalog
|
||||||
[JsonProperty("take")]
|
[JsonProperty("take")]
|
||||||
|
|
||||||
public int Take { get; set; } = 25;
|
public int Take { get; set; } = 25;
|
||||||
[JsonProperty("totalHits")]
|
|
||||||
public int TotalHits { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -51,14 +51,14 @@ namespace isnd.Data.Packages
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bid">base url tu use for building the id property</param>
|
/// <param name="bid">base url tu use for building the id property</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public RegistrationLeaf ToLeave(string bid)
|
public RegistrationLeaf ToLeave(string bid, string dlbase)
|
||||||
{
|
{
|
||||||
if (Versions.Count == 0) throw new Exception("NO VERSION");
|
if (Versions.Count == 0) throw new Exception("NO VERSION");
|
||||||
var v = Versions.OrderBy(w => w.NugetVersion).First();
|
var v = Versions.OrderBy(w => w.NugetVersion).First();
|
||||||
RegistrationLeaf leave = new RegistrationLeaf
|
RegistrationLeaf leave = new RegistrationLeaf
|
||||||
{
|
{
|
||||||
Id = bid + Id + "/" + v.FullString + ".json",
|
Id = bid + Id + "/" + v.FullString + ".json",
|
||||||
PackageContent = v.NugetLink,
|
PackageContent = dlbase + "/" + v.NugetLink,
|
||||||
Entry = new CatalogEntry
|
Entry = new CatalogEntry
|
||||||
{
|
{
|
||||||
Id = bid + Id + ".json",
|
Id = bid + Id + ".json",
|
||||||
|
|
|
||||||
|
|
@ -6,27 +6,9 @@ namespace isnd.Helpers
|
||||||
{
|
{
|
||||||
foreach (var part in id.Split('-'))
|
foreach (var part in id.Split('-'))
|
||||||
{
|
{
|
||||||
if (part.Equals(q, System.StringComparison.OrdinalIgnoreCase)) return true;
|
if (part.Equals(q, System.StringComparison.InvariantCultureIgnoreCase)) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static bool CamelCaseMatch(string id, string query)
|
|
||||||
{
|
|
||||||
// Assert.False (q==null);
|
|
||||||
if (string.IsNullOrEmpty(query)) return true;
|
|
||||||
|
|
||||||
while (id.Length > 0)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
while (id.Length > i && char.IsLower(id[i])) i++;
|
|
||||||
if (i == 0) break;
|
|
||||||
id = id.Substring(i);
|
|
||||||
if (id.Equals(query, System.StringComparison.OrdinalIgnoreCase)) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -29,6 +29,8 @@ namespace isnd.Interfaces
|
||||||
|
|
||||||
RegistrationPageIndex GetCatalogIndex();
|
RegistrationPageIndex GetCatalogIndex();
|
||||||
RegistrationPageIndex GetPackageRegistrationIndex(RegistrationPageIndexQuery query);
|
RegistrationPageIndex GetPackageRegistrationIndex(RegistrationPageIndexQuery query);
|
||||||
|
|
||||||
|
RegistrationPageIndex SearchPackage(RegistrationPageIndexQuery query);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +186,7 @@ namespace isnd.Services
|
||||||
string baseid = extUrl + ApiConfig.Catalog;
|
string baseid = extUrl + ApiConfig.Catalog;
|
||||||
string bidreg = $"{extUrl}v3.4.0/{ApiConfig.Registration}";
|
string bidreg = $"{extUrl}v3.4.0/{ApiConfig.Registration}";
|
||||||
string basepageid = extUrl + ApiConfig.CatalogPage;
|
string basepageid = extUrl + ApiConfig.CatalogPage;
|
||||||
CurrentCatalogIndex = new RegistrationPageIndex(baseid,"index");
|
CurrentCatalogIndex = new RegistrationPageIndex();
|
||||||
CurrentCatalogPages = new List<RegistrationPage>();
|
CurrentCatalogPages = new List<RegistrationPage>();
|
||||||
|
|
||||||
var scope = dbContext.Commits.OrderBy(c => c.TimeStamp);
|
var scope = dbContext.Commits.OrderBy(c => c.TimeStamp);
|
||||||
|
|
@ -199,7 +199,6 @@ namespace isnd.Services
|
||||||
{
|
{
|
||||||
page = new RegistrationPage(basepageid, extUrl)
|
page = new RegistrationPage(basepageid, extUrl)
|
||||||
{
|
{
|
||||||
Parent = baseid,
|
|
||||||
CommitId = commit.CommitId,
|
CommitId = commit.CommitId,
|
||||||
CommitTimeStamp = commit.CommitTimeStamp
|
CommitTimeStamp = commit.CommitTimeStamp
|
||||||
};
|
};
|
||||||
|
|
@ -317,10 +316,10 @@ namespace isnd.Services
|
||||||
.Include(v => v.Package)
|
.Include(v => v.Package)
|
||||||
.Include(v => v.Package.Owner)
|
.Include(v => v.Package.Owner)
|
||||||
.Include(v => v.LatestCommit)
|
.Include(v => v.LatestCommit)
|
||||||
.Where(v => v.PackageId == pkgId && semver.Equals(v.FullString, StringComparison.OrdinalIgnoreCase)
|
.Where(v => v.PackageId.Equals(pkgId, StringComparison.InvariantCultureIgnoreCase) && semver.Equals(v.FullString, StringComparison.InvariantCultureIgnoreCase)
|
||||||
&& (pkgType == null || pkgType == v.Type))
|
&& (pkgType == null || pkgType == v.Type))
|
||||||
.OrderByDescending(p=> p.CommitId)
|
.OrderByDescending(p=> p.CommitNId)
|
||||||
.Select(p => p.Package.ToLeave(bid))
|
.Select(p => p.ToLeave(bid, extUrl))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
public PackageVersion GetPackage(string pkgId, string semver, string pkgType)
|
public PackageVersion GetPackage(string pkgId, string semver, string pkgType)
|
||||||
|
|
@ -336,8 +335,7 @@ namespace isnd.Services
|
||||||
{
|
{
|
||||||
// RegistrationPageIndexAndQuery
|
// RegistrationPageIndexAndQuery
|
||||||
var scope = dbContext.Packages.Include(p => p.Versions).Include(p => p.Owner)
|
var scope = dbContext.Packages.Include(p => p.Versions).Include(p => p.Owner)
|
||||||
.Where(p => (PackageIdHelpers.CamelCaseMatch(p.Id, query.Query)
|
.Where(p => p.Id.Equals(query.Query, StringComparison.InvariantCultureIgnoreCase)
|
||||||
|| PackageIdHelpers.SeparatedByMinusMatch(p.Id, query.Query))
|
|
||||||
&& (query.Prerelease || p.Versions.Any(v => !v.IsPrerelease)));
|
&& (query.Prerelease || p.Versions.Any(v => !v.IsPrerelease)));
|
||||||
var total = scope.Count();
|
var total = scope.Count();
|
||||||
var pkgs = scope.Skip(query.Skip).Take(query.Take).ToArray();
|
var pkgs = scope.Skip(query.Skip).Take(query.Take).ToArray();
|
||||||
|
|
@ -345,5 +343,20 @@ namespace isnd.Services
|
||||||
return
|
return
|
||||||
new RegistrationPageIndex(bid, query.Query, extUrl, pkgs);
|
new RegistrationPageIndex(bid, query.Query, extUrl, pkgs);
|
||||||
}
|
}
|
||||||
|
public RegistrationPageIndex SearchPackage(RegistrationPageIndexQuery query)
|
||||||
|
{
|
||||||
|
string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}";
|
||||||
|
// RegistrationPageIndexAndQuery
|
||||||
|
if (query.Query == null) query.Query = "";
|
||||||
|
var scope = dbContext.Packages.Include(p => p.Versions).Include(p => p.Owner)
|
||||||
|
.Where(p => p.Id.StartsWith(query.Query, StringComparison.InvariantCultureIgnoreCase)
|
||||||
|
&& (query.Prerelease || p.Versions.Any(v => !v.IsPrerelease)))
|
||||||
|
.Where(p => p.Versions.Count>0);
|
||||||
|
var total = scope.Count();
|
||||||
|
var pkgs = scope.Skip(query.Skip).Take(query.Take).ToArray();
|
||||||
|
|
||||||
|
return
|
||||||
|
new RegistrationPageIndex(bid, query.Query, extUrl, pkgs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,48 +6,31 @@
|
||||||
|
|
||||||
<h2>Index</h2>
|
<h2>Index</h2>
|
||||||
|
|
||||||
<p>
|
|
||||||
<form method="get">
|
|
||||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Query.Query" class="control-label"></label>
|
|
||||||
<input asp-for="Query.Query" class="form-control" />
|
|
||||||
<label asp-for="Query.TotalHits" class="control-label"></label>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<input type="submit" value="Find" class="btn btn-default" />
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.Result.Items[0].Id)
|
@Html.DisplayNameFor(model => model.Result.Items[0].Items[0].Entry.idp)
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.Result.Items[0].CommitId)
|
@Html.DisplayNameFor(model => model.Result.Items[0].Items[0].Entry.Description)
|
||||||
</th>
|
</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach (var page in Model.Result.Items) {
|
@foreach (var regpage in Model.Result.Items) {
|
||||||
@foreach (var item in page.Items) {
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.Id)
|
@regpage.GetPackageId()
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.Entry.Description)
|
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@Html.ActionLink("Details", "Details", new { pkgid = item.Id })
|
@Html.ActionLink("Details", "Details", new { pkgid = regpage.GetPackageId() })
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue