Make created parts attachable by default

Also sort the parts by name in the "ListParts" page

Work Item: 17115

--HG--
branch : 1.x
This commit is contained in:
Renaud Paquay
2011-01-07 23:40:20 -08:00
parent ddb728c181
commit b3e13ed1a3
3 changed files with 19 additions and 12 deletions

View File

@@ -141,7 +141,7 @@ namespace Orchard.ContentTypes.Controllers {
var viewModel = new AddPartsViewModel {
Type = typeViewModel,
PartSelections = _contentDefinitionService.GetParts()
PartSelections = _contentDefinitionService.GetParts(false/*metadataPartsOnly*/)
.Where(cpd => !typeViewModel.Parts.Any(p => p.PartDefinition.Name == cpd.Name) && cpd.Settings.GetModel<ContentPartSettings>().Attachable)
.Select(cpd => new PartSelectionViewModel { PartName = cpd.Name, PartDisplayName = cpd.DisplayName })
};
@@ -226,7 +226,7 @@ namespace Orchard.ContentTypes.Controllers {
public ActionResult ListParts() {
return View(new ListContentPartsViewModel {
// only user-defined parts (not code as they are not configurable)
Parts = _contentDefinitionManager.ListPartDefinitions().Select(cpd => new EditPartViewModel(cpd))
Parts = _contentDefinitionService.GetParts(true/*metadataPartsOnly*/)
});
}

View File

@@ -152,15 +152,23 @@ namespace Orchard.ContentTypes.Services {
_contentDefinitionManager.AlterTypeDefinition(typeName, typeBuilder => typeBuilder.RemovePart(partName));
}
public IEnumerable<EditPartViewModel> GetParts() {
public IEnumerable<EditPartViewModel> GetParts(bool metadataPartsOnly) {
var typeNames = GetTypes().Select(ctd => ctd.Name);
// user-defined parts
var contentParts = _contentDefinitionManager.ListPartDefinitions().Select(cpd => new EditPartViewModel(cpd));
// except for those parts with the same name as a type (implicit type's part or a mistake)
var userContentParts = _contentDefinitionManager
.ListPartDefinitions()
.Where(cpd => !typeNames.Contains(cpd.Name))
.Select(cpd => new EditPartViewModel(cpd));
// code-defined parts
var codeDefinedParts = _contentPartDrivers
.SelectMany(d => d.GetPartInfo().Where(cpd => !contentParts.Any(m => m.Name == cpd.PartName)).Select(cpi => new EditPartViewModel { Name = cpi.PartName }));
// all together now, except for those parts with the same name as a type (implicit type's part or a mistake)
return contentParts.Where(m => !typeNames.Contains(m.Name)).Union(codeDefinedParts).OrderBy(m => m.Name);
var codeDefinedParts = metadataPartsOnly ?
Enumerable.Empty<EditPartViewModel>() :
_contentPartDrivers.SelectMany(d => d.GetPartInfo().Where(cpd => !userContentParts.Any(m => m.Name == cpd.PartName)).Select(cpi => new EditPartViewModel { Name = cpi.PartName }));
// Order by display name
return userContentParts.Union(codeDefinedParts).OrderBy(m => m.DisplayName);
}
public EditPartViewModel GetPart(string name) {
@@ -183,9 +191,8 @@ namespace Orchard.ContentTypes.Services {
name = VersionName(name);
if (!String.IsNullOrEmpty(name)) {
var contentPartDefinition = new ContentPartDefinition(name);
_contentDefinitionManager.StorePartDefinition(contentPartDefinition);
return new EditPartViewModel(contentPartDefinition);
_contentDefinitionManager.AlterPartDefinition(name, builder => builder.Attachable());
return new EditPartViewModel(_contentDefinitionManager.GetPartDefinition(name));
}
return null;

View File

@@ -15,7 +15,7 @@ namespace Orchard.ContentTypes.Services {
void RemovePartFromType(string partName, string typeName);
string GenerateName(string displayName);
IEnumerable<EditPartViewModel> GetParts();
IEnumerable<EditPartViewModel> GetParts(bool metadataPartsOnly);
EditPartViewModel GetPart(string name);
EditPartViewModel AddPart(CreatePartViewModel partViewModel);
void AlterPart(EditPartViewModel partViewModel, IUpdateModel updater);