hw 6-7 some fixes
This commit is contained in:
1 parent
34630657b8
commit
3080e5b5b6
8 files changed
+67
-65
No files matched your search
@@ -221,15 +221,18 @@ a:hover {
|
|||||||
|
|
||||||
.search-suggestions {
|
.search-suggestions {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
top: calc(100% + 0.4rem);
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
border: 1px solid #1f2d3a;
|
border: 1px solid #1f2d3a;
|
||||||
border-radius: 0.5rem;
|
border-radius: 0.5rem;
|
||||||
width: calc(100% - 2rem);
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
max-height: 18rem;
|
max-height: 18rem;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
display: none;
|
display: none;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
margin-top: 0.4rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-suggestion {
|
.search-suggestion {
|
||||||
|
|||||||
@@ -55,6 +55,30 @@ if (searchInput) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function askItSearch(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const query = searchInput ? searchInput.value.trim() : '';
|
||||||
|
if (!query) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch(`/search?q=${encodeURIComponent(query)}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
const results = data.results || [];
|
||||||
|
if (results.length) {
|
||||||
|
window.location.href = results[0].url;
|
||||||
|
} else {
|
||||||
|
window.location.href = `/ask?q=${encodeURIComponent(query)}`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
window.location.href = `/ask?q=${encodeURIComponent(query)}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function postReaction(url, data, onSuccess) {
|
function postReaction(url, data, onSuccess) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url,
|
url,
|
||||||
@@ -167,31 +191,3 @@ $(document).on('click', '.correct-answer-btn', function () {
|
|||||||
console.error('centrifuge init error', e);
|
console.error('centrifuge init error', e);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
// Handle ASK IT button - transfer search text to ask page
|
|
||||||
function redirectToAsk(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
const searchInput = document.getElementById('search-input');
|
|
||||||
const query = searchInput ? searchInput.value.trim() : '';
|
|
||||||
const url = query ? `/ask?q=${encodeURIComponent(query)}` : '/ask';
|
|
||||||
window.location.href = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Populate title field from URL parameter on ask page
|
|
||||||
function initializeTitleFromQuery() {
|
|
||||||
const params = new URLSearchParams(window.location.search);
|
|
||||||
const query = params.get('q');
|
|
||||||
if (query) {
|
|
||||||
const titleField = document.querySelector('[name="title"]');
|
|
||||||
if (titleField) {
|
|
||||||
titleField.value = query;
|
|
||||||
titleField.focus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run immediately (script.js loads at end of page, DOMContentLoaded may have already fired)
|
|
||||||
if (document.readyState === 'loading') {
|
|
||||||
document.addEventListener('DOMContentLoaded', initializeTitleFromQuery);
|
|
||||||
} else {
|
|
||||||
initializeTitleFromQuery();
|
|
||||||
}
|
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
<form class="search" onsubmit="return false;">
|
<form class="search" onsubmit="return false;">
|
||||||
<input id="search-input" type="text" placeholder="Search">
|
<input id="search-input" type="text" placeholder="Search">
|
||||||
<div id="search-suggestions" class="search-suggestions"></div>
|
<div id="search-suggestions" class="search-suggestions"></div>
|
||||||
<a class="button button--ask" href="#" onclick="redirectToAsk(event)">ASK IT</a>
|
<a class="button button--ask" href="#" onclick="return askItSearch(event)">ASK IT</a>
|
||||||
</form>
|
</form>
|
||||||
<div class="user-block">
|
<div class="user-block">
|
||||||
<div class="avatar-box small">
|
<div class="avatar-box small">
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="main-title">
|
<div class="main-title">
|
||||||
<h1>Profile: Dr. Pepper</h1>
|
<h1>Profile:</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form class="form" method="post" enctype="multipart/form-data">
|
<form class="form" method="post" enctype="multipart/form-data">
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from questions import views
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index'),
|
path('', views.index, name='index'),
|
||||||
path('login', views.login, name='login'),
|
path('login', views.login, name='login'),
|
||||||
|
path('login/', views.login),
|
||||||
path('ask', views.ask, name='ask'),
|
path('ask', views.ask, name='ask'),
|
||||||
path('profile', views.profile, name='profile'),
|
path('profile', views.profile, name='profile'),
|
||||||
path('question', views.question, name='question'),
|
path('question', views.question, name='question'),
|
||||||
|
|||||||
+6
-3
@@ -112,11 +112,14 @@ def search(request):
|
|||||||
if not query_text:
|
if not query_text:
|
||||||
return JsonResponse({'results': []})
|
return JsonResponse({'results': []})
|
||||||
|
|
||||||
vector = SearchVector('title', 'body')
|
vector = (
|
||||||
query = SearchQuery(query_text)
|
SearchVector('title', weight='A') +
|
||||||
|
SearchVector('body', weight='B')
|
||||||
|
)
|
||||||
|
query = SearchQuery(query_text, search_type='websearch')
|
||||||
questions = Question.objects.annotate(
|
questions = Question.objects.annotate(
|
||||||
rank=SearchRank(vector, query)
|
rank=SearchRank(vector, query)
|
||||||
).filter(rank__gte=0.1).order_by('-rank')[:10]
|
).filter(rank__gt=0).order_by('-rank')[:10]
|
||||||
|
|
||||||
results = [
|
results = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -221,15 +221,18 @@ a:hover {
|
|||||||
|
|
||||||
.search-suggestions {
|
.search-suggestions {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
top: calc(100% + 0.4rem);
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
border: 1px solid #1f2d3a;
|
border: 1px solid #1f2d3a;
|
||||||
border-radius: 0.5rem;
|
border-radius: 0.5rem;
|
||||||
width: calc(100% - 2rem);
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
max-height: 18rem;
|
max-height: 18rem;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
display: none;
|
display: none;
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
margin-top: 0.4rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.search-suggestion {
|
.search-suggestion {
|
||||||
|
|||||||
+24
-28
@@ -55,6 +55,30 @@ if (searchInput) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function askItSearch(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const query = searchInput ? searchInput.value.trim() : '';
|
||||||
|
if (!query) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch(`/search?q=${encodeURIComponent(query)}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
const results = data.results || [];
|
||||||
|
if (results.length) {
|
||||||
|
window.location.href = results[0].url;
|
||||||
|
} else {
|
||||||
|
window.location.href = `/ask?q=${encodeURIComponent(query)}`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
window.location.href = `/ask?q=${encodeURIComponent(query)}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function postReaction(url, data, onSuccess) {
|
function postReaction(url, data, onSuccess) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url,
|
url,
|
||||||
@@ -167,31 +191,3 @@ $(document).on('click', '.correct-answer-btn', function () {
|
|||||||
console.error('centrifuge init error', e);
|
console.error('centrifuge init error', e);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
// Handle ASK IT button - transfer search text to ask page
|
|
||||||
function redirectToAsk(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
const searchInput = document.getElementById('search-input');
|
|
||||||
const query = searchInput ? searchInput.value.trim() : '';
|
|
||||||
const url = query ? `/ask?q=${encodeURIComponent(query)}` : '/ask';
|
|
||||||
window.location.href = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Populate title field from URL parameter on ask page
|
|
||||||
function initializeTitleFromQuery() {
|
|
||||||
const params = new URLSearchParams(window.location.search);
|
|
||||||
const query = params.get('q');
|
|
||||||
if (query) {
|
|
||||||
const titleField = document.querySelector('[name="title"]');
|
|
||||||
if (titleField) {
|
|
||||||
titleField.value = query;
|
|
||||||
titleField.focus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run immediately (script.js loads at end of page, DOMContentLoaded may have already fired)
|
|
||||||
if (document.readyState === 'loading') {
|
|
||||||
document.addEventListener('DOMContentLoaded', initializeTitleFromQuery);
|
|
||||||
} else {
|
|
||||||
initializeTitleFromQuery();
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user