public Task<dynamic> UpdateTypeEditorAsync(ContentTypeDefinition contentTypeDefinition, IUpdateModel updater, string groupId) { if (contentTypeDefinition == null) { throw new ArgumentNullException(nameof(contentTypeDefinition)); } dynamic contentTypeDefinitionShape = CreateContentShape("ContentTypeDefinition_Edit"); contentTypeDefinitionShape.ContentTypeDefinition = contentTypeDefinition; _contentDefinitionManager.AlterTypeDefinition(contentTypeDefinition.Name, typeBuilder => { var typeContext = new UpdateTypeEditorContext( typeBuilder, contentTypeDefinitionShape, groupId, _shapeFactory, _layoutAccessor.GetLayout(), updater ); BindPlacementAsync(typeContext).Wait(); _handlers.InvokeAsync(handler => handler.UpdateTypeEditorAsync(contentTypeDefinition, typeContext), Logger).Wait(); }); return Task.FromResult<dynamic>(contentTypeDefinitionShape); }
public override IDisplayResult Edit(ContentTypeDefinition contentTypeDefinition) { return Shape<ContentTypeViewModel>("ContentType_Edit", model => { model.DisplayName = contentTypeDefinition.DisplayName; return Task.CompletedTask; }).Location("Content"); }
public Task UpdateTypeEditorAsync(ContentTypeDefinition model, UpdateTypeEditorContext context) { return _typeDisplayDrivers.InvokeAsync(async contentDisplay => { var result = await contentDisplay.UpdateEditorAsync(model, context); if (result != null) result.Apply(context); }, Logger); }
public override async Task<IDisplayResult> UpdateAsync(ContentTypeDefinition contentTypeDefinition, UpdateTypeEditorContext context) { var model = new ContentTypeSettingsViewModel(); if (await context.Updater.TryUpdateModelAsync(model, Prefix)) { context.Builder.Creatable(model.Creatable); context.Builder.Listable(model.Listable); context.Builder.Draftable(model.Draftable); context.Builder.Securable(model.Securable); context.Builder.Stereotype(model.Stereotype); } return Edit(contentTypeDefinition, context.Updater); }
public override IDisplayResult Edit(ContentTypeDefinition contentTypeDefinition) { return Shape<ContentTypeSettingsViewModel>("ContentTypeSettings_Edit", model => { var settings = contentTypeDefinition.Settings.ToObject<ContentTypeSettings>(); model.Creatable = settings.Creatable; model.Listable = settings.Listable; model.Draftable = settings.Draftable; model.Securable = settings.Securable; model.Stereotype = settings.Stereotype; return Task.CompletedTask; }).Location("Content:5"); }
public override async Task<IDisplayResult> UpdateAsync(ContentTypeDefinition contentTypeDefinition, UpdateTypeEditorContext context) { var model = new ContentTypeViewModel(); await context.Updater.TryUpdateModelAsync(model, Prefix); context.Builder.DisplayedAs(model.DisplayName); if (String.IsNullOrWhiteSpace(model.DisplayName)) { context.Updater.ModelState.AddModelError("DisplayName", T["The Content Type name can't be empty."]); } return Edit(contentTypeDefinition, context.Updater); }
public ContentTypeDefinitionBuilder(ContentTypeDefinition existing) { Current = existing; if (existing == null) { _parts = new List<ContentTypePartDefinition>(); _settings = new JObject(); } else { _name = existing.Name; _displayName = existing.DisplayName; _parts = existing.Parts.ToList(); _settings = new JObject(existing.Settings); } }
public async Task<dynamic> BuildTypeEditorAsync(ContentTypeDefinition contentTypeDefinition, IUpdateModel updater, string groupId) { if (contentTypeDefinition == null) { throw new ArgumentNullException(nameof(contentTypeDefinition)); } dynamic contentTypeDefinitionShape = CreateContentShape("ContentTypeDefinition_Edit"); contentTypeDefinitionShape.ContentTypeDefinition = contentTypeDefinition; var typeContext = new BuildEditorContext( contentTypeDefinitionShape, groupId, _shapeFactory, _layoutAccessor.GetLayout(), updater ); await BindPlacementAsync(typeContext); await _handlers.InvokeAsync(handler => handler.BuildTypeEditorAsync(contentTypeDefinition, typeContext), Logger); return contentTypeDefinitionShape; }
public void StoreTypeDefinition(ContentTypeDefinition contentTypeDefinition) { Apply(contentTypeDefinition, Acquire(contentTypeDefinition)); UpdateContentDefinitionRecord(); }
ContentTypeDefinition Build(ContentTypeDefinitionRecord source) { if(source == null) { return null; } var contentTypeDefinition = new ContentTypeDefinition( source.Name, source.DisplayName, source.ContentTypePartDefinitionRecords.Select(Build), source.Settings); return contentTypeDefinition; }
private void Apply(ContentTypeDefinition model, ContentTypeDefinitionRecord record) { record.DisplayName = model.DisplayName; record.Settings = model.Settings; var toRemove = record.ContentTypePartDefinitionRecords .Where(typePartDefinitionRecord => !model.Parts.Any(part => typePartDefinitionRecord.Name == part.Name)) .ToList(); foreach (var remove in toRemove) { record.ContentTypePartDefinitionRecords.Remove(remove); } foreach (var part in model.Parts) { var typePartRecord = record.ContentTypePartDefinitionRecords.FirstOrDefault(r => r.Name == part.Name); if (typePartRecord == null) { typePartRecord = new ContentTypePartDefinitionRecord { PartName = part.PartDefinition.Name, Name = part.Name, Settings = part.Settings }; record.ContentTypePartDefinitionRecords.Add(typePartRecord); } Apply(part, typePartRecord); } // Persist changes UpdateContentDefinitionRecord(); }
private ContentTypeDefinitionRecord Acquire(ContentTypeDefinition contentTypeDefinition) { var result = GetContentDefinitionRecord().ContentTypeDefinitionRecords.FirstOrDefault(x => x.Name == contentTypeDefinition.Name); if (result == null) { result = new ContentTypeDefinitionRecord { Name = contentTypeDefinition.Name, DisplayName = contentTypeDefinition.DisplayName }; GetContentDefinitionRecord().ContentTypeDefinitionRecords.Add(result); } return result; }
public ContentTypeDefinition AddType(string name, string displayName) { if (String.IsNullOrWhiteSpace(displayName)) { throw new ArgumentException(nameof(displayName)); } if (String.IsNullOrWhiteSpace(name)) { name = GenerateContentTypeNameFromDisplayName(displayName); } else { if (!name[0].IsLetter()) { throw new ArgumentException("Content type name must start with a letter", "name"); } } while (_contentDefinitionManager.GetTypeDefinition(name) != null) name = VersionName(name); var contentTypeDefinition = new ContentTypeDefinition(name, displayName); _contentDefinitionManager.StoreTypeDefinition(contentTypeDefinition); _contentDefinitionManager.AlterTypeDefinition(name, cfg => cfg.Creatable().Draftable().Listable().Securable()); _eventBus.Notify<IContentDefinitionEventHandler>(x => x.ContentTypeCreated(new ContentTypeCreatedContext { ContentTypeDefinition = contentTypeDefinition })); return contentTypeDefinition; }
public void AlterTypePartsOrder(ContentTypeDefinition typeDefinition, string[] partNames) { _contentDefinitionManager.AlterTypeDefinition(typeDefinition.Name, type => { for (var i = 0; i < partNames.Length; i++) { var partDefinition = typeDefinition.Parts.FirstOrDefault(x => x.Name == partNames[i]); type.WithPart(partNames[i], partDefinition.PartDefinition, part => { part.WithSetting("Position", i.ToString()); }); } }); }