// --- 사이드 메뉴 -- //
$(function () {
setSideMenu(
"sidebar_menu_requirement",
"sidebar_menu_requirement_review",
"requirement-elements-collapse"
);
makeTemplate("./js/reviewClassify.do", makeClassifyMenus);
makeTemplate("./js/reviewList.do", makeReviewList);
});
const makeTemplate = function (url, bindTemplate) {
getData(url).then((data) => bindTemplate(data));
};
const getData = (url) => {
const data = fetch(url).then((response) => {
return response.json();
});
return data;
};
// make review classify menu
const makeClassifyMenus = function (data) {
const reviewClassify = document.getElementById("review-classify");
let menus = "";
data.forEach(
(item) =>
(menus += `
${item.name}
`)
);
reviewClassify.innerHTML = menus;
};
// make review list
const makeReviewList = function (data) {
const reviewList = document.getElementById("review-list");
let list = "";
data.forEach(
(item) =>
(list += `
|
${item.register} |
${item.requirements} |
${dateFormat(item.timestamp)} |
`)
);
reviewList.innerHTML = list;
};
const dateFormat = (time = 0) => {
let date = time ? new Date(time).toISOString() : new Date().toISOString();
return date.split("T")[0];
};
// reviwe click
$("#review-list").click(function (ev) {
const row = ev.target.parentNode.dataset;
location.href = `reqReviewDetail.html?id=${row.id}`;
});
// side menu click
$("#review-classify").click(async function (ev) {
const li = ev.target.parentNode;
for (const item of ev.currentTarget.children) {
item.classList.remove("active");
}
li.classList.add("active");
// 서버에서 필터 될 때 사용
// makeTemplate("./js/reviewList.do", makeReviewList);
// 분류 예제 코드
const data = await getData("./js/reviewList.do");
const order = Number(li.dataset.order);
makeReviewList(
order ? data.filter((item) => item.order === Number(li.dataset.order)) : data
);
});