Skip to content

Commit

Permalink
add filter by content type to widget duplicator
Browse files Browse the repository at this point in the history
  • Loading branch information
ninianne98 committed Apr 19, 2024
1 parent 33c8bab commit 322627b
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 63 deletions.
21 changes: 13 additions & 8 deletions CMSAdmin/Models/DuplicateWidgetFromModel.cs
Expand Up @@ -41,6 +41,10 @@ public DuplicateWidgetFromModel(Guid id, string ph)
[Display(Name = "Hide Inactive Results")]
public bool HideInactive { get; set; }


[Display(Name = "Content Type")]
public ContentPageType.PageType ContentType { get; set; } = ContentPageType.PageType.Unknown;

public string PlaceholderName { get; set; }
public Guid Root_ContentID { get; set; }

Expand All @@ -56,16 +60,17 @@ public DuplicateWidgetFromModel(Guid id, string ph)
public int CopyCount { get; set; }

public void SearchOne() {
int iTake = 25;
this.SelectedPage = null;
this.Widgets = null;
int iTake = 50;
this.SelectedPage = new ContentPage();
this.Widgets = new List<Widget>();
this.Pages = new List<SiteNav>();
this.SelectedItem = Guid.Empty;
this.TotalPages = 0;

using (ISiteNavHelper navHelper = SiteNavFactory.GetSiteNavHelper()) {
if (!String.IsNullOrEmpty(this.SearchFor)) {
this.TotalPages = navHelper.GetSiteSearchCount(SiteData.CurrentSiteID, this.SearchFor, this.HideInactive);
this.Pages = navHelper.GetLatestContentSearchList(SiteData.CurrentSiteID, this.SearchFor, this.HideInactive, iTake, 0, "NavMenuText", "ASC");
if (!string.IsNullOrEmpty(this.SearchFor)) {
this.TotalPages = navHelper.GetContentSearchListCount(SiteData.CurrentSiteID, this.SearchFor, this.HideInactive, this.ContentType, SearchContentPortion.All);
this.Pages = navHelper.GetContentSearchList(SiteData.CurrentSiteID, this.SearchFor, this.HideInactive, iTake, 0, this.ContentType, SearchContentPortion.All, "EditDate", "DESC");
}
}
}
Expand All @@ -74,7 +79,7 @@ public DuplicateWidgetFromModel(Guid id, string ph)
this.Widgets = null;
this.Pages = null;

using (ContentPageHelper pageHelper = new ContentPageHelper()) {
using (var pageHelper = new ContentPageHelper()) {
this.SelectedPage = pageHelper.FindContentByID(SiteData.CurrentSiteID, this.SelectedItem);
this.Widgets = this.SelectedPage.GetWidgetList();
}
Expand All @@ -85,7 +90,7 @@ public DuplicateWidgetFromModel(Guid id, string ph)
if (this.Widgets != null) {
List<Guid> lstSel = this.Widgets.Where(x => x.Selected).Select(x => x.Root_WidgetID).ToList();

using (ContentPageHelper pageHelper = new ContentPageHelper()) {
using (var pageHelper = new ContentPageHelper()) {
this.SelectedPage = pageHelper.FindContentByID(SiteData.CurrentSiteID, this.SelectedItem);
this.Widgets = this.SelectedPage.GetWidgetList();
}
Expand Down
118 changes: 63 additions & 55 deletions CMSAdmin/Views/CmsAdmin/DuplicateWidgetFrom.cshtml
Expand Up @@ -79,7 +79,6 @@
<legend>
<label>
Search

@Html.Partial("_displayErrorPopupButton")
</label>
</legend>
Expand All @@ -95,15 +94,27 @@
<b class="caption">hide inactive results: </b>
@Html.CheckBoxFor(m => m.HideInactive)
</div>
<div>
<b class="caption">show content: <br /> </b>
<div class="jqradioset">
@Html.RadioButtonFor(i => i.ContentType, ContentPageType.PageType.Unknown, new { GroupName = "rdoSelectedSearch", id = "rdoSelectedSearch1" })
<label for="rdoSelectedSearch1">Show All</label>

@Html.RadioButtonFor(i => i.ContentType, ContentPageType.PageType.BlogEntry, new { GroupName = "rdoSelectedSearch", id = "rdoSelectedSearch2" })
<label for="rdoSelectedSearch2">Blog</label>

@Html.RadioButtonFor(i => i.ContentType, ContentPageType.PageType.ContentEntry, new { GroupName = "rdoSelectedSearch", id = "rdoSelectedSearch3" })
<label for="rdoSelectedSearch3">Content Page</label>
</div>
</div>
<br />

@if (!String.IsNullOrEmpty(Model.SearchFor) && Model.StepNumber >= 1) {
@if (!string.IsNullOrEmpty(Model.SearchFor) && Model.StepNumber >= 1) {

if (Model.SelectedItem == Guid.Empty && Model.StepNumber == 1) {
// step 1 results

var gridOne = CarrotWeb.CarrotWebGrid<SiteNav>
(Model.Pages);
var gridOne = CarrotWeb.CarrotWebGrid<SiteNav>(Model.Pages);

gridOne.TableAttributes = new { @class = "datatable" };
gridOne.THeadAttributes = new { @class = "tablehead" };
Expand Down Expand Up @@ -133,32 +144,32 @@
</text>
})

.AddColumn(x => x.NavMenuText, new CarrotGridColumn())
.AddColumn(x => x.FileName, new CarrotGridColumn())

.AddColumn(x => x.EditDate, new CarrotGridColumn { CellFormatString = Helper.ShortDateFormatPattern })
.AddColumn(x => x.CreateDate, new CarrotGridColumn { CellFormatString = Helper.ShortDateFormatPattern })
.AddColumn(x => x.GoLiveDate, new CarrotGridColumn { CellFormatString = Helper.ShortDateFormatPattern })

.AddColumn(x => x.ContentType, new CarrotGridImageColumn {
ImagePairs = typeImgs
})
.AddColumn(x => x.PageActive, new CarrotGridBooleanImageColumn {
AlternateTextTrue = "Active",
AlternateTextFalse = "Inactive",
Sortable = true
});

<div>
@if (Model.TotalPages > Model.Pages.Count) {
@String.Format("Showing {0} of {1} total results", Model.Pages.Count, Model.TotalPages);
} else {
@String.Format("Showing {0} results", Model.Pages.Count);
}
</div>
<div>
@gridOne.OutputHtmlBody()
</div>
.AddColumn(x => x.NavMenuText, new CarrotGridColumn())
.AddColumn(x => x.FileName, new CarrotGridColumn())

.AddColumn(x => x.EditDate, new CarrotGridColumn { CellFormatString = Helper.ShortDateFormatPattern })
.AddColumn(x => x.CreateDate, new CarrotGridColumn { CellFormatString = Helper.ShortDateFormatPattern })
.AddColumn(x => x.GoLiveDate, new CarrotGridColumn { CellFormatString = Helper.ShortDateFormatPattern })

.AddColumn(x => x.ContentType, new CarrotGridImageColumn {
ImagePairs = typeImgs
})
.AddColumn(x => x.PageActive, new CarrotGridBooleanImageColumn {
AlternateTextTrue = "Active",
AlternateTextFalse = "Inactive",
Sortable = true
});

<div>
@if (Model.TotalPages > Model.Pages.Count) {
@String.Format("Showing {0} of {1} total results", Model.Pages.Count, Model.TotalPages);
} else {
@String.Format("Showing {0} results", Model.Pages.Count);
}
</div>
<div>
@gridOne.OutputHtmlBody()
</div>
}

if (Model.SelectedItem != Guid.Empty && Model.StepNumber == 2) {
Expand All @@ -177,8 +188,7 @@
<input type="button" name="btnSave" value="Duplicate" id="btnSave" onclick="DuplicateItems()" /> <br />
}

var gridTwo = CarrotWeb.CarrotWebGrid<Widget>
(Model.Widgets);
var gridTwo = CarrotWeb.CarrotWebGrid<Widget>(Model.Widgets);

gridTwo.TableAttributes = new { @class = "datatable" };
gridTwo.THeadAttributes = new { @class = "tablehead" };
Expand All @@ -197,28 +207,27 @@
</text>
})

.AddColumn(new CarrotGridTemplateColumn<Widget> {
HasHeadingText = false,
BodyAttributes = new { @class = "centerItem" },
FormatTemplate = @<text>
<a class="dataPopupTrigger" rel="@item.Root_WidgetID" href="javascript:void(0)">
<img src="~/Assets/Admin/images/doc.png" alt="text" style="margin:0;" />
</a>
</text>
})

.AddColumn(x => x.EditDate, new CarrotGridColumn { CellFormatString = Helper.ShortDateFormatPattern })
.AddColumn(x => x.PlaceholderName, new CarrotGridColumn())
.AddColumn(x => x.ControlPath, new CarrotGridColumn())
.AddColumn(x => x.IsWidgetActive, new CarrotGridBooleanImageColumn {
AlternateTextTrue = "Active",
AlternateTextFalse = "Inactive",
Sortable = true
});

<div>
@gridTwo.OutputHtmlBody()
</div>
.AddColumn(new CarrotGridTemplateColumn<Widget> {
HasHeadingText = false,
BodyAttributes = new { @class = "centerItem" },
FormatTemplate = @<text>
<a class="dataPopupTrigger" rel="@item.Root_WidgetID" href="javascript:void(0)">
<img src="~/Assets/Admin/images/doc.png" alt="text" style="margin:0;" />
</a>
</text>
})
.AddColumn(x => x.EditDate, new CarrotGridColumn { CellFormatString = Helper.ShortDateFormatPattern })
.AddColumn(x => x.PlaceholderName, new CarrotGridColumn())
.AddColumn(x => x.ControlPath, new CarrotGridColumn())
.AddColumn(x => x.IsWidgetActive, new CarrotGridBooleanImageColumn {
AlternateTextTrue = "Active",
AlternateTextFalse = "Inactive",
Sortable = true
});

<div>
@gridTwo.OutputHtmlBody()
</div>
}

if (Model.StepNumber >= 3) {
Expand All @@ -228,7 +237,6 @@
}
}
</fieldset>

}

<script type="text/javascript">
Expand Down
16 changes: 16 additions & 0 deletions CMSCore/CannedQueries.cs
Expand Up @@ -134,6 +134,22 @@ orderby ct.ContentSnippetName
select ct);
}

internal static IQueryable<vw_carrot_Content> GetContentByStatusAndType(CarrotCMSDataContext ctx, Guid siteID,
ContentPageType.PageType pageType, bool bActiveOnly) {

Guid contentTypeID = ContentPageType.GetIDByType(pageType);

return (from ct in ctx.vw_carrot_Contents
orderby ct.ContentTypeValue, ct.NavMenuText
where ct.SiteID == siteID
&& ct.IsLatestVersion == true
&& (ct.ContentTypeID == contentTypeID || pageType == ContentPageType.PageType.Unknown)
&& (ct.PageActive == true || bActiveOnly == false)
&& (ct.GoLiveDate < DateTime.UtcNow || bActiveOnly == false)
&& (ct.RetireDate > DateTime.UtcNow || bActiveOnly == false)
select ct);
}

internal static IQueryable<vw_carrot_Content> GetLatestBlogList(CarrotCMSDataContext ctx, Guid siteID, bool bActiveOnly) {
return (from ct in ctx.vw_carrot_Contents
orderby ct.NavOrder, ct.NavMenuText
Expand Down
5 changes: 5 additions & 0 deletions CMSCore/SiteContent/ISiteNavHelper.cs
Expand Up @@ -95,6 +95,11 @@ public interface ISiteNavHelper : IDisposable {

List<SiteNav> GetLatestContentSearchList(Guid siteID, string searchTerm, bool bActiveOnly, int pageSize, int pageNumber, string sortField, string sortDir);

List<SiteNav> GetContentSearchList(Guid siteID, string searchTerm, bool bActiveOnly, int pageSize, int pageNumber, ContentPageType.PageType pageType,
SearchContentPortion portion, string sortField, string sortDir);

int GetContentSearchListCount(Guid siteID, string searchTerm, bool bActiveOnly, ContentPageType.PageType pageType, SearchContentPortion portion);

SiteNav GetLatestVersion(Guid siteID, bool bActiveOnly, string sPage);

SiteNav GetLatestVersion(Guid siteID, Guid rootContentID);
Expand Down
7 changes: 7 additions & 0 deletions CMSCore/SiteContent/SiteNavHelper.cs
Expand Up @@ -24,6 +24,13 @@ public enum SiteNavMode {
MockupNav,
}

public enum SearchContentPortion {
All,
Title,
FileName,
ContentBody
}

//=============
public static class SiteNavFactory {

Expand Down
9 changes: 9 additions & 0 deletions CMSCore/SiteContent/SiteNavHelperMock.cs
Expand Up @@ -220,6 +220,15 @@ public class SiteNavHelperMock : ISiteNavHelper {
return SiteNavHelper.GetSamplerFakeNav(pageSize);
}

public List<SiteNav> GetContentSearchList(Guid siteID, string searchTerm, bool bActiveOnly, int pageSize, int pageNumber, ContentPageType.PageType pageType,
SearchContentPortion portion, string sortField, string sortDir) {
return SiteNavHelper.GetSamplerFakeNav(pageSize);
}

public int GetContentSearchListCount(Guid siteID, string searchTerm, bool bActiveOnly, ContentPageType.PageType pageType, SearchContentPortion portion) {
return 50;
}

public string GetBlogHeadingFromURL(SiteData currentSite, string sFilterPath) {
string sTitle = string.Empty;

Expand Down
39 changes: 39 additions & 0 deletions CMSCore/SiteContent/SiteNavHelperReal.cs
Expand Up @@ -564,6 +564,45 @@ orderby ct.CategoryText
return PerformDataPagingQueryableContent(siteID, bActiveOnly, pageSize, pageNumber, sortField, sortDir, query1);
}

public List<SiteNav> GetContentSearchList(Guid siteID, string searchTerm, bool bActiveOnly, int pageSize, int pageNumber, ContentPageType.PageType pageType,
SearchContentPortion portion, string sortField, string sortDir) {
IQueryable<vw_carrot_Content> query1 = GetFilteredContentQuery(siteID, searchTerm, bActiveOnly, pageType, portion);

return PerformDataPagingQueryableContent(siteID, bActiveOnly, pageSize, pageNumber, sortField, sortDir, query1);
}

public int GetContentSearchListCount(Guid siteID, string searchTerm, bool bActiveOnly, ContentPageType.PageType pageType, SearchContentPortion portion) {
IQueryable<vw_carrot_Content> query1 = GetFilteredContentQuery(siteID, searchTerm, bActiveOnly, pageType, portion);

return query1.Count();
}

private IQueryable<vw_carrot_Content> GetFilteredContentQuery(Guid siteID, string searchTerm, bool bActiveOnly, ContentPageType.PageType pageType, SearchContentPortion portion) {
IQueryable<vw_carrot_Content> query1 = CannedQueries.GetContentByStatusAndType(db, siteID, pageType, bActiveOnly);

switch (portion) {
case SearchContentPortion.Title:
query1 = query1.Where(x => x.TitleBar.Contains(searchTerm) || x.PageHead.Contains(searchTerm) || x.NavMenuText.Contains(searchTerm));
break;

case SearchContentPortion.FileName:
query1 = query1.Where(x => x.FileName.Contains(searchTerm));
break;

case SearchContentPortion.ContentBody:
query1 = query1.Where(x => x.LeftPageText.Contains(searchTerm) || x.PageText.Contains(searchTerm) || x.RightPageText.Contains(searchTerm));
break;

default:
query1 = query1.Where(x => x.FileName.Contains(searchTerm)
|| x.TitleBar.Contains(searchTerm) || x.PageHead.Contains(searchTerm) || x.NavMenuText.Contains(searchTerm)
|| x.LeftPageText.Contains(searchTerm) || x.PageText.Contains(searchTerm) || x.RightPageText.Contains(searchTerm));
break;
}

return query1;
}

public int GetFilteredContentPagedCount(SiteData currentSite, string sFilterPath, bool bActiveOnly) {
IQueryable<vw_carrot_Content> query1 = null;
Guid siteID = currentSite.SiteID;
Expand Down

0 comments on commit 322627b

Please sign in to comment.