-
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
Showing
8 changed files
with
101 additions
and
227 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
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,65 +1,31 @@ | ||
import {createElement} from '../render.js'; | ||
import './abstract-view.css'; | ||
|
||
/** @const {string} Класс, реализующий эффект "покачивания головой" */ | ||
const SHAKE_CLASS_NAME = 'shake'; | ||
|
||
/** @const {number} Время анимации в миллисекундах */ | ||
const SHAKE_ANIMATION_TIMEOUT = 600; | ||
|
||
/** | ||
* Абстрактный класс представления | ||
*/ | ||
export default class AbstractView { | ||
/** @type {HTMLElement|null} Элемент представления */ | ||
#element = null; | ||
|
||
constructor() { | ||
if (new.target === AbstractView) { | ||
throw new Error('Can\'t instantiate AbstractView, only concrete one.'); | ||
} | ||
} | ||
|
||
/** | ||
* Геттер для получения элемента | ||
* @returns {HTMLElement} Элемент представления | ||
*/ | ||
get element() { | ||
if (!this.#element) { | ||
this.#element = createElement(this.template); | ||
} | ||
|
||
return this.#element; | ||
} | ||
|
||
/** | ||
* Геттер для получения разметки элемента | ||
* @abstract | ||
* @returns {string} Разметка элемента в виде строки | ||
*/ | ||
get template() { | ||
throw new Error('Abstract method not implemented: get template'); | ||
} | ||
|
||
/** Метод для удаления элемента */ | ||
removeElement() { | ||
this.#element = null; | ||
} | ||
|
||
/** | ||
* Метод, реализующий эффект "покачивания головой" | ||
* @param {shakeCallback} [callback] Функция, которая будет вызвана после завершения анимации | ||
*/ | ||
shake(callback) { | ||
this.element.classList.add(SHAKE_CLASS_NAME); | ||
setTimeout(() => { | ||
this.element.classList.remove(SHAKE_CLASS_NAME); | ||
callback?.(); | ||
}, SHAKE_ANIMATION_TIMEOUT); | ||
} | ||
} | ||
|
||
/** | ||
* Функция, которая будет вызвана методом shake после завершения анимации | ||
* @callback shakeCallback | ||
*/ | ||
import { | ||
render, | ||
RenderPosition | ||
} from './render.js'; | ||
import TripInfoView from './view/create-trip.js'; | ||
import FiltersView from './view/create-filter.js'; | ||
import PointsPresenter from './presenter/board-presenter.js'; | ||
|
||
const tripMainContainer = document.querySelector('.trip-main'); | ||
const tripEventsContainer = document.querySelector('.trip-events'); | ||
const filtersContainer = tripMainContainer.querySelector('.trip-controls__filters'); | ||
|
||
import PointsModel from './model/event-points-model.js'; | ||
import OffersModel from './model/offers-model.js'; | ||
import DestinationsModel from './model/destinations-model.js'; | ||
|
||
const pointsModel = new PointsModel(); | ||
const offersModel = new OffersModel(); | ||
const destinationsModel = new DestinationsModel(); | ||
|
||
const pointsPresenter = new PointsPresenter({ | ||
tripEventsContainer, | ||
pointsModel, | ||
offersModel, | ||
destinationsModel | ||
}); | ||
|
||
render(new TripInfoView(), tripMainContainer, RenderPosition.AFTERBEGIN); | ||
render(new FiltersView(), filtersContainer); | ||
|
||
pointsPresenter.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 |
---|---|---|
@@ -1,17 +1,15 @@ | ||
export default class DestinationsModel { | ||
#service = null; | ||
#destinations = null; | ||
import { getDestinations } from '../mock/destinations.js'; | ||
|
||
constructor(service) { | ||
this.#service = service; | ||
this.#destinations = this.#service.destinations; | ||
export default class DestinationsModel { | ||
constructor() { | ||
this.destinations = getDestinations(); | ||
} | ||
|
||
get() { | ||
return this.#destinations; | ||
return this.destinations; | ||
} | ||
|
||
getById(id) { | ||
return this.#destinations.find((destination) => destination.id === id); | ||
return this.destinations.find((destination) => destination.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,14 +1,12 @@ | ||
export default class PointsModel { | ||
#service = null; | ||
#points = null; | ||
import { getRandomEventPoint } from '../mock/event-points.js'; | ||
import { POINTS_COUNT } from '../const.js'; | ||
|
||
constructor(service) { | ||
this.#service = service; | ||
this.#points = this.#service.points; | ||
export default class PointsModel { | ||
constructor() { | ||
this.points = Array.from({ length: POINTS_COUNT }, getRandomEventPoint); | ||
} | ||
|
||
get() { | ||
return this.#points; | ||
getEventPoints() { | ||
return this.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,17 +1,15 @@ | ||
export default class OffersModel { | ||
#service = null; | ||
#offers = null; | ||
import { getOffers } from '../mock/offers.js'; | ||
|
||
constructor(service) { | ||
this.#service = service; | ||
this.#offers = this.#service.offers; | ||
export default class OffersModel { | ||
constructor() { | ||
this.offers = getOffers(); | ||
} | ||
|
||
get() { | ||
return this.#offers; | ||
return this.offers; | ||
} | ||
|
||
getByType(type) { | ||
return this.#offers.find((offers) => offers.type === type.toLowerCase()).offers; | ||
return this.offers.find((offers) => offers.type === type.toLowerCase()).offers; | ||
} | ||
} |
Oops, something went wrong.