-
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 #6 from licos87/module4-task2
Шаблонизируй то
- Loading branch information
Showing
17 changed files
with
371 additions
and
136 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,4 +1,35 @@ | ||
const EVENT_TYPES = ['taxi', 'bus', 'train', 'ship', 'drive', 'flight', 'check-in', 'sightseeing', 'restaurant']; | ||
const EVENT_TYPES = [ | ||
'taxi' | ||
, 'bus' | ||
, 'train' | ||
, 'ship' | ||
, 'drive' | ||
, 'flight' | ||
, 'check-in' | ||
, 'sightseeing' | ||
, 'restaurant']; | ||
|
||
const MESSAGE = { | ||
EMPTY: 'Click New Event to create your first point', | ||
LOADING: 'Loading...', | ||
FAILED_LOAD: 'Failed to load latest route information', | ||
}; | ||
|
||
export {EVENT_TYPES}; | ||
const FilterType = { | ||
EVERYTHING: 'everything', | ||
FUTURE: 'future', | ||
PRESENT: 'present', | ||
PAST: 'past' | ||
}; | ||
|
||
const SortType = { | ||
DAY: 'day', | ||
EVENT: 'event', | ||
TIME: 'time', | ||
PRICE: 'price', | ||
OFFERS: 'offers', | ||
}; | ||
|
||
const DisabledSortType = [SortType.EVENT, SortType.OFFERS]; | ||
|
||
export {EVENT_TYPES, MESSAGE, FilterType, SortType, DisabledSortType}; |
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,7 @@ | ||
import { filter } from '../utils/filter.js'; | ||
|
||
function generateFilter() { | ||
return Object.entries(filter).map(([filterType]) => ({type: filterType})); | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ export default class PointsTripModel { | |
this.#points = points; | ||
} | ||
|
||
get() { | ||
get points() { | ||
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { render, RenderPosition } from '../framework/render.js'; | ||
|
||
import SectionTripInfoView from '../view/section-trip-info-view.js'; | ||
import NewEventButtonView from '../view/new-event-button-view.js'; | ||
|
||
const tripMain = document.querySelector('.trip-main'); | ||
|
||
|
||
export default class HeaderPresenter { | ||
|
||
#pointsTrip = null; | ||
#destinations = null; | ||
#listPoints = []; | ||
|
||
constructor({destinations, pointsTrip}) { | ||
this.#pointsTrip = pointsTrip; | ||
this.#destinations = destinations; | ||
} | ||
|
||
init() { | ||
this.#listPoints = [...this.#pointsTrip]; | ||
|
||
this.#renderTripHeader(); | ||
|
||
} | ||
|
||
|
||
/** Создание шапки сайта */ | ||
#renderTripHeader() { | ||
render(new SectionTripInfoView({allDestinations: this.#destinations , allPoints: this.#listPoints}), tripMain, RenderPosition.AFTERBEGIN); // Заголовок, даты, общая цена | ||
|
||
render(new NewEventButtonView(), tripMain); // Заголовок, кнопка добавить событие | ||
} | ||
} |
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,53 @@ | ||
import { FilterType } from '../const.js'; | ||
import dayjs from 'dayjs'; | ||
|
||
const filter = { | ||
[FilterType.EVERYTHING]: (pointsTrip) => pointsTrip, | ||
[FilterType.FUTURE]: (pointsTrip) => pointsTrip.filter((pointTrip) => new Date(pointTrip.date_from) > Date.now()), | ||
[FilterType.PRESENT]: (pointsTrip) => pointsTrip.filter((pointTrip) => new Date(pointTrip.date_from) <= Date.now() && new Date(pointTrip.date_to) >= Date.now()), | ||
[FilterType.PAST]: (pointsTrip) => pointsTrip.filter((pointTrip) => new Date(pointTrip.date_to) < Date.now()), | ||
}; | ||
|
||
|
||
function sortEventsByDay (eventA, eventB) { | ||
|
||
if (dayjs(eventA.date_from).diff(dayjs(eventB.date_from)) < 0) { | ||
return -1; | ||
} | ||
|
||
if (dayjs(eventA.date_from).diff(dayjs(eventB.date_from)) > 0) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
function sortEventsByTime (eventA, eventB) { | ||
|
||
if (dayjs(eventA.date_from).diff(dayjs(eventA.date_to)) < | ||
dayjs(eventB.date_from).diff(dayjs(eventB.date_to))) { | ||
return -1; | ||
} | ||
|
||
if (dayjs(eventA.date_from).diff(dayjs(eventA.date_to)) > | ||
dayjs(eventB.date_from).diff(dayjs(eventB.date_to))) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
function sortEventsByPrice (eventA, eventB) { | ||
|
||
if (eventA.base_price < eventB.base_price) { | ||
return -1; | ||
} | ||
|
||
if (eventA.base_price > eventB.base_price) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
export { filter, sortEventsByDay, sortEventsByTime, sortEventsByPrice }; |
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
Oops, something went wrong.