-
Notifications
You must be signed in to change notification settings - Fork 48
Filter imports by list of item #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,6 +730,13 @@ function d20plusImporter () { | |
| d20plus.importer._importSelectPublished(importList); | ||
| }); | ||
|
|
||
| $("#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(); | ||
| $(`#import-list-filter-help`).show(); | ||
|
|
@@ -1213,6 +1220,60 @@ 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", () => { | ||
|
|
||
| function filterList () { | ||
| const toSearch = $winText.val().toLowerCase().replaceAll(`"`, "").split("\n"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we have quotes in the input, we should respect them; e.g. some generic CSV parsing ought to do the trick; should be simple enough to put in a utility function for it and call it good |
||
| 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, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please make everything uniformly use one style, then remove this workaround |
||
| } | ||
| }) | ||
|
|
||
| // Filters to match names and sources on the list | ||
| x = importList | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. junk line(?) |
||
| importList.filter(it => { | ||
| 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; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$winText.val().toLowerCase().replaceAll(", "").split("\n");->