Only require minor version

This commit is contained in:
Serial 2022-05-03 18:12:31 -04:00
parent 9173780568
commit 2c70af3cd5
2 changed files with 47 additions and 31 deletions

View File

@ -301,11 +301,15 @@ Otherwise, have a great day =^.^=
#version-filter li label {
padding-right: 0;
width: 40%;
width: 35%;
}
.version-filter-input {
height: 75%;
height: 60%;
width: 30%;
text-align: center;
border: none;
border-bottom: 1px solid #000000;
}
#filter-label, .filter-clear {
@ -429,7 +433,11 @@ Otherwise, have a great day =^.^=
<div id="version-filter">
<div class="btn-group" filter-dropdown>
<button type="button" class="btn btn-default dropdown-toggle">
Version <span id="version-filter-count" class="badge">{{versionFilterCount(version_filters)}}</span> <span class="caret"></span>
Version
<span id="version-filter-count" class="badge">
{{versionFilterCount(version_filters)}}
</span>
<span class="caret"></span>
</button>
<ul id="version-filter-selector" class="dropdown-menu">
<li class="checkbox">
@ -441,11 +449,20 @@ Otherwise, have a great day =^.^=
<li role="separator" class="divider"></li>
<li class="checkbox" ng-repeat="(filter, vars) in version_filters">
<label ng-attr-for="filter-{filter}">{{filter}}</label>
<input type="text" ng-attr-id="filter-{filter}" class="version-filter-input form-control filter-input" maxlength="6" placeholder="1.62.0" ng-model="version_filters[filter].version_str" ng-model-options="{debounce: 50}"/>
<span>1.</span>
<input type="text"
ng-attr-id="filter-{filter}"
class="version-filter-input form-control filter-input"
maxlength="2"
placeholder="62"
ng-model="version_filters[filter].minor_version"
ng-model-options="{debounce: 50}" />
<span>.0</span>
</li>
</ul>
</div>
</div>
</div>
<div class="col-12 col-md-7 search-control">
<div class="input-group">

View File

@ -137,13 +137,12 @@
$scope.themes = THEMES_DEFAULT;
const DEFAULT_VERSION_FILTERS = {
"≥": { enabled: false, version_str: "" },
"≤": { enabled: false, version_str: "" },
"=": { enabled: false, version_str: "" },
"≥": { enabled: false, minor_version: "" },
"≤": { enabled: false, minor_version: "" },
"=": { enabled: false, minor_version: "" },
};
// Weird workaround to get a copy of the object
$scope.version_filters = JSON.parse(JSON.stringify(DEFAULT_VERSION_FILTERS));
$scope.version_regex = new RegExp('1\.\\d{2}\.\\d');
$scope.selectTheme = function (theme) {
setTheme(theme, true);
@ -181,42 +180,42 @@
$scope.byVersion = function(lint) {
function validate_version_str(ver) {
return ver.length === 6 && $scope.version_regex.test(ver);
}
function cmp_version(ver1, ver2, filter) {
// < 0: lint_version < version
// 0: equal
// > 0: lint_version > version
let result = ver1.localeCompare(ver2, undefined, {
numeric: true,
sensitivity: "base"
});
// "==" gets the highest priority, since all filters are inclusive
return (result === 0) || (filter === ">=" && result > 0) || (filter === "<=" && result < 0);
return ver.length === 2 && !isNaN(ver);
}
let filters = $scope.version_filters;
// Strip the "pre " prefix for pre 1.29.0 lints
let lint_version = lint.version.startsWith("pre ") ? lint.version.substring(4, lint.version.length) : lint.version;
let lint_minor_verison = lint_version.substring(2, 4);
for (const filter in filters) {
let version_str = filters[filter].version_str;
let minor_version = filters[filter].minor_version;
// Skip the work for version strings with invalid lengths or characters
if (!validate_version_str(version_str)) {
if (!validate_version_str(minor_version)) {
filters[filter].enabled = false;
continue;
}
filters[filter].enabled = true;
let result = cmp_version(lint_version, version_str, filter);
if (result && filter === "==") {
return true;
} else if (!result) {
let result;
switch (filter) {
case "≥":
result = (lint_minor_verison >= minor_version);
break;
case "≤":
result = (lint_minor_verison <= minor_version);
break;
// "=" gets the highest priority, since all filters are inclusive
case "=":
return (lint_minor_verison === minor_version);
default:
return true
}
if (!result) {
return false;
}
@ -227,12 +226,12 @@
cmp_filter = "≥";
}
let cmp_version_str = filters[cmp_filter].version_str;
if (!filters[cmp_filter].enabled || !validate_version_str(cmp_version_str)) {
let cmp_minor_version = filters[cmp_filter].minor_version;
if (!filters[cmp_filter].enabled || !validate_version_str(cmp_minor_version)) {
return true;
}
return cmp_version(lint_version, cmp_version_str, cmp_filter);
return (cmp_filter === "≥") ? (lint_minor_verison > minor_version) : (lint_minor_verison < minor_version);
}
return true;