Skip to content

Commit

Permalink
Merge pull request #1815 from qdraw/feature/202411_imageformat_thenby
Browse files Browse the repository at this point in the history
OrderByImageFormat
  • Loading branch information
qdraw authored Nov 11, 2024
2 parents 11f960e + 7736b7a commit aae68ae
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 71 deletions.
3 changes: 3 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ Semantic Versioning 2.0.0 is from version 0.1.6+
- [x] (Fixed) _Back-end_ next/prev fixes to ignore xmp/json files (PR #1806)
- [x] (Fixed) _Back-end_ LensModel to loop and avoid returning default values. (PR #1807)
- [x] (Fixed) _Back-end_ LensModel add tests for sony raw files to avoid default values (PR #1807)
- [x] (Fixed) _Front-end_ increase description limit (Issue #1810) (PR #1814)
- [x] (Fixed) _Back-end_ Change reading order to favor XMP for description/title field (PR #1814)
- [x] (Fixed) _Back-end_ OrderBy ImageFormat and then alphabet (PR #1815)

## version 0.6.2 - 2024-10-11 {#v0.6.2}

Expand Down
26 changes: 16 additions & 10 deletions starsky/starsky.foundation.database/Helpers/SortHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
using System.Linq;
using starsky.foundation.database.Models;

namespace starsky.foundation.database.Helpers
namespace starsky.foundation.database.Helpers;

public static class SortHelper
{
public static class SortHelper
/// <summary>
/// Help order the list
/// </summary>
/// <param name="fileIndexItems">items</param>
/// <param name="sort">way of sorting</param>
/// <returns>sorted list</returns>
public static IEnumerable<FileIndexItem> Helper(IEnumerable<FileIndexItem> fileIndexItems,
SortType sort = SortType.FileName)
{
public static IEnumerable<FileIndexItem> Helper(IEnumerable<FileIndexItem> fileIndexItems, SortType sort = SortType.FileName)
switch ( sort )
{
switch ( sort )
{
case SortType.ImageFormat:
return fileIndexItems.OrderBy(p => p.ImageFormat).ToList();
default:
return fileIndexItems;
}
case SortType.ImageFormat:
return [.. fileIndexItems.OrderBy(p => p.ImageFormat).ThenBy(p => p.FileName)];
default:
return fileIndexItems;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,76 @@
using starsky.foundation.database.Models;
using starsky.foundation.platform.Helpers;

namespace starskytest.starsky.foundation.database.Helpers
namespace starskytest.starsky.foundation.database.Helpers;

[TestClass]
public sealed class SortHelperTest
{
[TestClass]
public sealed class SortHelperTest
[TestMethod]
public void ImageFormatOrder()
{
var exampleList = new List<FileIndexItem>
{
new("/test3.mp4") { ImageFormat = ExtensionRolesHelper.ImageFormat.mp4 },
new("/test3.gpx") { ImageFormat = ExtensionRolesHelper.ImageFormat.gpx },
new("/test3.jpg") { ImageFormat = ExtensionRolesHelper.ImageFormat.jpg },
new("/test.jpg") { ImageFormat = ExtensionRolesHelper.ImageFormat.notfound },
new("/test.xmp") { ImageFormat = ExtensionRolesHelper.ImageFormat.xmp },
new("/test.png") { ImageFormat = ExtensionRolesHelper.ImageFormat.png },
new("/test2.jpg") { ImageFormat = ExtensionRolesHelper.ImageFormat.unknown },
new("/test.bmp") { ImageFormat = ExtensionRolesHelper.ImageFormat.bmp },
new("/test2.jp4") { ImageFormat = ExtensionRolesHelper.ImageFormat.gif },
new("/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]);
}

[TestMethod]
public void ImageFormatOrder_ThenByFileName()
{
[TestMethod]
public void ImageFormatOrder()
var exampleList = new List<FileIndexItem>
{
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();
new("/test3.mp4") { ImageFormat = ExtensionRolesHelper.ImageFormat.mp4 },
new("/test3.gpx") { ImageFormat = ExtensionRolesHelper.ImageFormat.gpx },
new("/test3.jpg") { ImageFormat = ExtensionRolesHelper.ImageFormat.jpg },
new("/test.jpg") { ImageFormat = ExtensionRolesHelper.ImageFormat.notfound },
new("/test.xmp") { ImageFormat = ExtensionRolesHelper.ImageFormat.xmp },
new("/test.png") { ImageFormat = ExtensionRolesHelper.ImageFormat.png },
new("/test2.jpg") { ImageFormat = ExtensionRolesHelper.ImageFormat.unknown },
new("/test.bmp") { ImageFormat = ExtensionRolesHelper.ImageFormat.bmp },
new("/test2.jp4") { ImageFormat = ExtensionRolesHelper.ImageFormat.gif },
new("/test.tiff") { ImageFormat = ExtensionRolesHelper.ImageFormat.tiff }
};

var result = SortHelper.Helper(exampleList, SortType.ImageFormat).ToList();
var extensionList = result.Select(p => p.ImageFormat).ToList();
var fileNameList = result.Select(p => p.FileName).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]);

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]);
}
Assert.AreEqual("test.jpg", fileNameList[0]);
Assert.AreEqual("test2.jpg", fileNameList[1]);
Assert.AreEqual("test3.jpg", fileNameList[2]);
}
}

0 comments on commit aae68ae

Please sign in to comment.