Skip to content

Commit

Permalink
Разделяй и властвуй2
Browse files Browse the repository at this point in the history
  • Loading branch information
lunianka committed Apr 14, 2024
1 parent 1385812 commit 05f9a66
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 273 deletions.
72 changes: 36 additions & 36 deletions src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,56 @@ const CITIES = [
];

const OFFERS = [
'Order Uber',
'Add luggage',
'Switch to comfort',
'Rent a car',
'Add breakfast',
'Book tickets',
'Lunch in city',
'Upgrade to a business class'
'Order Uber',
'Add luggage',
'Switch to comfort',
'Rent a car',
'Add breakfast',
'Book tickets',
'Lunch in city',
'Upgrade to a business class'
];

const DESCRIPTION = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras aliquet varius magna, non porta ligula feugiat eget. Fusce tristique felis at fermentum pharetra. Aliquam id orci ut lectus varius viverra.';

const Price = {
MIN: 1,
MAX: 1000
MIN: 1,
MAX: 1000
};

const TYPES = [
'taxi',
'bus',
'train',
'ship',
'drive',
'flight',
'check-in',
'sightseeing',
'restaurant'
'taxi',
'bus',
'train',
'ship',
'drive',
'flight',
'check-in',
'sightseeing',
'restaurant'
];

const DEFAULT_TYPE = 'flight';

const POINT_EMPTY = {
basePrice: 0,
dateFrom: null,
dateTo: null,
destination: null,
isFavorite: false,
offers: [],
type: DEFAULT_TYPE
basePrice: 0,
dateFrom: null,
dateTo: null,
destination: null,
isFavorite: false,
offers: [],
type: DEFAULT_TYPE
};

export {
OFFER_COUNT,
DESTINATION_COUNT,
POINT_COUNT,
CITIES,
OFFERS,
DESCRIPTION,
Price,
TYPES,
DEFAULT_TYPE,
POINT_EMPTY
OFFER_COUNT,
DESTINATION_COUNT,
POINT_COUNT,
CITIES,
OFFERS,
DESCRIPTION,
Price,
TYPES,
DEFAULT_TYPE,
POINT_EMPTY
}

Check failure on line 73 in src/const.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const destinationsModel = new DestinationsModel(mockService);
const offersModel = new OffersModel(mockService);
const pointsModel = new PointsModel(mockService);

const tripPresenter = new TripPresenter({tripContainer: eventListElement, destinationsModel, offersModel, pointsModel});
const tripPresenter = new TripPresenter({ tripContainer: eventListElement, destinationsModel, offersModel, pointsModel });

render(new TripInfoView(), tripInfoElement, RenderPosition.AFTERBEGIN);
render(new FilterView(), tripInfoElement.querySelector('.trip-controls__filters'));
Expand Down
124 changes: 62 additions & 62 deletions src/presenter/trip-presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,79 @@ import TripView from '../view/point-list-view.js';
import { render, replace } from '../framework/render.js';

export default class TripPresenter {
#tripContainer = null;
#destinationsModel = null;
#offersModel = null;
#pointsModel = null;
#pointListComponent = new TripView();
#sortComponent = new SortView();
#tripContainer = null;
#destinationsModel = null;
#offersModel = null;
#pointsModel = null;
#pointListComponent = new TripView();
#sortComponent = new SortView();

#points = [];
#points = [];

constructor({tripContainer, destinationsModel, offersModel, pointsModel}) {
this.#tripContainer = tripContainer;
this.#destinationsModel = destinationsModel;
this.#offersModel = offersModel;
this.#pointsModel = pointsModel;
this.#points = [...this.#pointsModel.get()];
}
constructor({ tripContainer, destinationsModel, offersModel, pointsModel }) {
this.#tripContainer = tripContainer;
this.#destinationsModel = destinationsModel;
this.#offersModel = offersModel;
this.#pointsModel = pointsModel;
this.#points = [...this.#pointsModel.get()];
}

init() {
render(this.#sortComponent, this.#tripContainer);
render(this.#pointListComponent, this.#tripContainer);
init() {
render(this.#sortComponent, this.#tripContainer);
render(this.#pointListComponent, this.#tripContainer);

this.#points.forEach((point) => {
this.#renderPoint(point);
});
}
this.#points.forEach((point) => {
this.#renderPoint(point);
});
}

#renderPoint = (point) => {
const pointComponent = new PointView({
point,
pointDestination: this.#destinationsModel.getById(point.destination),
pointOffers: this.#offersModel.getByType(point.type),
onEditClick: pointEditClickHandler
});
#renderPoint = (point) => {
const pointComponent = new PointView({
point,
pointDestination: this.#destinationsModel.getById(point.destination),
pointOffers: this.#offersModel.getByType(point.type),
onEditClick: pointEditClickHandler
});

const editPointComponent = new EditPointView({
point,
pointDestination: this.#destinationsModel.getById(point.destination),
pointOffers: this.#offersModel.getByType(point.type),
onSubmitClick: pointSubmitHandler,
onResetClick: resetButtonClickHandler
});
const editPointComponent = new EditPointView({
point,
pointDestination: this.#destinationsModel.getById(point.destination),
pointOffers: this.#offersModel.getByType(point.type),
onSubmitClick: pointSubmitHandler,
onResetClick: resetButtonClickHandler
});

const replacePointToForm = () => {
replace(editPointComponent, pointComponent);
};
const replacePointToForm = () => {
replace(editPointComponent, pointComponent);
};

const replaceFormToPoint = () => {
replace(pointComponent, editPointComponent);
};
const replaceFormToPoint = () => {
replace(pointComponent, editPointComponent);
};

const escKeyDownHandler = (evt) => {
if (evt.key === 'Escape' || evt.key === 'Esc') {
evt.preventDefault();
replaceFormToPoint();
document.removeEventListener('keydown', escKeyDownHandler);
}
};
const escKeyDownHandler = (evt) => {
if (evt.key === 'Escape' || evt.key === 'Esc') {
evt.preventDefault();
replaceFormToPoint();
document.removeEventListener('keydown', escKeyDownHandler);
}
};

function pointEditClickHandler() {
replacePointToForm();
document.addEventListener('keydown', escKeyDownHandler);
};
function pointEditClickHandler() {
replacePointToForm();
document.addEventListener('keydown', escKeyDownHandler);
};

Check failure on line 69 in src/presenter/trip-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Unnecessary semicolon

function resetButtonClickHandler() {
replaceFormToPoint();
document.removeEventListener('keydown', escKeyDownHandler);
};
function resetButtonClickHandler() {
replaceFormToPoint();
document.removeEventListener('keydown', escKeyDownHandler);
};

Check failure on line 74 in src/presenter/trip-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Unnecessary semicolon

function pointSubmitHandler() {
replaceFormToPoint();
document.removeEventListener('keydown', escKeyDownHandler);
};
function pointSubmitHandler() {
replaceFormToPoint();
document.removeEventListener('keydown', escKeyDownHandler);
};

Check failure on line 79 in src/presenter/trip-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Unnecessary semicolon

render(pointComponent, this.#pointListComponent.element);
}
render(pointComponent, this.#pointListComponent.element);
}

Check failure on line 82 in src/presenter/trip-presenter.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
}
2 changes: 1 addition & 1 deletion src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ function render(component, container, place = RenderPosition.BEFOREEND) {
container.insertAdjacentElement(place, component.getElement());
}

export {RenderPosition, createElement, render};
export { RenderPosition, createElement, render };
100 changes: 50 additions & 50 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,88 +6,88 @@ dayjs.extend(duration);
dayjs.extend(relativeTime);

const TimePeriods = {
MSEC_IN_SEC: 1000,
SEC_IN_MIN: 60,
MIN_IN_HOUR: 60,
HOUR_IN_DAY: 24
MSEC_IN_SEC: 1000,
SEC_IN_MIN: 60,
MIN_IN_HOUR: 60,
HOUR_IN_DAY: 24
}

Check failure on line 13 in src/utils.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon

const MSEC_IN_HOUR = TimePeriods.MIN_IN_HOUR * TimePeriods.SEC_IN_MIN * TimePeriods.MSEC_IN_SEC;
const MSEC_IN_DAY = TimePeriods.HOUR_IN_DAY * MSEC_IN_HOUR;

const Duration = {
HOUR: 5,
DAY: 5,
MIN: 59
HOUR: 5,
DAY: 5,
MIN: 59
};

let date = dayjs().subtract(getRandomInteger(0, Duration.DAY), 'day').toDate();

function getDate({next}) {
const minsGap = getRandomInteger(0, Duration.MIN);
const hoursGap = getRandomInteger(1, Duration.HOUR);
const daysGap = getRandomInteger(0, Duration.DAY);
function getDate({ next }) {
const minsGap = getRandomInteger(0, Duration.MIN);
const hoursGap = getRandomInteger(1, Duration.HOUR);
const daysGap = getRandomInteger(0, Duration.DAY);

if (next) {
date = dayjs(date)
.add(minsGap, 'minute')
.add(hoursGap, 'hour')
.add(daysGap, 'day')
.toDate();
}
if (next) {
date = dayjs(date)
.add(minsGap, 'minute')
.add(hoursGap, 'hour')
.add(daysGap, 'day')
.toDate();
}

return date;
return date;
}

function getRandomInteger(a = 0, b = 1) {
const lower = Math.ceil(Math.min(a,b));
const upper = Math.floor(Math.max(a,b));
const lower = Math.ceil(Math.min(a, b));
const upper = Math.floor(Math.max(a, b));

return Math.floor(lower + Math.random() * (upper - lower + 1));
return Math.floor(lower + Math.random() * (upper - lower + 1));
}

function getRandomValue(items) {
return items[getRandomInteger(0, items.length - 1)];
return items[getRandomInteger(0, items.length - 1)];
}

function formatStringToDateTime(date) {

Check failure on line 53 in src/utils.js

View workflow job for this annotation

GitHub Actions / Check

'date' is already declared in the upper scope on line 24 column 5
return dayjs(date).format('DD/MM/YY HH:mm');
return dayjs(date).format('DD/MM/YY HH:mm');
}

function formatStringToShortDate(date) {

Check failure on line 57 in src/utils.js

View workflow job for this annotation

GitHub Actions / Check

'date' is already declared in the upper scope on line 24 column 5
return dayjs(date).format('MMM DD');
return dayjs(date).format('MMM DD');
}

function formatStringToTime(date) {

Check failure on line 61 in src/utils.js

View workflow job for this annotation

GitHub Actions / Check

'date' is already declared in the upper scope on line 24 column 5
return dayjs(date).format('HH:mm');
return dayjs(date).format('HH:mm');
}

function getPointDuration(dateFrom, dateTo) {
const timeDiff = dayjs(dateTo).diff(dayjs(dateFrom));

let pointDuration = 0;

switch (true) {
case (timeDiff >= MSEC_IN_DAY):
pointDuration = dayjs.duration(timeDiff).format('DD[D] HH[H] mm[M]');
break;
case (timeDiff >= MSEC_IN_HOUR):
pointDuration = dayjs.duration(timeDiff).format('HH[H] mm[M]');
break;
case (timeDiff < MSEC_IN_HOUR):
pointDuration = dayjs.duration(timeDiff).format('mm[M]');
break;
}

return pointDuration;
const timeDiff = dayjs(dateTo).diff(dayjs(dateFrom));

let pointDuration = 0;

switch (true) {
case (timeDiff >= MSEC_IN_DAY):
pointDuration = dayjs.duration(timeDiff).format('DD[D] HH[H] mm[M]');
break;
case (timeDiff >= MSEC_IN_HOUR):
pointDuration = dayjs.duration(timeDiff).format('HH[H] mm[M]');
break;
case (timeDiff < MSEC_IN_HOUR):
pointDuration = dayjs.duration(timeDiff).format('mm[M]');
break;
}

return pointDuration;
}

export {
getDate,
getRandomInteger,
getRandomValue,
formatStringToDateTime,
formatStringToShortDate,
formatStringToTime,
getPointDuration
getDate,
getRandomInteger,
getRandomValue,
formatStringToDateTime,
formatStringToShortDate,
formatStringToTime,
getPointDuration
}

Check failure on line 93 in src/utils.js

View workflow job for this annotation

GitHub Actions / Check

Missing semicolon
Loading

0 comments on commit 05f9a66

Please sign in to comment.