remove now redundant search forms

This commit is contained in:
simon 2021-12-31 13:42:07 +07:00
parent 5616d3ee0d
commit 4915aa0c11
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
9 changed files with 0 additions and 202 deletions

View File

@ -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/"""

View File

@ -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

View File

@ -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"

View File

@ -19,18 +19,6 @@
</form>
</div>
</div>
<div class="search-form icon-text">
<div class="search-icon">
<img src="{% static 'img/icon-search.svg' %}" alt="search-icon" onclick="showSearch()">
<p>Search your Channels</p>
</div>
<form onSubmit="return channelRedirect();" id="search-box">
{% csrf_token %}
{{ search_form }}
<datalist id="resultBox">
</datalist>
</form>
</div>
</div>
<div class="view-controls">
<div class="toggle">

View File

@ -28,15 +28,6 @@
{% endif %}
</select>
</div>
<div class="search-form icon-text">
<div class="search-icon">
<img src="{% static 'img/icon-search.svg' %}" alt="search-icon" onclick="showSearch()">
</div>
<form action="/" method="POST" id="search-box">
{% csrf_token %}
{{ search_form }}
</form>
</div>
</div>
<div class="view-controls">
<div class="toggle">

View File

@ -18,16 +18,6 @@
</form>
</div>
</div>
<div class="search-form icon-text">
<div class="search-icon">
<img src="{% static 'img/icon-search.svg' %}" alt="search-icon" onclick="showSearch()">
<p>Search your Playlists</p>
</div>
<form action="/playlist/" method="POST" id="search-box">
{% csrf_token %}
{{ search_form }}
</form>
</div>
</div>
<div class="view-controls">
<div class="toggle">

View File

@ -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")

View File

@ -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;
}

View File

@ -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