Inheritance: System.MarshalByRefObject
Esempio n. 1
0
        public static JsTreeNode add_Node(this JsTree jsTree, string title, string id)
        {
            var newJsTreeNode = new JsTreeNode(title, id);

            jsTree.data.Add(newJsTreeNode);
            return(newJsTreeNode);
        }
Esempio n. 2
0
 public static List <JsTreeNode> add_Nodes(this JsTree jsTree, params string[] titles)
 {
     return(titles.Select(jsTree.add_Node).ToList());
 }
        public JsTree JsTreeWithFoldersAndGuidanceItems()
        {
            // ReSharper disable JoinDeclarationAndInitializer
            var jsTree = new JsTree();
            Func<Guid, List<Folder_V3>, JsTreeNode, List<Guid>> mapFolders = null;
            Func<Guid, Guid, List<Guid>, JsTreeNode, List<Guid>> mapViews;
            // ReSharper restore JoinDeclarationAndInitializer

            //precalculate for performance reasons
            var allViews = new Dictionary<Guid, View_V3>();
            foreach(var view in GetViews())
                if (allViews.hasKey(view.viewId))
                    "[getFolderStructure_Library] duplicate viewID: {0} from Library {0}".format(view.viewId, view.libraryId);  // this should be moved into a TM Library health check
                else
                    allViews.Add(view.viewId, view);

            mapViews = (libraryId, folderId, viewIds, targetNode) =>
                {
                    var viewsId = new List<Guid>();
                    foreach(var viewId in viewIds)
                    {
                        var view = allViews[viewId];//GetViewById(viewId.str());

                        var viewNodeText =  view.viewId.str();
                        var viewNode = targetNode.add_Node(view.caption, viewNodeText);
                        //viewNode.state = "closed";   // views don't need this
                        viewNode.data.icon = "/Images/ViewIcon.png";
                        viewsId.add(view.viewId);
                    }
                    return viewsId;
                };

            mapFolders = (libraryId, folders, targetNode)=>
                {
                    var folderViewsId = new List<Guid>();
                    foreach(var folder in folders)
                    {
                        var subFolderViewsId  = new List<Guid>();
                        var folderId = folder.folderId;
                        var folderNode = targetNode.add_Node(folder.name);
                        folderNode.state = "closed";
                        folderNode.data.icon = "/Images/FolderIcon.png";
                        // ReSharper disable AccessToModifiedClosure
                        // ReSharper disable PossibleNullReferenceException
                        subFolderViewsId.AddRange(mapFolders(libraryId, folder.subFolders, folderNode));
                        // ReSharper restore PossibleNullReferenceException
                        // ReSharper restore AccessToModifiedClosure
                        var viewIds = (from view in folder.views
                                       select view.viewId).toList();
                        subFolderViewsId.AddRange(mapViews(libraryId, folderId, viewIds, folderNode));

                        folderNode.attr.id = folderId.str();
                        folderViewsId.AddRange(subFolderViewsId);
                    }
                    return folderViewsId;

                };
            var sessionLibraryId = GetCurrentSessionLibrary();

            var libraries = (sessionLibraryId == Guid.Empty)
                                ? tmXmlDatabase.tmLibraries()
                                : tmXmlDatabase.tmLibrary(sessionLibraryId).wrapOnList();

            foreach(var library in libraries)
            {
                var libraryNode =jsTree.add_Node(library.Caption);
                //var mappedFolders = new Dictionary<string, List<Folder_V3>>();
                mapFolders(library.Id, GetFolders(library.Id), libraryNode);
                mapViews(library.Id, Guid.Empty, GetViewsInLibraryRoot(library.Id).guids(), libraryNode);
                //libraryNode.state = "open";
                libraryNode.state = "closed";
                libraryNode.data.icon = "/Images/SingleLibrary.png";

                var libraryNodeText = library.Id.str();

                libraryNode.attr.id = libraryNodeText;

            }
            return jsTree;
        }
Esempio n. 4
0
 public static JsTreeNode add_Node(this JsTree jsTree, string title)
 {
     return(jsTree.add_Node(title, ""));
 }
Esempio n. 5
0
        [WebMethod(EnableSession = true)]   public JsTree JsTreeWithFoldersAndGuidanceItems()
        {
            // ReSharper disable JoinDeclarationAndInitializer
            var jsTree = new JsTree();
            Func <Guid, List <Folder_V3>, JsTreeNode, List <Guid> >  mapFolders = null;
            Func <Guid, Guid, List <Guid>, JsTreeNode, List <Guid> > mapViews;
            // ReSharper restore JoinDeclarationAndInitializer

            //precalculate for performance reasons
            var allViews = new Dictionary <Guid, View_V3>();

            foreach (var view in GetViews())
            {
                if (allViews.hasKey(view.viewId))
                {
                    "[getFolderStructure_Library] duplicate viewID: {0} from Library {0}".format(view.viewId, view.libraryId);  // this should be moved into a TM Library health check
                }
                else
                {
                    allViews.Add(view.viewId, view);
                }
            }

            mapViews = (libraryId, folderId, viewIds, targetNode) =>
            {
                var viewsId = new List <Guid>();
                foreach (var viewId in viewIds)
                {
                    var view = allViews[viewId];    //GetViewById(viewId.str());

                    var viewNodeText = view.viewId.str();
                    var viewNode     = targetNode.add_Node(view.caption, viewNodeText);
                    //viewNode.state = "closed";   // views don't need this
                    viewNode.data.icon = "/Images/ViewIcon.png";
                    viewsId.add(view.viewId);
                }
                return(viewsId);
            };

            mapFolders = (libraryId, folders, targetNode) =>
            {
                var folderViewsId = new List <Guid>();
                foreach (var folder in folders)
                {
                    var subFolderViewsId = new List <Guid>();
                    var folderId         = folder.folderId;
                    var folderNode       = targetNode.add_Node(folder.name);
                    folderNode.state     = "closed";
                    folderNode.data.icon = "/Images/FolderIcon.png";
                    // ReSharper disable AccessToModifiedClosure
                    // ReSharper disable PossibleNullReferenceException
                    subFolderViewsId.AddRange(mapFolders(libraryId, folder.subFolders, folderNode));
                    // ReSharper restore PossibleNullReferenceException
                    // ReSharper restore AccessToModifiedClosure
                    var viewIds = (from view in folder.views
                                   select view.viewId).toList();
                    subFolderViewsId.AddRange(mapViews(libraryId, folderId, viewIds, folderNode));

                    folderNode.attr.id = folderId.str();
                    folderViewsId.AddRange(subFolderViewsId);
                }
                return(folderViewsId);
            };
            var sessionLibraryId = GetCurrentSessionLibrary();

            var libraries = (sessionLibraryId == Guid.Empty)
                                ? tmXmlDatabase.tmLibraries()
                                : tmXmlDatabase.tmLibrary(sessionLibraryId).wrapOnList();

            foreach (var library in libraries)
            {
                var libraryNode = jsTree.add_Node(library.Caption);
                //var mappedFolders = new Dictionary<string, List<Folder_V3>>();
                mapFolders(library.Id, GetFolders(library.Id), libraryNode);
                mapViews(library.Id, Guid.Empty, GetViewsInLibraryRoot(library.Id).guids(), libraryNode);
                //libraryNode.state = "open";
                libraryNode.state     = "closed";
                libraryNode.data.icon = "/Images/SingleLibrary.png";

                var libraryNodeText = library.Id.str();

                libraryNode.attr.id = libraryNodeText;
            }
            return(jsTree);
        }