public void CollectChildContents(string html, Models.Content content) { var widgetModels = PageContentRenderHelper.ParseWidgetsFromHtml(html, true); if (widgetModels != null && widgetModels.Count > 0) { // Validate widget ids var widgetIds = widgetModels.Select(w => w.WidgetId).Distinct().ToArray(); var widgets = repository.AsQueryable<Models.Content>(c => widgetIds.Contains(c.Id)).Select(c => c.Id).ToList(); widgetIds.Where(id => widgets.All(dbId => dbId != id)).ToList().ForEach( id => { var message = RootGlobalization.ChildContent_WidgetNotFound_ById; var logMessage = string.Format("{0} Id: {1}", message, id); throw new ValidationException(() => message, logMessage); }); // Validate child content var group = widgetModels.GroupBy(w => w.AssignmentIdentifier).FirstOrDefault(g => g.Count() > 1); if (group != null) { var message = string.Format(RootGlobalization.ChildContent_AssignmentAlreadyAdded, group.First().AssignmentIdentifier); throw new ValidationException(() => message, message); } foreach (var model in widgetModels) { // Add child content only if it's not added yet (for example, it may be added when restoring / cloning a content) if (content.ChildContents.All(cc => cc.AssignmentIdentifier != model.AssignmentIdentifier)) { // Create child content var childContent = new ChildContent { Id = Guid.NewGuid(), Child = repository.AsProxy<Models.Content>(model.WidgetId), Parent = content, AssignmentIdentifier = model.AssignmentIdentifier }; content.ChildContents.Add(childContent); } } } }
/// <inheritdoc /> protected override void BuildRenderTree(RenderTreeBuilder builder) { // If _fixedEditContext changes, tear down and recreate all descendants. // This is so we can safely use the IsFixed optimization on CascadingValue, // optimizing for the common case where _fixedEditContext never changes. builder.OpenRegion(_fixedEditContext.GetHashCode()); builder.OpenElement(0, "form"); builder.AddMultipleAttributes(1, AdditionalAttributes); builder.AddAttribute(2, "id", Id); builder.AddAttribute(3, "onsubmit", _handleSubmitDelegate); builder.OpenComponent <CascadingValue <EditContext> >(4); builder.AddAttribute(5, "IsFixed", true); builder.AddAttribute(6, "Value", _fixedEditContext); builder.AddAttribute(7, "ChildContent", ChildContent?.Invoke(_fixedEditContext)); builder.CloseComponent(); builder.CloseElement(); builder.CloseRegion(); }
private IList <ChildContent> GetChildContents(Guid[] ids, bool canManageContent) { ChildContent ccAlias = null; ChildContentOption ccOptionAlias = null; Models.Content childAlias = null; ContentOption cOptionAlias = null; ContentRegion cRegionAlias = null; Region regionAlias = null; ChildContent ccAlias1 = null; Models.Content ccChildAlias = null; Models.Content historyAlias = null; ChildContent historyCcAlias = null; Models.Content historyChildAlias = null; var query = repository .AsQueryOver(() => ccAlias) .Where(Restrictions.In(NHibernate.Criterion.Projections.Property(() => ccAlias.Parent.Id), ids)) .Inner.JoinAlias(() => ccAlias.Child, () => childAlias) .Left.JoinAlias(() => childAlias.ContentOptions, () => cOptionAlias) .Left.JoinAlias(() => ccAlias.Options, () => ccOptionAlias) .Left.JoinAlias(() => childAlias.ContentRegions, () => cRegionAlias) .Left.JoinAlias(() => cRegionAlias.Region, () => regionAlias) .Left.JoinAlias(() => childAlias.ChildContents, () => ccAlias1) .Left.JoinAlias(() => ccAlias1.Child, () => ccChildAlias); if (canManageContent) { query = query .Left.JoinAlias(() => childAlias.History, () => historyAlias) .Left.JoinAlias(() => historyAlias.ChildContents, () => historyCcAlias) .Left.JoinAlias(() => historyCcAlias.Child, () => historyChildAlias); } return(query.List <ChildContent>()); }
private void CopyChildContents(IList <ChildContent> destinationChildren, IList <ChildContent> sourceChildren) { // Update all child and their options foreach (var sourceChildContent in sourceChildren) { var destinationChildContent = destinationChildren.FirstOrDefault(d => sourceChildContent.AssignmentIdentifier == d.AssignmentIdentifier); if (destinationChildContent == null) { destinationChildContent = new ChildContent(); destinationChildren.Add(destinationChildContent); } destinationChildContent.AssignmentIdentifier = sourceChildContent.AssignmentIdentifier; destinationChildContent.Child = sourceChildContent.Child; // Update all the options if (sourceChildContent.Options == null) { sourceChildContent.Options = new List <ChildContentOption>(); } if (destinationChildContent.Options == null) { destinationChildContent.Options = new List <ChildContentOption>(); } // Add new options foreach (var sourceChildOption in sourceChildContent.Options) { var destinationChildOption = destinationChildContent.Options.FirstOrDefault(o => o.Key == sourceChildOption.Key); if (destinationChildOption == null) { destinationChildOption = new ChildContentOption(); destinationChildContent.Options.Add(destinationChildOption); } sourceChildOption.CopyDataTo(destinationChildOption); destinationChildOption.ChildContent = destinationChildContent; } } }
protected override void BuildRenderTree(RenderTreeBuilder builder) { builder.OpenRegion(mFormContext.GetHashCode()); builder.OpenElement(0, "div"); builder.AddMultipleAttributes(1, AdditionalAttributes); builder.OpenComponent <CascadingValue <MFormContainerContext> >(3); builder.AddAttribute(4, "IsFixed", true); builder.AddAttribute(5, "Value", mFormContext); builder.AddAttribute(6, "ChildContent", ChildContent.Invoke(mFormContext)); builder.CloseComponent(); builder.CloseElement(); builder.OpenElement(55, "div"); builder.AddAttribute(56, "class", "m-form-row"); builder.OpenElement(55, "div"); builder.AddAttribute(56, "class", "form-group col-12"); builder.OpenElement(55, "div"); builder.AddAttribute(56, "class", "col-12"); if (EnableSaveButton) { builder.OpenElement(19, "button"); builder.AddAttribute(20, "type", "button"); builder.AddAttribute(20, "class", "m-btn m-btn-primary"); builder.AddAttribute(21, "onclick", EventCallback.Factory.Create <MouseEventArgs>(this, Click)); builder.AddContent(22, L["Save"]); builder.CloseElement(); } builder.CloseElement(); //div builder.CloseElement(); //div builder.CloseElement(); //div builder.CloseRegion(); }
private ChildContent RetrieveCorrectVersionOfChildContents(ChildContent childContent, bool canManageContent) { if (canManageContent) { return(childContent); } if (childContent.Child.Status == ContentStatus.Draft) { if (childContent.Child.Original != null && childContent.Child.Original.Status == ContentStatus.Published) { var childContentWithOriginalContent = childContent.Clone(); childContentWithOriginalContent.Child = childContent.Child.Original; return(childContentWithOriginalContent); } return(null); } return(childContent); }
/// <summary> /// Creates the framework control. /// </summary> /// <param name="context">Contains information associated with the current HTML tag.</param> /// <param name="output">A stateful HTML element used to generate an HTML tag.</param> /// <returns>The control instance.</returns> protected override IFWHtmlElement RenderControl(TagHelperContext context, TagHelperOutput output) { var options = context.Items["TemplateOptions"] as FWListOptions; if (options == null) { return(null); } context.StartInnerContent(); var content = ChildContent.GetContent(); context.EndInnerContent(); if (content != null) { // TODO: Url.Action will encode { and } characters. Is there anyway to improve the performance by removing the replaces below? content = content.Replace("%7B", "{").Replace("%7D", "}"); options.FluentConfiguration.Add(x => x.Template(content).ColumnClass(CssClass)); } return(null); }
/// <summary> /// Creates the framework control. /// </summary> /// <param name="context">Contains information associated with the current HTML tag.</param> /// <param name="output">A stateful HTML element used to generate an HTML tag.</param> /// <returns>The control instance.</returns> protected override IFWHtmlElement RenderControl(TagHelperContext context, TagHelperOutput output) { var control = new FWButtonGroupControl(Id, VisibleButtons) { Title = Title }; if (Color.HasValue) { control.Color(Color.Value); } if (Size.HasValue) { control.Size(Size.Value); } context.Items["btngroup"] = control; ChildContent.GetContent(); // Clears the group button. context.Items.Remove("btngroup"); return(control); }
private async Task ProcessParameters() { IStyled styled = Id == null ? StyledService : Priority.HasValue ? StyledService.WithId(Id, Priority.Value) : StyledService.WithId(Id); if (Classname == "blazor-styled-hide") { Classname = null; } string classname = null; string content = ChildContent.RenderAsSimpleString(); uint _currentHash = CalculateHash(content); if (content != null && content.Length > 0 && (_currentHash != _previousHash || _currentHash == _previousHash && ComposeAttributes != null)) { if (IsKeyframes) { classname = await styled.KeyframesAsync(content); } else if (Classname != null && MediaQuery == MediaQueries.None && _previousClassname == null) { //html elements await styled.CssAsync(ApplyPseudoClass(Classname), content); } else if (MediaQuery != MediaQueries.None && ClassnameChanged.HasDelegate) { //If ClassnameChanged has a delegate then @bind-Classname was used and this is a "new" style //Otherwise Classname was used and this an existing style which will be handled below content = WrapWithMediaQuery("&{" + content + "}"); classname = await styled.CssAsync(content); } else if (Classname != null && MediaQuery != MediaQueries.None && !ClassnameChanged.HasDelegate && _previousClassname == null) { //Media query support for classes where an existing Classname already exists content = WrapClass(ApplyPseudoClass(Classname), content); await styled.CssAsync(WrapWithMediaQuery(content)); } else if (Classname == null && PseudoClass == PseudoClasses.None && MediaQuery != MediaQueries.None && _previousClassname == null) { //Media queries for html elements await styled.CssAsync(GetMediaQuery(), content); } else if (Classname != null && PseudoClass != PseudoClasses.None && MediaQuery == MediaQueries.None && _previousClassname == null) { content = WrapClass(ApplyPseudoClass(Classname), content); await styled.CssAsync(content); } else { if (PseudoClass == PseudoClasses.None && MediaQuery == MediaQueries.None) { classname = await styled.CssAsync(content); } } if (ComposeAttributes == null || !ClassnameChanged.HasDelegate) { await NotifyChanged(classname); } } if (ComposeAttributes != null && ClassnameChanged.HasDelegate) { StringBuilder sb = new StringBuilder(); if (classname != null) { sb.Append(classname).Append(' '); } sb.Append(GetComposeClasses()); if (sb.Length != 0) { classname = sb.ToString().Trim(); await NotifyChanged(classname); } } if (GlobalStyle != null & classname != null && _currentHash != _previousHash) { _previousHash = _currentHash; // This needs to be done here even though it is also two lines down. Do not remove! StyledService.SetGlobalStyle(GlobalStyle, classname); } _previousHash = _currentHash; }
protected virtual IQueryOver <PagesView, PagesView> FilterQuery(IQueryOver <PagesView, PagesView> query, PagesFilter request, Junction hasnotSeoDisjunction) { PageProperties alias = null; if (!request.IncludeArchived) { query = query.Where(() => !alias.IsArchived); } if (request.OnlyMasterPages) { query = query.Where(() => alias.IsMasterPage); } else if (!request.IncludeMasterPages) { query = query.Where(() => !alias.IsMasterPage); } if (!string.IsNullOrWhiteSpace(request.SearchQuery)) { var searchQuery = string.Format("%{0}%", request.SearchQuery); query = query.Where(Restrictions.Disjunction() .Add(Restrictions.InsensitiveLike(Projections.Property(() => alias.Title), searchQuery)) .Add(Restrictions.InsensitiveLike(Projections.Property(() => alias.PageUrl), searchQuery)) .Add(Restrictions.InsensitiveLike(Projections.Property(() => alias.MetaTitle), searchQuery)) .Add(Restrictions.InsensitiveLike(Projections.Property(() => alias.MetaDescription), searchQuery)) .Add(Restrictions.InsensitiveLike(Projections.Property(() => alias.MetaKeywords), searchQuery))); } if (request.CategoryId.HasValue) { query = query.Where(Restrictions.Eq(Projections.Property(() => alias.Category.Id), request.CategoryId.Value)); } if (request.LanguageId.HasValue) { if (request.LanguageId.Value.HasDefaultValue()) { query = query.Where(Restrictions.IsNull(Projections.Property(() => alias.Language.Id))); } else { query = query.Where(Restrictions.Eq(Projections.Property(() => alias.Language.Id), request.LanguageId.Value)); } } if (request.Tags != null) { foreach (var tagKeyValue in request.Tags) { var id = tagKeyValue.Key.ToGuidOrDefault(); query = query.WithSubquery.WhereExists(QueryOver.Of <PageTag>().Where(tag => tag.Tag.Id == id && tag.Page.Id == alias.Id).Select(tag => 1)); } } if (request.Status.HasValue) { if (request.Status.Value == PageStatusFilterType.OnlyPublished) { query = query.Where(() => alias.Status == PageStatus.Published); } else if (request.Status.Value == PageStatusFilterType.OnlyUnpublished) { query = query.Where(() => alias.Status != PageStatus.Published); } else if (request.Status.Value == PageStatusFilterType.ContainingUnpublishedContents) { const ContentStatus draft = ContentStatus.Draft; Root.Models.Content contentAlias = null; var subQuery = QueryOver.Of <PageContent>() .JoinAlias(p => p.Content, () => contentAlias) .Where(pageContent => pageContent.Page.Id == alias.Id) .And(() => contentAlias.Status == draft) .And(() => !contentAlias.IsDeleted) .Select(pageContent => 1); query = query.WithSubquery.WhereExists(subQuery); } } if (request.SeoStatus.HasValue) { if (request.SeoStatus.Value == SeoStatusFilterType.HasNotSeo) { query = query.Where(hasnotSeoDisjunction); } else { query = query.Where(Restrictions.Not(hasnotSeoDisjunction)); } } if (!string.IsNullOrWhiteSpace(request.Layout)) { Guid id; var length = request.Layout.Length - 2; if (request.Layout.StartsWith("m-") && Guid.TryParse(request.Layout.Substring(2, length), out id)) { query = query.Where(() => alias.MasterPage.Id == id); } if (request.Layout.StartsWith("l-") && Guid.TryParse(request.Layout.Substring(2, length), out id)) { query = query.Where(() => alias.Layout.Id == id); } } if (request.ContentId.HasValue) { Root.Models.Content contentAlias = null; ChildContent childContentAlias = null; HtmlContent htmlContentAlias = null; PageContent pageContentAlias = null; var htmlChildContentSubQuery = QueryOver.Of(() => htmlContentAlias) .JoinAlias(h => h.ChildContents, () => childContentAlias) .Where(() => htmlContentAlias.Id == contentAlias.Id) .And(() => childContentAlias.Child.Id == request.ContentId.Value) .Select(pageContent => 1); var pageContentSubQuery = QueryOver.Of(() => pageContentAlias) .JoinAlias(() => pageContentAlias.Content, () => contentAlias) .And(() => pageContentAlias.Page.Id == alias.Id) .And(() => !contentAlias.IsDeleted) .And(() => !pageContentAlias.IsDeleted) .And(Restrictions.Or( Restrictions.Where(() => contentAlias.Id == request.ContentId.Value), Subqueries.WhereExists(htmlChildContentSubQuery) )) .Select(pageContent => 1); query = query.WithSubquery.WhereExists(pageContentSubQuery); } return(query); }
private ChildContent RetrieveCorrectVersionOfChildContents(ChildContent childContent, bool canManageContent) { if (canManageContent) { return childContent; } if (childContent.Child.Status == ContentStatus.Draft) { if (childContent.Child.Original != null && childContent.Child.Original.Status == ContentStatus.Published) { var childContentWithOriginalContent = childContent.Clone(); childContentWithOriginalContent.Child = childContent.Child.Original; return childContentWithOriginalContent; } return null; } return childContent; }
private void CopyChildContents(IList<ChildContent> destinationChildren, IList<ChildContent> sourceChildren) { // Update all child and their options foreach (var sourceChildContent in sourceChildren) { var destinationChildContent = destinationChildren.FirstOrDefault(d => sourceChildContent.AssignmentIdentifier == d.AssignmentIdentifier); if (destinationChildContent == null) { destinationChildContent = new ChildContent(); destinationChildren.Add(destinationChildContent); } destinationChildContent.AssignmentIdentifier = sourceChildContent.AssignmentIdentifier; destinationChildContent.Child = sourceChildContent.Child; // Update all the options if (sourceChildContent.Options == null) { sourceChildContent.Options = new List<ChildContentOption>(); } if (destinationChildContent.Options == null) { destinationChildContent.Options = new List<ChildContentOption>(); } // Add new options foreach (var sourceChildOption in sourceChildContent.Options) { var destinationChildOption = destinationChildContent.Options.FirstOrDefault(o => o.Key == sourceChildOption.Key); if (destinationChildOption == null) { destinationChildOption = new ChildContentOption(); destinationChildContent.Options.Add(destinationChildOption); } sourceChildOption.CopyDataTo(destinationChildOption, false); if (sourceChildOption.Translations != null) { foreach (var childContentOptionTranslation in sourceChildOption.Translations) { var languageId = childContentOptionTranslation.Language.Id; var translation = destinationChildOption.Translations.FirstOrDefault(x => x.Language.Id == languageId); if (translation == null) { translation = childContentOptionTranslation.Clone(); } else { translation.Value = childContentOptionTranslation.Value; } translation.ChildContentOption = destinationChildOption; destinationChildOption.Translations.Add(translation); } } destinationChildOption.ChildContent = destinationChildContent; } } }
public void OnChildContentConfigured(ChildContent childContent) { if (ChildContentConfigured != null) { ChildContentConfigured(new SingleItemEventArgs<ChildContent>(childContent)); } }
private void CopyChildContents(IList<ChildContent> destinationChildren, IList<ChildContent> sourceChildren) { // Update all child and their options foreach (var sourceChildContent in sourceChildren) { var destinationChildContent = destinationChildren.FirstOrDefault(d => sourceChildContent.AssignmentIdentifier == d.AssignmentIdentifier); if (destinationChildContent == null) { destinationChildContent = new ChildContent(); destinationChildren.Add(destinationChildContent); } destinationChildContent.AssignmentIdentifier = sourceChildContent.AssignmentIdentifier; destinationChildContent.Child = sourceChildContent.Child; // Update all the options if (sourceChildContent.Options == null) { sourceChildContent.Options = new List<ChildContentOption>(); } if (destinationChildContent.Options == null) { destinationChildContent.Options = new List<ChildContentOption>(); } // Add new options foreach (var sourceChildOption in sourceChildContent.Options) { var destinationChildOption = destinationChildContent.Options.FirstOrDefault(o => o.Key == sourceChildOption.Key); if (destinationChildOption == null) { destinationChildOption = new ChildContentOption(); destinationChildContent.Options.Add(destinationChildOption); } sourceChildOption.CopyDataTo(destinationChildOption); destinationChildOption.ChildContent = destinationChildContent; } } }
protected override void BuildRenderTree(RenderTreeBuilder builder) { builder.AddContent(1, ChildContent?.Invoke(Context)); base.BuildRenderTree(builder); }
/// <inheritdoc cref="ComponentBase.BuildRenderTree(RenderTreeBuilder)" /> protected override void BuildRenderTree(RenderTreeBuilder builder) { builder.OpenComponent <EditForm>(0); builder.AddAttribute(1, nameof(EditForm.Model), ModelInEdit); builder.AddAttribute(2, nameof(EditForm.OnValidSubmit), EventCallback.Factory.Create <EditContext>(this, HandleValidSubmit)); builder.AddAttribute(3, nameof(EditForm.ChildContent), (RenderFragment <EditContext>)((EditContext _) => ChildContent?.Invoke(ModelInEdit))); builder.AddAttribute(4, nameof(Id), Id); builder.AddAttribute(5, "class", "hx-form"); builder.CloseComponent(); }