Finish deleted messages and sent messages

This commit is contained in:
Marcin Kowalicki 2021-01-12 16:04:14 +01:00
parent db4895cd9c
commit 5c7194ae07
3 changed files with 78 additions and 8 deletions

View file

@ -18,6 +18,7 @@ const getGrades = () => {
}).then(response => response.json()).then(data => { }).then(response => response.json()).then(data => {
const allGrades = data.data.Oceny const allGrades = data.data.Oceny
const content = document.getElementById("content") const content = document.getElementById("content")
content.innerHTML = ""
const container = document.getElementsByClassName("gradeModals")[0] const container = document.getElementsByClassName("gradeModals")[0]
allGrades.forEach((grade) => { allGrades.forEach((grade) => {

View file

@ -1,8 +1,10 @@
const received_ = document.querySelector('#received_'); const received_ = document.querySelector('#received_');
const sent_ = document.querySelector('#sent_'); const sent_ = document.querySelector('#sent_');
const deleted_ = document.querySelector('#deleted_'); const deleted_ = document.querySelector('#deleted_');
const content = document.getElementById("content")
const getReceivedMessages = () => { const getReceivedMessages = () => {
content.innerHTML = ""
cookies_data = sessionStorage.getItem('cookies_data'); cookies_data = sessionStorage.getItem('cookies_data');
csrfcookie_ = sessionStorage.getItem('csrfcookie'); csrfcookie_ = sessionStorage.getItem('csrfcookie');
fetch(url = '../api/messages/received', { fetch(url = '../api/messages/received', {
@ -14,8 +16,7 @@ const getReceivedMessages = () => {
}, },
body: cookies_data body: cookies_data
}).then(response => response.json()).then(data => { }).then(response => response.json()).then(data => {
content = document.getElementById("content") const wiadomosci = data.data
wiadomosci = data.data
table = document.createElement("table") table = document.createElement("table")
table.className = "striped" table.className = "striped"
@ -38,7 +39,7 @@ const getReceivedMessages = () => {
wiadomoscRow = tbody.insertRow() wiadomoscRow = tbody.insertRow()
temat = wiadomoscRow.insertCell() temat = wiadomoscRow.insertCell()
temat.innerHTML = `<span id="${wiadomosc.id}">${wiadomosc.Temat}</span>` temat.innerHTML = `<span id="${wiadomosc.Id}">${wiadomosc.Temat}</span>`
wiadomoscRow.appendChild(temat) wiadomoscRow.appendChild(temat)
nadawca = wiadomoscRow.insertCell() nadawca = wiadomoscRow.insertCell()
@ -54,7 +55,7 @@ const getReceivedMessages = () => {
} }
const getSentMessages = () => { const getSentMessages = () => {
document.querySelector('#content').innerHTML = 'Here is sent messages (in my imagination)'; content.innerHTML = ""
cookies_data = sessionStorage.getItem('cookies_data'); cookies_data = sessionStorage.getItem('cookies_data');
csrfcookie_ = sessionStorage.getItem('csrfcookie'); csrfcookie_ = sessionStorage.getItem('csrfcookie');
fetch(url = '../api/messages/sent', { fetch(url = '../api/messages/sent', {
@ -66,12 +67,46 @@ const getSentMessages = () => {
}, },
body: cookies_data body: cookies_data
}).then(response => response.json()).then(data => { }).then(response => response.json()).then(data => {
console.log(data); const wiadomosci = data.data // haha spaghetti code goes brrr
table = document.createElement("table")
table.className = "striped"
table.innerHTML = "<thead>\n" +
" <tr>\n" +
" <th>Temat</th>\n" +
" <th>Nadawca</th>\n" +
" <th>Data</th>\n" +
" </tr>\n" +
" </thead>" +
" <tbody>" +
" " +
" </tbody>"
content.append(table)
wiadomosci.forEach((wiadomosc) => {
const tbody = document.getElementsByTagName("tbody")[0]
wiadomoscRow = tbody.insertRow()
temat = wiadomoscRow.insertCell()
temat.innerHTML = `<span id="${wiadomosc.Id}">${wiadomosc.Temat}</span>`
wiadomoscRow.appendChild(temat)
nadawca = wiadomoscRow.insertCell()
nadawca.innerHTML = `<span>${wiadomosc.Nadawca.Name}</span>`
wiadomoscRow.appendChild(nadawca)
dataWyslania = wiadomoscRow.insertCell()
dataWyslania.innerHTML = `<span>${wiadomosc.Data}</span>`
wiadomoscRow.appendChild(dataWyslania)
})
}) })
} }
const getDeletedMessages = () => { const getDeletedMessages = () => {
document.querySelector('#content').innerHTML = 'Here is deleted messages (in my imagination)'; content.innerHTML = ""
cookies_data = sessionStorage.getItem('cookies_data'); cookies_data = sessionStorage.getItem('cookies_data');
csrfcookie_ = sessionStorage.getItem('csrfcookie'); csrfcookie_ = sessionStorage.getItem('csrfcookie');
fetch(url = '../api/messages/deleted', { fetch(url = '../api/messages/deleted', {
@ -83,7 +118,41 @@ const getDeletedMessages = () => {
}, },
body: cookies_data body: cookies_data
}).then(response => response.json()).then(data => { }).then(response => response.json()).then(data => {
console.log(data); const wiadomosci = data.data
table = document.createElement("table")
table.className = "striped"
table.innerHTML = "<thead>\n" +
" <tr>\n" +
" <th>Temat</th>\n" +
" <th>Nadawca</th>\n" +
" <th>Data</th>\n" +
" </tr>\n" +
" </thead>" +
" <tbody>" +
" " +
" </tbody>"
content.append(table)
wiadomosci.forEach((wiadomosc) => {
const tbody = document.getElementsByTagName("tbody")[0]
wiadomoscRow = tbody.insertRow()
temat = wiadomoscRow.insertCell()
temat.innerHTML = `<span id="${wiadomosc.Id}">${wiadomosc.Temat}</span>`
wiadomoscRow.appendChild(temat)
nadawca = wiadomoscRow.insertCell()
nadawca.innerHTML = `<span>${wiadomosc.Nadawca.Name}</span>`
wiadomoscRow.appendChild(nadawca)
dataWyslania = wiadomoscRow.insertCell()
dataWyslania.innerHTML = `<span>${wiadomosc.Data}</span>`
wiadomoscRow.appendChild(dataWyslania)
})
}) })
} }

View file

@ -7,7 +7,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="{% static 'css/start.css' %}" type="text/css" /> <link rel="stylesheet" href="{% static 'css/start.css' %}" type="text/css" />
<script src="{% static 'js/start.js' %}" type="text/javascript" defer></script> <script src="{% static 'js/start.js' %}" type="text/javascript" defer></script>
<script src="{% static 'js/grades.js' %}" type="text/javascript" defer></script> <script src="{% static 'js/dist/out-grades.js' %}" type="text/javascript" defer></script>
<script src="{% static 'js/timetable.js' %}" type="text/javascript" defer></script> <script src="{% static 'js/timetable.js' %}" type="text/javascript" defer></script>
<script src="{% static 'js/exams.js' %}" type="text/javascript" defer></script> <script src="{% static 'js/exams.js' %}" type="text/javascript" defer></script>
<script src="{% static 'js/notes.js' %}" type="text/javascript" defer></script> <script src="{% static 'js/notes.js' %}" type="text/javascript" defer></script>