diff --git a/src/Bonsai/Areas/Admin/Logic/MediaManagerService.cs b/src/Bonsai/Areas/Admin/Logic/MediaManagerService.cs index 9d4e759..863c343 100644 --- a/src/Bonsai/Areas/Admin/Logic/MediaManagerService.cs +++ b/src/Bonsai/Areas/Admin/Logic/MediaManagerService.cs @@ -100,8 +100,18 @@ public async Task GetMediaAsync(MediaListRequestVM request) var totalCount = await query.CountAsync(); result.PageCount = (int) Math.Ceiling((double) totalCount / PageSize); - result.Items = await query.OrderBy(request.OrderBy, request.OrderDescending ?? false) - .ProjectToType(_mapper.Config) + if (request.OrderBy == nameof(Media.Tags)) + { + query = request.OrderDescending ?? false + ? query.OrderByDescending(x => x.Tags.Count) + : query.OrderBy(x => x.Tags.Count); + } + else + { + query = query.OrderBy(request.OrderBy, request.OrderDescending ?? false); + } + + result.Items = await query.ProjectToType(_mapper.Config) .Skip(PageSize * request.Page) .Take(PageSize) .ToListAsync(); @@ -323,7 +333,7 @@ private MediaListRequestVM NormalizeListRequest(MediaListRequestVM vm) if(vm == null) vm = new MediaListRequestVM { OrderDescending = true }; - var orderableFields = new[] { nameof(Media.UploadDate), nameof(Media.Date), nameof(Media.Title) }; + var orderableFields = new[] { nameof(Media.UploadDate), nameof(Media.Date), nameof(Media.Title), nameof(Media.Tags) }; if(!orderableFields.Contains(vm.OrderBy)) vm.OrderBy = orderableFields[0]; diff --git a/src/Bonsai/Areas/Admin/Views/Dashboard/Index.cshtml b/src/Bonsai/Areas/Admin/Views/Dashboard/Index.cshtml index 5929b92..e5f4c07 100644 --- a/src/Bonsai/Areas/Admin/Views/Dashboard/Index.cshtml +++ b/src/Bonsai/Areas/Admin/Views/Dashboard/Index.cshtml @@ -36,7 +36,7 @@ { } diff --git a/src/Bonsai/Areas/Admin/Views/Media/Index.cshtml b/src/Bonsai/Areas/Admin/Views/Media/Index.cshtml index 27ab744..80ffa87 100644 --- a/src/Bonsai/Areas/Admin/Views/Media/Index.cshtml +++ b/src/Bonsai/Areas/Admin/Views/Media/Index.cshtml @@ -74,7 +74,7 @@ @await Component.InvokeAsync("ListHeaderComponent", new { url = baseUrl, request = Model.Request, propName = nameof(MediaThumbnailExtendedVM.Title), title = "Название" }) @await Component.InvokeAsync("ListHeaderComponent", new { url = baseUrl, request = Model.Request, propName = nameof(MediaThumbnailExtendedVM.Date), title = "Снято" }) @await Component.InvokeAsync("ListHeaderComponent", new { url = baseUrl, request = Model.Request, propName = nameof(MediaThumbnailExtendedVM.UploadDate), title = "Загружено" }) - Отметки + @await Component.InvokeAsync("ListHeaderComponent", new { url = baseUrl, request = Model.Request, propName = nameof(Media.Tags), title = "Теги" })