From 4915aa0c11b73b5d9652774f1c594f4f84507fe8 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 31 Dec 2021 13:42:07 +0700 Subject: [PATCH] remove now redundant search forms --- tubearchivist/home/forms.py | 33 ---------- tubearchivist/home/src/frontend.py | 8 --- tubearchivist/home/src/searching.py | 21 ------- .../home/templates/home/channel.html | 12 ---- tubearchivist/home/templates/home/home.html | 9 --- .../home/templates/home/playlist.html | 10 --- tubearchivist/home/views.py | 26 -------- tubearchivist/static/css/style.css | 20 ------ tubearchivist/static/script.js | 63 ------------------- 9 files changed, 202 deletions(-) diff --git a/tubearchivist/home/forms.py b/tubearchivist/home/forms.py index e19e3c6..5eca965 100644 --- a/tubearchivist/home/forms.py +++ b/tubearchivist/home/forms.py @@ -83,39 +83,6 @@ class SchedulerSettingsForm(forms.Form): run_backup_rotate = forms.IntegerField(required=False) -class VideoSearchForm(forms.Form): - """search videos form""" - - searchInput = forms.CharField( - label="Search your videos", - widget=forms.TextInput(attrs={"autocomplete": "off"}), - ) - - -class ChannelSearchForm(forms.Form): - """search for channels""" - - searchInput = forms.CharField( - label="", - widget=forms.TextInput( - attrs={ - "oninput": "searchChannels(this.value)", - "autocomplete": "off", - "list": "resultBox", - } - ), - ) - - -class PlaylistSearchForm(forms.Form): - """search for playlists""" - - searchInput = forms.CharField( - label="", - widget=forms.TextInput(attrs={"autocomplete": "off"}), - ) - - class MultiSearchForm(forms.Form): """multi search form for /search/""" diff --git a/tubearchivist/home/src/frontend.py b/tubearchivist/home/src/frontend.py index 12d95e9..c81283e 100644 --- a/tubearchivist/home/src/frontend.py +++ b/tubearchivist/home/src/frontend.py @@ -75,7 +75,6 @@ class PostData: "db-backup": self._db_backup, "db-restore": self._db_restore, "fs-rescan": self._fs_rescan, - "channel-search": self._channel_search, "multi_search": self._multi_search, "delete-video": self._delete_video, "delete-channel": self._delete_channel, @@ -283,13 +282,6 @@ class PostData: rescan_filesystem.delay() return {"success": True} - def _channel_search(self): - """search for channel name as_you_type""" - search_query = self.exec_val - print("searching for: " + search_query) - search_results = SearchForm().search_channels(search_query) - return search_results - def _multi_search(self): """search through all indexes""" search_query = self.exec_val diff --git a/tubearchivist/home/src/searching.py b/tubearchivist/home/src/searching.py index b94d056..ffd11d4 100644 --- a/tubearchivist/home/src/searching.py +++ b/tubearchivist/home/src/searching.py @@ -155,27 +155,6 @@ class SearchForm: CONFIG = AppConfig().config ES_URL = CONFIG["application"]["es_url"] - def search_channels(self, search_query): - """fancy searching channels as you type""" - url = self.ES_URL + "/ta_channel/_search" - data = { - "size": 10, - "query": { - "multi_match": { - "query": search_query, - "type": "bool_prefix", - "fields": [ - "channel_name.search_as_you_type", - "channel_name._2gram", - "channel_name._3gram", - ], - } - }, - } - look_up = SearchHandler(url, data) - search_results = look_up.get_data() - return {"results": search_results} - def multi_search(self, search_query): """searching through index""" url = self.ES_URL + "/ta_video,ta_channel,ta_playlist/_search" diff --git a/tubearchivist/home/templates/home/channel.html b/tubearchivist/home/templates/home/channel.html index 80f9437..3198143 100644 --- a/tubearchivist/home/templates/home/channel.html +++ b/tubearchivist/home/templates/home/channel.html @@ -19,18 +19,6 @@ -
-
- search-icon -

Search your Channels

-
- -
diff --git a/tubearchivist/home/templates/home/home.html b/tubearchivist/home/templates/home/home.html index 6291c03..7591ef2 100644 --- a/tubearchivist/home/templates/home/home.html +++ b/tubearchivist/home/templates/home/home.html @@ -28,15 +28,6 @@ {% endif %}
-
-
- search-icon -
- -
diff --git a/tubearchivist/home/templates/home/playlist.html b/tubearchivist/home/templates/home/playlist.html index 431899c..451a09a 100644 --- a/tubearchivist/home/templates/home/playlist.html +++ b/tubearchivist/home/templates/home/playlist.html @@ -18,16 +18,6 @@
-
-
- search-icon -

Search your Playlists

-
- -
diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index cb274ab..7b33047 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -13,20 +13,16 @@ from django.contrib.auth import login from django.contrib.auth.forms import AuthenticationForm from django.http import JsonResponse from django.shortcuts import redirect, render -from django.utils.http import urlencode from django.views import View from home.forms import ( AddToQueueForm, ApplicationSettingsForm, - ChannelSearchForm, CustomAuthForm, MultiSearchForm, - PlaylistSearchForm, SchedulerSettingsForm, SubscribeToChannelForm, SubscribeToPlaylistForm, UserSettingsForm, - VideoSearchForm, ) from home.src.config import AppConfig, ScheduleBuilder from home.src.frontend import PostData @@ -199,7 +195,6 @@ class HomeView(ArchivistResultsView): self.initiate_vars(request) self._update_view_data() self.find_results() - self.context.update({"search_form": VideoSearchForm()}) return render(request, "home/home.html", self.context) @@ -219,18 +214,6 @@ class HomeView(ArchivistResultsView): } self.data["query"] = query - @staticmethod - def post(request): - """handle post from search form""" - search_form = VideoSearchForm(data=request.POST) - if search_form.is_valid(): - search_query = request.POST.get("searchInput") - print(search_query) - search_url = "/?" + urlencode({"search": search_query}) - return redirect(search_url, permanent=True) - - return redirect("home") - class LoginView(View): """resolves to /login/ @@ -408,7 +391,6 @@ class ChannelView(ArchivistResultsView): self.context.update( { "title": "Channels", - "search_form": ChannelSearchForm(), "subscribe_form": SubscribeToChannelForm(), } ) @@ -536,7 +518,6 @@ class PlaylistView(ArchivistResultsView): { "title": "Playlists", "subscribe_form": SubscribeToChannelForm(), - "search_form": PlaylistSearchForm(), } ) @@ -571,13 +552,6 @@ class PlaylistView(ArchivistResultsView): @staticmethod def post(request): """handle post from search form""" - search_form = PlaylistSearchForm(data=request.POST) - if search_form.is_valid(): - search_query = request.POST.get("searchInput") - print(search_query) - search_url = "/playlist/?" + urlencode({"search": search_query}) - return redirect(search_url, permanent=True) - subscribe_form = SubscribeToPlaylistForm(data=request.POST) if subscribe_form.is_valid(): url_str = request.POST.get("subscribe") diff --git a/tubearchivist/static/css/style.css b/tubearchivist/static/css/style.css index c7fe4c3..26a9eff 100644 --- a/tubearchivist/static/css/style.css +++ b/tubearchivist/static/css/style.css @@ -290,20 +290,6 @@ button:hover { width: 50%; } -.search-form input { - width: 90%; -} - -.search-icon { - flex: 0 0 40px; -} - -.search-icon img { - width: 100%; - cursor: pointer; - filter: var(--img-filter); -} - .view-controls { display: grid; grid-template-columns: 1fr 1fr; @@ -324,12 +310,6 @@ button:hover { filter: var(--img-filter); } -#search-box { - display: none; - flex: auto; - padding: 10px; -} - #hidden-form { display: none; } diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index ff36c72..f8af4ad 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -532,57 +532,6 @@ function createPlaylist(playlist, viewStyle) { } -// searching channels -function searchChannels(query) { - var searchResultBox = document.getElementById('resultBox'); - searchResultBox.innerHTML = ''; - if (query.length > 1) { - var payload = JSON.stringify({'channel-search': query}) - sendSearchAsYouType(payload); - }; -} - - -function populateChannelResults(allResults) { - var searchResultBox = document.getElementById('resultBox'); - for (let i = 0; i < allResults.length; i++) { - var singleResult = allResults[i]; - var source = singleResult['source']; - var channelName = source['channel_name']; - var channelId = source['channel_id']; - var optionElement = document.createElement('option'); - optionElement.value = channelName; - optionElement.setAttribute('data', channelId); - searchResultBox.appendChild(optionElement); - }; -} - -function channelRedirect(){ - var response = document.getElementById('resultBox'); - var firstChild = response.firstChild - if (firstChild) { - var redirectId = firstChild.getAttribute('data'); - location = '/channel/' + redirectId; - }; - return false; -} - - -function sendSearchAsYouType(payload) { - var http = new XMLHttpRequest(); - http.onreadystatechange = function() { - if (http.readyState === 4) { - allResults = JSON.parse(http.response)['results']; - populateChannelResults(allResults); - }; - }; - http.open("POST", "/process/", true); - http.setRequestHeader("X-CSRFToken", getCookie("csrftoken")); - http.setRequestHeader("Content-type", "application/json"); - http.send(payload); -} - - // generic function sendPost(payload) { var http = new XMLHttpRequest(); @@ -621,18 +570,6 @@ function textReveal() { }; } -function showSearch() { - var searchBox = document.getElementById('search-box'); - var displayStyle = searchBox.style.display - if (displayStyle === "") { - searchBox.style.display = 'block'; - } else { - searchBox.style.display = ""; - } - var inputBox = document.getElementById('id_searchInput'); - inputBox.focus(); -} - function showForm() { var formElement = document.getElementById('hidden-form'); var displayStyle = formElement.style.display