Switch input to type=number; Separate version validation out of byVersion

This commit is contained in:
Serial 2022-05-14 20:08:10 -04:00
parent 4ed52bf13e
commit a30587e0fe
2 changed files with 61 additions and 60 deletions

View file

@ -291,7 +291,7 @@ Otherwise, have a great day =^.^=
border: 1px solid var(--theme-popup-border);
}
#version-filter-selector .checkbox {
#version-filter-selector .item {
display: flex;
}
@ -440,23 +440,24 @@ Otherwise, have a great day =^.^=
<span class="caret"></span>
</button>
<ul id="version-filter-selector" class="dropdown-menu">
<li class="checkbox">
<li class="item">
<label ng-click="clearVersionFilters()">
<input type="checkbox" class="invisible" />
Clear filters
</label>
</li>
<li role="separator" class="divider"></li>
<li class="checkbox" ng-repeat="(filter, vars) in versionFilters">
<li class="item" ng-repeat="(filter, vars) in versionFilters">
<label ng-attr-for="filter-{filter}">{{filter}}</label>
<span>1.</span>
<input type="text"
<input type="number"
min="29"
ng-attr-id="filter-{filter}"
class="version-filter-input form-control filter-input"
maxlength="2"
placeholder="xx"
ng-model="versionFilters[filter].minorVersion"
ng-model-options="{debounce: 50}" />
ng-model-options="{debounce: 50}"
ng-change="updateVersionFilters()" />
<span>.0</span>
</li>
</ul>

View file

@ -137,9 +137,9 @@
$scope.themes = THEMES_DEFAULT;
$scope.versionFilters = {
"≥": {enabled: false, minorVersion: ""},
"≤": {enabled: false, minorVersion: ""},
"=": {enabled: false, minorVersion: ""},
"≥": {enabled: false, minorVersion: null },
"≤": {enabled: false, minorVersion: null },
"=": {enabled: false, minorVersion: null },
};
$scope.selectTheme = function (theme) {
@ -170,7 +170,7 @@
$scope.clearVersionFilters = function () {
for (let filter in $scope.versionFilters) {
$scope.versionFilters[filter] = { enabled: false, minorVersion: "" };
$scope.versionFilters[filter] = { enabled: false, minorVersion: null };
}
}
@ -178,62 +178,62 @@
return Object.values(obj).filter(x => x.enabled).length;
}
$scope.byVersion = function(lint) {
function validateVersionStr(ver) {
return ver.length === 2 && !isNaN(ver);
$scope.updateVersionFilters = function() {
for (const filter in $scope.versionFilters) {
let minorVersion = $scope.versionFilters[filter].minorVersion;
// 1.29.0 and greater
if (minorVersion && minorVersion > 28) {
$scope.versionFilters[filter].enabled = true;
}
$scope.versionFilters[filter].enabled = false;
}
}
$scope.byVersion = function(lint) {
let filters = $scope.versionFilters;
// Strip the "pre " prefix for pre 1.29.0 lints
let lintVersion = lint.version.startsWith("pre ") ? lint.version.substring(4, lint.version.length) : lint.version;
let lintMinorVersion = lintVersion.substring(2, 4);
for (const filter in filters) {
let minorVersion = filters[filter].minorVersion;
if (filters[filter].enabled) {
let minorVersion = filters[filter].minorVersion;
// Skip the work for version strings with invalid lengths or characters
if (!validateVersionStr(minorVersion)) {
filters[filter].enabled = false;
continue;
// Strip the "pre " prefix for pre 1.29.0 lints
let lintVersion = lint.version.startsWith("pre ") ? lint.version.substring(4, lint.version.length) : lint.version;
let lintMinorVersion = lintVersion.substring(2, 4);
let result;
switch (filter) {
case "≥":
result = (lintMinorVersion >= minorVersion);
break;
case "≤":
result = (lintMinorVersion <= minorVersion);
break;
// "=" gets the highest priority, since all filters are inclusive
case "=":
return (lintMinorVersion == minorVersion);
default:
return true
}
if (!result) {
return false;
}
let cmpFilter;
if (filter === "≥") {
cmpFilter = "≤";
} else {
cmpFilter = "≥";
}
if (filters[cmpFilter].enabled) {
let cmpMinorVersion = filters[cmpFilter].minorVersion;
result = (cmpFilter === "≥") ? (lintMinorVersion >= cmpMinorVersion) : (lintMinorVersion <= cmpMinorVersion);
}
return result;
}
filters[filter].enabled = true;
let result;
switch (filter) {
case "≥":
result = (lintMinorVersion >= minorVersion);
break;
case "≤":
result = (lintMinorVersion <= minorVersion);
break;
// "=" gets the highest priority, since all filters are inclusive
case "=":
return (lintMinorVersion === minorVersion);
default:
return true
}
if (!result) {
return false;
}
let cmpFilter;
if (filter === "≥") {
cmpFilter = "≤";
} else {
cmpFilter = "≥";
}
let cmpMinorVersion = filters[cmpFilter].minorVersion;
if (!validateVersionStr(cmpMinorVersion)) {
filters[cmpFilter].enabled = false;
return true;
}
filters[cmpFilter].enabled = true;
return (cmpFilter === "≥") ? (lintMinorVersion >= cmpMinorVersion) : (lintMinorVersion <= cmpMinorVersion);
}
return true;