private static RelativeObjects GetNextPrevInSubFolder( FileIndexItem currentFileIndexItem, List <FileIndexItem> fileIndexItemsList, SortType sortType) { // Check if this is item is not !deleted! yet if (currentFileIndexItem == null) { return(new RelativeObjects()); } fileIndexItemsList = SortHelper.Helper(fileIndexItemsList, sortType).ToList(); var currentIndex = fileIndexItemsList.FindIndex(p => p.FilePath == currentFileIndexItem.FilePath); var relativeObject = new RelativeObjects(); if (currentIndex != fileIndexItemsList.Count - 1) { relativeObject.NextFilePath = fileIndexItemsList[currentIndex + 1].FilePath; relativeObject.NextHash = fileIndexItemsList[currentIndex + 1].FileHash; } if (currentIndex >= 1) { relativeObject.PrevFilePath = fileIndexItemsList[currentIndex - 1].FilePath; relativeObject.PrevHash = fileIndexItemsList[currentIndex - 1].FileHash; } return(relativeObject); }
public void ImageFormatOrder() { var exampleList = new List <FileIndexItem> { new FileIndexItem("/test3.mp4") { ImageFormat = ExtensionRolesHelper.ImageFormat.mp4 }, new FileIndexItem("/test3.gpx") { ImageFormat = ExtensionRolesHelper.ImageFormat.gpx }, new FileIndexItem("/test3.jpg") { ImageFormat = ExtensionRolesHelper.ImageFormat.jpg }, new FileIndexItem("/test.jpg") { ImageFormat = ExtensionRolesHelper.ImageFormat.notfound }, new FileIndexItem("/test.xmp") { ImageFormat = ExtensionRolesHelper.ImageFormat.xmp }, new FileIndexItem("/test.png") { ImageFormat = ExtensionRolesHelper.ImageFormat.png }, new FileIndexItem("/test2.jpg") { ImageFormat = ExtensionRolesHelper.ImageFormat.unknown }, new FileIndexItem("/test.bmp") { ImageFormat = ExtensionRolesHelper.ImageFormat.bmp }, new FileIndexItem("/test2.jp4") { ImageFormat = ExtensionRolesHelper.ImageFormat.gif }, new FileIndexItem("/test.tiff") { ImageFormat = ExtensionRolesHelper.ImageFormat.tiff } }; var result = SortHelper.Helper(exampleList, SortType.ImageFormat); var extensionList = result.Select(p => p.ImageFormat).ToList(); Assert.AreEqual(ExtensionRolesHelper.ImageFormat.notfound, extensionList[0]); Assert.AreEqual(ExtensionRolesHelper.ImageFormat.unknown, extensionList[1]); Assert.AreEqual(ExtensionRolesHelper.ImageFormat.jpg, extensionList[2]); Assert.AreEqual(ExtensionRolesHelper.ImageFormat.tiff, extensionList[3]); Assert.AreEqual(ExtensionRolesHelper.ImageFormat.bmp, extensionList[4]); Assert.AreEqual(ExtensionRolesHelper.ImageFormat.gif, extensionList[5]); Assert.AreEqual(ExtensionRolesHelper.ImageFormat.png, extensionList[6]); Assert.AreEqual(ExtensionRolesHelper.ImageFormat.xmp, extensionList[7]); Assert.AreEqual(ExtensionRolesHelper.ImageFormat.gpx, extensionList[8]); Assert.AreEqual(ExtensionRolesHelper.ImageFormat.mp4, extensionList[9]); }
public IActionResult Index( string f = "/", string colorClass = null, bool collections = true, bool hidedelete = true, SortType sort = SortType.FileName ) { // Used in Detail and Index View => does not hide this single item var colorClassActiveList = FileIndexItem.GetColorClassList(colorClass); var subPath = PathHelper.PrefixDbSlash(f); subPath = PathHelper.RemoveLatestSlash(subPath); if (string.IsNullOrEmpty(subPath)) { subPath = "/"; } // First check if it is a single Item var singleItem = _query.SingleItem(subPath, colorClassActiveList, collections, hidedelete, sort); // returns no object when it a directory if (singleItem?.IsDirectory == false) { singleItem.IsReadOnly = _appSettings.IsReadOnly(singleItem.FileIndexItem.ParentDirectory); return(Json(singleItem)); } var fileIndexItems = SortHelper.Helper( _query.DisplayFileFolders(subPath, colorClassActiveList, collections, hidedelete), sort).ToList(); var fileIndexItemsWithoutCollections = _query.DisplayFileFolders( subPath, null, false, hidedelete).ToList(); // (singleItem.IsDirectory) or not found var directoryModel = new ArchiveViewModel { FileIndexItems = fileIndexItems, ColorClassActiveList = colorClassActiveList, RelativeObjects = _query.GetNextPrevInFolder(subPath), // Args are not shown in this view Breadcrumb = Breadcrumbs.BreadcrumbHelper(subPath), SearchQuery = subPath.Split("/").LastOrDefault(), SubPath = subPath, CollectionsCount = fileIndexItemsWithoutCollections. Count(p => p.IsDirectory == false), // when change colorclass selection you should see all options ColorClassUsage = fileIndexItemsWithoutCollections .Select(p => p.ColorClass).Distinct() .OrderBy(p => (int)(p)).ToList(), IsReadOnly = _appSettings.IsReadOnly(subPath), Collections = collections, }; if (singleItem == null) { // For showing a new database var queryIfFolder = _query.GetObjectByFilePath(subPath); // For showing a new database if (f == "/" && queryIfFolder == null) { return(Json(directoryModel)); } if (queryIfFolder == null) // used to have: singleItem?.FileIndexItem.FilePath == null && { Response.StatusCode = 404; return(Json("not found")); } } return(Json(directoryModel)); }