-
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.
- Loading branch information
1 parent
27b0a0a
commit 9b508d1
Showing
21 changed files
with
553 additions
and
255 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,19 +1,29 @@ | ||
import BoardPresenter from './presenter/board-presenter.js'; | ||
import TripPresenter from './presenter/trip-presenter.js'; | ||
import FilterPresenter from './presenter/filter-presenter.js'; | ||
|
||
import DestinationModel from './model/destination-model.js'; | ||
import OfferModel from './model/offers-model.js'; | ||
import PointModel from './model/point-model.js'; | ||
import MockService from './service/mock-service.js'; | ||
|
||
const bodyElement = document.querySelector('body'); | ||
|
||
const mockService = new MockService(); | ||
const destinationsModel = new DestinationModel(mockService); | ||
const pointsModel = new PointModel(mockService); | ||
const offersModel = new OfferModel(mockService); | ||
const boardPresenterElement = new BoardPresenter({ | ||
boardContainer: bodyElement, | ||
|
||
const filterPresenterElement = new FilterPresenter({ | ||
filterContainer: bodyElement, | ||
pointsModel | ||
}); | ||
|
||
const tripPresenterElement = new TripPresenter({ | ||
tripContainer: bodyElement, | ||
destinationsModel, | ||
offersModel, | ||
pointsModel | ||
}); | ||
|
||
boardPresenterElement.init(); | ||
filterPresenterElement.init(); | ||
tripPresenterElement.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,16 @@ | ||
import {FilterType} from './const.js'; | ||
import {ispointExpired} from '../utils.js'; | ||
|
||
const filter = { | ||
[FilterType.EVERYTHING]: (points) => points.filter((point) => point), | ||
[FilterType.FUTURE]:(points) => points.filter((point) => !ispointExpired(point.dateFrom) && !ispointExpired(point.dateTo)), | ||
[FilterType.PRESENT]:(points) => points.filter((point) => ispointExpired(point.dateFrom) && !ispointExpired(point.dateTo)), | ||
[FilterType.PAST]: (points) => points.filter((point) => ispointExpired(point.dateFrom) && ispointExpired(point.dateTo)) | ||
}; | ||
|
||
export const generateFilter = (points) => ( | ||
Object.entries(filter).map(([filterType, filterPoints]) => ({ | ||
type: filterType, | ||
filteredPoints: filterPoints(points) | ||
})) | ||
); |
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,10 +1,8 @@ | ||
import {getRandomArrayElement, getRandomInt} from '../utils.js'; | ||
import {OFFERS} from './const.js'; | ||
|
||
export const generateOffer = () => ({ | ||
offers: | ||
{ | ||
id: crypto.randomUUID(), | ||
title: getRandomArrayElement(OFFERS), | ||
price: getRandomInt() | ||
} | ||
id: crypto.randomUUID(), | ||
title: getRandomArrayElement(OFFERS), | ||
price: getRandomInt() | ||
}); |
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,12 +1,13 @@ | ||
import {getRandomInt, getRandomBulValue, getDate} from '../utils.js'; | ||
import {getRandomInt, getRandomBulValue, getDate, getRandomArrayElement} from '../utils.js'; | ||
|
||
export const generatePoint = (offerType, destinationId, offerIds) => ({ | ||
id: crypto.randomUUID(), | ||
basePrice: getRandomInt(), | ||
dateFrom: getDate(false), | ||
dateFrom: getDate(true), | ||
dateTo: getDate(true), | ||
destination: destinationId, | ||
isFavorite: getRandomBulValue(), | ||
offers: offerIds, | ||
offers: offerIds.map(() => (getRandomArrayElement(offerIds))), | ||
type: offerType | ||
} | ||
); |
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,17 @@ | ||
import {SortType} from './const.js'; | ||
import {getPointDuration} from '../utils.js'; | ||
|
||
const sort = { | ||
[SortType.DAY]: (points) => points.sort((point) => point.dateFrom), | ||
[SortType.EVENT]: (points) => points.sort((point) => point), | ||
[SortType.TIME]:(points) => points.sort((point) => getPointDuration(point.dateFrom, point.dateTo)), | ||
[SortType.PRICE]: (points) => points.sort((point) => point.basePrice), | ||
[SortType.OFFERS]: (points) => points.sort((point) => point), | ||
}; | ||
|
||
export const generateSorter = (points) => ( | ||
Object.entries(sort).map(([sortType, sortPoints]) => ({ | ||
type: sortType, | ||
sortedPoints: sortPoints(points) | ||
})) | ||
); |
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,13 +1,15 @@ | ||
export default class DestinationModel { | ||
#destinations = null; | ||
|
||
constructor(service){ | ||
this.destinations = service.getDestinations(); | ||
this.#destinations = service.getDestinations(); | ||
} | ||
|
||
get() { | ||
return this.destinations; | ||
return this.#destinations; | ||
} | ||
|
||
getById(id) { | ||
return this.destinations.find((destinations) => destinations.id === id); | ||
return this.#destinations.find((destinations) => destinations.id === id); | ||
} | ||
} |
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,13 +1,15 @@ | ||
export default class OfferModel { | ||
#offers = null; | ||
|
||
constructor(service){ | ||
this.offers = service.getOffers(); | ||
this.#offers = service.getOffers(); | ||
} | ||
|
||
get() { | ||
return this.offers; | ||
return this.#offers; | ||
} | ||
|
||
getByType(type) { | ||
return this.offers.find((offers) => offers.type === type).offers; | ||
return this.#offers.find((offers) => offers.type === type).offers; | ||
} | ||
} |
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,13 +1,15 @@ | ||
export default class PointModel { | ||
#points = null; | ||
|
||
constructor(service) { | ||
this.points = service.getPoints(); | ||
this.#points = service.getPoints(); | ||
} | ||
|
||
get() { | ||
return this.points; | ||
return this.#points; | ||
} | ||
|
||
getById(id) { | ||
return this.points.find((points) => points.id === id); | ||
return this.#points.find((points) => points.id === id); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {render} from '../framework/render.js'; | ||
import FilterView from '../view/filter-view.js'; | ||
import {generateFilter} from '../mock/filters.js'; | ||
|
||
export default class FilterPresenter{ | ||
#filterContainer = null; | ||
#pointsModel = null; | ||
|
||
constructor({filterContainer, pointsModel}) { | ||
this.#filterContainer = filterContainer; | ||
this.#pointsModel = pointsModel; | ||
} | ||
|
||
init(){ | ||
const points = [...this.#pointsModel.get()]; | ||
const tripControlFiltersElement = this.#filterContainer.querySelector('.trip-controls__filters'); | ||
const filters = generateFilter(points); | ||
|
||
render(new FilterView({ | ||
filters, | ||
onFilterClick: (filterType) => { | ||
this.#renderFilteredPoints(filters.filter((filter) => (filter.type === filterType))[0]); | ||
} | ||
}), tripControlFiltersElement); | ||
} | ||
|
||
#renderFilteredPoints(points){ | ||
points.filteredPoints.forEach((point) => { | ||
//Заглушка, пока не знаю, как решить | ||
// eslint-disable-next-line no-console | ||
console.log(point); | ||
}); | ||
} | ||
} |
Oops, something went wrong.