mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-12-28 21:00:11 +00:00
make search results follow default view styles
This commit is contained in:
parent
1cbe0bbfc0
commit
099f9dfe00
@ -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):
|
||||
|
@ -10,19 +10,19 @@
|
||||
</div>
|
||||
<div class="multi-search-result">
|
||||
<h2>Video Results</h2>
|
||||
<div id="video-results" class="video-list grid">
|
||||
<div id="video-results" class="video-list {{ all_styles.home }}">
|
||||
<p>No videos found.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="multi-search-result">
|
||||
<h2>Channel Results</h2>
|
||||
<div id="channel-results" class="channel-list list">
|
||||
<div id="channel-results" class="channel-list {{ all_styles.channel }}">
|
||||
<p>No channels found.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="multi-search-result">
|
||||
<h2>Playlist Results</h2>
|
||||
<div id="playlist-results" class="playlist-list grid">
|
||||
<div id="playlist-results" class="playlist-list {{ all_styles.playlist }}">
|
||||
<p>No playlists found.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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 = `
|
||||
<div class="channel-banner list">
|
||||
<div class="channel-banner ${viewStyle}">
|
||||
<a href="/channel/${channelId}/">
|
||||
<img src="/cache/channels/${channelId}_banner.jpg" alt="${channelId}-banner">
|
||||
</a>
|
||||
</div>
|
||||
<div class="info-box info-box-2 list">
|
||||
<div class="info-box info-box-2 ${viewStyle}">
|
||||
<div class="info-box-item">
|
||||
<div class="round-img">
|
||||
<a href="/channel/${channelId}/">
|
||||
|
Loading…
Reference in New Issue
Block a user