diff --git a/assets/controllers/result_filter_controller.js b/assets/controllers/result_filter_controller.js index a039da8..3806cdf 100644 --- a/assets/controllers/result_filter_controller.js +++ b/assets/controllers/result_filter_controller.js @@ -27,10 +27,23 @@ export default class extends Controller { 'episodes': Array, } - connect() { - if (this.mediaTypeValue === "tvshows") { - this.activeFilter['season'] = 1; - } + async connect() { + await fetch('/api/preferences/media') + .then(response => response.json()) + .then(response => { + this.addResolutions(response['resolution']); + this.addCodecs(response['codec']); + }); + + await fetch('/api/user/preferences/values') + .then(response => response.json()) + .then(response => { + this.activeFilter = response; + if (this.mediaTypeValue === "tvshows") { + this.activeFilter['season'] = 1; + } + console.log(this.activeFilter); + }) } async movieResultsOutletConnected(outlet) { @@ -51,6 +64,20 @@ export default class extends Controller { }) } + addResolutions(resolutions) { + this.resolutionTarget.innerHTML = ''; + this.resolutionTarget.innerHTML += resolutions.preferenceOptions + .map((resolution) => '') + .join(); + } + + addCodecs(codecs) { + this.codecTarget.innerHTML = ''; + this.codecTarget.innerHTML += codecs.preferenceOptions + .map((codec) => '') + .join(); + } + addLanguages(option, props) { const languages = Object.assign([], JSON.parse(props['languages'])); languages.forEach((language) => { diff --git a/src/Twig/Components/Filter.php b/src/Twig/Components/Filter.php new file mode 100644 index 0000000..0617073 --- /dev/null +++ b/src/Twig/Components/Filter.php @@ -0,0 +1,12 @@ +json( + Map::from($preferencesRepository->findEnabled()) + ->rekey(fn($element) => $element->getId()) + ->toArray() + ); + } +} diff --git a/src/User/Framework/Controller/Api/UserApiController.php b/src/User/Framework/Controller/Api/UserApiController.php new file mode 100644 index 0000000..950db6f --- /dev/null +++ b/src/User/Framework/Controller/Api/UserApiController.php @@ -0,0 +1,20 @@ +json( + $security->getUser()->getUserPreferenceValues() + ); + } +} diff --git a/src/User/Framework/Entity/PreferenceOption.php b/src/User/Framework/Entity/PreferenceOption.php index d9fd8ca..6fa7cad 100644 --- a/src/User/Framework/Entity/PreferenceOption.php +++ b/src/User/Framework/Entity/PreferenceOption.php @@ -4,6 +4,7 @@ namespace App\User\Framework\Entity; use App\User\Framework\Repository\PreferenceOptionRepository; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Serializer\Attribute\Ignore; #[ORM\Entity(repositoryClass: PreferenceOptionRepository::class)] class PreferenceOption @@ -19,6 +20,7 @@ class PreferenceOption #[ORM\Column(length: 255, nullable: true)] private ?string $value = null; + #[Ignore] #[ORM\ManyToOne(inversedBy: 'preferenceOptions')] private ?Preference $preference = null; diff --git a/src/User/Framework/Entity/User.php b/src/User/Framework/Entity/User.php index ae5ea0a..eb2eb91 100644 --- a/src/User/Framework/Entity/User.php +++ b/src/User/Framework/Entity/User.php @@ -2,6 +2,7 @@ namespace App\User\Framework\Entity; +use Aimeos\Map; use App\User\Framework\Repository\PreferencesRepository; use App\User\Framework\Repository\UserRepository; use Doctrine\Common\Collections\ArrayCollection; @@ -184,4 +185,12 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + + public function getUserPreferenceValues() + { + return Map::from($this->userPreferences) + ->rekey(fn(UserPreference $userPreference) => $userPreference->getPreference()->getId()) + ->map(fn(UserPreference $userPreference) => $userPreference->getPreferenceValue()) + ->toArray(); + } } diff --git a/templates/components/Filter.html.twig b/templates/components/Filter.html.twig new file mode 100644 index 0000000..7ec7964 --- /dev/null +++ b/templates/components/Filter.html.twig @@ -0,0 +1,88 @@ +