+
diff --git a/src/pages/process/process.ts b/src/pages/process/process.ts
index 2cb80ed..924e7ce 100644
--- a/src/pages/process/process.ts
+++ b/src/pages/process/process.ts
@@ -1,14 +1,5 @@
import { navigate } from '../../router';
import Services from '../../services/service';
-import { IProcess } from '~/models/process.model';
-function toggleMenu() {
- const menu = document.getElementById('menu') as HTMLDivElement;
- if (menu.style.display === 'block') {
- menu.style.display = 'none';
- } else {
- menu.style.display = 'block';
- }
-}
// Initialize function, create initial tokens with itens that are already selected by the user
export async function init() {
@@ -40,13 +31,12 @@ export async function init() {
search_div.appendChild(autocomplete_list);
search_div.appendChild(dropdown_icon);
-
const processes = await getProcesses();
- for(let process of processes) {
+ for (let process of processes) {
const processName = process[1].title;
- const opt = new Option(processName)
- opt.value = processName
- element.add(opt)
+ const opt = new Option(processName);
+ opt.value = processName;
+ element.add(opt);
}
// set the wrapper as child (instead of the element)
element.parentNode?.replaceChild(wrapper, element);
@@ -153,7 +143,6 @@ function clickDropdown(e: Event) {
dropdown.classList.toggle('active');
if (dropdown.classList.contains('active')) {
-
removePlaceholder(wrapper as HTMLElement);
input_search?.focus();
@@ -179,7 +168,7 @@ function clearAutocompleteList(select: HTMLSelectElement) {
// Populate the autocomplete list following a given query from the user
function populateAutocompleteList(select: HTMLSelectElement, query: string, dropdown = false) {
const { autocomplete_options } = getOptions(select);
- console.log("π ~ populateAutocompleteList ~ autocomplete_options:", autocomplete_options)
+ console.log('π ~ populateAutocompleteList ~ autocomplete_options:', autocomplete_options);
let options_to_show;
@@ -220,12 +209,12 @@ function populateAutocompleteList(select: HTMLSelectElement, query: string, drop
// Listener to autocomplete results when clicked set the selected property in the select option
function selectOption(e: any) {
- console.log("π ~ selectOption ~ e:", e)
+ console.log('π ~ selectOption ~ e:', e);
const wrapper = e.target.parentNode.parentNode.parentNode;
const input_search = wrapper.querySelector('.selected-input');
const option = wrapper.querySelector(`select option[value="${e.target.dataset.value}"]`);
- console.log("π ~ selectOption ~ option:", option)
+ console.log('π ~ selectOption ~ option:', option);
option.setAttribute('selected', '');
createToken(wrapper, e.target.dataset.value);
if (input_search.value) {
@@ -337,13 +326,6 @@ function deletePressed(e: KeyboardEvent) {
return true;
}
-// function addOption(target, val, text) {
-// const select = document.querySelector(target);
-// let opt = document.createElement("option");
-// opt.value = val;
-// opt.innerHTML = text;
-// select.appendChild(opt);
-// }
// Dismiss on outside click
document.addEventListener('click', () => {
// get select that has the options available
@@ -365,13 +347,6 @@ document.addEventListener('click', () => {
}
});
-export async function unpair() {
- const service = await Services.getInstance();
- await service.unpairDevice();
-}
-
-(window as any).unpair = unpair;
-
async function showSelectedProcess(elem: MouseEvent) {
if (elem) {
const cardContent = document.querySelector('.process-card-content');
@@ -396,7 +371,7 @@ async function showSelectedProcess(elem: MouseEvent) {
zoneElement.innerHTML = `${zone.title}: ${zone.description}`;
const service = await Services.getInstance();
// service.addSubscription(zoneElement, 'click', 'goToProcessPage');
- zoneElement.addEventListener('click', select)
+ zoneElement.addEventListener('click', select);
processDiv.appendChild(zoneElement);
}
if (cardContent) cardContent.appendChild(processDiv);
@@ -406,32 +381,32 @@ async function showSelectedProcess(elem: MouseEvent) {
function select(event: MouseEvent) {
const target = event.target as HTMLElement;
- const oldSelectedProcess = document.querySelector('.selected-process-zone')
- oldSelectedProcess?.classList.remove('selected-process-zone')
- if(target) {
- target.classList.add('selected-process-zone')
+ const oldSelectedProcess = document.querySelector('.selected-process-zone');
+ oldSelectedProcess?.classList.remove('selected-process-zone');
+ if (target) {
+ target.classList.add('selected-process-zone');
}
- const name = target.getAttribute('zone-id')
- console.log("π ~ select ~ name:", name)
+ const name = target.getAttribute('zone-id');
+ console.log('π ~ select ~ name:', name);
}
function goToProcessPage() {
const target = document.querySelector('.selected-process-zone');
- console.log("π ~ goToProcessPage ~ event:", target)
- if(target) {
+ console.log('π ~ goToProcessPage ~ event:', target);
+ if (target) {
const process = target?.getAttribute('process-id');
console.log('=======================> going to process page', process);
- navigate('process-element/' + process)
+ navigate('process-element/' + process);
}
}
-(window as any).goToProcessPage = goToProcessPage
+(window as any).goToProcessPage = goToProcessPage;
async function getProcesses(): Promise
{
const service = await Services.getInstance();
- const processes = await service.getProcesses()
- console.log("π ~ Services ~ getProcesses ~ processes:", processes)
-
- return processes
+ const processes = await service.getProcesses();
+ console.log('π ~ Services ~ getProcesses ~ processes:', processes);
+
+ return processes;
}
diff --git a/src/router.ts b/src/router.ts
index ef90ed9..2c2014b 100644
--- a/src/router.ts
+++ b/src/router.ts
@@ -7,12 +7,12 @@ const routes: { [key: string]: string } = {
'process-element': '/src/pages/process-element/process-element.html',
};
-export let currentRoute = ''
+export let currentRoute = '';
export async function navigate(path: string) {
path = path.replace(/^\//, '');
- if(path.includes('/')) {
- const parsedPath = path.split('/')[0]
+ if (path.includes('/')) {
+ const parsedPath = path.split('/')[0];
if (!routes[parsedPath]) {
path = 'home';
}
@@ -22,10 +22,9 @@ export async function navigate(path: string) {
}
async function handleLocation(path: string) {
- console.log("π ~ handleLocation ~ path:", path)
- const parsedPath = path.split('/')
- if(path.includes('/')) {
- path = parsedPath[0]
+ const parsedPath = path.split('/');
+ if (path.includes('/')) {
+ path = parsedPath[0];
}
const routeHtml = routes[path] || routes['home'];
@@ -33,23 +32,23 @@ async function handleLocation(path: string) {
if (content) {
const html = await fetch(routeHtml).then((data) => data.text());
content.innerHTML = html;
-
await new Promise(requestAnimationFrame);
+ injectHeader();
if (path === 'home') {
const { initHomePage } = await import('./pages/home/home');
initHomePage();
} else if (path === 'process') {
const { init } = await import('./pages/process/process');
- init()
- } else if(path.includes('process-element')) {
+ init();
+ } else if (path.includes('process-element')) {
const { initProcessElement } = await import('./pages/process-element/process-element');
- if(parsedPath && parsedPath.length) {
- const parseProcess = parsedPath[1].split('_')
- initProcessElement(parseProcess[0], parseProcess[1])
+ if (parsedPath && parsedPath.length) {
+ const parseProcess = parsedPath[1].split('_');
+ initProcessElement(parseProcess[0], parseProcess[1]);
}
}
- currentRoute = path
+ currentRoute = path;
}
}
@@ -71,20 +70,20 @@ async function init(): Promise {
await services.restoreProcesses();
await services.restoreMessages();
- // if (services.isPaired()) {
- // isPaired = true;
- // console.log('π ~ setTimeout ~ isPaired:', isPaired);
- // await navigate('process');
- // return isPaired;
- // } else {
- // const queryString = window.location.search;
- // const urlParams = new URLSearchParams(queryString);
- // const pairingAddress = urlParams.get('sp_address');
- // if (pairingAddress) {
- // setTimeout(async () => await services.sendPairingTx(pairingAddress), 2000);
- // }
- // return isPaired;
- // }
+ if (services.isPaired()) {
+ isPaired = true;
+ console.log('π ~ setTimeout ~ isPaired:', isPaired);
+ await navigate('process');
+ return isPaired;
+ } else {
+ const queryString = window.location.search;
+ const urlParams = new URLSearchParams(queryString);
+ const pairingAddress = urlParams.get('sp_address');
+ if (pairingAddress) {
+ setTimeout(async () => await services.sendPairingTx(pairingAddress), 2000);
+ }
+ return isPaired;
+ }
}, 200);
} catch (error) {
console.error(error);
@@ -93,8 +92,21 @@ async function init(): Promise {
return isPaired;
}
+async function injectHeader() {
+ const headerContainer = document.getElementById('header-container');
+ if (headerContainer) {
+ const headerHtml = await fetch('/src/components/header/header.html').then((res) => res.text());
+ headerContainer.innerHTML = headerHtml;
+
+ // Dynamically load the header JS
+ const script = document.createElement('script');
+ script.src = '/src/components/header/header.js';
+ script.type = 'module';
+ document.head.appendChild(script);
+ }
+}
+
(async () => {
const isPaired = await init();
- console.log('π ~ handleLocation ~ isPaired:', isPaired);
- await navigate('process');
+ await navigate('home');
})();
diff --git a/src/services/service.ts b/src/services/service.ts
index d8eb583..65b67c4 100644
--- a/src/services/service.ts
+++ b/src/services/service.ts
@@ -522,7 +522,7 @@ export default class Services {
console.error('Services ~ Error:', e);
}
- if(currentRoute === 'home') {
+ if (currentRoute === 'home') {
this.generateQRCode(spAddress || '');
//Adress to Emoji integration
this.displayEmojis(spAddress);
@@ -535,7 +535,7 @@ export default class Services {
try {
await this.sdkClient.restore_device(device);
const spAddress = this.sdkClient.get_address();
- if(currentRoute === 'home') {
+ if (currentRoute === 'home') {
this.generateQRCode(spAddress || '');
//Adress to Emoji integration
this.displayEmojis(spAddress);
@@ -548,69 +548,78 @@ export default class Services {
async getProcesses(): Promise {
const process = [
- ['1',{
- title: 'Messaging',
- description: 'Messagerie chiffrΓ©e',
- html: '',
- css: '',
- script: '',
- zones: [{
- id: '1',
- title: 'zone 1',
- description: 'zone 1'
- },
+ [
+ '1',
{
- id: '2',
- title: 'zone 2',
- description: 'zone 2'
- }],
- roles: {
- owner: {
- members: ['dfdsfdfdsf', 'dfdfdfdsfsfdfdsf'],
- validation_rules: [
- {
- quorum: 1.0,
- fields: ['description', 'roles', 'session_privkey', 'session_pubkey', 'key_parity'],
- min_sig_member: 1.0,
- },
- ],
+ title: 'Messaging',
+ description: 'Messagerie chiffrΓ©e',
+ html: '',
+ css: '',
+ script: '',
+ zones: [
+ {
+ id: '1',
+ title: 'zone 1',
+ description: 'zone 1',
+ },
+ {
+ id: '2',
+ title: 'zone 2',
+ description: 'zone 2',
+ },
+ ],
+ roles: {
+ owner: {
+ members: ['dfdsfdfdsf', 'dfdfdfdsfsfdfdsf'],
+ validation_rules: [
+ {
+ quorum: 1.0,
+ fields: ['description', 'roles', 'session_privkey', 'session_pubkey', 'key_parity'],
+ min_sig_member: 1.0,
+ },
+ ],
+ },
},
},
- }],
- ['2',{
- title: 'Database',
- description: 'Database chiffrΓ©e',
- html: '',
- css: '',
- script: '',
- zones: [{
- id: '1',
- title: 'zone 1',
- description: 'zone 1'
- },
+ ],
+ [
+ '2',
{
- id: '2',
- title: 'zone 2',
- description: 'zone 2'
- }],
- roles: {
- owner: {
- members: ['dfdsfdfdsf', 'dfdfdfdsfsfdfdsf'],
- validation_rules: [
- {
- quorum: 1.0,
- fields: ['description', 'roles', 'session_privkey', 'session_pubkey', 'key_parity'],
- min_sig_member: 1.0,
- },
- ],
+ title: 'Database',
+ description: 'Database chiffrΓ©e',
+ html: '',
+ css: '',
+ script: '',
+ zones: [
+ {
+ id: '1',
+ title: 'zone 1',
+ description: 'zone 1',
+ },
+ {
+ id: '2',
+ title: 'zone 2',
+ description: 'zone 2',
+ },
+ ],
+ roles: {
+ owner: {
+ members: ['dfdsfdfdsf', 'dfdfdfdsfsfdfdsf'],
+ validation_rules: [
+ {
+ quorum: 1.0,
+ fields: ['description', 'roles', 'session_privkey', 'session_pubkey', 'key_parity'],
+ min_sig_member: 1.0,
+ },
+ ],
+ },
},
},
- }],
+ ],
];
- return process
+ return process;
}
-
private getProcessesCache(): ProcessesCache {
// Regular expression to match 64-character hexadecimal strings
const hexU32KeyRegex: RegExp = /^[0-9a-fA-F]{64}:\d+$/;
@@ -709,7 +718,7 @@ export default class Services {
}
public async setProcessesInSelectElement(processList: any[]) {
- console.log("π ~ Services ~ setProcessesInSelectElement ~ processList:", processList)
+ console.log('π ~ Services ~ setProcessesInSelectElement ~ processList:', processList);
const select = document.querySelector('.select-field');
if (select) {
for (const process of processList) {