Lab 3
This commit is contained in:
parent
5650c55a67
commit
fab58b2e30
3 proba
@ -4,12 +4,35 @@ header nav {
|
||||
font-family: Santa Catarina;
|
||||
}
|
||||
|
||||
.book {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
flex: 0 0 calc(25% - 30px);
|
||||
}
|
||||
|
||||
.book img {
|
||||
max-width: 60%;
|
||||
max-height: 340px;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.book h3 {
|
||||
color: black;
|
||||
text-align: center;
|
||||
font-size: 30px;
|
||||
font-style: normal;
|
||||
font-weight: 300;
|
||||
line-height: normal;
|
||||
margin-bottom: 10px;
|
||||
height: 100px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
header nav {
|
||||
font-family: 'Santa Catarina', Arial, sans-serif;
|
||||
height: 64px;
|
||||
}
|
||||
|
||||
}
|
||||
body {
|
||||
overflow-x: hidden;
|
||||
@ -35,7 +58,7 @@ footer {
|
||||
color: white;
|
||||
text-align: center;
|
||||
padding: 10px 0;
|
||||
|
||||
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
@ -4,133 +4,113 @@
|
||||
const serverUrl = "http://localhost:8081";
|
||||
|
||||
// функция возвращает объект нужной структуры для отправки на сервер
|
||||
function createLineObject(item, author, name, desc, count, date, image) {
|
||||
return {
|
||||
itemsId: item,
|
||||
authorsId: author,
|
||||
name,
|
||||
desc,
|
||||
count,
|
||||
date,
|
||||
image,
|
||||
};
|
||||
// eslint-disable-next-line max-len
|
||||
function createLineObject(_name, _authorsType, _genresType, _year, _description, _count, _date, _image) {
|
||||
return {
|
||||
nameBook: _name,
|
||||
authorsId: _authorsType,
|
||||
genresId: _genresType,
|
||||
year: _year,
|
||||
description: _description,
|
||||
count: _count,
|
||||
date: _date,
|
||||
image: _image,
|
||||
};
|
||||
}
|
||||
|
||||
// обращение к серверу для получения всех типов товара (get)
|
||||
export async function getAllItemTypes() {
|
||||
const response = await fetch(`${serverUrl}/items`);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
return response.json();
|
||||
/// обращение к серверу для получения всех типов товара (get)
|
||||
export async function getAllAuthorTypes() {
|
||||
const response = await fetch(`${serverUrl}/authors`);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// обращение к серверу для получения всех типов товара (get)
|
||||
export async function getAllItemAuthors() {
|
||||
const response = await fetch(`${serverUrl}/authors`);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
return response.json();
|
||||
export async function getAllGengeTypes() {
|
||||
const response = await fetch(`${serverUrl}/genres`);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// обращение к серверу для получения всех записей (get)
|
||||
export async function getAllLines() {
|
||||
const response = await fetch(`${serverUrl}/lines?_expand=items&_expand=authors`);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
return response.json();
|
||||
const response = await fetch(`${serverUrl}/lines?_expand=authors&_expand=genres`);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// обращение к серверу для получения записи по первичному ключу (id) (get)
|
||||
// id передается в качестве части пути URL get-запроса
|
||||
export async function getLine(id) {
|
||||
const response = await fetch(`${serverUrl}/lines/${id}?_expand=items&_expand=authors`);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
return response.json();
|
||||
const response = await fetch(`${serverUrl}/lines/${id}?_expand=genres&_expand=authors`);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// обращение к серверу для создания записи (post)
|
||||
// объект отправляется в теле запроса (body)
|
||||
export async function createLine(item, author, name, desc, count, date, image) {
|
||||
const itemObject = createLineObject(
|
||||
item,
|
||||
author,
|
||||
name,
|
||||
desc,
|
||||
count,
|
||||
date,
|
||||
image,
|
||||
);
|
||||
// eslint-disable-next-line max-len
|
||||
export async function createLine(_name, _authorsType, _genresType, _year, _description, _count, _date, _image) {
|
||||
// eslint-disable-next-line max-len
|
||||
const itemObject = createLineObject(_name, _authorsType, _genresType, _year, _description, _count, _date, _image);
|
||||
|
||||
const options = {
|
||||
method: "POST",
|
||||
body: JSON.stringify(itemObject),
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
const options = {
|
||||
method: "POST",
|
||||
body: JSON.stringify(itemObject),
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
|
||||
const response = await fetch(`${serverUrl}/lines`, options);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
return response.json();
|
||||
const response = await fetch(`${serverUrl}/lines`, options);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// обращение к серверу для обновления записи по id (put)
|
||||
// объект отправляется в теле запроса (body)
|
||||
// id передается в качестве части пути URL get-запроса
|
||||
export async function updateLine(
|
||||
id,
|
||||
item,
|
||||
author,
|
||||
name,
|
||||
desc,
|
||||
count,
|
||||
date,
|
||||
image,
|
||||
) {
|
||||
const itemObject = createLineObject(
|
||||
item,
|
||||
author,
|
||||
name,
|
||||
desc,
|
||||
count,
|
||||
date,
|
||||
image,
|
||||
);
|
||||
// eslint-disable-next-line max-len
|
||||
export async function updateLine(id, _name, _authorsType, _genresType, _year, _description, _count, _date, _image) {
|
||||
// eslint-disable-next-line max-len
|
||||
const itemObject = createLineObject(_name, _authorsType, _genresType, _year, _description, _count, _date, _image);
|
||||
|
||||
const options = {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(itemObject),
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
const options = {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(itemObject),
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
|
||||
const response = await fetch(`${serverUrl}/lines/${id}`, options);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
return response.json();
|
||||
const response = await fetch(`${serverUrl}/lines/${id}`, options);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// обращение к серверу для удаления записи по id (delete)
|
||||
// id передается в качестве части пути URL get-запроса
|
||||
export async function deleteLine(id) {
|
||||
const options = {
|
||||
method: "DELETE",
|
||||
};
|
||||
const options = {
|
||||
method: "DELETE",
|
||||
};
|
||||
|
||||
const response = await fetch(`${serverUrl}/lines/${id}`, options);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
return response.json();
|
||||
const response = await fetch(`${serverUrl}/lines/${id}`, options);
|
||||
if (!response.ok) {
|
||||
throw response.statusText;
|
||||
}
|
||||
await response.json();
|
||||
location.reload();
|
||||
}
|
||||
|
@ -4,14 +4,16 @@
|
||||
// при обращении к атрибуту объекта вызывается
|
||||
// нужная функция для поиска элемента
|
||||
export const cntrls = {
|
||||
container: document.getElementById("my-id-for-text"),
|
||||
button: document.getElementById("items-add"),
|
||||
table: document.querySelector("#items-table tbody"),
|
||||
form: document.getElementById("items-form"),
|
||||
lineId: document.getElementById("items-line-id"),
|
||||
itemsType: document.getElementById("item"),
|
||||
author: document.getElementById("author"),
|
||||
name: document.getElementById("name"),
|
||||
desc: document.getElementById("desc"),
|
||||
genresType: document.getElementById("genre"),
|
||||
nameBook: document.getElementById("nameBook"),
|
||||
authorsType: document.getElementById("author"),
|
||||
year: document.getElementById("yearPicker"),
|
||||
description: document.getElementById("description"),
|
||||
count: document.getElementById("count"),
|
||||
date: document.getElementById("date"),
|
||||
image: document.getElementById("image"),
|
||||
@ -23,7 +25,15 @@ export const imagePlaceholder = "https://via.placeholder.com/200";
|
||||
|
||||
// функция создает тег option для select
|
||||
// <option value="" selected>name</option>
|
||||
export function createItemsOption(name, value = "", isSelected = false) {
|
||||
export function createGenresOption(name, value = "", isSelected = false) {
|
||||
const option = document.createElement("option");
|
||||
option.value = value || "";
|
||||
option.selected = isSelected;
|
||||
option.text = name;
|
||||
return option;
|
||||
}
|
||||
|
||||
export function createAuthorsOption(name, value = "", isSelected = false) {
|
||||
const option = document.createElement("option");
|
||||
option.value = value || "";
|
||||
option.selected = isSelected;
|
||||
@ -44,10 +54,10 @@ function createTableAnchor(icon, callback) {
|
||||
a.href = "#";
|
||||
a.appendChild(i);
|
||||
a.onclick = (event) => {
|
||||
// чтобы в URL не добавлялась решетка
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
callback();
|
||||
// чтобы в URL не добавлялась решетка
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
callback();
|
||||
};
|
||||
|
||||
const td = document.createElement("td");
|
||||
@ -74,13 +84,7 @@ function createTableColumn(value) {
|
||||
// <td><a href="#" onclick="editPageCallback()"><i class="fa-solid fa-pen-to-square"></i></a></td>
|
||||
// <td><a href="#" onclick="deleteCallback()"><i class="fa-solid fa-trash"></i></a></td>
|
||||
// </tr>
|
||||
export function createTableRow(
|
||||
item,
|
||||
index,
|
||||
editCallback,
|
||||
editPageCallback,
|
||||
deleteCallback,
|
||||
) {
|
||||
export function createTableRow(item, index, editCallback, deleteCallback) {
|
||||
const rowNumber = document.createElement("th");
|
||||
rowNumber.scope = "row";
|
||||
rowNumber.textContent = index + 1;
|
||||
@ -89,17 +93,47 @@ export function createTableRow(
|
||||
row.id = `line-${item.id}`;
|
||||
|
||||
row.appendChild(rowNumber);
|
||||
row.appendChild(createTableColumn(item.items.name));
|
||||
row.appendChild(createTableColumn(item.nameBook));
|
||||
row.appendChild(createTableColumn(item.authors.name));
|
||||
row.appendChild(createTableColumn(item.name));
|
||||
row.appendChild(createTableColumn(item.desc));
|
||||
row.appendChild(createTableColumn(item.genres.name));
|
||||
row.appendChild(createTableColumn(item.year));
|
||||
row.appendChild(createTableColumn(item.description));
|
||||
row.appendChild(createTableColumn(item.count));
|
||||
row.appendChild(createTableColumn(item.date));
|
||||
|
||||
// редактировать в модальном окне
|
||||
row.appendChild(createTableAnchor("fa-pencil", editCallback));
|
||||
// редактировать на странице page-edit
|
||||
row.appendChild(createTableAnchor("fa-pen-to-square", editPageCallback));
|
||||
// удаление
|
||||
row.appendChild(createTableAnchor("fa-trash", deleteCallback));
|
||||
return row;
|
||||
}
|
||||
|
||||
export function createTableRowOnIndex(item) {
|
||||
console.log(item);
|
||||
|
||||
const bookCard = createBookCard(item);
|
||||
return bookCard;
|
||||
}
|
||||
|
||||
function createBookCard(item) {
|
||||
const card = document.createElement("div");
|
||||
card.classList.add("book");
|
||||
|
||||
const image = document.createElement("img");
|
||||
image.src = item.image ? item.image : imagePlaceholder;
|
||||
image.alt = "Обложка книги";
|
||||
|
||||
const title = document.createElement("h3");
|
||||
title.textContent = `${item.nameBook}, ${item.authors.name}`;
|
||||
|
||||
card.appendChild(image);
|
||||
card.appendChild(title);
|
||||
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("col-12");
|
||||
div.classList.add("col-md-4");
|
||||
div.classList.add("col-lg-4");
|
||||
div.classList.add("col-xl-3");
|
||||
div.appendChild(card);
|
||||
return div;
|
||||
}
|
||||
|
@ -34,29 +34,34 @@
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<article class="container py-5">
|
||||
<h2 class="col-md-3 mb-4 text-center mx-auto">Бестселлеры</h2>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-3 mb-4 text-center">
|
||||
<img src="images/kafka.jpg" alt="" class="img-fluid" style="max-width: 260px; max-height: 372px;">
|
||||
<h3 class="h7 mt-3">Ф.Кафка “Превращение”</h3>
|
||||
<main class="container main_pannel">
|
||||
<div id="my-id-for-text" class="row">
|
||||
</div>
|
||||
<div class="col-md-3 mb-4 text-center">
|
||||
<img src="images/pandp.jpg" alt="" class="img-fluid" style="max-width: 260px; max-height: 372px;">
|
||||
<h3 class="h7 mt-3">Д.Остен “Гордость и предубеждение”</h3>
|
||||
</div>
|
||||
<div class="col-md-3 mb-4 text-center">
|
||||
<img src="images/leot.jpg" alt="" class="img-fluid" style="max-width: 260px; max-height: 372px;">
|
||||
<h3 class="h7 mt-3">Л.Толстой “Смерть Ивана Ильича”</h3>
|
||||
</div>
|
||||
<div class="col-md-3 mb-4 text-center">
|
||||
<img src="images/stranger.jpg" alt="" class="img-fluid" style="max-width: 260px; max-height: 372px;">
|
||||
<h3 class="h7 mt-3">А.Камю “Посторонний”</h3>
|
||||
</main>
|
||||
|
||||
<div class="modal" id="my-modal">
|
||||
<div class="modal-box">
|
||||
<button id="close-modal-btn" class="modal-close">
|
||||
<svg width="24" height="24" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M4.11 2.697L2.698 4.11 6.586 8l-3.89 3.89 1.415 1.413L8 9.414l3.89 3.89 1.413-1.415L9.414 8l3.89-3.89-1.415-1.413L8 6.586l-3.89-3.89z" fill="#000"></path>
|
||||
</svg>
|
||||
<ul>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
<footer class="footer mt-auto d-flex flex-shrink-0 justify-content-center align-items-center fixed-bottom">
|
||||
|
||||
<footer class="footer mt-auto d-flex flex-shrink-0 justify-content-center align-items-center">
|
||||
Жирнова Алена ПИбд-21
|
||||
</footer>
|
||||
<script type="module">
|
||||
import validation from "./scripts/validation";
|
||||
import { linesForm } from "./scripts/lines";
|
||||
import {linesFormOnIndex} from "./scripts/lines";
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
validation();
|
||||
linesFormOnIndex();
|
||||
//linesForm();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user