diff --git a/src/main.ts b/src/main.ts index bbbb06a..14aaae1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,13 +2,16 @@ import { SignatureComponent } from './pages/signature/signature-component'; import { SignatureElement } from './pages/signature/signature'; import { ChatComponent } from './pages/chat/chat-component'; import { ChatElement } from './pages/chat/chat'; - +import { AccountComponent } from './pages/account/account-component'; +import { AccountElement } from './pages/account/account'; export { SignatureComponent, SignatureElement, ChatComponent, - ChatElement + ChatElement, + AccountComponent, + AccountElement }; @@ -18,6 +21,8 @@ declare global { 'signature-element': SignatureElement; 'chat-component': ChatComponent; 'chat-element': ChatElement; + 'account-component': AccountComponent; + 'account-element': AccountElement; } } @@ -28,4 +33,6 @@ if ((import.meta as any).env.VITE_IS_INDEPENDANT_LIB) { customElements.define('signature-element', SignatureElement); customElements.define('chat-component', ChatComponent); customElements.define('chat-element', ChatElement); -} + customElements.define('account-component', AccountComponent); + customElements.define('account-element', AccountElement); +} \ No newline at end of file diff --git a/src/mocks/mock-account/constAccountMock.ts b/src/mocks/mock-account/constAccountMock.ts new file mode 100644 index 0000000..5beb139 --- /dev/null +++ b/src/mocks/mock-account/constAccountMock.ts @@ -0,0 +1,328 @@ +export const ALLOWED_ROLES = ['User', 'Member', 'Peer', 'Payment', 'Deposit', 'Artefact', 'Resolve', 'Backup']; + +export const STORAGE_KEYS = { + pairing: 'pairingRows', + wallet: 'walletRows', + process: 'processRows', + data: 'dataRows' +}; + +// Initialiser le stockage des lignes par défaut dans le localStorage +export const defaultRows = [ + { + column1: "sprt1qqwtvg5q5vcz0reqvmld98u7va3av6gakwe9yxw9yhnpj5djcunn4squ68tuzn8dz78dg4adfv0dekx8hg9sy0t6s9k5em7rffgxmrsfpyy7gtyrz", + column2: "🎊😑🎄😩", + column3: "Laptop" + }, + { + column1: "sprt1qqwtvg5q5vcz0reqvmld98u7va3av6gakwe9yxw9yhnpj5djcunn4squ68tuzn8dz78dg4adfv0dekx8hg9sy0t6s9k5em7rffgxmrsfpyy7gtyrx", + column2: "🎏🎕😧🌥", + column3: "Phone" } +]; + +export const mockNotifications: { [key: string]: Notification[] } = {}; + +export const notificationMessages = [ + "CPU usage high", + "Memory threshold reached", + "New update available", + "Backup completed", + "Security check required", + "Performance optimization needed", + "System alert", + "Network connectivity issue", + "Storage space low", + "Process checkpoint reached" +]; + +export const mockDataRows = [ + { + column1: "User Project", + column2: "private", + column3: "User", + column4: "6 months", + column5: "NDA signed", + column6: "Contract #123", + processName: "User Process", + zone: "A" + }, + { + column1: "Process Project", + column2: "private", + column3: "Process", + column4: "1 year", + column5: "Terms accepted", + column6: "Contract #456", + processName: "Process Management", + zone: "B" + }, + { + column1: "Member Project", + column2: "private", + column3: "Member", + column4: "3 months", + column5: "GDPR compliant", + column6: "Contract #789", + processName: "Member Process", + zone: "C" + }, + { + column1: "Peer Project", + column2: "public", + column3: "Peer", + column4: "2 years", + column5: "IP rights", + column6: "Contract #101", + processName: "Peer Process", + zone: "D" + }, + { + column1: "Payment Project", + column2: "confidential", + column3: "Payment", + column4: "1 year", + column5: "NDA signed", + column6: "Contract #102", + processName: "Payment Process", + zone: "E" + }, + { + column1: "Deposit Project", + column2: "private", + column3: "Deposit", + column4: "6 months", + column5: "Terms accepted", + column6: "Contract #103", + processName: "Deposit Process", + zone: "F" + }, + { + column1: "Artefact Project", + column2: "public", + column3: "Artefact", + column4: "1 year", + column5: "GDPR compliant", + column6: "Contract #104", + processName: "Artefact Process", + zone: "G" + }, + { + column1: "Resolve Project", + column2: "private", + column3: "Resolve", + column4: "2 years", + column5: "IP rights", + column6: "Contract #105", + processName: "Resolve Process", + zone: "H" + }, + { + column1: "Backup Project", + column2: "public", + column3: "Backup", + column4: "1 year", + column5: "NDA signed", + column6: "Contract #106", + processName: "Backup Process", + zone: "I" + } +]; + +export const mockProcessRows = [ + { + process: "User Project", + role: "User", + notification: { + messages: [ + { id: 1, read: false, date: "2024-03-10", message: "New user joined the project" }, + { id: 2, read: false, date: "2024-03-09", message: "Project milestone reached" }, + { id: 3, read: false, date: "2024-03-08", message: "Security update required" }, + { id: 4, read: true, date: "2024-03-07", message: "Weekly report available" }, + { id: 5, read: true, date: "2024-03-06", message: "Team meeting scheduled" } + ] + } + }, + { + process: "Member Project", + role: "Member", + notification: { + messages: [ + { id: 6, read: true, date: "2024-03-10", message: "Member access granted" }, + { id: 7, read: true, date: "2024-03-09", message: "Documentation updated" }, + { id: 8, read: true, date: "2024-03-08", message: "Project status: on track" } + ] + } + }, + { + process: "Peer Project", + role: "Peer", + notification: { + unread: 2, + total: 4, + messages: [ + { id: 9, read: false, date: "2024-03-10", message: "New peer project added" }, + { id: 10, read: false, date: "2024-03-09", message: "Project milestone reached" }, + { id: 11, read: false, date: "2024-03-08", message: "Security update required" }, + { id: 12, read: true, date: "2024-03-07", message: "Weekly report available" }, + { id: 13, read: true, date: "2024-03-06", message: "Team meeting scheduled" } + ] + } + }, + { + process: "Deposit Project", + role: "Deposit", + notification: { + unread: 1, + total: 10, + messages: [ + { id: 14, read: false, date: "2024-03-10", message: "Deposit milestone reached" }, + { id: 15, read: false, date: "2024-03-09", message: "Security update required" }, + { id: 16, read: false, date: "2024-03-08", message: "Weekly report available" }, + { id: 17, read: true, date: "2024-03-07", message: "Team meeting scheduled" }, + { id: 18, read: true, date: "2024-03-06", message: "Project status: on track" } + ] + } + }, + { + process: "Artefact Project", + role: "Artefact", + notification: { + unread: 0, + total: 3, + messages: [ + { id: 19, read: false, date: "2024-03-10", message: "New artefact added" }, + { id: 20, read: false, date: "2024-03-09", message: "Security update required" }, + { id: 21, read: false, date: "2024-03-08", message: "Weekly report available" }, + { id: 22, read: true, date: "2024-03-07", message: "Team meeting scheduled" }, + { id: 23, read: true, date: "2024-03-06", message: "Project status: on track" } + ] + } + }, + { + process: "Resolve Project", + role: "Resolve", + notification: { + unread: 5, + total: 12, + messages: [ + { id: 24, read: false, date: "2024-03-10", message: "New issue reported" }, + { id: 25, read: false, date: "2024-03-09", message: "Security update required" }, + { id: 26, read: false, date: "2024-03-08", message: "Weekly report available" }, + { id: 27, read: true, date: "2024-03-07", message: "Team meeting scheduled" }, + { id: 28, read: true, date: "2024-03-06", message: "Project status: on track" } + ] + } + } +]; + + +export const mockContracts = { + 'Contract #123': { + title: "User Project Agreement", + date: "2024-01-15", + parties: ["Company XYZ", "User Team"], + terms: [ + "Data Protection", + "User Privacy", + "Access Rights", + "Service Level Agreement" + ], + content: "This agreement establishes the terms and conditions for user project management." + }, + 'Contract #456': { + title: "Process Management Contract", + date: "2024-02-01", + parties: ["Company XYZ", "Process Team"], + terms: [ + "Process Workflow", + "Quality Standards", + "Performance Metrics", + "Monitoring Procedures" + ], + content: "This contract defines the process management standards and procedures." + }, + 'Contract #789': { + title: "Member Access Agreement", + date: "2024-03-15", + parties: ["Company XYZ", "Member Team"], + terms: [ + "Member Rights", + "Access Levels", + "Security Protocol", + "Confidentiality Agreement" + ], + content: "This agreement outlines the terms for member access and privileges." + }, + 'Contract #101': { + title: "Peer Collaboration Agreement", + date: "2024-04-01", + parties: ["Company XYZ", "Peer Network"], + terms: [ + "Collaboration Rules", + "Resource Sharing", + "Dispute Resolution", + "Network Protocol" + ], + content: "This contract establishes peer collaboration and networking guidelines." + }, + 'Contract #102': { + title: "Payment Processing Agreement", + date: "2024-05-01", + parties: ["Company XYZ", "Payment Team"], + terms: [ + "Transaction Protocol", + "Security Measures", + "Fee Structure", + "Service Availability" + ], + content: "This agreement defines payment processing terms and conditions." + }, + 'Contract #103': { + title: "Deposit Management Contract", + date: "2024-06-01", + parties: ["Company XYZ", "Deposit Team"], + terms: [ + "Deposit Rules", + "Storage Protocol", + "Access Control", + "Security Standards" + ], + content: "This contract outlines deposit management procedures and security measures." + }, + 'Contract #104': { + title: "Artefact Handling Agreement", + date: "2024-07-01", + parties: ["Company XYZ", "Artefact Team"], + terms: [ + "Handling Procedures", + "Storage Guidelines", + "Access Protocol", + "Preservation Standards" + ], + content: "This agreement establishes artefact handling and preservation guidelines." + }, + 'Contract #105': { + title: "Resolution Protocol Agreement", + date: "2024-08-01", + parties: ["Company XYZ", "Resolution Team"], + terms: [ + "Resolution Process", + "Time Constraints", + "Escalation Protocol", + "Documentation Requirements" + ], + content: "This contract defines the resolution process and protocol standards." + }, + 'Contract #106': { + title: "Backup Service Agreement", + date: "2024-09-01", + parties: ["Company XYZ", "Backup Team"], + terms: [ + "Backup Schedule", + "Data Protection", + "Recovery Protocol", + "Service Reliability" + ], + content: "This agreement outlines backup service terms and recovery procedures." + } +}; diff --git a/src/mocks/mock-account/interfacesAccountMock.ts b/src/mocks/mock-account/interfacesAccountMock.ts new file mode 100644 index 0000000..0834d4c --- /dev/null +++ b/src/mocks/mock-account/interfacesAccountMock.ts @@ -0,0 +1,45 @@ +export interface Row { + column1: string; + column2: string; + column3: string; +} + +// Types supplémentaires nécessaires +export interface Contract { + title: string; + date: string; + parties: string[]; + terms: string[]; + content: string; +} + +export interface WalletRow { + column1: string; // Label + column2: string; // Wallet + column3: string; // Type +} + +export interface DataRow { + column1: string; // Name + column2: string; // Visibility + column3: string; // Role + column4: string; // Duration + column5: string; // Legal + column6: string; // Contract + processName: string; + zone: string; +} + +export interface Notification { + message: string; + timestamp: string; + isRead: boolean; +} + +// Déplacer l'interface en dehors de la classe, au début du fichier +export interface NotificationMessage { + id: number; + read: boolean; + date: string; + message: string; +} diff --git a/src/pages/account/account-component.ts b/src/pages/account/account-component.ts new file mode 100644 index 0000000..31c0413 --- /dev/null +++ b/src/pages/account/account-component.ts @@ -0,0 +1,59 @@ +import { AccountElement } from './account'; +import accountCss from '../../../public/style/account.css?raw' +import Services from '../../services/service.js' + +class AccountComponent extends HTMLElement { + _callback: any + accountElement: AccountElement | null = null; + + constructor() { + super(); + console.log('INIT') + this.attachShadow({ mode: 'open' }); + + this.accountElement = this.shadowRoot?.querySelector('account-element') || null; + } + + connectedCallback() { + console.log('CALLBACKs') + this.render(); + this.fetchData(); + + if (!customElements.get('account-element')) { + customElements.define('account-element', AccountElement); + } + } + + async fetchData() { + if ((import.meta as any).env.VITE_IS_INDEPENDANT_LIB === false) { + const data = await (window as any).myService?.getProcesses(); + } else { + const service = await Services.getInstance() + const data = await service.getProcesses(); + } + } + + set callback(fn) { + if (typeof fn === 'function') { + this._callback = fn; + } else { + console.error('Callback is not a function'); + } + } + + get callback() { + return this._callback; + } + + render() { + if(this.shadowRoot) { + // Créer l'élément chat-element + const accountElement = document.createElement('account-element'); + this.shadowRoot.innerHTML = ``; + this.shadowRoot.appendChild(accountElement); + } + } +} + +export { AccountComponent } +customElements.define('account-component', AccountComponent); diff --git a/src/pages/account/account.ts b/src/pages/account/account.ts index ddc151b..0a5c6fd 100755 --- a/src/pages/account/account.ts +++ b/src/pages/account/account.ts @@ -1,391 +1,124 @@ +declare global { + interface Window { + localStorage: Storage; + initAccount: () => void; + showContractPopup: (contractId: string) => void; + showPairing: () => void; + showWallet: () => void; + showData: () => void; + addWalletRow: () => void; + confirmWalletRow: () => void; + cancelWalletRow: () => void; + openAvatarPopup: () => void; + closeAvatarPopup: () => void; + editDeviceName: (cell: HTMLTableCellElement) => void; + showNotifications: (processName: string) => void; + closeNotificationPopup: (event: Event) => void; + markAsRead: (processName: string, messageId: number, element: HTMLElement) => void; + exportRecovery: () => void; + confirmDeleteAccount: () => void; + deleteAccount: () => void; + updateNavbarBanner: (bannerUrl: string) => void; + saveBannerToLocalStorage: (bannerUrl: string) => void; + loadSavedBanner: () => void; + cancelAddRow: () => void; + saveName: (cell: HTMLElement, input: HTMLInputElement) => void; + showProcessNotifications: (processName: string) => void; + handleLogout: () => void; + initializeEventListeners: () => void; + showProcess: () => void; + updateNavbarName: (name: string) => void; + updateNavbarLastName: (lastName: string) => void; + showAlert: (title: string, text?: string, icon?: string) => void; + addRow: () => void; + confirmRow: () => void; + cancelRow: () => void; + deleteRow: (button: HTMLButtonElement) => void; + generateRecoveryWords: () => string[]; + exportUserData: () => void; + updateActionButtons: () => void; + } +} + import Swal from 'sweetalert2'; - - -//console.log("Account script loaded"); +import { STORAGE_KEYS, defaultRows, mockProcessRows, mockNotifications, notificationMessages, mockDataRows, mockContracts, ALLOWED_ROLES } from '../../mocks/mock-account/constAccountMock'; +import { Row, WalletRow, DataRow, Notification, Contract, NotificationMessage } from '../../mocks/mock-account/interfacesAccountMock'; +import { addressToEmoji } from '../../utils/sp-address.utils'; +import { getCorrectDOM } from '../../utils/document.utils'; let isAddingRow = false; let currentRow: HTMLTableRowElement | null = null; let currentMode: keyof typeof STORAGE_KEYS = 'pairing'; -interface Row { - column1: string; - column2: string; - column3: string; -} - -// Types supplémentaires nécessaires -interface Contract { - title: string; - date: string; - parties: string[]; - terms: string[]; - content: string; -} - -interface WalletRow { - column1: string; // Label - column2: string; // Wallet - column3: string; // Type -} - -interface DataRow { - column1: string; // Name - column2: string; // Visibility - column3: string; // Role - column4: string; // Duration - column5: string; // Legal - column6: string; // Contract - processName: string; - zone: string; -} - -const ALLOWED_ROLES = ['User', 'Member', 'Peer', 'Payment', 'Deposit', 'Artefact', 'Resolve', 'Backup']; - -const STORAGE_KEYS = { - pairing: 'pairingRows', - wallet: 'walletRows', - process: 'processRows', - data: 'dataRows' -}; - -// Initialiser le stockage des lignes par défaut dans le localStorage -const defaultRows = [ - { - column1: "sprt1qqwtvg5q5vcz0reqvmld98u7va3av6gakwe9yxw9yhnpj5djcunn4squ68tuzn8dz78dg4adfv0dekx8hg9sy0t6s9k5em7rffgxmrsfpyy7gtyrz", - column2: "🎊😑🎄😩", - column3: "Laptop" - }, - { - column1: "sprt1qqwtvg5q5vcz0reqvmld98u7va3av6gakwe9yxw9yhnpj5djcunn4squ68tuzn8dz78dg4adfv0dekx8hg9sy0t6s9k5em7rffgxmrsfpyy7gtyrx", - column2: "🎏🎕😧🌥", - column3: "Phone" } -]; - -// Vérifier si les lignes sont déjà dans le localStorage -if (!localStorage.getItem('rows')) { - localStorage.setItem('rows', JSON.stringify(defaultRows)); -} - -// Add this interface -interface Notification { - message: string; - timestamp: string; - isRead: boolean; -} - -// Update the declaration -const mockNotifications: { [key: string]: Notification[] } = {}; - -const notificationMessages = [ - "CPU usage high", - "Memory threshold reached", - "New update available", - "Backup completed", - "Security check required", - "Performance optimization needed", - "System alert", - "Network connectivity issue", - "Storage space low", - "Process checkpoint reached" -]; - -const mockDataRows = [ - { - column1: "User Project", - column2: "private", - column3: "User", - column4: "6 months", - column5: "NDA signed", - column6: "Contract #123", - processName: "User Process", - zone: "A" - }, - { - column1: "Process Project", - column2: "private", - column3: "Process", - column4: "1 year", - column5: "Terms accepted", - column6: "Contract #456", - processName: "Process Management", - zone: "B" - }, - { - column1: "Member Project", - column2: "private", - column3: "Member", - column4: "3 months", - column5: "GDPR compliant", - column6: "Contract #789", - processName: "Member Process", - zone: "C" - }, - { - column1: "Peer Project", - column2: "public", - column3: "Peer", - column4: "2 years", - column5: "IP rights", - column6: "Contract #101", - processName: "Peer Process", - zone: "D" - }, - { - column1: "Payment Project", - column2: "confidential", - column3: "Payment", - column4: "1 year", - column5: "NDA signed", - column6: "Contract #102", - processName: "Payment Process", - zone: "E" - }, - { - column1: "Deposit Project", - column2: "private", - column3: "Deposit", - column4: "6 months", - column5: "Terms accepted", - column6: "Contract #103", - processName: "Deposit Process", - zone: "F" - }, - { - column1: "Artefact Project", - column2: "public", - column3: "Artefact", - column4: "1 year", - column5: "GDPR compliant", - column6: "Contract #104", - processName: "Artefact Process", - zone: "G" - }, - { - column1: "Resolve Project", - column2: "private", - column3: "Resolve", - column4: "2 years", - column5: "IP rights", - column6: "Contract #105", - processName: "Resolve Process", - zone: "H" - }, - { - column1: "Backup Project", - column2: "public", - column3: "Backup", - column4: "1 year", - column5: "NDA signed", - column6: "Contract #106", - processName: "Backup Process", - zone: "I" +export function showAlert(message: string): void { + // Créer la popup si elle n'existe pas + let alertPopup = document.querySelector('.alert-popup'); + if (!alertPopup) { + alertPopup = document.createElement('div'); + alertPopup.className = 'alert-popup'; + document.body.appendChild(alertPopup); } -]; -const mockProcessRows = [ - { - process: "User Project", - role: "User", - notification: { - messages: [ - { id: 1, read: false, date: "2024-03-10", message: "New user joined the project" }, - { id: 2, read: false, date: "2024-03-09", message: "Project milestone reached" }, - { id: 3, read: false, date: "2024-03-08", message: "Security update required" }, - { id: 4, read: true, date: "2024-03-07", message: "Weekly report available" }, - { id: 5, read: true, date: "2024-03-06", message: "Team meeting scheduled" } - ] - } - }, - { - process: "Member Project", - role: "Member", - notification: { - messages: [ - { id: 6, read: true, date: "2024-03-10", message: "Member access granted" }, - { id: 7, read: true, date: "2024-03-09", message: "Documentation updated" }, - { id: 8, read: true, date: "2024-03-08", message: "Project status: on track" } - ] - } - }, - { - process: "Peer Project", - role: "Peer", - notification: { - unread: 2, - total: 4, - messages: [ - { id: 9, read: false, date: "2024-03-10", message: "New peer project added" }, - { id: 10, read: false, date: "2024-03-09", message: "Project milestone reached" }, - { id: 11, read: false, date: "2024-03-08", message: "Security update required" }, - { id: 12, read: true, date: "2024-03-07", message: "Weekly report available" }, - { id: 13, read: true, date: "2024-03-06", message: "Team meeting scheduled" } - ] - } - }, - { - process: "Deposit Project", - role: "Deposit", - notification: { - unread: 1, - total: 10, - messages: [ - { id: 14, read: false, date: "2024-03-10", message: "Deposit milestone reached" }, - { id: 15, read: false, date: "2024-03-09", message: "Security update required" }, - { id: 16, read: false, date: "2024-03-08", message: "Weekly report available" }, - { id: 17, read: true, date: "2024-03-07", message: "Team meeting scheduled" }, - { id: 18, read: true, date: "2024-03-06", message: "Project status: on track" } - ] - } - }, - { - process: "Artefact Project", - role: "Artefact", - notification: { - unread: 0, - total: 3, - messages: [ - { id: 19, read: false, date: "2024-03-10", message: "New artefact added" }, - { id: 20, read: false, date: "2024-03-09", message: "Security update required" }, - { id: 21, read: false, date: "2024-03-08", message: "Weekly report available" }, - { id: 22, read: true, date: "2024-03-07", message: "Team meeting scheduled" }, - { id: 23, read: true, date: "2024-03-06", message: "Project status: on track" } - ] - } - }, - { - process: "Resolve Project", - role: "Resolve", - notification: { - unread: 5, - total: 12, - messages: [ - { id: 24, read: false, date: "2024-03-10", message: "New issue reported" }, - { id: 25, read: false, date: "2024-03-09", message: "Security update required" }, - { id: 26, read: false, date: "2024-03-08", message: "Weekly report available" }, - { id: 27, read: true, date: "2024-03-07", message: "Team meeting scheduled" }, - { id: 28, read: true, date: "2024-03-06", message: "Project status: on track" } - ] + // Définir le message et afficher la popup + alertPopup.textContent = message; + (alertPopup as HTMLElement).style.display = 'block'; + + // Cacher la popup après 3 secondes + setTimeout(() => { + (alertPopup as HTMLElement).style.display = 'none'; + }, 3000); +} + +class AccountElement extends HTMLElement { + private dom: Node; + + + + + constructor() { + super(); + this.attachShadow({ mode: 'open' }); + this.dom = getCorrectDOM('account-element'); + + + window.showPairing = () => this.showPairing(); + window.showWallet = () => this.showWallet(); + window.showProcess = () => this.showProcess(); + window.showData = () => this.showData(); + window.addWalletRow = () => this.addWalletRow(); + window.confirmWalletRow = () => this.confirmWalletRow(); + window.cancelWalletRow = () => this.cancelWalletRow(); + window.editDeviceName = (cell: HTMLTableCellElement) => this.editDeviceName(cell); + window.showProcessNotifications = (processName: string) => this.showProcessNotifications(processName); + window.handleLogout = () => this.handleLogout(); + window.confirmDeleteAccount = () => this.confirmDeleteAccount(); + window.showContractPopup = (contractId: string) => this.showContractPopup(contractId); + window.addRow = () => this.addRow(); + window.deleteRow = (button: HTMLButtonElement) => this.deleteRow(button); + window.confirmRow = () => this.confirmRow(); + window.cancelRow = () => this.cancelRow(); + window.updateNavbarBanner = (bannerUrl: string) => this.updateNavbarBanner(bannerUrl); + window.saveBannerToLocalStorage = (bannerUrl: string) => this.saveBannerToLocalStorage(bannerUrl); + window.loadSavedBanner = () => this.loadSavedBanner(); + window.closeNotificationPopup = (event: Event) => this.closeNotificationPopup(event); + window.markAsRead = (processName: string, messageId: number, element: HTMLElement) => this.markAsRead(processName, messageId, element); + window.exportRecovery = () => this.exportRecovery(); + window.generateRecoveryWords = () => this.generateRecoveryWords(); + window.exportUserData = () => this.exportUserData(); + window.updateActionButtons = () => this.updateActionButtons(); + window.openAvatarPopup = () => this.openAvatarPopup(); + window.closeAvatarPopup = () => this.closeAvatarPopup(); + + if (!localStorage.getItem('rows')) { + localStorage.setItem('rows', JSON.stringify(defaultRows)); } } -]; - -const mockContracts = { - 'Contract #123': { - title: "User Project Agreement", - date: "2024-01-15", - parties: ["Company XYZ", "User Team"], - terms: [ - "Data Protection", - "User Privacy", - "Access Rights", - "Service Level Agreement" - ], - content: "This agreement establishes the terms and conditions for user project management." - }, - 'Contract #456': { - title: "Process Management Contract", - date: "2024-02-01", - parties: ["Company XYZ", "Process Team"], - terms: [ - "Process Workflow", - "Quality Standards", - "Performance Metrics", - "Monitoring Procedures" - ], - content: "This contract defines the process management standards and procedures." - }, - 'Contract #789': { - title: "Member Access Agreement", - date: "2024-03-15", - parties: ["Company XYZ", "Member Team"], - terms: [ - "Member Rights", - "Access Levels", - "Security Protocol", - "Confidentiality Agreement" - ], - content: "This agreement outlines the terms for member access and privileges." - }, - 'Contract #101': { - title: "Peer Collaboration Agreement", - date: "2024-04-01", - parties: ["Company XYZ", "Peer Network"], - terms: [ - "Collaboration Rules", - "Resource Sharing", - "Dispute Resolution", - "Network Protocol" - ], - content: "This contract establishes peer collaboration and networking guidelines." - }, - 'Contract #102': { - title: "Payment Processing Agreement", - date: "2024-05-01", - parties: ["Company XYZ", "Payment Team"], - terms: [ - "Transaction Protocol", - "Security Measures", - "Fee Structure", - "Service Availability" - ], - content: "This agreement defines payment processing terms and conditions." - }, - 'Contract #103': { - title: "Deposit Management Contract", - date: "2024-06-01", - parties: ["Company XYZ", "Deposit Team"], - terms: [ - "Deposit Rules", - "Storage Protocol", - "Access Control", - "Security Standards" - ], - content: "This contract outlines deposit management procedures and security measures." - }, - 'Contract #104': { - title: "Artefact Handling Agreement", - date: "2024-07-01", - parties: ["Company XYZ", "Artefact Team"], - terms: [ - "Handling Procedures", - "Storage Guidelines", - "Access Protocol", - "Preservation Standards" - ], - content: "This agreement establishes artefact handling and preservation guidelines." - }, - 'Contract #105': { - title: "Resolution Protocol Agreement", - date: "2024-08-01", - parties: ["Company XYZ", "Resolution Team"], - terms: [ - "Resolution Process", - "Time Constraints", - "Escalation Protocol", - "Documentation Requirements" - ], - content: "This contract defines the resolution process and protocol standards." - }, - 'Contract #106': { - title: "Backup Service Agreement", - date: "2024-09-01", - parties: ["Company XYZ", "Backup Team"], - terms: [ - "Backup Schedule", - "Data Protection", - "Recovery Protocol", - "Service Reliability" - ], - content: "This agreement outlines backup service terms and recovery procedures." - } -}; - -// Fonctions de gestion des comptes et de l'interface utilisateur -function confirmDeleteAccount(): void { - const modal = document.createElement('div'); - modal.className = 'confirm-delete-modal'; - modal.innerHTML = ` + // Fonctions de gestion des comptes et de l'interface utilisateur + private confirmDeleteAccount(): void { + const modal = document.createElement('div'); + modal.className = 'confirm-delete-modal'; + modal.innerHTML = `

Delete Account

Are you sure you want to delete your account? This action cannot be undone.

@@ -404,18 +137,18 @@ function confirmDeleteAccount(): void { modal.remove(); }); - confirmBtn?.addEventListener('click', () => { - deleteAccount(); - modal.remove(); - }); + confirmBtn?.addEventListener('click', () => { + this.deleteAccount(); + modal.remove(); + }); } -function deleteAccount(): void { +private deleteAccount(): void { localStorage.clear(); window.location.href = '/login.html'; } -function updateNavbarBanner(imageUrl: string): void { +private updateNavbarBanner(imageUrl: string): void { const navbarSection = document.querySelector('.nav-wrapper .avatar-section'); if (!navbarSection) return; @@ -430,23 +163,23 @@ function updateNavbarBanner(imageUrl: string): void { bannerImg.src = imageUrl; } -function saveBannerToLocalStorage(dataUrl: string): void { +private saveBannerToLocalStorage(dataUrl: string): void { localStorage.setItem('userBanner', dataUrl); } -function loadSavedBanner(): void { +private loadSavedBanner(): void { const savedBanner = localStorage.getItem('userBanner'); if (savedBanner) { const bannerImg = document.getElementById('popup-banner-img') as HTMLImageElement; if (bannerImg) { bannerImg.src = savedBanner; } - updateNavbarBanner(savedBanner); + this.updateNavbarBanner(savedBanner); } } -function closeNotificationPopup(event: Event): void { +private closeNotificationPopup(event: Event): void { const target = event.target as HTMLElement; const isOverlay = target.classList.contains('notification-popup-overlay'); const isCloseButton = target.classList.contains('close-popup'); @@ -456,7 +189,7 @@ function closeNotificationPopup(event: Event): void { if (popup) popup.remove(); } -function markAsRead(processName: string, messageId: number, element: HTMLElement): void { +private markAsRead(processName: string, messageId: number, element: HTMLElement): void { const process = mockProcessRows.find(p => p.process === processName); if (!process) return; @@ -473,7 +206,7 @@ function markAsRead(processName: string, messageId: number, element: HTMLElement statusIcon.classList.add('fa-check'); } - const notifCount = calculateNotifications(process.notification.messages); + const notifCount = this.calculateNotifications(process.notification.messages); const countElement = document.querySelector(`.notification-count[data-process="${processName}"]`); if (countElement) { countElement.textContent = `${notifCount.unread}/${notifCount.total}`; @@ -488,21 +221,14 @@ function markAsRead(processName: string, messageId: number, element: HTMLElement } // Fonctions de gestion des données et de l'interface -interface NotificationMessage { - id: number; - read: boolean; - date: string; - message: string; -} - -function calculateNotifications(messages: NotificationMessage[]): { unread: number; total: number } { +private calculateNotifications(messages: NotificationMessage[]): { unread: number; total: number } { const total = messages.length; const unread = messages.filter(msg => !msg.read).length; return { unread, total }; } // Fonctions de récupération -function exportRecovery(): void { +private exportRecovery(): void { Swal.fire({ title: 'Recovery Words Export', text: '4 words will be displayed. We strongly recommend writing them down on paper before exporting the account. Do you want to continue?', @@ -514,7 +240,7 @@ function exportRecovery(): void { cancelButtonColor: '#6c757d' }).then((result) => { if (result.isConfirmed) { - const recoveryWords = generateRecoveryWords(); + const recoveryWords = this.generateRecoveryWords(); localStorage.setItem('recoveryWords', JSON.stringify(recoveryWords)); Swal.fire({ @@ -554,13 +280,11 @@ function exportRecovery(): void { }); } -const wordsList: string[] = [ - "apple", "banana", "carrot", "diamond", "elephant", "forest", "guitar", "hammer", - "island", "jacket", "kettle", "lemon", "marble", "needle", "orange", "pencil", - "quartz", "rabbit", "sunset", "turtle", "umbrella", "violet", "wallet", "yellow" -]; - -function generateRecoveryWords(): string[] { +private generateRecoveryWords(): string[] { + const wordsList = [ + 'apple', 'banana', 'orange', 'grape', 'kiwi', 'mango', 'peach', 'plum', + 'lemon', 'lime', 'cherry', 'melon', 'pear', 'fig', 'date', 'berry' + ]; const recoveryWords: string[] = []; while (recoveryWords.length < 4) { const randomWord = wordsList[Math.floor(Math.random() * wordsList.length)]; @@ -571,7 +295,7 @@ function generateRecoveryWords(): string[] { return recoveryWords; } -function exportUserData(): void { +private exportUserData(): void { const data: { [key: string]: string | null } = {}; for (let i = 0; i < localStorage.length; i++) { const key = localStorage.key(i); @@ -593,19 +317,19 @@ function exportUserData(): void { URL.revokeObjectURL(url); } -function updateActionButtons(): void { +private updateActionButtons(): void { const buttonContainer = document.querySelector('.button-container'); if (!buttonContainer) return; buttonContainer.innerHTML = `
- - + +
`; } -function getConfirmFunction(): string { +private getConfirmFunction(): string { switch (currentMode) { case 'wallet': return 'window.confirmWalletRow()'; @@ -616,7 +340,7 @@ function getConfirmFunction(): string { } } -function getCancelFunction(): string { +private getCancelFunction(): string { switch (currentMode) { case 'wallet': return 'window.cancelWalletRow()'; @@ -628,7 +352,7 @@ function getCancelFunction(): string { } // Fonctions de gestion des tableaux -function addRow(): void { +private addRow(): void { if (isAddingRow) return; isAddingRow = true; @@ -645,19 +369,18 @@ function addRow(): void { input.className = 'edit-input'; // Ajouter un événement pour mettre à jour automatiquement les emojis - if (index === 0) { // SP Address input - input.addEventListener('input', (e) => { + if (index === 0) { + input.addEventListener('input', async (e) => { const addressInput = e.target as HTMLInputElement; - const emojiCell = currentRow!.cells[2]; // Changé à 2 pour la troisième colonne - const emojis = addressToEmoji(addressInput.value); + const emojiCell = currentRow!.cells[2]; + const emojis = await addressToEmoji(addressInput.value); if (emojiCell.querySelector('input')) { (emojiCell.querySelector('input') as HTMLInputElement).value = emojis; } }); } - // Désactiver l'input des emojis car il est automatique - if (index === 2) { // SP Emojis input (troisième colonne) + if (index === 2) { input.readOnly = true; } @@ -667,12 +390,31 @@ function addRow(): void { const deleteCell = currentRow.insertCell(); deleteCell.style.width = '40px'; - updateActionButtons(); + this.updateActionButtons(); +} + +// Fonctions de mise à jour de l'interface +private updateTableContent(rows: Row[]): void { + const tbody = document.querySelector('#pairing-table tbody'); + if (!tbody) return; + + tbody.innerHTML = rows.map(row => ` + + ${row.column1} + ${row.column2} + ${row.column3} + + + + + `).join(''); } -function confirmRow(): void { +private confirmRow(): void { if (!currentRow) return; const inputs = currentRow.getElementsByTagName('input'); @@ -704,30 +446,30 @@ function confirmRow(): void { isAddingRow = false; currentRow = null; - resetButtonContainer(); - updateTableContent(rows); + this.resetButtonContainer(); + this.updateTableContent(rows); } -function cancelRow(): void { +private cancelRow(): void { if (!currentRow) return; currentRow.remove(); isAddingRow = false; currentRow = null; - resetButtonContainer(); + this.resetButtonContainer(); } -function resetButtonContainer(): void { +private resetButtonContainer(): void { const buttonContainer = document.querySelector('.button-container'); if (!buttonContainer) return; buttonContainer.innerHTML = ` - + `; } -function deleteRow(button: HTMLButtonElement): void { +private deleteRow(button: HTMLButtonElement): void { const row = button.closest('tr'); if (!row) return; @@ -760,7 +502,7 @@ function deleteRow(button: HTMLButtonElement): void { }, 300); } -function editDeviceName(cell: HTMLTableCellElement): void { +private editDeviceName(cell: HTMLTableCellElement): void { if (cell.classList.contains('editing')) return; const currentValue = cell.textContent || ''; @@ -769,10 +511,10 @@ function editDeviceName(cell: HTMLTableCellElement): void { input.value = currentValue; input.className = 'edit-input'; - input.addEventListener('blur', () => finishEditing(cell, input)); + input.addEventListener('blur', () => this.finishEditing(cell, input)); input.addEventListener('keypress', (e: KeyboardEvent) => { if (e.key === 'Enter') { - finishEditing(cell, input); + this.finishEditing(cell, input); } }); @@ -782,7 +524,7 @@ function editDeviceName(cell: HTMLTableCellElement): void { input.focus(); } -function finishEditing(cell: HTMLTableCellElement, input: HTMLInputElement): void { +private finishEditing(cell: HTMLTableCellElement, input: HTMLInputElement): void { const newValue = input.value.trim(); if (newValue === '') { cell.textContent = cell.getAttribute('data-original-value') || ''; @@ -808,54 +550,8 @@ function finishEditing(cell: HTMLTableCellElement, input: HTMLInputElement): voi cell.textContent = newValue; cell.classList.remove('editing'); } - -function showAlert(message: string): void { - // Créer la popup si elle n'existe pas - let alertPopup = document.querySelector('.alert-popup'); - if (!alertPopup) { - alertPopup = document.createElement('div'); - alertPopup.className = 'alert-popup'; - document.body.appendChild(alertPopup); - } - - // Définir le message et afficher la popup - alertPopup.textContent = message; - (alertPopup as HTMLElement).style.display = 'block'; - - // Cacher la popup après 3 secondes - setTimeout(() => { - (alertPopup as HTMLElement).style.display = 'none'; - }, 3000); -} - -// Fonction pour gérer les événements d'édition -function initializeEventListeners(): void { - const editableFields = document.querySelectorAll('.editable'); - editableFields.forEach(field => { - field.addEventListener('click', () => { - if (!field.classList.contains('editing')) { - const currentValue = field.textContent || ''; - const input = document.createElement('input'); - input.type = 'text'; - input.value = currentValue; - input.className = 'edit-input'; - - field.textContent = ''; - field.appendChild(input); - field.classList.add('editing'); - input.focus(); - } - }); - }); - - const avatarInput = document.getElementById('avatar-upload') as HTMLInputElement; - if (avatarInput) { - avatarInput.addEventListener('change', handleAvatarUpload); - } -} - // Fonction pour gérer le téléchargement de l'avatar -function handleAvatarUpload(event: Event): void { +private handleAvatarUpload(event: Event): void { const input = event.target as HTMLInputElement; const file = input.files?.[0]; @@ -875,24 +571,11 @@ function handleAvatarUpload(event: Event): void { } } -// Initialisation au chargement de la page -if (!localStorage.getItem('rows')) { - localStorage.setItem('rows', JSON.stringify(defaultRows)); -} -// Event Listeners et initialisation -document.addEventListener('DOMContentLoaded', () => { - //console.log("DOM Content Loaded"); - initAccount(); - showPairing(); -}); - - - -function showProcess(): void { +private showProcess(): void { //console.log("showProcess called"); currentMode = 'process'; - hideAllContent(); + this.hideAllContent(); const headerTitle = document.getElementById('header-title'); if (headerTitle) headerTitle.textContent = 'Process'; @@ -917,12 +600,12 @@ function showProcess(): void { `; // Utiliser mockProcessRows au lieu du localStorage - updateProcessTableContent(mockProcessRows); + this.updateProcessTableContent(mockProcessRows); } } // Fonction utilitaire pour mettre à jour le contenu du tableau Process -function updateProcessTableContent(rows: any[]): void { +private updateProcessTableContent(rows: any[]): void { const tbody = document.querySelector('#process-table tbody'); if (!tbody) return; @@ -944,7 +627,7 @@ function updateProcessTableContent(rows: any[]): void { -function showProcessNotifications(processName: string): void { +private showProcessNotifications(processName: string): void { const process = mockProcessRows.find(p => p.process === processName); if (!process) return; @@ -983,54 +666,26 @@ function showProcessNotifications(processName: string): void { // Mettre à jour le compteur de notifications const countElement = document.querySelector(`.notification-count[data-process="${processName}"]`); if (countElement) { - const notifCount = calculateNotifications(process.notification.messages); + const notifCount = this.calculateNotifications(process.notification.messages); countElement.textContent = `${notifCount.unread}/${notifCount.total}`; } const closeButton = modal.querySelector('.close-notifications'); closeButton?.addEventListener('click', () => { modal.remove(); - showProcess(); // Rafraîchir l'affichage pour mettre à jour les compteurs + this.showProcess(); // Rafraîchir l'affichage pour mettre à jour les compteurs }); } -function generateRandomNotification(): void { - const processes = JSON.parse(localStorage.getItem(STORAGE_KEYS.process) || '[]'); - if (processes.length === 0) return; - const randomProcess = processes[Math.floor(Math.random() * processes.length)].column1; - const notification = { - message: notificationMessages[Math.floor(Math.random() * notificationMessages.length)], - timestamp: new Date().toLocaleString(), - isRead: false - }; - - if (!mockNotifications[randomProcess]) { - mockNotifications[randomProcess] = []; - } - mockNotifications[randomProcess].push(notification); - - if (currentMode === 'process') { - showProcess(); - } -} - -function handleLogout(): void { +private handleLogout(): void { localStorage.clear(); window.location.href = '../login/login.html'; } - -// Initialisation des notifications -document.addEventListener('DOMContentLoaded', () => { - loadUserInfo(); - setInterval(generateRandomNotification, 60000); -}); - - // Fonctions de gestion des contrats -function showContractPopup(contractId: string) { +private showContractPopup(contractId: string) { // Empêcher la navigation par défaut event?.preventDefault(); // Check if the contract exists in mockContracts @@ -1073,10 +728,10 @@ function showContractPopup(contractId: string) { } // Ajouter à l'objet window -window.showContractPopup = showContractPopup; + // Fonction utilitaire pour cacher tous les contenus -function hideAllContent(): void { +private hideAllContent(): void { const contents = ['pairing-content', 'wallet-content', 'process-content', 'data-content']; contents.forEach(id => { const element = document.getElementById(id); @@ -1087,14 +742,14 @@ function hideAllContent(): void { } // Fonctions d'affichage des sections -function showPairing(): void { +private showPairing(): void { isAddingRow = false; currentRow = null; currentMode = 'pairing'; // Cacher tous les contenus - hideAllContent(); + this.hideAllContent(); // Mettre à jour le titre const headerElement = document.getElementById('parameter-header'); @@ -1130,16 +785,16 @@ function showPairing(): void { // Mettre à jour le contenu du tableau const rows = JSON.parse(localStorage.getItem(STORAGE_KEYS.pairing) || '[]'); - updateTableContent(rows); + this.updateTableContent(rows); } } -function showWallet(): void { +private showWallet(): void { isAddingRow = false; currentRow = null; currentMode = 'wallet'; - hideAllContent(); + this.hideAllContent(); // Mettre à jour le titre const headerTitle = document.getElementById('header-title'); @@ -1147,7 +802,7 @@ function showWallet(): void { const walletContent = document.getElementById('wallet-content'); if (!walletContent) return; - walletContent.style.display = 'block'; // Ajout de cette ligne pour rendre visible + walletContent.style.display = 'block'; walletContent.innerHTML = `
Wallet
@@ -1168,11 +823,11 @@ function showWallet(): void { `; const rows = JSON.parse(localStorage.getItem(STORAGE_KEYS.wallet) || '[]'); - updateWalletTableContent(rows); + this.updateWalletTableContent(rows); } -function updateWalletTableContent(rows: WalletRow[]): void { +private updateWalletTableContent(rows: WalletRow[]): void { const tbody = document.querySelector('#wallet-table tbody'); if (!tbody) return; @@ -1185,10 +840,10 @@ function updateWalletTableContent(rows: WalletRow[]): void { `).join(''); } -function showData(): void { +private showData(): void { //console.log("showData called"); currentMode = 'data'; - hideAllContent(); + this.hideAllContent(); const headerTitle = document.getElementById('header-title'); if (headerTitle) headerTitle.textContent = 'Data'; @@ -1216,12 +871,12 @@ function showData(): void { `; const rows = mockDataRows || JSON.parse(localStorage.getItem(STORAGE_KEYS.data) || '[]'); - updateDataTableContent(rows); + this.updateDataTableContent(rows); } } // Fonctions de gestion du wallet -function addWalletRow(): void { +private addWalletRow(): void { if (isAddingRow) return; isAddingRow = true; @@ -1251,10 +906,10 @@ function addWalletRow(): void {
`; - updateActionButtons(); + this.updateActionButtons(); } -function confirmWalletRow(): void { +private confirmWalletRow(): void { if (!currentRow) return; const inputs = Array.from(currentRow.getElementsByTagName('input')); @@ -1273,13 +928,13 @@ function confirmWalletRow(): void { isAddingRow = false; currentRow = null; - showWallet(); + this.showWallet(); } else { showAlert('Please complete all fields before confirming.'); } } -function cancelWalletRow(): void { +private cancelWalletRow(): void { if (!currentRow) return; currentRow.remove(); @@ -1298,13 +953,13 @@ function cancelWalletRow(): void { } // Fonctions de sauvegarde -function saveDataRowToLocalStorage(row: DataRow): void { +private saveDataRowToLocalStorage(row: DataRow): void { const rows: DataRow[] = JSON.parse(localStorage.getItem(STORAGE_KEYS.data) || '[]'); rows.push(row); localStorage.setItem(STORAGE_KEYS.data, JSON.stringify(rows)); } -function saveDeviceName(cell: HTMLTableCellElement, newValue: string): void { +private saveDeviceName(cell: HTMLTableCellElement, newValue: string): void { const row = cell.closest('tr'); if (!row) return; @@ -1317,33 +972,13 @@ function saveDeviceName(cell: HTMLTableCellElement, newValue: string): void { } } -function saveRowToLocalStorage(row: Row): void { +private saveRowToLocalStorage(row: Row): void { const rows: Row[] = JSON.parse(localStorage.getItem(STORAGE_KEYS[currentMode]) || '[]'); rows.push(row); localStorage.setItem(STORAGE_KEYS[currentMode], JSON.stringify(rows)); } - -// Fonctions de mise à jour de l'interface -function updateTableContent(rows: Row[]): void { - const tbody = document.querySelector('#pairing-table tbody'); - if (!tbody) return; - - tbody.innerHTML = rows.map(row => ` - - ${row.column1} - ${row.column2} - ${row.column3} - - - - - `).join(''); -} - -function updateDataTableContent(rows: DataRow[]): void { +private updateDataTableContent(rows: DataRow[]): void { const tbody = document.querySelector('#data-table tbody'); if (!tbody) return; @@ -1362,7 +997,7 @@ function updateDataTableContent(rows: DataRow[]): void { } // Fonctions de gestion de l'avatar et de la bannière -function openAvatarPopup(): void { +private openAvatarPopup(): void { const popup = document.getElementById('avatar-popup'); if (!popup) return; @@ -1371,7 +1006,7 @@ function openAvatarPopup(): void { const savedLastName = localStorage.getItem('userLastName') || 'Doe'; const savedAvatar = localStorage.getItem('userAvatar') || 'https://via.placeholder.com/150'; const savedBanner = localStorage.getItem('userBanner') || 'https://via.placeholder.com/800x200'; - const savedAddress = localStorage.getItem('userAddress') || '🏠 🌍 🗽🎊😩-🎊😑🎄😩'; + const savedAddress = localStorage.getItem('userAddress') || '🏠 🌍 🗽🎊😩-🎊😑😩'; popup.innerHTML = `