-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
715 additions
and
613 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
import { View, Controller, Component, Router } from '@sndcds/mvc' | ||
|
||
|
||
export default class App extends Controller { | ||
/* eslint no-useless-constructor: 0 */ | ||
constructor(model, view) { | ||
super(model, view) | ||
} | ||
/* eslint no-useless-constructor: 0 */ | ||
constructor(model, view) { | ||
super(model, view) | ||
} | ||
|
||
initApp(url, id) { | ||
this.data = this.model.getStorage('data') | ||
this.districtId = this.model.getStorage('districtId') | ||
initApp(url, id) { | ||
this.data = this.model.getStorage('data') | ||
this.districtId = this.model.getStorage('districtId') | ||
|
||
if (this.districtId === null) { | ||
this.model.setDistrictId(id) | ||
} | ||
else { | ||
this.model.setDistrictId(this.districtId) | ||
} | ||
if (this.districtId === null) { | ||
this.model.setDistrictId(id) | ||
} else { | ||
this.model.setDistrictId(this.districtId) | ||
} | ||
|
||
if (this.data === null) { | ||
this.fetchData(url) | ||
} | ||
else { | ||
// this.state.onDataChanged(this.data) | ||
} | ||
if (this.data === null) { | ||
this.fetchData(url) | ||
} else { | ||
// this.state.onDataChanged(this.data) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,36 @@ | ||
import { Model } from '@sndcds/mvc' | ||
|
||
|
||
export default class AppModel extends Model { | ||
constructor() { | ||
super() | ||
this.data = null | ||
this.districtNames = null | ||
this.districtObject = null | ||
this.districtId = null | ||
} | ||
constructor() { | ||
super() | ||
this.data = null | ||
this.districtNames = null | ||
this.districtObject = null | ||
this.districtId = null | ||
} | ||
|
||
bindDataChanged(callback) { | ||
this.onDataChanged = callback | ||
} | ||
bindDataChanged(callback) { | ||
this.onDataChanged = callback | ||
} | ||
|
||
setDataObject(data) { | ||
this.data = data | ||
this.districtNames = data.map((item) => item.district_name) | ||
this.setStorage('data', data) | ||
} | ||
setDataObject(data) { | ||
this.data = data | ||
this.districtNames = data.map((item) => item.district_name) | ||
this.setStorage('data', data) | ||
} | ||
|
||
setDistrictId(districtId) { | ||
this.districtId = districtId | ||
this.setStorage('districtId', districtId) | ||
} | ||
setDistrictId(districtId) { | ||
this.districtId = districtId | ||
this.setStorage('districtId', districtId) | ||
} | ||
|
||
setDistrictObject(districtId) { | ||
const condition = (district) => district.district_id === districtId | ||
const items = this.data.filter(condition) | ||
setDistrictObject(districtId) { | ||
const condition = (district) => district.district_id === districtId | ||
const items = this.data.filter(condition) | ||
|
||
if (items.length > 0) { | ||
this.districtObject = items[0] | ||
this.setStorage('districtObject', items[0]) | ||
} | ||
if (items.length > 0) { | ||
this.districtObject = items[0] | ||
this.setStorage('districtObject', items[0]) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,41 @@ | ||
import { Component } from '@sndcds/mvc' | ||
|
||
|
||
export default class DistrictSelectComponent extends Component { | ||
/* eslint no-useless-constructor: 0 */ | ||
constructor(parent, id, setupData) { | ||
super(parent, id, setupData) | ||
} | ||
|
||
build() { | ||
this.e = this.domCreateElement('div') | ||
this.parent.e.appendChild(this.e) | ||
} | ||
|
||
setProperties(data) { | ||
console.trace() | ||
const selectElement = this.domCreateElement('select') | ||
|
||
data.data.forEach((item) => { | ||
const optionElement = this.domCreateElement('option') | ||
|
||
optionElement.value = item.district_id | ||
optionElement.textContent = item.district_name | ||
|
||
if (optionElement.value === data.districtId) { | ||
optionElement.selected = true | ||
} | ||
|
||
selectElement.appendChild(optionElement) | ||
}) | ||
|
||
this.e.appendChild(selectElement) | ||
} | ||
|
||
bindDistrictChanged(handler) { | ||
const e = this.e.children.item(0) | ||
e.addEventListener('change', (event) => { | ||
const selectedOption = e.value | ||
handler(selectedOption - 1) | ||
}) | ||
} | ||
} | ||
/* eslint no-useless-constructor: 0 */ | ||
constructor(parent, id, setupData) { | ||
super(parent, id, setupData) | ||
} | ||
|
||
build() { | ||
this.e = this.domCreateElement('div') | ||
this.parent.e.appendChild(this.e) | ||
} | ||
|
||
setProperties(data) { | ||
console.trace() | ||
const selectElement = this.domCreateElement('select') | ||
|
||
data.data.forEach((item) => { | ||
const optionElement = this.domCreateElement('option') | ||
|
||
optionElement.value = item.district_id | ||
optionElement.textContent = item.district_name | ||
|
||
if (optionElement.value === data.districtId) { | ||
optionElement.selected = true | ||
} | ||
|
||
selectElement.appendChild(optionElement) | ||
}) | ||
|
||
this.e.appendChild(selectElement) | ||
} | ||
|
||
bindDistrictChanged(handler) { | ||
const e = this.e.children.item(0) | ||
e.addEventListener('change', (event) => { | ||
const selectedOption = e.value | ||
handler(selectedOption - 1) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.