From 95600facf4ccdaa104532acffdba961ce99f4dfb Mon Sep 17 00:00:00 2001
From: Paul Schneider
Date: Mon, 17 Oct 2022 19:17:04 +0100
Subject: [PATCH] search view fixed
---
src/isnd/Controllers/Packages/Catalog.cs | 6 ++--
src/isnd/Controllers/Packages/WebViews.cs | 4 +--
src/isnd/Data/Catalog/RegistrationPage.cs | 10 +++---
.../Data/Catalog/RegistrationPageIndex.cs | 5 ++-
.../Catalog/RegistrationPageIndexQuery.cs | 3 --
src/isnd/Data/Packages/Package.cs | 4 +--
src/isnd/Helpers/PackageIdHelpers.cs | 20 +-----------
src/isnd/Interfaces/IPackageManager.cs | 2 ++
src/isnd/Services/PackageManager.cs | 27 +++++++++++-----
src/isnd/Views/Packages/Index.cshtml | 31 +++++--------------
10 files changed, 45 insertions(+), 67 deletions(-)
diff --git a/src/isnd/Controllers/Packages/Catalog.cs b/src/isnd/Controllers/Packages/Catalog.cs
index f0e7b78..e735b2b 100644
--- a/src/isnd/Controllers/Packages/Catalog.cs
+++ b/src/isnd/Controllers/Packages/Catalog.cs
@@ -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
{
@@ -39,8 +39,8 @@ namespace isnd.Controllers
// query.TotalHits = result.Items.Select(i=>i.Items.Length).Aggregate((a,b)=>a+b);
return Ok(index);
}
- var leaf = packageManager.SearchById(id,lower,null);
- if (leaf.Count()==0) return NotFound(new { id, lower });
+ var leaf = packageManager.SearchById(id, lower, null);
+ if (leaf.Count() == 0) return NotFound(new { id, lower });
return Ok(leaf.First());
}
diff --git a/src/isnd/Controllers/Packages/WebViews.cs b/src/isnd/Controllers/Packages/WebViews.cs
index da886f2..12f5af7 100644
--- a/src/isnd/Controllers/Packages/WebViews.cs
+++ b/src/isnd/Controllers/Packages/WebViews.cs
@@ -18,7 +18,7 @@ namespace isnd.Controllers
public async Task Index(RegistrationPageIndexQuery model)
{
return View(new RegistrationPageIndexQueryAndResult{Query = model,
- Result = packageManager.GetPackageRegistrationIndex(model)});
+ Result = packageManager.SearchPackage(model)});
}
public async Task Details(string pkgid)
@@ -34,7 +34,7 @@ namespace isnd.Controllers
.OrderByDescending(p => p)
;
- if (packageVersion == null)
+ if (packageVersion.Count() == 0)
{
return NotFound();
}
diff --git a/src/isnd/Data/Catalog/RegistrationPage.cs b/src/isnd/Data/Catalog/RegistrationPage.cs
index 0da3ec7..bb1b1fb 100644
--- a/src/isnd/Data/Catalog/RegistrationPage.cs
+++ b/src/isnd/Data/Catalog/RegistrationPage.cs
@@ -13,10 +13,11 @@ namespace isnd.Data.Catalog
[JsonRequired]
public string Id { get; protected set;}
+ private string pkgid;
private List 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(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()
diff --git a/src/isnd/Data/Catalog/RegistrationPageIndex.cs b/src/isnd/Data/Catalog/RegistrationPageIndex.cs
index 6a7d7eb..f7097a4 100644
--- a/src/isnd/Data/Catalog/RegistrationPageIndex.cs
+++ b/src/isnd/Data/Catalog/RegistrationPageIndex.cs
@@ -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();
}
- public RegistrationPageIndex(string bid, string id, string dlBase, IEnumerable pkgs) : this(bid, id)
+ public RegistrationPageIndex(string bid, string id, string dlBase, IEnumerable pkgs)
{
// leaves;
this.Items = new List
diff --git a/src/isnd/Data/Catalog/RegistrationPageIndexQuery.cs b/src/isnd/Data/Catalog/RegistrationPageIndexQuery.cs
index 41f5e89..33d5696 100644
--- a/src/isnd/Data/Catalog/RegistrationPageIndexQuery.cs
+++ b/src/isnd/Data/Catalog/RegistrationPageIndexQuery.cs
@@ -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; }
}
}
\ No newline at end of file
diff --git a/src/isnd/Data/Packages/Package.cs b/src/isnd/Data/Packages/Package.cs
index a33f74f..dfa91aa 100644
--- a/src/isnd/Data/Packages/Package.cs
+++ b/src/isnd/Data/Packages/Package.cs
@@ -51,14 +51,14 @@ namespace isnd.Data.Packages
///
/// base url tu use for building the id property
///
- 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",
diff --git a/src/isnd/Helpers/PackageIdHelpers.cs b/src/isnd/Helpers/PackageIdHelpers.cs
index a16b02c..28d2c97 100644
--- a/src/isnd/Helpers/PackageIdHelpers.cs
+++ b/src/isnd/Helpers/PackageIdHelpers.cs
@@ -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;
- }
-
}
}
\ No newline at end of file
diff --git a/src/isnd/Interfaces/IPackageManager.cs b/src/isnd/Interfaces/IPackageManager.cs
index 8087ed4..f2d2448 100644
--- a/src/isnd/Interfaces/IPackageManager.cs
+++ b/src/isnd/Interfaces/IPackageManager.cs
@@ -29,6 +29,8 @@ namespace isnd.Interfaces
RegistrationPageIndex GetCatalogIndex();
RegistrationPageIndex GetPackageRegistrationIndex(RegistrationPageIndexQuery query);
+
+ RegistrationPageIndex SearchPackage(RegistrationPageIndexQuery query);
}
}
\ No newline at end of file
diff --git a/src/isnd/Services/PackageManager.cs b/src/isnd/Services/PackageManager.cs
index 78c9eff..3a11ab1 100644
--- a/src/isnd/Services/PackageManager.cs
+++ b/src/isnd/Services/PackageManager.cs
@@ -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();
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);
+ }
}
}
\ No newline at end of file
diff --git a/src/isnd/Views/Packages/Index.cshtml b/src/isnd/Views/Packages/Index.cshtml
index fcebfdc..7a80ad9 100644
--- a/src/isnd/Views/Packages/Index.cshtml
+++ b/src/isnd/Views/Packages/Index.cshtml
@@ -6,48 +6,31 @@
Index
-
-
-
-
- @Html.DisplayNameFor(model => model.Result.Items[0].Id)
+ @Html.DisplayNameFor(model => model.Result.Items[0].Items[0].Entry.idp)
|
- @Html.DisplayNameFor(model => model.Result.Items[0].CommitId)
+ @Html.DisplayNameFor(model => model.Result.Items[0].Items[0].Entry.Description)
|
|
-@foreach (var page in Model.Result.Items) {
-@foreach (var item in page.Items) {
+@foreach (var regpage in Model.Result.Items) {
- @Html.DisplayFor(modelItem => item.Id)
-
+ @regpage.GetPackageId()
|
- @Html.DisplayFor(modelItem => item.Entry.Description)
+
|
- @Html.ActionLink("Details", "Details", new { pkgid = item.Id })
+ @Html.ActionLink("Details", "Details", new { pkgid = regpage.GetPackageId() })
|
-}}
+}