Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Меняй-удаляй #13

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
77cead8
Update package-lock.json
vvoyage Oct 10, 2024
1fd48c2
Update package.json
vvoyage Oct 10, 2024
ba185b2
Update index.html
vvoyage Oct 10, 2024
ef91e0a
Update const.js
vvoyage Oct 10, 2024
9bb04ec
Update api-service.js
vvoyage Oct 10, 2024
6cda3b4
Update ui-blocker.css
vvoyage Oct 10, 2024
b5eead0
Update abstract-view.js
vvoyage Oct 10, 2024
4193328
Update main.js
vvoyage Oct 10, 2024
606f43f
Update destinations-model.js
vvoyage Oct 10, 2024
1cd5b8d
Update offers-model.js
vvoyage Oct 10, 2024
fe7701c
Update points-model.js
vvoyage Oct 10, 2024
c3fef66
Create create-point-presenter.js
vvoyage Oct 10, 2024
c080436
Update filters-presenter.js
vvoyage Oct 10, 2024
c0a2349
Update point-presenter.js
vvoyage Oct 10, 2024
0b4e9cc
Update route-presenter.js
vvoyage Oct 10, 2024
795f436
Update trip-info-presenter.js
vvoyage Oct 10, 2024
f323a1b
Update utils.js
vvoyage Oct 10, 2024
ff6aefc
Create create-point-button-view.js
vvoyage Oct 10, 2024
edff307
Update point-editor-view.js
vvoyage Oct 10, 2024
c32dec2
Update point-view.js
vvoyage Oct 10, 2024
7f9e34b
Update sorting-view.js
vvoyage Oct 10, 2024
f8fe727
Update points-model.js
vvoyage Oct 10, 2024
571452d
Update create-point-presenter.js
vvoyage Oct 10, 2024
efe707b
Update route-presenter.js
vvoyage Oct 10, 2024
bda7509
Update utils.js
vvoyage Oct 10, 2024
c4e5b19
Update point-editor-view.js
vvoyage Oct 10, 2024
a2e32a4
Update points-model.js
vvoyage Oct 10, 2024
b4361d0
Update route-presenter.js
vvoyage Oct 10, 2024
929673e
Update point-editor-view.js
vvoyage Oct 10, 2024
45e02ff
Update route-presenter.js
vvoyage Oct 10, 2024
49b9f8a
Update points-model.js
vvoyage Oct 10, 2024
df2413d
Update create-point-presenter.js
vvoyage Oct 10, 2024
f43f92e
Update route-presenter.js
vvoyage Oct 10, 2024
c241856
Update utils.js
vvoyage Oct 10, 2024
7bc1282
Update point-editor-view.js
vvoyage Oct 10, 2024
3c54198
Create babel-config.json
vvoyage Oct 10, 2024
bc65c5c
Create trip-presenter.js
vvoyage Oct 10, 2024
a4594da
Create base-view.js
vvoyage Oct 10, 2024
09913ad
Create filter-view.js
vvoyage Oct 10, 2024
0f95103
Create trip-event-view.js
vvoyage Oct 10, 2024
1e86652
Create trip-events-form-view.js
vvoyage Oct 10, 2024
0ddbcd6
Create trip-events-list-view.js
vvoyage Oct 10, 2024
c87b394
Create trip-events-sorting-view.js
vvoyage Oct 10, 2024
88adf30
Create webpack-config.js
vvoyage Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions babel-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": "defaults"
}
]
]
}
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"not < 0.25%"
],
"dependencies": {
"dayjs": "1.11.9"
"dayjs": "1.11.9",
"flatpickr": "^4.6.13"
}
}
2 changes: 0 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ <h2 class="visually-hidden">Filter events</h2>
<!-- Фильтры -->
</div>
</div>

<button class="trip-main__event-add-btn btn btn--big btn--yellow" type="button">New event</button>
</div>
</div>
</header>
Expand Down
31 changes: 31 additions & 0 deletions src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,30 @@ const DESCRIPTIONS = [
'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odit ad eaque cupiditate praesentium maxime.',
];

const DEFAULT_EVENT_TYPE = 'flight';

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

const REQUIRED_POINT_FIELDS = ['dateFrom', 'dateTo', 'destination', 'type'];

const PointMode = {
IDLE: 'IDLE',
EDITABLE: 'EDITABLE',
};

const EditType = {
EDITING: 'EDITING',
CREATING: 'CREATING',
};

const FilterType = {
ANY: 'any',
FUTURE: 'future',
Expand Down Expand Up @@ -101,6 +120,7 @@ const DateFormat = {
SHORT: 'MMM DD',
FULL: 'YYYY-MM-DDTHH:mm',
WITH_DELIMITER: 'DD/MM/YY HH:mm',
WITH_DELIMITER_FLAT_PICKER: 'd/m/y H:i',
};

const DurationFormat = {
Expand All @@ -119,6 +139,13 @@ const MocksMaxCount = {
POINTS: 5,
};

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

export {
POINTS_COUNT,
EVENT_TYPES,
Expand All @@ -127,7 +154,10 @@ export {
CITIES,
DESCRIPTIONS,
SORTING_COLUMNS,
POINT_DUMMY,
REQUIRED_POINT_FIELDS,
PointMode,
EditType,
FilterType,
FilterSettings,
SortType,
Expand All @@ -137,4 +167,5 @@ export {
MocksMaxCount,
MSEC_IN_HOUR,
MSEC_IN_DAY,
UpdateType,
};
2 changes: 1 addition & 1 deletion src/framework/api-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class ApiService {
/**
* Метод для обработки ответа
* @param {Response} response Объект ответа
* @returns {Promise}
* @returns {Promise<JSON>}
*/
static parseResponse(response) {
return response.json();
Expand Down
6 changes: 3 additions & 3 deletions src/framework/ui-blocker/ui-blocker.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.ui-blocker {
display: none;
place-content: center;
position: fixed;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
min-width: 100%;
min-height: 100%;
z-index: 1000;
cursor: wait;
background-color: rgba(255, 255, 255, 0.5);
Expand Down
3 changes: 3 additions & 0 deletions src/framework/view/abstract-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export default class AbstractView {
/** @type {HTMLElement|null} Элемент представления */
#element = null;

/** @type {Object} Объект с колбэками. Может использоваться для хранения обработчиков событий */
_callback = {};

constructor() {
if (new.target === AbstractView) {
throw new Error('Can\'t instantiate AbstractView, only concrete one.');
Expand Down
21 changes: 17 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,37 @@ import RoutePresenter from './presenter/route-presenter.js';
import FiltersPresenter from './presenter/filters-presenter.js';
import TripInfoPresenter from './presenter/trip-info-presenter.js';
import MockService from './service/mock-service.js';
import CreatePointPresenter from './presenter/create-point-presenter.js';

const mockService = new MockService();
const pointsModel = new PointsModel(mockService);
const offersModel = new OffersModel(mockService);
const destinationsModel = new DestinationsModel(mockService);

const container = document.querySelector('.trip-events');
const pointsContainer = document.querySelector('.trip-events');
const filtersContainer = document.querySelector('.trip-controls__filters');
const tripMainContainer = document.querySelector('.trip-main');

const createPointPresenter = new CreatePointPresenter({
container: tripMainContainer,
editorContainer: pointsContainer,
pointsModel,
offersModel,
destinationsModel,
});

const routePresenter = new RoutePresenter({
container,
container: pointsContainer,
createPointBtnContainer: tripMainContainer,
pointsModel,
offersModel,
destinationsModel
});

const filtersPresenter = new FiltersPresenter({ pointsModel });
const tripInfoPresenter = new TripInfoPresenter();
const filtersPresenter = new FiltersPresenter({ container: filtersContainer, pointsModel });
const tripInfoPresenter = new TripInfoPresenter(tripMainContainer);

createPointPresenter.init();
routePresenter.init();
filtersPresenter.init();
tripInfoPresenter.init();
21 changes: 20 additions & 1 deletion src/model/destinations-model.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export default class DestinationsModel {
import Observable from '../framework/observable.js';
import { deleteItem, updateItem } from '../utils.js';

export default class DestinationsModel extends Observable {
#service = null;
#destinations = null;

constructor(service) {
super();
this.#service = service;
this.#destinations = this.#service.destinations;
}
Expand All @@ -14,4 +18,19 @@ export default class DestinationsModel {
getById(id) {
return this.#destinations.find((destination) => destination.id === id);
}

add(type, destination) {
this.#destinations.push(type, destination);
this._notify(destination);
}

update(type, destination) {
this.#destinations = updateItem(this.#destinations, destination);
this._notify(type, destination);
}

delete(type, destination) {
this.#destinations = deleteItem(this.#destinations, destination);
this._notify(type, destination);
}
}
21 changes: 20 additions & 1 deletion src/model/offers-model.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export default class OffersModel {
import Observable from '../framework/observable.js';
import { deleteItem, updateItem } from '../utils.js';

export default class OffersModel extends Observable {
#service = null;
#offers = null;

constructor(service) {
super();
this.#service = service;
this.#offers = this.#service.offers;
}
Expand All @@ -14,4 +18,19 @@ export default class OffersModel {
getByType(type) {
return this.#offers.find((offers) => offers.type === type.toLowerCase()).offers;
}

add(type, offer) {
this.#offers.push(offer);
this._notify(type, offer);
}

update(type, offer) {
this.#offers = updateItem(this.#offers, offer);
this._notify(type, offer);
}

delete(type, offer) {
this.#offers = deleteItem(this.#offers, offer);
this._notify(type, offer);
}
}
21 changes: 20 additions & 1 deletion src/model/points-model.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
export default class PointsModel {
import Observable from '../framework/observable.js';
import { deleteItem, updateItem } from '../utils.js';

export default class PointsModel extends Observable {
#service = null;
#points = null;

constructor(service) {
super();
this.#service = service;
this.#points = this.#service.points;
}

get() {
return this.#points;
}

add(type, point) {
this.#points.push(point);
this._notify(type, point);
}

update(type, point) {
this.#points = updateItem(this.#points, point);
this._notify(type, point);
}

delete(type, point) {
this.#points = deleteItem(this.#points, point);
this._notify(type, point);
}
}

77 changes: 77 additions & 0 deletions src/presenter/create-point-presenter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { EditType, POINT_DUMMY, UpdateType } from '../const.js';
import {
RenderPosition,
remove,
render,
} from '../framework/render.js';
import CreatePointButtonView from '../view/create-point-button-view.js';
import PointEditorView from '../view/point-editor-view.js';

export default class CreatePointPresenter {
#container = null;
#editorContainer = null;
#pointsModel = null;
#destinationsModel = null;
#offersModel = null;
#createPointButtonComponent = null;
#pointEditorComponent = null;

constructor({ container, editorContainer, pointsModel, destinationsModel, offersModel }) {
this.#container = container;
this.#editorContainer = editorContainer;
this.#pointsModel = pointsModel;
this.#destinationsModel = destinationsModel;
this.#offersModel = offersModel;
}

init() {
if (this.#createPointButtonComponent) {
throw new Error('Cannot init create point button twice');
}

this.#createPointButtonComponent = new CreatePointButtonView({ onClick: this.#createPointClickHandler });
render(this.#createPointButtonComponent, this.#container);
}

destroy() {
if (!this.#pointEditorComponent) {
return;
}

remove(this.#pointEditorComponent);
this.#pointEditorComponent = null;

document.removeEventListener('keydown', this.#escKeyDownHandler);
}

#createPointClickHandler = () => {
this.#pointEditorComponent = new PointEditorView({
point: POINT_DUMMY,
destinations: this.#destinationsModel.get(),
offers: this.#offersModel.get(),
onCloseClick: this.#cancelClickHandler,
onDeleteClick: this.#cancelClickHandler,
onSubmitForm: this.#formSubmitHandler,
mode: EditType.CREATING
});

render(this.#pointEditorComponent, this.#editorContainer, RenderPosition.AFTERBEGIN);
document.addEventListener('keydown', this.#escKeyDownHandler);
};

#cancelClickHandler = () => {
this.destroy();
};

#formSubmitHandler = (point) => {
this.#pointsModel.add(UpdateType.MAJOR, point);
this.destroy();
};

#escKeyDownHandler = (evt) => {
if (evt.key === 'Escape') {
evt.preventDefault();
this.destroy();
}
};
}
Loading