mirror of
https://github.com/tubearchivist/tubearchivist
synced 2024-11-02 09:41:07 +00:00
remove now redundant search forms
This commit is contained in:
parent
5616d3ee0d
commit
4915aa0c11
@ -83,39 +83,6 @@ class SchedulerSettingsForm(forms.Form):
|
|||||||
run_backup_rotate = forms.IntegerField(required=False)
|
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):
|
class MultiSearchForm(forms.Form):
|
||||||
"""multi search form for /search/"""
|
"""multi search form for /search/"""
|
||||||
|
|
||||||
|
@ -75,7 +75,6 @@ class PostData:
|
|||||||
"db-backup": self._db_backup,
|
"db-backup": self._db_backup,
|
||||||
"db-restore": self._db_restore,
|
"db-restore": self._db_restore,
|
||||||
"fs-rescan": self._fs_rescan,
|
"fs-rescan": self._fs_rescan,
|
||||||
"channel-search": self._channel_search,
|
|
||||||
"multi_search": self._multi_search,
|
"multi_search": self._multi_search,
|
||||||
"delete-video": self._delete_video,
|
"delete-video": self._delete_video,
|
||||||
"delete-channel": self._delete_channel,
|
"delete-channel": self._delete_channel,
|
||||||
@ -283,13 +282,6 @@ class PostData:
|
|||||||
rescan_filesystem.delay()
|
rescan_filesystem.delay()
|
||||||
return {"success": True}
|
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):
|
def _multi_search(self):
|
||||||
"""search through all indexes"""
|
"""search through all indexes"""
|
||||||
search_query = self.exec_val
|
search_query = self.exec_val
|
||||||
|
@ -155,27 +155,6 @@ class SearchForm:
|
|||||||
CONFIG = AppConfig().config
|
CONFIG = AppConfig().config
|
||||||
ES_URL = CONFIG["application"]["es_url"]
|
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):
|
def multi_search(self, search_query):
|
||||||
"""searching through index"""
|
"""searching through index"""
|
||||||
url = self.ES_URL + "/ta_video,ta_channel,ta_playlist/_search"
|
url = self.ES_URL + "/ta_video,ta_channel,ta_playlist/_search"
|
||||||
|
@ -19,18 +19,6 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
||||||
<div class="view-controls">
|
<div class="view-controls">
|
||||||
<div class="toggle">
|
<div class="toggle">
|
||||||
|
@ -28,15 +28,6 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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>
|
||||||
<div class="view-controls">
|
<div class="view-controls">
|
||||||
<div class="toggle">
|
<div class="toggle">
|
||||||
|
@ -18,16 +18,6 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
||||||
<div class="view-controls">
|
<div class="view-controls">
|
||||||
<div class="toggle">
|
<div class="toggle">
|
||||||
|
@ -13,20 +13,16 @@ from django.contrib.auth import login
|
|||||||
from django.contrib.auth.forms import AuthenticationForm
|
from django.contrib.auth.forms import AuthenticationForm
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
from django.utils.http import urlencode
|
|
||||||
from django.views import View
|
from django.views import View
|
||||||
from home.forms import (
|
from home.forms import (
|
||||||
AddToQueueForm,
|
AddToQueueForm,
|
||||||
ApplicationSettingsForm,
|
ApplicationSettingsForm,
|
||||||
ChannelSearchForm,
|
|
||||||
CustomAuthForm,
|
CustomAuthForm,
|
||||||
MultiSearchForm,
|
MultiSearchForm,
|
||||||
PlaylistSearchForm,
|
|
||||||
SchedulerSettingsForm,
|
SchedulerSettingsForm,
|
||||||
SubscribeToChannelForm,
|
SubscribeToChannelForm,
|
||||||
SubscribeToPlaylistForm,
|
SubscribeToPlaylistForm,
|
||||||
UserSettingsForm,
|
UserSettingsForm,
|
||||||
VideoSearchForm,
|
|
||||||
)
|
)
|
||||||
from home.src.config import AppConfig, ScheduleBuilder
|
from home.src.config import AppConfig, ScheduleBuilder
|
||||||
from home.src.frontend import PostData
|
from home.src.frontend import PostData
|
||||||
@ -199,7 +195,6 @@ class HomeView(ArchivistResultsView):
|
|||||||
self.initiate_vars(request)
|
self.initiate_vars(request)
|
||||||
self._update_view_data()
|
self._update_view_data()
|
||||||
self.find_results()
|
self.find_results()
|
||||||
self.context.update({"search_form": VideoSearchForm()})
|
|
||||||
|
|
||||||
return render(request, "home/home.html", self.context)
|
return render(request, "home/home.html", self.context)
|
||||||
|
|
||||||
@ -219,18 +214,6 @@ class HomeView(ArchivistResultsView):
|
|||||||
}
|
}
|
||||||
self.data["query"] = query
|
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):
|
class LoginView(View):
|
||||||
"""resolves to /login/
|
"""resolves to /login/
|
||||||
@ -408,7 +391,6 @@ class ChannelView(ArchivistResultsView):
|
|||||||
self.context.update(
|
self.context.update(
|
||||||
{
|
{
|
||||||
"title": "Channels",
|
"title": "Channels",
|
||||||
"search_form": ChannelSearchForm(),
|
|
||||||
"subscribe_form": SubscribeToChannelForm(),
|
"subscribe_form": SubscribeToChannelForm(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -536,7 +518,6 @@ class PlaylistView(ArchivistResultsView):
|
|||||||
{
|
{
|
||||||
"title": "Playlists",
|
"title": "Playlists",
|
||||||
"subscribe_form": SubscribeToChannelForm(),
|
"subscribe_form": SubscribeToChannelForm(),
|
||||||
"search_form": PlaylistSearchForm(),
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -571,13 +552,6 @@ class PlaylistView(ArchivistResultsView):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def post(request):
|
def post(request):
|
||||||
"""handle post from search form"""
|
"""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)
|
subscribe_form = SubscribeToPlaylistForm(data=request.POST)
|
||||||
if subscribe_form.is_valid():
|
if subscribe_form.is_valid():
|
||||||
url_str = request.POST.get("subscribe")
|
url_str = request.POST.get("subscribe")
|
||||||
|
@ -290,20 +290,6 @@ button:hover {
|
|||||||
width: 50%;
|
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 {
|
.view-controls {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr;
|
||||||
@ -324,12 +310,6 @@ button:hover {
|
|||||||
filter: var(--img-filter);
|
filter: var(--img-filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
#search-box {
|
|
||||||
display: none;
|
|
||||||
flex: auto;
|
|
||||||
padding: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#hidden-form {
|
#hidden-form {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
@ -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
|
// generic
|
||||||
function sendPost(payload) {
|
function sendPost(payload) {
|
||||||
var http = new XMLHttpRequest();
|
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() {
|
function showForm() {
|
||||||
var formElement = document.getElementById('hidden-form');
|
var formElement = document.getElementById('hidden-form');
|
||||||
var displayStyle = formElement.style.display
|
var displayStyle = formElement.style.display
|
||||||
|
Loading…
Reference in New Issue
Block a user