Skip to content

Commit

Permalink
Merge pull request #7 from boostcampaitech4lv23cv1/feat1_yj
Browse files Browse the repository at this point in the history
Feat1 yj
  • Loading branch information
bsh201 authored Jan 25, 2023
2 parents adad914 + 48df9fa commit a4c32a7
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 34 deletions.
1 change: 1 addition & 0 deletions app/static/css/bootstrap.min.css.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/static/css/bootstrap.rtl.min.css.map

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions app/static/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
li {
list-style-type: none;
}

.image-files {
border: 1.5px solid black;
}

.slides {
position:relative;
left: 0;
top: 0;
width: 100%; /* 슬라이드할 사진과 마진 총 넓이 */
transition: left 0.5s ease-out;
/*ease-out: 처음에는 느렸다가 점점 빨라짐*/
}
1 change: 1 addition & 0 deletions app/static/js/bootstrap.bundle.min.js.map

Large diffs are not rendered by default.

131 changes: 115 additions & 16 deletions app/static/js/custom.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,124 @@
function hello(){
alert('dd')
const images = new DataTransfer();
const chooseFile = document.getElementById('chooseFile');

function uploadBoxOnclick(){
chooseFile.click();
}

function getImageFiles(e) {//파일 추가 업로드 시 리셋되지 않고 뒤에 추가되도록
const files = e.currentTarget.files;

if(files != null && files.length>0){
for(var i=0;i<files.length;i++){
images.items.add(files[i])
}
}
chooseFile.files = images.files;
console.log("input FIles =>", chooseFile.files)
addImages(files);
e.target.value = ''; //같은 파일 추가 가능하도록 reset
}

chooseFile.addEventListener('change', getImageFiles);//파일 업로드 후 이벤트

/* 이미지 슬라이드 코드 */
const slides = document.querySelector('.slides'); //슬라이드 ul
let slideImg = document.querySelectorAll('.slides li'); //슬라이드 list
const uploadPage = slideImg[0]; //파일 업로드 페이지
let curIdx = 0; //현재 슬라이드 index
let slideCnt = slideImg.length; // 슬라이드 개수
const prev_btn = document.getElementById('prev_btn'); //이전 버튼
const next_btn = document.getElementById('next_btn'); //다음 버튼
const del_btn = document.getElementById('del_btn');

function moveImages(cur, next) {

if(cur > -1) slideImg[cur].hidden=true;
slideImg[next].hidden=false;
curIdx = next;
buttonDisable()
}

function preventDefaults(e) { //브라우저 파일 드래그&드롭 기본 이벤트 막기
e.preventDefault();
e.stopPropagation();
function buttonDisable(){
if(curIdx == 0) prev_btn.disabled = true;
else prev_btn.disabled = false;

if(curIdx==slideCnt-1){
next_btn.disabled = true;
del_btn.disabled = true;
} else{
next_btn.disabled = false;
del_btn.disabled = false;
}
}

/*드래그 인 시 하이라이팅 & 드래그 아웃 시 하이라이팅 제거*/
const dropArea = document.getElementById("drop-file");
function prevButton() {
/*첫 번째 슬라이드로 표시 됐을때는
이전 버튼 눌러도 아무런 반응 없게 하기 위해
curIdx !==0일때만 moveImages 함수 불러옴 */
if (curIdx !== 0) moveImages(curIdx, curIdx-1);
};

function highlight(e) {
preventDefaults(e);
dropArea.classList.add("highlight");
function nextButton() {
/* 마지막 슬라이드로 표시 됐을때는
다음 버튼 눌러도 아무런 반응 없게 하기 위해
curIdx !==slideCnt - 1 일때만
moveImages 함수 불러옴 */
if (curIdx !== slideCnt - 1) {
moveImages(curIdx, curIdx + 1);
}
};

function delButton() {
var result = confirm("현재 이미지를 삭제하시겠습니까?")
if(result){
slideImg[curIdx].remove();
slideImg = document.querySelectorAll('.slides li'); //변경된 리스트
slideCnt = slideImg.length;
moveImages(-1, curIdx);
}
}

function unhighlight(e) {
preventDefaults(e);
dropArea.classList.remove("highlight");
/* 이미지 li에 추가하는 함수 */
async function addImages(files){
slideImg[slideCnt-1].remove();

await Promise.all([...files].map(file => new Promise(resolve =>{
const reader = new FileReader();
reader.onload = (e) => {
const li = createElement(e, file)
slides.appendChild(li);
resolve();
}
reader.readAsDataURL(file);
})))

/* 이미지 추가 후처리 */
debugger;
console.log("이미지 추가 후처리")
slides.appendChild(uploadPage);
slideImg = document.querySelectorAll('.slides li'); //변경된 리스트
slideCnt = slideImg.length;
curIdx = slideCnt - files.length - 1;
if(curIdx+1==slideCnt) curIdx=0;
for(var i=0;i<slideCnt;i++){
slideImg[i].hidden = true;
}
slideImg[curIdx].hidden = false;
buttonDisable();
}

dropArea.addEventListener("dragenter", highlight, false);
dropArea.addEventListener("dragover", highlight, false);
dropArea.addEventListener("dragleave", unhighlight, false);
function createElement(e, file) {
debugger;
console.log("createElemete:: ", file);
const li = document.createElement('li');
const img = document.createElement('img');
img.setAttribute('src', e.target.result);
img.setAttribute('data-file', file.name);
img.setAttribute('width', '100%');
img.setAttribute('height', '100%');
img.setAttribute('class', 'image-files');
li.appendChild(img);

return li;
}
54 changes: 36 additions & 18 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<title>Maestro::Musical Score to Sound</title>

<link rel="canonical" href="https://getbootstrap.com/docs/5.2/examples/navbars/">
<link href="{{url_for('static', path='/css/custom.css')}}" rel="stylesheet">
<link href="{{url_for('static', path='/css/custom.css?after')}}" rel="stylesheet">

<link href="{{url_for('static', path='/css/bootstrap.min.css')}}" rel="stylesheet">

Expand Down Expand Up @@ -66,20 +66,26 @@
}

.upload {
margin-top: 25px;
margin-top: 15px;
text-align: center;
}

.upload .top-button{
background-color: #fff;
border: none;
}

.upload-box {
width: calc(50% - 15px);
width: 50%;
box-sizing: border-box;
margin-right: 30px;
/* margin-right: 30px; */
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin: auto;
}
.upload-box .drag-file {
.upload-box .upload-file {
width: 100%;
height: 750px;
display: flex;
Expand All @@ -88,15 +94,11 @@
align-items: center;
border: 3px dashed #dbdbdb;
}
.upload-box .drag-file.highlight {
border: 3px dashed red;
}
.upload-box .drag-file .image {
.upload-box .upload-file .image {
width: 40px;
}
.upload-box .drag-file .message {
margin-bottom: 0;
}


</style>

</head>
Expand Down Expand Up @@ -141,12 +143,28 @@ <h4 class="text-white">About us</h4>
</header>
<main>
<div class="upload">
<div class="upload-box" onclick="document.getElementById('chooseFile').click();">
<div id="drop-file" class="drag-file">
<label><img src="https://img.icons8.com/pastel-glyph/2x/image-file.png" alt="파일 아이콘" class="image"></label>
<label>Drag files or click here to upload</label>
<input class="file" id="chooseFile" type="file" accept="image/*" multiple style="display:none">
</div>
<button type="button" class="top-button" disabled id="prev_btn" onclick="prevButton()">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" class="bi bi-caret-left-fill" viewBox="0 0 16 16"><path d="m3.86 8.753 5.482 4.796c.646.566 1.658.106 1.658-.753V3.204a1 1 0 0 0-1.659-.753l-5.48 4.796a1 1 0 0 0 0 1.506z"/></svg>
</button>
<button type="submit" class="top-button" disabled id="submit_btn">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" class="bi bi-file-earmark-music-fill" viewBox="0 0 16 16"><path d="M9.293 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V4.707A1 1 0 0 0 13.707 4L10 .293A1 1 0 0 0 9.293 0zM9.5 3.5v-2l3 3h-2a1 1 0 0 1-1-1zM11 6.64v1.75l-2 .5v3.61c0 .495-.301.883-.662 1.123C7.974 13.866 7.499 14 7 14c-.5 0-.974-.134-1.338-.377-.36-.24-.662-.628-.662-1.123s.301-.883.662-1.123C6.026 11.134 6.501 11 7 11c.356 0 .7.068 1 .196V6.89a1 1 0 0 1 .757-.97l1-.25A1 1 0 0 1 11 6.64z"/></svg>
</button>
<button type="button" class="top-button" disabled id="del_btn" onclick="delButton()">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" class="bi bi-trash3-fill" viewBox="0 0 16 16"><path d="M11 1.5v1h3.5a.5.5 0 0 1 0 1h-.538l-.853 10.66A2 2 0 0 1 11.115 16h-6.23a2 2 0 0 1-1.994-1.84L2.038 3.5H1.5a.5.5 0 0 1 0-1H5v-1A1.5 1.5 0 0 1 6.5 0h3A1.5 1.5 0 0 1 11 1.5Zm-5 0v1h4v-1a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5ZM4.5 5.029l.5 8.5a.5.5 0 1 0 .998-.06l-.5-8.5a.5.5 0 1 0-.998.06Zm6.53-.528a.5.5 0 0 0-.528.47l-.5 8.5a.5.5 0 0 0 .998.058l.5-8.5a.5.5 0 0 0-.47-.528ZM8 4.5a.5.5 0 0 0-.5.5v8.5a.5.5 0 0 0 1 0V5a.5.5 0 0 0-.5-.5Z"/></svg>
</button>
<button type="button" class="top-button" disabled id="next_btn" onclick="nextButton()">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" fill="currentColor" class="bi bi-caret-right-fill" viewBox="0 0 16 16"><path d="m12.14 8.753-5.482 4.796c-.646.566-1.658.106-1.658-.753V3.204a1 1 0 0 1 1.659-.753l5.48 4.796a1 1 0 0 1 0 1.506z"/></svg>
</button>
<div class="upload-box">
<ul class="slides">
<!-- <li><img src="{{url_for('static', path='images/arirang.jpg')}}" width="100%" height="100%" class="image-files"></li> -->
<li>
<div class="upload-file" onclick="uploadBoxOnclick()">
<label><img src="https://img.icons8.com/pastel-glyph/2x/image-file.png" alt="파일 아이콘" class="image"><br/>Click here to upload images</label>
<input class="file" id="chooseFile" type="file" accept="image/*" multiple style="display:none">
</div>
</li>
</ul>
</div>
</div>
</main>
Expand Down

0 comments on commit a4c32a7

Please sign in to comment.