Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e45908f
:pencil: README에 구현 기능 목록 정리
bucketHaneul Dec 9, 2020
3fbf61b
:sparkles: 관리 버튼 및 관리 섹션 index.html에 추가
bucketHaneul Dec 9, 2020
82f4e0d
:sparkles: 눌리는 버튼마다 해당 화면 보이도록 구현
bucketHaneul Dec 9, 2020
865f6d4
:sparkles: Station 객체 생성
bucketHaneul Dec 9, 2020
34f7b56
:sparkles: 지하철 역 추가하기 기능 구현
bucketHaneul Dec 9, 2020
3f65582
:sparkles: 지하철 역 추가 완료시 input 초기화
bucketHaneul Dec 9, 2020
46ef536
:sparkles: addStationtoList 내 변수명 변경
bucketHaneul Dec 9, 2020
04a0027
:sparkles: 올바른 지하철 역 이름인지 확인하는 함수 추가
bucketHaneul Dec 9, 2020
2d418b4
:sparkles: 노선 추가하기 기능 구현
bucketHaneul Dec 9, 2020
5a600ab
:sparkles: 지하철 목록 동적으로 노선관리 페이지에 넘기기 구현
bucketHaneul Dec 9, 2020
94841fc
:sparkles: 노선 추가하기 기능 구현
bucketHaneul Dec 9, 2020
4d7eb0b
:sparkles: 노선 선택 메뉴 보여주기 구현
bucketHaneul Dec 9, 2020
0dd0d14
:bug: 구간 관리 선택 할 때마다 메뉴 늘어나는 버그 수정
bucketHaneul Dec 9, 2020
9161607
:sparkles: 선택한 노선별 관리 화면 보여주기 구현
bucketHaneul Dec 9, 2020
b9145a8
:sparkles: 선택한 노선 내 station 보여주기 구현
bucketHaneul Dec 9, 2020
631489f
:sparkles: 노선에 속해있는 모든 station 보여주는 메소드 구현
bucketHaneul Dec 9, 2020
d4c1be0
:sparkles: 구간 추가하기 구현
bucketHaneul Dec 9, 2020
8374eb7
:sparkles: 선택된 Line 리턴하는 메소드 추가
bucketHaneul Dec 10, 2020
ff672ff
:construction: Line 내 메소드 Line.prototype -> this로 변경
bucketHaneul Dec 10, 2020
9580a80
:sparkles: 구간 변경사항 Line 객체 배열에 적용 구현
bucketHaneul Dec 10, 2020
f17629c
:sparkles: 지하철 노선도 출력하기 구현
bucketHaneul Dec 10, 2020
7e1057b
:sparkles: 지하철 역 삭제하기 구현
bucketHaneul Dec 10, 2020
229ccb9
:bug: 지하철 역 이름에 영어 포함 가능하게 수정
bucketHaneul Dec 10, 2020
77e450e
:sparkles: 노선 삭제하기 구현 및 함수 분리
bucketHaneul Dec 10, 2020
fe1c9ed
:art: 하나의 line Button 만드는 함수 분리
bucketHaneul Dec 10, 2020
dcf4e31
:art: 선택된 라인 객체 찾는 방법 변경
bucketHaneul Dec 10, 2020
a6d327f
:sparkles: 구간 삭제하기 구현
bucketHaneul Dec 10, 2020
d40bedf
:art: 하나의 구간 <tr> 만드는 함수 분리
bucketHaneul Dec 10, 2020
ccd8370
:pencil: 기능 구현하며 수정한 README 업데이트
bucketHaneul Dec 10, 2020
8102d4f
:bug: 지하철 역 이름 숫자, 영어 가능 및 중복 불가하게 수정
bucketHaneul Dec 10, 2020
8e56e4a
:bug: 선택 노선 변경 시 지하철 역 계속 나열 안되게 수정
bucketHaneul Dec 10, 2020
873a5fb
:bug: 선택 노선 변경 시 지하철 역 option 계속 추가 안되게 수정
bucketHaneul Dec 10, 2020
bbeaeb5
:construction: 라인 추가시 manager객체 내에도 반영되게 수정
bucketHaneul Dec 11, 2020
79d341f
:construction: 역 추가시 manager객체 내에도 반영되게 수정
bucketHaneul Dec 11, 2020
710ae29
:sparkles: 이미 노선에 등록된 역은 삭제 못하게 하는 함수 구현
bucketHaneul Dec 11, 2020
c3652c1
:sparkles: station 객체가 포함된 노선의 속성 및 관련 메소드 추가
bucketHaneul Dec 11, 2020
e0b4e93
:sparkles: 구간 관리에서 station 삭제 시 선택된 노선 삭제 구현
bucketHaneul Dec 11, 2020
ecfc1f1
:white_check_mark: test 라인 추가
bucketHaneul Dec 11, 2020
5f9e391
:construction: 하나의 역 객체는 하나의 등록된 노선을 갖도록 수정
bucketHaneul Dec 11, 2020
33ffc27
:construction: manager 객체 index.js에서 분리
bucketHaneul Dec 11, 2020
9f17c2b
:construction: 역 추가시 새로운 station객체 생성하게 수정
bucketHaneul Dec 11, 2020
0d5e8aa
:sparkles: 역관리에서 역 삭제 다시 구현
bucketHaneul Dec 11, 2020
41f588b
:sparkles: 노선관리에서 노선 삭제 시 역도 같이 삭제되도록 수정
bucketHaneul Dec 11, 2020
f75eda0
:sparkles: 구간 관리에서 역 삭제 다시 구현
bucketHaneul Dec 11, 2020
5e77b3b
:sparkles: 중복 제거된 stationList 보여주기 구현
bucketHaneul Dec 11, 2020
7ae8b4f
:bug: 중복 노선 등록 불가하도록 조건 함수 추가
bucketHaneul Dec 11, 2020
bc10cfc
:bug: 구간 관리 input Index 올바른지 체크
bucketHaneul Dec 12, 2020
de5d688
:sparkles: 종점을 제거할 셩우 다음 역 종점으로 설정
bucketHaneul Dec 12, 2020
c487e22
:bug: 노선 이름 2글자 이상인지 체크
bucketHaneul Dec 12, 2020
41512b6
:bug: 노선 추가 후 지하철 역 선택 옵션 초기화
bucketHaneul Dec 12, 2020
8918752
:pencil: 예외처리 항목 추가한 README
bucketHaneul Dec 12, 2020
8420341
:construction: makeStationOption() params 1개로 변경
bucketHaneul Dec 12, 2020
5e7af7b
:construction: 버튼 클릭 이벤트 코드 각각의 모듈로 이동
bucketHaneul Dec 12, 2020
013721a
:construction: 지하철 역 selector 생성하는 함수들 모듈로 분리
bucketHaneul Dec 12, 2020
3437c54
:fire: 모듈 분리하며 작성한 주석 삭제
bucketHaneul Dec 12, 2020
e55e963
:hammer: station-manager.js 리팩토링
bucketHaneul Dec 12, 2020
31a16dc
:construction: 노선 관리 input 초기화 코드들 함수 분리
bucketHaneul Dec 12, 2020
6fd886f
:hammer: line-manager.js 리팩토링
bucketHaneul Dec 12, 2020
9596b0f
:hammer: section-manager.js 리팩토링
bucketHaneul Dec 12, 2020
4944d89
:hammer: map-print-manager.js 리팩토링
bucketHaneul Dec 12, 2020
6e623d6
:hammer: manager.js 리팩토링
bucketHaneul Dec 12, 2020
977818b
:bug: 라인의 첫 번째 역 삭제 시 isIncluded 업데이트
bucketHaneul Dec 14, 2020
f129073
:bug: 지하철 역 삭제 조건 수정
bucketHaneul Dec 14, 2020
aa7507c
:bug: 삭제 노선 정보 가져오는 과정 수정
bucketHaneul Dec 14, 2020
87662ea
:sparkles: localStorage 적용
bucketHaneul Dec 14, 2020
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
83 changes: 83 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
## ✅ 구현 기능 목록

### 기본 세팅

- 클릭되는 버튼마다 하단 result 변경하기

### 지하철 역 관련

- 지하철 역 목록 조회하기
- 지하철 역 등록하기
- 지하철 역 생성 객체(name, 속하는 line 등 포함)
- 지하철 역 삭제하기(노선에 등록 안 된거만)

### 지하철 노선 관련

- 노선 등록하기(상행 종점역, 하행 종점역)
- 노선 삭제하기
- 중복 노선 불가
- 지하철 노선 목록 조회하기

### 지하철 구간

- 관리할 노선 선택하기
- 선택된 노선의 전체 구간 보여주기
- 구간 추가하기( === 노선에 역 추가하기)
- 입력 받은 순서로, line 내 해당 번호 station 사이에 추가하기
- 추가 사항 적용된 구간 보여주기
- 상행 종점과 하행 종점 삭제시, 다음 역 종점으로 설정
-

### 지하철 노선도 출력 기능

- 노선도 출력 버튼 누르면 노선도 출력
- Line 객체 배열 순회하면서, 차례로 출력

## :star: 예외처리 항목

#### 역 관리

- 지하철 역 이름 예외처리
- 역이 한 line에 포함된 상태에서 삭제 될 때
- 노선에 등록된 역은 삭제할 수 없다는 조건 존재
- 역 삭제 시
1. 역 관리에서 삭제
- 삭제하는 대상의 station 객체의 isIncluded 속성의 길이가 === 1 일 시 삭제 불가
=> 역이 이미 노선에 등록되어 있음
- isIncluded 속성의 길이 === 0 일 시 삭제 가능
=> 역이 등록된 노선 없음
2. 구간 관리에서 삭제
- station 객체의 isInCluded 속성에서 선택된 라인을 삭제
- 중복 지하철 역 불가 => isOverlappedStationName()

#### 노선 관리

- 노선 이름 입력 값 예외처리
- 상행과 하행 이름 같을 때

#### 구간 관리

- 선택 노선 변경 시 지하철 역 계속 나열 안되게 수정
- 지하철 역 추가하고 나서 초기화
- 중복 지하철 역 추가 불가해야함
- 0 < inputIdx <= 마지막 인덱스 && 정수일 때
- 상행 종점과 하행 종점 삭제시, 다음 역 종점으로 설정

#### 그 외

- station 객체가 노선에 등록 될 때마다 등록되는 노선을 추가하면 안됌.
- 하나의 역은 여러 노선에 포함될 수 있음
- 하지만 하나의 역은 하나의 다음 역을 가짐
- 이상해짐
=> 노선을 추가할 때 새로운 역 객체를 만들기
=> 역 객체가 속하는 노선은 1개
- station 객체 전체를 보여줄 때
1. 역 관리에서
- isIncluded === null 인거 하나만 있으면 이거 보여주기
- isIncluded === null 외에 더 있으면 그 중 하나 보여주기
2. 노선 관리, 구간 관리의 option에서
- 중복만 없애서 보여주기

## :open_mouth: 의문점

- 객체 Line을 다룰 때 addStaionToIdx()라는 메소드를 통해서 station을 원하는 위치에 끼워넣으려 한다. 그런데 prototype을 메소드 명 앞에 붙히면 안되고, 안 붙히면 내가 원하는 대로 작동한다. 그래서 prototype에 대해 공부하였는데 내가 원하는 답을 찾지는 못했다. 더 알아봐야겠다.
78 changes: 77 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,83 @@
</head>
<body>
<div id="app">
<h1>🚇 지하철 노선도 관리 </h1>
<h1>🚇 지하철 노선도 관리</h1>
<div>
<button id="station-manager-button">1. 역 관리</button>
<button id="line-manager-button">2. 노선 관리</button>
<button id="section-manager-button">3. 구간 관리</button>
<button id="map-print-manager-button">4. 지하철 노선도 출력</button>
</div>
<div class="result">
<div id="station-manager-result" style="display: block">
<div>
<div>역 이름</div>
<div>
<input id="station-name-input" />
<button id="station-add-button">역 추가</button>
</div>
</div>
<div>
<div>지하철 역 목록</div>
<table id="staion-list-table">
<thead>
<th>역 이름</th>
<th>설정</th>
</thead>
<tbody id="station-list"></tbody>
</table>
</div>
</div>
<div id="line-manager-result" style="display: None">
<div>
<div>노선 이름</div>
<input id="line-name-input" />
<div>
<label for="line-start-station-selector">상행 종점</label>
<select id="line-start-station-selector"></select>
</div>
<div>
<label for="line-end-station-selector">하행 종점</label>
<select id="line-end-station-selector"></select>
</div>
<button id="line-add-button">노선 추가</button>
</div>
<div>
<div>지하철 역 목록</div>
<table id="line-list-table">
<thead>
<th>노선 이름</th>
<th>상행 종점역</th>
<th>하행 종점역</th>
<th>설정</th>
</thead>
<tbody id="line-list"></tbody>
</table>
</div>
</div>
<div id="section-manager-result" style="display: None">
<div>구간을 수정할 노선을 선택해주세요.</div>
<div id="section-line-list"></div>
<div id="selected-section-line" style="display: None">
<h3 id="section-line-name"></h3>
<div>구간 등록</div>
<div>
<select id="section-station-selector"></select>
<input id="section-order-input" />
<button id="section-add-button">등록</button>
</div>
<table id="station-in-selected-line-list-table">
<thead>
<th>순서</th>
<th>이름</th>
<th>설정</th>
</thead>
<tbody id="station-in-selected-line"></tbody>
</table>
</div>
</div>
<div id="map-print-manager-result" style="display: None"></div>
</div>
</div>
<script type="module" src="src/index.js"></script>
</body>
Expand Down
93 changes: 93 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import Station from "./station.js";
import { showAllStationInManager } from "./station-manager.js";
import Line from "./line.js";
import { showAllLineInLineManager } from "./line-manager.js";
import { showLineMenuInSectionManager } from "./section-manager.js";
import { showMapList } from "./map-print-manager.js";
import { manager } from "./manager.js";
import { makeStationOption, makeStationList } from "./make-selector-list.js";

const btnStationManager = document.getElementById("station-manager-button");
const btnLineManager = document.getElementById("line-manager-button");
const btnSectionManager = document.getElementById("section-manager-button");
const btnMapPrintManager = document.getElementById("map-print-manager-button");
const resultStationManager = document.getElementById("station-manager-result");
const resultSectionManager = document.getElementById("section-manager-result");
const resultLineManager = document.getElementById("line-manager-result");
const resultMapPrintManager = document.getElementById(
"map-print-manager-result"
);
const resultList = [
resultStationManager,
resultLineManager,
resultSectionManager,
resultMapPrintManager,
];

// storage.clear();
export const initializeStationList = () => {
const stationList = JSON.parse(storage.getItem("stationList"));
if (stationList === null) {
manager.stationList = [];
} else {
for (let i in stationList) {
const station = new Station(stationList[i].name);
station.next = stationList[i].next;
station.isIncluded = stationList[i].isIncluded;
manager.setStationInManager(station);
}
}
showAllStationInManager(makeStationList());
};
export const initializeLineList = () => {
const lineList = JSON.parse(storage.getItem("lineList"));
if (lineList === null) {
manager.lineList = [];
} else {
for (let i in lineList) {
const line = new Line(lineList[i].name);
line.length = lineList[i].length;
line.head = lineList[i].head;
manager.setLineInManager(line);
}
}
};
const storage = window.localStorage;
window.onload = () => {
// 페이지 새로 열릴 때
initializeStationList();
initializeLineList();
};
window.onbeforeunload = () => {
// 페이지 닫히기 전
storage.setItem("stationList", JSON.stringify(manager.stationList));
storage.setItem("lineList", JSON.stringify(manager.lineList));
};
const makeResultBlock = (idx) => {
for (let i in resultList) {
if (i === String(idx)) {
resultList[i].style.display = "Block";
} else {
resultList[i].style.display = "None";
}
}
};
showAllStationInManager(manager.stationList);
btnStationManager.onclick = () => {
makeResultBlock(0);
showAllStationInManager(makeStationList());
};
btnLineManager.onclick = () => {
makeResultBlock(1);
makeStationOption("line-start-station-selector");
makeStationOption("line-end-station-selector");
showAllLineInLineManager(manager.lineList);
};
btnSectionManager.onclick = () => {
makeResultBlock(2);
showLineMenuInSectionManager(manager.lineList);
};
btnMapPrintManager.onclick = () => {
makeResultBlock(3);
showMapList();
};
113 changes: 113 additions & 0 deletions src/line-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { makeStationOption } from "./make-selector-list.js";
import { manager } from "./manager.js";
import Line from "./line.js";
import Station from "./station.js";

export const deleteLineInList = (lineName) => {
const parent = document.querySelector("tbody#line-list");
const deleteIdx = manager.lineList.findIndex((line) => {
return line.name === lineName;
});
parent.removeChild(document.getElementById(`${lineName}-line`));
manager.lineList[deleteIdx].deleteAllStationInLine();
manager.lineList.splice(deleteIdx, 1);
};
export const makeLineChildUI = (line) => {
const lineName = document.createElement("td");
const startStation = document.createElement("td");
const endStation = document.createElement("td");
const deleteButton = document.createElement("td");
lineName.innerHTML = line.name;
startStation.innerHTML = line.getStartStation();
endStation.innerHTML = line.getEndStation();
deleteButton.innerHTML = "삭제";
deleteButton.setAttribute("class", "line-delete-button");
deleteButton.onclick = () => {
deleteLineInList(`${line.name}`);
};
deleteButton.innerHTML = "삭제";

return [lineName, startStation, endStation, deleteButton];
};
export const makeLineUI = (line) => {
const [lineName, startStation, endStation, deleteButton] = makeLineChildUI(
line
);
const newLine = document.createElement("tr");
newLine.setAttribute("id", `${line.name}-line`);
newLine.append(lineName, startStation, endStation, deleteButton);

return newLine;
};
export const showAllLineInLineManager = (lineList) => {
const table = document.getElementById("line-list");
table.innerHTML = "";
lineList.forEach((line) => {
const newLine = makeLineUI(line);
table.appendChild(newLine);
});
document.getElementById("line-name-input").value = "";
};
export const isPossibleLineName = (name) => {
const rHangel = /^[0-9A-Za-z가-힣]*$/;
if (name.length > 0 && rHangel.exec(name) !== null) {
return true;
}
alert("올바른 노선 이름을 입력 해주세요");

return false;
};
export const resetLineInput = () => {
document.getElementById("line-name-input").value = "";
makeStationOption("line-start-station-selector");
makeStationOption("line-end-station-selector");
};
export const isPossibleLine = (startName, endName) => {
if (startName === endName) {
alert("상행 종점과 다른 하행 종점을 선택 해주세요.");
resetLineInput();

return false;
}
return true;
};
export const isOverlappedLineName = (newLineName) => {
const overlappedName = manager.lineList.find(
(line) => line.name === newLineName
);
if (overlappedName) {
alert("이미 등록된 노선입니다.");
resetLineInput();

return true;
}
return false;
};
export const addLineToList = () => {
const newLineName = document.getElementById("line-name-input").value;
const startStationName = document.getElementById(
"line-start-station-selector"
).value;
const endStationName = document.getElementById("line-end-station-selector")
.value;
if (
isPossibleLineName(newLineName) &&
isPossibleLine(startStationName, endStationName) &&
!isOverlappedLineName(newLineName)
) {
const line = new Line(newLineName);
const startStation = new Station(startStationName);
const endStation = new Station(endStationName);
manager.setStationInManager(startStation);
manager.setStationInManager(endStation);
line.addLine(startStation, endStation);
manager.setLineInManager(line);
showAllLineInLineManager(manager.lineList);
resetLineInput();
}
};

const btnAddLine = document.getElementById("line-add-button");
btnAddLine.onclick = () => {
addLineToList();
};
Loading