Skip to content

Commit

Permalink
Merge pull request #15 from ssftvyn/module8-task3
Browse files Browse the repository at this point in the history
  • Loading branch information
keksobot authored May 19, 2024
2 parents 797f0ac + fa55939 commit 1a90dba
Show file tree
Hide file tree
Showing 24 changed files with 329 additions and 366 deletions.
12 changes: 7 additions & 5 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

<title>Big Trip</title>

<link rel="icon" href="./img/favicon.ico" type="image/x-icon">

<link rel="stylesheet" href="./css/style.css">
<link rel="icon" href="./img/favicon.ico" type="image/x-icon">
</head>

<body class="page-body">
Expand All @@ -18,13 +17,16 @@

<div class="trip-main">
<div class="trip-main__trip-controls trip-controls">
<div class="trip-controls__navigation">
<h2 class="visually-hidden">Switch trip view</h2>
<!-- Меню -->
</div>

<div class="trip-controls__filters">
<h2 class="visually-hidden">Filter events</h2>
<!-- Фильтры -->
</div>
</div>


</div>
</div>
</header>
Expand All @@ -40,4 +42,4 @@ <h2 class="visually-hidden">Trip events</h2>
</div>
</main>
</body>
</html>
</html>
12 changes: 0 additions & 12 deletions src/api-service/destinations-api.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import ApiService from '../framework/api-service.js';
import {ApiServiceMethod} from '../const';

export default class DestinationsApiService extends ApiService{
get destinations() {
return this._load({url: 'destinations'})
.then(ApiService.parseResponse);
}

async updateDestinations(destination) {
const response = await this._load({
url: `destinations/${destination.id}`,
method: ApiServiceMethod.PUT,
body: JSON.stringify(destination),
headers: new Headers({'Content-Type': 'application/json'}),
});
const parsedResponse = await ApiService.parseResponse(response);
return parsedResponse;
}
}
12 changes: 0 additions & 12 deletions src/api-service/offers-api.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import ApiService from '../framework/api-service.js';
import {ApiServiceMethod} from '../const';

export default class OffersApiService extends ApiService{
get offers() {
return this._load({url: 'offers'})
.then(ApiService.parseResponse);
}

async updateOffers(offer) {
const response = await this._load({
url: `offers/${offer.type}`,
method: ApiServiceMethod.PUT,
body: JSON.stringify(offer),
headers: new Headers({'Content-Type': 'application/json'}),
});
const parsedResponse = await ApiService.parseResponse(response);
return parsedResponse;
}
}
125 changes: 87 additions & 38 deletions src/const.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,97 @@
// export const TYPES = ['taxi', 'bus', 'train', 'ship', 'drive', 'flight', 'check-in', 'sightseeing', 'restaurant'];

// export const OFFERS = [
// 'Add luggage',
// 'Switch to comfort class',
// 'Add meal',
// 'Choose seats',
// 'Add a child safety seat'
// ];

// export const CITIES = ['Magnolia', 'Greed Island', 'Soul Society', 'Amestris', 'Death City', 'Karakura', 'Z-City', 'Alubarna', 'Aincrad'];

// export const DESCRIPTIONS = [
// 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
// 'Maecenas dapibus sed enim in ultrices.',
// 'Praesent non ex turpis.',
// 'Nunc mollis sed tortor a faucibus.',
// 'Morbi ac convallis erat, vel volutpat nisl.',
// 'Phasellus a interdum lacus. Aenean consectetur magna vel diam fringilla, at commodo sem placerat.',
// 'Etiam a pellentesque massa.',
// 'Sed sed nisi sed augue convallis suscipit in sed felis.',
// 'Aliquam erat volutpat.'
// ];

// export const Duration = {
// MIN: 60,
// HOUR: 10,
// DAY: 3
// };

// export const DateFormat = {
// LONG: 'YYYY-MM-DDTHH:mm',
// SHORT: 'MMM DD'
// };

// export const Price = {
// MIN: 0,
// MAX: 1000
// };

// export const MILLISECONDS_IN_DAY = 86400000;

// export const MILLISECONDS_IN_HOUR = 3600000;

// export const Mode = {
// DEFAULT: 'DEFAULT',
// EDITING: 'EDITING'
// };

// export const UserAction = {
// UPDATE_POINT: 'UPDATE_POINT',
// ADD_POINT: 'ADD_POINT',
// DELETE_POINT: 'DELETE_POINT'
// };

// export const UpdateType = {
// PATCH: 'PATCH',
// MAJOR: 'MAJOR',
// INIT: 'INIT'
// };

// export const POINT_COUNT_PER_STEP = 7;

// export const ApiServiceMethod = {
// GET: 'GET',
// PUT: 'PUT',
// POST: 'POST',
// DELETE: 'DELETE'
// };

// export const TimeLimit = {
// LOWER_LIMIT: 350,
// UPPER_LIMIT: 1000,
// };
export const TYPES = ['taxi', 'bus', 'train', 'ship', 'drive', 'flight', 'check-in', 'sightseeing', 'restaurant'];

export const OFFERS = [
'Add luggage',
'Switch to comfort class',
'Add meal',
'Choose seats',
'Add a child safety seat'
];

export const CITIES = ['Magnolia', 'Greed Island', 'Soul Society', 'Amestris', 'Death City', 'Karakura', 'Z-City', 'Alubarna', 'Aincrad'];

export const DESCRIPTIONS = [
'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'Maecenas dapibus sed enim in ultrices.',
'Praesent non ex turpis.',
'Nunc mollis sed tortor a faucibus.',
'Morbi ac convallis erat, vel volutpat nisl.',
'Phasellus a interdum lacus. Aenean consectetur magna vel diam fringilla, at commodo sem placerat.',
'Etiam a pellentesque massa.',
'Sed sed nisi sed augue convallis suscipit in sed felis.',
'Aliquam erat volutpat.'
];

export const Duration = {
MIN: 60,
HOUR: 10,
DAY: 3
export const FilterType = {
EVERYTHING: 'everything',
FUTURE: 'future',
PAST: 'past'
};

export const DateFormat = {
LONG: 'YYYY-MM-DDTHH:mm',
SHORT: 'MMM DD'
export const SortType = {
DEFAULT: 'day',
TIME: 'time',
PRICE: 'price'
};

export const Price = {
MIN: 0,
MAX: 1000
export const NoPointsTextType = {
[FilterType.EVERYTHING]: 'Click New Event to create your first point',
[FilterType.PAST]: 'There are no past events now',
[FilterType.FUTURE]: 'There are no future events now'
};

export const MILLISECONDS_IN_DAY = 86400000;

export const MILLISECONDS_IN_HOUR = 3600000;

export const Mode = {
DEFAULT: 'DEFAULT',
EDITING: 'EDITING'
Expand All @@ -55,12 +105,11 @@ export const UserAction = {

export const UpdateType = {
PATCH: 'PATCH',
MINOR: 'MINOR',
MAJOR: 'MAJOR',
INIT: 'INIT'
};

export const POINT_COUNT_PER_STEP = 7;

export const ApiServiceMethod = {
GET: 'GET',
PUT: 'PUT',
Expand Down
21 changes: 9 additions & 12 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import TripPresenter from './presenter/trip-presenter';
import PointModel from './model/point-model';
import HeaderPresenter from './presenter/header-presenter';
import DestinationsModel from './model/destinations-model';
import OffersModel from './model/offers-model';
import DestinationModel from './model/destinations-model';
import OfferModel from './model/offers-model';
import FilterModel from './model/filter-model';
import FilterPresenter from './presenter/filter-presenter';
import NewPointButtonView from './view/new-point-button-view';
Expand All @@ -11,18 +10,18 @@ import PointsApiService from './api-service/points-api';
import DestinationsApiService from './api-service/destinations-api';
import OffersApiService from './api-service/offers-api';

const AUTHORIZATION = 'Basic gq0Af3hqaR';
const AUTHORIZATION = 'Basic RsgQy3KcnM';
const END_POINT = 'https://21.objects.htmlacademy.pro/big-trip';

const tripContainer = document.querySelector('.trip-events');
const headerContainer = document.querySelector('.trip-main');
const pointsModel = new PointModel({
pointsApiService: new PointsApiService(END_POINT, AUTHORIZATION)
});
const destinationsModel = new DestinationsModel({
const destinationsModel = new DestinationModel({
destinationsApiService: new DestinationsApiService(END_POINT, AUTHORIZATION)
});
const offersModel = new OffersModel({
const offersModel = new OfferModel({
offersApiService: new OffersApiService(END_POINT, AUTHORIZATION)
});
const filtersModel = new FilterModel();
Expand All @@ -32,7 +31,7 @@ const tripPresenter = new TripPresenter({
destinationsModel: destinationsModel,
offersModel: offersModel,
filtersModel: filtersModel,
onNewPointDestroy: handleNewPointClose
onNewPointDestroy: newPointCloseHandler
});
const filterPresenter = new FilterPresenter({
filterContainer: headerContainer.querySelector('.trip-controls__filters'),
Expand All @@ -41,20 +40,18 @@ const filterPresenter = new FilterPresenter({
});

const newPointButtonComponent = new NewPointButtonView({
onClick: handleNewPointButtonClick
onClick: NewPointButtonClickHandler
});

function handleNewPointClose() {
function newPointCloseHandler() {
newPointButtonComponent.element.disabled = false;
}

function handleNewPointButtonClick() {
function NewPointButtonClickHandler() {
tripPresenter.createPoint();
newPointButtonComponent.element.disabled = true;
}

const headerPresenter = new HeaderPresenter(headerContainer, pointsModel.points, destinationsModel.destinations);
headerPresenter.init();
filterPresenter.init();
tripPresenter.init();
offersModel.init().finally(() => {
Expand Down
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 {UpdateType} from '../const';
import Observable from '../framework/observable';
import {UpdateType} from '../const';

export default class DestinationsModel extends Observable{
export default class DestinationModel extends Observable{
#destinationsApiService = null;
#destinations = [];
constructor({destinationsApiService}) {
Expand Down
5 changes: 3 additions & 2 deletions src/model/filter-model.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Observable from '../framework/observable.js';
import {FILTERTYPE} from '../utils/filter';
import {FilterType} from '../const';


export default class FilterModel extends Observable{
#filter = FILTERTYPE.EVERYTHING;
#filter = FilterType.EVERYTHING;

get filter() {
return this.#filter;
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 {UpdateType} from '../const';
import Observable from '../framework/observable';
import {UpdateType} from '../const';

export default class OffersModel extends Observable{
export default class OfferModel extends Observable{
#offersApiService = null;
#offers = [];
constructor({offersApiService}) {
Expand Down
2 changes: 1 addition & 1 deletion src/model/point-model.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {UpdateType} from '../const';
import Observable from '../framework/observable';
import {UpdateType} from '../const';

export default class PointModel extends Observable{
#pointsApiService = null;
Expand Down
Loading

0 comments on commit 1a90dba

Please sign in to comment.