From 57eafdb7afe3fedbf8f6ead88acebfda9935df16 Mon Sep 17 00:00:00 2001 From: Mohamed Riad Gahlouz Date: Tue, 28 Nov 2023 15:34:34 -0500 Subject: [PATCH 1/2] Support selecting specific number of packages on admin ui --- .../Admin/Views/UpdateListed/Index.cshtml | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/NuGetGallery/Areas/Admin/Views/UpdateListed/Index.cshtml b/src/NuGetGallery/Areas/Admin/Views/UpdateListed/Index.cshtml index 91642dd223..3ecdc59fa5 100644 --- a/src/NuGetGallery/Areas/Admin/Views/UpdateListed/Index.cshtml +++ b/src/NuGetGallery/Areas/Admin/Views/UpdateListed/Index.cshtml @@ -106,22 +106,33 @@ return true; }; - this.selectListed = function (e) { - ko.utils.arrayForEach($self.searchResults(), function (result) { - if (result.Listed) { + let selectFilteredResults = function (isListedFilter) { + var selection = parseInt(window.prompt("How many? (Default: All)", "")); + selection = isNaN(selection) ? $self.searchResults().length : selection; + + if (selection === 0) { + return true; + } + + let i = 0; + ko.utils.arrayFirst($self.searchResults(), function (result) { + if (result.Listed == isListedFilter) { result.Selected(true); + i++; } + + // Stop looping when we selected enough items + return i >= selection; }); return true; + } + + this.selectListed = function (e) { + selectFilteredResults(true); }; this.selectUnlisted = function (e) { - ko.utils.arrayForEach($self.searchResults(), function (result) { - if (!result.Listed) { - result.Selected(true); - } - }); - return true; + selectFilteredResults(false); }; this.generateValue = function (package) { From 69905f6c163047c426054e9dfd90280cc35cb724 Mon Sep 17 00:00:00 2001 From: Mohamed Riad Gahlouz Date: Thu, 7 Dec 2023 15:48:11 -0800 Subject: [PATCH 2/2] Clear state before selecting --- .../Areas/Admin/Views/UpdateListed/Index.cshtml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/NuGetGallery/Areas/Admin/Views/UpdateListed/Index.cshtml b/src/NuGetGallery/Areas/Admin/Views/UpdateListed/Index.cshtml index 3ecdc59fa5..139b6fc5d8 100644 --- a/src/NuGetGallery/Areas/Admin/Views/UpdateListed/Index.cshtml +++ b/src/NuGetGallery/Areas/Admin/Views/UpdateListed/Index.cshtml @@ -107,10 +107,14 @@ }; let selectFilteredResults = function (isListedFilter) { + ko.utils.arrayForEach($self.searchResults(), function (result) { + result.Selected(false); + }); + var selection = parseInt(window.prompt("How many? (Default: All)", "")); selection = isNaN(selection) ? $self.searchResults().length : selection; - - if (selection === 0) { + + if (selection <= 0) { return true; }