-
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 #3 from ershegm/module4-task2
Module4 task2
- Loading branch information
Showing
11 changed files
with
154 additions
and
81 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
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 |
---|---|---|
@@ -1,14 +1,30 @@ | ||
import { | ||
render | ||
} from '../framework/render.js'; | ||
|
||
import FiltersView from '../view/filters-view.js'; | ||
import { FilterSettings } from '../const.js'; | ||
import { filterByType } from '../utils'; | ||
|
||
const filtersContainer = document.querySelector('.trip-controls__filters'); | ||
|
||
export default class FiltersPresenter { | ||
#pointsModel = null; | ||
#filters = []; | ||
|
||
constructor({pointsModel}) { | ||
this.#pointsModel = pointsModel; | ||
|
||
this.#filters = Object.entries(filterByType) | ||
.map(([type, filter]) => ({ | ||
...FilterSettings[type], | ||
type, | ||
disabled: filter(this.#pointsModel.get()).length === 0 | ||
})); | ||
} | ||
|
||
init() { | ||
render(new FiltersView(), filtersContainer); | ||
render(new FiltersView({ | ||
items: this.#filters | ||
}), filtersContainer); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,35 +1,26 @@ | ||
import AbstractView from '../framework/view/abstract-view.js'; | ||
import ItemListView from './item-list-view.js'; | ||
|
||
function createFiltersTemplate() { | ||
function createFilterItemTemplate(filter) { | ||
const { type, label, defaultSelected, disabled } = filter; | ||
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" checked> | ||
<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"> | ||
<label class="trip-filters__filter-label" for="filter-past">Past</label> | ||
</div> | ||
`<div class="trip-filters__filter"> | ||
<input id="filter-${type}" class="trip-filters__filter-input visually-hidden" type="radio" name="trip-filter" value="${type}" ${defaultSelected ? 'checked' : ''} ${disabled ? 'disabled' : ''}> | ||
<label class="trip-filters__filter-label" for="filter-${type}">${label}</label> | ||
</div>` | ||
); | ||
} | ||
|
||
function createFiltersTemplate(filters) { | ||
return ( | ||
`<form class="trip-filters" action="#" method="get"> | ||
${filters.map(createFilterItemTemplate).join('')} | ||
<button class="visually-hidden" type="submit">Accept filter</button> | ||
</form>` | ||
); | ||
} | ||
|
||
export default class FiltersView extends AbstractView { | ||
export default class FiltersView extends ItemListView { | ||
get template() { | ||
return createFiltersTemplate(); | ||
return createFiltersTemplate(this._items); | ||
} | ||
} |
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,21 @@ | ||
import AbstractView from '../framework/view/abstract-view.js'; | ||
|
||
export default class ItemListView extends AbstractView { | ||
_items = []; | ||
_handleItemChange = null; | ||
|
||
constructor ({ | ||
items, | ||
onItemChange | ||
}) { | ||
super(); | ||
this._items = items; | ||
this._handleItemChange = onItemChange; | ||
this.element.addEventListener('change', this.#itemChangeHandler); | ||
} | ||
|
||
#itemChangeHandler = (evt) => { | ||
evt.preventDefault(); | ||
this._handleItemChange?.(evt.target.dataset.item); | ||
}; | ||
} |