Exemple #1
0
        protected IEnumerable <DriverResult> GetFolderMenuAndTitleShapes(FolderPart part, ProjectPart projectPart, dynamic shapeHelper)
        {
            FolderWithAncestorsViewModel model = new FolderWithAncestorsViewModel(this.folderService.Convert(part));

            model.Project   = projectPart.Record;
            model.ProjectId = projectPart.Id;

            List <DriverResult> shapes = new List <DriverResult>();

            if (this.contentOwnershipService.CurrentUserCanEditContent(projectPart.ContentItem))
            {
                shapes.Add(ContentShape("Parts_Folder_Menu", () => shapeHelper.Parts_Folder_Menu(Model: model)));
            }

            // folder path
            var folders   = this.folderService.GetFolders(projectPart.Id).Select(c => c.As <FolderPart>());
            var ancestors = this.folderService.GetAncestors(folders, part.Id);

            model.Ancestors.AddRange(ancestors.Select(c => this.folderService.Convert(c)));
            shapes.Add(this.ContentShape("Parts_Folder_Title",
                                         () => shapeHelper.Parts_Folder_Title(
                                             Model: model)));

            return(shapes);
        }
Exemple #2
0
        public FolderViewModel Convert(FolderPart part)
        {
            string title = part.Record.Title;

            return(new FolderViewModel
            {
                Title = title,
                ProjectId = part.Record.Project != null ? (int?)part.Record.Project.Id : null,
                FolderId = part.Id > 0 ? (int?)part.Id : null,
            });
        }
Exemple #3
0
        protected DriverResult RenderFolders(FolderListPart part, string displayType, dynamic shapeHelper)
        {
            int?projectId = ProjectHelper.GetProjectId(part, this.projectService);

            FolderPart folderPart = part.As <FolderPart>();
            int?       folderId   = folderPart != null ? (int?)folderPart.Id : null;

            if (folderId == null)
            {
                AttachToFolderPart attachToFolderPart = part.As <AttachToFolderPart>();
                if (attachToFolderPart != null && attachToFolderPart.Record.Folder != null)
                {
                    folderId = attachToFolderPart.Record.Folder.Id;
                }
            }

            var folders = this.folderService.GetFolders(projectId.Value).Select(c => c.As <FolderPart>()).ToList();

            // folders doesn't contain all folders, it is restrcited by the folders visible by current user. So currentFolder is
            // equal to part, if it exists in the folders list, otherwise it is null
            FolderPart currentFolder = folderId.HasValue ? folders.FirstOrDefault(c => c.Record.Id == folderId) : null;

            // Building the tree
            FolderViewModel root = new FolderViewModel();

            root.IsSelected = folderId == null && part.ContentItem.ContentType != ContentTypes.WikiContentType;
            var tree = this.folderService.ConvertToTree(folders, folderId);

            FolderPart parentFolder = currentFolder != null && currentFolder.Record.Parent_Id != null?
                                      folders.FirstOrDefault(c => c.Record.Id == currentFolder.Record.Parent_Id.Value) :
                                          null;

            // show the tree from the root, if the tree is small, or if there is no selected folder
            if (folderId == null || currentFolder == null || parentFolder == null || folders.Count < 100)
            {
                root.Title     = T("Root").Text;
                root.ProjectId = projectId.Value;
                root.Folders.AddRange(tree.Folders);
            }
            else
            {
                root       = this.folderService.FindInTree(tree, currentFolder.Record.Parent_Id.Value);
                root.Title = "...";
            }

            return(ContentShape("Parts_FolderList",
                                () => shapeHelper.Parts_FolderList(
                                    Model: root
                                    )));
        }