@@ -170,7 +160,7 @@ export default class BookSection {
-
+
${description || "Нет описания"}
@@ -197,17 +187,6 @@ export default class BookSection {
`;
}
- getMenuBody() {
- return menuEnum
- .map(({ label, id }) => {
- return `
-
- ${label}
- `;
- })
- .join("");
- }
-
getAuthors(authors) {
return (authors || [DEFAULT_AUTHOR])
.map(({ id, name }) => {
@@ -217,29 +196,6 @@ export default class BookSection {
.join("");
}
- openMenu(element) {
- this.closeMenu();
- element.classList.remove("main-book__menu_closed");
-
- const divElement = document.createElement("ul");
- divElement.innerHTML = this.getMenuBody();
-
- element.append(divElement);
- element.classList.add("main-book__menu_opened");
- }
-
- closeMenu() {
- const elements = document.querySelectorAll(".main-book__menu_opened");
-
- if (elements && elements.length) {
- for (const subElement of elements) {
- subElement.firstElementChild.remove();
- subElement.classList.remove("main-book__menu_opened");
- subElement.classList.add("main-book__menu_closed");
- }
- }
- }
-
toggleDetails(element) {
const isOpened = element.classList.contains("opened");
const article = element.parentNode.parentNode;
@@ -264,13 +220,23 @@ export default class BookSection {
const articles = document.querySelectorAll("[data-card]");
articles.forEach((article, i) => {
const tagWrapper = article.querySelector(".main-book__tags_wrapper");
+ const menuWrapper = article.querySelector(".main-book__menu_wrapper");
const bookid = article.dataset.bookid;
- const { tags } = this.data[i] || [];
+ const { tags, isBlocked, hasReadLater, authors } = this.data[i] || [];
const tagsComponent = new TagsComponent({ tags, article, bookid });
+ const menuComponent = new MenuComponent({
+ isBlocked,
+ hasReadLater,
+ authors,
+ bookid,
+ article,
+ });
tagWrapper.append(tagsComponent.element);
+ menuWrapper.append(menuComponent.element);
+ // console.log('article.scrollHeight', article.scrollHeight);
- if (article.scrollHeight > 502) {
+ if (article.scrollHeight > 424) {
const arrow = article.querySelector(".main-book__arrow_wrapper");
arrow.classList.remove("hidden");
}
@@ -295,27 +261,26 @@ export default class BookSection {
const { bookid: likedBookId, like } = element.dataset || {};
const isLiked = like === "true";
- if (!isLiked) {
- await likeEnum[0].action({ bookid: likedBookId });
- element.classList.remove("not-liked");
- element.classList.add("liked");
- } else {
+ if (isLiked) {
await likeEnum[1].action({ bookid: likedBookId });
element.classList.remove("liked");
element.classList.add("not-liked");
+ } else {
+ await likeEnum[0].action({ bookid: likedBookId });
+ element.classList.remove("not-liked");
+ element.classList.add("liked");
}
element.dataset.like = !isLiked;
this.data = this.data.map(({ isFavorite, id, ...rest }) =>
likedBookId === id
- ? { id, isFavorite: !isFavorite, ...rest }
+ ? { id, ...rest, isFavorite: !isFavorite }
: {
id,
isFavorite,
...rest,
}
);
- console.log("new data", this.data);
this.element.classList.remove("spinner");
}
@@ -326,6 +291,8 @@ export default class BookSection {
this.data = await searchByAuthor({ id: params.id });
} else if (params?.isByTag) {
this.data = await searchByTag({ id: params.id });
+ } else if (params?.isByRandom) {
+ this.data = await fetchRandomData();
} else {
const query = params;
this.data = await fetchData({ query, url: this.url });
@@ -335,10 +302,11 @@ export default class BookSection {
if (this.data && Object.values(this.data).length) {
this.subElements.body.innerHTML = this.getBookBody(this.data);
this.initialize();
+ await this.countHeight();
} else {
this.subElements.body.innerHTML = this.getEmptyBody();
}
- await this.countHeight();
+
this.element.classList.remove("spinner");
}
@@ -375,48 +343,50 @@ export default class BookSection {
}
}
-// this.data = [
-// {
-// id: "2",
-// authors: [{ id: "1", name: "123" }],
-// description:
-// "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
-// format: "123",
-// genres: [],
-// imageUrl: "",
-// title: "What is Lorem Ipsum?",
-// series: [],
-// subseries: [],
-// year: 1992,
-// tags: [
-// { id: 1, name: "Интересно" },
-// { id: 22, name: "Почитать" },
-// { id: 155, name: "Рекомендовали" },
-// { id: 166, name: "завтра" },
-// { id: 11, name: "наверное" },
-// { id: 221, name: "Почитданетать" },
-// { id: 1515, name: "раздватри" },
-// { id: 1661, name: "возможно" },
-// ],
-// isFavorite: true,
-// },
-// {
-// id: "22",
-// authors: [{ id: "1", name: "123" }],
-// description:
-// "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
-// format: "123",
-// genres: [],
-// imageUrl: "",
-// title: "dsfwqedwqefrwef",
-// series: [],
-// subseries: [],
-// year: 1992,
-// tags: [
-// { id: 1, name: "Интересно" },
-// { id: 22, name: "Почитать" },
-// { id: 155, name: "Рекомендовали" },
-// ],
-// isFavorite: true,
-// },
-// ];
+const testData = [
+ {
+ id: "2",
+ authors: [{ id: "1", name: "123" }],
+ description:
+ "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
+ format: "123",
+ genres: [],
+ imageUrl: "",
+ title: "What is Lorem Ipsum?",
+ series: [],
+ subseries: [],
+ year: 1992,
+ tags: [
+ { id: 1, name: "Интересно" },
+ { id: 22, name: "Почитать" },
+ { id: 155, name: "Рекомендовали" },
+ { id: 166, name: "завтра" },
+ { id: 11, name: "наверное" },
+ { id: 221, name: "Почитданетать" },
+ { id: 1515, name: "раздватри" },
+ { id: 1661, name: "возможно" },
+ ],
+ isFavorite: true,
+ hasReadLater: true,
+ isBlocked: true,
+ },
+ {
+ id: "22",
+ authors: [{ id: "1", name: "123" }],
+ description:
+ "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
+ format: "123",
+ genres: [],
+ imageUrl: "",
+ title: "dsfwqedwqefrwef",
+ series: [],
+ subseries: [],
+ year: 1992,
+ tags: [
+ { id: 1, name: "Интересно" },
+ { id: 22, name: "Почитать" },
+ { id: 155, name: "Рекомендовали" },
+ ],
+ isFavorite: true,
+ },
+];
diff --git a/src/BukiVedi.App/web/js/requests/index.js b/src/BukiVedi.App/web/js/requests/index.js
index 36fb7f3..fb03a35 100644
--- a/src/BukiVedi.App/web/js/requests/index.js
+++ b/src/BukiVedi.App/web/js/requests/index.js
@@ -20,6 +20,24 @@ export const fetchData = ({ query, url }) => {
});
};
+export const fetchRandomData = () => {
+ return $.ajax({
+ contentType: "application/json; charset=utf-8",
+ dataType: "json",
+ type: "POST",
+ url: "../api/books/qsearch",
+ success: function (data, textStatus, jqXHR) {
+ if (textStatus === SUCCESS) {
+ return data;
+ }
+ return [];
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+ console.log(jqXHR.statusText);
+ },
+ });
+};
+
export const addBookToFavourites = ({ bookid }) => {
return $.ajax({
type: "POST",
@@ -221,10 +239,6 @@ export const changeTags = ({ bookid, tags }) => {
console.log(jqXHR.statusText);
},
});
-
- // return [
- // {id: "6611598e1468849d1b00570d", name: "шиза"}
- // ];
};
export const searchByTag = ({ id }) => {
diff --git a/src/BukiVedi.App/web/js/utils/index.js b/src/BukiVedi.App/web/js/utils/index.js
index 9b8387a..b5e63b3 100644
--- a/src/BukiVedi.App/web/js/utils/index.js
+++ b/src/BukiVedi.App/web/js/utils/index.js
@@ -1,4 +1,4 @@
-export const stopPropagation = event => {
- event.stopImmediatePropagation();
- event.stopPropagation();
-}
\ No newline at end of file
+export const stopPropagation = (event) => {
+ event.stopImmediatePropagation();
+ event.stopPropagation();
+};
diff --git a/src/BukiVedi.App/web/script.js b/src/BukiVedi.App/web/script.js
index 4576623..87fbbac 100644
--- a/src/BukiVedi.App/web/script.js
+++ b/src/BukiVedi.App/web/script.js
@@ -1,14 +1,17 @@
-
import BookSection from "./js/main/index.js";
-import ButtonScroll from './js/scroll/index.js';
+import ButtonScroll from "./js/scroll/index.js";
const input = document.getElementById("search");
const books = document.getElementById("books");
const content = document.getElementById("content");
+const searchButton = document.getElementById("searchButton");
+const fortuneButton = document.getElementById("fortuneButton");
+
const booksSection = new BookSection({
url: "../api/books/search",
label: "books",
});
+
const click = () => {
const query = document.getElementById("search").value;
if (query) {
@@ -16,8 +19,19 @@ const click = () => {
}
};
-searchButton.addEventListener("click", click);
+const fortuneClick = () => {
+ booksSection.update({ isByRandom: true });
+};
+searchButton.addEventListener("click", click);
+fortuneButton.addEventListener("click", fortuneClick);
+input.addEventListener("input", function (e) {
+ if (e.target.value && e.target.value.length !== 0) {
+ searchButton.classList.add("visible");
+ } else {
+ searchButton.classList.remove("visible");
+ }
+});
input.addEventListener("keypress", function (event) {
if (event.key === "Enter") {
click();
@@ -25,5 +39,5 @@ input.addEventListener("keypress", function (event) {
});
books.append(booksSection.element);
-const scroll = new ButtonScroll()
-content.append(scroll.element)
\ No newline at end of file
+const scroll = new ButtonScroll();
+content.append(scroll.element);
diff --git a/src/BukiVedi.App/web/server.js b/src/BukiVedi.App/web/server.js
deleted file mode 100644
index fe8a538..0000000
--- a/src/BukiVedi.App/web/server.js
+++ /dev/null
@@ -1,52 +0,0 @@
-const path = require('path');
-const { createProxyMiddleware } = require('http-proxy-middleware');
-const cors = require('cors');
-
-const express = require('express');
-const app = express();
-
-const server = require('http').Server(app);
-const router = require('express').Router()
-
-const options = {
- target: 'https://book.ogoun.name/', // target host
- changeOrigin: true, // needed for virtual hosted sites
- ws: true, // proxy websockets
- logLevel: 'debug',
- secure: false,
- cookieDomainRewrite: {
- '*': 'localhost',
- },
- onProxyRes(proxyRes, req, _res) {
- if (proxyRes.headers['set-cookie'] !== undefined) {
- req.cookie = proxyRes.headers['set-cookie'];
- }
- },
- onProxyReq(proxyReq, req, _res) {
- if (req && req.cookie !== undefined) {
- proxyReq.setHeader('Cookie', req.cookie[0]);
- }
- },
-};
-
-const myLogger = function (req, res, next) {
- next()
-}
-
-app.use(myLogger)
-
-app.use(express.static(__dirname));
-app.use(express.static(__dirname + '/js'));
-app.use(express.static(__dirname + '/css'));
-app.use(express.static(__dirname + '/constants'));
-
-// app.get('/login', function (req, res) {
-// res.sendFile(path.join(__dirname, '/login.html'));
-// });
-
-app.use('/', cors({
- credentials: true,
- origin: 'http://localhost:3000',
-}), createProxyMiddleware(options));
-
-server.listen(3001);
\ No newline at end of file
diff --git a/src/BukiVedi.Shared/Apps/BooksHandler.cs b/src/BukiVedi.Shared/Apps/BooksHandler.cs
index bb52744..0486e26 100644
--- a/src/BukiVedi.Shared/Apps/BooksHandler.cs
+++ b/src/BukiVedi.Shared/Apps/BooksHandler.cs
@@ -2,6 +2,7 @@
using BukiVedi.Shared.Models;
using BukiVedi.Shared.Services;
using BukiVedi.Shared.Services.Mappers;
+using ZeroLevel.Patterns.Queries;
using ZeroLevel.Services.FileSystem;
namespace BukiVedi.Shared.Apps
@@ -176,6 +177,12 @@ namespace BukiVedi.Shared.Apps
return Enumerable.Empty();
}
+ public async Task> SearchAI(OperationContext context)
+ {
+ var books = (await _library.SearchBooksAI(context.OperationInitiator.Id)).ToArray();
+ return await BookEntityMapper.Map(books, context);
+ }
+
public async Task UnblockBook(string id, OperationContext context)
{
var account_id = context.OperationInitiator.Id;
diff --git a/src/BukiVedi.Shared/Apps/IBooksHandler.cs b/src/BukiVedi.Shared/Apps/IBooksHandler.cs
index f166ae5..97c256f 100644
--- a/src/BukiVedi.Shared/Apps/IBooksHandler.cs
+++ b/src/BukiVedi.Shared/Apps/IBooksHandler.cs
@@ -5,6 +5,7 @@ namespace BukiVedi.Shared.Apps
public interface IBooksHandler
{
Task> Search(string query, string? tag, OperationContext context);
+ Task> SearchAI(OperationContext context);
Task AddToFavorite(string id, OperationContext context);
Task AddAuthorsToFavorite(string id, OperationContext context);
Task BlockBook(string id, OperationContext context);
diff --git a/src/BukiVedi.Shared/IRepository.cs b/src/BukiVedi.Shared/IRepository.cs
index a219803..e81b70d 100644
--- a/src/BukiVedi.Shared/IRepository.cs
+++ b/src/BukiVedi.Shared/IRepository.cs
@@ -16,7 +16,7 @@ namespace BukiVedi.Shared
Task Count(FilterDefinition predicate);
Task Exists(FilterDefinition filter);
Task ExistById(string id);
-
+ T[] GetRandomDocuments(int count);
Task Write(T obj);
diff --git a/src/BukiVedi.Shared/Services/Library.cs b/src/BukiVedi.Shared/Services/Library.cs
index 41a118e..a707924 100644
--- a/src/BukiVedi.Shared/Services/Library.cs
+++ b/src/BukiVedi.Shared/Services/Library.cs
@@ -13,6 +13,7 @@ namespace BukiVedi.Shared.Services
{
Task> SearchBooksByAuthor(string author_id);
Task> SearchBooks(string title);
+ Task SearchBooksAI(string accountId);
Task> SearchByTagBooks(string accountId, string tagId);
Task> SearchTaggedBooks(string accountId, string tag = null!);
Task> SearchFavoritesBooks(string accountId);
@@ -96,7 +97,7 @@ namespace BukiVedi.Shared.Services
public async Task> SearchFavoritesBooks(string accountId)
{
-
+
IEnumerable bookIds = (await Tables.FavoriteBooks.Get(Filters.FavoriteBooks.ByUser(accountId)))?.Select(t => t.BookId)?.ToHashSet()!;
if (bookIds != null && bookIds.Any())
{
@@ -149,7 +150,7 @@ namespace BukiVedi.Shared.Services
{
IEnumerable bookIds;
if (string.IsNullOrWhiteSpace(tag))
- {
+ {
bookIds = (await Tables.UserTag.Get(Filters.Tags.ByUser(accountId)))?.Select(t => t.BookId)?.ToHashSet()!;
}
else
@@ -439,5 +440,27 @@ namespace BukiVedi.Shared.Services
await Tables.Books.Write(book);
}
}
+
+ public Task SearchBooksAI(string accountId)
+ {
+ var books = Tables.Books.GetRandomDocuments(50);
+ var result = new BookEntity[books.Length];
+ int index = 0;
+ foreach (var b in books)
+ {
+ result[index] = new BookEntity
+ {
+ Authors = GetAuthors(b),
+ Title = b.Title,
+ Year = b.Year,
+ Description = b.Description,
+ Format = b.Format,
+ Genre = new Genre(),
+ Id = b.Id,
+ };
+ index++;
+ }
+ return Task.FromResult(result);
+ }
}
}
diff --git a/src/BukiVedi.Shared/Services/MongoDB/MongoRepository.cs b/src/BukiVedi.Shared/Services/MongoDB/MongoRepository.cs
index 3c54efc..30156b3 100644
--- a/src/BukiVedi.Shared/Services/MongoDB/MongoRepository.cs
+++ b/src/BukiVedi.Shared/Services/MongoDB/MongoRepository.cs
@@ -1,6 +1,7 @@
using BukiVedi.Shared.Entities;
using MongoDB.Bson;
using MongoDB.Driver;
+using MongoDB.Driver.Linq;
using System.Linq.Expressions;
using ZeroLevel.Services.FileSystem;
@@ -104,6 +105,12 @@ namespace BukiVedi.Shared.Services.MongoDB
return result.ToEnumerable().ToArray();
}
+ public T[] GetRandomDocuments(int count)
+ {
+ var result = _collection.AsQueryable().Sample(count);
+ return result.ToArray();
+ }
+
public async Task Count(FilterDefinition filter)
{
return await _collection.CountDocumentsAsync(filter);
diff --git a/src/BukiVedi.Shared/bin/Debug/net8.0/BukiVedi.Shared.pdb b/src/BukiVedi.Shared/bin/Debug/net8.0/BukiVedi.Shared.pdb
index 538f7b2..da2fa32 100644
Binary files a/src/BukiVedi.Shared/bin/Debug/net8.0/BukiVedi.Shared.pdb and b/src/BukiVedi.Shared/bin/Debug/net8.0/BukiVedi.Shared.pdb differ
diff --git a/src/BukiVedi.Shared/obj/Debug/net8.0/BukiVedi.Shared.AssemblyInfo.cs b/src/BukiVedi.Shared/obj/Debug/net8.0/BukiVedi.Shared.AssemblyInfo.cs
index 133b6ef..034f311 100644
--- a/src/BukiVedi.Shared/obj/Debug/net8.0/BukiVedi.Shared.AssemblyInfo.cs
+++ b/src/BukiVedi.Shared/obj/Debug/net8.0/BukiVedi.Shared.AssemblyInfo.cs
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("BukiVedi.Shared")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
-[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+78ef654d3cca93dcdff7557d9a44da30b9d10a6a")]
+[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+708729b3f0a4a46b4ed8277753e30266f9b02ae4")]
[assembly: System.Reflection.AssemblyProductAttribute("BukiVedi.Shared")]
[assembly: System.Reflection.AssemblyTitleAttribute("BukiVedi.Shared")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
diff --git a/src/BukiVedi.Shared/obj/Debug/net8.0/BukiVedi.Shared.AssemblyInfoInputs.cache b/src/BukiVedi.Shared/obj/Debug/net8.0/BukiVedi.Shared.AssemblyInfoInputs.cache
index 8c5b692..6274847 100644
--- a/src/BukiVedi.Shared/obj/Debug/net8.0/BukiVedi.Shared.AssemblyInfoInputs.cache
+++ b/src/BukiVedi.Shared/obj/Debug/net8.0/BukiVedi.Shared.AssemblyInfoInputs.cache
@@ -1 +1 @@
-43fea615f27b115ca71adae9d28aa42c583a4dce3ecf8ac2e68c45249fa1eb8e
+47f2ecfa029d676b8f2f23a9542e5f91afdb2a5aba3b39b9691101443bb7f9e8
diff --git a/src/BukiVedi.Shared/obj/Debug/net8.0/BukiVedi.Shared.pdb b/src/BukiVedi.Shared/obj/Debug/net8.0/BukiVedi.Shared.pdb
index 538f7b2..da2fa32 100644
Binary files a/src/BukiVedi.Shared/obj/Debug/net8.0/BukiVedi.Shared.pdb and b/src/BukiVedi.Shared/obj/Debug/net8.0/BukiVedi.Shared.pdb differ