/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using Everest.Library.Extjs.Tree;
using Everest.CmsServices.Models;
using Everest.CmsServices.Services;
using Everest.Library.Web;
namespace Everest.CmsServices.Providers{
public class NavigationTreeProvider : AbstractTreeNodeProvider
{
#region ITreeNodeProvider Members
public override IDictionary<string, object>[] GetChildNodes(string parentNodeId, NameValueCollection attributes)
{
IList<Dictionary<string, object>> treeNodes;
switch (attributes["folderType"])
{
//case "BaseFolder":
//case "BaseNode":
// treeNodes = GetBaseFolder(attributes);
// break;
//case "DerivedFolder":
//case "DerivedNode":
// treeNodes = GetDerivedFolders(attributes);
// break;
default:
treeNodes = InternalGetChildNodes(parentNodeId, attributes);
break;
}
return treeNodes.ToArray();
}
///// <summary>
///// Gets the derived folders.
///// </summary>
///// <param name="attributes">The attributes.</param>
///// <returns></returns>
//private IList<Dictionary<string, object>> GetDerivedFolders(NameValueCollection attributes)
//{
// IList<Dictionary<string, object>> treeNodes = new List<Dictionary<string, object>>();
// IEverestCmsDataContext entities = EverestCmsEntities.GetDataContext();
// int folderId = int.Parse(attributes["folderId"]);
// var folder = (from f in entities.Cms_Folder
// where f.FolderId == folderId
// select f).FirstOrDefault();
// if (folder != null)
// {
// folder.Derives.Load();
// foreach (var item in folder.Derives)
// {
// TreeNode treeNode = new TreeNode();
// item.aspnet_ApplicationsReference.Load();
// treeNode.Text = item.aspnet_Applications.ApplicationName + ":" + item.FolderName;
// treeNode.AddAttribute("folderId", item.FolderId.ToString());
// treeNode.AddAttribute("FolderUUID", item.UUID.ToString());
// treeNode.AddAttribute("folderType", FolderType.DerivedNode.ToString());
// treeNodes.Add(treeNode.Attributes);
// }
// }
// return treeNodes;
//}
///// <summary>
///// Gets the base folder.
///// </summary>
///// <param name="attributes">The attributes.</param>
///// <returns></returns>
//private IList<Dictionary<string, object>> GetBaseFolder(NameValueCollection attributes)
//{
// IList<Dictionary<string, object>> treeNodes = new List<Dictionary<string, object>>();
// IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
// int folderId = int.Parse(attributes["folderId"]);
// var baseFolder = (from f in dataContext.Cms_Folder
// where f.FolderId == folderId
// select f.Base).FirstOrDefault();
// if (baseFolder != null)
// {
// baseFolder.aspnet_ApplicationsReference.Load();
// TreeNode treeNode = new TreeNode();
// treeNode.Text = baseFolder.aspnet_Applications.ApplicationName + ":" + baseFolder.FolderName;
// treeNode.AddAttribute("folderId", baseFolder.FolderId.ToString());
// treeNode.AddAttribute("FolderUUID", baseFolder.UUID.ToString());
// treeNode.AddAttribute("folderType", FolderType.BaseNode.ToString());
// treeNodes.Add(treeNode.Attributes);
// }
// return treeNodes;
//}
/// <summary>
/// Gets the child nodes.
/// </summary>
/// <param name="parentNodeId">The parent node id.</param>
/// <returns></returns>
private IList<Dictionary<string, object>> InternalGetChildNodes(string parentNodeId, NameValueCollection attributes)
{
IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
Guid? parentUUID = null;
if (!string.IsNullOrEmpty(attributes["folderUUID"]))
{
parentUUID = new Guid(attributes["folderUUID"]);
}
if (parentUUID == null)
{
parentUUID = (from f in dataContext.Cms_Folder
where f.Parent == null
select f).First().UUID;
}
var query = dataContext.Cms_Folder.Where(f => f.Parent.UUID == parentUUID)
.Select(f => new
{
FolderId = f.FolderId,
f.UUID,
FolderName = f.FolderName,
DisplayName = f.DisplayName,
IconCls = f.IconCls,
Order = f.Order,
f.SchemaName,
CanInherit = f.CanInherit,
FolderType = f.FolderType,
FormType = f.FormType,
ApplicationName = f.aspnet_Applications.ApplicationName,
f.Cms_Schema
});
var data = query.OrderBy(f => new { f.Order, f.FolderType, f.FolderName }).ToArray();
IList<Dictionary<string, object>> treeNodes = new List<Dictionary<string, object>>();
//if (parentFolder.CanInherit)
//{
// TreeNode baseFolder = new TreeNode();
// baseFolder.Text = "Base";
// baseFolder.IconCls = "baseFolder";
// baseFolder.ParentNode = parentNodeId;
// baseFolder.AddAttribute("folderType", FolderType.BaseFolder.ToString());
// baseFolder.AddAttribute("folderId", parentNodeId);
// treeNodes.Add(baseFolder.Attributes);
// TreeNode derivedFolder = new TreeNode();
// derivedFolder.Text = "Children";
// derivedFolder.IconCls = "derivedFolder";
// derivedFolder.ParentNode = parentNodeId;
// derivedFolder.AddAttribute("folderType", FolderType.DerivedFolder.ToString());
// derivedFolder.AddAttribute("folderId", parentNodeId);
// treeNodes.Add(derivedFolder.Attributes);
//}
foreach (var item in data)
{
TreeNode treeNode = new TreeNode();
treeNode.Id = item.FolderId.ToString();
treeNode.Text = string.IsNullOrEmpty(item.DisplayName) ? item.FolderName : item.DisplayName;
if ((FolderType)item.FolderType == FolderType.ContentView)
{
treeNode.Text += "(" + Resources.ContentFolderView + ")";
}
treeNode.IconCls = item.IconCls;
treeNode.ParentNode = parentNodeId;
treeNode.AddAttribute("schema", item.SchemaName);
if (item.Cms_Schema != null)
{
treeNode.AddAttribute("schemaUUID", item.Cms_Schema.UUID);
}
treeNode.AddAttribute("formType", item.FormType);
treeNode.AddAttribute("folderId", item.FolderId);
treeNode.AddAttribute("folderUUID", item.UUID);
treeNode.AddAttribute("folderType", ((FolderType)item.FolderType).ToString());
treeNode.AddAttribute("application", item.ApplicationName);
treeNode.AddAttribute("canInherit", item.CanInherit);
switch ((FolderType)item.FolderType)
{
case FolderType.Root:
break;
case FolderType.System:
treeNode.Text = Resources.TreeNode_System;
break;
case FolderType.SiteSetting:
treeNode.Text = Resources.TreeNode_SiteSetting;
treeNode.Leaf = true;
break;
case FolderType.UserGroup:
treeNode.Text = Resources.TreeNode_UserGroup;
break;
case FolderType.Users:
treeNode.Text = Resources.TreeNode_Users;
treeNode.Leaf = true;
break;
case FolderType.Roles:
treeNode.Text = Resources.TreeNode_Roles;
treeNode.Leaf = true;
break;
case FolderType.Schema:
treeNode.Text = Resources.TreeNode_Schema;
break;
case FolderType.TextSchema:
treeNode.Text = Resources.TreeNode_TextSchema;
treeNode.Leaf = true;
break;
case FolderType.BinarySchema:
treeNode.Text = Resources.TreeNode_BinarySchema;
treeNode.Leaf = true;
break;
case FolderType.Template:
treeNode.Text = Resources.TreeNode_Template;
break;
case FolderType.ContentTemplate:
treeNode.Text = Resources.TreeNode_ContentTemplate;
treeNode.AddAttribute("dataUrl", "Kooboo_ContentTemplate/GetNamespaceNodes");
break;
case FolderType.LayoutTemplate:
treeNode.Text = Resources.TreeNode_LayoutTemplate;
treeNode.Leaf = true;
break;
case FolderType.Extension:
treeNode.Text = Resources.TreeNode_Extension;
break;
case FolderType.PagePlugin:
treeNode.Text = Resources.TreeNode_PagePlugin;
treeNode.Leaf = true;
break;
case FolderType.Package:
treeNode.Text = Resources.TreeNode_Package;
treeNode.AddAttribute("dataUrl", "package/GetPackageNodes");
break;
case FolderType.Applications:
treeNode.Text = Resources.TreeNode_Applications;
break;
case FolderType.Application:
treeNode.AddAttribute("usedBy", "Kooboo_folder/usedby");
var displayName = CachedData.GetApplication(item.ApplicationName).DisplayName;
treeNode.Text = string.IsNullOrEmpty(displayName) ? item.ApplicationName : displayName;
break;
case FolderType.Content:
treeNode.Text = Resources.TreeNode_Content;
break;
case FolderType.TextContent:
treeNode.AddAttribute("usedBy", "Kooboo_folder/usedby");
treeNode.AddAttribute("iconCls", "TextContent");
treeNode.Leaf = true;
break;
case FolderType.Page:
treeNode.Text = Resources.TreeNode_Page;
treeNode.AddAttribute("dataUrl", "Kooboo_Page/GetPageNodes");
break;
case FolderType.BaseFolder:
break;
case FolderType.DerivedFolder:
break;
case FolderType.BaseNode:
break;
case FolderType.DerivedNode:
break;
case FolderType.Validator:
treeNode.Text = Resources.TreeNode_Validator;
treeNode.Leaf = true;
break;
case FolderType.ValidatorGroup:
treeNode.Text = Resources.TreeNode_ValidatorGroup;
treeNode.Leaf = true;
break;
case FolderType.BinaryResource:
treeNode.Text = Resources.TreeNode_BinaryResource;
treeNode.AddAttribute("directory", UrlConvertor.MakeRelativeUrl(TemplateFileManager.GetRelativeTemplateFolderPath(item.ApplicationName, (FolderType)item.FolderType)));
treeNode.AddAttribute("schema", FolderType.BinaryResource.ToString());
treeNode.AddAttribute("dataUrl", "Kooboo_BinaryResource/GetDirectoryNodes");
break;
case FolderType.BinaryContent:
treeNode.AddAttribute("usedBy", "Kooboo_folder/usedby");
treeNode.AddAttribute("iconCls", "BinaryContent");
treeNode.Leaf = true;
break;
case FolderType.BinaryResourceFolder:
break;
case FolderType.Schedule:
treeNode.Text = Resources.TreeNode_Schedule;
treeNode.Leaf = true;
break;
case FolderType.TextResource:
treeNode.Text = Resources.TreeNode_TextResource;
treeNode.AddAttribute("dataUrl", "Kooboo_TextResource/GetNamespaceNodes");
break;
case FolderType.TextResourceNamespace:
break;
case FolderType.Workflow:
treeNode.Text = Resources.TreeNode_Workflow;
treeNode.Leaf = true;
break;
//case FolderType.WebForm:
// treeNode.Text = Resources.TreeNode_WebForm;
// treeNode.Leaf = true;
// break;
case FolderType.ContentView:
treeNode.AddAttribute("iconCls", "ContentView");
treeNode.Leaf = true;
break;
case FolderType.UserProfile:
treeNode.Text = Resources.TreeNode_UserProfile;
treeNode.Leaf = true;
break;
case FolderType.SiteManager:
treeNode.Text = Resources.TreeNode_SiteManager;
break;
case FolderType.Module:
treeNode.Text = Resources.TreeNode_Module;
treeNode.Leaf = true;
break;
case FolderType.WebEvent:
treeNode.Text = Resources.TreeNode_WebEvent;
treeNode.Leaf = true;
break;
case FolderType.SearchSetting:
treeNode.Text = Resources.TreeNode_SearchSetting;
treeNode.Leaf = true;
break;
case FolderType.SitePackage:
treeNode.Text = Resources.TreeNode_SitePackage;
treeNode.Leaf = true;
break;
case FolderType.StaticCode:
treeNode.Text = Resources.TreeNode_StaticCode;
treeNode.Leaf = true;
break;
case FolderType.KoobooStore:
treeNode.Text = Resources.TreeNode_KoobooStore;
treeNode.AddAttribute("iconCls", "KoobooStore");
treeNode.Leaf = true;
break;
case FolderType.CheckUpdates:
treeNode.Text = Resources.TreeNode_CheckUpdates;
treeNode.Leaf = true;
break;
case FolderType.TemplatePackage:
treeNode.Text = Resources.TreeNode_TemplatePackage;
treeNode.Leaf = true;
break;
case FolderType.Rss:
treeNode.Text = Resources.TreeNode_Rss;
treeNode.Leaf = true;
break;
default:
break;
}
if (IsVisible(treeNode))
{
treeNodes.Add(treeNode.Attributes);
}
}
return treeNodes;
}
#endregion
}
}
|