Added vue handling the information from lubimy czytac to fetch information about the books and fill in the form automatically.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
// any CSS you import will output into a single css file (app.scss in this case)
|
||||
import './styles/app.scss';
|
||||
import '../styles/app.scss';
|
||||
import 'bootstrap';
|
||||
|
||||
|
||||
7
assets/js/book.js
Normal file
7
assets/js/book.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import Vue from 'vue';
|
||||
import Book from './pages/book'
|
||||
import App from "./pages/files";
|
||||
|
||||
Vue.component('Book', Book);
|
||||
|
||||
new Vue().$mount('#app');
|
||||
2
assets/bootstrap.js → assets/js/bootstrap.js
vendored
2
assets/bootstrap.js → assets/js/bootstrap.js
vendored
@@ -2,7 +2,7 @@ import { startStimulusApp } from '@symfony/stimulus-bridge';
|
||||
|
||||
// Registers Stimulus controllers from controllers.json and in the controllers/ directory
|
||||
export const app = startStimulusApp(require.context(
|
||||
'@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
|
||||
'@symfony/stimulus-bridge/lazy-controller-loader!../controllers',
|
||||
true,
|
||||
/\.[jt]sx?$/
|
||||
));
|
||||
11
assets/js/components/bookform.vue
Normal file
11
assets/js/components/bookform.vue
Normal file
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div>
|
||||
<slot></slot>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'BookForm'
|
||||
}
|
||||
</script>
|
||||
11
assets/js/components/message.vue
Normal file
11
assets/js/components/message.vue
Normal file
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<div>
|
||||
<h2>another message</h2>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'Message'
|
||||
}
|
||||
</script>
|
||||
@@ -2,6 +2,4 @@ import Vue from 'vue';
|
||||
import App from './pages/files'
|
||||
|
||||
|
||||
new Vue({
|
||||
render: h => h(App)
|
||||
}).$mount('#app');
|
||||
new Vue().$mount('#app');
|
||||
75
assets/js/pages/book.vue
Normal file
75
assets/js/pages/book.vue
Normal file
@@ -0,0 +1,75 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="row g-3 align-items-center">
|
||||
<div class="col-auto">
|
||||
<input name="searchTerm" class="input form-control" placeholder="book title to search" @keypress.enter="search"
|
||||
v-model="searchTerm" type="text"/>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<button class="btn btn-info" @click="search">Szukaj</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="selectedBook && selectedBook.cover_url.small">
|
||||
<img :src="selectedBook.cover_url.small" class="img-thumbnail"/>
|
||||
</div>
|
||||
<div v-for="book in books">
|
||||
<div class="d-flex flex-row border mb-3 cursor-pointer book-search-item" @click="getBookDetails(book.url)">
|
||||
<img :src="book.cover_url.small" class="img-fluid rounded-start">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ book.title }} ({{ book.author }})</h5>
|
||||
<p class="card-text"><a :href="book.url"><small class="text-muted">{{ book.url }}</small></a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<slot></slot>
|
||||
<BookForm></BookForm>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BookForm from '../components/bookform'
|
||||
import axios from 'axios';
|
||||
|
||||
export default {
|
||||
name: 'Book',
|
||||
components: {BookForm},
|
||||
data() {
|
||||
return {
|
||||
searchTerm: null,
|
||||
books: [],
|
||||
selectedBook: null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
search: function () {
|
||||
console.info(this.searchTerm);
|
||||
axios.get('/book/search/' + this.searchTerm).then(response => {
|
||||
this.books = response.data;
|
||||
});
|
||||
},
|
||||
getBookDetails: function (url) {
|
||||
console.info(url);
|
||||
axios.get('/book/info/' + btoa(url)).then(response => {
|
||||
const book = this.selectedBook = response.data;
|
||||
this.$el.querySelector('#book_title').value = book.title;
|
||||
this.$el.querySelector('#book_author').value = book.author;
|
||||
this.$el.querySelector('#book_isbn').value = book.isbn;
|
||||
this.$el.querySelector('#book_pages').value = book.pages;
|
||||
this.$el.querySelector('#book_publish_date').value = book.datePublished;
|
||||
this.$el.querySelector('#book_publisher').value = book.publisher;
|
||||
this.$el.querySelector('#book_category').value = book.category;
|
||||
this.$el.querySelector('#book_language').value = book.language;
|
||||
this.$el.querySelector('#book_description').value = book.description;
|
||||
this.$el.querySelector('#book_series').value = book.cycle || '';
|
||||
this.$el.querySelector('#book_volume').value = book.volume || '';
|
||||
this.$el.querySelector('#book_cover_url').value = book.cover_url.large || '';
|
||||
this.books = [];
|
||||
this.searchTerm = '';
|
||||
});
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
24
assets/js/pages/files.vue
Normal file
24
assets/js/pages/files.vue
Normal file
@@ -0,0 +1,24 @@
|
||||
<template>
|
||||
<div>
|
||||
|
||||
<h1>hello {{ world }}</h1>
|
||||
<MessageComponent></MessageComponent>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import MessageComponent from "../components/message";
|
||||
import axios from 'axios';
|
||||
|
||||
export default {
|
||||
name: 'Files',
|
||||
components: {MessageComponent},
|
||||
data() {
|
||||
return {
|
||||
world: "świecie 2"
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -1,15 +0,0 @@
|
||||
<template>
|
||||
<h1>hello {{ world }}</h1>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
name: 'Files',
|
||||
data() {
|
||||
return {
|
||||
world: "świecie"
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
@@ -1,5 +1,13 @@
|
||||
@import "~bootstrap";
|
||||
|
||||
body {
|
||||
background-color: lightblue !important;
|
||||
//background-color: lightblue !important;
|
||||
}
|
||||
|
||||
.cursor-pointer {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.book-search-item:hover {
|
||||
background-color: $light;
|
||||
}
|
||||
@@ -44,6 +44,7 @@
|
||||
"symfony/webapp-meta": "^1.0",
|
||||
"symfony/webpack-encore-bundle": "^1.14",
|
||||
"symfony/yaml": "6.0.*",
|
||||
"techtube/bookinfo": "1.*",
|
||||
"twig/extra-bundle": "^2.12|^3.0",
|
||||
"twig/twig": "^2.12|^3.0"
|
||||
},
|
||||
@@ -103,5 +104,9 @@
|
||||
"symfony/maker-bundle": "^1.0",
|
||||
"symfony/stopwatch": "6.0.*",
|
||||
"symfony/web-profiler-bundle": "6.0.*"
|
||||
}
|
||||
},
|
||||
"repositories": [{
|
||||
"type": "composer",
|
||||
"url": "https://satis.techtube.pl"
|
||||
}]
|
||||
}
|
||||
|
||||
930
composer.lock
generated
930
composer.lock
generated
File diff suppressed because it is too large
Load Diff
31
migrations/Version20220527100258.php
Normal file
31
migrations/Version20220527100258.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20220527100258 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE book ADD category LONGTEXT DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE book DROP category');
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,10 @@
|
||||
"@hotwired/stimulus": "^3.0.0",
|
||||
"@symfony/stimulus-bridge": "^3.0.0",
|
||||
"@symfony/webpack-encore": "^2.0.0",
|
||||
"axios": "^0.27.2",
|
||||
"core-js": "^3.0.0",
|
||||
"popper.js": "^1.16.1",
|
||||
"prettier": "^2.6.2",
|
||||
"regenerator-runtime": "^0.13.2",
|
||||
"sass": "^1.52.1",
|
||||
"sass-loader": "^12.0.0",
|
||||
|
||||
@@ -9,9 +9,12 @@ use App\Repository\BookRepository;
|
||||
use App\Repository\FileRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Techtube\Bookinfo\BookFinder;
|
||||
use Techtube\Bookinfo\DataParser;
|
||||
|
||||
#[Route('/book')]
|
||||
class BookController extends AbstractController
|
||||
@@ -34,12 +37,20 @@ class BookController extends AbstractController
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$bookRepository->add($book, true);
|
||||
|
||||
$cover = $request->files->get('book')['cover'];
|
||||
if ($cover) {
|
||||
$cover->move(
|
||||
$this->getParameter('book_covers'),
|
||||
'cover_' . $book->getId() . '.' . $cover->guessClientExtension()
|
||||
$bookRequest = $request->request->all('book');
|
||||
if (!empty($bookRequest['cover_url'])) {
|
||||
file_put_contents(
|
||||
$this->getParameter('book_covers') . 'cover_' . $book->getId() . '.jpg',
|
||||
file_get_contents($bookRequest['cover_url'])
|
||||
);
|
||||
} else {
|
||||
$cover = $request->files->get('book')['cover'];
|
||||
if ($cover) {
|
||||
$cover->move(
|
||||
$this->getParameter('book_covers'),
|
||||
'cover_' . $book->getId() . '.' . $cover->guessClientExtension()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$ebook = $request->files->get('book')['ebook'];
|
||||
@@ -59,6 +70,20 @@ class BookController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/search/{phrase}', name: 'app_book_search', methods: ['GET'])]
|
||||
public function search(string $phrase): JsonResponse
|
||||
{
|
||||
$bookFinder = new BookFinder();
|
||||
return new JsonResponse($bookFinder->search($phrase));
|
||||
}
|
||||
|
||||
#[Route('/info/{urlInBase64}', name: 'app_book_info', methods: ['GET'])]
|
||||
public function info(string $urlInBase64): JsonResponse
|
||||
{
|
||||
$bookFinder = new BookFinder();
|
||||
return new JsonResponse($bookFinder->byUrl(base64_decode($urlInBase64)));
|
||||
}
|
||||
|
||||
#[Route('/{id}', name: 'app_book_show', methods: ['GET'])]
|
||||
public function show(Book $book): Response
|
||||
{
|
||||
|
||||
@@ -57,6 +57,9 @@ class Book
|
||||
#[ORM\Column(type: 'smallint', nullable: true)]
|
||||
private $rating;
|
||||
|
||||
#[ORM\Column(type: 'text', nullable: true)]
|
||||
private $category;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->files = new ArrayCollection();
|
||||
@@ -252,4 +255,16 @@ class Book
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCategory(): ?string
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function setCategory(?string $category): self
|
||||
{
|
||||
$this->category = $category;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,10 @@ class BookType extends AbstractType
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('Title')
|
||||
->add('title')
|
||||
->add('subtitle')
|
||||
->add('author')
|
||||
->add('category', TextType::class, ['attr' => ['rows' => 1]])
|
||||
->add('isbn')
|
||||
->add('pages')
|
||||
->add('tags')
|
||||
@@ -51,7 +52,10 @@ class BookType extends AbstractType
|
||||
'required' => false,
|
||||
'attr' => ['accept' => ".pdf, .epub, .mobi"]
|
||||
])
|
||||
->add('cover', FileType::class, ['mapped' => false, 'data_class' => null, 'required' => false]);
|
||||
->add('cover', FileType::class, ['mapped' => false, 'data_class' => null, 'required' => false])
|
||||
->add('cover_url', TextType::class, ['mapped' => false, 'help' => 'Fill in the field with a link to a cover image to use it as a cover for the book.', 'label'=> 'Cover url', 'required' => false])
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
|
||||
27
symfony.lock
27
symfony.lock
@@ -80,6 +80,18 @@
|
||||
"friendsofphp/proxy-manager-lts": {
|
||||
"version": "v1.0.12"
|
||||
},
|
||||
"guzzlehttp/guzzle": {
|
||||
"version": "7.4.3"
|
||||
},
|
||||
"guzzlehttp/promises": {
|
||||
"version": "1.5.1"
|
||||
},
|
||||
"guzzlehttp/psr7": {
|
||||
"version": "2.2.1"
|
||||
},
|
||||
"imangazaliev/didom": {
|
||||
"version": "2.0"
|
||||
},
|
||||
"laminas/laminas-code": {
|
||||
"version": "4.5.1"
|
||||
},
|
||||
@@ -110,12 +122,24 @@
|
||||
"psr/event-dispatcher": {
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"psr/http-client": {
|
||||
"version": "1.0.1"
|
||||
},
|
||||
"psr/http-factory": {
|
||||
"version": "1.0.1"
|
||||
},
|
||||
"psr/http-message": {
|
||||
"version": "1.0.1"
|
||||
},
|
||||
"psr/link": {
|
||||
"version": "2.0.1"
|
||||
},
|
||||
"psr/log": {
|
||||
"version": "3.0.0"
|
||||
},
|
||||
"ralouphie/getallheaders": {
|
||||
"version": "3.0.3"
|
||||
},
|
||||
"sensio/framework-extra-bundle": {
|
||||
"version": "6.2",
|
||||
"recipe": {
|
||||
@@ -506,6 +530,9 @@
|
||||
"symfony/yaml": {
|
||||
"version": "v6.0.3"
|
||||
},
|
||||
"techtube/bookinfo": {
|
||||
"version": "dev-master"
|
||||
},
|
||||
"twig/extra-bundle": {
|
||||
"version": "v3.4.0"
|
||||
},
|
||||
|
||||
@@ -4,8 +4,14 @@
|
||||
|
||||
{% block body %}
|
||||
<h1>Create new Book</h1>
|
||||
|
||||
{{ include('book/_form.html.twig') }}
|
||||
|
||||
<div id="app">
|
||||
<book>
|
||||
{{ include('book/_form.html.twig') }}
|
||||
</book>
|
||||
</div>
|
||||
<a href="{{ path('app_book_index') }}">back to list</a>
|
||||
{% endblock %}
|
||||
|
||||
{% block javascripts %}
|
||||
{{ encore_entry_script_tags('book') }}
|
||||
{% endblock %}
|
||||
@@ -7,6 +7,5 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block javascripts %}
|
||||
{{ parent() }}
|
||||
{{ encore_entry_script_tags('files') }}
|
||||
{% endblock %}
|
||||
@@ -20,8 +20,9 @@ Encore
|
||||
* Each entry will result in one JavaScript file (e.g. app.js)
|
||||
* and one CSS file (e.g. app.scss) if your JavaScript imports CSS.
|
||||
*/
|
||||
.addEntry('app', './assets/app.js')
|
||||
.addEntry('files', './assets/files.js')
|
||||
.addEntry('app', './assets/js/app.js')
|
||||
.addEntry('files', './assets/js/files.js')
|
||||
.addEntry('book', './assets/js/book.js')
|
||||
|
||||
// enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
|
||||
.enableStimulusBridge('./assets/controllers.json')
|
||||
@@ -47,9 +48,9 @@ Encore
|
||||
// enables hashed filenames (e.g. app.abc123.css)
|
||||
.enableVersioning(Encore.isProduction())
|
||||
|
||||
.configureBabel((config) => {
|
||||
config.plugins.push('@babel/plugin-proposal-class-properties');
|
||||
})
|
||||
// .configureBabel((config) => {
|
||||
// config.plugins.push('@babel/plugin-proposal-class-properties');
|
||||
// })
|
||||
|
||||
// enables @babel/preset-env polyfills
|
||||
.configureBabelPresetEnv((config) => {
|
||||
|
||||
23
yarn.lock
23
yarn.lock
@@ -1768,6 +1768,14 @@ aws4@^1.8.0:
|
||||
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
|
||||
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
|
||||
|
||||
axios@^0.27.2:
|
||||
version "0.27.2"
|
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
|
||||
integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==
|
||||
dependencies:
|
||||
follow-redirects "^1.14.9"
|
||||
form-data "^4.0.0"
|
||||
|
||||
babel-loader@^8.2.2:
|
||||
version "8.2.5"
|
||||
resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.2.5.tgz#d45f585e654d5a5d90f5350a779d7647c5ed512e"
|
||||
@@ -2544,7 +2552,7 @@ combine-source-map@^0.8.0, combine-source-map@~0.8.0:
|
||||
lodash.memoize "~3.0.3"
|
||||
source-map "~0.5.3"
|
||||
|
||||
combined-stream@^1.0.6, combined-stream@~1.0.6:
|
||||
combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
|
||||
version "1.0.8"
|
||||
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
|
||||
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
|
||||
@@ -3634,7 +3642,7 @@ flat@^5.0.2:
|
||||
resolved "https://registry.yarnpkg.com/flat/-/flat-5.0.2.tgz#8ca6fe332069ffa9d324c327198c598259ceb241"
|
||||
integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==
|
||||
|
||||
follow-redirects@^1.0.0:
|
||||
follow-redirects@^1.0.0, follow-redirects@^1.14.9:
|
||||
version "1.15.0"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.0.tgz#06441868281c86d0dda4ad8bdaead2d02dca89d4"
|
||||
integrity sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ==
|
||||
@@ -3656,6 +3664,15 @@ forever-agent@~0.6.1:
|
||||
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
|
||||
integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=
|
||||
|
||||
form-data@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
|
||||
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
|
||||
dependencies:
|
||||
asynckit "^0.4.0"
|
||||
combined-stream "^1.0.8"
|
||||
mime-types "^2.1.12"
|
||||
|
||||
form-data@~2.3.2:
|
||||
version "2.3.3"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
|
||||
@@ -5894,7 +5911,7 @@ preserve@^0.2.0:
|
||||
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
|
||||
integrity sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=
|
||||
|
||||
"prettier@^1.18.2 || ^2.0.0":
|
||||
"prettier@^1.18.2 || ^2.0.0", prettier@^2.6.2:
|
||||
version "2.6.2"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.2.tgz#e26d71a18a74c3d0f0597f55f01fb6c06c206032"
|
||||
integrity sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==
|
||||
|
||||
Reference in New Issue
Block a user