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:
krzysiej
2022-05-27 14:04:08 +02:00
parent 120991e584
commit 507eeece9e
22 changed files with 1060 additions and 203 deletions

View File

@@ -6,7 +6,7 @@
*/ */
// any CSS you import will output into a single css file (app.scss in this case) // 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'; import 'bootstrap';

7
assets/js/book.js Normal file
View 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');

View File

@@ -2,7 +2,7 @@ import { startStimulusApp } from '@symfony/stimulus-bridge';
// Registers Stimulus controllers from controllers.json and in the controllers/ directory // Registers Stimulus controllers from controllers.json and in the controllers/ directory
export const app = startStimulusApp(require.context( export const app = startStimulusApp(require.context(
'@symfony/stimulus-bridge/lazy-controller-loader!./controllers', '@symfony/stimulus-bridge/lazy-controller-loader!../controllers',
true, true,
/\.[jt]sx?$/ /\.[jt]sx?$/
)); ));

View File

@@ -0,0 +1,11 @@
<template>
<div>
<slot></slot>
</div>
</template>
<script>
export default {
name: 'BookForm'
}
</script>

View File

@@ -0,0 +1,11 @@
<template>
<div>
<h2>another message</h2>
</div>
</template>
<script>
export default {
name: 'Message'
}
</script>

View File

@@ -2,6 +2,4 @@ import Vue from 'vue';
import App from './pages/files' import App from './pages/files'
new Vue({ new Vue().$mount('#app');
render: h => h(App)
}).$mount('#app');

75
assets/js/pages/book.vue Normal file
View 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
View 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>

View File

@@ -1,15 +0,0 @@
<template>
<h1>hello {{ world }}</h1>
</template>
<script>
export default {
name: 'Files',
data() {
return {
world: "świecie"
}
},
}
</script>

View File

@@ -1,5 +1,13 @@
@import "~bootstrap"; @import "~bootstrap";
body { body {
background-color: lightblue !important; //background-color: lightblue !important;
} }
.cursor-pointer {
cursor: pointer;
}
.book-search-item:hover {
background-color: $light;
}

View File

@@ -44,6 +44,7 @@
"symfony/webapp-meta": "^1.0", "symfony/webapp-meta": "^1.0",
"symfony/webpack-encore-bundle": "^1.14", "symfony/webpack-encore-bundle": "^1.14",
"symfony/yaml": "6.0.*", "symfony/yaml": "6.0.*",
"techtube/bookinfo": "1.*",
"twig/extra-bundle": "^2.12|^3.0", "twig/extra-bundle": "^2.12|^3.0",
"twig/twig": "^2.12|^3.0" "twig/twig": "^2.12|^3.0"
}, },
@@ -103,5 +104,9 @@
"symfony/maker-bundle": "^1.0", "symfony/maker-bundle": "^1.0",
"symfony/stopwatch": "6.0.*", "symfony/stopwatch": "6.0.*",
"symfony/web-profiler-bundle": "6.0.*" "symfony/web-profiler-bundle": "6.0.*"
} },
"repositories": [{
"type": "composer",
"url": "https://satis.techtube.pl"
}]
} }

930
composer.lock generated

File diff suppressed because it is too large Load Diff

View 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');
}
}

View File

@@ -3,8 +3,10 @@
"@hotwired/stimulus": "^3.0.0", "@hotwired/stimulus": "^3.0.0",
"@symfony/stimulus-bridge": "^3.0.0", "@symfony/stimulus-bridge": "^3.0.0",
"@symfony/webpack-encore": "^2.0.0", "@symfony/webpack-encore": "^2.0.0",
"axios": "^0.27.2",
"core-js": "^3.0.0", "core-js": "^3.0.0",
"popper.js": "^1.16.1", "popper.js": "^1.16.1",
"prettier": "^2.6.2",
"regenerator-runtime": "^0.13.2", "regenerator-runtime": "^0.13.2",
"sass": "^1.52.1", "sass": "^1.52.1",
"sass-loader": "^12.0.0", "sass-loader": "^12.0.0",

View File

@@ -9,9 +9,12 @@ use App\Repository\BookRepository;
use App\Repository\FileRepository; use App\Repository\FileRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
use Techtube\Bookinfo\BookFinder;
use Techtube\Bookinfo\DataParser;
#[Route('/book')] #[Route('/book')]
class BookController extends AbstractController class BookController extends AbstractController
@@ -34,12 +37,20 @@ class BookController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$bookRepository->add($book, true); $bookRepository->add($book, true);
$cover = $request->files->get('book')['cover']; $bookRequest = $request->request->all('book');
if ($cover) { if (!empty($bookRequest['cover_url'])) {
$cover->move( file_put_contents(
$this->getParameter('book_covers'), $this->getParameter('book_covers') . 'cover_' . $book->getId() . '.jpg',
'cover_' . $book->getId() . '.' . $cover->guessClientExtension() 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']; $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'])] #[Route('/{id}', name: 'app_book_show', methods: ['GET'])]
public function show(Book $book): Response public function show(Book $book): Response
{ {

View File

@@ -57,6 +57,9 @@ class Book
#[ORM\Column(type: 'smallint', nullable: true)] #[ORM\Column(type: 'smallint', nullable: true)]
private $rating; private $rating;
#[ORM\Column(type: 'text', nullable: true)]
private $category;
public function __construct() public function __construct()
{ {
$this->files = new ArrayCollection(); $this->files = new ArrayCollection();
@@ -252,4 +255,16 @@ class Book
return $this; return $this;
} }
public function getCategory(): ?string
{
return $this->category;
}
public function setCategory(?string $category): self
{
$this->category = $category;
return $this;
}
} }

View File

@@ -17,9 +17,10 @@ class BookType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options): void public function buildForm(FormBuilderInterface $builder, array $options): void
{ {
$builder $builder
->add('Title') ->add('title')
->add('subtitle') ->add('subtitle')
->add('author') ->add('author')
->add('category', TextType::class, ['attr' => ['rows' => 1]])
->add('isbn') ->add('isbn')
->add('pages') ->add('pages')
->add('tags') ->add('tags')
@@ -51,7 +52,10 @@ class BookType extends AbstractType
'required' => false, 'required' => false,
'attr' => ['accept' => ".pdf, .epub, .mobi"] '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 public function configureOptions(OptionsResolver $resolver): void

View File

@@ -80,6 +80,18 @@
"friendsofphp/proxy-manager-lts": { "friendsofphp/proxy-manager-lts": {
"version": "v1.0.12" "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": { "laminas/laminas-code": {
"version": "4.5.1" "version": "4.5.1"
}, },
@@ -110,12 +122,24 @@
"psr/event-dispatcher": { "psr/event-dispatcher": {
"version": "1.0.0" "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": { "psr/link": {
"version": "2.0.1" "version": "2.0.1"
}, },
"psr/log": { "psr/log": {
"version": "3.0.0" "version": "3.0.0"
}, },
"ralouphie/getallheaders": {
"version": "3.0.3"
},
"sensio/framework-extra-bundle": { "sensio/framework-extra-bundle": {
"version": "6.2", "version": "6.2",
"recipe": { "recipe": {
@@ -506,6 +530,9 @@
"symfony/yaml": { "symfony/yaml": {
"version": "v6.0.3" "version": "v6.0.3"
}, },
"techtube/bookinfo": {
"version": "dev-master"
},
"twig/extra-bundle": { "twig/extra-bundle": {
"version": "v3.4.0" "version": "v3.4.0"
}, },

View File

@@ -4,8 +4,14 @@
{% block body %} {% block body %}
<h1>Create new Book</h1> <h1>Create new Book</h1>
<div id="app">
{{ include('book/_form.html.twig') }} <book>
{{ include('book/_form.html.twig') }}
</book>
</div>
<a href="{{ path('app_book_index') }}">back to list</a> <a href="{{ path('app_book_index') }}">back to list</a>
{% endblock %} {% endblock %}
{% block javascripts %}
{{ encore_entry_script_tags('book') }}
{% endblock %}

View File

@@ -7,6 +7,5 @@
{% endblock %} {% endblock %}
{% block javascripts %} {% block javascripts %}
{{ parent() }}
{{ encore_entry_script_tags('files') }} {{ encore_entry_script_tags('files') }}
{% endblock %} {% endblock %}

View File

@@ -20,8 +20,9 @@ Encore
* Each entry will result in one JavaScript file (e.g. app.js) * 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. * and one CSS file (e.g. app.scss) if your JavaScript imports CSS.
*/ */
.addEntry('app', './assets/app.js') .addEntry('app', './assets/js/app.js')
.addEntry('files', './assets/files.js') .addEntry('files', './assets/js/files.js')
.addEntry('book', './assets/js/book.js')
// enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js) // enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
.enableStimulusBridge('./assets/controllers.json') .enableStimulusBridge('./assets/controllers.json')
@@ -47,9 +48,9 @@ Encore
// enables hashed filenames (e.g. app.abc123.css) // enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction()) .enableVersioning(Encore.isProduction())
.configureBabel((config) => { // .configureBabel((config) => {
config.plugins.push('@babel/plugin-proposal-class-properties'); // config.plugins.push('@babel/plugin-proposal-class-properties');
}) // })
// enables @babel/preset-env polyfills // enables @babel/preset-env polyfills
.configureBabelPresetEnv((config) => { .configureBabelPresetEnv((config) => {

View File

@@ -1768,6 +1768,14 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA== 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: babel-loader@^8.2.2:
version "8.2.5" version "8.2.5"
resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.2.5.tgz#d45f585e654d5a5d90f5350a779d7647c5ed512e" 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" lodash.memoize "~3.0.3"
source-map "~0.5.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" version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== 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" resolved "https://registry.yarnpkg.com/flat/-/flat-5.0.2.tgz#8ca6fe332069ffa9d324c327198c598259ceb241"
integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ== integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==
follow-redirects@^1.0.0: follow-redirects@^1.0.0, follow-redirects@^1.14.9:
version "1.15.0" version "1.15.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.0.tgz#06441868281c86d0dda4ad8bdaead2d02dca89d4" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.0.tgz#06441868281c86d0dda4ad8bdaead2d02dca89d4"
integrity sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ== 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" resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE= 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: form-data@~2.3.2:
version "2.3.3" version "2.3.3"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6" 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" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
integrity sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks= 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" version "2.6.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.2.tgz#e26d71a18a74c3d0f0597f55f01fb6c06c206032" resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.2.tgz#e26d71a18a74c3d0f0597f55f01fb6c06c206032"
integrity sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew== integrity sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==