-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from InsomniaRolodex/module7-task1
- Loading branch information
Showing
18 changed files
with
723 additions
and
155 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
}, | ||
"dependencies": { | ||
"dayjs": "1.11.6", | ||
"flatpickr": "4.6.13" | ||
"flatpickr": "4.6.13", | ||
"he": "1.2.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
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,15 +1,21 @@ | ||
import TripPresenter from './presenter/trip-presenter.js'; | ||
import HeaderPresenter from './presenter/header-presenter.js'; | ||
import FilterPresenter from './presenter/filter-presenter.js'; | ||
import FilterModel from './model/filter-model.js'; | ||
import PointModel from './model/point-model.js'; | ||
|
||
const tripSection = document.querySelector('.trip-events'); | ||
const headerContainer = document.querySelector('.trip-main'); | ||
const filtersContainer = document.querySelector('.trip-controls__filters'); | ||
|
||
const filterModel = new FilterModel(); | ||
const pointsModel = new PointModel(); | ||
|
||
const tripSectionPresenter = new TripPresenter({container: tripSection}); | ||
|
||
const tripSectionPresenter = new TripPresenter({container: tripSection, filterModel}); | ||
const tripInfoPresenter = new HeaderPresenter({container: headerContainer}); | ||
const filtersPresenter = new HeaderPresenter({ container: filtersContainer }); | ||
const filterPresenter = new FilterPresenter({ filtersContainer, filterModel, pointsModel }); | ||
|
||
tripInfoPresenter.initInfo(); | ||
filtersPresenter.initFilters(); | ||
filterPresenter.init(); | ||
tripSectionPresenter.init(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Observable from '../framework/observable.js'; | ||
import { FilterType } from '../const.js'; | ||
|
||
export default class FilterModel extends Observable { | ||
#filter = FilterType.EVERYTHING; | ||
|
||
get filter() { | ||
return this.#filter; | ||
} | ||
|
||
setFilter(updateType, filter) { | ||
this.#filter = filter; | ||
this._notify(updateType, filter); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
|
||
import FiltersView from '../view/filters-view'; | ||
import { FilterType, UpdateType } from '../const'; | ||
import { remove, replace, render } from '../framework/render'; | ||
import { filter } from '../util.js'; | ||
|
||
export default class FilterPresenter { | ||
#filtersContainer; | ||
#pointsModel; | ||
#filterComponent = null; | ||
#filterModel; | ||
|
||
constructor ({filtersContainer, filterModel, pointsModel}) { | ||
this.#filtersContainer = filtersContainer; | ||
this.#filterModel = filterModel; | ||
this.#pointsModel = pointsModel; | ||
|
||
this.#pointsModel.addObserver(this.#handleModelEvent); | ||
this.#filterModel.addObserver(this.#handleModelEvent); | ||
} | ||
|
||
get filters () { | ||
const points = this.#pointsModel.points; | ||
|
||
return [ | ||
{ | ||
type: FilterType.EVERYTHING, | ||
name: 'Everything', | ||
count: filter[FilterType.EVERYTHING](points).length | ||
}, | ||
{ | ||
type: FilterType.FUTURE, | ||
name: 'Future', | ||
count: filter[FilterType.FUTURE](points).length | ||
}, | ||
{ | ||
type: FilterType.PRESENT, | ||
name: 'Present', | ||
count: filter[FilterType.PRESENT](points).length | ||
}, | ||
{ | ||
type: FilterType.PAST, | ||
name: 'Past', | ||
count: filter[FilterType.PAST](points).length | ||
} | ||
]; | ||
} | ||
|
||
init () { | ||
const filters = this.filters; | ||
const prevFilterComponent = this.#filterComponent; | ||
|
||
this.#filterComponent = new FiltersView( | ||
this.#pointsModel.points, | ||
{ | ||
filters, | ||
currentFilterType: this.#filterModel.filter, | ||
onFilterTypeChange: this.#handleFilterTypeChange | ||
}); | ||
|
||
if (prevFilterComponent === null) { | ||
render(this.#filterComponent, this.#filtersContainer); | ||
return; | ||
} | ||
|
||
replace(this.#filterComponent, prevFilterComponent); | ||
remove(prevFilterComponent); | ||
} | ||
|
||
#handleModelEvent = () => { | ||
this.init(); | ||
}; | ||
|
||
#handleFilterTypeChange = (filterType) => { | ||
if (this.#filterModel.filter === filterType) { | ||
|
||
return; | ||
} | ||
|
||
this.#filterModel.setFilter(UpdateType.MAJOR, filterType); | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import {remove, render, RenderPosition} from '../framework/render.js'; | ||
import CreateFormView from '../view/create-form-view.js'; | ||
import { UserAction, UpdateType } from '../const.js'; | ||
|
||
export default class NewPointPresenter { | ||
#tripList; | ||
#handleDataChange; | ||
#handleDestroy; | ||
#createTripForm = null; | ||
|
||
constructor ({tripList, onDataChange}) { | ||
this.#tripList = tripList; | ||
this.#handleDataChange = onDataChange; | ||
} | ||
|
||
init(point, destination, offer) { | ||
if(this.#createTripForm !== null) { | ||
return; | ||
} | ||
|
||
this.#createTripForm = new CreateFormView(point, destination, offer, | ||
{ | ||
onFormSubmit: (newPoint) => { | ||
this.#handleFormSubmit(newPoint); | ||
}, | ||
onDeleteClick: () => { | ||
this.#handleDeleteClick(point); | ||
}, | ||
onNewEventClick: () => { | ||
this.#handleNewEventClick(point, destination, offer); | ||
} | ||
}); | ||
|
||
document.addEventListener('keydown', this.#escKeyDownHandler); | ||
} | ||
|
||
destroy() { | ||
if (this.#createTripForm === null) { | ||
return; | ||
} | ||
|
||
remove(this.#createTripForm); | ||
this.#createTripForm = null; | ||
|
||
document.removeEventListener('keydown', this.#escKeyDownHandler); | ||
} | ||
|
||
#handleFormSubmit = (point) => { | ||
this.#handleDataChange( | ||
UserAction.ADD_POINT, | ||
UpdateType.MINOR, | ||
{id: `test${Math.random().toString()}`, ...point} | ||
); | ||
|
||
this.destroy(); | ||
}; | ||
|
||
#handleDeleteClick = () => { | ||
this.destroy(); | ||
}; | ||
|
||
#escKeyDownHandler = (evt) => { | ||
if (evt.key === 'Escape' || evt.key === 'Esc') { | ||
evt.preventDefault(); | ||
this.destroy(); | ||
} | ||
}; | ||
|
||
#handleNewEventClick(point, destination, offer) { | ||
this.init(point, destination, offer); | ||
render(this.#createTripForm, this.#tripList.element, RenderPosition.AFTERBEGIN); | ||
} | ||
} |
Oops, something went wrong.