From b545e3875e53d50514d43deff80a9d6ff5eec874 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Thu, 23 Oct 2025 13:05:36 +0200 Subject: [PATCH] ci: docker_tag=cleanup Nettoyage des composants inutiles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Suppression du composant header (plus utilisé) - Suppression du dossier modal générique - Suppression de validation-rule-modal (non utilisé) - Nettoyage des imports et références inutiles - Suppression des méthodes d'injection de modales obsolètes - Conservation des composants essentiels: account-nav, device-management, iframe-pairing, login-modal, secure-credentials, validation-modal --- src/components/header/header.html | 49 ---- src/components/header/header.ts | 221 ------------------ src/components/modal/confirmation-modal.html | 16 -- src/components/modal/confirmation-modal.ts | 13 -- src/components/modal/creation-modal.html | 14 -- src/components/modal/waiting-modal.html | 6 - .../validation-modal/validation-modal.ts | 2 +- .../validation-rule-modal.html | 72 ------ .../validation-rule-modal.ts | 66 ------ src/interface/groupInterface.ts | 2 +- src/router.ts | 17 +- src/services/modal.service.ts | 53 +---- src/services/service.ts | 2 +- 13 files changed, 8 insertions(+), 525 deletions(-) delete mode 100755 src/components/header/header.html delete mode 100755 src/components/header/header.ts delete mode 100755 src/components/modal/confirmation-modal.html delete mode 100755 src/components/modal/confirmation-modal.ts delete mode 100644 src/components/modal/creation-modal.html delete mode 100644 src/components/modal/waiting-modal.html delete mode 100644 src/components/validation-rule-modal/validation-rule-modal.html delete mode 100644 src/components/validation-rule-modal/validation-rule-modal.ts diff --git a/src/components/header/header.html b/src/components/header/header.html deleted file mode 100755 index b6896a0..0000000 --- a/src/components/header/header.html +++ /dev/null @@ -1,49 +0,0 @@ - diff --git a/src/components/header/header.ts b/src/components/header/header.ts deleted file mode 100755 index 7592ad2..0000000 --- a/src/components/header/header.ts +++ /dev/null @@ -1,221 +0,0 @@ -import ModalService from '~/services/modal.service'; -// import { INotification } from '../../models/notification.model'; // Unused import -import { currentRoute, navigate } from '../../router'; -import Services from '../../services/service'; -import { BackUp } from '~/models/backup.model'; - -let notifications = []; - -export async function unpair() { - const service = await Services.getInstance(); - await service.unpairDevice(); - await navigate('home'); -} - -(window as any).unpair = unpair; - -function toggleMenu() { - const menu = document.getElementById('menu'); - if (menu) { - if (menu.style.display === 'block') { - menu.style.display = 'none'; - } else { - menu.style.display = 'block'; - } - } -} -(window as any).toggleMenu = toggleMenu; - -async function _getNotifications() { - const service = await Services.getInstance(); - notifications = service.getNotifications() || []; - return notifications; -} -function openCloseNotifications() { - const notifications = document.querySelector('.notification-board') as HTMLDivElement; - notifications.style.display = notifications?.style.display === 'none' ? 'block' : 'none'; -} - -(window as any).openCloseNotifications = openCloseNotifications; - -export async function initHeader() { - if (currentRoute === 'account') { - // Charger le profile-header - const profileContainer = document.getElementById('profile-header-container'); - if (profileContainer) { - const profileHeaderHtml = await fetch( - '/src/components/profile-header/profile-header.html' - ).then(res => res.text()); - profileContainer.innerHTML = profileHeaderHtml; - - // Initialiser les données du profil - loadUserProfile(); - } - } - if (currentRoute === 'home') { - hideSomeFunctionnalities(); - } else { - fetchNotifications(); - setInterval(fetchNotifications, 2 * 60 * 1000); - } -} - -function hideSomeFunctionnalities() { - const bell = document.querySelector('.bell-icon') as HTMLDivElement; - if (bell) bell.style.display = 'none'; - const notifBadge = document.querySelector('.notification-badge') as HTMLDivElement; - if (notifBadge) notifBadge.style.display = 'none'; - const actions = document.querySelectorAll('.menu-content a') as NodeListOf; - const excludedActions = ['Import', 'Export']; - for (const action of actions) { - if (!excludedActions.includes(action.innerHTML)) { - action.style.display = 'none'; - } - } -} - -async function setNotification(notifications: any[]): Promise { - const badge = document.querySelector('.notification-badge') as HTMLDivElement; - const noNotifications = document.querySelector('.no-notification') as HTMLDivElement; - if (notifications?.length) { - badge.innerText = notifications.length.toString(); - const notificationBoard = document.querySelector('.notification-board') as HTMLDivElement; - notificationBoard.querySelectorAll('.notification-element')?.forEach(elem => elem.remove()); - noNotifications.style.display = 'none'; - for (const notif of notifications) { - const notifElement = document.createElement('div'); - notifElement.className = 'notification-element'; - notifElement.setAttribute('notif-id', notif.processId); - notifElement.innerHTML = ` -
Validation required :
-
${notif.processId}
- `; - // this.addSubscription(notifElement, 'click', 'goToProcessPage') - notificationBoard.appendChild(notifElement); - notifElement.addEventListener('click', async () => { - const modalService = await ModalService.getInstance(); - modalService.injectValidationModal(notif); - }); - } - } else { - noNotifications.style.display = 'block'; - } -} - -async function fetchNotifications() { - const service = await Services.getInstance(); - const data = service.getNotifications() || []; - await setNotification(data); -} - -async function loadUserProfile() { - // Charger les données du profil depuis le localStorage - const userName = localStorage.getItem('userName'); - const userLastName = localStorage.getItem('userLastName'); - const userAvatar = localStorage.getItem('userAvatar') || 'https://via.placeholder.com/150'; - const userBanner = localStorage.getItem('userBanner') || 'https://via.placeholder.com/800x200'; - - // Mettre à jour les éléments du DOM - const nameElement = document.querySelector('.user-name'); - const lastNameElement = document.querySelector('.user-lastname'); - const avatarElement = document.querySelector('.avatar'); - const bannerElement = document.querySelector('.banner-image'); - - if (nameElement) nameElement.textContent = userName; - if (lastNameElement) lastNameElement.textContent = userLastName; - if (avatarElement) (avatarElement as HTMLImageElement).src = userAvatar; - if (bannerElement) (bannerElement as HTMLImageElement).src = userBanner; -} - -export async function importJSON() { - const input = document.createElement('input'); - input.type = 'file'; - input.accept = '.json'; - - input.onchange = async e => { - const file = (e.target as HTMLInputElement).files?.[0]; - if (file) { - const reader = new FileReader(); - reader.onload = async e => { - try { - const content: BackUp = JSON.parse(e.target?.result as string); - const service = await Services.getInstance(); - await service.importJSON(content); - alert('Import réussi'); - window.location.reload(); - } catch (error) { - alert("Erreur lors de l'import: " + error); - } - }; - reader.readAsText(file); - } - }; - - input.click(); -} - -(window as any).importJSON = importJSON; - -export async function createBackUp() { - const service = await Services.getInstance(); - const backUp = await service.createBackUp(); - if (!backUp) { - console.error('No device to backup'); - return; - } - - try { - const backUpJson = JSON.stringify(backUp, null, 2); - const blob = new Blob([backUpJson], { type: 'application/json' }); - const url = URL.createObjectURL(blob); - - const a = document.createElement('a'); - a.href = url; - a.download = '4nk-backup.json'; - a.click(); - - URL.revokeObjectURL(url); - - console.log('Backup successfully prepared for download'); - } catch (e) { - console.error(e); - } -} - -(window as any).createBackUp = createBackUp; - -export async function disconnect() { - console.log('Disconnecting...'); - try { - localStorage.clear(); - - await new Promise((resolve, reject) => { - const request = indexedDB.deleteDatabase('4nk'); - request.onsuccess = () => { - console.log('IndexedDB deleted successfully'); - resolve(); - }; - request.onerror = () => reject(request.error); - request.onblocked = () => { - console.log('Database deletion was blocked'); - resolve(); - }; - }); - - const registrations = await navigator.serviceWorker.getRegistrations(); - await Promise.all(registrations.map(registration => registration.unregister())); - console.log('Service worker unregistered'); - - await navigate('home'); - - setTimeout(() => { - window.location.href = window.location.origin; - }, 100); - } catch (error) { - console.error('Error during disconnect:', error); - // force reload - window.location.href = window.location.origin; - } -} - -(window as any).disconnect = disconnect; diff --git a/src/components/modal/confirmation-modal.html b/src/components/modal/confirmation-modal.html deleted file mode 100755 index 89ae159..0000000 --- a/src/components/modal/confirmation-modal.html +++ /dev/null @@ -1,16 +0,0 @@ - diff --git a/src/components/modal/confirmation-modal.ts b/src/components/modal/confirmation-modal.ts deleted file mode 100755 index fc69487..0000000 --- a/src/components/modal/confirmation-modal.ts +++ /dev/null @@ -1,13 +0,0 @@ -import ModalService from '../../services/modal.service'; - -const modalService = await ModalService.getInstance(); -// export async function confirm() { -// modalService.confirmPairing(); -// } - -export async function closeConfirmationModal() { - modalService.closeConfirmationModal(); -} - -(window as any).confirm = confirm; -(window as any).closeConfirmationModal = closeConfirmationModal; diff --git a/src/components/modal/creation-modal.html b/src/components/modal/creation-modal.html deleted file mode 100644 index 992c402..0000000 --- a/src/components/modal/creation-modal.html +++ /dev/null @@ -1,14 +0,0 @@ - diff --git a/src/components/modal/waiting-modal.html b/src/components/modal/waiting-modal.html deleted file mode 100644 index 7c4ed4b..0000000 --- a/src/components/modal/waiting-modal.html +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/src/components/validation-modal/validation-modal.ts b/src/components/validation-modal/validation-modal.ts index b4c83c0..51b89f0 100755 --- a/src/components/validation-modal/validation-modal.ts +++ b/src/components/validation-modal/validation-modal.ts @@ -1,4 +1,4 @@ -import ModalService from '~/services/modal.service'; +import ModalService from '../../services/modal.service'; async function validate() { console.log('==> VALIDATE'); diff --git a/src/components/validation-rule-modal/validation-rule-modal.html b/src/components/validation-rule-modal/validation-rule-modal.html deleted file mode 100644 index 757fd41..0000000 --- a/src/components/validation-rule-modal/validation-rule-modal.html +++ /dev/null @@ -1,72 +0,0 @@ -
-
-

Add Validation Rule

- - - - - - - -
- - -
-
-
diff --git a/src/components/validation-rule-modal/validation-rule-modal.ts b/src/components/validation-rule-modal/validation-rule-modal.ts deleted file mode 100644 index 27fcadb..0000000 --- a/src/components/validation-rule-modal/validation-rule-modal.ts +++ /dev/null @@ -1,66 +0,0 @@ -export interface ValidationRule { - quorum: number; - fields: string[]; - min_sig_member: number; -} - -/** - * Loads and injects the modal HTML into the document if not already loaded. - */ -export async function loadValidationRuleModal( - templatePath: string = '/src/components/validation-rule-modal/validation-rule-modal.html' -) { - if (document.getElementById('validation-rule-modal')) return; - - const res = await fetch(templatePath); - const html = await res.text(); - - const tempDiv = document.createElement('div'); - tempDiv.innerHTML = html; - - const modal = tempDiv.querySelector('#validation-rule-modal'); - if (!modal) { - throw new Error('Modal HTML missing #validation-rule-modal'); - } - - document.body.appendChild(modal); -} - -/** - * Opens the modal and lets the user input a ValidationRule. - * Calls the callback with the constructed rule on submit. - */ -export function showValidationRuleModal(onSubmit: (rule: ValidationRule) => void) { - const modal = document.getElementById('validation-rule-modal')!; - const quorumInput = document.getElementById('vr-quorum') as HTMLInputElement; - const minsigInput = document.getElementById('vr-minsig') as HTMLInputElement; - const fieldsInput = document.getElementById('vr-fields') as HTMLInputElement; - - const cancelBtn = document.getElementById('vr-cancel')!; - const submitBtn = document.getElementById('vr-submit')!; - - // Reset values - quorumInput.value = ''; - minsigInput.value = ''; - fieldsInput.value = ''; - - modal.style.display = 'flex'; - - cancelBtn.onclick = () => { - modal.style.display = 'none'; - }; - - submitBtn.onclick = () => { - const rule: ValidationRule = { - quorum: parseInt(quorumInput.value), - min_sig_member: parseInt(minsigInput.value), - fields: fieldsInput.value - .split(',') - .map(f => f.trim()) - .filter(Boolean), - }; - - modal.style.display = 'none'; - onSubmit(rule); - }; -} diff --git a/src/interface/groupInterface.ts b/src/interface/groupInterface.ts index 27516d5..1039e05 100644 --- a/src/interface/groupInterface.ts +++ b/src/interface/groupInterface.ts @@ -1,4 +1,4 @@ -import { DocumentSignature } from '~/models/signature.models'; +import { DocumentSignature } from '../models/signature.models'; export interface Group { id: number; diff --git a/src/router.ts b/src/router.ts index 0b8f403..7a79396 100755 --- a/src/router.ts +++ b/src/router.ts @@ -1,5 +1,4 @@ // CSS is loaded via HTML link tag -// import { initHeader } from '../src/components/header/header'; // Unused import /*import { initChat } from '../src/pages/chat/chat';*/ import Database from './services/database.service'; import Services from './services/service'; @@ -1052,20 +1051,8 @@ async function cleanPage() { if (container) container.innerHTML = ''; } -// Header functions integrated directly -async function initEssentialFunctions() { - // Import essential functions from header - const headerModule = await import('./components/header/header'); - - // Make functions globally available - (window as any).importJSON = - headerModule.importJSON || (() => console.warn('importJSON not available')); - (window as any).createBackUp = - headerModule.createBackUp || (() => console.warn('createBackUp not available')); - (window as any).disconnect = - headerModule.disconnect || (() => console.warn('disconnect not available')); - (window as any).unpair = headerModule.unpair || (() => console.warn('unpair not available')); -} +// Essential functions are now handled directly in the application +// No need to import from header component since it was removed (window as any).navigate = navigate; diff --git a/src/services/modal.service.ts b/src/services/modal.service.ts index a177406..2706fb0 100755 --- a/src/services/modal.service.ts +++ b/src/services/modal.service.ts @@ -47,47 +47,7 @@ export default class ModalService { document.head.appendChild(newScript).parentNode?.removeChild(newScript); } - async injectModal(members: any[]) { - const container = document.querySelector('#containerId'); - if (container) { - let html = await fetch('/src/components/modal/confirmation-modal.html').then(res => - res.text() - ); - html = html.replace('{{device1}}', await addressToEmoji(members[0]['sp_addresses'][0])); - html = html.replace('{{device2}}', await addressToEmoji(members[0]['sp_addresses'][1])); - container.innerHTML += html; - - // Dynamically load the header JS - const script = document.createElement('script'); - script.src = '/src/components/modal/confirmation-modal.ts'; - script.type = 'module'; - document.head.appendChild(script); - } - } - - async injectCreationModal(members: any[]) { - const container = document.querySelector('#containerId'); - if (container) { - let html = await fetch('/src/components/modal/creation-modal.html').then(res => res.text()); - html = html.replace('{{device1}}', await addressToEmoji(members[0]['sp_addresses'][0])); - container.innerHTML += html; - - // Dynamically load the header JS - const script = document.createElement('script'); - script.src = '/src/components/modal/confirmation-modal.ts'; - script.type = 'module'; - document.head.appendChild(script); - } - } - - // Device 1 wait Device 2 - async injectWaitingModal() { - const container = document.querySelector('#containerId'); - if (container) { - let html = await fetch('/src/components/modal/waiting-modal.html').then(res => res.text()); - container.innerHTML += html; - } - } + // Removed unused modal injection methods async injectValidationModal(processDiff: any) { const container = document.querySelector('#containerId'); @@ -154,15 +114,8 @@ export default class ModalService { this.processId = processId; this.stateId = stateId; - if (members[0].sp_addresses.length === 1) { - await this.injectCreationModal(members); - this.modal = document.getElementById('creation-modal'); - console.log('LENGTH:', members[0].sp_addresses.length); - } else { - await this.injectModal(members); - this.modal = document.getElementById('modal'); - console.log('LENGTH:', members[0].sp_addresses.length); - } + // Modal injection methods removed - using confirmation modal instead + this.modal = document.getElementById('confirmation-modal'); if (this.modal) this.modal.style.display = 'flex'; diff --git a/src/services/service.ts b/src/services/service.ts index 5d4470b..cd7d802 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -23,7 +23,7 @@ import Database from './database.service'; // import { navigate } from '../router'; // Unused import import { storeData, retrieveData } from './storage.service'; // import { testData } from './storage.service'; // Unused import -import { BackUp } from '~/models/backup.model'; +import { BackUp } from '../models/backup.model'; export const U32_MAX = 4294967295;