drf ๋ฐฑ์๋๊ฐ๋ฐ + ํ๋ก ํธ๊ฐ๋ฐ
: ์ด๋ฒ ํ๋ก์ ํธ๋ ํํ๋ก์ ํธ๋ก ์์ํฉ๋๋ค.
search_result.html
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>๋ ๊ทธ๊ฑฐ ํญ์ค์ผ</title>
<!-- ํ๋น์ฝ -->
<link rel="shortcut icon" href="../static/image/favicon.png" type="image/x-icon">
<!-- ๋ถํธ์คํธ๋ฉ -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<!--์คํ์ผ CSS -->
<link rel="stylesheet" href="/static/CSS/pagenation.css">
<link rel="stylesheet" href="../static/CSS/style.css">
<link rel="stylesheet" href="../static/CSS/board.css">
</head>
<body style="background-color: rgb(43, 43, 43); color: black;">
<!-- ๋ก๊ทธ์ธ ๊ณต๊ฐ -->
<div class="login-space">
<div class="login-block">
<button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#myModal1">
๋ก๊ทธ์ธ
</button>
<button type="button" class="btn btn-light btn-sm" id="signup-button"
onclick="location.href='signup.html'">ํ์๊ฐ์
</button>
<button type="button" id="logout-button" class="btn btn-warning btn-sm" id="#"
onclick="logout()">๋ก๊ทธ์์</button>
</div>
</div>
<!-- ์๋จ๊ณต๊ฐ -->
<div class="navbar">
<!-- ์ฌ์ดํธ ๋ก๊ณ -->
<img src="../static/image/logo.png" alt="" height="100px" onclick="location.href='index.html'">
</div>
<!-- ๊ฒ์์์ง -->
<!-- ๋๋กญ๋ค์ด ๊ฒ์ ์ ์ฉ๋ฒ ํ์ธ์ค, ์๋๋ฉด ๊ทธ๋ฅ ๊ฒ์์ฐฝ์ผ๋ก ๋๋ ์์ -->
<div class="input-group mt-3 mb-3 search-engine">
<select type="button" id="searchOption">
์ ์ฒด ๊ฒ์๊ธ
<option><a class="dropdown-item" href="#">์ ๋ชฉ</a></option>
<option><a class="dropdown-item" href="#">๋ด์ฉ</a></option>
<option><a class="dropdown-item" href="#">์ ๋ชฉ+๋ด์ฉ</a></option>
<option><a class="dropdown-item" href="#">์์ฑ์</a></option>
</select>
<input type="text" class="form-control" placeholder="๊ฒ์๊ธ ๊ฒ์" id="searchKeywords">
<img src="static/image/search_button.png" onclick="search()" class="search-button">
</div>
<!-- ๊ฒ์ํํ ๋ฒํผ๋ค -->
<div class="Top-bar1 row justify-content-center">
<div class="Top-bar1-buttons row">
<img class="board" src="static/image/board01.png" onclick="location.href='board.html?boards=์ง์ฅ์ธ'">
<img class="board" src="static/image/board02.png" onclick="location.href='board.html?boards=๋ํ์'">
<img class="board" src="static/image/board03.png" onclick="location.href='board.html?boards=10๋'">
<img class="board" src="static/image/board04.png" onclick="location.href='board.html?boards=์ฑ์ธ'">
<img class="board" src="static/image/board05.png" onclick="location.href='board.html?boards=LGBTQ'">
<img class="board" src="static/image/board06.png" onclick="location.href='board.html?boards=์์ '">
<img class="board" src="static/image/board07.png" onclick="location.href='board.html?boards=HOT'">
</div>
</div>
<!-- ๊ฒ์ํ ๊ณต๊ฐ -->
<div class="board-space">
<!-- ๊ฒ์ํ ๋ช
-->
<div class="board-name" ><b id="board-name"></b></div>
<div class="posting-space"><button class="posting-btn" onclick="location.href='posting.html'">๊ฒ์๋ฌผ ์์ฑ</button></div>
<div class="second-floor-board col">
<!--๊ฒ์ํ -->
<div class="worker-board row justify-content-center">
<!-- ์์ ๊ฒ์๊ธ for๋ฌธ -->
<div id="ArticlesDiv" class="articles">
<div id="search-post" class="list-post" ></div>
</div>
</div>
</div>
</div>
<!-- Scripts -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paginationjs/2.1.4/pagination.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/paginationjs/2.1.4/pagination.css"/>
<script type="module" src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.js"></script>
<script src="/static/JS/api.js"></script>
<script src="/static/Scripts/search.js"></script>
<script src="/static/Scripts/boards.js"></script>
</div>
<!-- The Modal -->
<div class="modal" id="myModal1">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Modal Heading</h4>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<!-- Modal body -->
<div class="modal-body">
Modal body..
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
</html>
search.js
// ๊ฒ์๊ธฐ๋ฅ
async function search() {
const searchData = {
type: document.getElementById('searchOption').value,
search: document.getElementById('searchKeywords').value,
}
const response = await fetch(`${backend_base_url}/article/search/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(searchData)
})
// ์ธ์
์ ์ฅ
response_json = await response.json()
result = JSON.stringify(response_json)
num = response_json.length
sessionStorage.setItem("result", result)
sessionStorage.setItem("keyword", searchData.search)
sessionStorage.setItem("type", searchData.type)
sessionStorage.setItem("num", num)
window.location.href = `${frontend_base_url}/search_result.html`
return result
}
const PagingConf = {
totalCount: 100,
numbersPerPage: 5,
navPageNumber: Math.ceil(sessionStorage.getItem("num")/10),
};
sessionStorage.removeItem("num")
const feedNumber = {
num : 0
}
$(document).ready(function () {
setPageInfo(PagingConf.numbersPerPage, PagingConf.navPageNumber, 1);
// setFeedNumber( $(val) );
makePageNav();
getPosts();
});
function makePageNav() {
const pageInfo = getPageInfo();
renderPaging($('.paging'), PagingConf.totalCount, pageInfo.numbersPerPage, pageInfo.navPageNumber, pageInfo.currentPage, true);
}
function renderPaging(appendElement, totalCount, numbersPerPage, navPageNumber, currentPage) {
let totalPage = Math.ceil(totalCount / numbersPerPage); // ์ ์ฒด ํ์ด์ง์
let pageGroup = Math.ceil(currentPage / navPageNumber); // 1~10 : 1๊ทธ๋ฃน 11~20 : 2๊ทธ๋ฃน
let last = pageGroup * navPageNumber; // ๋ง์ง๋ง ํ์ด์ง์, ์ ์ฒด ํ์ด์ง์ ๋์ง์๊ฒ ์ฒ๋ฆฌ
if (last > totalPage) {
last = totalPage;
}
let first = last - (navPageNumber - 1);
let front = 1;
let prev = first - 1;
let next = last + 1;
let rear = totalPage;
let innerHtml = ''; // ์ด๋ ํ์ด์ง ์์ ํ์ดํ html
// ์ผ์ชฝ < <<
if (prev > 0) {
innerHtml += '<a href=#token operator">+ front + ')"> << </a>';
innerHtml += '<a href=#token operator">+ prev + ')"> < </a> ';
}
// ์ค๊ฐ ์ด๋ ํ๊ทธ
for (let i = first; i <= last; i++) {
if (currentPage === i) {
innerHtml += '<a href=# class="on"token operator">+ i + ')">' + i + '</a> ';
} else {
innerHtml += '<a href=#token operator">+ i + ')">' + i + '</a> ';
}
}
// ์ค๋ฅธ์ชฝ > >>
if (last < totalPage) {
innerHtml += '<a href=#token operator">+ next + ')"> > </a>';
innerHtml += '<a href=#token operator">+ rear + ')"> >> </a>';
}
appendElement.empty();
appendElement.append(innerHtml);
}
function movePage(currentPage) {
const pageInfo = getPageInfo();
setPageInfo(pageInfo.numbersPerPage, pageInfo.navPageNumber, currentPage);
makePageNav();
getPosts();
}
function setPageInfo(numbersPerPage, navPageNumber, currentPage) {
const pageInfo = {
numbersPerPage: numbersPerPage,
navPageNumber: navPageNumber,
currentPage: currentPage
};
sessionStorage.setItem('pageInfo', JSON.stringify(pageInfo));
}
function getPageInfo() {
return JSON.parse(sessionStorage.getItem('pageInfo'));
}
function getFeedInfo() {
return JSON.parse(sessionStorage.getItem('pageInfo'));
}
function getPosts() {
$('#list-post').empty()
const pageInfo = getPageInfo();
let page = pageInfo.currentPage;
let offset = pageInfo.numbersPerPage;
let params = '?page=' + page;
params += '&offset=' + offset;
$.ajax({
type: 'POST',
url: `${backend_base_url}/article/search/`,
data: {
type: sessionStorage.getItem("type"),
search: sessionStorage.getItem("keyword")
},
async: false,
success: function (response) {
console.log(response)
if (response.length != 0) {
let posts = response;
console.log(posts)
let board_html = `<b id="board-name">'${sessionStorage.getItem("keyword")}' ๊ฒ์๊ฒฐ๊ณผ</b>`
$('#board-name').empty()
$('#board-name').append(board_html)
for (let i = 0; i < posts.length; i++) {
let cnt = i + 1
const id = posts[i]['id']
const title = posts[i]['article_title']
const author = posts[i]['author']
const date = posts[i]['article_post_date']
let temp_html = `<div class="tr" onclick="location.href='${frontend_base_url}/detail.html?id=${id}'">
<div class="th number" scope="col">${cnt}.</div>
<div class="th title" scope="col"><b>${title}</b></div>
<div class="th author" scope="col">${author}</div>
<div class="th date" scope="col">${date}</div>
</div>`
$('#search-post').append(temp_html)
}
}
},
fail: function (response) {
console.log("fail")
// window.location.reload()
}
});
}