mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-08 00:14:31 +08:00
Code styling in AdminController, ProjectionPartDriver and QueryPartDriver
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Title.Models;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Forms.Services;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Projections.Descriptors.Filter;
|
||||
using Orchard.Projections.Descriptors.Layout;
|
||||
@@ -11,13 +15,9 @@ using Orchard.Projections.Descriptors.SortCriterion;
|
||||
using Orchard.Projections.Models;
|
||||
using Orchard.Projections.Services;
|
||||
using Orchard.Projections.ViewModels;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Notify;
|
||||
using System;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Projections.Controllers {
|
||||
[ValidateInput(false)]
|
||||
@@ -84,7 +84,7 @@ namespace Orchard.Projections.Controllers {
|
||||
|
||||
var model = new AdminIndexViewModel {
|
||||
Queries = results.Select(x => new QueryEntry {
|
||||
Query = x.As<QueryPart>().Record,
|
||||
Query = x.As<QueryPart>().Record,
|
||||
QueryId = x.Id,
|
||||
Name = x.As<QueryPart>().Name
|
||||
}).ToList(),
|
||||
@@ -158,12 +158,12 @@ namespace Orchard.Projections.Controllers {
|
||||
Category = f.Category,
|
||||
Type = f.Type,
|
||||
FilterRecordId = filter.Id,
|
||||
DisplayText = String.IsNullOrWhiteSpace(filter.Description) ? f.Display(new FilterContext {State = FormParametersHelper.ToDynamic(filter.State)}).Text : filter.Description
|
||||
DisplayText = String.IsNullOrWhiteSpace(filter.Description) ? f.Display(new FilterContext { State = FormParametersHelper.ToDynamic(filter.State) }).Text : filter.Description
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
filterGroupEntries.Add( new FilterGroupEntry { Id = group.Id, Filters = filterEntries } );
|
||||
filterGroupEntries.Add(new FilterGroupEntry { Id = group.Id, Filters = filterEntries });
|
||||
}
|
||||
|
||||
viewModel.FilterGroups = filterGroupEntries;
|
||||
@@ -185,7 +185,7 @@ namespace Orchard.Projections.Controllers {
|
||||
Category = f.Category,
|
||||
Type = f.Type,
|
||||
SortCriterionRecordId = sortCriterion.Id,
|
||||
DisplayText = String.IsNullOrWhiteSpace(sortCriterion.Description) ? f.Display(new SortCriterionContext { State = FormParametersHelper.ToDynamic(sortCriterion.State) }).Text : sortCriterion.Description
|
||||
DisplayText = String.IsNullOrWhiteSpace(sortCriterion.Description) ? f.Display(new SortCriterionContext { State = FormParametersHelper.ToDynamic(sortCriterion.State) }).Text : sortCriterion.Description
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -20,10 +20,12 @@ using Orchard.Projections.Settings;
|
||||
using Orchard.Projections.ViewModels;
|
||||
using Orchard.Tokens;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Projections.Drivers {
|
||||
public class ProjectionPartDriver : ContentPartDriver<ProjectionPart> {
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
private readonly IRepository<QueryPartRecord> _queryRepository;
|
||||
private readonly IProjectionManagerExtension _projectionManager;
|
||||
private readonly IFeedManager _feedManager;
|
||||
@@ -33,25 +35,25 @@ namespace Orchard.Projections.Drivers {
|
||||
private const string TemplateName = "Parts/ProjectionPart";
|
||||
|
||||
public ProjectionPartDriver(
|
||||
IOrchardServices services,
|
||||
IOrchardServices orchardServices,
|
||||
IRepository<QueryPartRecord> queryRepository,
|
||||
IProjectionManagerExtension projectionManager,
|
||||
IFeedManager feedManager,
|
||||
ITokenizer tokenizer,
|
||||
IDisplayHelperFactory displayHelperFactory,
|
||||
IWorkContextAccessor workContextAccessor) {
|
||||
_orchardServices = orchardServices;
|
||||
_queryRepository = queryRepository;
|
||||
_projectionManager = projectionManager;
|
||||
_feedManager = feedManager;
|
||||
_tokenizer = tokenizer;
|
||||
_displayHelperFactory = displayHelperFactory;
|
||||
_workContextAccessor = workContextAccessor;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
Services = services;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
public IOrchardServices Services { get; set; }
|
||||
|
||||
protected override string Prefix { get { return "ProjectionPart"; } }
|
||||
|
||||
@@ -59,7 +61,7 @@ namespace Orchard.Projections.Drivers {
|
||||
var query = part.Record.QueryPartRecord;
|
||||
|
||||
// retrieving paging parameters
|
||||
var queryString = Services.WorkContext.HttpContext.Request.QueryString;
|
||||
var queryString = _orchardServices.WorkContext.HttpContext.Request.QueryString;
|
||||
|
||||
var pageKey = String.IsNullOrWhiteSpace(part.Record.PagerSuffix) ? "page" : "page-" + part.Record.PagerSuffix;
|
||||
var page = 0;
|
||||
@@ -88,7 +90,7 @@ namespace Orchard.Projections.Drivers {
|
||||
}
|
||||
}
|
||||
|
||||
var pager = new Pager(Services.WorkContext.CurrentSite, page, pageSize);
|
||||
var pager = new Pager(_orchardServices.WorkContext.CurrentSite, page, pageSize);
|
||||
|
||||
var pagerShape = shapeHelper.Pager(pager)
|
||||
.ContentPart(part)
|
||||
@@ -105,7 +107,7 @@ namespace Orchard.Projections.Drivers {
|
||||
ContentShape("Parts_ProjectionPart_List", shape => {
|
||||
|
||||
// generates a link to the RSS feed for this term
|
||||
var metaData = Services.ContentManager.GetItemMetadata(part.ContentItem);
|
||||
var metaData = _orchardServices.ContentManager.GetItemMetadata(part.ContentItem);
|
||||
_feedManager.Register(metaData.DisplayText, "rss", new RouteValueDictionary { { "projection", part.Id } });
|
||||
|
||||
// execute the query
|
||||
@@ -128,8 +130,8 @@ namespace Orchard.Projections.Drivers {
|
||||
|
||||
// renders in a standard List shape if no specific layout could be found
|
||||
if (layoutDescriptor == null) {
|
||||
var list = Services.New.List();
|
||||
var contentShapes = contentItems.Select(item => Services.ContentManager.BuildDisplay(item, "Summary"));
|
||||
var list = _orchardServices.New.List();
|
||||
var contentShapes = contentItems.Select(item => _orchardServices.ContentManager.BuildDisplay(item, "Summary"));
|
||||
list.AddRange(contentShapes);
|
||||
|
||||
return list;
|
||||
@@ -141,7 +143,7 @@ namespace Orchard.Projections.Drivers {
|
||||
var layoutComponents = contentItems.Select(
|
||||
contentItem => {
|
||||
|
||||
var contentItemMetadata = Services.ContentManager.GetItemMetadata(contentItem);
|
||||
var contentItemMetadata = _orchardServices.ContentManager.GetItemMetadata(contentItem);
|
||||
|
||||
var propertyDescriptors = fieldDescriptors.Select(
|
||||
d => {
|
||||
@@ -154,9 +156,9 @@ namespace Orchard.Projections.Drivers {
|
||||
});
|
||||
|
||||
// apply all settings to the field content, wrapping it in a FieldWrapper shape
|
||||
var properties = Services.New.Properties(
|
||||
var properties = _orchardServices.New.Properties(
|
||||
Items: propertyDescriptors.Select(
|
||||
pd => Services.New.PropertyWrapper(
|
||||
pd => _orchardServices.New.PropertyWrapper(
|
||||
Item: pd.Shape,
|
||||
Property: pd.Property,
|
||||
ContentItem: contentItem,
|
||||
@@ -197,14 +199,14 @@ namespace Orchard.Projections.Drivers {
|
||||
return key;
|
||||
}).Select(x => new { Key = x.Key, Components = x });
|
||||
|
||||
var list = Services.New.List();
|
||||
var list = _orchardServices.New.List();
|
||||
foreach (var group in groups) {
|
||||
|
||||
var localResult = layoutDescriptor.Render(renderLayoutContext, group.Components);
|
||||
// add the Context to the shape
|
||||
localResult.Context(renderLayoutContext);
|
||||
|
||||
list.Add(Services.New.LayoutGroup(Key: new MvcHtmlString(group.Key), List: localResult));
|
||||
list.Add(_orchardServices.New.LayoutGroup(Key: new MvcHtmlString(group.Key), List: localResult));
|
||||
}
|
||||
|
||||
return list;
|
||||
@@ -270,7 +272,7 @@ namespace Orchard.Projections.Drivers {
|
||||
|
||||
// populating the list of queries and layouts
|
||||
var layouts = _projectionManager.DescribeLayouts().SelectMany(x => x.Descriptors).ToList();
|
||||
model.QueryRecordEntries = Services.ContentManager.Query<QueryPart, QueryPartRecord>().Join<TitlePartRecord>().OrderBy(x => x.Title).List()
|
||||
model.QueryRecordEntries = _orchardServices.ContentManager.Query<QueryPart, QueryPartRecord>().Join<TitlePartRecord>().OrderBy(x => x.Title).List()
|
||||
.Select(x => new QueryRecordEntry {
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
@@ -394,9 +396,9 @@ namespace Orchard.Projections.Drivers {
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("DisplayPager", part.Record.DisplayPager);
|
||||
|
||||
if (part.Record.QueryPartRecord != null) {
|
||||
var queryPart = Services.ContentManager.Query<QueryPart, QueryPartRecord>("Query").Where(x => x.Id == part.Record.QueryPartRecord.Id).List().FirstOrDefault();
|
||||
var queryPart = _orchardServices.ContentManager.Query<QueryPart, QueryPartRecord>("Query").Where(x => x.Id == part.Record.QueryPartRecord.Id).List().FirstOrDefault();
|
||||
if (queryPart != null) {
|
||||
var queryIdentity = Services.ContentManager.GetItemMetadata(queryPart).Identity;
|
||||
var queryIdentity = _orchardServices.ContentManager.GetItemMetadata(queryPart).Identity;
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Query", queryIdentity.ToString());
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("LayoutIndex", part.Record.QueryPartRecord.Layouts.IndexOf(part.Record.LayoutRecord));
|
||||
}
|
||||
|
@@ -19,14 +19,16 @@ namespace Orchard.Projections.Drivers {
|
||||
_projectionManager = projectionManager;
|
||||
_formManager = formManager;
|
||||
}
|
||||
|
||||
protected override string Prefix {
|
||||
get {
|
||||
return "Query_Part";
|
||||
}
|
||||
}
|
||||
protected override DriverResult Editor(QueryPart part, dynamic shapeHelper) {
|
||||
return Editor(part, null, shapeHelper);
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(QueryPart part, dynamic shapeHelper) =>
|
||||
Editor(part, null, shapeHelper);
|
||||
|
||||
protected override DriverResult Editor(QueryPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
var model = new QueryViewModel { VersionScope = part.VersionScope };
|
||||
if (updater != null) {
|
||||
|
Reference in New Issue
Block a user