-
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 #15 from lunianka/module4-task2
- Loading branch information
Showing
10 changed files
with
130 additions
and
28 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
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 { filter } from '../utils/filter.js'; | ||
|
||
const generateFilters = (points) => { | ||
return Object.entries(filter) | ||
.map(([filterType, filterPoints]) => ({ | ||
type: filterType, | ||
hasPoints: filterPoints(points).length > 0 | ||
})); | ||
}; | ||
|
||
export { generateFilters }; |
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,19 @@ | ||
import FilterView from '../view/filter-view.js'; | ||
import { render } from '../framework/render.js'; | ||
import { generateFilters } from '../mock/filter.js'; | ||
|
||
export default class FilterPresenter { | ||
#container = null; | ||
#pointsModel = null; | ||
#filters = []; | ||
|
||
constructor({ container, pointsModel }) { | ||
this.#container = container; | ||
this.#pointsModel = pointsModel; | ||
this.#filters = generateFilters(this.#pointsModel.get()); | ||
} | ||
|
||
init() { | ||
render(new FilterView(this.#filters), this.#container); | ||
} | ||
} |
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 { isPointFuture, isPointPresent, isPointPast } from '../utils.js'; | ||
|
||
const filter = { | ||
[FilterType.EVERYTHING]: (points) => [...points], | ||
[FilterType.FUTURE]: (points) => points.filter((point) => isPointFuture(point)), | ||
[FilterType.PRESENT]: (points) => points.filter((point) => isPointPresent(point)), | ||
[FilterType.PAST]: (points) => points.filter((point) => isPointPast(point)) | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import AbstractView from '../framework/view/abstract-view.js'; | ||
|
||
const createEmptyListViewTemplate = () => { | ||
return ( | ||
`<section class="trip-events"> | ||
<h2 class="visually-hidden">Trip events</h2> | ||
<p class="trip-events__msg">Click New Event to create your first point</p> | ||
</section>` | ||
); | ||
}; | ||
|
||
export default class EmptyListView extends AbstractView { | ||
get template() { | ||
return createEmptyListViewTemplate(); | ||
} | ||
} |
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,32 +1,41 @@ | ||
import AbstractView from '../framework/view/abstract-view.js'; | ||
import { capitalize } from '../utils.js'; | ||
|
||
const createFilterTemplate = () => { | ||
const createFilterItemsTemplate = ({ filters }) => { | ||
const filterItems = filters.map(filter => { | ||
return ( | ||
`<div class="trip-filters__filter"> | ||
<input id="filter-${filter.type}" class="trip-filters__filter-input visually-hidden" type="radio" name="trip-filter" value="${filter.type}" | ||
${(filter.hasPoints) ? '' : 'disabled'}> | ||
<label class="trip-filters__filter-label" for="filter-${filter.type}">${capitalize(filter.type)}</label> | ||
</div>` | ||
); | ||
}).join(''); | ||
|
||
return filterItems; | ||
}; | ||
|
||
const createFilterTemplate = ({ filters }) => { | ||
return ( | ||
`<form class="trip-filters" action="#" method="get"> | ||
<div class="trip-filters__filter"> | ||
<input id="filter-everything" class="trip-filters__filter-input visually-hidden" type="radio" name="trip-filter" value="everything"> | ||
<label class="trip-filters__filter-label" for="filter-everything">Everything</label> | ||
</div> | ||
<div class="trip-filters__filter"> | ||
<input id="filter-future" class="trip-filters__filter-input visually-hidden" type="radio" name="trip-filter" value="future"> | ||
<label class="trip-filters__filter-label" for="filter-future">Future</label> | ||
</div> | ||
<div class="trip-filters__filter"> | ||
<input id="filter-present" class="trip-filters__filter-input visually-hidden" type="radio" name="trip-filter" value="present"> | ||
<label class="trip-filters__filter-label" for="filter-present">Present</label> | ||
</div> | ||
<div class="trip-filters__filter"> | ||
<input id="filter-past" class="trip-filters__filter-input visually-hidden" type="radio" name="trip-filter" value="past" checked> | ||
<label class="trip-filters__filter-label" for="filter-past">Past</label> | ||
</div> | ||
<button class="visually-hidden" type="submit">Accept filter</button> | ||
${createFilterItemsTemplate({ filters })} | ||
<button class="visually-hidden" type="submit">Accept filter</button> | ||
</form>` | ||
); | ||
} | ||
}; | ||
|
||
export default class FilterView extends AbstractView { | ||
#filters = []; | ||
|
||
constructor(filters) { | ||
super(); | ||
this.#filters = filters; | ||
} | ||
|
||
get template() { | ||
return createFilterTemplate(); | ||
return createFilterTemplate({ | ||
filters: this.#filters | ||
}); | ||
} | ||
|
||
} |
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