This commit is contained in:
Pascal 2025-01-17 15:15:15 +01:00
parent 33c170f58f
commit 34ce754be4
2 changed files with 61 additions and 18 deletions

View File

@ -17,22 +17,12 @@ class ChatComponent extends HTMLElement {
connectedCallback() {
console.log('CALLBACKs');
this.render();
this.fetchData();
if (!customElements.get('chat-element')) {
customElements.define('chat-element', ChatElement);
}
}
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;

View File

@ -30,6 +30,7 @@ export function initChat() {
}
}
class ChatElement extends HTMLElement {
static get observedAttributes() {
return ['process-id'];
@ -130,7 +131,7 @@ class ChatElement extends HTMLElement {
console.log(`🔄 Attribute ${name} changed from ${oldValue} to ${newValue}`);
if (name === 'process-id' && newValue) {
console.log('🔍 Loading chat with new process ID:', newValue);
this.loadGroupList(newValue);
this.loadGroupListFromAProcess(newValue);
}
}
@ -413,6 +414,8 @@ class ChatElement extends HTMLElement {
console.log('Found child process', messagesProcess);
}
/* TODO
console.log("Je suis messagesProcess", messagesProcess);
// --- GET THE STATE ID ---
const messagesProcessStateId = messagesProcess?.states?.[0]?.state_id;
console.log("Je suis messagesProcessStateId", messagesProcessStateId);
@ -421,7 +424,7 @@ class ChatElement extends HTMLElement {
if (messagesProcessStateId) {
const diffFromStateId = await this.getDiffByStateId(messagesProcessStateId);
console.log("Je suis diffFromStateId", diffFromStateId);
}
}*/
// Récupérer les messages depuis les états du processus
const allMessages: any[] = [];
@ -617,7 +620,43 @@ class ChatElement extends HTMLElement {
return null;
}
private async loadGroupList(processId: string): Promise<void> {
public async loadAllGroupList(): Promise<void> {
console.log('🎯 Loading all group list');
const groupList = this.shadowRoot?.querySelector('#group-list');
if (!groupList) {
console.error('❌ Group list element not found');
return;
}
groupList.innerHTML = '';
const service = await Services.getInstance();
// Récupérer tous les processus
const processes = await service.getProcesses();
console.log('All processes here:', processes);
if (!processes || Object.keys(processes).length === 0) {
console.log('⚠️ No processes found');
return;
}
// Pour chaque processus, récupérer et afficher les rôles
/*for (const [processId, process] of Object.entries(processes)) {
console.log(`🔄 Processing: ${processId}`, process);
const roles = await this.getRoles(process);
console.log(`👥 Roles for ${processId}:`, roles);
if (roles === null) {
console.error(`❌ No roles in process ${processId}`);
continue;
}
console.log(`📝 Loading group list for process ${processId}`);
await this.loadGroupListFromAProcess(processId);
}*/
}
private async loadGroupListFromAProcess(processId: string): Promise<void> {
console.log('Loading group list with processId:', processId);
const groupList = this.shadowRoot?.querySelector('#group-list');
if (!groupList) return;
@ -767,7 +806,7 @@ class ChatElement extends HTMLElement {
text: `Fichier envoyé: ${file.name}`,
timestamp: timestamp,
sender: myAddresses[0],
recipient: this.selectedMemberId,
recipient: this.selectedMember,
messageState: this.messageState,
roleName: this.selectedRole,
type: 'file',
@ -794,7 +833,7 @@ class ChatElement extends HTMLElement {
metadata: {
text: "J'ai bien reçu votre fichier 📎",
timestamp: timestamp + 1000,
sender: this.selectedMemberId,
sender: this.selectedMember,
recipient: myAddresses[0],
messageState: this.messageState,
roleName: this.selectedRole
@ -827,8 +866,8 @@ class ChatElement extends HTMLElement {
if (fileInput) fileInput.value = '';
// Recharger les messages
if (this.selectedMemberId) {
await this.loadMemberChat(this.selectedMemberId);
if (this.selectedMember) {
await this.loadMemberChat(this.selectedMember);
}
} catch (error) {
@ -887,13 +926,27 @@ class ChatElement extends HTMLElement {
}
async connectedCallback() {
console.log('🔍 Connected Callback started');
// Log du contenu d'IndexedDB
const dbRequest = indexedDB.open('4nk');
dbRequest.onsuccess = (event: any) => {
const db = event.target.result;
const transaction = db.transaction('processes', 'readonly');
// Log des processes
const processesStore = transaction.objectStore('processes');
processesStore.getAll().onsuccess = (event: any) => {
console.log('🔄 Processes in IndexedDB:', event.target.result);
};
};
if (this.processId) {
console.log('🔍 Loading chat with process ID:', this.processId);
this.loadGroupList(this.processId);
this.loadGroupListFromAProcess(this.processId);
} else {
console.error('❌ No process ID found in element attributes');
}
// Si un membre est sélectionné par défaut, charger ses messages
if (this.selectedMember) {
await this.loadMemberChat(this.selectedMember);