Get processes from Service

This commit is contained in:
NicolasCantu 2025-02-11 16:01:19 +01:00
parent 1a6e6d595e
commit 7403fb7a5e

View File

@ -5,8 +5,9 @@ import { Process } from 'pkg/sdk_client';
import chatStyle from '../../../public/style/chat.css?inline'; import chatStyle from '../../../public/style/chat.css?inline';
import { Database } from '../../services/database.service'; import { Database } from '../../services/database.service';
let myProcesses = new Set(); const service = await Service.getInstance();
let allProcesses = new Set(); let myProcesses = service.getMyProcesses();
let allProcesses = service.getProcesses();
// Initialize function, create initial tokens with itens that are already selected by the user // Initialize function, create initial tokens with itens that are already selected by the user
export async function init() { export async function init() {
@ -50,7 +51,7 @@ export async function init() {
addPlaceholder(wrapper); addPlaceholder(wrapper);
await loadAllProcesses(); // await loadAllProcesses();
const database = await Database.getInstance(); const database = await Database.getInstance();
@ -385,19 +386,19 @@ addSubscription(document, 'click', () => {
} }
}); });
async function loadAllProcesses() { // async function loadAllProcesses() {
try { // try {
const [allProcessesNew, myProcessesNew] = await Promise.all([ // const [allProcessesNew, myProcessesNew] = await Promise.all([
getProcesses(), // getProcesses(),
getMyProcesses() // getMyProcesses()
]); // ]);
myProcesses = myProcesses.union(myProcessesNew); // myProcesses = myProcesses.union(myProcessesNew);
allProcesses = allProcesses.union(allProcessesNew); // allProcesses = allProcesses.union(allProcessesNew);
} catch (error) { // } catch (error) {
console.error("Error loading processes:", error); // console.error("Error loading processes:", error);
} // }
} // }
async function showSelectedProcess(elem: MouseEvent) { async function showSelectedProcess(elem: MouseEvent) {
const container = getCorrectDOM('process-list-4nk-component') as HTMLElement; const container = getCorrectDOM('process-list-4nk-component') as HTMLElement;
@ -546,39 +547,39 @@ async function getDescription(processId: string, process: Process): Promise<stri
return null; return null;
} }
async function getProcesses(): Promise<Set<string>> { // async function getProcesses(): Promise<Set<string>> {
const service = await Services.getInstance(); // const service = await Services.getInstance();
const processes = await service.getProcesses(); // const processes = await service.getProcesses();
const processIds = new Set<string>(Object.keys(processes)); // const processIds = new Set<string>(Object.keys(processes));
return processIds; // return processIds;
} // }
async function getMyProcesses(): Promise<Set<string>> { // async function getMyProcesses(): Promise<Set<string>> {
const service = await Services.getInstance(); // const service = await Services.getInstance();
try { // try {
const processes = await service.getProcesses(); // const processes = await service.getProcesses();
const userProcessSet = new Set<string>(); // const userProcessSet = new Set<string>();
for (const [processId, process] of Object.entries(processes)) { // for (const [processId, process] of Object.entries(processes)) {
let roles; // let roles;
try { // try {
roles = await service.getRoles(process); // roles = await service.getRoles(process);
// console.log("ROLES: ", roles); // // console.log("ROLES: ", roles);
const hasCurrentUser = service.rolesContainsUs(roles); // const hasCurrentUser = service.rolesContainsUs(roles);
if (hasCurrentUser) { // if (hasCurrentUser) {
userProcessSet.add(processId); // userProcessSet.add(processId);
} // }
} catch (e) { // } catch (e) {
continue; // continue;
} // }
} // }
return userProcessSet; // return userProcessSet;
} catch (e) { // } catch (e) {
console.error("Failed to get processes:", e); // console.error("Failed to get processes:", e);
} // }
} // }