Patching in Blacklist/Whitelist Default Filters changes

Adds the ability to have default Whitelist/Blacklist filters that apply to all tabs at all times.
Whitelist - Only show matches (same as filter bar)
Blacklist - Do not show/hide matches
Both filter types are OR not AND, so a match on any keyword is considered a match.
This commit is contained in:
XxInvictus 2023-11-23 12:07:07 +10:30
parent c1b8ea99d6
commit 992a58266c
4 changed files with 39 additions and 14 deletions

View File

@ -44,10 +44,6 @@ public class IgnoreList extends GridPane {
setVgap(10);
setPadding(new Insets(20, 10, 10, 10));
var headline = new Label("Ignore List");
headline.getStyleClass().add("settings-group-label");
add(headline, 0, 0);
ignoreListView = new ListView<>();
ignoreListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
ignoreListView.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
@ -55,7 +51,7 @@ public class IgnoreList extends GridPane {
removeSelectedModels();
}
});
add(ignoreListView, 0, 1);
add(ignoreListView, 0, 0);
GridPane.setHgrow(ignoreListView, Priority.ALWAYS);
var remove = new Button("Remove");

View File

@ -129,6 +129,8 @@ public class SettingsTab extends Tab implements TabSelectionListener {
private final VariablePlayGroundDialogFactory variablePlayGroundDialogFactory = new VariablePlayGroundDialogFactory();
private SimpleBooleanProperty checkForUpdates;
private PostProcessingStepPanel postProcessingStepPanel;
private SimpleStringProperty filterBlacklist;
private SimpleStringProperty filterWhitelist;
public SettingsTab(List<Site> sites, Recorder recorder) {
this.sites = sites;
@ -207,6 +209,8 @@ public class SettingsTab extends Tab implements TabSelectionListener {
dateTimeFormat = new SimpleStringProperty(null, "dateTimeFormat", settings.dateTimeFormat);
tabsSortable = new SimpleBooleanProperty(null, "tabsSortable", settings.tabsSortable);
checkForUpdates = new SimpleBooleanProperty(null, "checkForUpdates", settings.checkForUpdates);
filterBlacklist = new SimpleStringProperty(null, "filterBlacklist", settings.filterBlacklist);
filterWhitelist = new SimpleStringProperty(null, "filterWhitelist", settings.filterWhitelist);
}
private void createGui() {
@ -297,8 +301,13 @@ public class SettingsTab extends Tab implements TabSelectionListener {
Setting.of("Steps", postProcessingStepPanel),
Setting.of("", createHelpButton("Post-Processing Help", "http://localhost:5689/docs/PostProcessing.md")),
Setting.of("", createVariablePlayGroundButton()))),
Category.of("Events & Actions", new ActionSettingsPanel(recorder)), Category.of("Ignore List", ignoreList),
Category.of("Sites", siteCategories.toArray(new Category[0])),
Category.of("Events & Actions", new ActionSettingsPanel(recorder)),
Category.of("Filtering",
Group.of("Ignore List",
Setting.of("", ignoreList)),
Group.of("Text Filters",
Setting.of("Default Blacklist", filterBlacklist, "Default list of blacklist filters for site views, space seperated"),
Setting.of("Default Whitelist", filterWhitelist, "Default list of whitelist filters for site views, space seperated"))), Category.of("Sites", siteCategories.toArray(new Category[0])),
Category.of("Proxy",
Group.of("Proxy",
Setting.of("Type", proxyType).needsRestart(),

View File

@ -317,13 +317,29 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
if (updatesSuspended) {
return;
}
List<Model> models = filterIgnoredModels(updateService.getValue());
List<Model> models = filterModels(updateService.getValue());
updateGrid(models);
}
private List<Model> filterIgnoredModels(List<Model> models) {
private List<Model> filterModels(List<Model> models) {
List<String> ignored = Config.getInstance().getSettings().ignoredModels;
return models.stream().filter(m -> !ignored.contains(m.getUrl())).collect(Collectors.toList());
String filterBlacklist = Config.getInstance().getSettings().filterBlacklist;
String filterWhitelist = Config.getInstance().getSettings().filterWhitelist;
if (filterBlacklist.isBlank() && filterWhitelist.isBlank()) {
return models.stream()
.filter(m -> !ignored.contains(m.getUrl()))
.collect(Collectors.toList());
} else if (filterBlacklist.isBlank()) {
return models.stream()
.filter(m -> !ignored.contains(m.getUrl()))
.filter(m -> matches(m, filterWhitelist, true))
.collect(Collectors.toList());
}
return models.stream()
.filter(m -> !ignored.contains(m.getUrl()))
.filter(m -> !matches(m, filterBlacklist, true))
.filter(m -> matches(m, filterWhitelist, true))
.collect(Collectors.toList());
}
protected void updateGrid(List<? extends Model> models) {
@ -633,7 +649,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
var node = iterator.next();
if (node instanceof ThumbCell cell) {
var m = cell.getModel();
if (!matches(m, filter)) {
if (!matches(m, filter, false)) {
iterator.remove();
filteredThumbCells.add(cell);
cell.setSelected(false);
@ -645,7 +661,7 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
for (Iterator<ThumbCell> iterator = filteredThumbCells.iterator(); iterator.hasNext(); ) {
var thumbCell = iterator.next();
var m = thumbCell.getModel();
if (matches(m, filter)) {
if (matches(m, filter, false)) {
iterator.remove();
insert(thumbCell);
}
@ -687,12 +703,14 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
}
}
private boolean matches(Model m, String filter) {
private boolean matches(Model m, String filter, Boolean anyMatch) {
try {
String[] tokens = filter.split(" ");
var tokensMissing = false;
for (String token : tokens) {
if (!modelPropertiesMatchToken(token, m)) {
if (anyMatch && modelPropertiesMatchToken(token, m)) {
return true;
} else if (!modelPropertiesMatchToken(token, m)) {
tokensMissing = true;
}
}

View File

@ -216,4 +216,6 @@ public class Settings {
public boolean checkForUpdates = true;
public int thumbCacheSize = 16;
public boolean dreamcamVR = false;
public String filterBlacklist = "";
public String filterWhitelist = "";
}