perf(web): embed static files and templates
@@ -0,0 +1,14 @@
|
||||
.loader {
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
max-width: 20%;
|
||||
}
|
||||
|
||||
.quote-form {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
left: 0;
|
||||
height: 100vh;
|
||||
background-color: #0008;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/* 自定义媒体查询设置根字体大小 */
|
||||
@media (max-width: 640px) {
|
||||
html {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
@media (width>640px) {
|
||||
html {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 9.8 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 9.8 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 651 KiB |
|
After Width: | Height: | Size: 972 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 95 KiB |
|
After Width: | Height: | Size: 9.5 KiB |
@@ -0,0 +1,16 @@
|
||||
$("#auth").on("submit", function (e) {
|
||||
e.preventDefault();
|
||||
$.ajax({
|
||||
url: "/api/auth",
|
||||
type: "POST",
|
||||
data: $("#auth").serialize(),
|
||||
dataType: "json",
|
||||
success: function (resp) {
|
||||
location.reload();
|
||||
},
|
||||
error: function (err) {
|
||||
$("#error-message").text(err.responseJSON.error);
|
||||
$("#error").removeClass("hidden");
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,256 @@
|
||||
const PAGE_SIZE = 10;
|
||||
var totalPages;
|
||||
var currPage = +sessionStorage.getItem("page");
|
||||
if (currPage == 0) {
|
||||
currPage = 1;
|
||||
}
|
||||
var search = sessionStorage.getItem("search");
|
||||
if (search == null) {
|
||||
search = "";
|
||||
}
|
||||
var sorting = sessionStorage.getItem("sort");
|
||||
if (sorting == null) {
|
||||
sorting = "-datetime";
|
||||
}
|
||||
var temp_quote_id;
|
||||
|
||||
function renderBlockQuote(quote) {
|
||||
return `
|
||||
<div class="border rounded-lg p-6 hover:shadow-md transition-shadow">
|
||||
<div class="flex justify-between items-start">
|
||||
<div>
|
||||
<p class="text-lg font-[Playfair_Display] mb-2">${escapedString(quote.text)}</p>
|
||||
<p class="text-sm text-gray-800">${escapedString(quote.author)}</p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<button class="text-gray-600 hover:text-custom" onclick="quoteEdit('${quote.id}');">
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
<button class="text-gray-600 hover:text-red-500" onclick="quoteDelete('${quote.id}');">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="w-full flex justify-between items-center flex-wrap gap-1 mt-2">
|
||||
<p class="text-xs text-gray-400">${new Date(quote.datetime).toLocaleString()}</p>
|
||||
<p class="text-xs text-gray-400">Добавил ${quote.creator.name}</p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function load() {
|
||||
var quotesCount;
|
||||
$("#input-search").val(search);
|
||||
$("#input-sorting").val(sorting);
|
||||
container = $("#block-quotes");
|
||||
$.ajax({
|
||||
async: false,
|
||||
url: `/api/quotes?filter=${encodeURIComponent(search)}&sort=${encodeURIComponent(sorting)}&limit=${PAGE_SIZE}&offset=${(currPage - 1)*PAGE_SIZE}`,
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function (resp) {
|
||||
quotesCount = resp.pagination.totalCount
|
||||
if (resp.pagination.count == 0) {
|
||||
container.html("<p style='text-align: center;'><i>Чёт нету ничего...</i></p>");
|
||||
return;
|
||||
}
|
||||
resp.quotes.forEach((quote) => {
|
||||
container.append(renderBlockQuote(quote));
|
||||
});
|
||||
},
|
||||
error: function (err) {
|
||||
$("#error-message").text(err.responseJSON.error);
|
||||
$("#error").removeClass("hidden");
|
||||
},
|
||||
complete: function () {
|
||||
$("#block-quotes-loader").addClass("hidden");
|
||||
},
|
||||
});
|
||||
totalPages = Math.ceil(quotesCount / PAGE_SIZE);
|
||||
$("#btn-page-curr").text(currPage);
|
||||
if (currPage > 1) {
|
||||
$("#btn-page-first").removeClass("hidden");
|
||||
if (currPage > 2) {
|
||||
$("#btn-page-prev").text(currPage - 1);
|
||||
$("#btn-page-prev").removeClass("hidden");
|
||||
if (currPage > 3) {
|
||||
$("#pages-prev").removeClass("hidden");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (currPage < totalPages) {
|
||||
$("#btn-page-last").text(totalPages);
|
||||
$("#btn-page-last").removeClass("hidden");
|
||||
if (currPage < totalPages - 1) {
|
||||
$("#btn-page-next").text(currPage + 1);
|
||||
$("#btn-page-next").removeClass("hidden");
|
||||
if (currPage < totalPages - 2) {
|
||||
$("#pages-next").removeClass("hidden");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function reload() {
|
||||
container = $("#block-quotes");
|
||||
loader = $("#block-quotes-loader");
|
||||
loader.removeClass("hidden");
|
||||
container.html(loader);
|
||||
$("#error").addClass("hidden");
|
||||
$("#btn-page-first").addClass("hidden");
|
||||
$("#pages-prev").addClass("hidden");
|
||||
$("#btn-page-prev").addClass("hidden");
|
||||
$("#btn-page-curr").text(1);
|
||||
$("#btn-page-next").addClass("hidden");
|
||||
$("#pages-next").addClass("hidden");
|
||||
$("#btn-page-last").addClass("hidden");
|
||||
load();
|
||||
}
|
||||
|
||||
function quoteEdit(quote_id) {
|
||||
$.ajax({
|
||||
url: `/api/quotes/${quote_id}`,
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function (resp) {
|
||||
temp_quote_id = quote_id;
|
||||
$("#edit-quote-text").val(resp.text);
|
||||
$("#edit-quote-author").val(resp.author);
|
||||
$("#edit-quote-datetime").val(resp.datetime.slice(0,19));
|
||||
$("body").css("overflow", "hidden");
|
||||
$("#quote-editor").css("top", $(window).scrollTop());
|
||||
$("#quote-editor").removeClass("hidden");
|
||||
},
|
||||
error: function (err) {
|
||||
$("#quote-editor-error-message").text(err.responseJSON.error);
|
||||
$("#quote-editor-error").removeClass("hidden");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function quoteDelete(quote_id) {
|
||||
$.ajax({
|
||||
url: `/api/quotes/${quote_id}`,
|
||||
type: "DELETE",
|
||||
success: function (resp) {
|
||||
reload();
|
||||
$("#error").addClass("hidden");
|
||||
},
|
||||
error: function (err) {
|
||||
$("#error-message").text(err.responseJSON.error);
|
||||
$("#error").removeClass("hidden");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on("click", "#btn-add-open", function (e) {
|
||||
now = new Date;
|
||||
now = new Date(now.getTime() - now.getTimezoneOffset() * 60000);
|
||||
$("#new-quote-datetime").val(now.toJSON().slice(0,19));
|
||||
$("body").css("overflow", "hidden");
|
||||
$("#quote-creator").css("top", $(window).scrollTop());
|
||||
$("#quote-creator").removeClass("hidden");
|
||||
});
|
||||
|
||||
$(document).on("click", "#btn-add-close", function (e) {
|
||||
$("#quote-creator").addClass("hidden");
|
||||
$("body").css("overflow", "");
|
||||
});
|
||||
|
||||
$(document).on("submit", "#quote-create", function (e) {
|
||||
e.preventDefault();
|
||||
data = formToJSON($("#quote-create"));
|
||||
data.datetime = datetimeToLocalISO(data.datetime);
|
||||
$.ajax({
|
||||
url: "/api/quotes",
|
||||
type: "POST",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
processData: false,
|
||||
dataType: "json",
|
||||
success: function (resp) {
|
||||
$("#quote-creator").addClass("hidden");
|
||||
$("body").css("overflow", "");
|
||||
reload();
|
||||
$("#new-quote-text").val("");
|
||||
$("#new-quote-author").val("");
|
||||
},
|
||||
error: function (err) {
|
||||
$("#quote-creator-error-message").text(err.responseJSON.error);
|
||||
$("#quote-creator-error").removeClass("hidden");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on("submit", "#quote-update", function (e) {
|
||||
e.preventDefault();
|
||||
data = formToJSON($("#quote-update"));
|
||||
data.datetime = datetimeToLocalISO(data.datetime);
|
||||
$.ajax({
|
||||
url: `/api/quotes/${temp_quote_id}`,
|
||||
type: "PATCH",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
processData: false,
|
||||
dataType: "json",
|
||||
success: function (resp) {
|
||||
$("#quote-editor").addClass("hidden");
|
||||
$("body").css("overflow", "");
|
||||
reload();
|
||||
$("#new-quote-text").val("");
|
||||
$("#new-quote-author").val("");
|
||||
},
|
||||
error: function (err) {
|
||||
$("#quote-editor-error-message").text(err.responseJSON.error);
|
||||
$("#quote-editor-error").removeClass("hidden");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on("click", "#btn-edit-close", function (e) {
|
||||
$("body").css("overflow", "");
|
||||
$("#quote-editor").addClass("hidden");
|
||||
$("#quote-editor textarea,input").val("");
|
||||
$("#quote-editor-error").addClass("hidden");
|
||||
});
|
||||
|
||||
$(window).on("load", function (e) {
|
||||
load();
|
||||
});
|
||||
|
||||
$(document).on("click", "#btn-refresh", function (e) {
|
||||
search = $("#input-search").val();
|
||||
if (search != "") {
|
||||
currPage = 1;
|
||||
sessionStorage.setItem("search", currPage);
|
||||
}
|
||||
sorting = $("#input-sorting option:selected").val();
|
||||
reload();
|
||||
sessionStorage.setItem("search", search);
|
||||
sessionStorage.setItem("sort", sorting);
|
||||
});
|
||||
|
||||
$(document).on("click", "#btn-page-first", function (e) {
|
||||
currPage = 1;
|
||||
reload();
|
||||
sessionStorage.setItem("page", currPage);
|
||||
});
|
||||
|
||||
$(document).on("click", "#btn-page-prev", function (e) {
|
||||
currPage--;
|
||||
reload();
|
||||
sessionStorage.setItem("page", currPage);
|
||||
});
|
||||
|
||||
$(document).on("click", "#btn-page-next", function (e) {
|
||||
currPage++;
|
||||
reload();
|
||||
sessionStorage.setItem("page", currPage);
|
||||
});
|
||||
|
||||
$(document).on("click", "#btn-page-last", function (e) {
|
||||
currPage = totalPages;
|
||||
reload();
|
||||
sessionStorage.setItem("page", currPage);
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
$(window).on("load", function (e) {
|
||||
$.ajax({
|
||||
url: "/api/auth",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function (resp) {
|
||||
$("#input-name").val(resp.name);
|
||||
$("#input-login").val(resp.login);
|
||||
$("#input-tgid").val(resp.telegram_id);
|
||||
},
|
||||
error: function (err) {
|
||||
$("#error-message").text(err.responseJSON.error);
|
||||
$("#error").removeClass("hidden");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on("click", "#btn-logout", function (e) {
|
||||
$.ajax({
|
||||
url: "/api/auth",
|
||||
type: "DELETE",
|
||||
success: function () {
|
||||
location.reload();
|
||||
},
|
||||
error: function (err) {
|
||||
$("#error-message").text(err.responseJSON.error);
|
||||
$("#error").removeClass("hidden");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on("submit", "#user-update", function (e) {
|
||||
e.preventDefault();
|
||||
data = formToJSON($("#user-update"));
|
||||
$.ajax({
|
||||
url: "/api/auth",
|
||||
type: "PATCH",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
processData: false,
|
||||
dataType: "json",
|
||||
success: function () {
|
||||
$("#error").addClass("hidden");
|
||||
$("#success").removeClass("hidden");
|
||||
$("#input-password").val("");
|
||||
},
|
||||
error: function (err) {
|
||||
$("#success").addClass("hidden");
|
||||
$("#error-message").text(err.responseJSON.error);
|
||||
$("#error").removeClass("hidden");
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
function datetimeToLocalISO(datetime) {
|
||||
options = {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
timeZoneName: "longOffset",
|
||||
};
|
||||
formatter = new Intl.DateTimeFormat("iso", options);
|
||||
date = new Date(datetime);
|
||||
parts = {}
|
||||
formatter
|
||||
.formatToParts(date)
|
||||
.map(({ type, value }) => {
|
||||
if (type === "timeZoneName") {
|
||||
value = value.slice(3);
|
||||
}
|
||||
if (type !== "literal") {
|
||||
parts[type] = value;
|
||||
}
|
||||
});
|
||||
return `${parts.year}-${parts.month}-${parts.day}T${parts.hour}:${parts.minute}:${parts.second}${parts.timeZoneName}`;
|
||||
}
|
||||
|
||||
function escapedString(str) {
|
||||
return str
|
||||
.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace("\n", "<br>");
|
||||
}
|
||||
|
||||
function formToJSON(form) {
|
||||
formdata = form.serializeArray();
|
||||
data = {};
|
||||
$(formdata).each(function (index, obj) {
|
||||
data[obj.name] = obj.value;
|
||||
});
|
||||
return data;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<browserconfig>
|
||||
<msapplication>
|
||||
<tile>
|
||||
<square70x70logo src="/ms-icon-70x70.png" />
|
||||
<square150x150logo src="/ms-icon-150x150.png" />
|
||||
<square310x310logo src="/ms-icon-310x310.png" />
|
||||
<TileColor>#8B6D5C</TileColor>
|
||||
</tile>
|
||||
</msapplication>
|
||||
</browserconfig>
|
||||
|
After Width: | Height: | Size: 76 KiB |
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "SkazaNull",
|
||||
"lang": "ru-RU",
|
||||
"start_url": "/",
|
||||
"scope": "/",
|
||||
"display": "standalone",
|
||||
"theme_color": "#8B6D5C",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/static/images/android-icon-36x36.png",
|
||||
"sizes": "36x36",
|
||||
"type": "image/png",
|
||||
"density": "0.75"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/android-icon-48x48.png",
|
||||
"sizes": "48x48",
|
||||
"type": "image/png",
|
||||
"density": "1.0"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/android-icon-72x72.png",
|
||||
"sizes": "72x72",
|
||||
"type": "image/png",
|
||||
"density": "1.5"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/android-icon-96x96.png",
|
||||
"sizes": "96x96",
|
||||
"type": "image/png",
|
||||
"density": "2.0"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/android-icon-144x144.png",
|
||||
"sizes": "144x144",
|
||||
"type": "image/png",
|
||||
"density": "3.0"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/android-icon-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"density": "4.0"
|
||||
}
|
||||
]
|
||||
}
|
||||