mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding paging when listing Taxonomies and Taxonomy terms, fixes #4506
This commit is contained in:
@@ -9,31 +9,49 @@ using Orchard.Settings;
|
||||
using Orchard.Taxonomies.Models;
|
||||
using Orchard.Taxonomies.ViewModels;
|
||||
using Orchard.Taxonomies.Services;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.DisplayManagement;
|
||||
|
||||
namespace Orchard.Taxonomies.Controllers {
|
||||
|
||||
[ValidateInput(false)]
|
||||
public class AdminController : Controller, IUpdateModel {
|
||||
private readonly ITaxonomyService _taxonomyService;
|
||||
private readonly ISiteService _siteService;
|
||||
|
||||
public AdminController(
|
||||
IOrchardServices services,
|
||||
ITaxonomyService taxonomyService) {
|
||||
ITaxonomyService taxonomyService,
|
||||
ISiteService siteService,
|
||||
IShapeFactory shapeFactory) {
|
||||
Services = services;
|
||||
_siteService = siteService;
|
||||
_taxonomyService = taxonomyService;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
Shape = shapeFactory;
|
||||
}
|
||||
|
||||
dynamic Shape { get; set; }
|
||||
public IOrchardServices Services { get; set; }
|
||||
protected virtual ISite CurrentSite { get; private set; }
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index() {
|
||||
var taxonomies = _taxonomyService.GetTaxonomies();
|
||||
var entries = taxonomies.Select(CreateTaxonomyEntry).ToList();
|
||||
var model = new TaxonomyAdminIndexViewModel { Taxonomies = entries };
|
||||
public ActionResult Index(PagerParameters pagerParameters) {
|
||||
var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);
|
||||
|
||||
var taxonomies = _taxonomyService.GetTaxonomiesQuery().Slice(pager.GetStartIndex(), pager.PageSize);
|
||||
|
||||
var pagerShape = Shape.Pager(pager).TotalItemCount(_taxonomyService.GetTaxonomiesQuery().Count());
|
||||
|
||||
var entries = taxonomies
|
||||
.Select(CreateTaxonomyEntry)
|
||||
.ToList();
|
||||
|
||||
var model = new TaxonomyAdminIndexViewModel { Taxonomies = entries, Pager = pagerShape };
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,26 +10,52 @@ using Orchard.UI.Admin;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Taxonomies.Helpers;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.Settings;
|
||||
using Orchard.DisplayManagement;
|
||||
|
||||
namespace Orchard.Taxonomies.Controllers {
|
||||
[ValidateInput(false), Admin]
|
||||
public class TermAdminController : Controller, IUpdateModel {
|
||||
private readonly ITaxonomyService _taxonomyService;
|
||||
private readonly ISiteService _siteService;
|
||||
|
||||
public TermAdminController(IOrchardServices services, ITaxonomyService taxonomyService) {
|
||||
public TermAdminController(IOrchardServices services,
|
||||
ITaxonomyService taxonomyService,
|
||||
ISiteService siteService,
|
||||
IShapeFactory shapeFactory) {
|
||||
Services = services;
|
||||
_siteService = siteService;
|
||||
_taxonomyService = taxonomyService;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
Shape = shapeFactory;
|
||||
}
|
||||
|
||||
dynamic Shape { get; set; }
|
||||
public IOrchardServices Services { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ActionResult Index(int taxonomyId) {
|
||||
public ActionResult Index(int taxonomyId, PagerParameters pagerParameters) {
|
||||
var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);
|
||||
|
||||
var taxonomy = _taxonomyService.GetTaxonomy(taxonomyId);
|
||||
var terms = _taxonomyService.GetTerms(taxonomyId);
|
||||
var entries = terms.Select(term => term.CreateTermEntry()).ToList();
|
||||
var model = new TermAdminIndexViewModel { Terms = entries, Taxonomy = taxonomy, TaxonomyId = taxonomyId };
|
||||
|
||||
var terms = _taxonomyService.GetTermsQuery(taxonomyId).Slice(pager.GetStartIndex(), pager.PageSize);
|
||||
|
||||
var pagerShape = Shape.Pager(pager).TotalItemCount(_taxonomyService.GetTermsQuery(taxonomyId).Count());
|
||||
|
||||
var entries = terms
|
||||
.Select(term => term.CreateTermEntry())
|
||||
.ToList();
|
||||
|
||||
var model = new TermAdminIndexViewModel {
|
||||
Terms = entries,
|
||||
Taxonomy = taxonomy,
|
||||
TaxonomyId = taxonomyId,
|
||||
Pager = pagerShape
|
||||
};
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
@@ -83,7 +109,7 @@ namespace Orchard.Taxonomies.Controllers {
|
||||
if (!Services.Authorizer.Authorize(Permissions.CreateTerm, T("Not allowed to create terms")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var terms = _taxonomyService.GetTerms(taxonomyId).ToList();
|
||||
var terms = _taxonomyService.GetTerms(taxonomyId);
|
||||
|
||||
if (terms.Any()) {
|
||||
var model = new SelectTermViewModel {
|
||||
|
||||
@@ -37,6 +37,8 @@ namespace Orchard.Taxonomies.Services {
|
||||
/// <param name="taxonomy">The taxonomy to delete.</param>
|
||||
/// <remarks>It will also remove all its terms and delete their content type.</remarks>
|
||||
void DeleteTaxonomy(TaxonomyPart taxonomy);
|
||||
IContentQuery<TaxonomyPart, TaxonomyPartRecord> GetTaxonomiesQuery();
|
||||
|
||||
|
||||
IEnumerable<TermPart> GetTerms(int taxonomyId);
|
||||
TermPart GetTerm(int id);
|
||||
@@ -44,6 +46,7 @@ namespace Orchard.Taxonomies.Services {
|
||||
void DeleteTerm(TermPart termPart);
|
||||
void MoveTerm(TaxonomyPart taxonomy, TermPart term, TermPart parentTerm);
|
||||
void ProcessPath(TermPart term);
|
||||
IContentQuery<TermPart, TermPartRecord> GetTermsQuery(int taxonomyId);
|
||||
|
||||
string GenerateTermTypeName(string taxonomyName);
|
||||
|
||||
|
||||
@@ -390,5 +390,13 @@ namespace Orchard.Taxonomies.Services {
|
||||
Level = part.Path.Count(x => x == '/')
|
||||
};
|
||||
}
|
||||
|
||||
public IContentQuery<TaxonomyPart, TaxonomyPartRecord> GetTaxonomiesQuery() {
|
||||
return _contentManager.Query<TaxonomyPart, TaxonomyPartRecord>();
|
||||
}
|
||||
|
||||
public IContentQuery<TermPart, TermPartRecord> GetTermsQuery(int taxonomyId) {
|
||||
return _contentManager.Query<TermPart, TermPartRecord>().Where(x => x.TaxonomyId == taxonomyId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Orchard.Taxonomies.ViewModels {
|
||||
public class TaxonomyAdminIndexViewModel {
|
||||
public IList<TaxonomyEntry> Taxonomies { get; set; }
|
||||
public TaxonomiesAdminIndexBulkAction BulkAction { get; set; }
|
||||
public dynamic Pager { get; set; }
|
||||
}
|
||||
|
||||
public class TaxonomyEntry {
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Orchard.Taxonomies.ViewModels {
|
||||
public TermsAdminIndexBulkAction BulkAction { get; set; }
|
||||
public TaxonomyPart Taxonomy { get; set; }
|
||||
public int TaxonomyId { get; set; }
|
||||
public dynamic Pager { get; set; }
|
||||
}
|
||||
|
||||
public class TermEntry {
|
||||
|
||||
@@ -60,5 +60,6 @@
|
||||
taxonomyIndex++;
|
||||
}
|
||||
</table>
|
||||
@Display(Model.Pager)
|
||||
</fieldset>
|
||||
}
|
||||
@@ -51,5 +51,6 @@
|
||||
termIndex++;
|
||||
}
|
||||
</table>
|
||||
@Display(Model.Pager)
|
||||
</fieldset>
|
||||
}
|
||||
Reference in New Issue
Block a user