forked from ontoportal/ontoportal_web_ui
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the filtering logic of the browse page
- Loading branch information
1 parent
c57eb9f
commit 719e456
Showing
8 changed files
with
407 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import {Controller} from "@hotwired/stimulus" | ||
import debounce from "debounce" | ||
// Connects to data-controller="browse-filters" | ||
export default class extends Controller { | ||
|
||
initialize() { | ||
this.dispatchInputEvent = debounce(this.dispatchInputEvent.bind(this), 900); | ||
} | ||
|
||
dispatchInputEvent(event) { | ||
if (event.target.name !== "search") { | ||
return | ||
} | ||
this.#dispatchEvent("search", [event.target.value]) | ||
} | ||
|
||
dispatchFilterEvent(event) { | ||
let checks; | ||
let filter; | ||
|
||
switch (event.target.name) { | ||
case "format": | ||
checks = event.target.value === '' ? [] : [event.target.value] | ||
filter = "format" | ||
break; | ||
case "Sort_by": | ||
checks = [event.target.value] | ||
filter = "sort_by" | ||
break; | ||
case "search": | ||
return | ||
case "views": | ||
checks = event.target.checked ? ['true'] : [] | ||
filter = "show_views" | ||
break; | ||
case "retired": | ||
checks = event.target.checked ? ['true'] : [] | ||
filter = "show_retired" | ||
break; | ||
default: | ||
checks = this.#getSelectedChecks().map(x => x.name) | ||
filter = this.element.id.split("_")[0] | ||
} | ||
|
||
this.#dispatchEvent(filter, checks) | ||
} | ||
|
||
|
||
#dispatchEvent(filter, checks){ | ||
let data = { | ||
[filter]: checks, | ||
} | ||
const customEvent = new CustomEvent('changed', { | ||
detail: { | ||
data: data | ||
}, bubbles: true | ||
}); | ||
|
||
this.element.dispatchEvent(customEvent); | ||
} | ||
#getSelectedChecks() { | ||
return Array.from(this.element.querySelectorAll('input:checked')) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters