-
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 #5 from vvvyat/module4-task1
- Loading branch information
Showing
15 changed files
with
506 additions
and
206 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,24 +1,18 @@ | ||
import FilterView from './view/filter-view.js'; | ||
import SortView from './view/sort-view.js'; | ||
import ListPresenter from './presenter/list-presenter.js'; | ||
import {render} from './render.js'; | ||
import PointsModel from './model/points-model.js'; | ||
import DestinationsModel from './model/destinations-model.js'; | ||
import OffersModel from './model/offers-model.js'; | ||
import {render} from './framework/render.js'; | ||
|
||
const filterContainer = document.querySelector('.trip-controls__filters'); | ||
const sortAndListContainer = document.querySelector('.trip-events'); | ||
const pointsContainer = document.querySelector('.trip-events'); | ||
|
||
const pointsModel = new PointsModel(); | ||
const destinationsModel = new DestinationsModel({pointsModel}); | ||
const offersModel = new OffersModel({pointsModel}); | ||
const listPresenter = new ListPresenter({ | ||
container: sortAndListContainer, | ||
pointsModel: pointsModel, | ||
destinationsModel: destinationsModel, | ||
offersModel: offersModel | ||
container: pointsContainer, | ||
pointsModel | ||
}); | ||
|
||
render(new FilterView(), filterContainer); | ||
render(new SortView(), sortAndListContainer); | ||
render(new SortView(), pointsContainer); | ||
listPresenter.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 was deleted.
Oops, something went wrong.
This file was deleted.
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
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,30 +1,73 @@ | ||
import ListView from '../view/list-view.js'; | ||
import EditPointView from '../view/edit-point-view.js'; | ||
import ListPointView from '../view/list-point-view.js'; | ||
import {render} from '../render.js'; | ||
import ListPointView from '../view/point-view.js'; | ||
import {render, replace} from '../framework/render.js'; | ||
import {getDestinationById, getOffersByType, getSelectedOffers} from '../mock/point.js'; | ||
|
||
export default class ListPresenter { | ||
listComponent = new ListView(); | ||
#listComponent = new ListView(); | ||
#container; | ||
#pointsModel; | ||
#points; | ||
|
||
constructor({container, pointsModel, destinationsModel, offersModel}) { | ||
this.container = container; | ||
this.pointsModel = pointsModel; | ||
this.destinationsModel = destinationsModel; | ||
this.offersModel = offersModel; | ||
constructor({container, pointsModel}) { | ||
this.#container = container; | ||
this.#pointsModel = pointsModel; | ||
} | ||
|
||
init() { | ||
this.points = [...this.pointsModel.getPoints()]; | ||
this.destinations = [...this.destinationsModel.getDestinations(this.points)]; | ||
this.selectedOffers = [...this.offersModel.getSelectedOffers(this.points)]; | ||
this.typesOffers = [...this.offersModel.getTypesOffers(this.points)]; | ||
render(this.listComponent, this.container); | ||
render(new EditPointView({pointData: this.points[0], destinationData: this.destinations[0], offersByType: this.typesOffers[0]}), | ||
this.listComponent.getElement()); | ||
|
||
for (let i = 1; i < this.points.length; i++) { | ||
render(new ListPointView({pointData: this.points[i], destinationData: this.destinations[i], | ||
selectedOffersData: this.selectedOffers[i]}), this.listComponent.getElement()); | ||
this.#points = [...this.#pointsModel.points]; | ||
render(this.#listComponent, this.#container); | ||
|
||
for (let i = 0; i < this.#points.length; i++) { | ||
this.#renderPoint(this.#points[i]); | ||
} | ||
} | ||
|
||
#renderPoint(point) { | ||
const escKeyDownHandler = (evt) => { | ||
if (evt.key === 'Escape') { | ||
evt.preventDefault(); | ||
replaceEditFormToPoint(); | ||
document.removeEventListener('keydown', escKeyDownHandler); | ||
} | ||
}; | ||
|
||
const offersByType = getOffersByType(point.type); | ||
const destination = getDestinationById(point.destination); | ||
|
||
const pointComponent = new ListPointView({ | ||
point, | ||
destination, | ||
selectedOffers: getSelectedOffers(point.offers, offersByType), | ||
handleClick: () => { | ||
replacePointToEditForm(); | ||
document.addEventListener('keydown', escKeyDownHandler); | ||
} | ||
}); | ||
|
||
const pointEditComponent = new EditPointView({ | ||
point, | ||
destination, | ||
offersByType, | ||
handleSubmit: () => { | ||
replaceEditFormToPoint(); | ||
document.removeEventListener('keydown', escKeyDownHandler); | ||
}, | ||
handleClick: () => { | ||
replaceEditFormToPoint(); | ||
document.removeEventListener('keydown', escKeyDownHandler); | ||
} | ||
}); | ||
|
||
function replacePointToEditForm() { | ||
replace(pointEditComponent, pointComponent); | ||
} | ||
|
||
function replaceEditFormToPoint() { | ||
replace(pointComponent, pointEditComponent); | ||
} | ||
|
||
render(pointComponent, this.#listComponent.element); | ||
} | ||
} |
This file was deleted.
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
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.