Skip to content

Commit 98475cd

Browse files
author
Scott Bommarito
authored
Integrate Deprecate form with CVE/CWE autocomplete (#6944)
1 parent cf4911e commit 98475cd

14 files changed

Lines changed: 516 additions & 95 deletions

src/Bootstrap/dist/css/bootstrap-theme.css

Lines changed: 47 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Bootstrap/less/theme/page-manage-deprecation.less

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,60 @@
3838
margin-right: 15px;
3939
}
4040
}
41+
42+
.security-detail-list-item {
43+
padding: 10px;
44+
45+
span {
46+
text-decoration: none;
47+
color: black;
48+
}
49+
50+
.security-detail-list-item-existing {
51+
color: @state-info-text;
52+
}
53+
54+
.security-detail-list-item-missing {
55+
color: @state-danger-text;
56+
}
57+
58+
.security-detail-list-item-header {
59+
display: flex;
60+
justify-content: space-between;
61+
}
62+
63+
.security-detail-list-item-description {
64+
margin-top: 5px;
65+
}
66+
}
4167

4268
.security-detail-list-input {
4369
display: flex;
4470
justify-content: space-between;
4571

72+
.security-detail-list-autocomplete {
73+
width: 100%;
74+
position: relative;
75+
display: block;
76+
77+
.security-detail-list-autocomplete-content {
78+
position: absolute;
79+
z-index: 1;
80+
width: 100%;
81+
border-top: 0px;
82+
83+
.security-detail-list-item {
84+
overflow: hidden;
85+
text-overflow: ellipsis;
86+
white-space: nowrap;
87+
88+
&:focus, & > :focus, &:hover {
89+
background-color: @alert-info-bg;
90+
}
91+
}
92+
}
93+
}
94+
4695
button {
4796
margin-left: 15px;
4897
}
@@ -52,9 +101,6 @@
52101
margin-top: 10px;
53102

54103
.security-detail-list-item {
55-
display: flex;
56-
justify-content: space-between;
57-
padding: 10px;
58104
margin-top: 10px;
59105
}
60106
}

src/NuGetGallery/ActionName.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace NuGetGallery
5+
{
6+
public static class ActionName
7+
{
8+
public const string GetCveIds = "CveIds";
9+
public const string GetCweIds = "CweIds";
10+
}
11+
}

src/NuGetGallery/Controllers/ManageDeprecationJsonApiController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public ManageDeprecationJsonApiController(
4545

4646
[HttpGet]
4747
[UIAuthorize]
48-
[ActionName("CveIds")]
48+
[ActionName(ActionName.GetCveIds)]
4949
public JsonResult GetCveIds(string query)
5050
{
5151
// Get CVE data.
@@ -61,7 +61,7 @@ public JsonResult GetCveIds(string query)
6161

6262
[HttpGet]
6363
[UIAuthorize]
64-
[ActionName("CweIds")]
64+
[ActionName(ActionName.GetCweIds)]
6565
public JsonResult GetCweIds(string query)
6666
{
6767
// Get CWE data.

src/NuGetGallery/NuGetGallery.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
<Reference Include="System.Xml" />
124124
</ItemGroup>
125125
<ItemGroup>
126+
<Compile Include="ActionName.cs" />
126127
<Compile Include="App_Start\NuGetODataV2CuratedFeedConfig.cs" />
127128
<Compile Include="App_Start\NuGetODataV2FeedConfig.cs" />
128129
<Compile Include="App_Start\NuGetODataV1FeedConfig.cs" />

src/NuGetGallery/Scripts/gallery/common-multi-select-dropdown.js

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,11 @@ function MultiSelectDropdown(items, singularItemTitle, pluralItemTitle) {
1919
self.dropdownOpen(!self.dropdownOpen());
2020
};
2121

22-
this.isAncestor = function (element, ancestorSelector) {
23-
var $target = $(element);
24-
// '.closest' returns the list of ancestors between this element and the selector.
25-
// If the selector is not an ancestor of the element, it returns an empty list.
26-
return !!$target.closest(ancestorSelector).length;
27-
};
28-
29-
this.isElementInsideDropdown = function (element) {
30-
return self.isAncestor(element, self.dropdownSelector);
31-
};
32-
33-
// If the user clicks outside of the dropdown, close it.
34-
$(document).click(function (event) {
35-
if (!self.isElementInsideDropdown(event.target)) {
36-
self.dropdownOpen(false);
37-
}
38-
});
39-
40-
// If an element outside of the dropdown gains focus, close it.
41-
$(document).focusin(function (event) {
42-
if (!self.isElementInsideDropdown(event.target)) {
43-
self.dropdownOpen(false);
44-
}
45-
});
46-
47-
$(document).keydown(function (event) {
48-
var target = event.target;
49-
if (self.isElementInsideDropdown(target)) {
50-
// If we press escape while focus is inside the dropdown, close it
51-
if (event.which === 27) { // Escape key
52-
self.dropdownOpen(false);
53-
event.preventDefault();
54-
$(self.dropdownBtnSelector).focus();
55-
}
56-
}
57-
});
22+
window.nuget.configureDropdown(
23+
self.dropdownSelector,
24+
self.dropdownBtnSelector,
25+
self.dropdownOpen,
26+
false);
5827

5928
// A filter to be applied to the items
6029
this.filter = ko.observable('');

src/NuGetGallery/Scripts/gallery/common.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,49 @@
353353
return stringToFormat;
354354
};
355355

356+
nuget.isAncestor = function (element, ancestorSelector) {
357+
var $target = $(element);
358+
// '.closest' returns the list of ancestors between this element and the selector.
359+
// If the selector is not an ancestor of the element, it returns an empty list.
360+
return !!$target.closest(ancestorSelector).length;
361+
};
362+
363+
nuget.configureDropdown = function (dropdownSelector, dropdownHeaderSelector, setDropdownOpen, openWhenFocused) {
364+
var isElementInsideDropdown = function (element) {
365+
return window.nuget.isAncestor(element, dropdownSelector);
366+
};
367+
368+
// If the user clicks outside the dropdown, close it
369+
$(document).click(function (event) {
370+
if (!isElementInsideDropdown(event.target)) {
371+
setDropdownOpen(false);
372+
}
373+
});
374+
375+
$(document).focusin(function (event) {
376+
var isInsideDropdown = isElementInsideDropdown(event.target);
377+
if (isInsideDropdown && openWhenFocused) {
378+
// If an element inside the dropdown gains focus, open the dropdown if configured to
379+
setDropdownOpen(true);
380+
} else if (!isInsideDropdown) {
381+
// If an element outside of the dropdown gains focus, close it
382+
setDropdownOpen(false);
383+
}
384+
});
385+
386+
$(document).keydown(function (event) {
387+
var target = event.target;
388+
if (isElementInsideDropdown(target)) {
389+
// If we press escape while focus is inside the dropdown, close it
390+
if (event.which === 27) { // Escape key
391+
setDropdownOpen(false);
392+
event.preventDefault();
393+
$(dropdownHeaderSelector).focus();
394+
}
395+
}
396+
});
397+
};
398+
356399
window.nuget = nuget;
357400

358401
jQuery.extend(jQuery.expr[':'], {

0 commit comments

Comments
 (0)