Лаб3
20
.eslintrc.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"es2021": true
|
||||||
|
},
|
||||||
|
"extends": "airbnb-base",
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 12,
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"quotes": "off",
|
||||||
|
"indent": "off",
|
||||||
|
"no-console": "off",
|
||||||
|
"no-use-before-define": "off",
|
||||||
|
"no-alert": "off",
|
||||||
|
"no-restricted-globals": "off",
|
||||||
|
"quote-props": "off"
|
||||||
|
}
|
||||||
|
}
|
3
.gitignore
vendored
@ -40,3 +40,6 @@ testem.log
|
|||||||
# System files
|
# System files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
||||||
|
# Ignore dist
|
||||||
|
dist/
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
<p class="lead text-muted">Выполнение CRUD-операций над фильмами или сериалами</p>
|
<p class="lead text-muted">Выполнение CRUD-операций над фильмами или сериалами</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button class="btn btn-primary" id="items-add">Добавить запись</button>
|
<button class="btn btn-primary" id="addMovieButton">Добавить запись</button>
|
||||||
|
|
||||||
<table id="items-table" class="table table-striped">
|
<table id="items-table" class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
@ -141,29 +141,60 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<img id="image-preview" src="https://via.placeholder.com/200" class="rounded rounded-circle"
|
<img id="image-preview" src="https://via.placeholder.com/200" class="image-preview"
|
||||||
alt="placeholder">
|
alt="placeholder">
|
||||||
</div>
|
</div>
|
||||||
<input id="items-line-id" type="number" hidden>
|
<input id="items-line-id" type="number" hidden>
|
||||||
|
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<label for="item" class="form-label">Товары</label>
|
<label for="item" class="form-label">Название</label>
|
||||||
<select id="item" class="form-select" name="selected" required>
|
<input id="title" name="title" class="form-control" type="text" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="type" class="form-label">Тип</label>
|
||||||
|
<select id="type" class="form-select" required>
|
||||||
|
<option value="Фильм" selected>Фильм</option>
|
||||||
|
<option value="Сериал">Сериал</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
<div class="form-check mb-3">
|
||||||
<label class="form-label" for="price">Цена</label>
|
<input type="checkbox" class="form-check-input" id="requiresSubscription">
|
||||||
<input id="price" name="price" class="form-control" type="number" value="0.00" min="1000.00"
|
<label for="requiresSubscription" class="form-check-label">Требуется подписка</label>
|
||||||
step="0.50" required>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<label class="form-label" for="count">Количество</label>
|
<label class="form-label" for="image">Постер</label>
|
||||||
<input id="count" name="count" class="form-control" type="number" value="0" min="1" step="1"
|
<input id="image" type="file" name="image" class="form-control" accept="image/*">
|
||||||
|
</div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<label class="form-label" for="description">Описание</label>
|
||||||
|
<textarea id="description" class="form-control" style="height: 140px"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<label class="form-label" for="releaseDate">Год производства</label>
|
||||||
|
<input id="releaseDate" name="releaseDate" class="form-control" type="number" min="1900" step="1"
|
||||||
required>
|
required>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<label class="form-label" for="image">Изображение</label>
|
<label for="country" class="form-label">Страна</label>
|
||||||
<input id="image" type="file" name="image" class="form-control" accept="image/*">
|
<input id="country" name="country" class="form-control" type="text" required>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<label for="tagline" class="form-label">Слоган</label>
|
||||||
|
<input id="tagline" name="tagline" class="form-control" type="text" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<label for="director" class="form-label">Режиссер</label>
|
||||||
|
<input id="director" name="director" class="form-control" type="text" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<label for="ageRating" class="form-label">Возрастное ограничение</label>
|
||||||
|
<input id="ageRating" name="ageRating" class="form-control" type="text" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<label for="video" class="form-label">URL видео</label>
|
||||||
|
<input id="video" name="video" class="form-control" type="text" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
||||||
@ -174,5 +205,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script type="module">
|
||||||
|
import validation from "./js/validation";
|
||||||
|
import { tableModal } from './js/admin_panel.js';
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
validation();
|
||||||
|
tableModal();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
BIN
assets/LoginBG.png
Normal file
After Width: | Height: | Size: 1.8 MiB |
BIN
assets/LoginBG_2.png
Normal file
After Width: | Height: | Size: 1.5 MiB |
3
assets/footer/Telegram.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg fill="#fff" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||||
|
<path fill-rule="evenodd" d="M12.59 16.594l-2.593 2.423s-.203.157-.425.059l.497-4.5.017.013.01-.092s7.272-6.697 7.57-6.982c.298-.285.198-.346.198-.346.02-.346-.536 0-.536 0l-9.636 6.27-4.013-1.384s-.616-.224-.676-.713c-.06-.488.696-.753.696-.753l15.953-6.412s1.312-.59 1.312.387L18.123 19.24s-.398 1.018-1.49.53l-4.043-3.176z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 436 B |
3
assets/footer/Twitter.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg fill="#fff" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||||
|
<path fill-rule="evenodd" d="M19.761 6.474a3.949 3.949 0 0 0 1.715-2.185 7.732 7.732 0 0 1-2.477.957A3.865 3.865 0 0 0 16.154 4c-2.15 0-3.897 1.77-3.897 3.95 0 .31.034.61.101.9-3.24-.166-6.111-1.736-8.036-4.13a3.986 3.986 0 0 0-.527 1.99c0 1.368.688 2.578 1.734 3.286a3.861 3.861 0 0 1-1.766-.492v.048c0 1.915 1.344 3.512 3.128 3.873a3.83 3.83 0 0 1-1.762.07c.497 1.569 1.936 2.71 3.643 2.741A7.754 7.754 0 0 1 3 17.873a10.945 10.945 0 0 0 5.975 1.774c7.17 0 11.091-6.018 11.091-11.238 0-.172-.003-.344-.01-.512A7.945 7.945 0 0 0 22 5.852c-.71.32-1.465.53-2.239.622z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 677 B |
3
assets/footer/VK.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg fill="#fff" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||||
|
<path fill-rule="evenodd" d="M22.463 6.823c.095-.447-.116-.698-.615-.698h-2.515c-.576 0-.787.233-.96.572 0 0-1.36 2.7-3.013 4.4-.532.55-.802.715-1.095.715-.236 0-.345-.183-.345-.68V6.788c0-.608-.077-.787-.615-.787H9.274c-.307 0-.5.166-.5.393 0 .573.941.702.941 2.254v3.2c0 .645-.038.895-.364.895-.864 0-2.918-2.772-4.07-5.92C5.051 6.18 4.801 6 4.148 6H1.634C1.269 6 1 6.232 1 6.572c0 .626.787 3.523 3.878 7.404C6.95 16.587 9.678 18 12.134 18c1.498 0 1.862-.232 1.862-.823v-2.003c0-.5.212-.715.519-.715.345 0 .955.103 2.38 1.413C18.585 17.374 18.7 18 19.621 18h2.822c.288 0 .557-.125.557-.572 0-.59-.826-1.646-2.093-2.897-.518-.644-1.363-1.342-1.631-1.664-.384-.375-.269-.59 0-.983 0 0 2.898-3.81 3.187-5.061z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 819 B |
3
assets/footer/YouTube.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg fill="#fff" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||||
|
<path fill-rule="evenodd" d="M21.654 6.413c-.244-1.145-1.114-1.989-2.162-2.115-2.48-.298-4.99-.3-7.489-.298-2.499-.001-5.01 0-7.49.298-1.046.126-1.916.97-2.16 2.115C2.002 8.043 2 9.822 2 11.5s0 3.457.348 5.087c.245 1.144 1.115 1.989 2.162 2.115 2.48.298 4.99.3 7.49.298 2.499.001 5.009 0 7.488-.298 1.047-.126 1.917-.97 2.162-2.115.349-1.63.35-3.409.35-5.087s.003-3.457-.346-5.087zM10 15V8l6 3.51L10 15z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 514 B |
BIN
assets/main-page/posters/BetterCallSaul.jpg
Normal file
After Width: | Height: | Size: 551 KiB |
@ -180,5 +180,13 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
<script type="module">
|
||||||
|
import renderMovies from './js/main_page.js';
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
renderMovies();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
145
js/admin_panel.js
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
import {
|
||||||
|
getMovies, createMovie, updateMovie, deleteMovie,
|
||||||
|
} from './rest_api';
|
||||||
|
|
||||||
|
import { hideUpdateModal, showUpdateModal } from './table_modal';
|
||||||
|
|
||||||
|
import {
|
||||||
|
controls, imagePlaceholder, addTableRow,
|
||||||
|
} from './admin_panel_ui';
|
||||||
|
|
||||||
|
export async function showAllMovieEntries() {
|
||||||
|
const tableBody = document.querySelector('tbody');
|
||||||
|
console.log(tableBody);
|
||||||
|
tableBody.innerHTML = '';
|
||||||
|
|
||||||
|
const movies = await getMovies();
|
||||||
|
movies.forEach((movie, index) => {
|
||||||
|
tableBody.appendChild(
|
||||||
|
addTableRow(
|
||||||
|
movie,
|
||||||
|
index,
|
||||||
|
() => showUpdateModal(movie),
|
||||||
|
() => removeMovieObject(movie.id),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addMovieObject(serializedMovieObject) {
|
||||||
|
const data = await createMovie(serializedMovieObject);
|
||||||
|
console.info("Added");
|
||||||
|
console.info(data);
|
||||||
|
|
||||||
|
showAllMovieEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function editMovieObject(id, serializedMovieObject) {
|
||||||
|
const data = await updateMovie(id, serializedMovieObject);
|
||||||
|
console.info("Updated");
|
||||||
|
console.info(data);
|
||||||
|
|
||||||
|
showAllMovieEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeMovieObject(id) {
|
||||||
|
if (!confirm("Do you really want to remove this item?")) {
|
||||||
|
console.info("Canceled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await deleteMovie(id);
|
||||||
|
console.info("Removed");
|
||||||
|
console.info(data);
|
||||||
|
|
||||||
|
showAllMovieEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function readFile(file) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
reader.onloadend = () => {
|
||||||
|
const fileContent = reader.result;
|
||||||
|
resolve(fileContent);
|
||||||
|
};
|
||||||
|
|
||||||
|
reader.onerror = () => {
|
||||||
|
reject(new Error("oops, something went wrong with the file reader."));
|
||||||
|
};
|
||||||
|
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateImagePreview() {
|
||||||
|
const file = controls.image.files[0];
|
||||||
|
const fileContent = await readFile(file);
|
||||||
|
|
||||||
|
controls.imagePreview.src = fileContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function tableModal() {
|
||||||
|
showAllMovieEntries();
|
||||||
|
|
||||||
|
controls.image.addEventListener("change", () => updateImagePreview());
|
||||||
|
controls.button.addEventListener("click", () => showUpdateModal(null));
|
||||||
|
|
||||||
|
controls.form.addEventListener("submit", async (event) => {
|
||||||
|
console.info("Form onSubmit");
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
if (!controls.form.checkValidity()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let imageBase64 = "";
|
||||||
|
|
||||||
|
if (controls.imagePreview.src !== imagePlaceholder) {
|
||||||
|
const result = await fetch(controls.imagePreview.src);
|
||||||
|
const blob = await result.blob();
|
||||||
|
|
||||||
|
imageBase64 = await readFile(blob);
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentId = controls.lineId.value;
|
||||||
|
if (!currentId) {
|
||||||
|
await addMovieObject(
|
||||||
|
{
|
||||||
|
title: controls.title.value,
|
||||||
|
type: controls.type.value,
|
||||||
|
requiresSubscription: controls.requiresSubscription.checked,
|
||||||
|
poster: imageBase64,
|
||||||
|
description: controls.description.value,
|
||||||
|
releaseDate: controls.releaseDate.value,
|
||||||
|
country: controls.country.value,
|
||||||
|
tagline: controls.tagline.value,
|
||||||
|
director: controls.director.value,
|
||||||
|
ageRating: controls.ageRating.value,
|
||||||
|
video: controls.video.value,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await editMovieObject(
|
||||||
|
currentId,
|
||||||
|
{
|
||||||
|
title: controls.title.value,
|
||||||
|
type: controls.type.value,
|
||||||
|
requiresSubscription: controls.requiresSubscription.checked,
|
||||||
|
poster: imageBase64,
|
||||||
|
description: controls.description.value,
|
||||||
|
releaseDate: controls.releaseDate.value,
|
||||||
|
country: controls.country.value,
|
||||||
|
tagline: controls.tagline.value,
|
||||||
|
director: controls.director.value,
|
||||||
|
ageRating: controls.ageRating.value,
|
||||||
|
video: controls.video.value,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
hideUpdateModal();
|
||||||
|
});
|
||||||
|
}
|
65
js/admin_panel_ui.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
export const controls = {
|
||||||
|
button: document.getElementById("addMovieButton"),
|
||||||
|
table: document.querySelector("#items-table tbody"),
|
||||||
|
form: document.getElementById("items-form"),
|
||||||
|
lineId: document.getElementById("items-line-id"),
|
||||||
|
imagePreview: document.getElementById("image-preview"),
|
||||||
|
|
||||||
|
title: document.querySelector('#title'),
|
||||||
|
type: document.querySelector('#type'),
|
||||||
|
requiresSubscription: document.querySelector('#requiresSubscription'),
|
||||||
|
image: document.querySelector('#image'),
|
||||||
|
description: document.querySelector('#description'),
|
||||||
|
releaseDate: document.querySelector('#releaseDate'),
|
||||||
|
country: document.querySelector('#country'),
|
||||||
|
tagline: document.querySelector('#tagline'),
|
||||||
|
director: document.querySelector('#director'),
|
||||||
|
ageRating: document.querySelector('#ageRating'),
|
||||||
|
video: document.querySelector('#video'),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const imagePlaceholder = "https://via.placeholder.com/200";
|
||||||
|
|
||||||
|
export function createTableColumn(value) {
|
||||||
|
const td = document.createElement("td");
|
||||||
|
td.textContent = value;
|
||||||
|
|
||||||
|
return td;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createTableAnchor(icon, callback) {
|
||||||
|
const i = document.createElement("i");
|
||||||
|
i.classList.add("fa-solid", icon);
|
||||||
|
|
||||||
|
const a = document.createElement("a");
|
||||||
|
a.href = "#";
|
||||||
|
a.appendChild(i);
|
||||||
|
a.onclick = (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
callback();
|
||||||
|
};
|
||||||
|
|
||||||
|
const td = document.createElement("td");
|
||||||
|
td.appendChild(a);
|
||||||
|
return td;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addTableRow(movie, index, editCallback, deleteCallback) {
|
||||||
|
const rowNumber = document.createElement("th");
|
||||||
|
rowNumber.scope = "row";
|
||||||
|
rowNumber.textContent = index + 1;
|
||||||
|
|
||||||
|
const row = document.createElement("tr");
|
||||||
|
row.id = `line-${movie.id}`;
|
||||||
|
|
||||||
|
row.appendChild(rowNumber);
|
||||||
|
row.appendChild(createTableColumn(movie.title));
|
||||||
|
row.appendChild(createTableColumn(movie.type));
|
||||||
|
row.appendChild(createTableColumn(movie.requiresSubscription === true ? 'Да' : 'Нет'));
|
||||||
|
row.appendChild(createTableColumn(movie.releaseDate));
|
||||||
|
row.appendChild(createTableAnchor("fa-pencil", editCallback));
|
||||||
|
row.appendChild(createTableAnchor("fa-trash", deleteCallback));
|
||||||
|
|
||||||
|
return row;
|
||||||
|
}
|
36
js/main_page.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { getMovies } from './rest_api';
|
||||||
|
|
||||||
|
export async function renderMovies() {
|
||||||
|
const moviesSection = document.querySelector('#movies');
|
||||||
|
const moviesContainer = moviesSection.querySelector('.row');
|
||||||
|
|
||||||
|
const seriesSection = document.querySelector('#series');
|
||||||
|
const seriesContainer = seriesSection.querySelector('.row');
|
||||||
|
|
||||||
|
moviesContainer.innerHTML = '';
|
||||||
|
seriesContainer.innerHTML = '';
|
||||||
|
|
||||||
|
const movies = await getMovies();
|
||||||
|
movies.forEach((movie) => {
|
||||||
|
console.log(movie.id);
|
||||||
|
console.log(movie.requiresSubscription);
|
||||||
|
|
||||||
|
const movieTemplate = `
|
||||||
|
<div class="col-6 col-lg-3">
|
||||||
|
<a href="videoplayer.html?id=${movie.id}" class="text-decoration-none">
|
||||||
|
<img src="${movie.poster}" class="img-fluid film-poster" alt="">
|
||||||
|
<h5 class="text-black mt-3">${movie.title}</h5>
|
||||||
|
<h6 class="text-secondary">${movie.requiresSubscription === true ? 'По подписке' : 'Бесплатно'}</h6>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
if (movie.type === 'Фильм') {
|
||||||
|
moviesContainer.innerHTML += movieTemplate;
|
||||||
|
} else if (movie.type === 'Сериал') {
|
||||||
|
seriesContainer.innerHTML += movieTemplate;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default renderMovies;
|
70
js/rest_api.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
const uri = "http://localhost:8081";
|
||||||
|
|
||||||
|
export async function getMovies() {
|
||||||
|
const response = await fetch(`${uri}/movies`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw response.statusText;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getMovieById(id) {
|
||||||
|
const response = await fetch(`${uri}/movies/${id}`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw response.statusText;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createMovie(serializedMovie) {
|
||||||
|
console.log(serializedMovie);
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(serializedMovie),
|
||||||
|
headers: {
|
||||||
|
"Accept": "application/json",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(`${uri}/movies`, options);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw response.statusText;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateMovie(id, serializedMovie) {
|
||||||
|
const options = {
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify(serializedMovie),
|
||||||
|
headers: {
|
||||||
|
"Accept": "application/json",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(`${uri}/movies/${id}`, options);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw response.statusText;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteMovie(id) {
|
||||||
|
const options = {
|
||||||
|
method: "DELETE",
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(`${uri}/movies/${id}`, options);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw response.statusText;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
56
js/table_modal.js
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import { Modal } from "bootstrap";
|
||||||
|
import { controls, imagePlaceholder } from "./admin_panel_ui";
|
||||||
|
|
||||||
|
const modal = document.getElementById("items-update");
|
||||||
|
const myModal = modal ? new Modal(modal, {}) : null;
|
||||||
|
|
||||||
|
const modalTitle = document.getElementById("items-update-title");
|
||||||
|
|
||||||
|
function resetValues() {
|
||||||
|
controls.lineId.value = "";
|
||||||
|
controls.imagePreview.src = imagePlaceholder;
|
||||||
|
|
||||||
|
controls.title.value = "";
|
||||||
|
controls.type.value = "";
|
||||||
|
controls.requiresSubscription.checked = false;
|
||||||
|
controls.image.value = "";
|
||||||
|
controls.description.value = "";
|
||||||
|
controls.releaseDate.value = "";
|
||||||
|
controls.country.value = "";
|
||||||
|
controls.tagline.value = "";
|
||||||
|
controls.director.value = "";
|
||||||
|
controls.ageRating.value = "";
|
||||||
|
controls.video.value = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showUpdateModal(item) {
|
||||||
|
modalTitle.innerHTML = item === null ? "Добавить" : "Изменить";
|
||||||
|
console.info(item);
|
||||||
|
|
||||||
|
if (item) {
|
||||||
|
controls.lineId.value = item.id;
|
||||||
|
controls.imagePreview.src = item.poster ? item.poster : imagePlaceholder;
|
||||||
|
|
||||||
|
controls.title.value = item.title;
|
||||||
|
controls.type.value = item.type;
|
||||||
|
controls.requiresSubscription.checked = item.requiresSubscription;
|
||||||
|
controls.description.value = item.description;
|
||||||
|
controls.releaseDate.value = item.releaseDate;
|
||||||
|
controls.country.value = item.country;
|
||||||
|
controls.tagline.value = item.tagline;
|
||||||
|
controls.director.value = item.director;
|
||||||
|
controls.ageRating.value = item.ageRating;
|
||||||
|
controls.video.value = item.video;
|
||||||
|
} else {
|
||||||
|
resetValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
myModal.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hideUpdateModal() {
|
||||||
|
resetValues();
|
||||||
|
controls.form.classList.remove("was-validated");
|
||||||
|
|
||||||
|
myModal.hide();
|
||||||
|
}
|
16
js/validation.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
function validation() {
|
||||||
|
const forms = document.querySelectorAll("form.needs-validation");
|
||||||
|
|
||||||
|
forms.forEach((form) => {
|
||||||
|
form.addEventListener("submit", (event) => {
|
||||||
|
if (!form.checkValidity()) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
|
form.classList.add("was-validated");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default validation;
|
36
js/videoplayer.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { getMovieById } from './rest_api';
|
||||||
|
|
||||||
|
export async function loadMovieData() {
|
||||||
|
const id = new URLSearchParams(location.search).get('id');
|
||||||
|
|
||||||
|
const movie = await getMovieById(id);
|
||||||
|
|
||||||
|
document.querySelector('iframe').setAttribute('src', movie.video);
|
||||||
|
document.querySelector('#movieTitle').innerHTML = movie.title;
|
||||||
|
document.querySelector('#movieDescription').innerHTML = movie.description;
|
||||||
|
|
||||||
|
const movieInfoTemplate = `
|
||||||
|
<h3>О фильме</h3>
|
||||||
|
<ul class="list-group list-group-flush my-3">
|
||||||
|
<li class="list-group-item">
|
||||||
|
<span class="fw-bold">Год производства:</span> ${movie.releaseDate}
|
||||||
|
</li>
|
||||||
|
<li class="list-group-item">
|
||||||
|
<span class="fw-bold">Страна:</span> ${movie.country}
|
||||||
|
</li>
|
||||||
|
<li class="list-group-item">
|
||||||
|
<span class="fw-bold">Слоган:</span> <span class="text-secondary">«${movie.tagline}»</span>
|
||||||
|
</li>
|
||||||
|
<li class="list-group-item">
|
||||||
|
<span class="fw-bold">Режиссер:</span> ${movie.director}
|
||||||
|
</li>
|
||||||
|
<li class="list-group-item">
|
||||||
|
<span class="fw-bold">Возраст:</span> ${movie.ageRating}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.querySelector('#movieInfoContainer').innerHTML = movieInfoTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default loadMovieData;
|
14
jsconfig.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Node",
|
||||||
|
"target": "ES2020",
|
||||||
|
"jsx": "preserve",
|
||||||
|
"strictNullChecks": true,
|
||||||
|
"strictFunctionTypes": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"**/node_modules/*"
|
||||||
|
]
|
||||||
|
}
|
27
login.html
@ -77,6 +77,10 @@
|
|||||||
<div class="input-group mb-3">
|
<div class="input-group mb-3">
|
||||||
<span class="input-group-text"><i class="bi bi-lock-fill"></i></span>
|
<span class="input-group-text"><i class="bi bi-lock-fill"></i></span>
|
||||||
<input type="password" class="form-control" id="password">
|
<input type="password" class="form-control" id="password">
|
||||||
|
<div class="input-group-text" id="hidePassword">
|
||||||
|
<a href=""><i class="bi bi-eye-fill"></i></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="input-group mt-4 d-flex justify-content-between">
|
<div class="input-group mt-4 d-flex justify-content-between">
|
||||||
@ -85,7 +89,7 @@
|
|||||||
<label for="formCheck" class="form-check-label text-secondary"><small>Запомнить на этом компьютере</small></label>
|
<label for="formCheck" class="form-check-label text-secondary"><small>Запомнить на этом компьютере</small></label>
|
||||||
</div>
|
</div>
|
||||||
<div class="forgot">
|
<div class="forgot">
|
||||||
<button class="btn btn-sm text-primary" data-bs-toggle="modal" data-bs-target="#forgot-modal">Забыли пароль?</button>
|
<button class="btn btn-sm text-primary" data-bs-toggle="modal" data-bs-target="#forgot-modal" id="forgotPassword">Забыли пароль?</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -144,5 +148,26 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
document.querySelector('#hidePassword').addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const inputField = document.querySelector('#password');
|
||||||
|
|
||||||
|
if (inputField.getAttribute('type') === 'password') {
|
||||||
|
inputField.setAttribute('type', 'text');
|
||||||
|
} else {
|
||||||
|
inputField.setAttribute('type', 'password');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelector('#forgotPassword').addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
4107
package-lock.json
generated
14
package.json
@ -3,18 +3,24 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "vite",
|
"vite": "vite",
|
||||||
"serve": "http-server -p 3000 ./dist/",
|
"serve": "http-server -p 3000 ./dist/",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"prod": "npm-run-all build serve"
|
"rest": "json-server --watch data.json -p 8081",
|
||||||
|
"dev": "npm-run-all --parallel rest vite",
|
||||||
|
"prod": "npm-run-all build --parallel serve rest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-free": "6.4.2",
|
"@fortawesome/fontawesome-free": "6.4.2",
|
||||||
"bootstrap": "^5.3.2"
|
"bootstrap": "^5.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"vite": "4.4.9",
|
||||||
|
"eslint": "8.50.0",
|
||||||
|
"eslint-config-airbnb-base": "15.0.0",
|
||||||
|
"eslint-plugin-import": "2.28.1",
|
||||||
"http-server": "14.1.1",
|
"http-server": "14.1.1",
|
||||||
"npm-run-all": "4.1.5",
|
"json-server": "0.17.4",
|
||||||
"vite": "4.4.9"
|
"npm-run-all": "4.1.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,3 +37,9 @@ body{
|
|||||||
.login-icon {
|
.login-icon {
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.image-preview {
|
||||||
|
border-radius: 20px;
|
||||||
|
max-width: 200px;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
@ -54,16 +54,16 @@
|
|||||||
<div class="ratio ratio-16x9 my-4">
|
<div class="ratio ratio-16x9 my-4">
|
||||||
<iframe width="560" height="315" src="https://www.youtube.com/embed/dfeUzm6KF4g?si=U2D-2WNsJzkcxlBX" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
<iframe width="560" height="315" src="https://www.youtube.com/embed/dfeUzm6KF4g?si=U2D-2WNsJzkcxlBX" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
||||||
</div>
|
</div>
|
||||||
<p class="display-4">Бойцовский клуб</p>
|
<p class="display-4" id="movieTitle">Бойцовский клуб</p>
|
||||||
|
|
||||||
<div class="row gx-5 gy-5 mb-4">
|
<div class="row gx-5 gy-5 mb-4">
|
||||||
<div class="col-lg-7">
|
<div class="col-lg-7">
|
||||||
<h3>Описание</h3>
|
<h3>Описание</h3>
|
||||||
<p class="my-4">
|
<p class="my-4" id="movieDescription">
|
||||||
Сотрудник страховой компании страдает хронической бессонницей и отчаянно пытается вырваться из мучительно скучной жизни. Однажды в очередной командировке он встречает некоего Тайлера Дёрдена — харизматического торговца мылом с извращенной философией. Тайлер уверен, что самосовершенствование — удел слабых, а единственное, ради чего стоит жить, — саморазрушение.<br><br> Проходит немного времени, и вот уже новые друзья лупят друг друга почем зря на стоянке перед баром, и очищающий мордобой доставляет им высшее блаженство. Приобщая других мужчин к простым радостям физической жестокости, они основывают тайный Бойцовский клуб, который начинает пользоваться невероятной популярностью.
|
Сотрудник страховой компании страдает хронической бессонницей и отчаянно пытается вырваться из мучительно скучной жизни. Однажды в очередной командировке он встречает некоего Тайлера Дёрдена — харизматического торговца мылом с извращенной философией. Тайлер уверен, что самосовершенствование — удел слабых, а единственное, ради чего стоит жить, — саморазрушение.<br><br> Проходит немного времени, и вот уже новые друзья лупят друг друга почем зря на стоянке перед баром, и очищающий мордобой доставляет им высшее блаженство. Приобщая других мужчин к простым радостям физической жестокости, они основывают тайный Бойцовский клуб, который начинает пользоваться невероятной популярностью.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-5">
|
<div class="col-lg-5" id="movieInfoContainer">
|
||||||
<h3>О фильме</h3>
|
<h3>О фильме</h3>
|
||||||
<ul class="list-group list-group-flush my-3">
|
<ul class="list-group list-group-flush my-3">
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
@ -112,5 +112,13 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
<script type="module">
|
||||||
|
import loadMovieData from './js/videoplayer.js';
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
loadMovieData();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
import { resolve } from 'path'
|
import { resolve } from "path";
|
||||||
import { defineConfig } from 'vite'
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
import { defineConfig } from "vite";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
build: {
|
build: {
|
||||||
|
sourcemap: true,
|
||||||
|
emptyOutDir: true,
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
input: {
|
input: {
|
||||||
main: resolve(__dirname, 'index.html'),
|
main: resolve(__dirname, "index.html"),
|
||||||
page2: resolve(__dirname, 'page2.html'),
|
page2: resolve(__dirname, "page2.html"),
|
||||||
page3: resolve(__dirname, 'page3.html'),
|
page3: resolve(__dirname, "page3.html"),
|
||||||
|
page4: resolve(__dirname, "page4.html"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
|
3
пример добавления.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Бегущий по лезвию - 2049
|
||||||
|
В недалеком будущем мир населен людьми и репликантами, созданными выполнять самую тяжелую работу. Работа офицера полиции Кей — держать репликантов под контролем в условиях нарастающего напряжения. Он случайно становится обладателем секретной информации, которая ставит под угрозу существование всего человечества. Желая найти ключ к разгадке, Кей решает разыскать Рика Декарда — бывшего офицера специального подразделения полиции Лос-Анджелеса, который бесследно исчез много лет назад
|
||||||
|
https://www.youtube.com/embed/tRcZ6yc1IMI?si=jhNRAis5XMW0yeH8
|