From 9243c4f9121b69189ffb63930fe0113507ab5629 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Mon, 14 Dec 2020 12:23:36 +0900 Subject: [PATCH 01/48] =?UTF-8?q?docs=20:=20=EC=A7=80=ED=95=98=EC=B2=A0=20?= =?UTF-8?q?=EB=85=B8=EC=84=A0=EB=8F=84=20=EB=AF=B8=EC=85=98=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84=20=EB=AA=A9=EB=A1=9D=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 127 +++++++++++------------------------------------------- 1 file changed, 25 insertions(+), 102 deletions(-) diff --git a/README.md b/README.md index e97a1d649..a68c94b37 100644 --- a/README.md +++ b/README.md @@ -1,114 +1,37 @@ # πŸš‡ μ§€ν•˜μ²  노선도 λ―Έμ…˜ +μ§€ν•˜μ²  역을 μΆ”κ°€ 및 μ‚­μ œν•˜κ³ , μƒμ„±λœ 노선에 역을 μΆ”κ°€ν•˜κ³  μ‚­μ œν•  수 μžˆλŠ” ν”„λ‘œκ·Έλž¨μ΄λ‹€. -## πŸš€ κΈ°λŠ₯ μš”κ΅¬μ‚¬ν•­ +## πŸš€ κΈ°λŠ₯ κ΅¬ν˜„ λͺ©λ‘ +1. μ‚¬μš©μžλŠ” λ²„νŠΌ 4개(μ—­ 관리, λ…Έμ„  관리, ꡬ간 관리, μ§€ν•˜μ²  노선도 좜λ ₯)λ₯Ό 선택할 수 μžˆλ‹€. ### μ§€ν•˜μ²  μ—­ κ΄€λ ¨ κΈ°λŠ₯ -- μ§€ν•˜μ²  역을 λ“±λ‘ν•˜κ³  μ‚­μ œν•  수 μžˆλ‹€. (단, 노선에 λ“±λ‘λœ 역은 μ‚­μ œν•  수 μ—†λ‹€) -- μ€‘λ³΅λœ μ§€ν•˜μ²  μ—­ 이름이 등둝될 수 μ—†λ‹€. -- μ§€ν•˜μ²  역은 2κΈ€μž 이상이어야 ν•œλ‹€. -- μ§€ν•˜μ²  μ—­μ˜ λͺ©λ‘μ„ μ‘°νšŒν•  수 μžˆλ‹€. +2. μ‚¬μš©μžλŠ” 역을 등둝할 수 μžˆλ‹€. + - [μ˜ˆμ™Έμ²˜λ¦¬] 2κΈ€μž μ΄μƒμ˜ 이름인지 검증해야 ν•œλ‹€. + - [μ˜ˆμ™Έμ²˜λ¦¬] μ€‘λ³΅λœ 이름이 μžˆλŠ”μ§€ 검증해야 ν•œλ‹€. +3. μ‚¬μš©μžλŠ” 역을 μ‚­μ œν•  수 μžˆλ‹€. + - [μ˜ˆμ™Έμ²˜λ¦¬] 노선에 μžˆλŠ”μ§€ κ²€μ¦ν•˜κ³ , 노선에 μžˆλ‹€λ©΄ μ‚­μ œν•  수 μ—†λ‹€. +4. μ‚¬μš©μž μ§€ν•˜μ²  μ—­μ˜ λͺ©λ‘μ„ μ‘°νšŒν•  수 μžˆλ‹€. ### μ§€ν•˜μ²  λ…Έμ„  κ΄€λ ¨ κΈ°λŠ₯ -- μ§€ν•˜μ²  노선을 λ“±λ‘ν•˜κ³  μ‚­μ œν•  수 μžˆλ‹€. -- μ€‘λ³΅λœ μ§€ν•˜μ²  λ…Έμ„  이름이 등둝될 수 μ—†λ‹€. -- λ…Έμ„  등둝 μ‹œ 상행 쒅점역과 ν•˜ν–‰ 쒅점역을 μž…λ ₯λ°›λŠ”λ‹€. -- μ§€ν•˜μ²  λ…Έμ„ μ˜ λͺ©λ‘μ„ μ‘°νšŒν•  수 μžˆλ‹€. +5. μ‚¬μš©μžλŠ” μ§€ν•˜μ²  노선을 등둝할 수 μžˆλ‹€. + - [쑰건] λ…Έμ„  등둝 μ‹œ 상행 쒅점역과 ν•˜ν–‰ 쒅점역을 μž…λ ₯λ°›λŠ”λ‹€. + - [μ˜ˆμ™Έμ²˜λ¦¬] μ€‘λ³΅λœ λ…Έμ„  이름이 μžˆλŠ”μ§€ 검증해야 ν•œλ‹€. + - [μ˜ˆμ™Έμ²˜λ¦¬] ~μ„  ν˜•νƒœμ˜ 이름인지 검증해야 ν•œλ‹€. + - [μ˜ˆμ™Έμ²˜λ¦¬] μ‹œμž‘μ κ³Ό 끝점이 같은 노선이 μžˆλŠ”μ§€ 검증해야 ν•œλ‹€. +6. μ‚¬μš©μžλŠ” μ§€ν•˜μ²  노선을 μ‚­μ œν•  수 μžˆλ‹€. +7. μ‚¬μš©μžλŠ” μ§€ν•˜μ²  λ…Έμ„ μ˜ λͺ©λ‘μ„ μ‘°νšŒν•  수 μžˆλ‹€. ### μ§€ν•˜μ²  ꡬ간 μΆ”κ°€ κΈ°λŠ₯ -- μ§€ν•˜μ²  노선에 ꡬ간을 μΆ”κ°€ν•˜λŠ” κΈ°λŠ₯은 노선에 역을 μΆ”κ°€ν•˜λŠ” κΈ°λŠ₯이라고도 ν•  수 μžˆλ‹€. - - μ—­κ³Ό 역사이λ₯Ό ꡬ간이라 ν•˜κ³  이 κ΅¬κ°„λ“€μ˜ λͺ¨μŒμ΄ 노선이닀. -- ν•˜λ‚˜μ˜ 역은 μ—¬λŸ¬κ°œμ˜ 노선에 좔가될 수 μžˆλ‹€. -- μ—­κ³Ό μ—­ 사이에 μƒˆλ‘œμš΄ 역이 μΆ”κ°€ 될 수 μžˆλ‹€. -- λ…Έμ„ μ—μ„œ κ°ˆλž˜κΈΈμ€ 생길 수 μ—†λ‹€. - - +8. μ‚¬μš©μžλŠ” 노선에 역을 μΆ”κ°€ν•  수 μžˆλ‹€. + - [μ˜ˆμ™Έμ²˜λ¦¬] μ€‘λ³΅λœ 노선이 μžˆλŠ”μ§€ 검증해야 ν•œλ‹€. + - [쑰건] ν•˜λ‚˜μ˜ 역은 μ—¬λŸ¬κ°œμ˜ 노선에 좔가될 수 μžˆλ‹€. + - [쑰건] μ—­κ³Ό μ—­ 사이에 μƒˆλ‘œμš΄ 역이 μΆ”κ°€ 될 수 μžˆλ‹€. + - [쑰건] λ…Έμ„ μ—μ„œ κ°ˆλž˜κΈΈμ€ 생길 수 μ—†λ‹€. ### μ§€ν•˜μ²  ꡬ간 μ‚­μ œ κΈ°λŠ₯ -- 노선에 λ“±λ‘λœ 역을 μ œκ±°ν•  수 μžˆλ‹€. -- 쒅점을 μ œκ±°ν•  경우 λ‹€μŒ 역이 쒅점이 λœλ‹€. -- 노선에 ν¬ν•¨λœ 역이 λ‘κ°œ μ΄ν•˜μΌ λ•ŒλŠ” 역을 μ œκ±°ν•  수 μ—†λ‹€. - - +9. μ‚¬μš©μžλŠ” λ…Έμ„ μ˜ 역을 μ‚­μ œν•  수 μžˆλ‹€. + - [μ˜ˆμ™Έμ²˜λ¦¬] 노선에 역이 2개 μ΄ν•˜μΈμ§€ κ²€μ¦ν•˜κ³ , 2개 μ΄ν•˜λ©΄ μ‚­μ œν•  수 μ—†λ‹€. + - [쑰건] 쒅점을 μ œκ±°ν•  경우 λ‹€μŒ 역이 쒅점이 λœλ‹€. ### μ§€ν•˜μ²  노선에 λ“±λ‘λœ μ—­ 쑰회 κΈ°λŠ₯ -- λ…Έμ„ μ˜ 상행 쒅점뢀터 ν•˜ν–‰ μ’…μ κΉŒμ§€ μ—°κ²°λœ μˆœμ„œλŒ€λ‘œ μ—­ λͺ©λ‘μ„ μ‘°νšŒν•  수 μžˆλ‹€. - -
- -## πŸ’» ν”„λ‘œκ·Έλž¨ μ‹€ν–‰ κ²°κ³Ό - -### 역관리 - - -### 노선관리 - - -### ꡬ간관리 - - -### 노선도 좜λ ₯ - - - -## βœ… ν”„λ‘œκ·Έλž˜λ° μš”κ΅¬μ‚¬ν•­ - -### 메뉴 λ²„νŠΌ -- μ—­ 관리 button νƒœκ·ΈλŠ” `#station-manager-button` id값을 κ°€μ§„λ‹€. -- λ…Έμ„  관리 button νƒœκ·ΈλŠ” `#line-manager-button` id값을 κ°€μ§„λ‹€. -- ꡬ간 관리 button νƒœκ·ΈλŠ” `#section-manager-button` id값을 κ°€μ§„λ‹€. -- μ§€ν•˜μ²  노선도 좜λ ₯ 관리 button νƒœκ·ΈλŠ” `#map-print-manager-button` id값을 κ°€μ§„λ‹€. - -### μ§€ν•˜μ²  μ—­ κ΄€λ ¨ κΈ°λŠ₯ -- μ§€ν•˜μ²  역을 μž…λ ₯ν•˜λŠ” input νƒœκ·ΈλŠ” `#station-name-input` id값을 κ°€μ§„λ‹€. -- μ§€ν•˜μ²  역을 μΆ”κ°€ν•˜λŠ” button νƒœκ·ΈλŠ” `#station-add-button` id값을 κ°€μ§„λ‹€. -- μ§€ν•˜μ²  역을 μ‚­μ œν•˜λŠ” button νƒœκ·ΈλŠ” `.station-delete-button` class값을 κ°€μ§„λ‹€. - -### μ§€ν•˜μ²  λ…Έμ„  κ΄€λ ¨ κΈ°λŠ₯ -- μ§€ν•˜μ²  λ…Έμ„ μ˜ 이름을 μž…λ ₯ν•˜λŠ” input νƒœκ·ΈλŠ” `#line-name-input` id값을 κ°€μ§„λ‹€. -- μ§€ν•˜μ²  λ…Έμ„ μ˜ 상행 쒅점을 μ„ νƒν•˜λŠ” select νƒœκ·ΈλŠ” `#line-start-station-selector` id값을 κ°€μ§„λ‹€. -- μ§€ν•˜μ²  λ…Έμ„ μ˜ ν•˜ν–‰ 쒅점을 μ„ νƒν•˜λŠ” select νƒœκ·ΈλŠ” `#line-end-station-selector` id값을 κ°€μ§„λ‹€. -- μ§€ν•˜μ²  노선을 μΆ”κ°€ν•˜λŠ” button νƒœκ·ΈλŠ” `#line-add-button` id값을 κ°€μ§„λ‹€. -- μ§€ν•˜μ²  노선을 μ‚­μ œν•˜λŠ” button νƒœκ·ΈλŠ” `.line-delete-button` class값을 κ°€μ§„λ‹€. - -### μ§€ν•˜μ²  ꡬ간 μΆ”κ°€ κΈ°λŠ₯ -- μ§€ν•˜μ²  노선을 μ„ νƒν•˜λŠ” button νƒœκ·ΈλŠ” `.section-line-menu-button` class값을 κ°€μ§„λ‹€. -- μ§€ν•˜μ²  ꡬ간을 μ„€μ •ν•  μ—­ select νƒœκ·ΈλŠ” `#section-station-selector` id값을 κ°€μ§„λ‹€. -- μ§€ν•˜μ²  κ΅¬κ°„μ˜ μˆœμ„œλ₯Ό μž…λ ₯ν•˜λŠ” input νƒœκ·ΈλŠ” `#section-order-input` id값을 κ°€μ§„λ‹€. -- μ§€ν•˜μ²  ꡬ간을 λ“±λ‘ν•˜λŠ” button νƒœκ·ΈλŠ” `#section-add-button` id값을 κ°€μ§„λ‹€. -- μ§€ν•˜μ²  ꡬ간을 μ œκ±°ν•˜λŠ” button νƒœκ·ΈλŠ” `.section-delete-button` class값을 κ°€μ§„λ‹€. - -### μ§€ν•˜μ²  노선도 좜λ ₯ κΈ°λŠ₯ -- μ§€ν•˜μ²  노선도 좜λ ₯ λ²„νŠΌμ„ λˆ„λ₯΄λ©΄ `
` νƒœκ·Έλ₯Ό λ§Œλ“€κ³  ν•΄λ‹Ή νƒœκ·Έ 내뢀에 노선도λ₯Ό 좜λ ₯ν•œλ‹€. - -### κΈ°μ‘΄ μš”κ΅¬μ‚¬ν•­ - -- μ‚¬μš©μžκ°€ 잘λͺ»λœ μž…λ ₯ 값을 μž‘μ„±ν•œ 경우 `alert`을 μ΄μš©ν•΄ λ©”μ‹œμ§€λ₯Ό 보여주고, μž¬μž…λ ₯ν•  수 있게 ν•œλ‹€. -- μ™ΈλΆ€ 라이브러리(jQuery, Lodash λ“±)λ₯Ό μ‚¬μš©ν•˜μ§€ μ•Šκ³ , 순수 Vanilla JS둜만 κ΅¬ν˜„ν•œλ‹€. -- **μžλ°”μŠ€ν¬λ¦½νŠΈ μ½”λ“œ μ»¨λ²€μ…˜μ„ μ§€ν‚€λ©΄μ„œ ν”„λ‘œκ·Έλž˜λ°** ν•œλ‹€ - - [https://google.github.io/styleguide/jsguide.html](https://google.github.io/styleguide/jsguide.html) - - [https://ui.toast.com/fe-guide/ko_CODING-CONVENSION/](https://ui.toast.com/fe-guide/ko_CODING-CONVENTION) -- **indent(인덴트, λ“€μ—¬μ“°κΈ°) depthλ₯Ό 3이 λ„˜μ§€ μ•Šλ„λ‘ κ΅¬ν˜„ν•œλ‹€. 2κΉŒμ§€λ§Œ ν—ˆμš©**ν•œλ‹€. - - 예λ₯Ό λ“€μ–΄ whileλ¬Έ μ•ˆμ— if문이 있으면 λ“€μ—¬μ“°κΈ°λŠ” 2이닀. - - 힌트: indent(인덴트, λ“€μ—¬μ“°κΈ°) depthλ₯Ό μ€„μ΄λŠ” 쒋은 방법은 ν•¨μˆ˜(λ˜λŠ” λ©”μ†Œλ“œ)λ₯Ό λΆ„λ¦¬ν•˜λ©΄ λœλ‹€. -- **ν•¨μˆ˜(λ˜λŠ” λ©”μ†Œλ“œ)의 길이가 15라인을 λ„˜μ–΄κ°€μ§€ μ•Šλ„λ‘ κ΅¬ν˜„ν•œλ‹€.** - - ν•¨μˆ˜(λ˜λŠ” λ©”μ†Œλ“œ)κ°€ ν•œ κ°€μ§€ 일만 잘 ν•˜λ„λ‘ κ΅¬ν˜„ν•œλ‹€. -- λ³€μˆ˜ μ„ μ–Έμ‹œ `var` λ₯Ό μ‚¬μš©ν•˜μ§€ μ•ŠλŠ”λ‹€. `const` 와 `let` 을 μ‚¬μš©ν•œλ‹€. - - [const](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/const) - - [let](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/let) -- `import` 문을 μ΄μš©ν•΄ 슀크립트λ₯Ό λͺ¨λ“ˆν™”ν•˜κ³  뢈러올 수 있게 λ§Œλ“ λ‹€. - - [https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/import](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/import) -- `template literal`을 μ΄μš©ν•΄ 데이터와 html string을 가독성 μ’‹κ²Œ ν‘œν˜„ν•œλ‹€. - - [https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Template_literals](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Template_literals) - -### μΆ”κ°€λœ μš”κ΅¬μ‚¬ν•­ -- [data](https://developer.mozilla.org/ko/docs/Learn/HTML/Howto/%EB%8D%B0%EC%9D%B4%ED%84%B0_%EC%86%8D%EC%84%B1_%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0)속성을 ν™œμš©ν•˜μ—¬ html νƒœκ·Έμ— μ—­, λ…Έμ„ , κ΅¬κ°„μ˜ μœ μΌν•œ 데이터 값듀을 κ΄€λ¦¬ν•œλ‹€. -- [localStorage](https://developer.mozilla.org/ko/docs/Web/API/Window/localStorage)λ₯Ό μ΄μš©ν•˜μ—¬, μƒˆλ‘œκ³ μΉ¨ν•˜λ”λΌλ„ κ°€μž₯ μ΅œκ·Όμ— μž‘μ—…ν•œ 정보듀을 뢈러올 수 μžˆλ„λ‘ ν•œλ‹€. - -
- -## πŸ“ λ―Έμ…˜ μ €μž₯μ†Œ 및 μ§„ν–‰ μš”κ΅¬μ‚¬ν•­ - -- λ―Έμ…˜μ€ [https://github.com/woowacourse/javascript-subway-map-precours](https://github.com/woowacourse/javascript-subway-map-precourse) μ €μž₯μ†Œλ₯Ό fork/cloneν•΄ μ‹œμž‘ν•œλ‹€. -- **κΈ°λŠ₯을 κ΅¬ν˜„ν•˜κΈ° 전에 javascript-subway-precourse/docs/README.md νŒŒμΌμ— κ΅¬ν˜„ν•  κΈ°λŠ₯ λͺ©λ‘**을 정리해 μΆ”κ°€ν•œλ‹€. -- **git의 commit λ‹¨μœ„λŠ” μ•ž λ‹¨κ³„μ—μ„œ README.md νŒŒμΌμ— μ •λ¦¬ν•œ κΈ°λŠ₯ λͺ©λ‘ λ‹¨μœ„λ‘œ μΆ”κ°€**ν•œλ‹€. -- [ν”„λ¦¬μ½”μŠ€ 과제 제좜](https://github.com/woowacourse/woowacourse-docs/tree/master/precourse) λ¬Έμ„œ 절차λ₯Ό 따라 λ―Έμ…˜μ„ μ œμΆœν•œλ‹€. +10. μ‚¬μš©μž λ…Έμ„ μ˜ 상행 쒅점뢀터 ν•˜ν–‰ μ’…μ κΉŒμ§€ μ—°κ²°λœ μˆœμ„œλŒ€λ‘œ 전체 λ…Έμ„ κ³Ό μ—­ λͺ©λ‘μ„ μ‘°νšŒν•  수 μžˆλ‹€. From 5043ffe5403cf626a2e03d645c8eb268c546f5c2 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Mon, 14 Dec 2020 12:23:52 +0900 Subject: [PATCH 02/48] =?UTF-8?q?chore=20:=20gitignore=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..ae7194bd3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.ieda +.DS_Store From 7821a1cb7c69ceeddb1bc45d71ee8a4aacba43e6 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Mon, 14 Dec 2020 12:24:11 +0900 Subject: [PATCH 03/48] =?UTF-8?q?chore=20:=20eslint=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.json | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 000000000..ee22f13cf --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,26 @@ +{ + "env": { + "browser": true, + "es2021": true, + "node": true + }, + "extends": [ + "eslint:recommended", + "airbnb-base", + "prettier" + ], + "parserOptions": { + "ecmaVersion": 2015, + "sourceType": "module" + }, + "rules": { + "no-console": "off", + "no-plusplus": "off", + "class-methods-use-this": "off", + "radix": "off", + "no-restricted-properties": "off", + "max-depth" : ["error", 2], + "no-return-assign" : "off", + "no-continue" : "off" + } +} From 91181d61e0c3848155af9d2974eed848d42b1067 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Mon, 14 Dec 2020 12:24:26 +0900 Subject: [PATCH 04/48] =?UTF-8?q?chore=20:=20prettier=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierrc | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..13a6d0595 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,8 @@ +{ + "singleQuote": true, + "printWidth": 100, + "tabWidth": 2, + "useTabs": false, + "semi": true, + "arrowParens": "always" +} From 3e8a068b73f01b8dbbbcfd1817742881351fa4db Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Mon, 14 Dec 2020 13:07:44 +0900 Subject: [PATCH 05/48] =?UTF-8?q?feat=20:=20'=EC=97=AD=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC',=20'=EB=85=B8=EC=84=A0=20=EA=B4=80=EB=A6=AC',=20'?= =?UTF-8?q?=EA=B5=AC=EA=B0=84=20=EA=B4=80=EB=A6=AC',=20'=EC=A7=80=ED=95=98?= =?UTF-8?q?=EC=B2=A0=20=EB=85=B8=EC=84=A0=EB=8F=84=20=EC=B6=9C=EB=A0=A5'?= =?UTF-8?q?=20=EB=B2=84=ED=8A=BC=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 | 4 ++++ src/subwayMapApp.js | 24 ++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 src/subwayMapApp.js diff --git a/index.html b/index.html index fc99deac2..d87b907e5 100644 --- a/index.html +++ b/index.html @@ -3,10 +3,30 @@ μ§€ν•˜μ²  노선도 관리 +

πŸš‡ μ§€ν•˜μ²  노선도 관리

+
diff --git a/src/index.js b/src/index.js index e69de29bb..646aeb386 100644 --- a/src/index.js +++ b/src/index.js @@ -0,0 +1,4 @@ +import subwayMapApp from './subwayMapApp.js'; + +const $app = document.querySelector('#app'); +subwayMapApp($app); diff --git a/src/subwayMapApp.js b/src/subwayMapApp.js new file mode 100644 index 000000000..40af7055c --- /dev/null +++ b/src/subwayMapApp.js @@ -0,0 +1,24 @@ +export default function subwayMapApp($element) { + const $stationManagerBtn = $element.querySelector('#station-manager-button'); + const $lineManagerBtn = $element.querySelector('#line-manager-button'); + const $sectionManagerBtn = $element.querySelector('#section-manager-button'); + const $mapPrintManagerBtn = $element.querySelector('#map-print-manager-button'); + + const onStationManageHandler = () => { + console.log('역관리 μž…λ‹ˆλ‹€.'); + }; + const onLineManageHandler = () => { + console.log('라인관리 μž…λ‹ˆλ‹€.'); + }; + const onSectionManageHandler = () => { + console.log('노선관리 μž…λ‹ˆλ‹€.'); + }; + const onMapPrintManageHandler = () => { + console.log('전체 노선도 좜λ ₯ μž…λ‹ˆλ‹€.'); + }; + + $stationManagerBtn.addEventListener('click', onStationManageHandler); + $lineManagerBtn.addEventListener('click', onLineManageHandler); + $sectionManagerBtn.addEventListener('click', onSectionManageHandler); + $mapPrintManagerBtn.addEventListener('click', onMapPrintManageHandler); +} From 572997538cc46f3d650c2de1446d6c499542bbc7 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Mon, 14 Dec 2020 17:23:35 +0900 Subject: [PATCH 06/48] =?UTF-8?q?feat=20:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EB=8A=94=20=EC=97=AD=EC=9D=84=20=EB=93=B1=EB=A1=9D=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=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 - 역관리 templete κ΅¬ν˜„ - contentλ₯Ό ν‘œμ‹œν•  section νƒœκ·Έ 생성 - Station 객체 생성 - μ‚¬μš©μžκ°€ station을 μž…λ ₯ν•˜λ©΄ λ“±λ‘ν•˜λŠ” κΈ°λŠ₯ κ΅¬ν˜„ - localStorage에 λ“±λ‘ν•œ station μ €μž₯ν•˜λŠ” κΈ°λŠ₯ κ΅¬ν˜„ - μ€‘λ³΅λœ 이름 및 κΈ€μž 수 μ˜ˆμ™Έμ²˜λ¦¬ --- index.html | 6 ++++ src/components/stationManagerPage.js | 44 ++++++++++++++++++++++++++++ src/subwayMapApp.js | 10 +++++-- src/utils/Station.js | 13 ++++++++ src/utils/constant.js | 3 ++ src/utils/stationStorage.js | 20 +++++++++++++ src/utils/templete.js | 26 ++++++++++++++++ 7 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 src/components/stationManagerPage.js create mode 100644 src/utils/Station.js create mode 100644 src/utils/constant.js create mode 100644 src/utils/stationStorage.js create mode 100644 src/utils/templete.js diff --git a/index.html b/index.html index d87b907e5..c71f72567 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,11 @@ μ§€ν•˜μ²  노선도 관리 From 58d1f66cb4ab11eaa93f644dffdc7ee2acbd8e8b Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 02:54:19 +0900 Subject: [PATCH 18/48] =?UTF-8?q?docs=20:=20=EB=85=B8=EC=84=A0=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EA=B8=B0=EB=8A=A5=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a68c94b37..112f2b8bd 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ - [쑰건] λ…Έμ„  등둝 μ‹œ 상행 쒅점역과 ν•˜ν–‰ 쒅점역을 μž…λ ₯λ°›λŠ”λ‹€. - [μ˜ˆμ™Έμ²˜λ¦¬] μ€‘λ³΅λœ λ…Έμ„  이름이 μžˆλŠ”μ§€ 검증해야 ν•œλ‹€. - [μ˜ˆμ™Έμ²˜λ¦¬] ~μ„  ν˜•νƒœμ˜ 이름인지 검증해야 ν•œλ‹€. - - [μ˜ˆμ™Έμ²˜λ¦¬] μ‹œμž‘μ κ³Ό 끝점이 같은 노선이 μžˆλŠ”μ§€ 검증해야 ν•œλ‹€. + - [μ˜ˆμ™Έμ²˜λ¦¬] μ‹œμž‘ 쒅점과 ν•˜ν–‰ 쒅점이 같은 노선은 등둝할 수 μ—†λ‹€. + - [μ˜ˆμ™Έμ²˜λ¦¬] 상행 쒅점과 ν•˜ν–‰ 쒅점이 λ™μΌν•œ 기쑴의 노선이 μžˆλŠ”μ§€ 검증해야 ν•œλ‹€. + - [μ˜ˆμ™Έμ²˜λ¦¬] λ…Έμ„  이름은 무쑰건 μž…λ ₯ν•΄μ•Ό ν•œλ‹€. 6. μ‚¬μš©μžλŠ” μ§€ν•˜μ²  노선을 μ‚­μ œν•  수 μžˆλ‹€. 7. μ‚¬μš©μžλŠ” μ§€ν•˜μ²  λ…Έμ„ μ˜ λͺ©λ‘μ„ μ‘°νšŒν•  수 μžˆλ‹€. From c5b1472fd15888c0ef1fce2ca2af0d5d37d8a95c Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 03:37:44 +0900 Subject: [PATCH 19/48] =?UTF-8?q?fix=20:=20=EB=8B=A4=EB=A5=B8=20=EB=85=B8?= =?UTF-8?q?=EC=84=A0=EA=B3=BC=20=EB=8F=99=EC=9D=BC=ED=95=9C=20=EC=A2=85?= =?UTF-8?q?=EC=A0=90=EC=9D=84=20=EA=B0=80=EC=A7=80=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=ED=95=98=EB=8A=94=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - lineStorageμ—μ„œ 쒅점 station만 κ°€μ Έμ˜¬ 수 μžˆλ„λ‘ λ©”μ†Œλ“œ μΆ”κ°€ - 거꾸둜 ν–ˆμ„ λ•Œ 쒅점이 같아도 μ˜ˆμ™Έμ²˜λ¦¬ ν•  수 μžˆλ„λ‘ λ©”μ†Œλ“œ μΆ”κ°€ κ΅¬ν˜„ --- src/components/lineManagerPage.js | 2 +- src/utils/lineStorage.js | 18 ++++++++++++++ src/utils/validator/lineValidator.js | 36 +++++++++++++++++++--------- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/components/lineManagerPage.js b/src/components/lineManagerPage.js index 9680f281b..c5e0b4e03 100644 --- a/src/components/lineManagerPage.js +++ b/src/components/lineManagerPage.js @@ -60,7 +60,7 @@ export default function stationManagerPage($element) { if ( lineNameValidator(lines, newLineName) && - lineStationsValidator(lines, startStationName, endStationName) + lineStationsValidator(startStationName, endStationName) ) { createLine(newLineName, startStationName, endStationName); } diff --git a/src/utils/lineStorage.js b/src/utils/lineStorage.js index d2f2454fd..4992056b4 100644 --- a/src/utils/lineStorage.js +++ b/src/utils/lineStorage.js @@ -13,8 +13,26 @@ export default function lineStorage() { localStorage.setItem(LINE_STORAGE_NAME, JSON.stringify(line)); }; + const getStartPoints = () => { + if (!localStorage.getItem(LINE_STORAGE_NAME)) { + return []; + } + const startPoints = localStorage.getItem(LINE_STORAGE_NAME); + return JSON.parse(startPoints).map((line) => line.stations[0]); + }; + + const getEndPoints = () => { + if (!localStorage.getItem(LINE_STORAGE_NAME)) { + return []; + } + const startPoints = localStorage.getItem(LINE_STORAGE_NAME); + return JSON.parse(startPoints).map((line) => line.stations[line.stations.length - 1]); + }; + return { getLine, setLine, + getStartPoints, + getEndPoints, }; } diff --git a/src/utils/validator/lineValidator.js b/src/utils/validator/lineValidator.js index 29f87ef54..e4591c45b 100644 --- a/src/utils/validator/lineValidator.js +++ b/src/utils/validator/lineValidator.js @@ -1,3 +1,5 @@ +import lineStorage from '../lineStorage.js'; + const isEqualName = (lines, lineName) => { if (lines.some((line) => line.name === lineName)) { return alert('μ€‘λ³΅λœ λ…Έμ„  μ΄λ¦„μž…λ‹ˆλ‹€.'); @@ -26,16 +28,27 @@ const isEqualPoints = (startStationName, endStationName) => { return true; }; -const isEqualLine = (lines, startStationName, endStationName) => { - const linesStations = lines.map((line) => line.stations); - const linesPoints = linesStations.filter( - (currentLineStations, index) => index === 0 || index === currentLineStations.length - 1 - ); +const isEqualLine = (startStationName, endStationName) => { + const startStations = lineStorage() + .getStartPoints() + .map((station) => station.name === startStationName); + const endStations = lineStorage() + .getEndPoints() + .map((station) => station.name === endStationName); - const equalLine = linesPoints.filter( - (currentLinePoint) => - currentLinePoint[0].name === startStationName && currentLinePoint[1].name === endStationName - ); + const equalLine = startStations.filter((station, index) => station && endStations[index]); + return equalLine.length !== 0 ? alert('λ™μΌν•œ 쒅점을 κ°€μ§„ 노선이 μžˆμŠ΅λ‹ˆλ‹€') : true; +}; + +const isEqualReverseLine = (startStationName, endStationName) => { + const endStations = lineStorage() + .getStartPoints() + .map((station) => station.name === endStationName); + const StartStations = lineStorage() + .getEndPoints() + .map((station) => station.name === startStationName); + + const equalLine = StartStations.filter((station, index) => station && endStations[index]); return equalLine.length !== 0 ? alert('λ™μΌν•œ 쒅점을 κ°€μ§„ 노선이 μžˆμŠ΅λ‹ˆλ‹€') : true; }; @@ -43,10 +56,11 @@ function lineNameValidator(lines, lineName) { return isEqualName(lines, lineName) && isNameNotNull(lineName) && isCorrectName(lineName); } -function lineStationsValidator(lines, startStationName, endStationName) { +function lineStationsValidator(startStationName, endStationName) { return ( isEqualPoints(startStationName, endStationName) && - isEqualLine(lines, startStationName, endStationName) + isEqualLine(startStationName, endStationName) && + isEqualReverseLine(startStationName, endStationName) ); } From 7eced0bd0c6069c2462a6bac79b8f46a755ffe4b Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 03:41:22 +0900 Subject: [PATCH 20/48] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EA=B0=84=EA=B2=B0=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/validator/lineValidator.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/utils/validator/lineValidator.js b/src/utils/validator/lineValidator.js index e4591c45b..707dc97c9 100644 --- a/src/utils/validator/lineValidator.js +++ b/src/utils/validator/lineValidator.js @@ -1,31 +1,23 @@ import lineStorage from '../lineStorage.js'; const isEqualName = (lines, lineName) => { - if (lines.some((line) => line.name === lineName)) { - return alert('μ€‘λ³΅λœ λ…Έμ„  μ΄λ¦„μž…λ‹ˆλ‹€.'); - } - return true; + return lines.some((line) => line.name === lineName) ? alert('μ€‘λ³΅λœ λ…Έμ„  μ΄λ¦„μž…λ‹ˆλ‹€.') : true; }; const isNameNotNull = (lineName) => { - if (!lineName) { - return alert('λ…Έμ„  이름을 μž…λ ₯ν•΄μ£Όμ„Έμš”'); - } - return true; + return !lineName ? alert('λ…Έμ„  이름을 μž…λ ₯ν•΄μ£Όμ„Έμš”') : true; }; const isCorrectName = (lineName) => { - if (lineName.split('')[lineName.length - 1] !== 'μ„ ') { - return alert("λ…Έμ„ μ˜ 이름은 'μ„ '으둜 λλ‚˜μ•Ό ν•©λ‹ˆλ‹€"); - } - return true; + return lineName.split('')[lineName.length - 1] !== 'μ„ ' + ? alert("λ…Έμ„ μ˜ 이름은 'μ„ '으둜 λλ‚˜μ•Ό ν•©λ‹ˆλ‹€") + : true; }; const isEqualPoints = (startStationName, endStationName) => { - if (startStationName === endStationName) { - return alert('상행 쒅점과 ν•˜ν–‰ 쒅점은 μ„œλ‘œ 달라야 ν•©λ‹ˆλ‹€'); - } - return true; + return startStationName === endStationName + ? alert('상행 쒅점과 ν•˜ν–‰ 쒅점은 μ„œλ‘œ 달라야 ν•©λ‹ˆλ‹€') + : true; }; const isEqualLine = (startStationName, endStationName) => { From efbfbd4842c0ab9d4b5f845e8c20b5139e304593 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 03:58:34 +0900 Subject: [PATCH 21/48] =?UTF-8?q?feat=20:=20=EB=85=B8=EC=84=A0=EC=9D=84=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=ED=95=98=EB=8A=94=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 --- src/components/lineManagerPage.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/components/lineManagerPage.js b/src/components/lineManagerPage.js index c5e0b4e03..0d98abcd4 100644 --- a/src/components/lineManagerPage.js +++ b/src/components/lineManagerPage.js @@ -17,7 +17,7 @@ export default function stationManagerPage($element) { const $lineTableBody = $element.querySelector('.line-table-tbody'); const stations = stationStorage().getStation(); - const lines = lineStorage().getLine(); + let lines = lineStorage().getLine(); $startStation.innerHTML = ALL_STATION_OPTION_LIST(stations); $endStation.innerHTML = ALL_STATION_OPTION_LIST(stations); @@ -53,6 +53,22 @@ export default function stationManagerPage($element) { addLine(newLine); }; + const deleteLine = (stationTag) => { + console.log(stationTag); + lines = lines.filter((line) => line.id !== parseInt(stationTag.id)); + lineStorage().setLine(lines); + renderLines(); + }; + + const onLineDeleteHandler = (e) => { + if (!e.target.classList.contains('line-delete-button')) { + return; + } + if (confirm('μ •λ§λ‘œ μ‚­μ œν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ?')) { + deleteLine(e.target.closest('tr')); + } + }; + const onLineSubmitHandler = () => { const newLineName = $userInputLine.value; const startStationName = $startStation.value; @@ -68,5 +84,6 @@ export default function stationManagerPage($element) { }; $userLineSubmitBtn.addEventListener('click', onLineSubmitHandler); + $lineTableBody.addEventListener('click', onLineDeleteHandler); renderLines(); } From 3859a789566079cd278cfd9970287373d7a526c9 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 04:05:26 +0900 Subject: [PATCH 22/48] =?UTF-8?q?refactor=20:=20template=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/lineManagerPage.js | 2 +- src/components/stationManagerPage.js | 5 ++- .../template/lineManagerTemplate.js} | 32 +------------------ .../template/stationManagerTemplate.js | 25 +++++++++++++++ 4 files changed, 31 insertions(+), 33 deletions(-) rename src/{utils/templete.js => components/template/lineManagerTemplate.js} (65%) create mode 100644 src/components/template/stationManagerTemplate.js diff --git a/src/components/lineManagerPage.js b/src/components/lineManagerPage.js index 0d98abcd4..727cd0bdb 100644 --- a/src/components/lineManagerPage.js +++ b/src/components/lineManagerPage.js @@ -2,7 +2,7 @@ import { LINE_MANAGER_PAGE_TEMPLATE, ALL_STATION_OPTION_LIST, LINE_TABLE_TEMPLATE, -} from '../utils/templete.js'; +} from './template/lineManagerTemplate.js'; import { lineNameValidator, lineStationsValidator } from '../utils/validator/lineValidator.js'; import stationStorage from '../utils/stationStorage.js'; import lineStorage from '../utils/lineStorage.js'; diff --git a/src/components/stationManagerPage.js b/src/components/stationManagerPage.js index 74ec373af..e57222bf6 100644 --- a/src/components/stationManagerPage.js +++ b/src/components/stationManagerPage.js @@ -1,4 +1,7 @@ -import { STATION_MANAGER_PAGE_TEMPLATE, STATION_TABLE_TEMPLATE } from '../utils/templete.js'; +import { + STATION_MANAGER_PAGE_TEMPLATE, + STATION_TABLE_TEMPLATE, +} from './template/stationManagerTemplate.js'; import { stationNameValidator, stationDeleteValidation, diff --git a/src/utils/templete.js b/src/components/template/lineManagerTemplate.js similarity index 65% rename from src/utils/templete.js rename to src/components/template/lineManagerTemplate.js index b7cf0be2a..f973e67ce 100644 --- a/src/utils/templete.js +++ b/src/components/template/lineManagerTemplate.js @@ -1,27 +1,3 @@ -const STATION_MANAGER_PAGE_TEMPLATE = `

μ—­ 이름

- - -
- -

πŸš‰ μ§€ν•˜μ²  μ—­ λͺ©λ‘

- - - - - - - - -
μ—­ 이름섀정
-
`; - -const STATION_TABLE_TEMPLATE = (station) => { - return ` - ${station.name} - - `; -}; - const LINE_MANAGER_PAGE_TEMPLATE = `

λ…Έμ„  이름

@@ -71,10 +47,4 @@ const LINE_TABLE_TEMPLATE = (lines) => { `; }; -export { - STATION_MANAGER_PAGE_TEMPLATE, - STATION_TABLE_TEMPLATE, - LINE_MANAGER_PAGE_TEMPLATE, - ALL_STATION_OPTION_LIST, - LINE_TABLE_TEMPLATE, -}; +export { LINE_MANAGER_PAGE_TEMPLATE, ALL_STATION_OPTION_LIST, LINE_TABLE_TEMPLATE }; diff --git a/src/components/template/stationManagerTemplate.js b/src/components/template/stationManagerTemplate.js new file mode 100644 index 000000000..b6fdc37f9 --- /dev/null +++ b/src/components/template/stationManagerTemplate.js @@ -0,0 +1,25 @@ +const STATION_MANAGER_PAGE_TEMPLATE = `

μ—­ 이름

+ + +
+ +

πŸš‰ μ§€ν•˜μ²  μ—­ λͺ©λ‘

+ + + + + + + + +
μ—­ 이름섀정
+
`; + +const STATION_TABLE_TEMPLATE = (station) => { + return ` + ${station.name} + + `; +}; + +export { STATION_MANAGER_PAGE_TEMPLATE, STATION_TABLE_TEMPLATE }; From 5f9b81e1574649c0486d861dd6c0d59a84d4a5fa Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 04:05:50 +0900 Subject: [PATCH 23/48] =?UTF-8?q?docs=20:=20README=20=EC=98=A4=ED=83=80=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 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 112f2b8bd..f402a1dad 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ ### μ§€ν•˜μ²  ꡬ간 μΆ”κ°€ κΈ°λŠ₯ 8. μ‚¬μš©μžλŠ” 노선에 역을 μΆ”κ°€ν•  수 μžˆλ‹€. - - [μ˜ˆμ™Έμ²˜λ¦¬] μ€‘λ³΅λœ 노선이 μžˆλŠ”μ§€ 검증해야 ν•œλ‹€. + - [μ˜ˆμ™Έμ²˜λ¦¬] μ€‘λ³΅λœ 역이 μžˆλŠ”μ§€ 검증해야 ν•œλ‹€. - [쑰건] ν•˜λ‚˜μ˜ 역은 μ—¬λŸ¬κ°œμ˜ 노선에 좔가될 수 μžˆλ‹€. - [쑰건] μ—­κ³Ό μ—­ 사이에 μƒˆλ‘œμš΄ 역이 μΆ”κ°€ 될 수 μžˆλ‹€. - [쑰건] λ…Έμ„ μ—μ„œ κ°ˆλž˜κΈΈμ€ 생길 수 μ—†λ‹€. From 603b9a4d7505579a875953263ff6914fc8040b9b Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 04:50:15 +0900 Subject: [PATCH 24/48] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EA=B0=84=EB=9E=B5=ED=95=98=EA=B2=8C=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/lineStorage.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/utils/lineStorage.js b/src/utils/lineStorage.js index 4992056b4..69dd888a1 100644 --- a/src/utils/lineStorage.js +++ b/src/utils/lineStorage.js @@ -14,19 +14,11 @@ export default function lineStorage() { }; const getStartPoints = () => { - if (!localStorage.getItem(LINE_STORAGE_NAME)) { - return []; - } - const startPoints = localStorage.getItem(LINE_STORAGE_NAME); - return JSON.parse(startPoints).map((line) => line.stations[0]); + return getLine().map((line) => line.stations[0]); }; const getEndPoints = () => { - if (!localStorage.getItem(LINE_STORAGE_NAME)) { - return []; - } - const startPoints = localStorage.getItem(LINE_STORAGE_NAME); - return JSON.parse(startPoints).map((line) => line.stations[line.stations.length - 1]); + return getLine().map((line) => line.stations[line.stations.length - 1]); }; return { From b2663733edebdde3386fdb71fb048767808e765f Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 05:37:23 +0900 Subject: [PATCH 25/48] =?UTF-8?q?docs=20:=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EB=AA=A9=EB=A1=9D=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 --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f402a1dad..a7a818659 100644 --- a/README.md +++ b/README.md @@ -23,17 +23,16 @@ 6. μ‚¬μš©μžλŠ” μ§€ν•˜μ²  노선을 μ‚­μ œν•  수 μžˆλ‹€. 7. μ‚¬μš©μžλŠ” μ§€ν•˜μ²  λ…Έμ„ μ˜ λͺ©λ‘μ„ μ‘°νšŒν•  수 μžˆλ‹€. -### μ§€ν•˜μ²  ꡬ간 μΆ”κ°€ κΈ°λŠ₯ +### μ§€ν•˜μ²  ꡬ간 κ΄€λ ¨ κΈ°λŠ₯ 8. μ‚¬μš©μžλŠ” 노선에 역을 μΆ”κ°€ν•  수 μžˆλ‹€. - [μ˜ˆμ™Έμ²˜λ¦¬] μ€‘λ³΅λœ 역이 μžˆλŠ”μ§€ 검증해야 ν•œλ‹€. - [쑰건] ν•˜λ‚˜μ˜ 역은 μ—¬λŸ¬κ°œμ˜ 노선에 좔가될 수 μžˆλ‹€. - [쑰건] μ—­κ³Ό μ—­ 사이에 μƒˆλ‘œμš΄ 역이 μΆ”κ°€ 될 수 μžˆλ‹€. - [쑰건] λ…Έμ„ μ—μ„œ κ°ˆλž˜κΈΈμ€ 생길 수 μ—†λ‹€. - -### μ§€ν•˜μ²  ꡬ간 μ‚­μ œ κΈ°λŠ₯ 9. μ‚¬μš©μžλŠ” λ…Έμ„ μ˜ 역을 μ‚­μ œν•  수 μžˆλ‹€. - [μ˜ˆμ™Έμ²˜λ¦¬] 노선에 역이 2개 μ΄ν•˜μΈμ§€ κ²€μ¦ν•˜κ³ , 2개 μ΄ν•˜λ©΄ μ‚­μ œν•  수 μ—†λ‹€. - [쑰건] 쒅점을 μ œκ±°ν•  경우 λ‹€μŒ 역이 쒅점이 λœλ‹€. +10. μ‚¬μš©μžλŠ” λ…Έμ„  λ³„λ‘œ μ—­μ˜ λͺ©λ‘μ„ λ³Ό 수 μžˆλ‹€. ### μ§€ν•˜μ²  노선에 λ“±λ‘λœ μ—­ 쑰회 κΈ°λŠ₯ -10. μ‚¬μš©μž λ…Έμ„ μ˜ 상행 쒅점뢀터 ν•˜ν–‰ μ’…μ κΉŒμ§€ μ—°κ²°λœ μˆœμ„œλŒ€λ‘œ 전체 λ…Έμ„ κ³Ό μ—­ λͺ©λ‘μ„ μ‘°νšŒν•  수 μžˆλ‹€. +11. μ‚¬μš©μž λ…Έμ„ μ˜ 상행 쒅점뢀터 ν•˜ν–‰ μ’…μ κΉŒμ§€ μ—°κ²°λœ μˆœμ„œλŒ€λ‘œ 전체 λ…Έμ„ κ³Ό μ—­ λͺ©λ‘μ„ μ‘°νšŒν•  수 μžˆλ‹€. From dfcddd016fe77eabaa3aef5d121694a4371f7818 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 05:40:09 +0900 Subject: [PATCH 26/48] =?UTF-8?q?feat=20:=20=EB=85=B8=EC=84=A0=20=EB=B3=84?= =?UTF-8?q?=EB=A1=9C=20=EC=97=AD=EC=9D=98=20=EB=AA=A9=EB=A1=9D=EC=9D=84=20?= =?UTF-8?q?=EB=B3=BC=20=EC=88=98=20=EC=9E=88=EB=8A=94=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ꡬ간 등둝 ν™”λ©΄ template κ΅¬ν˜„ - μ‚¬μš©μžκ°€ 노선을 μ„ νƒν•˜λ©΄ λ…Έμ„ μ˜ ꡬ간 λͺ©λ‘ ν…Œμ΄λΈ”μ„ λ³Ό 수 μžˆλ„λ‘ κ΅¬ν˜„ - localStorage에 ν•œκ°œμ˜ λ…Έμ„ λ§Œ κ°€μ Έμ˜€λŠ” κΈ°λŠ₯ κ΅¬ν˜„ --- src/components/sectionManagerPage.js | 42 ++++++++++++++++ .../template/sectionManagerTemplate.js | 48 +++++++++++++++++++ src/subwayMapApp.js | 3 +- src/utils/lineStorage.js | 5 ++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/components/sectionManagerPage.js create mode 100644 src/components/template/sectionManagerTemplate.js diff --git a/src/components/sectionManagerPage.js b/src/components/sectionManagerPage.js new file mode 100644 index 000000000..ab6f925d7 --- /dev/null +++ b/src/components/sectionManagerPage.js @@ -0,0 +1,42 @@ +import { + SECTION_MANAGER_PAGE_MENU_TEMPLATE, + SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE, + SECTION_MANAGER_PAGE_TABLE_TEMPLATE, + SECTION_LINE_MENU_BTN, + SECTION_TABLE_TEMPLATE, +} from './template/sectionManagerTemplate.js'; +import lineStorage from '../utils/lineStorage.js'; +import stationStorage from '../utils/stationStorage.js'; +import { ALL_STATION_OPTION_LIST } from './template/lineManagerTemplate.js'; + +export default function sectionManagerPage($element) { + const lines = lineStorage().getLine(); + const stations = stationStorage().getStation(); + + $element.innerHTML = SECTION_MANAGER_PAGE_MENU_TEMPLATE; + const $listMenuBtn = $element.querySelector('.line-buttons'); + $listMenuBtn.innerHTML = lines.map(SECTION_LINE_MENU_BTN).join(''); + const $sectionSelectorContainer = $element.querySelector('#section-selector-container'); + const $lineTitle = $element.querySelector('#line-title'); + + const renderSectionManager = (currentLine) => { + $lineTitle.innerText = `${currentLine.name} 관리`; + $sectionSelectorContainer.innerHTML = SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE; + const $sectionSelector = $element.querySelector('#section-station-selector'); + const $sectionTable = $element.querySelector('#section-table'); + $sectionSelector.innerHTML = ALL_STATION_OPTION_LIST(stations); + $sectionTable.innerHTML = SECTION_MANAGER_PAGE_TABLE_TEMPLATE; + const $sectionTableBody = $element.querySelector('.section-table-tbody'); + $sectionTableBody.innerHTML = SECTION_TABLE_TEMPLATE(currentLine); + }; + + const onMenuFilterHandler = (e) => { + if (!e.target.classList.contains('section-line-menu-button')) { + return; + } + const currentLine = lineStorage().getOneLine(e.target.dataset.lineid); + renderSectionManager(currentLine); + }; + + $listMenuBtn.addEventListener('click', onMenuFilterHandler); +} diff --git a/src/components/template/sectionManagerTemplate.js b/src/components/template/sectionManagerTemplate.js new file mode 100644 index 000000000..decf94dc9 --- /dev/null +++ b/src/components/template/sectionManagerTemplate.js @@ -0,0 +1,48 @@ +const SECTION_MANAGER_PAGE_MENU_TEMPLATE = `
+

ꡬ간을 μˆ˜μ •ν•  노선을 μ„ νƒν•΄μ£Όμ„Έμš”

+ +

+
+
+
`; + +const SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE = `

ꡬ간 등둝

+ + + `; + +const SECTION_MANAGER_PAGE_TABLE_TEMPLATE = ` + + + + + + + + +
μˆœμ„œμ΄λ¦„μ„€μ •
`; + +const SECTION_TABLE_TEMPLATE = ({ id, stations }) => { + return stations + .map( + (station, index) => + ` + ${index} + ${station.name} + + ` + ) + .join(''); +}; + +const SECTION_LINE_MENU_BTN = (line) => { + return ``; +}; + +export { + SECTION_MANAGER_PAGE_MENU_TEMPLATE, + SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE, + SECTION_MANAGER_PAGE_TABLE_TEMPLATE, + SECTION_LINE_MENU_BTN, + SECTION_TABLE_TEMPLATE, +}; diff --git a/src/subwayMapApp.js b/src/subwayMapApp.js index ca45e56c7..e5d096bae 100644 --- a/src/subwayMapApp.js +++ b/src/subwayMapApp.js @@ -1,5 +1,6 @@ import stationManagerPage from './components/stationManagerPage.js'; import lineManagerPage from './components/lineManagerPage.js'; +import sectionManagerPage from './components/sectionManagerPage.js'; export default function subwayMapApp($element) { const $stationManagerBtn = $element.querySelector('#station-manager-button'); @@ -15,7 +16,7 @@ export default function subwayMapApp($element) { lineManagerPage($contentSection); }; const onSectionManageHandler = () => { - console.log('ꡬ간관리 μž…λ‹ˆλ‹€.'); + sectionManagerPage($contentSection); }; const onMapPrintManageHandler = () => { console.log('전체 노선도 좜λ ₯ μž…λ‹ˆλ‹€.'); diff --git a/src/utils/lineStorage.js b/src/utils/lineStorage.js index 69dd888a1..9c96fa272 100644 --- a/src/utils/lineStorage.js +++ b/src/utils/lineStorage.js @@ -21,10 +21,15 @@ export default function lineStorage() { return getLine().map((line) => line.stations[line.stations.length - 1]); }; + const getOneLine = (lineId) => { + return getLine().filter((line) => line.id === parseInt(lineId))[0]; + }; + return { getLine, setLine, getStartPoints, getEndPoints, + getOneLine, }; } From 1cd523974988070f291b4cdc14f83027653cfba8 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 05:40:21 +0900 Subject: [PATCH 27/48] =?UTF-8?q?style=20:=20=20html=20=EC=8A=A4=ED=83=80?= =?UTF-8?q?=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.html b/index.html index ed6d4b063..3012bea43 100644 --- a/index.html +++ b/index.html @@ -14,9 +14,17 @@ color: black; } + button { + margin-left : 0.2rem; + } + .select-line-points { margin: 1rem 0; } + + #section-selector-container{ + margin-bottom: 2rem; + } From abf48efb8add1f96e031670dfa02efc2833f35f1 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 16:28:31 +0900 Subject: [PATCH 28/48] =?UTF-8?q?refactor=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/Station.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/utils/Station.js b/src/utils/Station.js index 38981c886..07c1baf13 100644 --- a/src/utils/Station.js +++ b/src/utils/Station.js @@ -2,12 +2,4 @@ export default function Station(id, name) { this.id = id; this.name = name; this.line = []; - - this.setLine = (lineName) => { - if (this.line.includes(lineName)) { - alert(`${lineName}에 이미 ${name}역이 ν¬ν•¨λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.`); - } else { - this.line.push(lineName); - } - }; } From 10706542412be4152c48a56be2afae4a8d8bc03a Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 16:29:33 +0900 Subject: [PATCH 29/48] =?UTF-8?q?feat=20:=20station=20localstorag=EC=97=90?= =?UTF-8?q?=EC=84=9C=20id=EC=99=80=20=EC=9D=B4=EB=A6=84=EC=9C=BC=EB=A1=9C?= =?UTF-8?q?=20station,=20id=20=EA=B0=80=EC=A7=80=EA=B3=A0=20=EC=98=A4?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/stationStorage.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/utils/stationStorage.js b/src/utils/stationStorage.js index dd818caed..5ea458c16 100644 --- a/src/utils/stationStorage.js +++ b/src/utils/stationStorage.js @@ -1,7 +1,7 @@ import { STATION_STORAGE_NAME } from './constant.js'; export default function stationStorage() { - const getStation = () => { + const getStations = () => { if (!localStorage.getItem(STATION_STORAGE_NAME)) { return []; } @@ -13,8 +13,18 @@ export default function stationStorage() { localStorage.setItem(STATION_STORAGE_NAME, JSON.stringify(station)); }; + const getStationIdByName = (stationName) => { + return getStations().filter((station) => station.name === stationName)[0].id; + }; + + const getStationIdById = (stationId) => { + return getStations().filter((station) => station.id === stationId)[0]; + }; + return { - getStation, + getStations, setStation, + getStationIdByName, + getStationIdById, }; } From faa4e32ec448be17c71fa4d2d050de648ef6eaea Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 16:29:52 +0900 Subject: [PATCH 30/48] =?UTF-8?q?refactor=20:=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EB=AA=85=20=EC=88=98=EC=A0=95=ED=95=9C=EA=B1=B0=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/stationManagerPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/stationManagerPage.js b/src/components/stationManagerPage.js index e57222bf6..c43e32225 100644 --- a/src/components/stationManagerPage.js +++ b/src/components/stationManagerPage.js @@ -15,7 +15,7 @@ export default function stationManagerPage($element) { const $userStationSubmit = $element.querySelector('#station-add-button'); const $stationTablebody = $element.querySelector('.station_manager_tbody'); - let stations = stationStorage().getStation(); + let stations = stationStorage().getStations(); const showStations = () => { $stationTablebody.innerHTML = stations.map(STATION_TABLE_TEMPLATE).join(''); From 24da4655273396e09ef05c5907b03d3f81044ec5 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 16:32:45 +0900 Subject: [PATCH 31/48] =?UTF-8?q?refactor=20:=20line=20storage=20=EC=86=8D?= =?UTF-8?q?=EC=84=B1=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=EB=85=B8=EC=84=A0?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C,=EB=93=B1=EB=A1=9D=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - line storageμ—μ„œ station λͺ¨λ‘λ₯Ό κ°€μ§€κ³  μžˆλŠ” κ²ƒμ—μ„œ id만 κ°€μ§€κ³  있게 μˆ˜μ • - 노선을 λ“±λ‘ν•˜κ³  μ‚­μ œν•  λ•Œ, station storage에 μ μš©μ•ˆλ˜λ˜ 것 적용되게 μˆ˜μ • --- src/components/lineManagerPage.js | 45 ++++++++++++++----- .../template/lineManagerTemplate.js | 19 +++++--- src/utils/Line.js | 9 ++-- src/utils/lineStorage.js | 12 ++--- src/utils/validator/lineValidator.js | 39 +++++++++------- 5 files changed, 80 insertions(+), 44 deletions(-) diff --git a/src/components/lineManagerPage.js b/src/components/lineManagerPage.js index 727cd0bdb..db33ab3f7 100644 --- a/src/components/lineManagerPage.js +++ b/src/components/lineManagerPage.js @@ -16,7 +16,7 @@ export default function stationManagerPage($element) { const $userLineSubmitBtn = $element.querySelector('#line-add-button'); const $lineTableBody = $element.querySelector('.line-table-tbody'); - const stations = stationStorage().getStation(); + const stations = stationStorage().getStations(); let lines = lineStorage().getLine(); $startStation.innerHTML = ALL_STATION_OPTION_LIST(stations); @@ -40,22 +40,45 @@ export default function stationManagerPage($element) { }; const getStation = (stationName) => { - return stations.filter((station) => station.name === stationName); + return stations.filter((station) => station.name === stationName)[0]; }; - const createLine = (newLineName, startStationName, endStationName) => { - const startStation = getStation(startStationName)[0]; - const endStation = getStation(endStationName)[0]; + const getStationById = (stationIds) => { + return stations.filter((station) => station.id === stationIds)[0]; + }; + const addLineInStation = (lineId, stationName) => { + getStation(stationName).line.push(lineId); + stationStorage().setStation(stations); + }; + + const createLine = (newLineName, startStationName, endStationName) => { + const startStationId = stationStorage().getStationIdByName(startStationName); + const endStationId = stationStorage().getStationIdByName(endStationName); const newLine = new Line(getNewId(), newLineName); - newLine.setLine(startStation, 0); - newLine.setLine(endStation, 1); + newLine.setLine(startStationId, 0); + newLine.setLine(endStationId, 1); + + addLineInStation(newLine.id, startStationName); + addLineInStation(newLine.id, endStationName); addLine(newLine); }; - const deleteLine = (stationTag) => { - console.log(stationTag); - lines = lines.filter((line) => line.id !== parseInt(stationTag.id)); + const removeLineInStation = (currentLineId) => { + const stationIdsInLine = lines.filter((line) => line.id === parseInt(currentLineId))[0] + .stationIds; + + const stationsInLine = stationIdsInLine.map(getStationById); + for (let i = 0; i < stationsInLine.length; i++) { + const deleteIndex = stationsInLine[i].line.indexOf(parseInt(currentLineId)); + stationsInLine[i].line.splice(deleteIndex, 1); + } + stationStorage().setStation(stations); + }; + + const removeLine = (currentLineId) => { + removeLineInStation(currentLineId); + lines = lines.filter((line) => line.id !== parseInt(currentLineId)); lineStorage().setLine(lines); renderLines(); }; @@ -65,7 +88,7 @@ export default function stationManagerPage($element) { return; } if (confirm('μ •λ§λ‘œ μ‚­μ œν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ?')) { - deleteLine(e.target.closest('tr')); + removeLine(e.target.closest('tr').id); } }; diff --git a/src/components/template/lineManagerTemplate.js b/src/components/template/lineManagerTemplate.js index f973e67ce..a50ce5a1c 100644 --- a/src/components/template/lineManagerTemplate.js +++ b/src/components/template/lineManagerTemplate.js @@ -1,3 +1,5 @@ +import stationStorage from '../../utils/stationStorage.js'; + const LINE_MANAGER_PAGE_TEMPLATE = `

λ…Έμ„  이름

@@ -36,13 +38,18 @@ const ALL_STATION_OPTION_LIST = (stations) => { .join(''); }; -const LINE_TABLE_TEMPLATE = (lines) => { - const lineLength = lines.stations.length; +const LINE_TABLE_TEMPLATE = (line) => { + const lastStationId = line.stationIds[line.stationIds.length - 1]; + const firstStationId = line.stationIds[0]; - return ` - ${lines.name} - ${lines.stations[0].name} - ${lines.stations[lineLength - 1].name} + return ` + ${line.name} + ${ + stationStorage().getStationIdById(firstStationId).name + } + ${ + stationStorage().getStationIdById(lastStationId).name + } `; }; diff --git a/src/utils/Line.js b/src/utils/Line.js index a2a3b703a..c82eb4369 100644 --- a/src/utils/Line.js +++ b/src/utils/Line.js @@ -1,13 +1,12 @@ export default function Line(id, name) { this.id = id; this.name = name; - this.stations = []; + this.stationIds = []; - this.setLine = (Station, index) => { - const stationNames = this.stations.map((station) => station.name); - if (stationNames.includes(Station)) { + this.setLine = (stationId, index) => { + if (this.stationIds.includes(stationId)) { alert('이미 λ“±λ‘λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€'); } - this.stations.splice(index, 0, Station); + this.stationIds.splice(index, 0, stationId); }; } diff --git a/src/utils/lineStorage.js b/src/utils/lineStorage.js index 9c96fa272..9b33232d5 100644 --- a/src/utils/lineStorage.js +++ b/src/utils/lineStorage.js @@ -13,12 +13,12 @@ export default function lineStorage() { localStorage.setItem(LINE_STORAGE_NAME, JSON.stringify(line)); }; - const getStartPoints = () => { - return getLine().map((line) => line.stations[0]); + const getStartPointsId = () => { + return getLine().map((line) => line.stationIds[0]); }; - const getEndPoints = () => { - return getLine().map((line) => line.stations[line.stations.length - 1]); + const getEndPointsId = () => { + return getLine().map((line) => line.stationIds[line.stationIds.length - 1]); }; const getOneLine = (lineId) => { @@ -28,8 +28,8 @@ export default function lineStorage() { return { getLine, setLine, - getStartPoints, - getEndPoints, + getStartPointsId, + getEndPointsId, getOneLine, }; } diff --git a/src/utils/validator/lineValidator.js b/src/utils/validator/lineValidator.js index 707dc97c9..d93acb6fc 100644 --- a/src/utils/validator/lineValidator.js +++ b/src/utils/validator/lineValidator.js @@ -1,4 +1,5 @@ import lineStorage from '../lineStorage.js'; +import stationStorage from '../stationStorage.js'; const isEqualName = (lines, lineName) => { return lines.some((line) => line.name === lineName) ? alert('μ€‘λ³΅λœ λ…Έμ„  μ΄λ¦„μž…λ‹ˆλ‹€.') : true; @@ -21,26 +22,32 @@ const isEqualPoints = (startStationName, endStationName) => { }; const isEqualLine = (startStationName, endStationName) => { - const startStations = lineStorage() - .getStartPoints() - .map((station) => station.name === startStationName); - const endStations = lineStorage() - .getEndPoints() - .map((station) => station.name === endStationName); - - const equalLine = startStations.filter((station, index) => station && endStations[index]); + const startStationId = stationStorage().getStationIdByName(startStationName); + const endStationId = stationStorage().getStationIdByName(endStationName); + + const startStationIds = lineStorage() + .getStartPointsId() + .map((stationId) => stationId === parseInt(startStationId)); + const endStationIds = lineStorage() + .getEndPointsId() + .map((stationId) => stationId === parseInt(endStationId)); + + const equalLine = startStationIds.filter((station, index) => station && endStationIds[index]); return equalLine.length !== 0 ? alert('λ™μΌν•œ 쒅점을 κ°€μ§„ 노선이 μžˆμŠ΅λ‹ˆλ‹€') : true; }; const isEqualReverseLine = (startStationName, endStationName) => { - const endStations = lineStorage() - .getStartPoints() - .map((station) => station.name === endStationName); - const StartStations = lineStorage() - .getEndPoints() - .map((station) => station.name === startStationName); - - const equalLine = StartStations.filter((station, index) => station && endStations[index]); + const startStationId = stationStorage().getStationIdByName(startStationName); + const endStationId = stationStorage().getStationIdByName(endStationName); + + const endStationsIds = lineStorage() + .getStartPointsId() + .map((stationId) => stationId === parseInt(startStationId)); + const StartStationsIds = lineStorage() + .getEndPointsId() + .map((stationId) => stationId === parseInt(endStationId)); + + const equalLine = StartStationsIds.filter((station, index) => station && endStationsIds[index]); return equalLine.length !== 0 ? alert('λ™μΌν•œ 쒅점을 κ°€μ§„ 노선이 μžˆμŠ΅λ‹ˆλ‹€') : true; }; From 0553dcd1d8348737e477e39927def9b24f5d08cb Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 16:41:19 +0900 Subject: [PATCH 32/48] =?UTF-8?q?refatcor=20:=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EC=9E=98=EB=AA=BB=EB=90=9C=20=EA=B2=83=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/components/template/lineManagerTemplate.js | 8 ++++---- src/utils/stationStorage.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/template/lineManagerTemplate.js b/src/components/template/lineManagerTemplate.js index a50ce5a1c..1255fc9c0 100644 --- a/src/components/template/lineManagerTemplate.js +++ b/src/components/template/lineManagerTemplate.js @@ -44,11 +44,11 @@ const LINE_TABLE_TEMPLATE = (line) => { return ` ${line.name} - ${ - stationStorage().getStationIdById(firstStationId).name + ${ + stationStorage().getStationById(firstStationId).name } - ${ - stationStorage().getStationIdById(lastStationId).name + ${ + stationStorage().getStationById(lastStationId).name } `; diff --git a/src/utils/stationStorage.js b/src/utils/stationStorage.js index 5ea458c16..4289c4018 100644 --- a/src/utils/stationStorage.js +++ b/src/utils/stationStorage.js @@ -17,7 +17,7 @@ export default function stationStorage() { return getStations().filter((station) => station.name === stationName)[0].id; }; - const getStationIdById = (stationId) => { + const getStationById = (stationId) => { return getStations().filter((station) => station.id === stationId)[0]; }; @@ -25,6 +25,6 @@ export default function stationStorage() { getStations, setStation, getStationIdByName, - getStationIdById, + getStationById, }; } From 1649fa568b642dbeb0c8d57acd728884bdd7c1d2 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 17:11:41 +0900 Subject: [PATCH 33/48] =?UTF-8?q?feat=20:=20=EB=85=B8=EC=84=A0=EC=97=90=20?= =?UTF-8?q?=EC=97=AD=20=EC=B6=94=EA=B0=80=ED=95=98=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - μ€‘λ³΅λœ 역이 μ—†λŠ”μ§€ μœ νš¨μ„± 검사 κ΅¬ν˜„ - μž…λ ₯ν•˜λŠ” index의 μœ νš¨μ„± 검사 κ΅¬ν˜„ --- src/components/oneSectionManager.js | 77 +++++++++++++++++++ src/components/sectionManagerPage.js | 22 +----- .../template/sectionManagerTemplate.js | 16 ++-- src/utils/validator/sectionValidator.js | 30 ++++++++ 4 files changed, 120 insertions(+), 25 deletions(-) create mode 100644 src/components/oneSectionManager.js create mode 100644 src/utils/validator/sectionValidator.js diff --git a/src/components/oneSectionManager.js b/src/components/oneSectionManager.js new file mode 100644 index 000000000..ccf0a7be7 --- /dev/null +++ b/src/components/oneSectionManager.js @@ -0,0 +1,77 @@ +import { + sectionIndexValidator, + sectionStationNameValidator, +} from '../utils/validator/sectionValidator.js'; +import { + SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE, + SECTION_MANAGER_PAGE_TABLE_TEMPLATE, + SECTION_TABLE_TEMPLATE, +} from './template/sectionManagerTemplate.js'; +import { ALL_STATION_OPTION_LIST } from './template/lineManagerTemplate.js'; +import stationStorage from '../utils/stationStorage.js'; +import lineStorage from '../utils/lineStorage.js'; + +export default function oneSectionManager($container, $table, line) { + const stations = stationStorage().getStations(); + const lines = lineStorage().getLine(); + + $container.innerHTML = SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE; + const $lineTitle = $container.querySelector('#line-title'); + $lineTitle.innerText = `${line.name} 관리`; + + const $sectionSelector = $container.querySelector('#section-station-selector'); + $sectionSelector.innerHTML = ALL_STATION_OPTION_LIST(stations); + + $table.innerHTML = SECTION_MANAGER_PAGE_TABLE_TEMPLATE; + const $sectionTableBody = $table.querySelector('.section-table-tbody'); + $sectionTableBody.innerHTML = SECTION_TABLE_TEMPLATE(line); + + const $userSectionIndexInput = $container.querySelector('#section-order-input'); + const $userSelectStationBtn = $container.querySelector('#section-station-selector'); + const $userSectionSubmitBtn = $container.querySelector('#section-add-button'); + + const renderSection = (newLine) => { + $sectionTableBody.innerHTML = SECTION_TABLE_TEMPLATE(newLine); + }; + + const getStationById = (stationIds) => { + return stations.filter((station) => station.id === stationIds)[0]; + }; + + const updateLineState = (stationId, stationIndex) => { + line.stationIds.splice(stationIndex, 0, stationId); + for (let i = 0; i < lines.length; i++) { + if (lines[i].id === line.id) { + lines[i] = line; + } + } + lineStorage().setLine(lines); + return line; + }; + + const updateStationState = (stationId) => { + getStationById(stationId).line.push(line.id); + stationStorage().setStation(stations); + }; + + const updateSection = (stationName, stationIndex) => { + const stationId = stationStorage().getStationIdByName(stationName); + updateStationState(stationIndex); + renderSection(updateLineState(stationId, stationIndex)); + }; + + const onSectionSubmitHandler = () => { + const userSelectStationName = $userSelectStationBtn.value; + const userSectionIndex = parseInt($userSectionIndexInput.value); + + if ( + sectionStationNameValidator(line, stations, userSelectStationName) && + sectionIndexValidator(line.stationIds.length, userSectionIndex) + ) { + updateSection(userSelectStationName, userSectionIndex); + } + $userSectionIndexInput.value = ''; + }; + + $userSectionSubmitBtn.addEventListener('click', onSectionSubmitHandler); +} diff --git a/src/components/sectionManagerPage.js b/src/components/sectionManagerPage.js index ab6f925d7..9f86347bc 100644 --- a/src/components/sectionManagerPage.js +++ b/src/components/sectionManagerPage.js @@ -1,41 +1,25 @@ import { SECTION_MANAGER_PAGE_MENU_TEMPLATE, - SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE, - SECTION_MANAGER_PAGE_TABLE_TEMPLATE, SECTION_LINE_MENU_BTN, - SECTION_TABLE_TEMPLATE, } from './template/sectionManagerTemplate.js'; import lineStorage from '../utils/lineStorage.js'; -import stationStorage from '../utils/stationStorage.js'; -import { ALL_STATION_OPTION_LIST } from './template/lineManagerTemplate.js'; +import oneSectionManager from './oneSectionManager.js'; export default function sectionManagerPage($element) { const lines = lineStorage().getLine(); - const stations = stationStorage().getStation(); $element.innerHTML = SECTION_MANAGER_PAGE_MENU_TEMPLATE; const $listMenuBtn = $element.querySelector('.line-buttons'); $listMenuBtn.innerHTML = lines.map(SECTION_LINE_MENU_BTN).join(''); const $sectionSelectorContainer = $element.querySelector('#section-selector-container'); - const $lineTitle = $element.querySelector('#line-title'); - - const renderSectionManager = (currentLine) => { - $lineTitle.innerText = `${currentLine.name} 관리`; - $sectionSelectorContainer.innerHTML = SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE; - const $sectionSelector = $element.querySelector('#section-station-selector'); - const $sectionTable = $element.querySelector('#section-table'); - $sectionSelector.innerHTML = ALL_STATION_OPTION_LIST(stations); - $sectionTable.innerHTML = SECTION_MANAGER_PAGE_TABLE_TEMPLATE; - const $sectionTableBody = $element.querySelector('.section-table-tbody'); - $sectionTableBody.innerHTML = SECTION_TABLE_TEMPLATE(currentLine); - }; + const $sectionTable = $element.querySelector('#section-table'); const onMenuFilterHandler = (e) => { if (!e.target.classList.contains('section-line-menu-button')) { return; } const currentLine = lineStorage().getOneLine(e.target.dataset.lineid); - renderSectionManager(currentLine); + oneSectionManager($sectionSelectorContainer, $sectionTable, currentLine); }; $listMenuBtn.addEventListener('click', onMenuFilterHandler); diff --git a/src/components/template/sectionManagerTemplate.js b/src/components/template/sectionManagerTemplate.js index decf94dc9..e89c7fa39 100644 --- a/src/components/template/sectionManagerTemplate.js +++ b/src/components/template/sectionManagerTemplate.js @@ -1,15 +1,17 @@ +import stationStorage from '../../utils/stationStorage.js'; + const SECTION_MANAGER_PAGE_MENU_TEMPLATE = `

ꡬ간을 μˆ˜μ •ν•  노선을 μ„ νƒν•΄μ£Όμ„Έμš”

-

`; -const SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE = `

ꡬ간 등둝

- - - `; +const SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE = `

+

ꡬ간 등둝

+ + + `; const SECTION_MANAGER_PAGE_TABLE_TEMPLATE = ` @@ -22,7 +24,9 @@ const SECTION_MANAGER_PAGE_TABLE_TEMPLATE = `
`; -const SECTION_TABLE_TEMPLATE = ({ id, stations }) => { +const SECTION_TABLE_TEMPLATE = ({ id, stationIds }) => { + const stations = stationIds.map(stationStorage().getStationById); + return stations .map( (station, index) => diff --git a/src/utils/validator/sectionValidator.js b/src/utils/validator/sectionValidator.js new file mode 100644 index 000000000..6560c4c33 --- /dev/null +++ b/src/utils/validator/sectionValidator.js @@ -0,0 +1,30 @@ +const isNotRegistered = (id, stations, stationName) => { + const stationLines = stations.filter((station) => station.name === stationName)[0].line; + return stationLines.includes(id) ? alert('이미 λ“±λ‘λœ μ—­μž…λ‹ˆλ‹€') : true; +}; + +const isNumber = (sectionIndex) => { + return Number.isNaN(sectionIndex) ? alert('μ •ν™•ν•œ 숫자λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”') : true; +}; + +const isPositiveNumber = (sectionIndex) => { + return sectionIndex >= 0 ? true : alert('μŒμˆ˜κ°€ μ•„λ‹Œ 0 μ΄μƒμ˜ 숫자λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”'); +}; + +const isCorrectIndex = (sectionLength, sectionIndex) => { + return sectionIndex <= sectionLength ? true : alert('μž…λ ₯ν•œ μˆœμ„œλ₯Ό ν™•μΈν•΄μ£Όμ„Έμš”'); +}; + +function sectionStationNameValidator({ id }, stations, stationName) { + return isNotRegistered(id, stations, stationName); +} + +function sectionIndexValidator(sectionLength, sectionIndex) { + return ( + isNumber(sectionIndex) && + isPositiveNumber(sectionIndex) && + isCorrectIndex(sectionLength, sectionIndex) + ); +} + +export { sectionStationNameValidator, sectionIndexValidator }; From ac69f86949fec4054d7dc5580e81c01e18f896b4 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 18:16:52 +0900 Subject: [PATCH 34/48] =?UTF-8?q?feat=20:=20=EB=85=B8=EC=84=A0=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=97=AD=EC=9D=84=20=EC=82=AD=EC=A0=9C=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=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 --- src/components/oneSectionManager.js | 39 +++++++++++++++++++ .../template/sectionManagerTemplate.js | 2 +- src/utils/validator/sectionValidator.js | 16 +++++++- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/components/oneSectionManager.js b/src/components/oneSectionManager.js index ccf0a7be7..68e44cc84 100644 --- a/src/components/oneSectionManager.js +++ b/src/components/oneSectionManager.js @@ -1,6 +1,7 @@ import { sectionIndexValidator, sectionStationNameValidator, + sectionDeleteValidator, } from '../utils/validator/sectionValidator.js'; import { SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE, @@ -60,6 +61,43 @@ export default function oneSectionManager($container, $table, line) { renderSection(updateLineState(stationId, stationIndex)); }; + const removeStationInLine = (stationId) => { + const deleteIndex = line.stationIds.findIndex((id) => id === stationId); + line.stationIds.splice(deleteIndex, 1); + for (let i = 0; i < lines.length; i++) { + if (lines[i].id === line.id) { + lines[i] = line; + } + } + lineStorage().setLine(lines); + return line; + }; + + const removeLineInStation = (stationId, lineId) => { + const station = getStationById(stationId); + const deleteIndex = station.line.findIndex((lineNum) => lineNum === lineId); + station.line.splice(deleteIndex, 1); + stationStorage().setStation(stations); + }; + + const removeStationInSection = (stationId, lineId) => { + removeLineInStation(stationId, lineId); + console.log(lines); + renderSection(removeStationInLine(stationId)); + }; + + const onRemoveSubmitHandler = (e) => { + const stationId = parseInt(e.target.dataset.stationid); + const lineId = parseInt(e.target.closest('tr').id); // line.id + if (Number.isNaN(stationId)) { + return; + } + + if (sectionDeleteValidator(lineId) && confirm('μ •λ§λ‘œ λ…Έμ„ μ—μ„œ μ‚­μ œν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ?')) { + removeStationInSection(stationId, lineId); + } + }; + const onSectionSubmitHandler = () => { const userSelectStationName = $userSelectStationBtn.value; const userSectionIndex = parseInt($userSectionIndexInput.value); @@ -74,4 +112,5 @@ export default function oneSectionManager($container, $table, line) { }; $userSectionSubmitBtn.addEventListener('click', onSectionSubmitHandler); + $sectionTableBody.addEventListener('click', onRemoveSubmitHandler); } diff --git a/src/components/template/sectionManagerTemplate.js b/src/components/template/sectionManagerTemplate.js index e89c7fa39..cf0a3304b 100644 --- a/src/components/template/sectionManagerTemplate.js +++ b/src/components/template/sectionManagerTemplate.js @@ -33,7 +33,7 @@ const SECTION_TABLE_TEMPLATE = ({ id, stationIds }) => { ` ${index} ${station.name} - + ` ) .join(''); diff --git a/src/utils/validator/sectionValidator.js b/src/utils/validator/sectionValidator.js index 6560c4c33..49e5993c6 100644 --- a/src/utils/validator/sectionValidator.js +++ b/src/utils/validator/sectionValidator.js @@ -1,3 +1,5 @@ +import lineStorage from '../lineStorage.js'; + const isNotRegistered = (id, stations, stationName) => { const stationLines = stations.filter((station) => station.name === stationName)[0].line; return stationLines.includes(id) ? alert('이미 λ“±λ‘λœ μ—­μž…λ‹ˆλ‹€') : true; @@ -15,6 +17,14 @@ const isCorrectIndex = (sectionLength, sectionIndex) => { return sectionIndex <= sectionLength ? true : alert('μž…λ ₯ν•œ μˆœμ„œλ₯Ό ν™•μΈν•΄μ£Όμ„Έμš”'); }; +const isLengthLongerThanTwo = (lineId) => { + const stationLength = lineStorage().getOneLine(lineId).stationIds.length; + if (stationLength < 3) { + return alert('노선은 μ΅œμ†Œ 2개의 μ—­μœΌλ‘œ 이루어져 μžˆμŠ΅λ‹ˆλ‹€.'); + } + return true; +}; + function sectionStationNameValidator({ id }, stations, stationName) { return isNotRegistered(id, stations, stationName); } @@ -27,4 +37,8 @@ function sectionIndexValidator(sectionLength, sectionIndex) { ); } -export { sectionStationNameValidator, sectionIndexValidator }; +function sectionDeleteValidator(lineId) { + return isLengthLongerThanTwo(lineId); +} + +export { sectionStationNameValidator, sectionIndexValidator, sectionDeleteValidator }; From 263b8c1c8aefa488e134d447b6124f7d60b610b4 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 18:28:56 +0900 Subject: [PATCH 35/48] =?UTF-8?q?fix=20:=20=EB=85=B8=EC=84=A0=EC=97=90=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=ED=95=A0=20=EB=95=8C=20station=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - μ„ νƒν•˜μ§€ μ•Šμ€ station에 λ…Έμ„  λ²ˆν˜Έκ°€ λ“€μ–΄κ°€λŠ” 였λ₯˜ μˆ˜μ • --- src/components/oneSectionManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/oneSectionManager.js b/src/components/oneSectionManager.js index 68e44cc84..e0625fa23 100644 --- a/src/components/oneSectionManager.js +++ b/src/components/oneSectionManager.js @@ -57,7 +57,7 @@ export default function oneSectionManager($container, $table, line) { const updateSection = (stationName, stationIndex) => { const stationId = stationStorage().getStationIdByName(stationName); - updateStationState(stationIndex); + updateStationState(stationId); renderSection(updateLineState(stationId, stationIndex)); }; From 7ea4917e9f95f247594cb30405414f5a6e8bdc56 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 19:04:29 +0900 Subject: [PATCH 36/48] =?UTF-8?q?feat=20:=20=EC=A0=84=EC=B2=B4=20=EC=A7=80?= =?UTF-8?q?=ED=95=98=EC=B2=A0=20=EB=85=B8=EC=84=A0=EB=8F=84=20=EB=B3=B4?= =?UTF-8?q?=EC=97=AC=EC=A3=BC=EB=8A=94=20=EA=B8=B0=EB=8A=A5=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/components/mapPrintManagerPage.js | 5 ++++ .../template/mapPrintManagerTemplate.js | 24 +++++++++++++++++++ src/subwayMapApp.js | 3 ++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/components/mapPrintManagerPage.js create mode 100644 src/components/template/mapPrintManagerTemplate.js diff --git a/src/components/mapPrintManagerPage.js b/src/components/mapPrintManagerPage.js new file mode 100644 index 000000000..d8ef19f85 --- /dev/null +++ b/src/components/mapPrintManagerPage.js @@ -0,0 +1,5 @@ +import MAP_MANAGER_PAGE_TEMPLATE from './template/mapPrintManagerTemplate.js'; + +export default function mapPrintManagerPage($element) { + $element.innerHTML = MAP_MANAGER_PAGE_TEMPLATE(); +} diff --git a/src/components/template/mapPrintManagerTemplate.js b/src/components/template/mapPrintManagerTemplate.js new file mode 100644 index 000000000..fed0719d9 --- /dev/null +++ b/src/components/template/mapPrintManagerTemplate.js @@ -0,0 +1,24 @@ +import stationStorage from '../../utils/stationStorage.js'; +import lineStorage from '../../utils/lineStorage.js'; + +const STATION_LIST_TEMPLATE = (stationId) => { + const station = stationStorage().getStationById(stationId); + return `
  • ${station.name}
  • `; +}; + +const MAP_MANAGER_PAGE_TEMPLATE = () => { + const lines = lineStorage().getLine(); + return `
    + ${lines + .map( + (line) => + `

    ${line.name}

    + ${line.stationIds + .map(STATION_LIST_TEMPLATE) + .join('')}
    ` + ) + .join('')} +
    `; +}; + +export default MAP_MANAGER_PAGE_TEMPLATE; diff --git a/src/subwayMapApp.js b/src/subwayMapApp.js index e5d096bae..4205f9eec 100644 --- a/src/subwayMapApp.js +++ b/src/subwayMapApp.js @@ -1,6 +1,7 @@ import stationManagerPage from './components/stationManagerPage.js'; import lineManagerPage from './components/lineManagerPage.js'; import sectionManagerPage from './components/sectionManagerPage.js'; +import mapPrintManagerPage from './components/mapPrintManagerPage.js'; export default function subwayMapApp($element) { const $stationManagerBtn = $element.querySelector('#station-manager-button'); @@ -19,7 +20,7 @@ export default function subwayMapApp($element) { sectionManagerPage($contentSection); }; const onMapPrintManageHandler = () => { - console.log('전체 노선도 좜λ ₯ μž…λ‹ˆλ‹€.'); + mapPrintManagerPage($contentSection); }; $stationManagerBtn.addEventListener('click', onStationManageHandler); From 7434a800c75a51335d63eaaf65baf28615279ef0 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 19:04:45 +0900 Subject: [PATCH 37/48] =?UTF-8?q?style=20:=20css=20style=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.html b/index.html index 3012bea43..b0d5daab9 100644 --- a/index.html +++ b/index.html @@ -18,6 +18,10 @@ margin-left : 0.2rem; } + li { + margin-left : 1rem; + } + .select-line-points { margin: 1rem 0; } From 7db007572f6dfd00f534cc5f2f6207be845dc35e Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 21:56:23 +0900 Subject: [PATCH 38/48] =?UTF-8?q?refactor=20:=20init=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=ED=99=94=EB=A9=B4=20?= =?UTF-8?q?=EA=B5=AC=EC=84=B1=EC=9A=94=EC=86=8C=20views=20=ED=8F=B4?= =?UTF-8?q?=EB=8D=94=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 - μ „μ—­λ³€μˆ˜λ‘œ 있던 λ³€μˆ˜λ“€μ„ init ν•¨μˆ˜μ— λ„£κΈ° --- src/subwayMapApp.js | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/subwayMapApp.js b/src/subwayMapApp.js index 4205f9eec..31c00ff79 100644 --- a/src/subwayMapApp.js +++ b/src/subwayMapApp.js @@ -1,30 +1,21 @@ -import stationManagerPage from './components/stationManagerPage.js'; -import lineManagerPage from './components/lineManagerPage.js'; -import sectionManagerPage from './components/sectionManagerPage.js'; -import mapPrintManagerPage from './components/mapPrintManagerPage.js'; +import stationManagerPage from './components/views/stationManagerPage.js'; +import lineManagerPage from './components/views/lineManagerPage.js'; +import sectionManagerPage from './components/views/SectionManagerPages/sectionManagerPage.js'; +import mapPrintManagerPage from './components/views/mapPrintManagerPage.js'; export default function subwayMapApp($element) { - const $stationManagerBtn = $element.querySelector('#station-manager-button'); - const $lineManagerBtn = $element.querySelector('#line-manager-button'); - const $sectionManagerBtn = $element.querySelector('#section-manager-button'); - const $mapPrintManagerBtn = $element.querySelector('#map-print-manager-button'); - const $contentSection = $element.querySelector('.content-container'); + const init = () => { + const $stationManagerBtn = $element.querySelector('#station-manager-button'); + const $lineManagerBtn = $element.querySelector('#line-manager-button'); + const $sectionManagerBtn = $element.querySelector('#section-manager-button'); + const $mapPrintManagerBtn = $element.querySelector('#map-print-manager-button'); + const $contentSection = $element.querySelector('.content-container'); - const onStationManageHandler = () => { - stationManagerPage($contentSection); - }; - const onLineManageHandler = () => { - lineManagerPage($contentSection); - }; - const onSectionManageHandler = () => { - sectionManagerPage($contentSection); - }; - const onMapPrintManageHandler = () => { - mapPrintManagerPage($contentSection); + $stationManagerBtn.addEventListener('click', () => stationManagerPage($contentSection)); + $lineManagerBtn.addEventListener('click', () => lineManagerPage($contentSection)); + $sectionManagerBtn.addEventListener('click', () => sectionManagerPage($contentSection)); + $mapPrintManagerBtn.addEventListener('click', () => mapPrintManagerPage($contentSection)); }; - $stationManagerBtn.addEventListener('click', onStationManageHandler); - $lineManagerBtn.addEventListener('click', onLineManageHandler); - $sectionManagerBtn.addEventListener('click', onSectionManageHandler); - $mapPrintManagerBtn.addEventListener('click', onMapPrintManageHandler); + init(); } From 52b6f711858c5cdda399bba308c5be20bbcb10c1 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 22:02:54 +0900 Subject: [PATCH 39/48] =?UTF-8?q?refactor=20:=20storage=20=ED=8F=B4?= =?UTF-8?q?=EB=8D=94=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{utils => storage}/lineStorage.js | 2 +- src/{utils => storage}/stationStorage.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/{utils => storage}/lineStorage.js (93%) rename src/{utils => storage}/stationStorage.js (92%) diff --git a/src/utils/lineStorage.js b/src/storage/lineStorage.js similarity index 93% rename from src/utils/lineStorage.js rename to src/storage/lineStorage.js index 9b33232d5..fcc797a31 100644 --- a/src/utils/lineStorage.js +++ b/src/storage/lineStorage.js @@ -1,4 +1,4 @@ -import { LINE_STORAGE_NAME } from './constant.js'; +import { LINE_STORAGE_NAME } from '../utils/constant.js'; export default function lineStorage() { const getLine = () => { diff --git a/src/utils/stationStorage.js b/src/storage/stationStorage.js similarity index 92% rename from src/utils/stationStorage.js rename to src/storage/stationStorage.js index 4289c4018..e6b1b9891 100644 --- a/src/utils/stationStorage.js +++ b/src/storage/stationStorage.js @@ -1,4 +1,4 @@ -import { STATION_STORAGE_NAME } from './constant.js'; +import { STATION_STORAGE_NAME } from '../utils/constant.js'; export default function stationStorage() { const getStations = () => { From f02d06e387089077b04378f915f1402508842156 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 22:03:25 +0900 Subject: [PATCH 40/48] =?UTF-8?q?refactor=20:=20=EC=97=AD=20=EA=B4=80?= =?UTF-8?q?=EB=A6=AC=20=EA=B8=B0=EB=8A=A5=20=EC=BD=94=EB=93=9C=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 - temeplate μ½”λ“œ μ •λ ¬ - 역관리 ν™”λ©΄ 파일(stationManagerPage) views 폴더 μƒμ„±ν•˜μ—¬ 이동 - stationManagerPage 속 λ³€μˆ˜λͺ… μˆ˜μ • - μ΅œμ†Œ κΈ€μžμˆ˜ μƒμˆ˜λ‘œ μ €μž₯ - μ—­ 이름 및 μ‚­μ œν•  λ•Œ μœ νš¨μ„± 검사 μ½”λ“œ λ¦¬νŒ©ν† λ§ --- .../template/stationManagerTemplate.js | 21 ++++--- .../{ => views}/stationManagerPage.js | 58 ++++++++++--------- src/utils/constant.js | 3 +- src/utils/validator/stationValidator.js | 21 +++---- 4 files changed, 51 insertions(+), 52 deletions(-) rename src/components/{ => views}/stationManagerPage.js (71%) diff --git a/src/components/template/stationManagerTemplate.js b/src/components/template/stationManagerTemplate.js index b6fdc37f9..209f21d6b 100644 --- a/src/components/template/stationManagerTemplate.js +++ b/src/components/template/stationManagerTemplate.js @@ -2,17 +2,16 @@ const STATION_MANAGER_PAGE_TEMPLATE = `

    μ—­ 이름

    - -

    πŸš‰ μ§€ν•˜μ²  μ—­ λͺ©λ‘

    - - - - - - - - -
    μ—­ 이름섀정
    + +

    πŸš‰ μ§€ν•˜μ²  μ—­ λͺ©λ‘

    + + + + + + + +
    μ—­ 이름섀정
    `; const STATION_TABLE_TEMPLATE = (station) => { diff --git a/src/components/stationManagerPage.js b/src/components/views/stationManagerPage.js similarity index 71% rename from src/components/stationManagerPage.js rename to src/components/views/stationManagerPage.js index c43e32225..17762faac 100644 --- a/src/components/stationManagerPage.js +++ b/src/components/views/stationManagerPage.js @@ -1,41 +1,24 @@ import { STATION_MANAGER_PAGE_TEMPLATE, STATION_TABLE_TEMPLATE, -} from './template/stationManagerTemplate.js'; +} from '../template/stationManagerTemplate.js'; import { stationNameValidator, stationDeleteValidation, -} from '../utils/validator/stationValidator.js'; -import stationStorage from '../utils/stationStorage.js'; -import Station from '../utils/Station.js'; +} from '../../utils/validator/stationValidator.js'; +import stationStorage from '../../storage/stationStorage.js'; +import Station from '../../utils/Station.js'; export default function stationManagerPage($element) { $element.innerHTML = STATION_MANAGER_PAGE_TEMPLATE; const $userStationInput = $element.querySelector('#station-name-input'); const $userStationSubmit = $element.querySelector('#station-add-button'); - const $stationTablebody = $element.querySelector('.station_manager_tbody'); + const $stationTableBody = $element.querySelector('.station_manager_tbody'); let stations = stationStorage().getStations(); - const showStations = () => { - $stationTablebody.innerHTML = stations.map(STATION_TABLE_TEMPLATE).join(''); - }; - - const getNewId = () => { - if (!stations || stations.length === 0) { - return 0; - } - return stations[stations.length - 1].id + 1; - }; - - const addStations = (newStations) => { - stations.push(newStations); - stationStorage().setStation(stations); - showStations(); - }; - - const createStation = (newStationName) => { - addStations(new Station(getNewId(), newStationName)); + const renderStationTable = () => { + $stationTableBody.innerHTML = stations.map(STATION_TABLE_TEMPLATE).join(''); }; const deleteStation = (stationTag) => { @@ -44,14 +27,33 @@ export default function stationManagerPage($element) { } stations = stations.filter((station) => station.id !== parseInt(stationTag.id)); stationStorage().setStation(stations); - showStations(); + renderStationTable(); }; const onStationDeleteHandler = (e) => { if (!e.target.classList.contains('station-delete-button')) { return false; } - deleteStation(e.target.closest('tr')); + if (confirm('μ •λ§λ‘œ μ‚­μ œν•˜μ‹œκ² μŠ΅λ‹ˆκΉŒ?')) { + deleteStation(e.target.closest('tr')); + } + }; + + const addStations = (newStations) => { + stations.push(newStations); + stationStorage().setStation(stations); + renderStationTable(); + }; + + const getNewId = () => { + if (!stations || stations.length === 0) { + return 0; + } + return stations[stations.length - 1].id + 1; + }; + + const createStation = (newStationName) => { + addStations(new Station(getNewId(), newStationName)); }; const onStationSubmitHandler = () => { @@ -63,6 +65,6 @@ export default function stationManagerPage($element) { }; $userStationSubmit.addEventListener('click', onStationSubmitHandler); - $stationTablebody.addEventListener('click', onStationDeleteHandler); - showStations(); + $stationTableBody.addEventListener('click', onStationDeleteHandler); + renderStationTable(); } diff --git a/src/utils/constant.js b/src/utils/constant.js index 38363dfcb..2dd21c072 100644 --- a/src/utils/constant.js +++ b/src/utils/constant.js @@ -1,4 +1,5 @@ const STATION_STORAGE_NAME = 'STATIONS'; const LINE_STORAGE_NAME = 'LINES'; +const NAME_MINT_LENGTH = 2; -export { STATION_STORAGE_NAME, LINE_STORAGE_NAME }; +export { STATION_STORAGE_NAME, LINE_STORAGE_NAME, NAME_MINT_LENGTH }; diff --git a/src/utils/validator/stationValidator.js b/src/utils/validator/stationValidator.js index 7d382d49d..cd50c3771 100644 --- a/src/utils/validator/stationValidator.js +++ b/src/utils/validator/stationValidator.js @@ -1,22 +1,19 @@ +import { NAME_MINT_LENGTH } from '../constant.js'; + const isNameLengthLongerThanTwo = (stationName) => { - if (stationName.length < 2) { - return alert('이름은 λ‘κΈ€μž μ΄μƒμž…λ‹ˆλ‹€'); - } - return true; + return stationName.length < NAME_MINT_LENGTH ? alert('이름은 λ‘κΈ€μž μ΄μƒμž…λ‹ˆλ‹€') : true; }; const isEqualName = (stations, stationName) => { - if (stations && stations.map((value) => value.name).includes(stationName)) { - return alert('μ€‘λ³΅λœ μ΄λ¦„μž…λ‹ˆλ‹€.'); - } - return true; + return stations && stations.map((value) => value.name).includes(stationName) + ? alert('μ€‘λ³΅λœ μ΄λ¦„μž…λ‹ˆλ‹€.') + : true; }; const isIncludedLine = (stationTag) => { - if (stationTag.dataset.lines.length !== 0) { - return alert('노선에 ν¬ν•¨λ˜μ–΄ μžˆλŠ” 라인은 μ‚­μ œν•  수 μ—†μŠ΅λ‹ˆλ‹€'); - } - return true; + return stationTag.dataset.lines.length !== 0 + ? alert('노선에 ν¬ν•¨λ˜μ–΄ μžˆλŠ” 라인은 μ‚­μ œν•  수 μ—†μŠ΅λ‹ˆλ‹€') + : true; }; function stationNameValidator(stations, stationName) { From 07227100081511088a3c82f6e4d9f10657bcdb00 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 22:32:18 +0900 Subject: [PATCH 41/48] =?UTF-8?q?refactor=20:=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EB=B3=B5=EC=88=98=ED=98=95=EC=9C=BC=EB=A1=9C=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/storage/lineStorage.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/storage/lineStorage.js b/src/storage/lineStorage.js index fcc797a31..4d9fcdbec 100644 --- a/src/storage/lineStorage.js +++ b/src/storage/lineStorage.js @@ -1,7 +1,7 @@ import { LINE_STORAGE_NAME } from '../utils/constant.js'; export default function lineStorage() { - const getLine = () => { + const getLines = () => { if (!localStorage.getItem(LINE_STORAGE_NAME)) { return []; } @@ -14,19 +14,19 @@ export default function lineStorage() { }; const getStartPointsId = () => { - return getLine().map((line) => line.stationIds[0]); + return getLines().map((line) => line.stationIds[0]); }; const getEndPointsId = () => { - return getLine().map((line) => line.stationIds[line.stationIds.length - 1]); + return getLines().map((line) => line.stationIds[line.stationIds.length - 1]); }; const getOneLine = (lineId) => { - return getLine().filter((line) => line.id === parseInt(lineId))[0]; + return getLines().filter((line) => line.id === parseInt(lineId))[0]; }; return { - getLine, + getLines, setLine, getStartPointsId, getEndPointsId, From a555f28319296107d0a8b4197324011d7a5bd2dc Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 22:34:17 +0900 Subject: [PATCH 42/48] =?UTF-8?q?refactor=20:=20=EB=85=B8=EC=84=A0=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=20=EA=B8=B0=EB=8A=A5=20=EC=BD=94=EB=93=9C=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 - views ν΄λ”λ‘œ lineManagerPage 파일 이동 - λ©”μ†Œλ“œ μˆœμ„œ μˆ˜μ • --- .../template/lineManagerTemplate.js | 2 +- src/components/{ => views}/lineManagerPage.js | 77 +++++++++---------- 2 files changed, 38 insertions(+), 41 deletions(-) rename src/components/{ => views}/lineManagerPage.js (74%) diff --git a/src/components/template/lineManagerTemplate.js b/src/components/template/lineManagerTemplate.js index 1255fc9c0..815ac02d3 100644 --- a/src/components/template/lineManagerTemplate.js +++ b/src/components/template/lineManagerTemplate.js @@ -1,4 +1,4 @@ -import stationStorage from '../../utils/stationStorage.js'; +import stationStorage from '../../storage/stationStorage.js'; const LINE_MANAGER_PAGE_TEMPLATE = `

    λ…Έμ„  이름

    diff --git a/src/components/lineManagerPage.js b/src/components/views/lineManagerPage.js similarity index 74% rename from src/components/lineManagerPage.js rename to src/components/views/lineManagerPage.js index db33ab3f7..6eea2a0fb 100644 --- a/src/components/lineManagerPage.js +++ b/src/components/views/lineManagerPage.js @@ -2,11 +2,11 @@ import { LINE_MANAGER_PAGE_TEMPLATE, ALL_STATION_OPTION_LIST, LINE_TABLE_TEMPLATE, -} from './template/lineManagerTemplate.js'; -import { lineNameValidator, lineStationsValidator } from '../utils/validator/lineValidator.js'; -import stationStorage from '../utils/stationStorage.js'; -import lineStorage from '../utils/lineStorage.js'; -import Line from '../utils/Line.js'; +} from '../template/lineManagerTemplate.js'; +import { lineNameValidator, lineStationsValidator } from '../../utils/validator/lineValidator.js'; +import stationStorage from '../../storage/stationStorage.js'; +import lineStorage from '../../storage/lineStorage.js'; +import Line from '../../utils/Line.js'; export default function stationManagerPage($element) { $element.innerHTML = LINE_MANAGER_PAGE_TEMPLATE; @@ -17,7 +17,7 @@ export default function stationManagerPage($element) { const $lineTableBody = $element.querySelector('.line-table-tbody'); const stations = stationStorage().getStations(); - let lines = lineStorage().getLine(); + let lines = lineStorage().getLines(); $startStation.innerHTML = ALL_STATION_OPTION_LIST(stations); $endStation.innerHTML = ALL_STATION_OPTION_LIST(stations); @@ -33,42 +33,15 @@ export default function stationManagerPage($element) { return lines[lines.length - 1].id + 1; }; - const addLine = (newLine) => { - lines.push(newLine); - lineStorage().setLine(lines); - renderLines(); - }; - - const getStation = (stationName) => { - return stations.filter((station) => station.name === stationName)[0]; - }; - const getStationById = (stationIds) => { return stations.filter((station) => station.id === stationIds)[0]; }; - const addLineInStation = (lineId, stationName) => { - getStation(stationName).line.push(lineId); - stationStorage().setStation(stations); - }; - - const createLine = (newLineName, startStationName, endStationName) => { - const startStationId = stationStorage().getStationIdByName(startStationName); - const endStationId = stationStorage().getStationIdByName(endStationName); - const newLine = new Line(getNewId(), newLineName); - newLine.setLine(startStationId, 0); - newLine.setLine(endStationId, 1); - - addLineInStation(newLine.id, startStationName); - addLineInStation(newLine.id, endStationName); - addLine(newLine); - }; - const removeLineInStation = (currentLineId) => { - const stationIdsInLine = lines.filter((line) => line.id === parseInt(currentLineId))[0] - .stationIds; + const stationsInLine = lines + .filter((line) => line.id === parseInt(currentLineId))[0] + .stationIds.map(getStationById); - const stationsInLine = stationIdsInLine.map(getStationById); for (let i = 0; i < stationsInLine.length; i++) { const deleteIndex = stationsInLine[i].line.indexOf(parseInt(currentLineId)); stationsInLine[i].line.splice(deleteIndex, 1); @@ -92,17 +65,41 @@ export default function stationManagerPage($element) { } }; + const addLine = (newLine) => { + lines.push(newLine); + lineStorage().setLine(lines); + renderLines(); + }; + + const getStation = (stationName) => { + return stations.filter((station) => station.name === stationName)[0]; + }; + + const addLineInStation = (lineId, stationName) => { + getStation(stationName).line.push(lineId); + stationStorage().setStation(stations); + }; + + const createLine = (newLineName, startStationName, endStationName) => { + const newLine = new Line(getNewId(), newLineName); + newLine.setLine(stationStorage().getStationIdByName(startStationName), 0); + newLine.setLine(stationStorage().getStationIdByName(endStationName), 1); + + addLineInStation(newLine.id, startStationName); + addLineInStation(newLine.id, endStationName); + addLine(newLine); + }; + const onLineSubmitHandler = () => { const newLineName = $userInputLine.value; - const startStationName = $startStation.value; - const endStationName = $endStation.value; if ( lineNameValidator(lines, newLineName) && - lineStationsValidator(startStationName, endStationName) + lineStationsValidator($startStation.value, $endStation.value) ) { - createLine(newLineName, startStationName, endStationName); + createLine(newLineName, $startStation.value, $endStation.value); } + $userInputLine.value = ''; }; From 0b0cb07aab4c4c14b5702724b7017d99f5025881 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 22:35:13 +0900 Subject: [PATCH 43/48] =?UTF-8?q?refactor=20:=20=EB=85=B8=EC=84=A0=20?= =?UTF-8?q?=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=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/utils/validator/lineValidator.js | 36 +++++++++++++--------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/utils/validator/lineValidator.js b/src/utils/validator/lineValidator.js index d93acb6fc..a4cec836e 100644 --- a/src/utils/validator/lineValidator.js +++ b/src/utils/validator/lineValidator.js @@ -1,5 +1,5 @@ -import lineStorage from '../lineStorage.js'; -import stationStorage from '../stationStorage.js'; +import lineStorage from '../../storage/lineStorage.js'; +import stationStorage from '../../storage/stationStorage.js'; const isEqualName = (lines, lineName) => { return lines.some((line) => line.name === lineName) ? alert('μ€‘λ³΅λœ λ…Έμ„  μ΄λ¦„μž…λ‹ˆλ‹€.') : true; @@ -21,31 +21,29 @@ const isEqualPoints = (startStationName, endStationName) => { : true; }; -const isEqualLine = (startStationName, endStationName) => { - const startStationId = stationStorage().getStationIdByName(startStationName); - const endStationId = stationStorage().getStationIdByName(endStationName); - - const startStationIds = lineStorage() +const getStartStationIds = (stationName) => { + return lineStorage() .getStartPointsId() - .map((stationId) => stationId === parseInt(startStationId)); - const endStationIds = lineStorage() + .map((stationId) => stationId === parseInt(stationStorage().getStationIdByName(stationName))); +}; + +const getEndStationIds = (stationName) => { + return lineStorage() .getEndPointsId() - .map((stationId) => stationId === parseInt(endStationId)); + .map((stationId) => stationId === parseInt(stationStorage().getStationIdByName(stationName))); +}; + +const isEqualLine = (startStationName, endStationName) => { + const startStationIds = getStartStationIds(startStationName); + const endStationIds = getEndStationIds(endStationName); const equalLine = startStationIds.filter((station, index) => station && endStationIds[index]); return equalLine.length !== 0 ? alert('λ™μΌν•œ 쒅점을 κ°€μ§„ 노선이 μžˆμŠ΅λ‹ˆλ‹€') : true; }; const isEqualReverseLine = (startStationName, endStationName) => { - const startStationId = stationStorage().getStationIdByName(startStationName); - const endStationId = stationStorage().getStationIdByName(endStationName); - - const endStationsIds = lineStorage() - .getStartPointsId() - .map((stationId) => stationId === parseInt(startStationId)); - const StartStationsIds = lineStorage() - .getEndPointsId() - .map((stationId) => stationId === parseInt(endStationId)); + const endStationsIds = getStartStationIds(startStationName); + const StartStationsIds = getEndStationIds(endStationName); const equalLine = StartStationsIds.filter((station, index) => station && endStationsIds[index]); return equalLine.length !== 0 ? alert('λ™μΌν•œ 쒅점을 κ°€μ§„ 노선이 μžˆμŠ΅λ‹ˆλ‹€') : true; From ff349819d7ee0c71837fc8789183b7761d805c3d Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 22:53:03 +0900 Subject: [PATCH 44/48] =?UTF-8?q?refactor=20:=20=EC=98=A4=ED=83=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B0=8F=20=20section=20=EC=B5=9C?= =?UTF-8?q?=EC=86=8C=20=EA=B0=9C=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/constant.js | 5 +++-- src/utils/validator/stationValidator.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/constant.js b/src/utils/constant.js index 2dd21c072..98c0788fe 100644 --- a/src/utils/constant.js +++ b/src/utils/constant.js @@ -1,5 +1,6 @@ const STATION_STORAGE_NAME = 'STATIONS'; const LINE_STORAGE_NAME = 'LINES'; -const NAME_MINT_LENGTH = 2; +const NAME_MIN_LENGTH = 2; +const SECTION_MIN_LENGTH = 2; -export { STATION_STORAGE_NAME, LINE_STORAGE_NAME, NAME_MINT_LENGTH }; +export { STATION_STORAGE_NAME, LINE_STORAGE_NAME, NAME_MIN_LENGTH, SECTION_MIN_LENGTH }; diff --git a/src/utils/validator/stationValidator.js b/src/utils/validator/stationValidator.js index cd50c3771..12f8763b8 100644 --- a/src/utils/validator/stationValidator.js +++ b/src/utils/validator/stationValidator.js @@ -1,7 +1,7 @@ -import { NAME_MINT_LENGTH } from '../constant.js'; +import { NAME_MIN_LENGTH } from '../constant.js'; const isNameLengthLongerThanTwo = (stationName) => { - return stationName.length < NAME_MINT_LENGTH ? alert('이름은 λ‘κΈ€μž μ΄μƒμž…λ‹ˆλ‹€') : true; + return stationName.length < NAME_MIN_LENGTH ? alert('이름은 λ‘κΈ€μž μ΄μƒμž…λ‹ˆλ‹€') : true; }; const isEqualName = (stations, stationName) => { From 20456c213e68d1f5893fcbb5bdb5ede213a30bd0 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 22:56:01 +0900 Subject: [PATCH 45/48] =?UTF-8?q?refactor=20:=20=EB=85=B8=EC=84=A0=20?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20=EA=B8=B0=EB=8A=A5=20=EC=BD=94=EB=93=9C=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 - views ν΄λ”λ‘œ SectionManager 파일 이동 - λΆˆν•„μš”ν•œ λ³€μˆ˜ μ‚­μ œ 및 λΉ λ₯Έ return - λ©”μ†Œλ“œ μˆœμ„œ λ³€κ²½ --- .../template/sectionManagerTemplate.js | 10 ++-- .../sectionManagerPage.js | 10 ++-- .../singleSectionManager.js} | 59 +++++++++---------- src/utils/validator/sectionValidator.js | 21 +++---- 4 files changed, 50 insertions(+), 50 deletions(-) rename src/components/{ => views/SectionManagerPages}/sectionManagerPage.js (71%) rename src/components/{oneSectionManager.js => views/SectionManagerPages/singleSectionManager.js} (89%) diff --git a/src/components/template/sectionManagerTemplate.js b/src/components/template/sectionManagerTemplate.js index cf0a3304b..7a5123daf 100644 --- a/src/components/template/sectionManagerTemplate.js +++ b/src/components/template/sectionManagerTemplate.js @@ -1,4 +1,4 @@ -import stationStorage from '../../utils/stationStorage.js'; +import stationStorage from '../../storage/stationStorage.js'; const SECTION_MANAGER_PAGE_MENU_TEMPLATE = `

    ꡬ간을 μˆ˜μ •ν•  노선을 μ„ νƒν•΄μ£Όμ„Έμš”

    @@ -7,6 +7,10 @@ const SECTION_MANAGER_PAGE_MENU_TEMPLATE = `
    `; +const SECTION_LINE_MENU_BTN = (line) => { + return ``; +}; + const SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE = `

    ꡬ간 등둝

    @@ -39,10 +43,6 @@ const SECTION_TABLE_TEMPLATE = ({ id, stationIds }) => { .join(''); }; -const SECTION_LINE_MENU_BTN = (line) => { - return ``; -}; - export { SECTION_MANAGER_PAGE_MENU_TEMPLATE, SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE, diff --git a/src/components/sectionManagerPage.js b/src/components/views/SectionManagerPages/sectionManagerPage.js similarity index 71% rename from src/components/sectionManagerPage.js rename to src/components/views/SectionManagerPages/sectionManagerPage.js index 9f86347bc..d5f0cb7a1 100644 --- a/src/components/sectionManagerPage.js +++ b/src/components/views/SectionManagerPages/sectionManagerPage.js @@ -1,12 +1,12 @@ import { SECTION_MANAGER_PAGE_MENU_TEMPLATE, SECTION_LINE_MENU_BTN, -} from './template/sectionManagerTemplate.js'; -import lineStorage from '../utils/lineStorage.js'; -import oneSectionManager from './oneSectionManager.js'; +} from '../../template/sectionManagerTemplate.js'; +import lineStorage from '../../../storage/lineStorage.js'; +import singleSectionManager from './singleSectionManager.js'; export default function sectionManagerPage($element) { - const lines = lineStorage().getLine(); + const lines = lineStorage().getLines(); $element.innerHTML = SECTION_MANAGER_PAGE_MENU_TEMPLATE; const $listMenuBtn = $element.querySelector('.line-buttons'); @@ -19,7 +19,7 @@ export default function sectionManagerPage($element) { return; } const currentLine = lineStorage().getOneLine(e.target.dataset.lineid); - oneSectionManager($sectionSelectorContainer, $sectionTable, currentLine); + singleSectionManager($sectionSelectorContainer, $sectionTable, currentLine); }; $listMenuBtn.addEventListener('click', onMenuFilterHandler); diff --git a/src/components/oneSectionManager.js b/src/components/views/SectionManagerPages/singleSectionManager.js similarity index 89% rename from src/components/oneSectionManager.js rename to src/components/views/SectionManagerPages/singleSectionManager.js index e0625fa23..c6af11abe 100644 --- a/src/components/oneSectionManager.js +++ b/src/components/views/SectionManagerPages/singleSectionManager.js @@ -2,19 +2,19 @@ import { sectionIndexValidator, sectionStationNameValidator, sectionDeleteValidator, -} from '../utils/validator/sectionValidator.js'; +} from '../../../utils/validator/sectionValidator.js'; import { SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE, SECTION_MANAGER_PAGE_TABLE_TEMPLATE, SECTION_TABLE_TEMPLATE, -} from './template/sectionManagerTemplate.js'; -import { ALL_STATION_OPTION_LIST } from './template/lineManagerTemplate.js'; -import stationStorage from '../utils/stationStorage.js'; -import lineStorage from '../utils/lineStorage.js'; +} from '../../template/sectionManagerTemplate.js'; +import { ALL_STATION_OPTION_LIST } from '../../template/lineManagerTemplate.js'; +import stationStorage from '../../../storage/stationStorage.js'; +import lineStorage from '../../../storage/lineStorage.js'; -export default function oneSectionManager($container, $table, line) { +export default function singleSectionManager($container, $table, line) { const stations = stationStorage().getStations(); - const lines = lineStorage().getLine(); + const lines = lineStorage().getLines(); $container.innerHTML = SECTION_MANAGER_PAGE_SELECTOR_TEMPLATE; const $lineTitle = $container.querySelector('#line-title'); @@ -39,28 +39,6 @@ export default function oneSectionManager($container, $table, line) { return stations.filter((station) => station.id === stationIds)[0]; }; - const updateLineState = (stationId, stationIndex) => { - line.stationIds.splice(stationIndex, 0, stationId); - for (let i = 0; i < lines.length; i++) { - if (lines[i].id === line.id) { - lines[i] = line; - } - } - lineStorage().setLine(lines); - return line; - }; - - const updateStationState = (stationId) => { - getStationById(stationId).line.push(line.id); - stationStorage().setStation(stations); - }; - - const updateSection = (stationName, stationIndex) => { - const stationId = stationStorage().getStationIdByName(stationName); - updateStationState(stationId); - renderSection(updateLineState(stationId, stationIndex)); - }; - const removeStationInLine = (stationId) => { const deleteIndex = line.stationIds.findIndex((id) => id === stationId); line.stationIds.splice(deleteIndex, 1); @@ -82,7 +60,6 @@ export default function oneSectionManager($container, $table, line) { const removeStationInSection = (stationId, lineId) => { removeLineInStation(stationId, lineId); - console.log(lines); renderSection(removeStationInLine(stationId)); }; @@ -98,6 +75,28 @@ export default function oneSectionManager($container, $table, line) { } }; + const updateLineState = (stationId, stationIndex) => { + line.stationIds.splice(stationIndex, 0, stationId); + for (let i = 0; i < lines.length; i++) { + if (lines[i].id === line.id) { + lines[i] = line; + } + } + lineStorage().setLine(lines); + return line; + }; + + const updateStationState = (stationId) => { + getStationById(stationId).line.push(line.id); + stationStorage().setStation(stations); + }; + + const updateSection = (stationName, stationIndex) => { + const stationId = stationStorage().getStationIdByName(stationName); + updateStationState(stationId); + renderSection(updateLineState(stationId, stationIndex)); + }; + const onSectionSubmitHandler = () => { const userSelectStationName = $userSelectStationBtn.value; const userSectionIndex = parseInt($userSectionIndexInput.value); diff --git a/src/utils/validator/sectionValidator.js b/src/utils/validator/sectionValidator.js index 49e5993c6..d5438036d 100644 --- a/src/utils/validator/sectionValidator.js +++ b/src/utils/validator/sectionValidator.js @@ -1,9 +1,5 @@ -import lineStorage from '../lineStorage.js'; - -const isNotRegistered = (id, stations, stationName) => { - const stationLines = stations.filter((station) => station.name === stationName)[0].line; - return stationLines.includes(id) ? alert('이미 λ“±λ‘λœ μ—­μž…λ‹ˆλ‹€') : true; -}; +import lineStorage from '../../storage/lineStorage.js'; +import { SECTION_MIN_LENGTH } from '../constant.js'; const isNumber = (sectionIndex) => { return Number.isNaN(sectionIndex) ? alert('μ •ν™•ν•œ 숫자λ₯Ό μž…λ ₯ν•΄μ£Όμ„Έμš”') : true; @@ -19,10 +15,15 @@ const isCorrectIndex = (sectionLength, sectionIndex) => { const isLengthLongerThanTwo = (lineId) => { const stationLength = lineStorage().getOneLine(lineId).stationIds.length; - if (stationLength < 3) { - return alert('노선은 μ΅œμ†Œ 2개의 μ—­μœΌλ‘œ 이루어져 μžˆμŠ΅λ‹ˆλ‹€.'); - } - return true; + return stationLength <= SECTION_MIN_LENGTH + ? alert('노선은 μ΅œμ†Œ 2개의 μ—­μœΌλ‘œ 이루어져 μžˆμŠ΅λ‹ˆλ‹€.') + : true; +}; + +const isNotRegistered = (id, stations, stationName) => { + return stations.filter((station) => station.name === stationName)[0].line.includes(id) + ? alert('이미 λ“±λ‘λœ μ—­μž…λ‹ˆλ‹€') + : true; }; function sectionStationNameValidator({ id }, stations, stationName) { From 21182c75a3e1aaf7339fe79fbdb953738be13df9 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 22:58:01 +0900 Subject: [PATCH 46/48] =?UTF-8?q?refactor=20:=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=A7=80=ED=95=98=EC=B2=A0=20=EB=85=B8=EC=84=A0=20=EB=B3=B4?= =?UTF-8?q?=EC=97=AC=EC=A3=BC=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=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 - views 폴더 생성 및 파일 이동 --- src/components/template/mapPrintManagerTemplate.js | 6 +++--- src/components/{ => views}/mapPrintManagerPage.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/components/{ => views}/mapPrintManagerPage.js (58%) diff --git a/src/components/template/mapPrintManagerTemplate.js b/src/components/template/mapPrintManagerTemplate.js index fed0719d9..b96ac3494 100644 --- a/src/components/template/mapPrintManagerTemplate.js +++ b/src/components/template/mapPrintManagerTemplate.js @@ -1,5 +1,5 @@ -import stationStorage from '../../utils/stationStorage.js'; -import lineStorage from '../../utils/lineStorage.js'; +import stationStorage from '../../storage/stationStorage.js'; +import lineStorage from '../../storage/lineStorage.js'; const STATION_LIST_TEMPLATE = (stationId) => { const station = stationStorage().getStationById(stationId); @@ -7,7 +7,7 @@ const STATION_LIST_TEMPLATE = (stationId) => { }; const MAP_MANAGER_PAGE_TEMPLATE = () => { - const lines = lineStorage().getLine(); + const lines = lineStorage().getLines(); return `
    ${lines .map( diff --git a/src/components/mapPrintManagerPage.js b/src/components/views/mapPrintManagerPage.js similarity index 58% rename from src/components/mapPrintManagerPage.js rename to src/components/views/mapPrintManagerPage.js index d8ef19f85..71938c49e 100644 --- a/src/components/mapPrintManagerPage.js +++ b/src/components/views/mapPrintManagerPage.js @@ -1,4 +1,4 @@ -import MAP_MANAGER_PAGE_TEMPLATE from './template/mapPrintManagerTemplate.js'; +import MAP_MANAGER_PAGE_TEMPLATE from '../template/mapPrintManagerTemplate.js'; export default function mapPrintManagerPage($element) { $element.innerHTML = MAP_MANAGER_PAGE_TEMPLATE(); From d85b549c203ff35c68f7598a4c86fc9b2fee3397 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 22:58:32 +0900 Subject: [PATCH 47/48] =?UTF-8?q?chore=20:=20eslint=20rules=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index ee22f13cf..3a2021c21 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,6 +21,8 @@ "no-restricted-properties": "off", "max-depth" : ["error", 2], "no-return-assign" : "off", - "no-continue" : "off" + "no-continue" : "off", + "no-param-reassign" : "off", + "import/extensions" : "off" } } From 29813913ae5db7af0167d4adb6037a16bc4f86d1 Mon Sep 17 00:00:00 2001 From: devhyun637 <59258239+devhyun637@users.noreply.github.com> Date: Tue, 15 Dec 2020 23:03:06 +0900 Subject: [PATCH 48/48] =?UTF-8?q?fix=20:=20=EB=8F=99=EC=9D=BC=ED=95=9C=20?= =?UTF-8?q?=EC=A2=85=EC=A0=90=EC=9D=84=20=EA=B0=80=EC=A7=84=20=EC=97=AD=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=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/utils/validator/lineValidator.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/validator/lineValidator.js b/src/utils/validator/lineValidator.js index a4cec836e..bc338d0bd 100644 --- a/src/utils/validator/lineValidator.js +++ b/src/utils/validator/lineValidator.js @@ -42,10 +42,10 @@ const isEqualLine = (startStationName, endStationName) => { }; const isEqualReverseLine = (startStationName, endStationName) => { - const endStationsIds = getStartStationIds(startStationName); - const StartStationsIds = getEndStationIds(endStationName); + const startStationIds = getStartStationIds(endStationName); + const endStationIds = getEndStationIds(startStationName); - const equalLine = StartStationsIds.filter((station, index) => station && endStationsIds[index]); + const equalLine = startStationIds.filter((station, index) => station && endStationIds[index]); return equalLine.length !== 0 ? alert('λ™μΌν•œ 쒅점을 κ°€μ§„ 노선이 μžˆμŠ΅λ‹ˆλ‹€') : true; };