Skip to content

Commit

Permalink
Merge pull request #1 from hyp3rflow/seminar-slide
Browse files Browse the repository at this point in the history
세미나 슬라이드를 새 탭에서 열 수 있는 버튼을 추가합니다.
  • Loading branch information
henrylee97 authored Jan 22, 2024
2 parents d4f7b0c + ab10610 commit 53da2a5
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions layouts/seminar/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
<script>
const api_url = 'https://salbox.korea.ac.kr/seminar/api/'

function format() {
var args = Array.prototype.slice.call (arguments, 1);
return arguments[0].replace (/\{(\d+)\}/g, function (match, index) {
return args[index];
});
}

const handleDownload = async (file_url, slide) => {
const handleSlide = async (file_url, slide, mode) => {
console.log(file_url)
// URL에서 GET 요청 보내기
fetch(file_url, {
Expand All @@ -27,7 +20,8 @@
file_name = slide.split('/').pop()
// 생성한 URL과 다운로드할 파일명 설정
link.setAttribute('href', url);
link.setAttribute('download', file_name);
if (mode === 'download') link.setAttribute('download', file_name);
if (mode === 'open') link.setAttribute('target', '_blank')

// 링크를 문서(body)에 추가
document.body.appendChild(link);
Expand All @@ -53,14 +47,14 @@
}

const getSeminars = async (schedule_id) => {
let response = await fetch(format(api_url + 'seminar/?scheduled_at={0}', schedule_id))
let response = await fetch(api_url + `seminar?scheduled_at=${schedule_id}`)
let data = await response.json()
// console.log(data)
return data
}

const getMember = async (member_id) => {
let response = await fetch(format(api_url + '/member/{0}', member_id))
let response = await fetch(api_url + `/member/${member_id}`)
let data = await response.json()
// console.log(data)
return data
Expand Down Expand Up @@ -113,16 +107,27 @@

if (seminar.slide != null) {
console.log(seminar.slide)
var seminar_slide = document.createElement('button')
seminar_slide.className = 'btn btn-primary'
seminar_slide.innerHTML = 'Download'
seminar_slide.id = seminar.id
seminar_slide.slide = seminar.slide
seminar_slide.onclick = function(event) {
var seminar_download = document.createElement('button')
seminar_download.className = 'btn btn-primary me-2'
seminar_download.innerHTML = 'Download'
seminar_download.id = seminar.id
seminar_download.slide = seminar.slide
seminar_download.onclick = function (event) {
url = api_url + 'download/' + event.target.id
handleSlide(url, event.target.slide, 'download')
}
seminar_inner.appendChild(seminar_download)

var seminar_open = document.createElement('button')
seminar_open.className = 'btn btn-primary'
seminar_open.innerHTML = 'Open in browser'
seminar_open.id = seminar.id
seminar_open.slide = seminar.slide
seminar_open.onclick = function (event) {
url = api_url + 'download/' + event.target.id
handleDownload(url, event.target.slide)
handleSlide(url, event.target.slide, 'open')
}
seminar_inner.appendChild(seminar_slide)
seminar_inner.appendChild(seminar_open)
}

seminar_html.appendChild(seminar_inner)
Expand Down

0 comments on commit 53da2a5

Please sign in to comment.