Commit 260e22fb authored by Nicolas Mérigot's avatar Nicolas Mérigot

Merge branch 'fix/remove_id_prefix' into 'master'

fix: remove id prefix, use b64 url encoded iri id instead

Closes #23

See merge request !2
parents dc940e55 e3edc760
......@@ -27,23 +27,39 @@ export class SIBRoute extends HTMLElement {
return this.closest('sib-router');
}
get resourceId() {
//get resource id from url
if(this.hasAttribute('id-prefix') && this.router.currentURL.split('/')[1])
return this.getAttribute('id-prefix') + this.router.currentURL.split('/')[1] + '/';
if(this.router.currentURL.split('/')[1]) {
return this.decodeId(this.router.currentURL.split('/')[1]);
}
return '';
}
getPath(prefix, name, id) {
if(id && this.hasAttribute('id-prefix'))
id = id.replace(this.getAttribute('id-prefix'), '');
return [prefix, name, id].filter(s=>s).join('/');
encodeId(id) {
if (id) {
return btoa(unescape(encodeURIComponent(id)));
}
return;
}
decodeId(id) {
if(id) {
return decodeURIComponent(escape(atob(id)));
}
return;
}
getPath(prefix, name, id = '') {
const encodedId = this.encodeId(id);
return [prefix, name, encodedId].filter(s=>s).join('/');
}
updateResource() {
if(this.resourceId) {
if(this.view.hasAttribute('bind-resources'))
if(this.view.hasAttribute('bind-resources')) {
this.view.setAttribute('data-src', this.resourceId);
for(let element of this.view.querySelectorAll('[bind-resources]'))
}
for(let element of this.view.querySelectorAll('[bind-resources]')) {
element.setAttribute('data-src', this.resourceId);
}
}
}
updateSubrouter(router) {
......@@ -116,10 +132,10 @@ export class SIBRouter extends HTMLElement {
navigate(routeName = '', resource) {
const route = this.querySelector('sib-route[name='+routeName+']');
if(!route) return; //this route is not for me!
const id = resource ? resource['@id'] : null;
const path = route.getPath(this.prefix, routeName, id)
route.getPath(this.prefix, routeName, id);
//update current URL
if(this.useHash)
window.location.hash = path;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment