search view fixed

net6
Paul Schneider 2 years ago
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")]
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
{

@ -18,7 +18,7 @@ namespace isnd.Controllers
public async Task<IActionResult> Index(RegistrationPageIndexQuery model)
{
return View(new RegistrationPageIndexQueryAndResult{Query = model,
Result = packageManager.GetPackageRegistrationIndex(model)});
Result = packageManager.SearchPackage(model)});
}
public async Task<IActionResult> Details(string pkgid)
@ -34,7 +34,7 @@ namespace isnd.Controllers
.OrderByDescending(p => p)
;
if (packageVersion == null)
if (packageVersion.Count() == 0)
{
return NotFound();
}

@ -13,10 +13,11 @@ namespace isnd.Data.Catalog
[JsonRequired]
public string Id { get; protected set;}
private string pkgid;
private List<PackageVersion> items;
protected string Bid { get ; private set; }
public string DlBase { get; }
protected string DlBase { get; }
public RegistrationPage (string bid, string dlBase)
{
@ -31,13 +32,14 @@ namespace isnd.Data.Catalog
Parent = Bid + "/index.json";
DlBase = dlBase;
this.items = new List<PackageVersion>(items);
SetPackageId(pkgid);
this.Id = Bid + "/" + pkgid + "/index.json";
this.pkgid = pkgid;
UpdateCompact();
}
protected void SetPackageId(string pkgid)
public string GetPackageId()
{
this.Id = Bid + "/" + pkgid + "/index.json";
return pkgid;
}
private void UpdateCompact()

@ -14,13 +14,12 @@ namespace isnd.Data.Catalog
[JsonProperty("@id")]
public string Id { get; protected set; }
public RegistrationPageIndex(string bid, string id)
public RegistrationPageIndex()
{
Id = bid + "/" + id + "/index.json";
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;
this.Items = new List<RegistrationPage>

@ -6,7 +6,6 @@ namespace isnd.Data.Catalog
{
public class RegistrationPageIndexQuery
{
public RegistrationPageIndexQuery()
{
}
@ -22,7 +21,5 @@ namespace isnd.Data.Catalog
[JsonProperty("take")]
public int Take { get; set; } = 25;
[JsonProperty("totalHits")]
public int TotalHits { get; set; }
}
}

@ -51,14 +51,14 @@ namespace isnd.Data.Packages
/// </summary>
/// <param name="bid">base url tu use for building the id property</param>
/// <returns></returns>
public RegistrationLeaf ToLeave(string bid)
public RegistrationLeaf ToLeave(string bid, string dlbase)
{
if (Versions.Count == 0) throw new Exception("NO VERSION");
var v = Versions.OrderBy(w => w.NugetVersion).First();
RegistrationLeaf leave = new RegistrationLeaf
{
Id = bid + Id + "/" + v.FullString + ".json",
PackageContent = v.NugetLink,
PackageContent = dlbase + "/" + v.NugetLink,
Entry = new CatalogEntry
{
Id = bid + Id + ".json",

@ -6,27 +6,9 @@ namespace isnd.Helpers
{
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;
}
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 GetPackageRegistrationIndex(RegistrationPageIndexQuery query);
RegistrationPageIndex SearchPackage(RegistrationPageIndexQuery query);
}
}

@ -186,7 +186,7 @@ namespace isnd.Services
string baseid = extUrl + ApiConfig.Catalog;
string bidreg = $"{extUrl}v3.4.0/{ApiConfig.Registration}";
string basepageid = extUrl + ApiConfig.CatalogPage;
CurrentCatalogIndex = new RegistrationPageIndex(baseid,"index");
CurrentCatalogIndex = new RegistrationPageIndex();
CurrentCatalogPages = new List<RegistrationPage>();
var scope = dbContext.Commits.OrderBy(c => c.TimeStamp);
@ -199,7 +199,6 @@ namespace isnd.Services
{
page = new RegistrationPage(basepageid, extUrl)
{
Parent = baseid,
CommitId = commit.CommitId,
CommitTimeStamp = commit.CommitTimeStamp
};
@ -317,10 +316,10 @@ namespace isnd.Services
.Include(v => v.Package)
.Include(v => v.Package.Owner)
.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))
.OrderByDescending(p=> p.CommitId)
.Select(p => p.Package.ToLeave(bid))
.OrderByDescending(p=> p.CommitNId)
.Select(p => p.ToLeave(bid, extUrl))
;
}
public PackageVersion GetPackage(string pkgId, string semver, string pkgType)
@ -336,8 +335,7 @@ namespace isnd.Services
{
// RegistrationPageIndexAndQuery
var scope = dbContext.Packages.Include(p => p.Versions).Include(p => p.Owner)
.Where(p => (PackageIdHelpers.CamelCaseMatch(p.Id, query.Query)
|| PackageIdHelpers.SeparatedByMinusMatch(p.Id, query.Query))
.Where(p => p.Id.Equals(query.Query, StringComparison.InvariantCultureIgnoreCase)
&& (query.Prerelease || p.Versions.Any(v => !v.IsPrerelease)));
var total = scope.Count();
var pkgs = scope.Skip(query.Skip).Take(query.Take).ToArray();
@ -345,5 +343,20 @@ namespace isnd.Services
return
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>
<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">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Result.Items[0].Id)
@Html.DisplayNameFor(model => model.Result.Items[0].Items[0].Entry.idp)
</th>
<th>
@Html.DisplayNameFor(model => model.Result.Items[0].CommitId)
@Html.DisplayNameFor(model => model.Result.Items[0].Items[0].Entry.Description)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var page in Model.Result.Items) {
@foreach (var item in page.Items) {
@foreach (var regpage in Model.Result.Items) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
@regpage.GetPackageId()
</td>
<td>
@Html.DisplayFor(modelItem => item.Entry.Description)
</td>
<td>
@Html.ActionLink("Details", "Details", new { pkgid = item.Id })
@Html.ActionLink("Details", "Details", new { pkgid = regpage.GetPackageId() })
</td>
</tr>
}}
}
</tbody>
</table>

Loading…