-
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 #8 from vvvyat/module5-task2
- Loading branch information
Showing
11 changed files
with
218 additions
and
56 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
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,16 +1,18 @@ | ||
import FilterView from './view/filter-view.js'; | ||
import ListPresenter from './presenter/presenter.js'; | ||
import Presenter from './presenter/presenter.js'; | ||
import PointsModel from './model/points-model.js'; | ||
import {render} from './framework/render.js'; | ||
import {generateFilter} from './mock/filter.js'; | ||
|
||
const filterContainer = document.querySelector('.trip-controls__filters'); | ||
const pointsListContainer = document.querySelector('.trip-events'); | ||
|
||
const pointsModel = new PointsModel(); | ||
const listPresenter = new ListPresenter({ | ||
const presenter = new Presenter({ | ||
container: pointsListContainer, | ||
pointsModel | ||
}); | ||
|
||
render(new FilterView(), filterContainer); | ||
listPresenter.init(); | ||
const filters = generateFilter(pointsModel.points); | ||
render(new FilterView({filters}), filterContainer); | ||
presenter.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {filter} from '../utils/filters.js'; | ||
|
||
function generateFilter(points) { | ||
return Object.entries(filter).map( | ||
([filterType, filterPoints]) => ({ | ||
type: filterType, | ||
count: filterPoints(points).length, | ||
}), | ||
); | ||
} | ||
|
||
export {generateFilter}; |
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
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,11 @@ | ||
import {FilterType} from '../const.js'; | ||
import dayjs from 'dayjs'; | ||
|
||
const filter = { | ||
[FilterType.EVERYTHING]: (points) => points, | ||
[FilterType.FUTURE]: (points) => points.filter((point) => dayjs().isBefore(point.dateFrom)), | ||
[FilterType.PRESENT]: (points) => points.filter((point) => (dayjs().isAfter(point.dateFrom)) && dayjs().isBefore(point.dateTo)), | ||
[FilterType.PAST]: (points) => points.filter((point) => dayjs().isAfter(point.dateTo)), | ||
}; | ||
|
||
export {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 |
---|---|---|
@@ -1,27 +1,37 @@ | ||
import AbstractView from '../framework/view/abstract-view.js'; | ||
import {FILTERS, DEFAULT_FILTER} from '../const.js'; | ||
|
||
function createFilterTemplate(filterName, count) { | ||
const filter = filterName.toLowerCase(); | ||
const isChecked = filterName === DEFAULT_FILTER ? 'checked' : ''; | ||
function createFilterItemTemplate(filter, isChecked) { | ||
const {type, count} = filter; | ||
const isDisabled = count === 0 ? 'disabled' : ''; | ||
|
||
return ` | ||
<div class="trip-filters__filter"> | ||
<input id="filter-${filter}" class="trip-filters__filter-input visually-hidden" type="radio" name="trip-filter" value="${filter}" ${isChecked} ${isDisabled}> | ||
<label class="trip-filters__filter-label" for="filter-${filter}">${filterName}</label> | ||
<input id="filter-${type}" class="trip-filters__filter-input visually-hidden" type="radio" name="trip-filter" value="${type}" ${isChecked} ${isDisabled}> | ||
<label class="trip-filters__filter-label" for="filter-${type}">${type}</label> | ||
</div> | ||
`; | ||
} | ||
|
||
function createFilterTemplate(filters) { | ||
const filtersTemplate = filters | ||
.map((filter, index) => createFilterItemTemplate(filter, index === 0)) | ||
.join(''); | ||
|
||
return ` | ||
<form class="trip-filters" action="#" method="get"> | ||
${filtersTemplate} | ||
<button class="visually-hidden" type="submit">Accept filter</button> | ||
</form>`; | ||
} | ||
export default class FilterView extends AbstractView { | ||
get template() { | ||
const filtersTemplate = Object.entries(FILTERS).map(([filter, count]) => createFilterTemplate(filter, count)).join(''); | ||
#filters; | ||
|
||
constructor({filters}) { | ||
super(); | ||
this.#filters = filters; | ||
} | ||
|
||
return ` | ||
<form class="trip-filters" action="#" method="get"> | ||
${filtersTemplate} | ||
<button class="visually-hidden" type="submit">Accept filter</button> | ||
</form> | ||
`; | ||
get template() { | ||
return createFilterTemplate(this.#filters); | ||
} | ||
} |
Oops, something went wrong.