Skip to content

Commit

Permalink
Merge pull request #10 from bebriks/module6-task1
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored May 8, 2024
2 parents 68bf9e5 + a30fce1 commit bb94783
Show file tree
Hide file tree
Showing 14 changed files with 347 additions and 298 deletions.
24 changes: 18 additions & 6 deletions src/mock/const.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
const TRANSPORT_IMAGES = [
'bus',
'taxi',
'check-in',
'bus',
'train',
'ship',
'drive',
'flight',
'restaurant',
'ship',
'check-in',
'sightseeing',
'train',
'restaurant',
];

const TRANSPORT_OFFERS = [
{'taxi': [{title: 'taxi-offer-1', price: 10}, {title: 'taxi-offer-2', price: 20}, {title: 'taxi-offer-3', price: 30}]},
{'bus': [{title: 'bus-offer-1', price: 10}, {title: 'bus-offer-2', price: 20}, {title: 'bus-offer-3', price: 30}]},
{'train': [{title: 'train-offer-1', price: 10}, {title: 'train-offer-2', price: 20}, {title: 'train-offer-3', price: 30}]},
{'ship': [{title: 'ship-offer-1', price: 10}, {title: 'ship-offer-2', price: 20}, {title: 'ship-offer-3', price: 30}]},
{'drive': [{title: 'drive-offer-1', price: 10}, {title: 'drive-offer-2', price: 20}, {title: 'drive-offer-3', price: 30}]},
{'flight': [{title: 'flight-offer-1', price: 10}, {title: 'flight-offer-2', price: 20}, {title: 'flight-offer-3', price: 30}]},
{'check-in': [{title: 'check-in-offer-1', price: 10}, {title: 'check-in-offer-2', price: 20}, {title: 'check-in-offer-3', price: 30}]},
{'sightseeing': [{title: 'sightseeing-offer-1', price: 10}, {title: 'sightseeing-offer-2', price: 20}, {title: 'sightseeing-offer-3', price: 30}]},
{'restaurant': [{title: 'restaurant-offer-1', price: 10}, {title: 'restaurant-offer-2', price: 20}, {title: 'restaurant-offer-3', price: 30}]},
];

const CITIES = [
Expand Down Expand Up @@ -57,4 +69,4 @@ const SortType = {
};


export {TRANSPORT_IMAGES, CITIES, OFFERS, FilterType, EmptyFilter, SortType};
export {TRANSPORT_IMAGES, CITIES, OFFERS, FilterType, EmptyFilter, SortType, TRANSPORT_OFFERS};
51 changes: 0 additions & 51 deletions src/mock/destinations.js

This file was deleted.

51 changes: 0 additions & 51 deletions src/mock/offers.js

This file was deleted.

138 changes: 85 additions & 53 deletions src/mock/point.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,91 @@
import { getRandomArrayElement } from '../utils/common';

const mockPoints = [
{
id: 'f4b62099-293f-4c3d-a702-94eec4a2808c',
basePrice: 800,
dateFrom: '2019-07-13T22:55:00.845Z',
dateTo: '2019-07-13T23:46:00.375Z',
destination: 'cfe416cq-10xa-ye10-8077-2fs9a01edcab',
isFavorite: false,
offers: [
'b4c3e4e6-9053-42ce-b747-e281314baa31'
],
type: 'drive',
},
{
id: 'f5b62099-293f-4c3d-a702-94eec4a2808c',
basePrice: 1100,
dateFrom: '2019-07-19T22:55:56.845Z',
dateTo: '2019-07-20T12:22:13.375Z',
destination: 'cfe516cq-10xa-ye10-8077-2fs9a01edcab',
isFavorite: true,
offers: [
'b5c3e4e6-9053-42ce-b747-e281314baa31'
],
type: 'taxi'
},
{
id: 'f6b62099-293f-4c3d-a702-94eec4a2808c',
basePrice: 2100,
dateFrom: '2019-07-14T22:55:56.845Z',
dateTo: '2019-07-16T23:22:13.375Z',
destination: 'cfe616cq-10xa-ye10-8077-2fs9a01edcab',
isFavorite: false,
import { getRandomArrayElement, getRandomInt } from '../utils/common';
import { TRANSPORT_IMAGES, TRANSPORT_OFFERS, CITIES } from './const';
import { NOW } from '../utils/task';

const mockOffers = [];
const mockDests = [];
//`cfe${d}16cq-10xa-ye10-8077-2fs9a01edcab`
function getRandomPoint() {

const id = crypto.randomUUID();
const price = getRandomInt(20, 2000);
const isFavorite = getRandomInt(0, 2) === 1;
const type = getRandomArrayElement(TRANSPORT_IMAGES);
const dateFrom = NOW.toISOString();
const dateTo = NOW.set('day', getRandomInt(1, 10)).set('hour', getRandomInt(NOW.$H, 24)).toISOString();
//const d = getRandomInt(4,8);
const offersIds = [];
const destId = crypto.randomUUID();

for(let i = 0; i < getRandomInt(0,4); i++) {
offersIds.push(crypto.randomUUID());
}

const point = {
id: id,
basePrice: price,
dateFrom: dateFrom,
dateTo: dateTo,
destination: destId,
isFavorite: isFavorite,
offers: [
'b6c3e4e6-9053-42ce-b747-e281314baa31'
...offersIds,
],
type: 'bus'
},
{
id: 'f7b62099-293f-4c3d-a702-94eec4a2808c',
basePrice: 350,
dateFrom: '2019-07-18T22:55:56.845Z',
dateTo: '2019-07-23T23:22:13.375Z',
destination: 'cfe716cq-10xa-ye10-8077-2fs9a01edcab',
isFavorite: false,
type: type
};

getOffers(point);
getDests(point);

return point;
}

function getOffers(point) {
if(point === undefined) {
return;
}

const allOffers = [];
const offersArr = Object.values(TRANSPORT_OFFERS.find((x) => Object.keys(x)[0] === point.type));
for(let i = 0; i < point.offers.length; i++) {

const ofEl = offersArr[0][i];

const of = {
id: point.offers[i],
title: ofEl.title,
price: ofEl.price
};

allOffers.push(of);
}

const offer = {
type: point.type,
offers: [
'b7c3e4e6-9053-42ce-b747-e281314baa31'
],
type: 'check-in'
},
];
...allOffers,
]
};
mockOffers.push(offer);

function getRandomPoint() {
const randPoint = getRandomArrayElement(mockPoints);
return randPoint;
return mockOffers;
}

function getDests(point) {
const id = point.destination;
const city = getRandomArrayElement(CITIES);
const dest = {
id: id,
description: `${city}, is a beautiful city, a true asian pearl, with crowded streets.`,
name: `${city}`,
pictures: [
{
src: `https://loremflickr.com/300/200?random=${point.destination}`,
description: `${city} parliament building`,
}
]
};
mockDests.push(dest);
}

export {getRandomPoint};
export {getRandomPoint, mockOffers, mockDests};
4 changes: 2 additions & 2 deletions src/model/destinations-model.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getDestination } from '../mock/destinations';
import { mockDests } from '../mock/point';

export default class DestinationsModel {
#destinations = getDestination();
#destinations = mockDests;

get destinations(){
return this.#destinations;
Expand Down
4 changes: 2 additions & 2 deletions src/model/offers-model.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getOffer } from '../mock/offers';
import { mockOffers } from '../mock/point';

export default class OffersModel {
#offers = getOffer();
#offers = mockOffers;

get offers(){
return this.#offers;
Expand Down
2 changes: 2 additions & 0 deletions src/model/points-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export default class PointsModel {
#points = Array.from({length: POINTS_COUNT}, getRandomPoint).sort(sortPointsArrByDay);

get points() {
//console.log(this.#points)
return this.#points;
}
}
export {POINTS_COUNT};
14 changes: 6 additions & 8 deletions src/presenter/board-presenter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { render, RenderPosition } from '../framework/render';
import { updateItem } from '../utils/common';
import NewPointView from '../view/add-new-point';
import EditPointView from '../view/edit-point-view';
import EventListView from '../view/event-list-view';
import PointView from '../view/point-view';
Expand All @@ -19,7 +18,7 @@ export default class BoardPresenter {
#destinationsModel = null;
#sortComponent = null;
#eventListComponent = null;
#newPoint = null;
#newPointComponent = null;
#listEmpty = null;

#pointPresenter = new Map();
Expand All @@ -33,14 +32,14 @@ export default class BoardPresenter {
#sortedOffers = [];
#sortedDests = [];

constructor({container, headerContainer, eventListComponent, editPoint, newPoint, infoView, pointView, pointsModel, offersModel, destinationsModel, listEmpty}) {
constructor({container, headerContainer, eventListComponent, editPoint, infoView, pointView, pointsModel, offersModel, destinationsModel, listEmpty}) {
this.#container = container;
this.#headerContainer = headerContainer;
this.#pointsModel = pointsModel;
this.#offersModel = offersModel;
this.#destinationsModel = destinationsModel;
this.#eventListComponent = eventListComponent || new EventListView();
this.#newPoint = newPoint || (() => new NewPointView());
/* this.#newPoint = newPoint || (() => new NewPointView()); */
this.editPoint = editPoint || (() => new EditPointView());
this.pointView = pointView || (() => new PointView());
this.#listEmpty = listEmpty || (() => new ListEmpty());
Expand All @@ -51,9 +50,8 @@ export default class BoardPresenter {
this.#boardPoints = [...this.#pointsModel.points];
this.#boardOffers = [...this.#offersModel.offers];
this.#boardDestinations = [...this.#destinationsModel.destinations];

this.#sourcedBoardPoints = [...this.#pointsModel.points];

//console.log(this.#boardOffers)
this.#renderComponents();
}

Expand Down Expand Up @@ -131,7 +129,7 @@ export default class BoardPresenter {
}

#findOffer(point) {
return this.#boardOffers.find((x) => x.offers[0].id === point.offers[0]);
return this.#boardOffers.find((x) => x.id === point.offers[0]);
}

#findDest(point) {
Expand All @@ -140,8 +138,8 @@ export default class BoardPresenter {

#renderDynamicComponents() {
for (let i = 0; i < this.#boardPoints.length; i++) {
const offer = this.#findOffer(this.#boardPoints[i]);
const dest = this.#findDest(this.#boardPoints[i]);
const offer = this.#boardOffers[i];

this.#sortedOffers.push(offer);
this.#sortedDests.push(dest);
Expand Down
Loading

0 comments on commit bb94783

Please sign in to comment.