refactor: supprimer tout le code legacy MVC/Twig/Stimulus
Supprime toutes les couches pré-DDD pour ne garder que l'architecture hexagonale (src/Domain/), les entités Doctrine et le front Vue.js SPA. Supprimé : - src/Controller/ (9 controllers Twig, garde SecurityController) - src/Service/, src/Message/, src/MessageHandler/ (services et messages legacy) - src/Manager/, src/Twig/, src/Form/ (UI legacy) - src/Event/, src/EventListener/, src/EventSubscriber/QueueStatusSubscriber - src/Client/MangadexClient.php (doublon du Domain) - src/Interface/, src/Factory/, src/DataFixtures/, src/Scheduler/MainSchedule - templates/ (tous sauf vue/ et base retiré — SecurityController = pur JSON) - assets/controllers/ (20 Stimulus controllers), app.js, bootstrap.js, controllers.json Modifié : - config/routes.yaml : suppression du chargement des controllers legacy - config/packages/messenger.yaml : suppression des routes legacy - config/services.yaml : suppression des bindings legacy + entrées Domain\Import fantômes - webpack.config.js : suppression entry 'app' et enableStimulusBridge - src/Entity/Chapter.php : suppression #[Broadcast] (Turbo Streams legacy) Déplacé : - src/Factory/*.php → tests/Factory/ (namespace App\Tests\Factory)
This commit is contained in:
parent
d7e6bf56d0
commit
5a0888eb28
@@ -1,17 +0,0 @@
|
||||
import './bootstrap.js';
|
||||
|
||||
import '@fortawesome/fontawesome-free/js/all.js';
|
||||
/*
|
||||
* Welcome to your app's main JavaScript file!
|
||||
*
|
||||
* We recommend including the built version of this JavaScript file
|
||||
* (and its CSS file) in your base layout (base.html.twig).
|
||||
*/
|
||||
|
||||
// any CSS you import will output into a single css file (app.css in this case)
|
||||
import './styles/app.scss';
|
||||
|
||||
// start the Stimulus application
|
||||
import './bootstrap';
|
||||
|
||||
// La ligne registerReactControllerComponents a déjà été commentée
|
||||
35
assets/bootstrap.js
vendored
35
assets/bootstrap.js
vendored
@@ -1,35 +0,0 @@
|
||||
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',
|
||||
true,
|
||||
/\.[jt]sx?$/
|
||||
));
|
||||
|
||||
// register any custom, 3rd party controllers here
|
||||
// app.register('some_controller_name', SomeImportedController);
|
||||
|
||||
//DEBUG TURBO
|
||||
// import * as Turbo from "@hotwired/turbo"
|
||||
//
|
||||
// Turbo.session.drive = false
|
||||
// Turbo.start()
|
||||
//
|
||||
// // Écouteurs existants
|
||||
// document.addEventListener("turbo:before-stream-render", (event) => {
|
||||
// console.log("Before stream render", event.target);
|
||||
// });
|
||||
//
|
||||
// document.addEventListener("turbo:stream-render", (event) => {
|
||||
// console.log("Stream rendered", event.target);
|
||||
// });
|
||||
//
|
||||
// // Nouvel écouteur pour les événements de création
|
||||
// document.addEventListener("turbo:before-fetch-request", (event) => {
|
||||
// console.log("Before fetch request", event.detail.fetchOptions);
|
||||
// });
|
||||
//
|
||||
// document.addEventListener("turbo:before-fetch-response", (event) => {
|
||||
// console.log("Before fetch response", event.detail.fetchResponse);
|
||||
// });
|
||||
@@ -1,30 +0,0 @@
|
||||
{
|
||||
"controllers": {
|
||||
"@symfony/ux-live-component": {
|
||||
"live": {
|
||||
"enabled": true,
|
||||
"fetch": "eager",
|
||||
"autoimport": {
|
||||
"@symfony/ux-live-component/dist/live.min.css": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"@symfony/ux-react": {
|
||||
"react": {
|
||||
"enabled": true,
|
||||
"fetch": "eager"
|
||||
}
|
||||
},
|
||||
"@symfony/ux-turbo": {
|
||||
"turbo-core": {
|
||||
"enabled": true,
|
||||
"fetch": "eager"
|
||||
},
|
||||
"mercure-turbo-stream": {
|
||||
"enabled": true,
|
||||
"fetch": "eager"
|
||||
}
|
||||
}
|
||||
},
|
||||
"entrypoints": []
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
import {Controller} from '@hotwired/stimulus';
|
||||
|
||||
/*
|
||||
* The following line makes this controller "lazy": it won't be downloaded until needed
|
||||
* See https://github.com/symfony/stimulus-bridge#lazy-controllers
|
||||
*/
|
||||
/* stimulusFetch: 'lazy' */
|
||||
export default class extends Controller {
|
||||
static targets = ['activity']
|
||||
|
||||
// ...
|
||||
async connect() {
|
||||
try {
|
||||
const response = await fetch(`/activity/status`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
// Handle the response data as needed
|
||||
this.activityTarget.innerHTML = data.length;
|
||||
if (data.length > 0) {
|
||||
this.activityTarget.classList.remove('hidden');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
|
||||
|
||||
const mercureHubUrl = 'https://mangarr.test.nestor-server.fr/.well-known/mercure';
|
||||
const eventSource = new EventSource(`${mercureHubUrl}?topic=activity`, {withCredentials: true});
|
||||
|
||||
eventSource.onmessage = (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.processing !== undefined && data.pending !== undefined) {
|
||||
let totalActivities = data.processing.length + data.pending.length;
|
||||
this.activityTarget.innerHTML = totalActivities;
|
||||
if (totalActivities > 0) {
|
||||
this.activityTarget.classList.remove('hidden');
|
||||
}else if (totalActivities === 0) {
|
||||
this.activityTarget.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
eventSource
|
||||
.onerror = (event) => {
|
||||
console.error('EventSource failed:', event);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
// assets/controllers/addmanga_controller.js
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static values = {
|
||||
index: Number
|
||||
}
|
||||
|
||||
openModal(event) {
|
||||
event.preventDefault()
|
||||
const openEvent = new CustomEvent(`openAddMangaModal${this.indexValue}`)
|
||||
document.dispatchEvent(openEvent)
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
import {Controller} from '@hotwired/stimulus';
|
||||
|
||||
/*
|
||||
* The following line makes this controller "lazy": it won't be downloaded until needed
|
||||
* See https://github.com/symfony/stimulus-bridge#lazy-controllers
|
||||
*/
|
||||
/* stimulusFetch: 'lazy' */
|
||||
export default class extends Controller {
|
||||
static targets = ['alert', 'icon', 'message']
|
||||
|
||||
connect() {
|
||||
window.addEventListener('alert:show', this.showAlert.bind(this));
|
||||
}
|
||||
|
||||
// ...
|
||||
showAlert(event) {
|
||||
const detail = event.detail;
|
||||
const message = detail.message;
|
||||
const level = detail.level;
|
||||
|
||||
let alertClass = "";
|
||||
let iconClass = "";
|
||||
switch (level) {
|
||||
case 'success':
|
||||
alertClass = "bg-green-500";
|
||||
iconClass = "fa-circle-check";
|
||||
break;
|
||||
case 'warning':
|
||||
alertClass = "bg-yellow-500";
|
||||
iconClass = "fa-circle-exclamation";
|
||||
break;
|
||||
case 'error':
|
||||
alertClass = "bg-red-500";
|
||||
iconClass = "fa-circle-xmark";
|
||||
break;
|
||||
case 'info':
|
||||
default:
|
||||
alertClass = "bg-blue-500";
|
||||
iconClass = "fa-circle-info";
|
||||
break;
|
||||
}
|
||||
|
||||
this.messageTarget.innerHTML = message;
|
||||
this.alertTarget.classList.add(alertClass);
|
||||
this.iconTarget.classList.add(iconClass);
|
||||
this.alertTarget.style.display = "block";
|
||||
|
||||
setTimeout(() => {
|
||||
this.alertTarget.style.opacity = 0;
|
||||
|
||||
setTimeout(() => {
|
||||
this.alertTarget.style.display = 'none';
|
||||
this.alertTarget.classList.remove(alertClass);
|
||||
this.alertTarget.style.opacity = 1;
|
||||
this.iconTarget.classList.remove(iconClass);
|
||||
this.messageTarget.innerHTML = message;
|
||||
}, 1000);
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
/* stimulusFetch: 'lazy' */
|
||||
export default class extends Controller {
|
||||
static targets = ['progressBar', 'progressText']
|
||||
static values = {
|
||||
chapterId: Number
|
||||
}
|
||||
|
||||
connect() {
|
||||
this.currentPage = 0;
|
||||
this.totalPages = 0;
|
||||
|
||||
const mercureHubUrl = 'https://mangarr.test.nestor-server.fr/.well-known/mercure';
|
||||
this.eventSource = new EventSource(`${mercureHubUrl}?topic=activity`, {withCredentials: true});
|
||||
|
||||
this.eventSource.onmessage = this.handleMessage.bind(this);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
if (this.eventSource) {
|
||||
this.eventSource.close();
|
||||
}
|
||||
}
|
||||
|
||||
handleMessage(event) {
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.status === "scrapping.progress" && data.chapterId === this.chapterIdValue) {
|
||||
this.handleProgressUpdate(data);
|
||||
}
|
||||
}
|
||||
|
||||
handleProgressUpdate(data) {
|
||||
this.currentPage = data.pageIndex;
|
||||
this.totalPages = data.totalPages;
|
||||
|
||||
this.updateProgressBar();
|
||||
}
|
||||
|
||||
updateProgressBar() {
|
||||
const progress = (this.currentPage / this.totalPages) * 100;
|
||||
this.progressBarTarget.style.width = `${progress}%`;
|
||||
this.progressTextTarget.textContent = `${this.currentPage} / ${this.totalPages}`;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import {Controller} from '@hotwired/stimulus';
|
||||
|
||||
/*
|
||||
* The following line makes this controller "lazy": it won't be downloaded until needed
|
||||
* See https://github.com/symfony/stimulus-bridge#lazy-controllers
|
||||
*/
|
||||
/* stimulusFetch: 'lazy' */
|
||||
export default class extends Controller {
|
||||
static targets = ['container', 'template', 'item'];
|
||||
|
||||
connect() {
|
||||
this.index = this.itemTargets.length;
|
||||
}
|
||||
|
||||
add(event) {
|
||||
event.preventDefault();
|
||||
const template = this.templateTarget.innerHTML.replace(/__name__/g, this.index);
|
||||
this.containerTarget.insertAdjacentHTML('beforeend', template);
|
||||
this.index++;
|
||||
}
|
||||
|
||||
remove(event) {
|
||||
event.preventDefault();
|
||||
event.target.closest('.collection-item').remove();
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
/* stimulusFetch: 'lazy' */
|
||||
export default class extends Controller {
|
||||
static targets = ['icon']
|
||||
static values = {
|
||||
url: String
|
||||
}
|
||||
|
||||
connect() {
|
||||
this.defaultIconClass = this.iconTarget.classList.value;
|
||||
}
|
||||
|
||||
async download(event) {
|
||||
event.preventDefault();
|
||||
|
||||
// Change the icon to a loader
|
||||
this.iconTarget.classList.remove("fa-download", "fa-search");
|
||||
this.iconTarget.classList.add("fa-spinner", "fa-spin");
|
||||
|
||||
try {
|
||||
const response = await fetch(this.urlValue, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
}
|
||||
});
|
||||
|
||||
const contentType = response.headers.get("Content-Type");
|
||||
if (contentType && contentType.includes("application/json")) {
|
||||
const data = await response.json();
|
||||
if (data.error) {
|
||||
this.dispatchAlert(data.error, 'error');
|
||||
} else if (data.success) {
|
||||
this.dispatchAlert(data.success, 'success');
|
||||
}
|
||||
} else {
|
||||
// C'est un fichier à télécharger
|
||||
const blob = await response.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.style.display = 'none';
|
||||
a.href = url;
|
||||
const contentDisposition = response.headers.get('Content-Disposition');
|
||||
const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
||||
const matches = filenameRegex.exec(contentDisposition);
|
||||
let filename = 'download';
|
||||
if (matches != null && matches[1]) {
|
||||
filename = matches[1].replace(/['"]/g, '');
|
||||
}
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
}
|
||||
} finally {
|
||||
// Revert the icon back to the original one
|
||||
this.iconTarget.classList.value = this.defaultIconClass;
|
||||
}
|
||||
}
|
||||
|
||||
dispatchAlert(message, level) {
|
||||
const event = new CustomEvent('alert:show', {
|
||||
detail: { message: message, level: level }
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
// assets/controllers/dropdown_controller.js
|
||||
import {Controller} from "@hotwired/stimulus"
|
||||
import {useClickOutside} from "stimulus-use"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["button", "menu"]
|
||||
|
||||
connect() {
|
||||
useClickOutside(this)
|
||||
}
|
||||
|
||||
toggle(event) {
|
||||
this.menuTarget.classList.toggle('hidden')
|
||||
if (!this.menuTarget.classList.contains('hidden')) {
|
||||
this.positionMenu()
|
||||
}
|
||||
}
|
||||
|
||||
clickOutside(event) {
|
||||
this.menuTarget.classList.add('hidden')
|
||||
}
|
||||
|
||||
positionMenu() {
|
||||
const buttonRect = this.buttonTarget.getBoundingClientRect()
|
||||
const menuRect = this.menuTarget.getBoundingClientRect()
|
||||
const spaceRight = window.innerWidth - buttonRect.right
|
||||
const spaceBottom = window.innerHeight - buttonRect.bottom
|
||||
|
||||
if (spaceRight < menuRect.width && buttonRect.left > menuRect.width) {
|
||||
this.menuTarget.style.left = 'auto'
|
||||
this.menuTarget.style.right = '0'
|
||||
} else {
|
||||
this.menuTarget.style.left = '0'
|
||||
this.menuTarget.style.right = 'auto'
|
||||
}
|
||||
|
||||
if (spaceBottom < menuRect.height && buttonRect.top > menuRect.height) {
|
||||
this.menuTarget.style.top = 'auto'
|
||||
this.menuTarget.style.bottom = '100%'
|
||||
} else {
|
||||
this.menuTarget.style.top = '100%'
|
||||
this.menuTarget.style.bottom = 'auto'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
/*
|
||||
* This is an example Stimulus controller!
|
||||
*
|
||||
* Any element with a data-controller="hello" attribute will cause
|
||||
* this controller to be executed. The name "hello" comes from the filename:
|
||||
* hello_controller.js -> "hello"
|
||||
*
|
||||
* Delete this file or adapt it for your use!
|
||||
*/
|
||||
export default class extends Controller {
|
||||
connect() {
|
||||
this.element.textContent = 'Hello Stimulus! Edit me in assets/controllers/hello_controller.js';
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["checkbox", "modal", "modalContent"]
|
||||
|
||||
toggleAllCheckboxes(event) {
|
||||
this.checkboxTargets.forEach(checkbox => {
|
||||
checkbox.checked = event.target.checked;
|
||||
});
|
||||
}
|
||||
|
||||
updateMangaInfo(event) {
|
||||
const select = event.target;
|
||||
const selectedOption = select.options[select.selectedIndex];
|
||||
const mangaInfo = JSON.parse(selectedOption.dataset.mangaInfo);
|
||||
}
|
||||
|
||||
showDetails(event) {
|
||||
const fileId = event.currentTarget.dataset.fileId;
|
||||
const select = document.querySelector(`select[name="manga_slug[${fileId}]"]`);
|
||||
const mangaInfo = JSON.parse(select.options[select.selectedIndex].dataset.mangaInfo);
|
||||
|
||||
this.modalContentTarget.innerHTML = `
|
||||
<h3 class="text-lg leading-6 font-medium text-gray-900">${mangaInfo.title}</h3>
|
||||
<div class="mt-2">
|
||||
<p><strong>Author:</strong> ${mangaInfo.author || 'N/A'}</p>
|
||||
<p><strong>Publication Year:</strong> ${mangaInfo.publicationYear || 'N/A'}</p>
|
||||
<p><strong>Genres:</strong> ${mangaInfo.genres ? mangaInfo.genres.join(', ') : 'N/A'}</p>
|
||||
<p><strong>Description:</strong> ${this.truncate(mangaInfo.description || 'N/A', 200)}</p>
|
||||
</div>
|
||||
`;
|
||||
|
||||
this.modalTarget.classList.remove('hidden');
|
||||
}
|
||||
|
||||
closeModal() {
|
||||
this.modalTarget.classList.add('hidden');
|
||||
}
|
||||
|
||||
confirmSelected(event) {
|
||||
const selectedFiles = this.checkboxTargets.filter(checkbox => checkbox.checked).map(checkbox => checkbox.value);
|
||||
if (selectedFiles.length === 0) {
|
||||
event.preventDefault();
|
||||
alert('Veuillez sélectionner au moins un fichier à importer.');
|
||||
}
|
||||
}
|
||||
|
||||
truncate(str, length) {
|
||||
return str.length > length ? str.substring(0, length) + '...' : str;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
// assets/controllers/loading_button_controller.js
|
||||
import {Controller} from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["text", "loader"];
|
||||
static values = {form: String};
|
||||
|
||||
startLoading(event) {
|
||||
event.preventDefault();
|
||||
this.textTarget.classList.add("hidden");
|
||||
this.loaderTarget.classList.remove("hidden");
|
||||
this.element.disabled = true;
|
||||
|
||||
if (this.hasFormValue) {
|
||||
const form = document.getElementById(this.formValue);
|
||||
if (form) {
|
||||
form.submit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// assets/controllers/menu_controller.js
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["sidebar"]
|
||||
|
||||
toggleMenu() {
|
||||
this.sidebarTarget.classList.toggle('-translate-x-full')
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import {Controller} from '@hotwired/stimulus';
|
||||
|
||||
/*
|
||||
* The following line makes this controller "lazy": it won't be downloaded until needed
|
||||
* See https://github.com/symfony/stimulus-bridge#lazy-controllers
|
||||
*/
|
||||
/* stimulusFetch: 'lazy' */
|
||||
export default class extends Controller {
|
||||
// ...
|
||||
connect() {
|
||||
const topic = this.data.get('topic');
|
||||
const mercureHubUrl = 'https://mangarr.test.nestor-server.fr/.well-known/mercure';
|
||||
const eventSource = new EventSource(`${mercureHubUrl}?topic=${topic}`, {withCredentials: true});
|
||||
|
||||
eventSource.onmessage = (event) => {
|
||||
const data = JSON.parse(event.data);
|
||||
console.log('Received Mercure update:', data);
|
||||
|
||||
this.dispatchAlert(data.message, data.status);
|
||||
};
|
||||
|
||||
eventSource.onerror = (event) => {
|
||||
console.error('EventSource failed:', event);
|
||||
};
|
||||
}
|
||||
|
||||
dispatchAlert(message, level) {
|
||||
const event = new CustomEvent('alert:show', {
|
||||
detail: { message: message, level: level }
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
// assets/controllers/modal_controller.js
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["modal"]
|
||||
static values = {
|
||||
openTrigger: String,
|
||||
closeTrigger: String
|
||||
}
|
||||
|
||||
connect() {
|
||||
if (this.hasOpenTriggerValue) {
|
||||
document.addEventListener(this.openTriggerValue, this.open.bind(this))
|
||||
}
|
||||
if (this.hasCloseTriggerValue) {
|
||||
document.addEventListener(this.closeTriggerValue, this.close.bind(this))
|
||||
}
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
if (this.hasOpenTriggerValue) {
|
||||
document.removeEventListener(this.openTriggerValue, this.open.bind(this))
|
||||
}
|
||||
if (this.hasCloseTriggerValue) {
|
||||
document.removeEventListener(this.closeTriggerValue, this.close.bind(this))
|
||||
}
|
||||
}
|
||||
|
||||
open() {
|
||||
console.log("Opening modal...")
|
||||
this.modalTarget.classList.remove('hidden')
|
||||
}
|
||||
|
||||
close() {
|
||||
this.modalTarget.classList.add('hidden')
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
// assets/controllers/preferred-sources_controller.js
|
||||
|
||||
import {Controller} from "@hotwired/stimulus"
|
||||
import Sortable from 'sortablejs'
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["preferredList", "availableList"]
|
||||
static values = {
|
||||
mangaId: Number,
|
||||
preferredSources: Array,
|
||||
allSources: Array
|
||||
}
|
||||
|
||||
connect() {
|
||||
this.initSortable()
|
||||
}
|
||||
|
||||
initSortable() {
|
||||
new Sortable(this.preferredListTarget, {
|
||||
animation: 150,
|
||||
ghostClass: 'bg-gray-300',
|
||||
onEnd: this.handleDragEnd.bind(this)
|
||||
})
|
||||
}
|
||||
|
||||
handleDragEnd() {
|
||||
this.updatePreferredSources()
|
||||
}
|
||||
|
||||
addSource(event) {
|
||||
const sourceId = parseInt(event.currentTarget.dataset.sourceId)
|
||||
if (!this.preferredSourcesValue.includes(sourceId)) {
|
||||
this.preferredSourcesValue = [...this.preferredSourcesValue, sourceId]
|
||||
this.updateLists()
|
||||
this.save()
|
||||
}
|
||||
}
|
||||
|
||||
removeSource(event) {
|
||||
const sourceId = parseInt(event.currentTarget.dataset.sourceId)
|
||||
this.preferredSourcesValue = this.preferredSourcesValue.filter(id => id !== sourceId)
|
||||
this.updateLists()
|
||||
this.save()
|
||||
}
|
||||
|
||||
updatePreferredSources() {
|
||||
this.preferredSourcesValue = Array.from(this.preferredListTarget.children).map(li => parseInt(li.dataset.id))
|
||||
this.save()
|
||||
}
|
||||
|
||||
updateLists() {
|
||||
this.preferredListTarget.innerHTML = this.preferredSourcesValue
|
||||
.map(id => this.allSourcesValue.find(s => s.id === id))
|
||||
.map(source => this.sourceTemplate(source, true))
|
||||
.join('')
|
||||
|
||||
this.availableListTarget.innerHTML = this.allSourcesValue
|
||||
.filter(source => !this.preferredSourcesValue.includes(source.id))
|
||||
.map(source => this.sourceTemplate(source, false))
|
||||
.join('')
|
||||
|
||||
this.initSortable()
|
||||
}
|
||||
|
||||
sourceTemplate(source, isPreferred) {
|
||||
return `
|
||||
<li data-id="${source.id}" draggable="true" class="flex items-center justify-between p-2 bg-gray-100 rounded ${isPreferred ? 'cursor-move' : ''}">
|
||||
<span>${source.name}</span>
|
||||
<button type="button" data-action="preferred-sources#${isPreferred ? 'removeSource' : 'addSource'}" data-source-id="${source.id}" class="text-${isPreferred ? 'red' : 'green'}-500 hover:text-${isPreferred ? 'red' : 'green'}-700">
|
||||
<i class="fas fa-${isPreferred ? 'times' : 'plus'}"></i>
|
||||
</button>
|
||||
</li>
|
||||
`
|
||||
}
|
||||
|
||||
async save() {
|
||||
try {
|
||||
const response = await fetch(`/manga/${this.mangaIdValue}/preferred-sources`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
preferredSources: this.preferredSourcesValue
|
||||
})
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
console.log('Preferred sources saved successfully')
|
||||
// Optionally show a success message
|
||||
} else {
|
||||
console.error('Error saving preferred sources')
|
||||
// Optionally show an error message
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
// Optionally show an error message
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ['pageContainer', 'currentPage', 'chapterSelect', 'readingModeButton']
|
||||
static values = {
|
||||
mangaSlug: String,
|
||||
chapterNumber: Number,
|
||||
totalPages: Number,
|
||||
currentPage: { type: Number, default: 1 },
|
||||
readingMode: { type: String, default: 'horizontal' }
|
||||
}
|
||||
|
||||
connect() {
|
||||
this.loadChapters();
|
||||
this.loadPages();
|
||||
}
|
||||
|
||||
async loadChapters() {
|
||||
try {
|
||||
const response = await fetch(`/api/chapters/${this.mangaSlugValue}`);
|
||||
const chapters = await response.json();
|
||||
|
||||
this.chapterSelectTarget.innerHTML = chapters.map(chapter =>
|
||||
`<option value="${chapter.number}" ${chapter.number === this.chapterNumberValue ? 'selected' : ''}>
|
||||
Chapitre ${chapter.number}
|
||||
</option>`
|
||||
).join('');
|
||||
} catch (error) {
|
||||
console.error('Error loading chapters:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async loadPages() {
|
||||
this.pageContainerTarget.innerHTML = '';
|
||||
if (this.readingModeValue === 'horizontal') {
|
||||
await this.loadPage(this.currentPageValue);
|
||||
} else {
|
||||
for (let i = 1; i <= this.totalPagesValue; i++) {
|
||||
await this.loadPage(i, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async loadPage(pageNumber, isVertical = false) {
|
||||
const response = await fetch(`/api/read/${this.mangaSlugValue}/${this.chapterNumberValue}/${pageNumber}`);
|
||||
const pageContent = await response.text();
|
||||
|
||||
const img = document.createElement('img');
|
||||
img.src = `data:image/jpeg;base64,${pageContent}`;
|
||||
img.alt = `Page ${pageNumber}`;
|
||||
img.classList.add('shadow-lg', 'w-full', 'h-auto');
|
||||
|
||||
if (this.readingModeValue === 'horizontal') {
|
||||
img.classList.add('cursor-pointer');
|
||||
img.dataset.action = 'click->reader#pageClick';
|
||||
this.pageContainerTarget.innerHTML = '';
|
||||
}
|
||||
|
||||
if (isVertical) {
|
||||
img.loading = 'lazy';
|
||||
img.classList.add('mb-4');
|
||||
}
|
||||
|
||||
this.pageContainerTarget.appendChild(img);
|
||||
|
||||
if (!isVertical) {
|
||||
this.currentPageTarget.textContent = pageNumber;
|
||||
this.currentPageValue = pageNumber;
|
||||
}
|
||||
}
|
||||
|
||||
pageClick(event) {
|
||||
if (this.readingModeValue === 'horizontal') {
|
||||
const pageWidth = event.target.offsetWidth;
|
||||
const clickX = event.offsetX;
|
||||
|
||||
if (clickX < pageWidth / 2) {
|
||||
this.previousPage();
|
||||
} else {
|
||||
this.nextPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
previousPage() {
|
||||
if (this.currentPageValue > 1) {
|
||||
this.loadPage(this.currentPageValue - 1);
|
||||
} else {
|
||||
this.previousChapter();
|
||||
}
|
||||
}
|
||||
|
||||
nextPage() {
|
||||
if (this.currentPageValue < this.totalPagesValue) {
|
||||
this.loadPage(this.currentPageValue + 1);
|
||||
} else {
|
||||
this.nextChapter();
|
||||
}
|
||||
}
|
||||
|
||||
async previousChapter() {
|
||||
const response = await fetch(`/api/previous-chapter/${this.mangaSlugValue}/${this.chapterNumberValue}`);
|
||||
const previousChapter = await response.json();
|
||||
if (previousChapter) {
|
||||
window.location.href = `/read/${this.mangaSlugValue}/${previousChapter.number}`;
|
||||
}
|
||||
}
|
||||
|
||||
async nextChapter() {
|
||||
const response = await fetch(`/api/next-chapter/${this.mangaSlugValue}/${this.chapterNumberValue}`);
|
||||
const nextChapter = await response.json();
|
||||
if (nextChapter) {
|
||||
window.location.href = `/read/${this.mangaSlugValue}/${nextChapter.number}`;
|
||||
}
|
||||
}
|
||||
|
||||
changeChapter(event) {
|
||||
const selectedChapterNumber = event.target.value;
|
||||
window.location.href = `/read/${this.mangaSlugValue}/${selectedChapterNumber}`;
|
||||
}
|
||||
|
||||
toggleReadingMode() {
|
||||
this.readingModeValue = this.readingModeValue === 'horizontal' ? 'vertical' : 'horizontal';
|
||||
this.readingModeButtonTarget.textContent = this.readingModeValue === 'horizontal' ? 'Passer en mode vertical' : 'Passer en mode horizontal';
|
||||
this.loadPages();
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ['form', 'testForm', 'imageSelector', 'nextPageSelector', 'testResults', 'scrapingType']
|
||||
|
||||
connect() {
|
||||
}
|
||||
|
||||
async saveConfiguration(event) {
|
||||
event.preventDefault();
|
||||
this.formTarget.submit();
|
||||
}
|
||||
|
||||
async testConfiguration(event) {
|
||||
event.preventDefault();
|
||||
const formData = new FormData(this.formTarget);
|
||||
const testFormData = new FormData(this.testFormTarget);
|
||||
|
||||
for (let [key, value] of formData.entries()) {
|
||||
const cleanKey = key.replace(/^content_source\[(.+)]$/, '$1');
|
||||
testFormData.append(`content_source[${cleanKey}]`, value);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(this.testFormTarget.action, {
|
||||
method: 'POST',
|
||||
body: testFormData
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
this.displayTestResults(result.data);
|
||||
} else {
|
||||
this.displayError(result.message, result.errors);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
this.displayError('An error occurred while testing the configuration');
|
||||
}
|
||||
}
|
||||
|
||||
displayTestResults(data) {
|
||||
let html = '<h3 class="text-xl font-semibold mb-4">Test Results</h3>';
|
||||
html += '<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">';
|
||||
data.forEach(page => {
|
||||
html += `
|
||||
<div class="border rounded-lg p-2 flex flex-col items-center">
|
||||
<img src="${page.image_url}" alt="Page ${page.page_number}" class="w-full h-48 object-cover mb-2">
|
||||
<p class="text-sm font-medium">Page ${page.page_number}</p>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
html += '</div>';
|
||||
this.testResultsTarget.innerHTML = html;
|
||||
}
|
||||
|
||||
displayError(message, errors = []) {
|
||||
let errorHtml = `
|
||||
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
|
||||
<strong class="font-bold">Error:</strong>
|
||||
<span class="block sm:inline">${message}</span>
|
||||
`;
|
||||
|
||||
if (errors.length > 0) {
|
||||
errorHtml += '<ul class="list-disc list-inside mt-2">';
|
||||
errors.forEach(error => {
|
||||
errorHtml += `<li>${error}</li>`;
|
||||
});
|
||||
errorHtml += '</ul>';
|
||||
}
|
||||
|
||||
errorHtml += '</div>';
|
||||
this.testResultsTarget.innerHTML = errorHtml;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
/*
|
||||
* The following line makes this controller "lazy": it won't be downloaded until needed
|
||||
* See https://github.com/symfony/stimulus-bridge#lazy-controllers
|
||||
*/
|
||||
/* stimulusFetch: 'lazy' */
|
||||
export default class extends Controller {
|
||||
// ...
|
||||
static targets = ["textarea", "submitButton"]
|
||||
|
||||
connect() {
|
||||
document.addEventListener('openImportModal', this.prepareImportModal.bind(this));
|
||||
document.addEventListener('openExportModal', this.prepareExportModal.bind(this));
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
document.removeEventListener('openImportModal', this.prepareImportModal.bind(this));
|
||||
document.removeEventListener('openExportModal', this.prepareExportModal.bind(this));
|
||||
}
|
||||
|
||||
async prepareExportModal() {
|
||||
try {
|
||||
const response = await fetch('/settings/export_scrappers');
|
||||
const data = await response.json();
|
||||
this.textareaTarget.value = JSON.stringify(data, null, 2);
|
||||
this.submitButtonTarget.textContent = 'Copy to Clipboard';
|
||||
this.submitButtonTarget.dataset.action = 'scrapper-import#copyToClipboard';
|
||||
this.openModal('Export Scrapper Configurations');
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
}
|
||||
|
||||
prepareImportModal() {
|
||||
this.textareaTarget.value = '';
|
||||
this.submitButtonTarget.textContent = 'Import';
|
||||
this.submitButtonTarget.dataset.action = 'scrapper-import#submitImport';
|
||||
this.openModal('Import Scrapper Configurations');
|
||||
}
|
||||
|
||||
openModal(title) {
|
||||
const event = new CustomEvent('openScrapperModal', { detail: { title: title } });
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
|
||||
async submitImport() {
|
||||
const jsonData = this.textareaTarget.value;
|
||||
|
||||
try {
|
||||
const response = await fetch('/settings/import_scrappers', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: jsonData
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
console.log(result.message);
|
||||
document.dispatchEvent(new CustomEvent('closeScrapperModal'));
|
||||
window.location.reload();
|
||||
} else {
|
||||
console.error(result.error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
}
|
||||
}
|
||||
|
||||
copyToClipboard() {
|
||||
navigator.clipboard.writeText(this.textareaTarget.value).then(() => {
|
||||
console.log('Copied to clipboard');
|
||||
document.dispatchEvent(new CustomEvent('closeScrapperModal'));
|
||||
}, (err) => {
|
||||
console.error('Could not copy text: ', err);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { Controller } from '@hotwired/stimulus';
|
||||
|
||||
/*
|
||||
* The following line makes this controller "lazy": it won't be downloaded until needed
|
||||
* See https://github.com/symfony/stimulus-bridge#lazy-controllers
|
||||
*/
|
||||
/* stimulusFetch: 'lazy' */
|
||||
export default class extends Controller {
|
||||
static targets = ['input']
|
||||
|
||||
clearSearch() {
|
||||
this.inputTarget.value = '';
|
||||
this.inputTarget.focus();
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
import {Controller} from '@hotwired/stimulus';
|
||||
|
||||
/*
|
||||
* The following line makes this controller "lazy": it won't be downloaded until needed
|
||||
* See https://github.com/symfony/stimulus-bridge#lazy-controllers
|
||||
*/
|
||||
/* stimulusFetch: 'lazy' */
|
||||
export default class extends Controller {
|
||||
static targets = ["body", "toggleIcon"]
|
||||
static values = { open: Boolean }
|
||||
|
||||
connect() {
|
||||
if (!this.openValue) {
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if (this.bodyTarget.style.display === "none") {
|
||||
this.open()
|
||||
} else {
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
|
||||
open() {
|
||||
this.bodyTarget.style.display = "block"
|
||||
this.toggleIconTarget.classList.replace("fa-chevron-down", "fa-chevron-up")
|
||||
}
|
||||
|
||||
close() {
|
||||
this.bodyTarget.style.display = "none"
|
||||
this.toggleIconTarget.classList.replace("fa-chevron-up", "fa-chevron-down")
|
||||
}
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
// assets/controllers/toolbar_controller.js
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
import { visit } from "@hotwired/turbo"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["dropdown", "icon", "text"]
|
||||
static values = {
|
||||
currentSort: String,
|
||||
currentOrder: String,
|
||||
currentStatus: String,
|
||||
mangaId: Number
|
||||
}
|
||||
|
||||
connect() {
|
||||
window.addEventListener('alert:show', this.stopLoading.bind(this));
|
||||
}
|
||||
|
||||
stopLoading(event) {
|
||||
if(event.currentTarget.dataset !== undefined){
|
||||
this.iconTarget.classList.remove('fa-spin');
|
||||
}
|
||||
}
|
||||
|
||||
refreshMetadata(event) {
|
||||
const mangaId = event.currentTarget.dataset.mangaid;
|
||||
const url = `/refresh_metadata`;
|
||||
|
||||
this.iconTarget.classList.add('fa-spin');
|
||||
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ mangaId: mangaId })
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.json();
|
||||
});
|
||||
}
|
||||
|
||||
searchLastChapter() {
|
||||
console.log("Searching last chapter...");
|
||||
}
|
||||
|
||||
import() {
|
||||
console.log("Importing...");
|
||||
}
|
||||
|
||||
monitoring(event){
|
||||
const mangaId = event.currentTarget.dataset.mangaid;
|
||||
const currentTarget = event.currentTarget;
|
||||
|
||||
const url = `/toggle_monitored`;
|
||||
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ mangaId: mangaId })
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.json();
|
||||
}).then(data => {
|
||||
if(data.isMonitored === true){
|
||||
currentTarget.classList.remove('text-white');
|
||||
currentTarget.classList.add('text-green-500');
|
||||
this.textTarget.innerHTML = "Monitored";
|
||||
}else if(data.isMonitored === false){
|
||||
currentTarget.classList.remove('text-green-500');
|
||||
currentTarget.classList.add('text-white');
|
||||
this.textTarget.innerHTML = "Monitoring";
|
||||
}
|
||||
// console.log(data.isMonitored);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
editMangas() {
|
||||
console.log("Editing mangas...");
|
||||
}
|
||||
|
||||
editManga() {
|
||||
const event = new CustomEvent('openEditModal');
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
|
||||
editPreferredSources() {
|
||||
const event = new CustomEvent('openPreferredSourcesModal');
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
|
||||
openImportModal() {
|
||||
const importEvent = new CustomEvent('openImportModal');
|
||||
document.dispatchEvent(importEvent);
|
||||
}
|
||||
|
||||
openExportModal() {
|
||||
const exportEvent = new CustomEvent('openExportModal');
|
||||
document.dispatchEvent(exportEvent);
|
||||
}
|
||||
|
||||
deleteMangas() {
|
||||
console.log("Deleting mangas...");
|
||||
}
|
||||
|
||||
deleteManga() {
|
||||
const event = new CustomEvent('openDeleteModal');
|
||||
document.dispatchEvent(event);
|
||||
}
|
||||
|
||||
confirmDelete(event) {
|
||||
event.preventDefault();
|
||||
const url = `/manga/delete/${this.mangaIdValue}`;
|
||||
|
||||
fetch(url, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
visit('/', {});
|
||||
} else {
|
||||
throw new Error(data.error);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
// Show error message to user
|
||||
});
|
||||
}
|
||||
|
||||
showOptions() {
|
||||
console.log("Showing options...");
|
||||
}
|
||||
|
||||
expandAll() {
|
||||
console.log("Expanding all...");
|
||||
}
|
||||
|
||||
changeView(event) {
|
||||
event.preventDefault();
|
||||
const viewOption = event.currentTarget.dataset.view;
|
||||
|
||||
const url = new URL(window.location);
|
||||
url.searchParams.set('view', viewOption);
|
||||
|
||||
window.location = url.toString();
|
||||
}
|
||||
|
||||
sort(event) {
|
||||
event.preventDefault()
|
||||
const sortOption = event.currentTarget.dataset.sort;
|
||||
let order = 'asc';
|
||||
|
||||
if (sortOption === this.currentSortValue && this.currentOrderValue === 'asc') {
|
||||
order = 'desc';
|
||||
}
|
||||
|
||||
const url = new URL(window.location);
|
||||
url.searchParams.set('sort', sortOption);
|
||||
url.searchParams.set('order', order);
|
||||
|
||||
window.location = url.toString();
|
||||
}
|
||||
|
||||
filter(event) {
|
||||
event.preventDefault();
|
||||
const filterOption = event.currentTarget.dataset.filter;
|
||||
|
||||
const url = new URL(window.location);
|
||||
url.searchParams.set('status', filterOption);
|
||||
|
||||
// Réinitialiser la page à 1 si on utilise la pagination
|
||||
// url.searchParams.set('page', '1');
|
||||
|
||||
window.location = url.toString();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user