Permalink
Browse files

added support for separating shadow page blocks from page when saving…

… page
  • Loading branch information...
markentingh committed Jun 18, 2017
1 parent 25a152c commit ab7520b6b7bb572aeca70cd602bb799f53b0b792
Showing with 48 additions and 5 deletions.
  1. +48 −5 App/Core/Page.cs
View
@@ -27,6 +27,7 @@ public struct structPage
//structure used to save page content to JSON file
public int pageId;
public int shadowId;
public bool isShadow;
public string layout;
public List<structArea> areas;
}
@@ -341,6 +342,7 @@ public structPage loadPage(bool fromCache = true)
//get a list of components to load onto the page
var page = new structPage();
page.pageId = pageId;
page.shadowId = shadowTemplateId;
page.areas = new List<structArea>();
//load shadow page first (if available)
@@ -378,7 +380,7 @@ public structPage loadPage(bool fromCache = true)
return page;
}
public void combinePages(ref structPage page, string file, bool fromCache = true)
public void combinePages(ref structPage page, string file, bool isShadow, bool fromCache = true)
{
var newpage = new structPage();
if (file != "")
@@ -388,9 +390,12 @@ public void combinePages(ref structPage page, string file, bool fromCache = true
else
{
//initialize a new page
newpage = new structPage();
newpage.pageId = pageId;
newpage.areas = new List<structArea>();
newpage = new structPage()
{
pageId = pageId,
isShadow = isShadow,
areas = new List<structArea>()
};
}
//combine new page with page
@@ -402,7 +407,34 @@ public void combinePages(ref structPage page, string file, bool fromCache = true
var area = page.areas[y];
for(var z = 0; z < newpage.areas[x].blocks.Count; z++)
{
area.blocks.Add(newpage.areas[x].blocks[z]);
if(newpage.isShadow == false)
{
if(newpage.areas[x].blocks[z].isPage == true)
{
//add page block components to existing page block
var b = area.blocks.FindIndex(a => a.id == area.blocks[z].id);
if(b >= 0)
{
foreach(var c in newpage.areas[x].blocks[z].components)
{
area.blocks[b].components.Add(c);
}
}
else
{
area.blocks.Add(newpage.areas[x].blocks[z]);
}
}
else
{
area.blocks.Add(newpage.areas[x].blocks[z]);
}
}
else
{
area.blocks.Add(newpage.areas[x].blocks[z]);
}
}
page.areas[y] = area;
}
@@ -1066,6 +1098,17 @@ public void SaveShadowTemplate(ref structPage oldpage, bool saveToDisk = true)
{
//add block to new page object
newpage.areas[newpage.areas.Count - 1].blocks.Add(block);
//add page-level block to shadow template object (to remember the order in which the page-level blocks are loaded)
var b = new structBlock()
{
id = block.id,
isPage = true,
name = block.name,
components = new List<Component>(),
changed = block.changed
};
page.areas[page.areas.Count - 1].blocks.Add(b);
}
else
{

0 comments on commit ab7520b

Please sign in to comment.