diff --git a/tubearchivist/home/forms.py b/tubearchivist/home/forms.py index d5a52db..1aa3235 100644 --- a/tubearchivist/home/forms.py +++ b/tubearchivist/home/forms.py @@ -105,6 +105,9 @@ class MultiSearchForm(forms.Form): } ), ) + home = forms.CharField(widget=forms.HiddenInput()) + channel = forms.CharField(widget=forms.HiddenInput()) + playlist = forms.CharField(widget=forms.HiddenInput()) class AddToQueueForm(forms.Form): diff --git a/tubearchivist/home/templates/home/search.html b/tubearchivist/home/templates/home/search.html index 7a0f411..2ca799b 100644 --- a/tubearchivist/home/templates/home/search.html +++ b/tubearchivist/home/templates/home/search.html @@ -10,19 +10,19 @@

Video Results

-
+

No videos found.

Channel Results

-
+

No channels found.

Playlist Results

-
+

No playlists found.

diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index d9a4e40..95b3c61 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -71,6 +71,19 @@ class ArchivistViewConfig(View): return view_style + def get_all_view_styles(self): + """get dict of all view stiles for search form""" + all_keys = ["channel", "playlist", "home"] + all_styles = {} + for view_origin in all_keys: + view_key = f"{self.user_id}:view:{view_origin}" + view_style = self.user_conf.get_message(view_key)["status"] + if not view_style: + view_style = self.default_conf["default_view"][view_origin] + all_styles[view_origin] = view_style + + return all_styles + def _get_hide_watched(self): hide_watched_key = f"{self.user_id}:hide_watched" hide_watched = self.user_conf.get_message(hide_watched_key)["status"] @@ -655,7 +668,11 @@ class SearchView(ArchivistResultsView): def get(self, request): """handle get request""" self.initiate_vars(request) - self.context.update({"search_form": MultiSearchForm()}) + all_styles = self.get_all_view_styles() + self.context.update({"all_styles": all_styles}) + self.context.update( + {"search_form": MultiSearchForm(initial=all_styles)} + ) return render(request, "home/search.html", self.context) diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index 19f54c1..2d5b465 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -379,33 +379,40 @@ function searchMulti(query) { }; } +function getViewDefaults(view) { + var defaultView = document.getElementById("id_" + view).value; + return defaultView +} function populateMultiSearchResults(allResults) { // videos + var defaultVideo = getViewDefaults("home"); var allVideos = allResults["video_results"]; var videoBox = document.getElementById("video-results"); videoBox.innerHTML = ""; for (let index = 0; index < allVideos.length; index++) { const video = allVideos[index]["source"]; - const videoDiv = createVideo(video, "grid"); + const videoDiv = createVideo(video, defaultVideo); videoBox.appendChild(videoDiv); }; // channels + var defaultChannel = getViewDefaults("channel"); var allChannels = allResults["channel_results"]; var channelBox = document.getElementById("channel-results"); channelBox.innerHTML = ""; for (let index = 0; index < allChannels.length; index++) { const channel = allChannels[index]["source"]; - const channelDiv = createChannel(channel, "list"); + const channelDiv = createChannel(channel, defaultChannel); channelBox.appendChild(channelDiv); }; // playlists + var defaultPlaylist = getViewDefaults("playlist"); var allPlaylists = allResults["playlist_results"]; var playlistBox = document.getElementById("playlist-results"); playlistBox.innerHTML = ""; for (let index = 0; index < allPlaylists.length; index++) { const playlist = allPlaylists[index]["source"]; - const playlistDiv = createPlaylist(playlist, "grid"); + const playlistDiv = createPlaylist(playlist, defaultPlaylist); playlistBox.appendChild(playlistDiv); }; } @@ -469,12 +476,12 @@ function createChannel(channel, viewStyle) { }; // build markup const markup = ` -
+ -
+