From 5dd4e7a3bed095a450ee9a02bcf6bff785cbdffc Mon Sep 17 00:00:00 2001
From: Shaina Peters
Date: Wed, 24 May 2023 06:24:57 -0400
Subject: [PATCH 1/4] added to ability to filter imports by list
---
js/5etools-importer.js | 28 ++++++++++++++++++++++++++++
js/5etools-template.js | 16 ++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/js/5etools-importer.js b/js/5etools-importer.js
index f315fde5..62c18594 100644
--- a/js/5etools-importer.js
+++ b/js/5etools-importer.js
@@ -730,6 +730,10 @@ function d20plusImporter () {
d20plus.importer._importSelectPublished(importList);
});
+ $("#importlist-filter-list").bind("click", () => {
+ d20plus.importer._importFilterList(importList);
+ });
+
if (options.listIndexConverter) {
const $iptFilter = $(`#import-list-filter`).show();
$(`#import-list-filter-help`).show();
@@ -1213,6 +1217,30 @@ function d20plusImporter () {
});
};
+ d20plus.importer._importFilterList = function (importList) {
+ const $winFilterList = $("#d20plus-import-filter-list");
+ $winFilterList.dialog("open");
+ const $btnImport = $winFilterList.find(".btn");
+ const $winText = $winFilterList.find(".table-import-textarea");
+
+ $btnImport.on("click", () => {
+ const toSearch = $winText.val().split("\n");
+
+ // If no search terms are entered, reset the filter
+ if (toSearch.length == 1 && toSearch[0] == '') {
+ importList.filter();
+ }
+ // Filters to match names on the list
+ else{
+ importList.filter(it => {
+ return toSearch.includes(it._values.name.toLowerCase());
+ });
+ }
+
+ $winFilterList.dialog("close");
+ }).appendTo($winFilterList);
+ };
+
d20plus.importer.CharacterAttributesProxy = class {
constructor (character) {
this.character = character;
diff --git a/js/5etools-template.js b/js/5etools-template.js
index f24146dd..5ca02752 100644
--- a/js/5etools-template.js
+++ b/js/5etools-template.js
@@ -207,6 +207,7 @@ const d20plusTemplate = function () {
$body.append(d20plus.template5e.importDialogHtml);
$body.append(d20plus.template5e.importListHTML);
$body.append(d20plus.template5e.importListPropsHTML);
+ $body.append(d20plus.template5e.importFilterList);
$("#d20plus-import").dialog({
autoOpen: false,
resizable: false,
@@ -223,6 +224,12 @@ const d20plusTemplate = function () {
width: 300,
height: 600,
});
+ $("#d20plus-import-filter-list").dialog({
+ autoOpen: false,
+ resizable: true,
+ width: 640,
+ height: 480,
+ });
// add class subclasses to the subclasses dropdown(s)
d20plus.template5e._populateDropdown("#button-subclasses-select", "#import-subclasses-url", CLASS_DATA_DIR, classDataUrls, "", ["class"]);
@@ -321,6 +328,8 @@ ${finalText}
+
+
@@ -351,6 +360,13 @@ ${finalText}
+`;
+
+d20plus.template5e.importFilterList = `
+
+
`;
d20plus.template5e.importDialogHtml = `
From 7f761838d7a06498a0d61376a1979c659368e2a0 Mon Sep 17 00:00:00 2001
From: Shaina Peters
Date: Wed, 24 May 2023 14:06:52 -0400
Subject: [PATCH 2/4] fixed case issue
---
js/5etools-importer.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/js/5etools-importer.js b/js/5etools-importer.js
index 62c18594..32cd34a1 100644
--- a/js/5etools-importer.js
+++ b/js/5etools-importer.js
@@ -1224,7 +1224,7 @@ function d20plusImporter () {
const $winText = $winFilterList.find(".table-import-textarea");
$btnImport.on("click", () => {
- const toSearch = $winText.val().split("\n");
+ const toSearch = $winText.val().toLowerCase().split("\n");
// If no search terms are entered, reset the filter
if (toSearch.length == 1 && toSearch[0] == '') {
From 7627d1c6f72ea764bb78824405a54084962d48d6 Mon Sep 17 00:00:00 2001
From: Shaina Peters
Date: Sun, 28 May 2023 07:27:40 -0400
Subject: [PATCH 3/4] source filtering and ui improvements
---
js/5etools-importer.js | 53 ++++++++++++++++++++++++++++++++++--------
js/5etools-template.js | 26 +++++++++++++++++----
2 files changed, 65 insertions(+), 14 deletions(-)
diff --git a/js/5etools-importer.js b/js/5etools-importer.js
index 32cd34a1..94c68eb1 100644
--- a/js/5etools-importer.js
+++ b/js/5etools-importer.js
@@ -705,7 +705,7 @@ function d20plusImporter () {
// init list library
const importList = new List("import-list", {
- valueNames: options.listIndex || ["name"],
+ valueNames: options.listIndex || ["name", "source"],
});
// reset the UI and add handlers
@@ -730,9 +730,12 @@ function d20plusImporter () {
d20plus.importer._importSelectPublished(importList);
});
- $("#importlist-filter-list").bind("click", () => {
+ $("#importlist-filter").bind("click", () => {
d20plus.importer._importFilterList(importList);
});
+ $("#importlist-reset").bind("click", () => {
+ d20plus.importer._importResetList(importList);
+ });
if (options.listIndexConverter) {
const $iptFilter = $(`#import-list-filter`).show();
@@ -1224,23 +1227,53 @@ function d20plusImporter () {
const $winText = $winFilterList.find(".table-import-textarea");
$btnImport.on("click", () => {
- const toSearch = $winText.val().toLowerCase().split("\n");
- // If no search terms are entered, reset the filter
- if (toSearch.length == 1 && toSearch[0] == '') {
- importList.filter();
- }
- // Filters to match names on the list
- else{
+ function filterList () {
+ const toSearch = $winText.val().toLowerCase().replaceAll(`"`, "").split("\n");
+ const firstLine = toSearch[0];
+ const filterUnofficial = !d20plus.cfg.getOrDefault("import", "allSourcesIncludeUnofficial");
+
+ // If no search terms are entered, reset the filter
+ if (toSearch.length == 1 && firstLine == '') {
+ importList.filter();
+ return;
+ }
+
+ const searchDict = {};
+ toSearch.forEach(it => {
+ const items = it.split(",");
+ // If additional filters are added, they can go here
+ searchDict[items[0].trim()] = {
+ "name": items[0].trim(),
+ "source": items.length > 1 ? items[1].trim() : null,
+ // Some categories list their source in this format
+ "altsource": items.length > 1 ? `src[${items[1].trim()}]`: null,
+ }
+ })
+
+ // Filters to match names and sources on the list
+ x = importList
importList.filter(it => {
- return toSearch.includes(it._values.name.toLowerCase());
+ const name = it._values.name.toLowerCase();
+ const source = it._values.source.toLowerCase();
+
+ if (!(name in searchDict)) return false;
+ if (!searchDict[name].source) return true;
+ if (searchDict[name].source === source || searchDict[name].altsource === source) return true;
+ return false;
});
}
+ filterList();
+
$winFilterList.dialog("close");
}).appendTo($winFilterList);
};
+ d20plus.importer._importResetList = function (importList) {
+ importList.filter();
+ };
+
d20plus.importer.CharacterAttributesProxy = class {
constructor (character) {
this.character = character;
diff --git a/js/5etools-template.js b/js/5etools-template.js
index 5ca02752..753737e1 100644
--- a/js/5etools-template.js
+++ b/js/5etools-template.js
@@ -228,7 +228,7 @@ const d20plusTemplate = function () {
autoOpen: false,
resizable: true,
width: 640,
- height: 480,
+ height: 540,
});
// add class subclasses to the subclasses dropdown(s)
@@ -329,7 +329,8 @@ ${finalText}
-
+
+
@@ -363,10 +364,27 @@ ${finalText}
`;
d20plus.template5e.importFilterList = `
+
+ Write down a vertical list of the items you want to filter and then Filter List > Select Visible > Import
+ [!].
+
+
+ You can either manually write down your list, or you can go to the corresponding page in 5etools > make your list > Table View > Copy CSV to Clipboard > Paste it here > Filter List
+ [?].
+
-
+
`;
d20plus.template5e.importDialogHtml = `
From b5091a64e232fb2a38f006fda8efa4ae2a24e17c Mon Sep 17 00:00:00 2001
From: Shaina Peters
Date: Sun, 28 May 2023 07:29:48 -0400
Subject: [PATCH 4/4] fixed typo
---
js/5etools-template.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/js/5etools-template.js b/js/5etools-template.js
index 753737e1..a3630a01 100644
--- a/js/5etools-template.js
+++ b/js/5etools-template.js
@@ -384,7 +384,7 @@ etc.
(the 2nd and 3rd example show the 2 ways to indicate source)'
class="table-import-textarea">
-
+