Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dir 예외처리 #41

Open
wants to merge 5 commits into
base: dev-test-1014
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ async function initUserHistoryData() {
},
];
writeDB(datas, "userHistoryStore");
//아 얘도 필요하기는 함, list.js와 코드 중복 아님
//익스텐션 실행시(dirlist 로드 하지 않더라도 기본 세팅) 확인하는거고, list.js 는 페이지 로드시 확인
const dirDatas = [{
dir_name: '초기 New Dir',
}];
Expand Down
14 changes: 5 additions & 9 deletions list.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ body {
text-overflow: ellipsis;
}

.dir-title {
/* overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis; */
}


.dir-list {
margin-bottom: 9px;
Expand Down Expand Up @@ -423,7 +419,7 @@ a>p {
font-size: 1rem;
font-family: inherit;
font-weight: inherit;
margin-top:1rem;
margin-top: 1rem;
margin-bottom: 1rem;
padding-bottom: 0.5rem;
outline: none;
Expand Down Expand Up @@ -672,11 +668,11 @@ footer {
color: #606060;
}

.dir-buttonBox{
display:flex;
.dir-buttonBox {
display: flex;
align-items: center;
}

.dir-link{
.dir-link {
width: 250px;
}
72 changes: 56 additions & 16 deletions list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ document.addEventListener("DOMContentLoaded", function () {
if (window.location.pathname === "/list.html") {
initListPage();



} else if (window.location.pathname === "/dirList.html") {
readDBAndDisplay();
document.getElementById("dirAddButton").addEventListener("click", () => { dirAddButtonClick(); });

defaultDirSet();
//경우에 따라 다르게 부여
//TODO
// if (onDirId != 0) {
Expand Down Expand Up @@ -44,7 +42,6 @@ function dirAddButtonClick() {
// 오 템플릿이기 때문에, 이벤트 리스너도 템플릿 생성할 때 추가하도록 해야함
const editButton = copy.querySelector(".button-edit");
const deleteButton = copy.querySelector(".button-del");
const buttonBox = copy.querySelector(".dir-buttonBox");
const dirLink = copy.querySelector(".dir-link");
const dirText = copy.querySelector(".dir-text");

Expand Down Expand Up @@ -157,6 +154,7 @@ function setupDirDeleteEvent(button) {
// 디렉토리 데이터베이스에서도 삭제
const d_id = dirElement.id;
deleteDirDB(d_id);
location.reload();
}


Expand All @@ -167,16 +165,30 @@ async function initListPage() {
var dirId = urlParams.get("dir_id");
const dirNameElement = document.querySelector("#dir-name");

console.log('initListpage');
console.log(dirId);


if (dirId == null) {
//초기 진입할 때,
try {
var userHistoryData = await readDBbyStoreName('userHistoryStore');


dirId = userHistoryData[0]['recentlyExecutedDir'];
console.log(dirId);
var initDirName = await readDBbyStoreNameAndId('dirStore', parseInt(dirId));
console.log(initDirName);

if (initDirName == undefined) { //recentlyExecutedDir가 삭제 됨 -> 아무 디렉토리
var tempDir = await readDBbyStoreName('dirStore');
dirId = tempDir[0]['d_id'];
console.log('체크');
console.log(dirId);
initDirName = await readDBbyStoreNameAndId('dirStore', parseInt(dirId));
//오 코드 완전 별로
//위에랑 if-else 로 처리하는 방법으로 나중에 수정
}
dirName = initDirName['dir_name']
dirNameElement.textContent = dirName;

Expand Down Expand Up @@ -265,16 +277,17 @@ function readDBbyStoreNameAndId(store_name, id) {
});
}

// async function getNowDirId() {
// try {
// var userHistoryData = await readDBbyStoreName('userHistoryStore');
// console.log(userHistoryData[0]['nowExecutedDir']);
// data = userHistoryData[0]['nowExecutedDir'];
// return data;
// } catch (error) {

// }
// }
async function getNowDirId() {
try {
var userHistoryData = await readDBbyStoreName('userHistoryStore');
console.log('현재 실ㅇ중인 ');
console.log(userHistoryData[0]['nowExecutedDir']);
data = userHistoryData[0]['nowExecutedDir'];
return data;
} catch (error) {
return 0;
}
}

/********************************************************************************************************* */

Expand Down Expand Up @@ -632,6 +645,23 @@ function displayURL(data) {
// displayTooltip();


async function defaultDirSet() {
console.log('디폴트 디비 함수 실행됨');
try {
var dirData = await readDBbyStoreName('dirStore');
if (dirData.length < 1) {

dirAddButtonClick();
//위 함수도 따로 더 범용성 있게 하면 좋을 듯,, 클릭이 아니라 그냥 add자체로

}


} catch (error) {
console.error(error);
}
}



function displayTooltip(dataCount) {
Expand Down Expand Up @@ -1014,8 +1044,12 @@ function readDBAndDisplay() {
}

// 데이터를 화면에 표시
function displayData(data) {
async function displayData(data) {
const container = document.getElementById("dir_container");
var nowDIrId;
nowDIrId = await getNowDirId();
console.log('현재 실행 중 :');
console.log(nowDIrId);

data.forEach(item => {
const copy = document.getElementById("dir_template").content.cloneNode(true);
Expand All @@ -1025,7 +1059,13 @@ function displayData(data) {
const dirLink = copy.querySelector(".dir-link");

dirList.id = item.d_id;
dirList.querySelector(".dir-text").textContent = item.dir_name;
if (dirList.id == nowDIrId) {
// dirLink.querySelector(".dir-point").textContent = '❗';
dirList.querySelector(".dir-text").textContent = '❗' + item.dir_name;
} else {
dirList.querySelector(".dir-text").textContent = item.dir_name;

}

editButton.addEventListener("click", function () {
setupDirEditEvent(this);
Expand Down