Skip to content

Commit

Permalink
Merge pull request #11 from frontend-park-mail-ru/e8branch
Browse files Browse the repository at this point in the history
МР для РК2
  • Loading branch information
AlexandraSmirnova authored Nov 20, 2024
2 parents c62ef9b + dcc8441 commit c14459a
Show file tree
Hide file tree
Showing 40 changed files with 2,030 additions and 441 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/node_modules
/node_modules
/public/components/*/*.precompiled.js
/public/config.js
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Frontend проекта "KudaGo" Команда 7
* [Backend](https://github.com/go-park-mail-ru/2024_2_Team7)

# Проект
* http://37.139.40.252/
* [vyhodnoy.ru](http://37.139.40.252/)

# figma
* https://www.figma.com/design/B9I0SPwTjYkMcqq6MwO2jW/kudaGo?node-id=0-1&t=DndAvQ4zTz4isemp-1
Expand Down
8 changes: 7 additions & 1 deletion dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ RUN npm install handlebars
# Копируем остальные файлы приложения
COPY . .

# Запускаем команду Handlebars
RUN node ./node_modules/handlebars/bin/handlebars public/components/EditEventForm/EditEventForm.hbs -f public/components/EditEventForm/EditEventForm.precompiled.js || echo "Handlebars command failed"
RUN node ./node_modules/handlebars/bin/handlebars public/components/EventCreateForm/EventCreateForm.hbs -f public/components/EventCreateForm/EventCreateForm.precompiled.js || echo "Handlebars command failed"
RUN node ./node_modules/handlebars/bin/handlebars public/components/Login/Login.hbs -f public/components/Login/Login.precompiled.js || echo "Handlebars command failed"
RUN node ./node_modules/handlebars/bin/handlebars public/components/Nav/Nav.hbs -f public/components/Nav/Nav.precompiled.js || echo "Handlebars command failed"
RUN node ./node_modules/handlebars/bin/handlebars public/components/Register/Register.hbs -f public/components/Register/Register.precompiled.js || echo "Handlebars command failed"

# Открываем порт 80
EXPOSE 80

# Команда для запуска приложения

CMD ["node", "server/server.js"]
31 changes: 15 additions & 16 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "npx eslint",
"prepare": "husky && husky install"
"prepare": "husky && husky install",
"compile:templates": "handlebars public/components/EventCreateForm/EventCreateForm.hbs -f public/components/EventCreateForm/EventCreateForm.precompiled.js"
},
"lint-staged": {
"*.{js, jsx}": [
Expand All @@ -32,7 +33,7 @@
"dependencies": {
"cors": "^2.8.5",
"dompurify": "^3.1.7",
"express": "^4.21.0",
"express": "^4.21.1",
"handlebars": "^4.7.8",
"minimist": "^1.2.8",
"node": "^22.9.0"
Expand Down
Empty file.
20 changes: 20 additions & 0 deletions public/components/CategorySelect/CategorySelect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
async function loadCategories() {
const selectElement = document.createElement('select');
try {
const request = { headers: {} };
const response = await api.get('/categories', request);
const categories = await response.json();

// Заполнение выпадающего списка
categories.forEach(category => {
const option = document.createElement('option');
option.value = category.id; // id категории
option.textContent = category.name; // название категории
selectElement.appendChild(option);
});

} catch (error) {
console.error('Ошибка при загрузке категорий:', error);
}
return categorySelect;
}
5 changes: 5 additions & 0 deletions public/components/EditEventForm/EditEventForm.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.edit_container {
display: flex;
align-items: center;
}

13 changes: 13 additions & 0 deletions public/components/EditEventForm/EditEventForm.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{#each items}}

{{#if this.needPlaceholder}}
<div style = ".edit_container">
<label>{{this.text}}</label>
<{{this.tag}} class="{{this.className}}" id = "{{this.key}}" placeholder = "{{this.text}}" type="{{this.type}}" data-section="{{this.key}}"></{{this.tag}}>
</div>

{{else}}
<{{this.tag}} class="{{this.className}}" id = "{{this.key}}" data-section="{{this.key}}">{{this.text}}</{{this.tag}}>
{{/if}}

{{/each}}
180 changes: 180 additions & 0 deletions public/components/EditEventForm/EditEventForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/**
* EditEventForm class
*/
import { api } from '../../modules/FrontendAPI.js';


export class EditEventForm {
constructor(formId) {
this.form = document.createElement('form');
this.form.id = formId;
this.form.className = 'event-edit-form';
}
async init(id) {
const path = `/events/${id}`;
const request = { headers: {} };
try {
const response = await api.get(path, request);
const event = await response.json();
this._renderEvent(event);
} catch (error) {
console.log(error);
console.log("Ошибка при загрузке события");
}
}
_renderEvent(event) {
const mapping = {
title: 'eventNameEntry',
image: 'imageInput',
description: 'eventDescriptionEntry',
category_id: 'categories',

};
const time = {
event_start: 'eventBeginEntry',
event_end: 'eventEndEntry',
};
for (const key in mapping) {
const inputElement = this.form.querySelector(`[id="${mapping[key]}"]`);
if (inputElement) {
if (mapping[key] === 'imageInput') {
inputElement.src = event[key];
} else {
inputElement.value = event[key];
}
}
}
for (const key in time) {
const inputElement = this.form.querySelector(`[id="${time[key]}"]`);
if (inputElement) {
inputElement.value = formatDateTimeForInput(event[key]);
}
}
}
config = {
eventServerError: {
text: '',
tag: 'label',
className: 'event-edit-form__error-text',
type: '',
},
eventAddLabel: {
text: 'Редактировать мероприятие',
tag: 'label',
className: 'event-edit-form__title',
type: '',
},
eventNameEntry: {
text: 'Название мероприятия',
tag: 'input',
type: 'text',
className: 'event-edit-form__input',
},
eventNameError: {
text: '',
tag: 'label',
className: 'event-edit-form__error-text',
type: '',
},
eventDescriptionEntry: {
text: 'Описание мероприятия',
tag: 'textarea',
type: '',
className: 'event-edit-form__textarea',
},
eventDescriptionError: {
text: '',
tag: 'label',
className: 'event-edit-form__error-text',
type: '',
},
eventTagEntry: {
text: 'Тэги (не более 3 штук)',
tag: 'input',
type: 'text',
className: 'event-edit-form__input',
},
eventTagsError: {
text: '',
tag: 'label',
className: 'event-edit-form__error-text',
type: '',
},
eventBeginEntry: {
text: 'Время начала мероприятия',
tag: 'input',
type: 'datetime-local',
className: 'event-edit-form__input event-edit-form__input--datetime-local',
},
eventBeginError: {
text: '',
tag: 'label',
className: 'event-edit-form__error-text',
type: '',
},
eventEndEntry: {
text: 'Время окончания мероприятия',
tag: 'input',
type: 'datetime-local',
className: 'event-edit-form__input event-edit-form__input--datetime-local',
},
eventEndError: {
text: '',
tag: 'label',
className: 'event-edit-form__error-text',
type: '',
},
imageInput: {
text: '',
tag: 'input',
className: 'event-edit-form__input event-edit-form__input--file',
type: 'file',
accept: "image/png, image/jpeg",
},
categories: {
text: '',
tag: 'div',
className: 'event-edit-form__categories-select',
type: '',
},
editSubmitBtn: {
text: 'Изменить',
tag: 'button',
type: 'submit',
className: 'event-edit-form__submit-btn',
},
};
/**
* Renders the form template
* @returns {HTMLFormElement} The rendered form
*/
renderTemplate(selectElement) {
const template = Handlebars.templates['EditEventForm.hbs'];
const config = this.config;
const itemsArray = Object.entries(config);
const items = itemsArray.map(([key, { tag, text, className, type }]) => ({
key,
tag,
text,
className,
type,
needPlaceholder: tag === 'input',
needMaxMinTime: type === 'time',
}));
this.form.innerHTML = template({ items });
const categoriesSelect = selectElement;
categoriesSelect.classList.add('event-edit-form__categories');
categoriesSelect.id = 'categoriesInput';
this.form.insertBefore(categoriesSelect, this.form.querySelector('.event-edit-form__submit-btn'));
return this.form;
}
}
function formatDateTimeForInput(dateTime) {
const date = new Date(dateTime);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${year}-${month}-${day}T${hours}:${minutes}`;
}
Loading

0 comments on commit c14459a

Please sign in to comment.