From e45908fd8c432ad3ab39d2554cd1d551f843b9e2 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Wed, 9 Dec 2020 17:20:20 +0900 Subject: [PATCH 01/65] =?UTF-8?q?:pencil:=20README=EC=97=90=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9=EB=A1=9D=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 docs/README.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 000000000..f8bf3a077 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,20 @@ +## ✅ 구현 기능 목록 + +### 지하철 역 관련 + +- 지하철 역 등록하기 +- 지하철 역 삭제하기(노선에 등록 안 된거만) +- 지하철 역 목록 조회하기 + +### 지하철 노선 관련 + +- 노선 등록하기(상행 종점역, 하행 종점역) +- 노선 삭제하기 +- 중복 노선 불가 +- 지하철 노선 목록 조회하기 + +### 지하철 구간 + +- 구간 추가하기( === 노선에 역 추가하기) + +## :star: 예외처리 항목 From 3fbf61b30cf3dfa3a85d6ea6ba795c091a4c67cd Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Wed, 9 Dec 2020 18:14:00 +0900 Subject: [PATCH 02/65] =?UTF-8?q?:sparkles:=20=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=EB=B2=84=ED=8A=BC=20=EB=B0=8F=20=EA=B4=80=EB=A6=AC=20=EC=84=B9?= =?UTF-8?q?=EC=85=98=20index.html=EC=97=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index fc99deac2..10994bf9f 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,21 @@
-

🚇 지하철 노선도 관리

+

🚇 지하철 노선도 관리

+
+ + + + +
+
+ + + + +
From 82f4e0dee9264419254f3698843a482fddceb2e6 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Wed, 9 Dec 2020 18:15:37 +0900 Subject: [PATCH 03/65] =?UTF-8?q?:sparkles:=20=EB=88=8C=EB=A6=AC=EB=8A=94?= =?UTF-8?q?=20=EB=B2=84=ED=8A=BC=EB=A7=88=EB=8B=A4=20=ED=95=B4=EB=8B=B9=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=20=EB=B3=B4=EC=9D=B4=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/index.js b/src/index.js index e69de29bb..b20831710 100644 --- a/src/index.js +++ b/src/index.js @@ -0,0 +1,37 @@ +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, +]; +function makeResultBlock(idx) { + for (let i in resultList) { + if (i == idx) { + resultList[i].style.display = "Block"; + } else { + resultList[i].style.display = "None"; + } + } +} +btnStationManager.onclick = function () { + makeResultBlock(0); +}; +btnLineManager.onclick = function () { + makeResultBlock(1); +}; +btnSectionManager.onclick = function () { + makeResultBlock(2); +}; +btnMapPrintManager.onclick = function () { + makeResultBlock(3); +}; From 865f6d4bad8c0937b923337e7091f41bdfac684e Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Wed, 9 Dec 2020 19:53:22 +0900 Subject: [PATCH 04/65] =?UTF-8?q?:sparkles:=20Station=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/station.js | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/station.js diff --git a/src/station.js b/src/station.js new file mode 100644 index 000000000..63e1ce035 --- /dev/null +++ b/src/station.js @@ -0,0 +1,4 @@ +export default function Station(name) { + this.name = name; + this.includedLine = []; +} From 34f7b565a63aa0fd78c16d62364180b00241b282 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Wed, 9 Dec 2020 20:08:50 +0900 Subject: [PATCH 05/65] =?UTF-8?q?:sparkles:=20=EC=A7=80=ED=95=98=EC=B2=A0?= =?UTF-8?q?=20=EC=97=AD=20=EC=B6=94=EA=B0=80=ED=95=98=EA=B8=B0=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 20 +++++++++++++++++++- src/index.js | 24 ++++++++++++++++++------ src/station-manager.js | 13 +++++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 src/station-manager.js diff --git a/index.html b/index.html index 10994bf9f..a9ccc5954 100644 --- a/index.html +++ b/index.html @@ -14,7 +14,25 @@

🚇 지하철 노선도 관리

- +
+
+
역 이름
+
+ + +
+
+
+
지하철 역 목록
+ + + + + + +
역 이름설정
+
+
- + diff --git a/src/index.js b/src/index.js index eb916b21a..3dd764cbc 100644 --- a/src/index.js +++ b/src/index.js @@ -30,8 +30,20 @@ const makeResultBlock = (idx) => { btnStationManager.onclick = () => { makeResultBlock(0); }; +const setStationList = (stationList) => { + const startOptions = document.getElementById("line-start-station-selector"); + const endOptions = document.getElementById("line-end-station-selector"); + for (let idx in stationList) { + const newOption = document.createElement("option"); + newOption.innerHTML = stationList[idx].name; + const copyOption = newOption.cloneNode(true); + startOptions.appendChild(newOption); + endOptions.appendChild(copyOption); + } +}; btnLineManager.onclick = () => { makeResultBlock(1); + setStationList(stationList); }; btnSectionManager.onclick = () => { makeResultBlock(2); From 94841fc53ea2fb115d0aaa93455a490ce9029bb8 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Wed, 9 Dec 2020 22:42:44 +0900 Subject: [PATCH 11/65] =?UTF-8?q?:sparkles:=20=EB=85=B8=EC=84=A0=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=95=98=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 12 ++++++++++++ src/index.js | 10 ++++++++-- src/line-manager.js | 19 +++++++++++++++++++ src/line.js | 11 +++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 694afbd14..9527f99ab 100644 --- a/index.html +++ b/index.html @@ -47,6 +47,18 @@

🚇 지하철 노선도 관리

+
+
지하철 역 목록
+ + + + + + + + +
노선 이름상행 종점역하행 종점역설정
+
- + diff --git a/src/index.js b/src/index.js index 0776ca2ef..0c3ebe1fd 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ import Station from "./station.js"; import { addStationToList, isCorrectStationName } from "./station-manager.js"; import Line from "./line.js"; import { addLineToList } from "./line-manager.js"; +import { showLineList } from "./section-manager.js"; const btnStationManager = document.getElementById("station-manager-button"); const btnLineManager = document.getElementById("line-manager-button"); @@ -45,10 +46,10 @@ const setStationList = (stationList) => { btnLineManager.onclick = () => { makeResultBlock(1); setStationList(stationList); - // showLineList(lineList); }; btnSectionManager.onclick = () => { makeResultBlock(2); + showLineList(lineList); }; btnMapPrintManager.onclick = () => { makeResultBlock(3); @@ -70,6 +71,11 @@ btnAddStation.onclick = () => { const btnAddLine = document.getElementById("line-add-button"); let lineList = []; +for (let i = 0; i < 5; i++) { + const tmp = new Line(`${i}호선`); + tmp.addLine(new Station("오금"), new Station("길음")); + lineList.push(tmp); +} btnAddLine.onclick = () => { const newLineName = document.getElementById("line-name-input").value; const startStation = document.getElementById("line-start-station-selector") diff --git a/src/section-manager.js b/src/section-manager.js new file mode 100644 index 000000000..037ee3392 --- /dev/null +++ b/src/section-manager.js @@ -0,0 +1,11 @@ +export const showLineList = (lineList) => { + console.log(lineList); + lineList.forEach((line) => { + const lineMenuButton = document.createElement("button"); + const lineMenu = document.getElementById("section-line-list"); + lineMenuButton.setAttribute("class", "section-line-menu-button"); + lineMenuButton.setAttribute("id", `${line.name}`); + lineMenuButton.innerHTML = line.name; + lineMenu.appendChild(lineMenuButton); + }); +}; From 0dd0d14159523f8af0943c8768bcdfb9b8ea3fd4 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Wed, 9 Dec 2020 23:07:56 +0900 Subject: [PATCH 13/65] =?UTF-8?q?:bug:=20=EA=B5=AC=EA=B0=84=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20=EC=84=A0=ED=83=9D=20=ED=95=A0=20=EB=95=8C=EB=A7=88?= =?UTF-8?q?=EB=8B=A4=20=EB=A9=94=EB=89=B4=20=EB=8A=98=EC=96=B4=EB=82=98?= =?UTF-8?q?=EB=8A=94=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/section-manager.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/section-manager.js b/src/section-manager.js index 037ee3392..f1c614747 100644 --- a/src/section-manager.js +++ b/src/section-manager.js @@ -1,8 +1,9 @@ export const showLineList = (lineList) => { console.log(lineList); + const lineMenu = document.getElementById("section-line-list"); + lineMenu.innerHTML = ""; lineList.forEach((line) => { const lineMenuButton = document.createElement("button"); - const lineMenu = document.getElementById("section-line-list"); lineMenuButton.setAttribute("class", "section-line-menu-button"); lineMenuButton.setAttribute("id", `${line.name}`); lineMenuButton.innerHTML = line.name; From 9161607e0d8cebd8dd4f8d08c6dd913e94f0609e Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Thu, 10 Dec 2020 00:35:03 +0900 Subject: [PATCH 14/65] =?UTF-8?q?:sparkles:=20=EC=84=A0=ED=83=9D=ED=95=9C?= =?UTF-8?q?=20=EB=85=B8=EC=84=A0=EB=B3=84=20=EA=B4=80=EB=A6=AC=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20=EB=B3=B4=EC=97=AC=EC=A3=BC=EA=B8=B0=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 3 ++- src/section-manager.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index dd760895a..376762bb7 100644 --- a/index.html +++ b/index.html @@ -63,7 +63,8 @@

🚇 지하철 노선도 관리

diff --git a/src/index.js b/src/index.js index ba49d6293..abf3d24e6 100644 --- a/src/index.js +++ b/src/index.js @@ -9,10 +9,24 @@ import { addLineToList } from "./line-manager.js"; import { showLineList } from "./section-manager.js"; import { showMapList } from "./map-print-manager.js"; -export function ManageStationLine(lineList, stationList) { - this.lineList = lineList; - this.stationList = stationList; +export function ManageStationLine() { + this.lineList = []; + this.stationList = []; this.selectedLine = null; + this.addStationInList = (station) => { + this.stationList.push(station); + }; + this.addLineInList = (line) => { + this.lineList.push(line); + }; + this.getAllLineName = () => { + let lineNameList = []; + for (let i in lineList) { + lineNameList.push(this.lineList[i].name); + } + + return lineNameList; + }; this.setSelectedLine = (selectedLine) => { this.selectedLine = selectedLine; }; @@ -28,6 +42,8 @@ export function ManageStationLine(lineList, stationList) { }); }; } +export const manager = new ManageStationLine(); + const btnStationManager = document.getElementById("station-manager-button"); const btnLineManager = document.getElementById("line-manager-button"); const btnSectionManager = document.getElementById("section-manager-button"); @@ -72,7 +88,7 @@ btnLineManager.onclick = () => { }; btnSectionManager.onclick = () => { makeResultBlock(2); - showLineList(lineList); + showLineList(manager.lineList); }; btnMapPrintManager.onclick = () => { makeResultBlock(3); @@ -84,34 +100,26 @@ let stationList = [ new Station("혜화"), new Station("성신"), ]; +for (let i in stationList) { + manager.addStationInList(stationList[i]); +} + btnAddStation.onclick = () => { const newStationName = document.getElementById("station-name-input").value; if ( isCorrectStationName(newStationName) === true && isOverlappedStationName(newStationName) === false ) { - const station = new Station(newStationName); - stationList.push(station); addStationToList(newStationName); } }; -const btnAddLine = document.getElementById("line-add-button"); -let lineList = []; for (let i = 0; i < 5; i++) { const tmp = new Line(`${i}호선`); tmp.addLine(new Station("오금"), new Station("길음")); - lineList.push(tmp); + manager.addLineInList(tmp); } +const btnAddLine = document.getElementById("line-add-button"); btnAddLine.onclick = () => { - const newLineName = document.getElementById("line-name-input").value; - const startStation = document.getElementById("line-start-station-selector") - .value; - const endStation = document.getElementById("line-end-station-selector").value; - const line = new Line(newLineName); - line.addLine(new Station(startStation), new Station(endStation)); - lineList.push(line); - addLineToList(line); - console.log(lineList); + addLineToList(); }; -export const manager = new ManageStationLine(lineList, stationList); diff --git a/src/line-manager.js b/src/line-manager.js index c5979cde8..20a7f2774 100644 --- a/src/line-manager.js +++ b/src/line-manager.js @@ -1,4 +1,5 @@ import { manager } from "./index.js"; +import Line from "./line.js"; export const deleteLineInList = (lineName) => { const parent = document.querySelector("table#line-list-table tbody"); @@ -26,7 +27,6 @@ export const makeChildInLine = (line) => { deleteLineInList(`${line.name}`); }; deleteButton.innerHTML = "삭제"; - return [lineName, startStation, endStation, deleteButton]; }; export const makeLineBox = (line) => { @@ -43,9 +43,39 @@ export const makeLineBox = (line) => { return newLine; }; -export const addLineToList = (line) => { - const newLine = makeLineBox(line); - const table = document.getElementById("line-list-table"); - table.children[1].appendChild(newLine); +export const showLineToList = (lineList) => { + const table = document.getElementById("line-list"); + lineList.forEach((line) => { + const newLine = makeLineBox(line); + table.appendChild(newLine); + }); document.getElementById("line-name-input").value = ""; }; +export const isPossibleLine = (startName, endName) => { + if (startName === endName) { + alert("상행 종점과 다른 하행 종점을 선택 해주세요."); + + return false; + } + return true; +}; +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 (isPossibleLine(startStationName, endStationName)) { + const startStation = manager.stationList.find( + (station) => station.name === startStationName + ); + const endStation = manager.stationList.find( + (station) => station.name === endStationName + ); + const line = new Line(newLineName); + line.addLine(startStation, endStation); + manager.addLineInList(line); + showLineToList(manager.lineList); + } +}; From 79d341fd5309a166ce26a81ac2356439274107c2 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Fri, 11 Dec 2020 16:17:02 +0900 Subject: [PATCH 34/65] =?UTF-8?q?:construction:=20=EC=97=AD=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=EC=8B=9C=20manager=EA=B0=9D=EC=B2=B4=20=EB=82=B4?= =?UTF-8?q?=EC=97=90=EB=8F=84=20=EB=B0=98=EC=98=81=EB=90=98=EA=B2=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/station-manager.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/station-manager.js b/src/station-manager.js index 5271d52b9..220950aae 100644 --- a/src/station-manager.js +++ b/src/station-manager.js @@ -1,4 +1,5 @@ import { manager } from "./index.js"; +import Station from "./station.js"; export const isCorrectStationName = (newStationName) => { const rHangel = /^[0-9A-Za-z가-힣]*$/; @@ -49,6 +50,8 @@ export const makeStationBox = (newStationName) => { return newStation; }; export const addStationToList = (newStationName) => { + const station = new Station(newStationName); + manager.addStationInList(station); const newStation = makeStationBox(newStationName); const table = document.getElementById("staion-list-table"); table.children[1].appendChild(newStation); From 710ae2998e79f36e482041f56ea57a179f6063e5 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Fri, 11 Dec 2020 16:41:51 +0900 Subject: [PATCH 35/65] =?UTF-8?q?:sparkles:=20=EC=9D=B4=EB=AF=B8=20?= =?UTF-8?q?=EB=85=B8=EC=84=A0=EC=97=90=20=EB=93=B1=EB=A1=9D=EB=90=9C=20?= =?UTF-8?q?=EC=97=AD=EC=9D=80=20=EC=82=AD=EC=A0=9C=20=EB=AA=BB=ED=95=98?= =?UTF-8?q?=EA=B2=8C=20=ED=95=98=EB=8A=94=20=ED=95=A8=EC=88=98=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/station-manager.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/station-manager.js b/src/station-manager.js index 220950aae..19b365009 100644 --- a/src/station-manager.js +++ b/src/station-manager.js @@ -23,15 +23,27 @@ export const isOverlappedStationName = (newStationName) => { } return false; }; -export const deleteStationInList = (stationName) => { - const parent = document.querySelector("table#staion-list-table tbody"); - const deleteIdx = manager.stationList.findIndex((station) => { +export const isPossibleToDeleteStation = (stationName) => { + const deleteStation = manager.stationList.find((station) => { return station.name === stationName; }); - parent.removeChild( - document.querySelector(`table#staion-list-table tbody tr#${stationName}`) - ); - manager.stationList.splice(deleteIdx, 1); + if (deleteStation.isIncluded.length > 0) { + alert("이미 노선에 등록되어 있는 역입니다."); + return false; // 이미 노선에 등록되어있어서 삭제 불가 + } + return true; +}; +export const deleteStationInList = (stationName) => { + const parent = document.querySelector("table#staion-list-table tbody"); + if (isPossibleToDeleteStation(stationName)) { + const deleteIdx = manager.stationList.findIndex((station) => { + return station.name === stationName; + }); + parent.removeChild( + document.querySelector(`table#staion-list-table tbody tr#${stationName}`) + ); + manager.stationList.splice(deleteIdx, 1); + } }; export const makeStationBox = (newStationName) => { const newStation = document.createElement("tr"); @@ -56,4 +68,5 @@ export const addStationToList = (newStationName) => { const table = document.getElementById("staion-list-table"); table.children[1].appendChild(newStation); document.getElementById("station-name-input").value = ""; + console.log(manager.stationList); }; From c3652c19d3f1a851c74b8fe3753a17d0fd2ef34a Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Fri, 11 Dec 2020 17:02:19 +0900 Subject: [PATCH 36/65] =?UTF-8?q?:sparkles:=20station=20=EA=B0=9D=EC=B2=B4?= =?UTF-8?q?=EA=B0=80=20=ED=8F=AC=ED=95=A8=EB=90=9C=20=EB=85=B8=EC=84=A0?= =?UTF-8?q?=EC=9D=98=20=EC=86=8D=EC=84=B1=20=EB=B0=8F=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/station.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/station.js b/src/station.js index 2b2022f2a..ffb2e6f84 100644 --- a/src/station.js +++ b/src/station.js @@ -1,4 +1,14 @@ export default function Station(name) { this.name = name; this.next = null; + this.isIncluded = []; + this.addIncludedLine = (lineName) => { + this.isIncluded.push(lineName); + }; + this.deleteIncludedLine = (lineName) => { + const deleteIdx = this.isIncluded.findIndex( + (line) => line.name === lineName + ); + this.isIncluded.splice(deleteIdx, 1); + }; } From e0b4e93c259bd7c1b5dad992e0c79b9e91dce02c Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Fri, 11 Dec 2020 17:04:43 +0900 Subject: [PATCH 37/65] =?UTF-8?q?:sparkles:=20=EA=B5=AC=EA=B0=84=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=EC=97=90=EC=84=9C=20station=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EC=8B=9C=20=EC=84=A0=ED=83=9D=EB=90=9C=20=EB=85=B8?= =?UTF-8?q?=EC=84=A0=20=EC=82=AD=EC=A0=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/line.js | 11 +++++++++-- src/section-manager.js | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/line.js b/src/line.js index 383555588..2755dea90 100644 --- a/src/line.js +++ b/src/line.js @@ -8,6 +8,9 @@ export default function Line(name) { this.head = startStation; this.head.next = endStation; this.length += 2; + + startStation.addIncludedLine(this.name); + endStation.addIncludedLine(this.name); }; this.getStartStation = () => { return this.head.name; @@ -28,6 +31,7 @@ export default function Line(name) { current = current.next; } stationList.push(current.name); + return stationList; }; this.addStationInIdx = (station, idx) => { @@ -42,15 +46,18 @@ export default function Line(name) { currentStation.next = addStation; this.length++; manager.setChangedLine(this); + + station.addIncludedLine(this.name); }; - this.deleteStationInIdx = (idx) => { - // const deleteStation = station; + this.deleteStationInIdx = (idx, selectedLine) => { let currentIdx = 0; let currentStation = this.head; while (currentIdx < idx - 1) { currentStation = currentStation.next; currentIdx++; } + currentStation.next.deleteIncludedLine(selectedLine); + currentStation.next.next = null; currentStation.next = currentStation.next.next; this.length--; manager.setChangedLine(this); diff --git a/src/section-manager.js b/src/section-manager.js index 46717c923..5e5561ffb 100644 --- a/src/section-manager.js +++ b/src/section-manager.js @@ -5,9 +5,10 @@ export const deleteSectionInList = (idx) => { "station-in-selected-line" ); stationInSelecteLine.innerHTML = ""; - manager.selectedLine.deleteStationInIdx(idx); + manager.selectedLine.deleteStationInIdx(idx, manager.getSelectedLine().name); manager.setSelectedLine(manager.selectedLine); showStationList(manager.getSelectedLine().getAllStationName()); + console.log(manager.stationList); }; export const makeStationBox = (station, idx) => { const oneStation = document.createElement("tr"); @@ -89,4 +90,5 @@ btnAddSection.onclick = () => { const stationList = document.getElementById("station-in-selected-line"); stationList.innerHTML = ""; showStationList(manager.getSelectedLine().getAllStationName()); + console.log("등록 후stationList", manager.stationList); }; From ecfc1f189ca137709e122e2b7d89c1fbee1966fc Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Fri, 11 Dec 2020 19:29:48 +0900 Subject: [PATCH 38/65] =?UTF-8?q?:white=5Fcheck=5Fmark:=20test=20=EB=9D=BC?= =?UTF-8?q?=EC=9D=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/index.js b/src/index.js index abf3d24e6..e1e0856a8 100644 --- a/src/index.js +++ b/src/index.js @@ -5,8 +5,8 @@ import { isOverlappedStationName, } from "./station-manager.js"; import Line from "./line.js"; -import { addLineToList } from "./line-manager.js"; -import { showLineList } from "./section-manager.js"; +import { addLineToList, showAllLineInLineManager } from "./line-manager.js"; +import { showLineMenuInSectionManager } from "./section-manager.js"; import { showMapList } from "./map-print-manager.js"; export function ManageStationLine() { @@ -35,7 +35,6 @@ export function ManageStationLine() { }; this.setChangedLine = (changedLine) => { this.lineList.forEach((line) => { - console.log(line.name, changedLine.name); if (line.name === changedLine.name) { line = changedLine; } @@ -83,12 +82,15 @@ export const makeStationOption = (stationList, optionName) => { }; btnLineManager.onclick = () => { makeResultBlock(1); + console.log(manager.stationList); + console.log(manager.lineList); makeStationOption(stationList, "line-start-station-selector"); makeStationOption(stationList, "line-end-station-selector"); + showAllLineInLineManager(manager.lineList); }; btnSectionManager.onclick = () => { makeResultBlock(2); - showLineList(manager.lineList); + showLineMenuInSectionManager(manager.lineList); }; btnMapPrintManager.onclick = () => { makeResultBlock(3); @@ -96,9 +98,10 @@ btnMapPrintManager.onclick = () => { }; const btnAddStation = document.getElementById("station-add-button"); let stationList = [ - new Station("길음"), + new Station("잠실"), new Station("혜화"), new Station("성신"), + new Station("강남"), ]; for (let i in stationList) { manager.addStationInList(stationList[i]); @@ -114,11 +117,16 @@ btnAddStation.onclick = () => { } }; -for (let i = 0; i < 5; i++) { - const tmp = new Line(`${i}호선`); - tmp.addLine(new Station("오금"), new Station("길음")); - manager.addLineInList(tmp); -} +const tmp = new Line("2호선"); +tmp.addLine(new Station("잠실"), new Station("신림")); +manager.addLineInList(tmp); +const tmp2 = new Line("3호선"); +tmp2.addLine(new Station("오금"), new Station("대화")); +manager.addLineInList(tmp2); +const tmp3 = new Line("4호선"); +tmp3.addLine(new Station("당고개"), new Station("오이도")); +manager.addLineInList(tmp3); + const btnAddLine = document.getElementById("line-add-button"); btnAddLine.onclick = () => { addLineToList(); From 5f9e3912287661c86d1c5fdd54f979fe784321b9 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Fri, 11 Dec 2020 19:37:45 +0900 Subject: [PATCH 39/65] =?UTF-8?q?:construction:=20=ED=95=98=EB=82=98?= =?UTF-8?q?=EC=9D=98=20=EC=97=AD=20=EA=B0=9D=EC=B2=B4=EB=8A=94=20=ED=95=98?= =?UTF-8?q?=EB=82=98=EC=9D=98=20=EB=93=B1=EB=A1=9D=EB=90=9C=20=EB=85=B8?= =?UTF-8?q?=EC=84=A0=EC=9D=84=20=EA=B0=96=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/line-manager.js | 18 ++++++------------ src/station.js | 4 ++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/line-manager.js b/src/line-manager.js index 20a7f2774..929791d53 100644 --- a/src/line-manager.js +++ b/src/line-manager.js @@ -1,5 +1,6 @@ import { manager } from "./index.js"; import Line from "./line.js"; +import Station from "./station.js"; export const deleteLineInList = (lineName) => { const parent = document.querySelector("table#line-list-table tbody"); @@ -9,9 +10,7 @@ export const deleteLineInList = (lineName) => { parent.removeChild( document.querySelector(`table#line-list-table tbody tr#${lineName}`) ); - console.log(manager.lineList); manager.lineList.splice(deleteIdx, 1); - console.log(manager.lineList); }; export const makeChildInLine = (line) => { const lineName = document.createElement("td"); @@ -43,8 +42,9 @@ export const makeLineBox = (line) => { return newLine; }; -export const showLineToList = (lineList) => { +export const showAllLineInLineManager = (lineList) => { const table = document.getElementById("line-list"); + table.innerHTML = ""; lineList.forEach((line) => { const newLine = makeLineBox(line); table.appendChild(newLine); @@ -67,15 +67,9 @@ export const addLineToList = () => { const endStationName = document.getElementById("line-end-station-selector") .value; if (isPossibleLine(startStationName, endStationName)) { - const startStation = manager.stationList.find( - (station) => station.name === startStationName - ); - const endStation = manager.stationList.find( - (station) => station.name === endStationName - ); const line = new Line(newLineName); - line.addLine(startStation, endStation); - manager.addLineInList(line); - showLineToList(manager.lineList); + line.addLine(new Station(startStationName), new Station(endStationName)); + manager.setLineInManager(line); + showAllLineInLineManager(manager.lineList); } }; diff --git a/src/station.js b/src/station.js index ffb2e6f84..26fc19a5c 100644 --- a/src/station.js +++ b/src/station.js @@ -1,9 +1,9 @@ export default function Station(name) { this.name = name; this.next = null; - this.isIncluded = []; + this.isIncluded = null; this.addIncludedLine = (lineName) => { - this.isIncluded.push(lineName); + this.isIncluded = lineName; }; this.deleteIncludedLine = (lineName) => { const deleteIdx = this.isIncluded.findIndex( From 33ffc27beddc930b00d557d85a76afd469be6984 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Fri, 11 Dec 2020 19:42:09 +0900 Subject: [PATCH 40/65] =?UTF-8?q?:construction:=20manager=20=EA=B0=9D?= =?UTF-8?q?=EC=B2=B4=20index.js=EC=97=90=EC=84=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 43 +++++----------------------------------- src/line-manager.js | 2 +- src/line.js | 2 +- src/manager.js | 33 ++++++++++++++++++++++++++++++ src/map-print-manager.js | 2 +- src/section-manager.js | 7 +++---- src/station-manager.js | 4 ++-- 7 files changed, 46 insertions(+), 47 deletions(-) create mode 100644 src/manager.js diff --git a/src/index.js b/src/index.js index e1e0856a8..6c890011f 100644 --- a/src/index.js +++ b/src/index.js @@ -8,40 +8,7 @@ import Line from "./line.js"; import { addLineToList, showAllLineInLineManager } from "./line-manager.js"; import { showLineMenuInSectionManager } from "./section-manager.js"; import { showMapList } from "./map-print-manager.js"; - -export function ManageStationLine() { - this.lineList = []; - this.stationList = []; - this.selectedLine = null; - this.addStationInList = (station) => { - this.stationList.push(station); - }; - this.addLineInList = (line) => { - this.lineList.push(line); - }; - this.getAllLineName = () => { - let lineNameList = []; - for (let i in lineList) { - lineNameList.push(this.lineList[i].name); - } - - return lineNameList; - }; - this.setSelectedLine = (selectedLine) => { - this.selectedLine = selectedLine; - }; - this.getSelectedLine = () => { - return this.selectedLine; - }; - this.setChangedLine = (changedLine) => { - this.lineList.forEach((line) => { - if (line.name === changedLine.name) { - line = changedLine; - } - }); - }; -} -export const manager = new ManageStationLine(); +import { manager } from "./manager.js"; const btnStationManager = document.getElementById("station-manager-button"); const btnLineManager = document.getElementById("line-manager-button"); @@ -104,7 +71,7 @@ let stationList = [ new Station("강남"), ]; for (let i in stationList) { - manager.addStationInList(stationList[i]); + manager.setStationInManager(stationList[i]); } btnAddStation.onclick = () => { @@ -119,13 +86,13 @@ btnAddStation.onclick = () => { const tmp = new Line("2호선"); tmp.addLine(new Station("잠실"), new Station("신림")); -manager.addLineInList(tmp); +manager.setLineInManager(tmp); const tmp2 = new Line("3호선"); tmp2.addLine(new Station("오금"), new Station("대화")); -manager.addLineInList(tmp2); +manager.setLineInManager(tmp2); const tmp3 = new Line("4호선"); tmp3.addLine(new Station("당고개"), new Station("오이도")); -manager.addLineInList(tmp3); +manager.setLineInManager(tmp3); const btnAddLine = document.getElementById("line-add-button"); btnAddLine.onclick = () => { diff --git a/src/line-manager.js b/src/line-manager.js index 929791d53..28d492e18 100644 --- a/src/line-manager.js +++ b/src/line-manager.js @@ -1,4 +1,4 @@ -import { manager } from "./index.js"; +import { manager } from "./manager.js"; import Line from "./line.js"; import Station from "./station.js"; diff --git a/src/line.js b/src/line.js index 2755dea90..abaccfa05 100644 --- a/src/line.js +++ b/src/line.js @@ -1,4 +1,4 @@ -import { manager } from "./index.js"; +import { manager } from "./manager.js"; export default function Line(name) { this.name = name; diff --git a/src/manager.js b/src/manager.js new file mode 100644 index 000000000..6859df1b2 --- /dev/null +++ b/src/manager.js @@ -0,0 +1,33 @@ +export function Manager() { + this.lineList = []; + this.stationList = []; + this.selectedLine = null; + this.setStationInManager = (station) => { + this.stationList.push(station); + }; + this.setLineInManager = (line) => { + this.lineList.push(line); + }; + this.getAllLineName = () => { + let lineNameList = []; + for (let i in lineList) { + lineNameList.push(this.lineList[i].name); + } + + return lineNameList; + }; + this.setSelectedLine = (selectedLine) => { + this.selectedLine = selectedLine; + }; + this.getSelectedLine = () => { + return this.selectedLine; + }; + this.setChangedLine = (changedLine) => { + this.lineList.forEach((line) => { + if (line.name === changedLine.name) { + line = changedLine; + } + }); + }; +} +export const manager = new Manager(); diff --git a/src/map-print-manager.js b/src/map-print-manager.js index 78be18184..5be0bc955 100644 --- a/src/map-print-manager.js +++ b/src/map-print-manager.js @@ -1,4 +1,4 @@ -import { manager } from "./index.js"; +import { manager } from "./manager.js"; export const showLineTitleInMap = (lineName) => { const lineNameBox = document.createElement("div"); diff --git a/src/section-manager.js b/src/section-manager.js index 5e5561ffb..35987c2da 100644 --- a/src/section-manager.js +++ b/src/section-manager.js @@ -1,4 +1,5 @@ -import { manager, makeStationOption } from "./index.js"; +import { makeStationOption } from "./index.js"; +import { manager } from "./manager.js"; export const deleteSectionInList = (idx) => { const stationInSelecteLine = document.getElementById( @@ -8,7 +9,6 @@ export const deleteSectionInList = (idx) => { manager.selectedLine.deleteStationInIdx(idx, manager.getSelectedLine().name); manager.setSelectedLine(manager.selectedLine); showStationList(manager.getSelectedLine().getAllStationName()); - console.log(manager.stationList); }; export const makeStationBox = (station, idx) => { const oneStation = document.createElement("tr"); @@ -67,7 +67,7 @@ export const makeLineButton = (line) => { return lineMenuButton; }; -export const showLineList = (lineList) => { +export const showLineMenuInSectionManager = (lineList) => { const lineMenu = document.getElementById("section-line-list"); lineMenu.innerHTML = ""; lineList.forEach((line) => { @@ -90,5 +90,4 @@ btnAddSection.onclick = () => { const stationList = document.getElementById("station-in-selected-line"); stationList.innerHTML = ""; showStationList(manager.getSelectedLine().getAllStationName()); - console.log("등록 후stationList", manager.stationList); }; diff --git a/src/station-manager.js b/src/station-manager.js index 19b365009..4e20ab749 100644 --- a/src/station-manager.js +++ b/src/station-manager.js @@ -1,4 +1,4 @@ -import { manager } from "./index.js"; +import { manager } from "./manager.js"; import Station from "./station.js"; export const isCorrectStationName = (newStationName) => { @@ -63,7 +63,7 @@ export const makeStationBox = (newStationName) => { }; export const addStationToList = (newStationName) => { const station = new Station(newStationName); - manager.addStationInList(station); + manager.setStationInManager(station); const newStation = makeStationBox(newStationName); const table = document.getElementById("staion-list-table"); table.children[1].appendChild(newStation); From 9f17c2bb1ba403cb5d127a00a83515f92e650c6b Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Fri, 11 Dec 2020 20:39:49 +0900 Subject: [PATCH 41/65] =?UTF-8?q?:construction:=20=EC=97=AD=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=EC=8B=9C=20=EC=83=88=EB=A1=9C=EC=9A=B4=20station?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EC=83=9D=EC=84=B1=ED=95=98=EA=B2=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 2 +- src/index.js | 46 +++++++++++++++++++----------------------- src/section-manager.js | 14 ++++++------- src/station-manager.js | 15 +++++++++----- 4 files changed, 39 insertions(+), 38 deletions(-) diff --git a/index.html b/index.html index f9e5ed1d6..7b7744d1d 100644 --- a/index.html +++ b/index.html @@ -29,7 +29,7 @@

🚇 지하철 노선도 관리

역 이름 설정 - + diff --git a/src/index.js b/src/index.js index 6c890011f..c7874ed01 100644 --- a/src/index.js +++ b/src/index.js @@ -3,6 +3,7 @@ import { addStationToList, isCorrectStationName, isOverlappedStationName, + showAllStationInManager, } from "./station-manager.js"; import Line from "./line.js"; import { addLineToList, showAllLineInLineManager } from "./line-manager.js"; @@ -26,6 +27,22 @@ const resultList = [ resultSectionManager, resultMapPrintManager, ]; + +const tmp = new Line("2호선"); +const tmp2 = new Station("잠실"); +const tmp3 = new Station("신림"); +tmp.addLine(tmp2, tmp3); +manager.setStationInManager(tmp2); +manager.setStationInManager(tmp3); +manager.setLineInManager(tmp); +const tmp4 = new Line("3호선"); +const tmp5 = new Station("대화"); +const tmp6 = new Station("오금"); +tmp4.addLine(tmp5, tmp6); +manager.setStationInManager(tmp5); +manager.setStationInManager(tmp6); +manager.setLineInManager(tmp4); + const makeResultBlock = (idx) => { for (let i in resultList) { if (i == idx) { @@ -35,8 +52,10 @@ const makeResultBlock = (idx) => { } } }; +showAllStationInManager(manager.stationList); btnStationManager.onclick = () => { makeResultBlock(0); + showAllStationInManager(manager.stationList); }; export const makeStationOption = (stationList, optionName) => { const optionList = document.getElementById(optionName); @@ -49,10 +68,8 @@ export const makeStationOption = (stationList, optionName) => { }; btnLineManager.onclick = () => { makeResultBlock(1); - console.log(manager.stationList); - console.log(manager.lineList); - makeStationOption(stationList, "line-start-station-selector"); - makeStationOption(stationList, "line-end-station-selector"); + makeStationOption(manager.stationList, "line-start-station-selector"); + makeStationOption(manager.stationList, "line-end-station-selector"); showAllLineInLineManager(manager.lineList); }; btnSectionManager.onclick = () => { @@ -64,16 +81,6 @@ btnMapPrintManager.onclick = () => { showMapList(); }; const btnAddStation = document.getElementById("station-add-button"); -let stationList = [ - new Station("잠실"), - new Station("혜화"), - new Station("성신"), - new Station("강남"), -]; -for (let i in stationList) { - manager.setStationInManager(stationList[i]); -} - btnAddStation.onclick = () => { const newStationName = document.getElementById("station-name-input").value; if ( @@ -83,17 +90,6 @@ btnAddStation.onclick = () => { addStationToList(newStationName); } }; - -const tmp = new Line("2호선"); -tmp.addLine(new Station("잠실"), new Station("신림")); -manager.setLineInManager(tmp); -const tmp2 = new Line("3호선"); -tmp2.addLine(new Station("오금"), new Station("대화")); -manager.setLineInManager(tmp2); -const tmp3 = new Line("4호선"); -tmp3.addLine(new Station("당고개"), new Station("오이도")); -manager.setLineInManager(tmp3); - const btnAddLine = document.getElementById("line-add-button"); btnAddLine.onclick = () => { addLineToList(); diff --git a/src/section-manager.js b/src/section-manager.js index 35987c2da..156b75c8a 100644 --- a/src/section-manager.js +++ b/src/section-manager.js @@ -1,5 +1,6 @@ import { makeStationOption } from "./index.js"; import { manager } from "./manager.js"; +import Station from "./station.js"; export const deleteSectionInList = (idx) => { const stationInSelecteLine = document.getElementById( @@ -80,13 +81,12 @@ btnAddSection.onclick = () => { const addSectionIdx = document.getElementById("section-order-input").value; const addStationName = document.getElementById("section-station-selector") .value; - manager.stationList.forEach((station) => { - if (station.name === addStationName) { - const selectedLine = manager.getSelectedLine(); - console.log(selectedLine); - selectedLine.addStationInIdx(station, addSectionIdx); - } - }); + const selectedLine = manager.getSelectedLine(); + const inputStation = new Station(addStationName); + inputStation.addIncludedLine(selectedLine.name); + manager.setStationInManager(inputStation); + selectedLine.addStationInIdx(inputStation, addSectionIdx); + const stationList = document.getElementById("station-in-selected-line"); stationList.innerHTML = ""; showStationList(manager.getSelectedLine().getAllStationName()); diff --git a/src/station-manager.js b/src/station-manager.js index 4e20ab749..9f0c68ef1 100644 --- a/src/station-manager.js +++ b/src/station-manager.js @@ -61,12 +61,17 @@ export const makeStationBox = (newStationName) => { return newStation; }; +export const showAllStationInManager = (stationList) => { + const table = document.getElementById("station-list"); + table.innerHTML = ""; + stationList.forEach((station) => { + const newStation = makeStationBox(station.name); + table.appendChild(newStation); + }); + document.getElementById("station-name-input").value = ""; +}; export const addStationToList = (newStationName) => { const station = new Station(newStationName); manager.setStationInManager(station); - const newStation = makeStationBox(newStationName); - const table = document.getElementById("staion-list-table"); - table.children[1].appendChild(newStation); - document.getElementById("station-name-input").value = ""; - console.log(manager.stationList); + showAllStationInManager(manager.stationList); }; From 0d5e8aa61571fbc696056766d7f4f3d3e520f095 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Fri, 11 Dec 2020 20:47:50 +0900 Subject: [PATCH 42/65] =?UTF-8?q?:sparkles:=20=EC=97=AD=EA=B4=80=EB=A6=AC?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=97=AD=20=EC=82=AD=EC=A0=9C=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/station-manager.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/station-manager.js b/src/station-manager.js index 9f0c68ef1..2c048ddee 100644 --- a/src/station-manager.js +++ b/src/station-manager.js @@ -27,7 +27,7 @@ export const isPossibleToDeleteStation = (stationName) => { const deleteStation = manager.stationList.find((station) => { return station.name === stationName; }); - if (deleteStation.isIncluded.length > 0) { + if (deleteStation.isIncluded !== null) { alert("이미 노선에 등록되어 있는 역입니다."); return false; // 이미 노선에 등록되어있어서 삭제 불가 } @@ -37,10 +37,12 @@ export const deleteStationInList = (stationName) => { const parent = document.querySelector("table#staion-list-table tbody"); if (isPossibleToDeleteStation(stationName)) { const deleteIdx = manager.stationList.findIndex((station) => { - return station.name === stationName; + return station.name === stationName && station.isIncluded === null; }); parent.removeChild( - document.querySelector(`table#staion-list-table tbody tr#${stationName}`) + document.querySelector( + `table#staion-list-table tbody tr#${stationName}-null` + ) ); manager.stationList.splice(deleteIdx, 1); } @@ -49,7 +51,7 @@ export const makeStationBox = (newStationName) => { const newStation = document.createElement("tr"); const stationName = document.createElement("td"); const deleteButton = document.createElement("td"); - newStation.setAttribute("id", `${newStationName}`); + newStation.setAttribute("id", `${newStationName}-null`); stationName.innerHTML = newStationName; deleteButton.setAttribute("class", "station-delete-class"); deleteButton.onclick = () => { From 41f588b4d991e8ca0b518d38e4586d10fa3559db Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Fri, 11 Dec 2020 21:30:48 +0900 Subject: [PATCH 43/65] =?UTF-8?q?:sparkles:=20=EB=85=B8=EC=84=A0=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=EC=97=90=EC=84=9C=20=EB=85=B8=EC=84=A0=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EC=8B=9C=20=EC=97=AD=EB=8F=84=20=EA=B0=99=EC=9D=B4?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/line-manager.js | 12 ++++++++---- src/line.js | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/line-manager.js b/src/line-manager.js index 28d492e18..460ddc31a 100644 --- a/src/line-manager.js +++ b/src/line-manager.js @@ -7,9 +7,8 @@ export const deleteLineInList = (lineName) => { const deleteIdx = manager.lineList.findIndex((line) => { return line.name === lineName; }); - parent.removeChild( - document.querySelector(`table#line-list-table tbody tr#${lineName}`) - ); + manager.lineList[deleteIdx].deleteAllStationInLine(); + parent.removeChild(document.querySelector(`tbody#line-list tr#${lineName}`)); manager.lineList.splice(deleteIdx, 1); }; export const makeChildInLine = (line) => { @@ -26,6 +25,7 @@ export const makeChildInLine = (line) => { deleteLineInList(`${line.name}`); }; deleteButton.innerHTML = "삭제"; + return [lineName, startStation, endStation, deleteButton]; }; export const makeLineBox = (line) => { @@ -68,7 +68,11 @@ export const addLineToList = () => { .value; if (isPossibleLine(startStationName, endStationName)) { const line = new Line(newLineName); - line.addLine(new Station(startStationName), new Station(endStationName)); + 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); } diff --git a/src/line.js b/src/line.js index abaccfa05..880cefbb2 100644 --- a/src/line.js +++ b/src/line.js @@ -62,4 +62,19 @@ export default function Line(name) { this.length--; manager.setChangedLine(this); }; + this.deleteOneStationInLine = (current) => { + const deleteIdx = manager.stationList.findIndex( + (station) => + station.name === current.name && station.isIncluded === this.name + ); + manager.stationList.splice(deleteIdx, 1); + }; + this.deleteAllStationInLine = () => { + let current = this.head; + while (current.next !== null) { + this.deleteOneStationInLine(current); + current = current.next; // 마지막 전까지 지우기 + } + this.deleteOneStationInLine(current); // 마지막 역 지우기 + }; } From f75eda0530097ab25748712b32c61d2e870b789e Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Fri, 11 Dec 2020 21:39:18 +0900 Subject: [PATCH 44/65] =?UTF-8?q?:sparkles:=20=EA=B5=AC=EA=B0=84=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=EC=97=90=EC=84=9C=20=EC=97=AD=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=8B=A4=EC=8B=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/line.js | 3 +-- src/station.js | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/line.js b/src/line.js index 880cefbb2..580da0353 100644 --- a/src/line.js +++ b/src/line.js @@ -56,8 +56,7 @@ export default function Line(name) { currentStation = currentStation.next; currentIdx++; } - currentStation.next.deleteIncludedLine(selectedLine); - currentStation.next.next = null; + this.deleteOneStationInLine(currentStation.next); currentStation.next = currentStation.next.next; this.length--; manager.setChangedLine(this); diff --git a/src/station.js b/src/station.js index 26fc19a5c..fc03f01d1 100644 --- a/src/station.js +++ b/src/station.js @@ -5,10 +5,4 @@ export default function Station(name) { this.addIncludedLine = (lineName) => { this.isIncluded = lineName; }; - this.deleteIncludedLine = (lineName) => { - const deleteIdx = this.isIncluded.findIndex( - (line) => line.name === lineName - ); - this.isIncluded.splice(deleteIdx, 1); - }; } From 5e77b3b9f0740cf36821da525ff10bf649ae58a0 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Fri, 11 Dec 2020 22:27:25 +0900 Subject: [PATCH 45/65] =?UTF-8?q?:sparkles:=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=EB=90=9C=20stationList=20=EB=B3=B4=EC=97=AC?= =?UTF-8?q?=EC=A3=BC=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 38 ++++++++++++++++++++++++++++++++------ src/station-manager.js | 3 ++- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index c7874ed01..ab47d8c89 100644 --- a/src/index.js +++ b/src/index.js @@ -55,21 +55,47 @@ const makeResultBlock = (idx) => { showAllStationInManager(manager.stationList); btnStationManager.onclick = () => { makeResultBlock(0); - showAllStationInManager(manager.stationList); + showAllStationInManager(makeStationList()); }; -export const makeStationOption = (stationList, optionName) => { +export const makeStationList = () => { + const finalStationList = []; + const nowStationList = manager.stationList; + const stationName = []; + nowStationList.forEach((station) => { + stationName.push(station.name); + }); + const stationNameSet = Array.from(new Set(stationName)); + stationNameSet.forEach((name) => { + const sameName = nowStationList.filter( + (station) => station.name === name && station.isIncluded !== null + ); + if (sameName.length === 0) { + finalStationList.push( + nowStationList.filter( + (station) => station.name === name && station.isIncluded === null + )[0] + ); + } else { + finalStationList.push(sameName[0]); + } + }); + return finalStationList; +}; +export const makeStationOption = (optionStationList, optionName) => { const optionList = document.getElementById(optionName); optionList.innerHTML = ""; // 선택 노선 변경 시 지하철 역 새로 load - for (let idx in stationList) { + console.log(optionStationList); + for (let idx in optionStationList) { const newOption = document.createElement("option"); - newOption.innerHTML = stationList[idx].name; + newOption.innerHTML = optionStationList[idx].name; optionList.appendChild(newOption); } }; btnLineManager.onclick = () => { makeResultBlock(1); - makeStationOption(manager.stationList, "line-start-station-selector"); - makeStationOption(manager.stationList, "line-end-station-selector"); + const optionStationList = makeStationList(); + makeStationOption(optionStationList, "line-start-station-selector"); + makeStationOption(optionStationList, "line-end-station-selector"); showAllLineInLineManager(manager.lineList); }; btnSectionManager.onclick = () => { diff --git a/src/station-manager.js b/src/station-manager.js index 2c048ddee..d027acac5 100644 --- a/src/station-manager.js +++ b/src/station-manager.js @@ -1,5 +1,6 @@ import { manager } from "./manager.js"; import Station from "./station.js"; +import { makeStationList } from "./index.js"; export const isCorrectStationName = (newStationName) => { const rHangel = /^[0-9A-Za-z가-힣]*$/; @@ -75,5 +76,5 @@ export const showAllStationInManager = (stationList) => { export const addStationToList = (newStationName) => { const station = new Station(newStationName); manager.setStationInManager(station); - showAllStationInManager(manager.stationList); + showAllStationInManager(makeStationList()); }; From 7ae8b4f1c8dfcd2f41d71b5b68ae4b40ee03267d Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Fri, 11 Dec 2020 22:35:44 +0900 Subject: [PATCH 46/65] =?UTF-8?q?:bug:=20=EC=A4=91=EB=B3=B5=20=EB=85=B8?= =?UTF-8?q?=EC=84=A0=20=EB=93=B1=EB=A1=9D=20=EB=B6=88=EA=B0=80=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=A1=B0=EA=B1=B4=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 4 ++-- src/line-manager.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index ab47d8c89..d6ba095ab 100644 --- a/src/index.js +++ b/src/index.js @@ -110,8 +110,8 @@ const btnAddStation = document.getElementById("station-add-button"); btnAddStation.onclick = () => { const newStationName = document.getElementById("station-name-input").value; if ( - isCorrectStationName(newStationName) === true && - isOverlappedStationName(newStationName) === false + isCorrectStationName(newStationName) && + !isOverlappedStationName(newStationName) ) { addStationToList(newStationName); } diff --git a/src/line-manager.js b/src/line-manager.js index 460ddc31a..d3182956a 100644 --- a/src/line-manager.js +++ b/src/line-manager.js @@ -59,6 +59,18 @@ export const isPossibleLine = (startName, endName) => { } return true; }; +export const isOverlappedLineName = (newLineName) => { + const overlappedName = manager.lineList.find( + (line) => line.name === newLineName + ); + if (overlappedName) { + alert("이미 등록된 노선입니다."); + document.getElementById("line-name-input").value = ""; + + return true; + } + return false; +}; export const addLineToList = () => { const newLineName = document.getElementById("line-name-input").value; const startStationName = document.getElementById( @@ -66,7 +78,10 @@ export const addLineToList = () => { ).value; const endStationName = document.getElementById("line-end-station-selector") .value; - if (isPossibleLine(startStationName, endStationName)) { + if ( + isPossibleLine(startStationName, endStationName) && + !isOverlappedLineName(newLineName) + ) { const line = new Line(newLineName); const startStation = new Station(startStationName); const endStation = new Station(endStationName); From bc10cfc7cb7705ce2cc3e8aaa68397a469246d13 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sat, 12 Dec 2020 22:45:51 +0900 Subject: [PATCH 47/65] =?UTF-8?q?:bug:=20=EA=B5=AC=EA=B0=84=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20input=20Index=20=EC=98=AC=EB=B0=94=EB=A5=B8?= =?UTF-8?q?=EC=A7=80=20=EC=B2=B4=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/section-manager.js | 47 ++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/section-manager.js b/src/section-manager.js index 156b75c8a..85f06b42e 100644 --- a/src/section-manager.js +++ b/src/section-manager.js @@ -1,4 +1,4 @@ -import { makeStationOption } from "./index.js"; +import { makeStationOption, makeStationList } from "./index.js"; import { manager } from "./manager.js"; import Station from "./station.js"; @@ -50,7 +50,7 @@ export const onClickedLine = (lineName) => { sectionManagerTitle.innerHTML = `${selectedLineName} 관리`; const stationListBox = document.getElementById("station-in-selected-line"); stationListBox.innerHTML = ""; // 선택 노선 변경 시 역 계속 나열 안되게 초기화 - makeStationOption(manager.stationList, "section-station-selector"); + makeStationOption(makeStationList(), "section-station-selector"); const selectedLine = manager.lineList.find( (line) => line.name === selectedLineName ); @@ -76,18 +76,39 @@ export const showLineMenuInSectionManager = (lineList) => { lineMenu.appendChild(lineMenuButton); }); }; +export const isCorrectAddIdx = (idx, addSectionIdx) => { + if ( + idx > 0 && + idx < manager.getSelectedLine().length && + !isNaN(idx) && + idx % 10 === 0 + ) { + return true; + } else { + alert("올바른 구간 번호를 입력하세요"); + addSectionIdx.value = ""; + makeStationOption(makeStationList(), "section-station-selector"); + + return false; + } +}; const btnAddSection = document.getElementById("section-add-button"); btnAddSection.onclick = () => { - const addSectionIdx = document.getElementById("section-order-input").value; - const addStationName = document.getElementById("section-station-selector") - .value; - const selectedLine = manager.getSelectedLine(); - const inputStation = new Station(addStationName); - inputStation.addIncludedLine(selectedLine.name); - manager.setStationInManager(inputStation); - selectedLine.addStationInIdx(inputStation, addSectionIdx); + const addSectionIdx = document.getElementById("section-order-input"); + const inputIdx = addSectionIdx.value; + if (isCorrectAddIdx(inputIdx, addSectionIdx)) { + const addStationName = document.getElementById("section-station-selector") + .value; + const selectedLine = manager.getSelectedLine(); + const inputStation = new Station(addStationName); + inputStation.addIncludedLine(selectedLine.name); + manager.setStationInManager(inputStation); + selectedLine.addStationInIdx(inputStation, addSectionIdx); - const stationList = document.getElementById("station-in-selected-line"); - stationList.innerHTML = ""; - showStationList(manager.getSelectedLine().getAllStationName()); + const stationList = document.getElementById("station-in-selected-line"); + stationList.innerHTML = ""; + showStationList(manager.getSelectedLine().getAllStationName()); + addSectionIdx.value = ""; + makeStationOption(makeStationList(), "section-station-selector"); + } }; From de5d6888bd550131d22e210dea5f2c7e3b1a2112 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sat, 12 Dec 2020 23:05:44 +0900 Subject: [PATCH 48/65] =?UTF-8?q?:sparkles:=20=EC=A2=85=EC=A0=90=EC=9D=84?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0=ED=95=A0=20=EC=85=A9=EC=9A=B0=20=EB=8B=A4?= =?UTF-8?q?=EC=9D=8C=20=EC=97=AD=20=EC=A2=85=EC=A0=90=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/line.js | 16 ++++++++++------ src/section-manager.js | 26 ++++++++++++++++++-------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/line.js b/src/line.js index 580da0353..55f62b649 100644 --- a/src/line.js +++ b/src/line.js @@ -49,15 +49,19 @@ export default function Line(name) { station.addIncludedLine(this.name); }; - this.deleteStationInIdx = (idx, selectedLine) => { + this.deleteStationInIdx = (idx) => { let currentIdx = 0; let currentStation = this.head; - while (currentIdx < idx - 1) { - currentStation = currentStation.next; - currentIdx++; + if (idx === "0") { + this.head = currentStation.next; + } else { + while (currentIdx < idx - 1) { + currentStation = currentStation.next; + currentIdx++; + } + this.deleteOneStationInLine(currentStation.next); + currentStation.next = currentStation.next.next; } - this.deleteOneStationInLine(currentStation.next); - currentStation.next = currentStation.next.next; this.length--; manager.setChangedLine(this); }; diff --git a/src/section-manager.js b/src/section-manager.js index 85f06b42e..59d4d9c26 100644 --- a/src/section-manager.js +++ b/src/section-manager.js @@ -2,14 +2,24 @@ import { makeStationOption, makeStationList } from "./index.js"; import { manager } from "./manager.js"; import Station from "./station.js"; +export const isPossibleDeleteIdx = () => { + if (manager.getSelectedLine().length <= 2) { + alert("더 이상 지하철 역을 제거 할 수 없습니다."); + + return false; + } + return true; +}; export const deleteSectionInList = (idx) => { - const stationInSelecteLine = document.getElementById( - "station-in-selected-line" - ); - stationInSelecteLine.innerHTML = ""; - manager.selectedLine.deleteStationInIdx(idx, manager.getSelectedLine().name); - manager.setSelectedLine(manager.selectedLine); - showStationList(manager.getSelectedLine().getAllStationName()); + if (isPossibleDeleteIdx()) { + const stationInSelecteLine = document.getElementById( + "station-in-selected-line" + ); + stationInSelecteLine.innerHTML = ""; + manager.getSelectedLine().deleteStationInIdx(idx); + manager.setSelectedLine(manager.selectedLine); + showStationList(manager.getSelectedLine().getAllStationName()); + } }; export const makeStationBox = (station, idx) => { const oneStation = document.createElement("tr"); @@ -81,7 +91,7 @@ export const isCorrectAddIdx = (idx, addSectionIdx) => { idx > 0 && idx < manager.getSelectedLine().length && !isNaN(idx) && - idx % 10 === 0 + Number.isInteger(Number(idx)) ) { return true; } else { From c487e22ebea82c0846b19666cbf25936a7031b4f Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sat, 12 Dec 2020 23:22:28 +0900 Subject: [PATCH 49/65] =?UTF-8?q?:bug:=20=EB=85=B8=EC=84=A0=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=202=EA=B8=80=EC=9E=90=20=EC=9D=B4=EC=83=81=EC=9D=B8?= =?UTF-8?q?=EC=A7=80=20=EC=B2=B4=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/line-manager.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/line-manager.js b/src/line-manager.js index d3182956a..c1a1b4990 100644 --- a/src/line-manager.js +++ b/src/line-manager.js @@ -8,7 +8,7 @@ export const deleteLineInList = (lineName) => { return line.name === lineName; }); manager.lineList[deleteIdx].deleteAllStationInLine(); - parent.removeChild(document.querySelector(`tbody#line-list tr#${lineName}`)); + parent.removeChild(document.querySelector(`#line-list [id = ${lineName}]`)); manager.lineList.splice(deleteIdx, 1); }; export const makeChildInLine = (line) => { @@ -51,6 +51,14 @@ export const showAllLineInLineManager = (lineList) => { }); 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 isPossibleLine = (startName, endName) => { if (startName === endName) { alert("상행 종점과 다른 하행 종점을 선택 해주세요."); @@ -79,6 +87,7 @@ export const addLineToList = () => { const endStationName = document.getElementById("line-end-station-selector") .value; if ( + isPossibleLineName(newLineName) && isPossibleLine(startStationName, endStationName) && !isOverlappedLineName(newLineName) ) { From 41512b638576e332ab2743fe435dc5a7445fe64d Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sat, 12 Dec 2020 23:35:40 +0900 Subject: [PATCH 50/65] =?UTF-8?q?:bug:=20=EB=85=B8=EC=84=A0=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20=ED=9B=84=20=EC=A7=80=ED=95=98=EC=B2=A0=20=EC=97=AD?= =?UTF-8?q?=20=EC=84=A0=ED=83=9D=20=EC=98=B5=EC=85=98=20=EC=B4=88=EA=B8=B0?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/line-manager.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/line-manager.js b/src/line-manager.js index c1a1b4990..a998e478c 100644 --- a/src/line-manager.js +++ b/src/line-manager.js @@ -1,3 +1,4 @@ +import { makeStationOption, makeStationList } from "./index.js"; import { manager } from "./manager.js"; import Line from "./line.js"; import Station from "./station.js"; @@ -62,6 +63,8 @@ export const isPossibleLineName = (name) => { export const isPossibleLine = (startName, endName) => { if (startName === endName) { alert("상행 종점과 다른 하행 종점을 선택 해주세요."); + makeStationOption(makeStationList(), "line-start-station-selector"); + makeStationOption(makeStationList(), "line-end-station-selector"); return false; } @@ -74,6 +77,8 @@ export const isOverlappedLineName = (newLineName) => { if (overlappedName) { alert("이미 등록된 노선입니다."); document.getElementById("line-name-input").value = ""; + makeStationOption(makeStationList(), "line-start-station-selector"); + makeStationOption(makeStationList(), "line-end-station-selector"); return true; } @@ -99,5 +104,7 @@ export const addLineToList = () => { line.addLine(startStation, endStation); manager.setLineInManager(line); showAllLineInLineManager(manager.lineList); + makeStationOption(makeStationList(), "line-start-station-selector"); + makeStationOption(makeStationList(), "line-end-station-selector"); } }; From 8918752198a71cb695a3aae3f28694791045fa06 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sat, 12 Dec 2020 23:36:07 +0900 Subject: [PATCH 51/65] =?UTF-8?q?:pencil:=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=ED=95=AD=EB=AA=A9=20=EC=B6=94=EA=B0=80=ED=95=9C=20?= =?UTF-8?q?README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 36fc53417..3aa66ddd4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -25,6 +25,8 @@ - 구간 추가하기( === 노선에 역 추가하기) - 입력 받은 순서로, line 내 해당 번호 station 사이에 추가하기 - 추가 사항 적용된 구간 보여주기 +- 상행 종점과 하행 종점 삭제시, 다음 역 종점으로 설정 +- ### 지하철 노선도 출력 기능 @@ -33,9 +35,48 @@ ## :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: 의문점 From 8420341e80d06a1c29a0410931f99050b8512d62 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sun, 13 Dec 2020 00:04:57 +0900 Subject: [PATCH 52/65] =?UTF-8?q?:construction:=20makeStationOption()=20pa?= =?UTF-8?q?rams=201=EA=B0=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 47 +++++++++++++++++++++--------------------- src/line-manager.js | 14 ++++++------- src/section-manager.js | 8 +++---- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/index.js b/src/index.js index d6ba095ab..2b793f7fb 100644 --- a/src/index.js +++ b/src/index.js @@ -45,7 +45,7 @@ manager.setLineInManager(tmp4); const makeResultBlock = (idx) => { for (let i in resultList) { - if (i == idx) { + if (i === String(idx)) { resultList[i].style.display = "Block"; } else { resultList[i].style.display = "None"; @@ -53,10 +53,6 @@ const makeResultBlock = (idx) => { } }; showAllStationInManager(manager.stationList); -btnStationManager.onclick = () => { - makeResultBlock(0); - showAllStationInManager(makeStationList()); -}; export const makeStationList = () => { const finalStationList = []; const nowStationList = manager.stationList; @@ -81,31 +77,16 @@ export const makeStationList = () => { }); return finalStationList; }; -export const makeStationOption = (optionStationList, optionName) => { +export const makeStationOption = (optionName) => { + const StationListInOption = makeStationList(); const optionList = document.getElementById(optionName); optionList.innerHTML = ""; // 선택 노선 변경 시 지하철 역 새로 load - console.log(optionStationList); - for (let idx in optionStationList) { + for (let idx in StationListInOption) { const newOption = document.createElement("option"); - newOption.innerHTML = optionStationList[idx].name; + newOption.innerHTML = StationListInOption[idx].name; optionList.appendChild(newOption); } }; -btnLineManager.onclick = () => { - makeResultBlock(1); - const optionStationList = makeStationList(); - makeStationOption(optionStationList, "line-start-station-selector"); - makeStationOption(optionStationList, "line-end-station-selector"); - showAllLineInLineManager(manager.lineList); -}; -btnSectionManager.onclick = () => { - makeResultBlock(2); - showLineMenuInSectionManager(manager.lineList); -}; -btnMapPrintManager.onclick = () => { - makeResultBlock(3); - showMapList(); -}; const btnAddStation = document.getElementById("station-add-button"); btnAddStation.onclick = () => { const newStationName = document.getElementById("station-name-input").value; @@ -120,3 +101,21 @@ const btnAddLine = document.getElementById("line-add-button"); btnAddLine.onclick = () => { addLineToList(); }; +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(); +}; diff --git a/src/line-manager.js b/src/line-manager.js index a998e478c..82404e798 100644 --- a/src/line-manager.js +++ b/src/line-manager.js @@ -1,4 +1,4 @@ -import { makeStationOption, makeStationList } from "./index.js"; +import { makeStationOption } from "./index.js"; import { manager } from "./manager.js"; import Line from "./line.js"; import Station from "./station.js"; @@ -63,8 +63,8 @@ export const isPossibleLineName = (name) => { export const isPossibleLine = (startName, endName) => { if (startName === endName) { alert("상행 종점과 다른 하행 종점을 선택 해주세요."); - makeStationOption(makeStationList(), "line-start-station-selector"); - makeStationOption(makeStationList(), "line-end-station-selector"); + makeStationOption("line-start-station-selector"); + makeStationOption("line-end-station-selector"); return false; } @@ -77,8 +77,8 @@ export const isOverlappedLineName = (newLineName) => { if (overlappedName) { alert("이미 등록된 노선입니다."); document.getElementById("line-name-input").value = ""; - makeStationOption(makeStationList(), "line-start-station-selector"); - makeStationOption(makeStationList(), "line-end-station-selector"); + makeStationOption("line-start-station-selector"); + makeStationOption("line-end-station-selector"); return true; } @@ -104,7 +104,7 @@ export const addLineToList = () => { line.addLine(startStation, endStation); manager.setLineInManager(line); showAllLineInLineManager(manager.lineList); - makeStationOption(makeStationList(), "line-start-station-selector"); - makeStationOption(makeStationList(), "line-end-station-selector"); + makeStationOption("line-start-station-selector"); + makeStationOption("line-end-station-selector"); } }; diff --git a/src/section-manager.js b/src/section-manager.js index 59d4d9c26..761f57889 100644 --- a/src/section-manager.js +++ b/src/section-manager.js @@ -1,4 +1,4 @@ -import { makeStationOption, makeStationList } from "./index.js"; +import { makeStationOption } from "./index.js"; import { manager } from "./manager.js"; import Station from "./station.js"; @@ -60,7 +60,7 @@ export const onClickedLine = (lineName) => { sectionManagerTitle.innerHTML = `${selectedLineName} 관리`; const stationListBox = document.getElementById("station-in-selected-line"); stationListBox.innerHTML = ""; // 선택 노선 변경 시 역 계속 나열 안되게 초기화 - makeStationOption(makeStationList(), "section-station-selector"); + makeStationOption("section-station-selector"); const selectedLine = manager.lineList.find( (line) => line.name === selectedLineName ); @@ -97,7 +97,7 @@ export const isCorrectAddIdx = (idx, addSectionIdx) => { } else { alert("올바른 구간 번호를 입력하세요"); addSectionIdx.value = ""; - makeStationOption(makeStationList(), "section-station-selector"); + makeStationOption("section-station-selector"); return false; } @@ -119,6 +119,6 @@ btnAddSection.onclick = () => { stationList.innerHTML = ""; showStationList(manager.getSelectedLine().getAllStationName()); addSectionIdx.value = ""; - makeStationOption(makeStationList(), "section-station-selector"); + makeStationOption("section-station-selector"); } }; From 5e7af7b5c19bb940267087d1e28d1f259109876b Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sun, 13 Dec 2020 00:09:12 +0900 Subject: [PATCH 53/65] =?UTF-8?q?:construction:=20=EB=B2=84=ED=8A=BC=20?= =?UTF-8?q?=ED=81=B4=EB=A6=AD=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EA=B0=81=EA=B0=81=EC=9D=98=20=EB=AA=A8=EB=93=88?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 23 ++--------------------- src/line-manager.js | 5 +++++ src/station-manager.js | 11 +++++++++++ 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/index.js b/src/index.js index 2b793f7fb..f83285b42 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,7 @@ import Station from "./station.js"; -import { - addStationToList, - isCorrectStationName, - isOverlappedStationName, - showAllStationInManager, -} from "./station-manager.js"; +import { showAllStationInManager } from "./station-manager.js"; import Line from "./line.js"; -import { addLineToList, showAllLineInLineManager } from "./line-manager.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"; @@ -87,20 +82,6 @@ export const makeStationOption = (optionName) => { optionList.appendChild(newOption); } }; -const btnAddStation = document.getElementById("station-add-button"); -btnAddStation.onclick = () => { - const newStationName = document.getElementById("station-name-input").value; - if ( - isCorrectStationName(newStationName) && - !isOverlappedStationName(newStationName) - ) { - addStationToList(newStationName); - } -}; -const btnAddLine = document.getElementById("line-add-button"); -btnAddLine.onclick = () => { - addLineToList(); -}; btnStationManager.onclick = () => { makeResultBlock(0); showAllStationInManager(makeStationList()); diff --git a/src/line-manager.js b/src/line-manager.js index 82404e798..f796ef910 100644 --- a/src/line-manager.js +++ b/src/line-manager.js @@ -108,3 +108,8 @@ export const addLineToList = () => { makeStationOption("line-end-station-selector"); } }; + +const btnAddLine = document.getElementById("line-add-button"); +btnAddLine.onclick = () => { + addLineToList(); +}; diff --git a/src/station-manager.js b/src/station-manager.js index d027acac5..618bd1e4f 100644 --- a/src/station-manager.js +++ b/src/station-manager.js @@ -78,3 +78,14 @@ export const addStationToList = (newStationName) => { manager.setStationInManager(station); showAllStationInManager(makeStationList()); }; + +const btnAddStation = document.getElementById("station-add-button"); +btnAddStation.onclick = () => { + const newStationName = document.getElementById("station-name-input").value; + if ( + isCorrectStationName(newStationName) && + !isOverlappedStationName(newStationName) + ) { + addStationToList(newStationName); + } +}; From 013721a254127b1abaadb3b04901403c04e693da Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sun, 13 Dec 2020 00:42:39 +0900 Subject: [PATCH 54/65] =?UTF-8?q?:construction:=20=EC=A7=80=ED=95=98?= =?UTF-8?q?=EC=B2=A0=20=EC=97=AD=20selector=20=EC=83=9D=EC=84=B1=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=ED=95=A8=EC=88=98=EB=93=A4=20=EB=AA=A8=EB=93=88?= =?UTF-8?q?=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 72 +++++++++++++++++++++------------------ src/line-manager.js | 2 +- src/make-selector-list.js | 37 ++++++++++++++++++++ src/section-manager.js | 2 +- src/station-manager.js | 4 ++- 5 files changed, 80 insertions(+), 37 deletions(-) create mode 100644 src/make-selector-list.js diff --git a/src/index.js b/src/index.js index f83285b42..136f2fc89 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,7 @@ 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"); @@ -48,40 +49,43 @@ const makeResultBlock = (idx) => { } }; showAllStationInManager(manager.stationList); -export const makeStationList = () => { - const finalStationList = []; - const nowStationList = manager.stationList; - const stationName = []; - nowStationList.forEach((station) => { - stationName.push(station.name); - }); - const stationNameSet = Array.from(new Set(stationName)); - stationNameSet.forEach((name) => { - const sameName = nowStationList.filter( - (station) => station.name === name && station.isIncluded !== null - ); - if (sameName.length === 0) { - finalStationList.push( - nowStationList.filter( - (station) => station.name === name && station.isIncluded === null - )[0] - ); - } else { - finalStationList.push(sameName[0]); - } - }); - return finalStationList; -}; -export const makeStationOption = (optionName) => { - const StationListInOption = makeStationList(); - const optionList = document.getElementById(optionName); - optionList.innerHTML = ""; // 선택 노선 변경 시 지하철 역 새로 load - for (let idx in StationListInOption) { - const newOption = document.createElement("option"); - newOption.innerHTML = StationListInOption[idx].name; - optionList.appendChild(newOption); - } -}; +// export const pushStation = (sameName, finalStationList, stationList) => { +// if (sameName.length === 0) { +// finalStationList.push( +// stationList.filter( +// (station) => station.name === name && station.isIncluded === null +// )[0] +// ); +// } else { +// finalStationList.push(sameName[0]); +// } +// }; +// export const makeStationList = () => { +// const finalStationList = []; +// const stationList = manager.stationList; +// const stationName = stationList.map((station) => { +// return station.name; +// }); +// const stationNameSet = Array.from(new Set(stationName)); +// stationNameSet.forEach((name) => { +// const sameName = stationList.filter( +// (station) => station.name === name && station.isIncluded !== null +// ); +// pushStation(sameName, finalStationList, stationList); +// }); + +// return finalStationList; +// }; +// export const makeStationOption = (optionName) => { +// const StationListInOption = makeStationList(); +// const optionList = document.getElementById(optionName); +// optionList.innerHTML = ""; // 선택 노선 변경 시 지하철 역 새로 load +// for (let idx in StationListInOption) { +// const newOption = document.createElement("option"); +// newOption.innerHTML = StationListInOption[idx].name; +// optionList.appendChild(newOption); +// } +// }; btnStationManager.onclick = () => { makeResultBlock(0); showAllStationInManager(makeStationList()); diff --git a/src/line-manager.js b/src/line-manager.js index f796ef910..81d7b7bbf 100644 --- a/src/line-manager.js +++ b/src/line-manager.js @@ -1,4 +1,4 @@ -import { makeStationOption } from "./index.js"; +import { makeStationOption } from "./make-selector-list.js"; import { manager } from "./manager.js"; import Line from "./line.js"; import Station from "./station.js"; diff --git a/src/make-selector-list.js b/src/make-selector-list.js new file mode 100644 index 000000000..3b09a8cfa --- /dev/null +++ b/src/make-selector-list.js @@ -0,0 +1,37 @@ +import { manager } from "./manager.js"; + +export const pushStation = (sameName, name, stationList) => { + if (sameName.length === 0) { + return stationList.filter( + (station) => station.name === name && station.isIncluded === null + )[0]; + } else { + return sameName[0]; + } +}; +export const makeStationList = () => { + const finalStationList = []; + const stationList = manager.stationList; + const stationName = stationList.map((station) => { + return station.name; + }); + const stationNameSet = Array.from(new Set(stationName)); + stationNameSet.forEach((name) => { + const sameName = stationList.filter( + (station) => station.name === name && station.isIncluded !== null + ); + finalStationList.push(pushStation(sameName, name, stationList)); + }); + + return finalStationList; +}; +export const makeStationOption = (optionName) => { + const StationListInOption = makeStationList(); + const optionList = document.getElementById(optionName); + optionList.innerHTML = ""; // 선택 노선 변경 시 지하철 역 새로 load + for (let idx in StationListInOption) { + const newOption = document.createElement("option"); + newOption.innerHTML = StationListInOption[idx].name; + optionList.appendChild(newOption); + } +}; diff --git a/src/section-manager.js b/src/section-manager.js index 761f57889..55e3a1e2c 100644 --- a/src/section-manager.js +++ b/src/section-manager.js @@ -1,4 +1,4 @@ -import { makeStationOption } from "./index.js"; +import { makeStationOption } from "./make-selector-list.js"; import { manager } from "./manager.js"; import Station from "./station.js"; diff --git a/src/station-manager.js b/src/station-manager.js index 618bd1e4f..722db5086 100644 --- a/src/station-manager.js +++ b/src/station-manager.js @@ -1,6 +1,6 @@ import { manager } from "./manager.js"; import Station from "./station.js"; -import { makeStationList } from "./index.js"; +import { makeStationList } from "./make-selector-list.js"; export const isCorrectStationName = (newStationName) => { const rHangel = /^[0-9A-Za-z가-힣]*$/; @@ -49,6 +49,7 @@ export const deleteStationInList = (stationName) => { } }; export const makeStationBox = (newStationName) => { + console.log(newStationName); const newStation = document.createElement("tr"); const stationName = document.createElement("td"); const deleteButton = document.createElement("td"); @@ -68,6 +69,7 @@ export const showAllStationInManager = (stationList) => { const table = document.getElementById("station-list"); table.innerHTML = ""; stationList.forEach((station) => { + console.log(station); const newStation = makeStationBox(station.name); table.appendChild(newStation); }); From 3437c5414d4afed3e992625f9ddb88aacad52674 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sun, 13 Dec 2020 00:43:55 +0900 Subject: [PATCH 55/65] =?UTF-8?q?:fire:=20=EB=AA=A8=EB=93=88=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=ED=95=98=EB=A9=B0=20=EC=9E=91=EC=84=B1=ED=95=9C=20?= =?UTF-8?q?=EC=A3=BC=EC=84=9D=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/src/index.js b/src/index.js index 136f2fc89..db7066180 100644 --- a/src/index.js +++ b/src/index.js @@ -49,43 +49,6 @@ const makeResultBlock = (idx) => { } }; showAllStationInManager(manager.stationList); -// export const pushStation = (sameName, finalStationList, stationList) => { -// if (sameName.length === 0) { -// finalStationList.push( -// stationList.filter( -// (station) => station.name === name && station.isIncluded === null -// )[0] -// ); -// } else { -// finalStationList.push(sameName[0]); -// } -// }; -// export const makeStationList = () => { -// const finalStationList = []; -// const stationList = manager.stationList; -// const stationName = stationList.map((station) => { -// return station.name; -// }); -// const stationNameSet = Array.from(new Set(stationName)); -// stationNameSet.forEach((name) => { -// const sameName = stationList.filter( -// (station) => station.name === name && station.isIncluded !== null -// ); -// pushStation(sameName, finalStationList, stationList); -// }); - -// return finalStationList; -// }; -// export const makeStationOption = (optionName) => { -// const StationListInOption = makeStationList(); -// const optionList = document.getElementById(optionName); -// optionList.innerHTML = ""; // 선택 노선 변경 시 지하철 역 새로 load -// for (let idx in StationListInOption) { -// const newOption = document.createElement("option"); -// newOption.innerHTML = StationListInOption[idx].name; -// optionList.appendChild(newOption); -// } -// }; btnStationManager.onclick = () => { makeResultBlock(0); showAllStationInManager(makeStationList()); From e55e96336e7532c926cac67cee973bb58782ba72 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sun, 13 Dec 2020 00:54:17 +0900 Subject: [PATCH 56/65] =?UTF-8?q?:hammer:=20station-manager.js=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/station-manager.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/station-manager.js b/src/station-manager.js index 722db5086..95162203f 100644 --- a/src/station-manager.js +++ b/src/station-manager.js @@ -30,7 +30,8 @@ export const isPossibleToDeleteStation = (stationName) => { }); if (deleteStation.isIncluded !== null) { alert("이미 노선에 등록되어 있는 역입니다."); - return false; // 이미 노선에 등록되어있어서 삭제 불가 + + return false; } return true; }; @@ -49,7 +50,6 @@ export const deleteStationInList = (stationName) => { } }; export const makeStationBox = (newStationName) => { - console.log(newStationName); const newStation = document.createElement("tr"); const stationName = document.createElement("td"); const deleteButton = document.createElement("td"); @@ -69,16 +69,16 @@ export const showAllStationInManager = (stationList) => { const table = document.getElementById("station-list"); table.innerHTML = ""; stationList.forEach((station) => { - console.log(station); const newStation = makeStationBox(station.name); table.appendChild(newStation); }); - document.getElementById("station-name-input").value = ""; }; export const addStationToList = (newStationName) => { const station = new Station(newStationName); manager.setStationInManager(station); - showAllStationInManager(makeStationList()); + const stationList = makeStationList(); // 중복 제거 된 지하철 역 리스트 + showAllStationInManager(stationList); + document.getElementById("station-name-input").value = ""; }; const btnAddStation = document.getElementById("station-add-button"); From 31a16dc8c1668fcc7d9a9c8f9be574d187bd6d52 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sun, 13 Dec 2020 01:00:01 +0900 Subject: [PATCH 57/65] =?UTF-8?q?:construction:=20=EB=85=B8=EC=84=A0=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=20input=20=EC=B4=88=EA=B8=B0=ED=99=94=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EB=93=A4=20=ED=95=A8=EC=88=98=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/line-manager.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/line-manager.js b/src/line-manager.js index 81d7b7bbf..89bd0c806 100644 --- a/src/line-manager.js +++ b/src/line-manager.js @@ -57,14 +57,19 @@ export const isPossibleLineName = (name) => { if (name.length > 0 && rHangel.exec(name) !== null) { return true; } - alert("노선 이름을 입력 해주세요"); + 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("상행 종점과 다른 하행 종점을 선택 해주세요."); - makeStationOption("line-start-station-selector"); - makeStationOption("line-end-station-selector"); + resetLineInput(); return false; } @@ -76,9 +81,7 @@ export const isOverlappedLineName = (newLineName) => { ); if (overlappedName) { alert("이미 등록된 노선입니다."); - document.getElementById("line-name-input").value = ""; - makeStationOption("line-start-station-selector"); - makeStationOption("line-end-station-selector"); + resetLineInput(); return true; } @@ -104,8 +107,7 @@ export const addLineToList = () => { line.addLine(startStation, endStation); manager.setLineInManager(line); showAllLineInLineManager(manager.lineList); - makeStationOption("line-start-station-selector"); - makeStationOption("line-end-station-selector"); + resetLineInput(); } }; From 6fd886f28ba0769b8b7e3e4dc5f6cec5051fa090 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sun, 13 Dec 2020 01:17:05 +0900 Subject: [PATCH 58/65] =?UTF-8?q?:hammer:=20line-manager.js=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/line-manager.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/line-manager.js b/src/line-manager.js index 89bd0c806..57a9b5571 100644 --- a/src/line-manager.js +++ b/src/line-manager.js @@ -12,7 +12,7 @@ export const deleteLineInList = (lineName) => { parent.removeChild(document.querySelector(`#line-list [id = ${lineName}]`)); manager.lineList.splice(deleteIdx, 1); }; -export const makeChildInLine = (line) => { +export const makeLineChildUI = (line) => { const lineName = document.createElement("td"); const startStation = document.createElement("td"); const endStation = document.createElement("td"); @@ -29,17 +29,13 @@ export const makeChildInLine = (line) => { return [lineName, startStation, endStation, deleteButton]; }; -export const makeLineBox = (line) => { - const lineName = makeChildInLine(line)[0]; - const startStation = makeChildInLine(line)[1]; - const endStation = makeChildInLine(line)[2]; - const deleteButton = makeChildInLine(line)[3]; +export const makeLineUI = (line) => { + const [lineName, startStation, endStation, deleteButton] = makeLineChildUI( + line + ); const newLine = document.createElement("tr"); newLine.setAttribute("id", `${line.name}`); - newLine.appendChild(lineName); - newLine.appendChild(startStation); - newLine.appendChild(endStation); - newLine.appendChild(deleteButton); + newLine.append(lineName, startStation, endStation, deleteButton); return newLine; }; @@ -47,7 +43,7 @@ export const showAllLineInLineManager = (lineList) => { const table = document.getElementById("line-list"); table.innerHTML = ""; lineList.forEach((line) => { - const newLine = makeLineBox(line); + const newLine = makeLineUI(line); table.appendChild(newLine); }); document.getElementById("line-name-input").value = ""; From 9596b0f8938859998d3873ca6c0401d33840dcdb Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sun, 13 Dec 2020 01:39:35 +0900 Subject: [PATCH 59/65] =?UTF-8?q?:hammer:=20section-manager.js=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/section-manager.js | 51 ++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/src/section-manager.js b/src/section-manager.js index 55e3a1e2c..61a403185 100644 --- a/src/section-manager.js +++ b/src/section-manager.js @@ -2,7 +2,7 @@ import { makeStationOption } from "./make-selector-list.js"; import { manager } from "./manager.js"; import Station from "./station.js"; -export const isPossibleDeleteIdx = () => { +export const isCorrectDeleteIdx = () => { if (manager.getSelectedLine().length <= 2) { alert("더 이상 지하철 역을 제거 할 수 없습니다."); @@ -11,17 +11,17 @@ export const isPossibleDeleteIdx = () => { return true; }; export const deleteSectionInList = (idx) => { - if (isPossibleDeleteIdx()) { + if (isCorrectDeleteIdx()) { const stationInSelecteLine = document.getElementById( "station-in-selected-line" ); stationInSelecteLine.innerHTML = ""; manager.getSelectedLine().deleteStationInIdx(idx); manager.setSelectedLine(manager.selectedLine); - showStationList(manager.getSelectedLine().getAllStationName()); + showSectionList(manager.getSelectedLine().getAllStationName()); } }; -export const makeStationBox = (station, idx) => { +export const makeSectionUI = (station, idx) => { const oneStation = document.createElement("tr"); oneStation.setAttribute("id", `${idx}`); const stationIdx = document.createElement("td"); @@ -37,17 +37,13 @@ export const makeStationBox = (station, idx) => { return [stationIdx, stationName, deleteButton]; }; -export const showStationList = (allStationName) => { +export const showSectionList = (allStationName) => { const table = document.getElementById("station-in-selected-line-list-table"); allStationName.forEach((station, idx) => { - const stationIdx = makeStationBox(station, idx)[0]; - const stationName = makeStationBox(station, idx)[1]; - const deleteButton = makeStationBox(station, idx)[2]; + const [stationIdx, stationName, deleteButton] = makeSectionUI(station, idx); const oneStation = document.createElement("tr"); oneStation.setAttribute("id", `${idx}`); - oneStation.appendChild(stationIdx); - oneStation.appendChild(stationName); - oneStation.appendChild(deleteButton); + oneStation.append(stationIdx, stationName, deleteButton); table.children[1].appendChild(oneStation); }); @@ -58,14 +54,13 @@ export const onClickedLine = (lineName) => { selectedLineBox.style.display = "Block"; const sectionManagerTitle = document.getElementById("section-line-name"); sectionManagerTitle.innerHTML = `${selectedLineName} 관리`; - const stationListBox = document.getElementById("station-in-selected-line"); - stationListBox.innerHTML = ""; // 선택 노선 변경 시 역 계속 나열 안되게 초기화 - makeStationOption("section-station-selector"); + resetSectionInput(); + resetSectionList(); const selectedLine = manager.lineList.find( (line) => line.name === selectedLineName ); manager.setSelectedLine(selectedLine); - showStationList(manager.getSelectedLine().getAllStationName()); + showSectionList(manager.getSelectedLine().getAllStationName()); }; export const makeLineButton = (line) => { const lineMenuButton = document.createElement("button"); @@ -86,7 +81,14 @@ export const showLineMenuInSectionManager = (lineList) => { lineMenu.appendChild(lineMenuButton); }); }; -export const isCorrectAddIdx = (idx, addSectionIdx) => { +export const resetSectionInput = () => { + document.getElementById("section-order-input").value = ""; + makeStationOption("section-station-selector"); +}; +export const resetSectionList = () => { + document.getElementById("station-in-selected-line").innerHTML = ""; +}; +export const isCorrectAddIdx = (idx) => { if ( idx > 0 && idx < manager.getSelectedLine().length && @@ -96,17 +98,15 @@ export const isCorrectAddIdx = (idx, addSectionIdx) => { return true; } else { alert("올바른 구간 번호를 입력하세요"); - addSectionIdx.value = ""; - makeStationOption("section-station-selector"); + resetSectionInput(); return false; } }; const btnAddSection = document.getElementById("section-add-button"); btnAddSection.onclick = () => { - const addSectionIdx = document.getElementById("section-order-input"); - const inputIdx = addSectionIdx.value; - if (isCorrectAddIdx(inputIdx, addSectionIdx)) { + const addSectionIdx = document.getElementById("section-order-input").value; + if (isCorrectAddIdx(addSectionIdx)) { const addStationName = document.getElementById("section-station-selector") .value; const selectedLine = manager.getSelectedLine(); @@ -114,11 +114,8 @@ btnAddSection.onclick = () => { inputStation.addIncludedLine(selectedLine.name); manager.setStationInManager(inputStation); selectedLine.addStationInIdx(inputStation, addSectionIdx); - - const stationList = document.getElementById("station-in-selected-line"); - stationList.innerHTML = ""; - showStationList(manager.getSelectedLine().getAllStationName()); - addSectionIdx.value = ""; - makeStationOption("section-station-selector"); + resetSectionList(); + showSectionList(manager.getSelectedLine().getAllStationName()); + resetSectionInput(); } }; From 4944d89f50abadda6c10c6d7bcd68caba11ae357 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sun, 13 Dec 2020 01:43:43 +0900 Subject: [PATCH 60/65] =?UTF-8?q?:hammer:=20map-print-manager.js=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/map-print-manager.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/map-print-manager.js b/src/map-print-manager.js index 5be0bc955..e2146f75b 100644 --- a/src/map-print-manager.js +++ b/src/map-print-manager.js @@ -1,12 +1,12 @@ import { manager } from "./manager.js"; -export const showLineTitleInMap = (lineName) => { +export const makeLineNameUI = (lineName) => { const lineNameBox = document.createElement("div"); lineNameBox.innerHTML = lineName; return lineNameBox; }; -export const showStationInMap = (line) => { +export const makeStationInLineUI = (line) => { const stationBox = document.createElement("ul"); const stationList = line.getAllStationName(); stationList.forEach((station) => { @@ -17,12 +17,11 @@ export const showStationInMap = (line) => { return stationBox; }; -export const showMap = (line) => { +export const makeMapUI = (line) => { const oneMap = document.createElement("div"); - const lineNameBox = showLineTitleInMap(line.name); - const stationBox = showStationInMap(line); - oneMap.appendChild(lineNameBox); - oneMap.appendChild(stationBox); + const lineNameBox = makeLineNameUI(line.name); + const stationBox = makeStationInLineUI(line); + oneMap.append(lineNameBox, stationBox); return oneMap; }; @@ -33,7 +32,7 @@ export const showMapList = () => { mapPrintResult.innerHTML = ""; // 버튼 누를때 마다 map 추가되지 않게 초기화 mapList.setAttribute("class", "map"); lineList.forEach((line) => { - const map = showMap(line); // 라인 하나의 map그리기 + const map = makeMapUI(line); // 라인 하나의 map그리기 mapList.appendChild(map); }); mapPrintResult.appendChild(mapList); From 6e623d675067692af59efbd50e2c1786f0169681 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Sun, 13 Dec 2020 01:47:10 +0900 Subject: [PATCH 61/65] =?UTF-8?q?:hammer:=20manager.js=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/manager.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/manager.js b/src/manager.js index 6859df1b2..0a1d35280 100644 --- a/src/manager.js +++ b/src/manager.js @@ -9,12 +9,9 @@ export function Manager() { this.lineList.push(line); }; this.getAllLineName = () => { - let lineNameList = []; - for (let i in lineList) { - lineNameList.push(this.lineList[i].name); - } - - return lineNameList; + return this.lineList.map((line) => { + return line.name; + }); }; this.setSelectedLine = (selectedLine) => { this.selectedLine = selectedLine; From 977818b6d938222646c3516e04668252bfd01a6f Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Mon, 14 Dec 2020 16:59:17 +0900 Subject: [PATCH 62/65] =?UTF-8?q?:bug:=20=EB=9D=BC=EC=9D=B8=EC=9D=98=20?= =?UTF-8?q?=EC=B2=AB=20=EB=B2=88=EC=A7=B8=20=EC=97=AD=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EC=8B=9C=20isIncluded=20=EC=97=85=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/line.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/line.js b/src/line.js index 55f62b649..a2f5424a1 100644 --- a/src/line.js +++ b/src/line.js @@ -53,6 +53,7 @@ export default function Line(name) { let currentIdx = 0; let currentStation = this.head; if (idx === "0") { + this.deleteOneStationInLine(currentStation); this.head = currentStation.next; } else { while (currentIdx < idx - 1) { From f129073f4158d5151826713720ea446299b5b162 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Mon, 14 Dec 2020 17:07:31 +0900 Subject: [PATCH 63/65] =?UTF-8?q?:bug:=20=EC=A7=80=ED=95=98=EC=B2=A0=20?= =?UTF-8?q?=EC=97=AD=20=EC=82=AD=EC=A0=9C=20=EC=A1=B0=EA=B1=B4=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/station-manager.js | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/station-manager.js b/src/station-manager.js index 95162203f..be7c37c32 100644 --- a/src/station-manager.js +++ b/src/station-manager.js @@ -13,31 +13,30 @@ export const isCorrectStationName = (newStationName) => { return false; }; export const isOverlappedStationName = (newStationName) => { - const overlappedName = manager.stationList.find( - (station) => station.name === newStationName - ); - if (overlappedName) { - alert("중복된 역 이름 입니다."); - document.getElementById("station-name-input").value = ""; + if (manager.stationList.length > 0) { + const overlappedName = manager.stationList.find( + (station) => station.name === newStationName + ); + if (overlappedName) { + alert("중복된 역 이름 입니다."); + document.getElementById("station-name-input").value = ""; - return true; + return true; + } + return false; } - return false; }; -export const isPossibleToDeleteStation = (stationName) => { - const deleteStation = manager.stationList.find((station) => { - return station.name === stationName; - }); - if (deleteStation.isIncluded !== null) { - alert("이미 노선에 등록되어 있는 역입니다."); - - return false; +export const isPossibleToDeleteStation = (stationIsIncluded) => { + if (stationIsIncluded === "null") { + return true; } - return true; + alert("이미 노선에 등록되어 있는 역입니다."); + + return false; }; -export const deleteStationInList = (stationName) => { +export const deleteStationInList = (stationName, stationIsIncluded) => { const parent = document.querySelector("table#staion-list-table tbody"); - if (isPossibleToDeleteStation(stationName)) { + if (isPossibleToDeleteStation(stationIsIncluded)) { const deleteIdx = manager.stationList.findIndex((station) => { return station.name === stationName && station.isIncluded === null; }); @@ -47,9 +46,10 @@ export const deleteStationInList = (stationName) => { ) ); manager.stationList.splice(deleteIdx, 1); + showAllStationInManager(makeStationList()); } }; -export const makeStationBox = (newStationName) => { +export const makeStationBox = (newStationName, newStationIsIncluded) => { const newStation = document.createElement("tr"); const stationName = document.createElement("td"); const deleteButton = document.createElement("td"); @@ -57,7 +57,7 @@ export const makeStationBox = (newStationName) => { stationName.innerHTML = newStationName; deleteButton.setAttribute("class", "station-delete-class"); deleteButton.onclick = () => { - deleteStationInList(`${newStationName}`); + deleteStationInList(`${newStationName}`, `${newStationIsIncluded}`); }; deleteButton.innerHTML = "삭제"; newStation.appendChild(stationName); @@ -69,7 +69,7 @@ export const showAllStationInManager = (stationList) => { const table = document.getElementById("station-list"); table.innerHTML = ""; stationList.forEach((station) => { - const newStation = makeStationBox(station.name); + const newStation = makeStationBox(station.name, station.isIncluded); table.appendChild(newStation); }); }; From aa7507cc0b581ccc6fb81ca639835684bcea5500 Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Mon, 14 Dec 2020 17:08:21 +0900 Subject: [PATCH 64/65] =?UTF-8?q?:bug:=20=EC=82=AD=EC=A0=9C=20=EB=85=B8?= =?UTF-8?q?=EC=84=A0=20=EC=A0=95=EB=B3=B4=20=EA=B0=80=EC=A0=B8=EC=98=A4?= =?UTF-8?q?=EB=8A=94=20=EA=B3=BC=EC=A0=95=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/line-manager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/line-manager.js b/src/line-manager.js index 57a9b5571..2bf969c7e 100644 --- a/src/line-manager.js +++ b/src/line-manager.js @@ -4,12 +4,12 @@ import Line from "./line.js"; import Station from "./station.js"; export const deleteLineInList = (lineName) => { - const parent = document.querySelector("table#line-list-table tbody"); + 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(); - parent.removeChild(document.querySelector(`#line-list [id = ${lineName}]`)); manager.lineList.splice(deleteIdx, 1); }; export const makeLineChildUI = (line) => { @@ -34,7 +34,7 @@ export const makeLineUI = (line) => { line ); const newLine = document.createElement("tr"); - newLine.setAttribute("id", `${line.name}`); + newLine.setAttribute("id", `${line.name}-line`); newLine.append(lineName, startStation, endStation, deleteButton); return newLine; From 87662ea71b8d5628f9593a82cb07cc21641ce9bd Mon Sep 17 00:00:00 2001 From: HyuuunjuKim Date: Mon, 14 Dec 2020 17:11:35 +0900 Subject: [PATCH 65/65] =?UTF-8?q?:sparkles:=20localStorage=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 54 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/src/index.js b/src/index.js index db7066180..b6711b5c2 100644 --- a/src/index.js +++ b/src/index.js @@ -24,21 +24,45 @@ const resultList = [ resultMapPrintManager, ]; -const tmp = new Line("2호선"); -const tmp2 = new Station("잠실"); -const tmp3 = new Station("신림"); -tmp.addLine(tmp2, tmp3); -manager.setStationInManager(tmp2); -manager.setStationInManager(tmp3); -manager.setLineInManager(tmp); -const tmp4 = new Line("3호선"); -const tmp5 = new Station("대화"); -const tmp6 = new Station("오금"); -tmp4.addLine(tmp5, tmp6); -manager.setStationInManager(tmp5); -manager.setStationInManager(tmp6); -manager.setLineInManager(tmp4); - +// 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)) {