곡μ§μ¬ν κΈ°λ₯μ κ°λ°νλ κ³Όμ μμ λ³μ μ μΈ μμΉμ μ μ/μ§μ λ³μ μ¬μ© λ°©μμΌλ‘ μΈν΄ λ°μν λ¬Έμ λ₯Ό ν΄κ²°νκΈ° μν΄ μ½λ 리ν©ν°λ§μ μ§ννλ€.
λΆνμν μ μ λ³μ μ¬μ©μ μ΅μννκ³ , λ³΄λ€ μ μ§λ³΄μνκΈ° μ¬μ΄ κ΅¬μ‘°λ‘ κ°μ νμλ€.
β
곡μ§μ¬νμ μ μ₯νλ noticeUids
, readNoticeList
, selfDeletedNoticeList
λ³μκ° μ μμΌλ‘ μ μΈλμ΄ μμ΄ μμμΉ λͺ»ν λμμ΄ λ°μ
β λ³μμ κ°μ΄ λμ μΌλ‘ λ³κ²½λ λ, μ¬λ¬ ν¨μμμ μ κ·Όνλ©΄μ λ°μ΄ν° λΆμΌμΉ λ¬Έμ κ° λ°μ
β νΉμ ν¨μ μ€ν ν λ°μ΄ν°κ° μ λλ‘ κ°±μ λμ§ μκ±°λ, UIκ° λ°μλμ§ μλ λ¬Έμ κ° λνλ¨
β νμν κ²½μ°μλ§ μ μ λ³μ μ¬μ©νκ³ , ν¨μ λ΄λΆμμλ§ νμν λ³μλ μ§μ λ³μλ‘ νμ νμ¬ μ¬μ©
β λ°μ΄ν°λ₯Ό λΆλ¬μ¨ ν UI μ λ°μ΄νΈκ° λκΈ°μ μΌλ‘ 보μ₯λλλ‘ κ΅¬μ‘°λ₯Ό λ³κ²½
β
getNotices()
ν¨μ λ΄λΆμμ λΆνμνκ² μ€λ³΅ νΈμΆλλ λ‘μ§μ μ κ±°νκ³ , μ½λ°± λ°©μμΌλ‘ λ°μ΄ν° νλ¦μ λͺ
νν κ°μ
π 리ν©ν°λ§ ν 곡μ§μ¬ν λ°μ΄ν° λΆλ¬μ€κΈ° μ½λ
function getNotices(categoryFilter, callback) {
let alarmValue = $("#alarmSelect").val();
let alarmFilter = alarmValue === "Y" ? "Y" : alarmValue === "N" ? "N" : "";
let apiUrl = server_host + server_port + "/api/notices";
categoryFilter = categoryFilter || "all";
cordova.plugin.http.get(apiUrl, {}, {
Authorization: 'Bearer ' + userData.token
}, function(response) {
let jsonData = JSON.parse(response.data);
let notices = jsonData.data;
notices.sort((a, b) => b.uid - a.uid);
let filteredNotices = filterNoticesByAlarm(notices, alarmFilter);
updateNoticeUI(filteredNotices, categoryFilter);
markReadNotices(filteredNotices);
localStorage.setItem('readNoticeList', JSON.stringify(readNoticeList));
if (typeof callback === "function") {
callback();
}
}, function(error) {
console.error("곡μ§μ¬ν λΆλ¬μ€κΈ° μ€ν¨:", error);
});
}
π 리ν©ν°λ§ ν UI μ λ°μ΄νΈ μ½λ
function updateNoticeUI(notices, categoryFilter) {
let noticeList = $("#noticeList");
noticeList.empty();
notices.forEach(function(notice) {
if (selfDeletedNoticeList.includes(notice.uid)) return;
if (categoryFilter !== "all" && notice.category !== categoryFilter) return;
let formattedDate = notice.create_time ? formatDate(new Date(notice.create_time)) : "-";
let isNewClass = readNoticeList.includes(notice.uid) ? '' : '<span class="new">N</span>';
let noticeItem = `
<li class="notice-item" data-uid="${notice.uid}">
<div>
<h4 class="btn_notice_view" id="${notice.uid}">${isNewClass} ${notice.title}</h4>
<p>${formattedDate} / ${notice.creator_name || "μ μ μμ"}</p>
</div>
</li>`;
noticeList.append(noticeItem);
});
}