Skip to content

Commit

Permalink
Merge pull request #116 from lazypic/iss115
Browse files Browse the repository at this point in the history
source 추가에 대해 id 방식으로 변경함.
  • Loading branch information
khw7096 authored Jun 17, 2023
2 parents 5494810 + 631e943 commit 09dad41
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 214 deletions.
92 changes: 40 additions & 52 deletions assets/js/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -1729,17 +1729,15 @@ function rmPublish() {
});
}

function setAddSourceModal(project, id) {
document.getElementById("modal-addsource-project").value = project;
function setAddSourceModal(id) {
document.getElementById("modal-addsource-id").value = id;
document.getElementById("modal-addsource-subject").value = "";
document.getElementById("modal-addsource-path").value = "";
document.getElementById("modal-addsource-title").innerHTML = "Add Source" + multiInputTitle(id);
}

function addSource(project, id, title, path) {
function addSource(id, title, path) {
let token = document.getElementById("token").value;
let userid = document.getElementById("userid").value;
if (isMultiInput()) {
let cboxes = document.getElementsByName('selectID');
for (var i = 0; i < cboxes.length; ++i) {
Expand All @@ -1752,11 +1750,9 @@ function addSource(project, id, title, path) {
url: "/api/addsource",
type: "post",
data: {
project: project,
name: id2name(currentID),
id: currentID,
title: title,
path: path,
userid: userid,
},
headers: {
"Authorization": "Basic "+ token
Expand All @@ -1766,20 +1762,20 @@ function addSource(project, id, title, path) {
// 기존 Sources 추가된다.
let source = "";
if (path.startsWith("http")) {
source = `<div id="source-${data.name}-${data.title}"><a href="${data.path}" class="badge badge-outline-darkmode ml-1" alt="${data.userid}" title="${data.userid}">${data.title}</a></div>`;
source = `<div id="source-${data.id}-${data.title}"><a href="${data.path}" class="badge badge-outline-darkmode ml-1" alt="${data.userid}" title="${data.userid}">${data.title}</a></div>`;
} else {
source = `<div id="source-${data.name}-${data.title}"><a href="${data.protocol}://${data.path}" class="badge badge-outline-darkmode ml-1" alt="${data.userid}" title="${data.userid}" onclick="copyClipboard('${data.path}')">${data.title}</a></div>`;
source = `<div id="source-${data.id}-${data.title}"><a href="${data.protocol}://${data.path}" class="badge badge-outline-darkmode ml-1" alt="${data.userid}" title="${data.userid}" onclick="copyClipboard('${data.path}')">${data.title}</a></div>`;
}
document.getElementById("sources-"+data.name).innerHTML = document.getElementById("sources-"+data.name).innerHTML + source;
document.getElementById("sources-"+data.id).innerHTML = document.getElementById("sources-"+data.id).innerHTML + source;
// 요소갯수에 따라 버튼을 설정한다.
if (document.getElementById(`sources-${data.name}`).childElementCount > 0) {
document.getElementById("source-button-"+data.name).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.project}','${data.id}')">+</span>
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmsource" onclick="setRmSourceModal('${data.project}','${data.id}')">-</span>
if (document.getElementById(`sources-${data.id}`).childElementCount > 0) {
document.getElementById("source-button-"+data.id).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="(setAddSourceModal('${data.id}')">+</span>
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmsource" onclick="setRmSourceModal('${data.id}')">-</span>
`
} else {
document.getElementById("source-button-"+data.name).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.project}','${data.id}')">+</span>
document.getElementById("source-button-"+data.id).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.id}')">+</span>
`
}
},
Expand All @@ -1794,11 +1790,9 @@ function addSource(project, id, title, path) {
url: "/api/addsource",
type: "post",
data: {
project: project,
name: id2name(id),
id: id,
title: title,
path: path,
userid: userid,
},
headers: {
"Authorization": "Basic "+ token
Expand All @@ -1808,20 +1802,20 @@ function addSource(project, id, title, path) {
// 기존 Sources 추가된다.
let source = "";
if (path.startsWith("http")) {
source = `<div id="source-${data.name}-${data.title}"><a href="${data.path}" class="badge badge-outline-darkmode ml-1" alt="${data.userid}" title="${data.userid}">${data.title}</a></div>`;
source = `<div id="source-${data.id}-${data.title}"><a href="${data.path}" class="badge badge-outline-darkmode ml-1" alt="${data.userid}" title="${data.userid}">${data.title}</a></div>`;
} else {
source = `<div id="source-${data.name}-${data.title}"><a href="${data.protocol}://${data.path}" class="badge badge-outline-darkmode ml-1" alt="${data.userid}" title="${data.userid}" onclick="copyClipboard('${data.path}')">${data.title}</a></div>`;
source = `<div id="source-${data.id}-${data.title}"><a href="${data.protocol}://${data.path}" class="badge badge-outline-darkmode ml-1" alt="${data.userid}" title="${data.userid}" onclick="copyClipboard('${data.path}')">${data.title}</a></div>`;
}
document.getElementById("sources-"+data.name).innerHTML = document.getElementById("sources-"+data.name).innerHTML + source;
document.getElementById("sources-"+data.id).innerHTML = document.getElementById("sources-"+data.id).innerHTML + source;
// 요소갯수에 따라 버튼을 설정한다.
if (document.getElementById(`sources-${data.name}`).childElementCount > 0) {
document.getElementById("source-button-"+data.name).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.project}','${data.id}')">+</span>
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmsource" onclick="setRmSourceModal('${data.project}','${data.id}')">-</span>
if (document.getElementById(`sources-${data.id}`).childElementCount > 0) {
document.getElementById("source-button-"+data.id).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.id}')">+</span>
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmsource" onclick="setRmSourceModal('${data.id}')">-</span>
`
} else {
document.getElementById("source-button-"+data.name).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.project}','${data.id}')">+</span>
document.getElementById("source-button-"+data.id).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.id}')">+</span>
`
}
},
Expand All @@ -1832,16 +1826,14 @@ function addSource(project, id, title, path) {
}
}

function setRmSourceModal(project, id) {
document.getElementById("modal-rmsource-project").value = project;
function setRmSourceModal(id) {
document.getElementById("modal-rmsource-id").value = id;
document.getElementById("modal-rmsource-subject").value = "";
document.getElementById("modal-rmsource-title").innerHTML = "Rm Source" + multiInputTitle(id);
}

function rmSource(project, id, title) {
function rmSource(id, title) {
let token = document.getElementById("token").value;
let userid = document.getElementById("userid").value;
if (isMultiInput()) {
var cboxes = document.getElementsByName('selectID');
for (var i = 0; i < cboxes.length; ++i) {
Expand All @@ -1854,25 +1846,23 @@ function rmSource(project, id, title) {
url: "/api/rmsource",
type: "post",
data: {
project: project,
name: id2name(currentID),
id: currentID,
title: title,
userid: userid,
},
headers: {
"Authorization": "Basic "+ token
},
dataType: "json",
success: function(data) {
document.getElementById(`source-${data.name}-${data.title}`).remove();
if (document.getElementById(`sources-${data.name}`).childElementCount > 0) {
document.getElementById("source-button-"+data.name).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.project}','${data.id}')">+</span>
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmsource" onclick="setRmSourceModal('${data.project}','${data.id}')>-</span>
document.getElementById(`source-${data.id}-${data.title}`).remove();
if (document.getElementById(`sources-${data.id}`).childElementCount > 0) {
document.getElementById("source-button-"+data.id).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.id}')">+</span>
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmsource" onclick="setRmSourceModal('${data.id}')>-</span>
`
} else {
document.getElementById("source-button-"+data.name).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.project}','${data.id}')">+</span>
document.getElementById("source-button-"+data.id).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.id}')">+</span>
`
}
},
Expand All @@ -1887,25 +1877,23 @@ function rmSource(project, id, title) {
url: "/api/rmsource",
type: "post",
data: {
project: project,
name: id2name(id),
id: id,
title: title,
userid: userid,
},
headers: {
"Authorization": "Basic "+ token
},
dataType: "json",
success: function(data) {
document.getElementById(`source-${data.name}-${data.title}`).remove();
if (document.getElementById(`sources-${data.name}`).childElementCount > 0) {
document.getElementById("source-button-"+data.name).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.project}','${data.id}')">+</span>
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmsource" onclick="setRmSourceModal('${data.project}','${data.id}')">-</span>
document.getElementById(`source-${data.id}-${data.title}`).remove();
if (document.getElementById(`sources-${data.id}`).childElementCount > 0) {
document.getElementById("source-button-"+data.id).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.id}')">+</span>
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmsource" onclick="setRmSourceModal('${data.id}')">-</span>
`
} else {
document.getElementById("source-button-"+data.name).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.project}','${data.id}')">+</span>
document.getElementById("source-button-"+data.id).innerHTML = `
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('${data.id}')">+</span>
`
}
},
Expand Down
28 changes: 14 additions & 14 deletions assets/template/detailItem.html
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,18 @@
</div>

<div class="ml-2 row">
<div id="sources-{{$.Item.Name}}" class="row">
<div id="sources-{{$.Item.ID}}" class="row">
{{range $.Item.Sources -}}
<div id="source-{{$.Item.Name}}-{{.Title}}">
<div id="source-{{$.Item.ID}}-{{.Title}}">
<a href="{{Protocol .Path}}://{{RmProtocol .Path}}" class="badge badge-outline-darkmode ml-1" alt="{{.Author}},{{.Date}}" title="{{.Author}},{{.Date}}" target="{{ProtocolTarget .Path}}">{{.Title}}</a>
</div>
{{- end}}
</div>
<div class="ml-3" id="source-button-{{$.Item.Name}}">
<div class="ml-3" id="source-button-{{$.Item.ID}}">
{{if eq $.User.AccessLevel 4 5 6 7 8 9 10 11}}
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('{{$.Item.Project}}', '{{$.Item.ID}}')"></span>
{{if $.Item.Sources}}
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmsource" onclick="setRmSourceModal('{{$.Item.Project}}', '{{$.Item.ID}}')"></span>
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('{{$.Item.ID}}')"></span>
{{if $.Item.Sources}}
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmsource" onclick="setRmSourceModal('{{$.Item.ID}}')"></span>
{{end}}
{{end}}
</div>
Expand All @@ -416,18 +416,18 @@
<span class="text-badge">References:</span>
</div>
<div class="ml-2 row">
<div id="references-{{$.Item.Name}}" class="row">
<div id="references-{{$.Item.ID}}" class="row">
{{range $.Item.References -}}
<div id="reference-{{$.Item.Name}}-{{.Title}}">
<div id="reference-{{$.Item.ID}}-{{.Title}}">
<a href="{{Protocol .Path}}://{{RmProtocol .Path}}" class="badge badge-outline-darkmode ml-1" alt="{{.Author}},{{.Date}}" title="{{.Author}},{{.Date}}" target="{{ProtocolTarget .Path}}">{{.Title}}</a>
</div>
{{- end}}
</div>
<div class="ml-3" id="reference-button-{{$.Item.Name}}">
<div class="ml-3" id="reference-button-{{$.Item.ID}}">
{{if eq $.User.AccessLevel 4 5 6 7 8 9 10 11}}
<span class="add ml-1" data-toggle="modal" data-target="#modal-addreference" onclick="setAddReferenceModal('{{$.Item.Project}}','{{$.Item.ID}}')"></span>
<span class="add ml-1" data-toggle="modal" data-target="#modal-addreference" onclick="setAddReferenceModal('{{$.Item.ID}}')"></span>
{{if $.Item.References}}
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmreference" onclick="setRmReferenceModal('{{$.Item.Project}}','{{$.Item.ID}}')"></span>
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmreference" onclick="setRmReferenceModal('{{$.Item.ID}}')"></span>
{{end}}
{{end}}
</div>
Expand Down Expand Up @@ -589,16 +589,16 @@
<div class="col-sm-12 col-md-12 col-lg-12">
{{if eq $.User.AccessLevel 5 6 7 8 9 10 11}}
<div class="float-right">
<span class="add" data-toggle="modal" data-target="#modal-addcomment" onclick="setAddCommentModal('{{$.Item.Project}}', '{{$.Item.ID}}')"></span>
<span class="add" data-toggle="modal" data-target="#modal-addcomment" onclick="setAddCommentModal('{{$.Item.ID}}')"></span>
</div>
{{end}}
<div id="comments-{{$.Item.ID}}" onclick="selectCheckboxNone()">
{{range ReverseCommentSlice $.Item.Comments}}
<div id="comment-{{$.Item.ID}}-{{.Date}}">
<span class="text-badge">{{.Date}} / <a href="/user?id={{.Author}}" class="text-darkmode">{{.Author}}</a></span>
{{if eq $.User.AccessLevel 5 6 7 8 9 10 11}}
<span class="edit" data-toggle="modal" data-target="#modal-editcomment" onclick="setEditCommentModal('{{$.Item.Project}}','{{$.Item.ID}}','{{.Date}}','{{.Text}}','{{.MediaTitle}}','{{.Media}}')"></span>
<span class="remove" data-toggle="modal" data-target="#modal-rmcomment" onclick="setRmCommentModal('{{$.Item.Project}}', '{{$.Item.ID}}', '{{.Date}}','{{.Text}}')">×</span>
<span class="edit" data-toggle="modal" data-target="#modal-editcomment" onclick="setEditCommentModal('{{$.Item.ID}}','{{.Date}}','{{.Text}}','{{.MediaTitle}}','{{.Media}}')"></span>
<span class="remove" data-toggle="modal" data-target="#modal-rmcomment" onclick="setRmCommentModal('{{$.Item.ID}}', '{{.Date}}','{{.Text}}')">×</span>
{{end}}
<br>
<div class="text-white small">
Expand Down
10 changes: 5 additions & 5 deletions assets/template/listview.html
Original file line number Diff line number Diff line change
Expand Up @@ -412,18 +412,18 @@
</div>

<div class="ml-2 row">
<div id="sources-{{.Name}}" class="row">
<div id="sources-{{.ID}}" class="row">
{{range .Sources -}}
<div id="source-{{$name}}-{{.Title}}">
<div id="source-{{$id}}-{{.Title}}">
<a href="{{Protocol .Path}}://{{RmProtocol .Path}}" class="badge badge-outline-darkmode ml-1" alt="{{.Author}},{{.Date}}" title="{{.Author}},{{.Date}}" target="{{ProtocolTarget .Path}}" onclick="copyClipboard('{{.Path}}')">{{.Title}}</a>
</div>
{{- end}}
</div>
<div class="ml-3" id="source-button-{{.Name}}">
<div class="ml-3" id="source-button-{{.ID}}">
{{if eq $.User.AccessLevel 4 5 6 7 8 9 10 11}}
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('{{.Project}}', '{{.ID}}')"></span>
<span class="add ml-1" data-toggle="modal" data-target="#modal-addsource" onclick="setAddSourceModal('{{.ID}}')"></span>
{{if .Sources}}
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmsource" onclick="setRmSourceModal('{{.Project}}', '{{.ID}}')"></span>
<span class="remove ml-0" data-toggle="modal" data-target="#modal-rmsource" onclick="setRmSourceModal('{{.ID}}')"></span>
{{end}}
{{end}}
</div>
Expand Down
Loading

0 comments on commit 09dad41

Please sign in to comment.