-
Notifications
You must be signed in to change notification settings - Fork 643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Organizations] Include reserved namespaces and package ownership requests in Manage Packages page filtering #5491
Changes from 10 commits
60e0257
5d0ab6a
1247894
4326914
62bd96d
c3ea995
8529734
e610989
43da5b4
6943e08
6da8985
6067daa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,16 @@ | |
|
||
function showInitialPackagesData(dataSelector, packagesList) { | ||
var downloadsCount = 0; | ||
$.each(packagesList, function () { downloadsCount += this.TotalDownloadCount }); | ||
$.each(packagesList, function () { downloadsCount += this.TotalDownloadCount; }); | ||
$(dataSelector).text(formatPackagesData(packagesList.length, downloadsCount)); | ||
} | ||
|
||
function formatPackagesData(packagesCount, downloadsCount) { | ||
return packagesCount.toLocaleString() | ||
+ ' package' + (packagesCount == 1 ? '' : 's') | ||
+ ' package' + (packagesCount === 1 ? '' : 's') | ||
+ ' / ' | ||
+ downloadsCount.toLocaleString() | ||
+ ' download' + (downloadsCount == 1 ? '' : 's'); | ||
+ ' download' + (downloadsCount === 1 ? '' : 's'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. awesome - thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was tired of those LINT errors haha |
||
} | ||
|
||
$(function () { | ||
|
@@ -90,6 +90,141 @@ | |
}, this); | ||
} | ||
|
||
function showInitialReservedNamespaceData(dataSelector, namespacesList) { | ||
$(dataSelector).text(formatReservedNamespacesData(namespacesList.length)); | ||
} | ||
|
||
function formatReservedNamespacesData(namespacesCount) { | ||
return namespacesCount.toLocaleString() + " namespace" + (namespacesCount === 1 ? '' : 's'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can add a pluralize helper in common.js? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little skeptical about adding something like this given that I'm fine with adding a function just for this file because it is used 3 times but beyond that scope might be misleading. |
||
|
||
function ReservedNamespaceListItemViewModel(reservedNamespaceListViewModel, namespaceItem) { | ||
var self = this; | ||
|
||
this.ReservedNamespaceListViewModel = reservedNamespaceListViewModel; | ||
this.Pattern = namespaceItem.Pattern; | ||
this.SearchUrl = namespaceItem.SearchUrl; | ||
this.Owners = namespaceItem.Owners; | ||
this.IsPublic = namespaceItem.IsPublic; | ||
|
||
this.Visible = ko.observable(true); | ||
|
||
this.UpdateVisibility = function (ownerFilter) { | ||
var visible = ownerFilter === "All packages"; | ||
if (!visible) { | ||
for (var i in self.Owners) { | ||
if (ownerFilter === self.Owners[i].Username) { | ||
visible = true; | ||
break; | ||
} | ||
} | ||
} | ||
this.Visible(visible); | ||
}; | ||
} | ||
|
||
function ReservedNamespaceListViewModel(managePackagesViewModel, namespaces) { | ||
var self = this; | ||
|
||
this.ManagePackagesViewModel = managePackagesViewModel; | ||
this.Namespaces = $.map(namespaces, function (data) { | ||
return new ReservedNamespaceListItemViewModel(self, data); | ||
}); | ||
this.VisibleNamespacesCount = ko.observable(); | ||
this.VisibleNamespacesHeading = ko.pureComputed(function () { | ||
return formatReservedNamespacesData(ko.unwrap(self.VisibleNamespacesCount())); | ||
}); | ||
|
||
this.ManagePackagesViewModel.OwnerFilter.subscribe(function (newOwner) { | ||
var namespacesCount = 0; | ||
for (var i in self.Namespaces) { | ||
self.Namespaces[i].UpdateVisibility(newOwner.Username); | ||
if (self.Namespaces[i].Visible()) { | ||
namespacesCount++; | ||
} | ||
} | ||
this.VisibleNamespacesCount(namespacesCount); | ||
}, this); | ||
} | ||
|
||
function showInitialOwnerRequestsData(dataSelector, requestsList) { | ||
$(dataSelector).text(formatOwnerRequestsData(requestsList.length)); | ||
} | ||
|
||
function formatOwnerRequestsData(requestsCount) { | ||
return requestsCount.toLocaleString() + " request" + (requestsCount === 1 ? '' : 's'); | ||
} | ||
|
||
function OwnerRequestsItemViewModel(ownerRequestsListViewModel, ownerRequestItem, showReceived, showSent) { | ||
var self = this; | ||
|
||
this.OwnerRequestsListViewModel = ownerRequestsListViewModel; | ||
this.Id = ownerRequestItem.Id; | ||
this.Requesting = ownerRequestItem.Requesting; | ||
this.New = ownerRequestItem.New; | ||
this.Owners = ownerRequestItem.Owners; | ||
this.PackageIconUrl = ownerRequestItem.PackageIconUrl | ||
? ownerRequestItem.PackageIconUrl | ||
: this.OwnerRequestsListViewModel.ManagePackagesViewModel.DefaultPackageIconUrl; | ||
this.PackageUrl = ownerRequestItem.PackageUrl; | ||
this.CanAccept = ownerRequestItem.CanAccept; | ||
this.CanCancel = ownerRequestItem.CanCancel; | ||
this.ConfirmUrl = ownerRequestItem.ConfirmUrl; | ||
this.RejectUrl = ownerRequestItem.RejectUrl; | ||
this.CancelUrl = ownerRequestItem.CancelUrl; | ||
this.ShowReceived = showReceived; | ||
this.ShowSent = showSent; | ||
|
||
this.Visible = ko.observable(true); | ||
|
||
this.UpdateVisibility = function (ownerFilter) { | ||
var visible = ownerFilter === "All packages"; | ||
if (!visible) { | ||
if (self.ShowReceived && ownerFilter === self.New.Username) { | ||
visible = true; | ||
} | ||
|
||
if (self.ShowSent) { | ||
for (var i in self.Owners) { | ||
if (ownerFilter === self.Owners[i].Username) { | ||
visible = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
this.Visible(visible); | ||
}; | ||
this.PackageIconUrlFallback = ko.pureComputed(function () { | ||
var url = this.OwnerRequestsListViewModel.ManagePackagesViewModel.PackageIconUrlFallback; | ||
return "this.src='" + url + "'; this.onerror = null;"; | ||
}, this); | ||
} | ||
|
||
function OwnerRequestsListViewModel(managePackagesViewModel, requests, showReceived, showSent) { | ||
var self = this; | ||
|
||
this.ManagePackagesViewModel = managePackagesViewModel; | ||
this.Requests = $.map(requests, function (data) { | ||
return new OwnerRequestsItemViewModel(self, data, showReceived, showSent); | ||
}); | ||
this.VisibleRequestsCount = ko.observable(); | ||
this.VisibleRequestsHeading = ko.pureComputed(function () { | ||
return formatOwnerRequestsData(ko.unwrap(self.VisibleRequestsCount())); | ||
}, this); | ||
|
||
this.ManagePackagesViewModel.OwnerFilter.subscribe(function (newOwner) { | ||
var requestsCount = 0; | ||
for (var i in self.Requests) { | ||
self.Requests[i].UpdateVisibility(newOwner.Username); | ||
if (self.Requests[i].Visible()) { | ||
requestsCount++; | ||
} | ||
} | ||
this.VisibleRequestsCount(requestsCount); | ||
}, this); | ||
} | ||
|
||
function ManagePackagesViewModel(initialData) { | ||
var self = this; | ||
|
||
|
@@ -105,11 +240,17 @@ | |
|
||
this.ListedPackages = new PackagesListViewModel(this, "published", initialData.ListedPackages); | ||
this.UnlistedPackages = new PackagesListViewModel(this, "unlisted", initialData.UnlistedPackages); | ||
this.ReservedNamespaces = new ReservedNamespaceListViewModel(this, initialData.ReservedNamespaces); | ||
this.RequestsReceived = new OwnerRequestsListViewModel(this, initialData.RequestsReceived, true, false); | ||
this.RequestsSent = new OwnerRequestsListViewModel(this, initialData.RequestsSent, false, true); | ||
} | ||
|
||
// Immediately load initial expander data | ||
showInitialPackagesData("#listed-data", initialData.ListedPackages); | ||
showInitialPackagesData("#unlisted-data", initialData.UnlistedPackages); | ||
showInitialReservedNamespaceData("#namespaces-data", initialData.ReservedNamespaces); | ||
showInitialOwnerRequestsData("#requests-received-data", initialData.RequestsReceived); | ||
showInitialOwnerRequestsData("#requests-sent-data", initialData.RequestsSent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks great - I know this was a lot of work! |
||
|
||
// Set up the data binding. | ||
var managePackagesViewModel = new ManagePackagesViewModel(initialData); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably this should not throw.