From bfb99c1b9253f935c50cb01b3222c21c49f32309 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Pasquier <contact@jbpasquier.eu> Date: Wed, 20 Jul 2022 15:06:22 +0200 Subject: [PATCH] feature: solid-directory widget --- src/custom-tzcld.js | 90 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) diff --git a/src/custom-tzcld.js b/src/custom-tzcld.js index 0c7cbb1..478215a 100644 --- a/src/custom-tzcld.js +++ b/src/custom-tzcld.js @@ -1,7 +1,8 @@ import("./utils.js").then((utils) => { import(utils.coreVersion()).then((core) => { + core.Sib.register({ - name: "customtzcld-display-widget", + name: "customtzcld-display-community-widget", use: [core.StoreMixin], empty() { @@ -27,7 +28,7 @@ import("./utils.js").then((utils) => { contact_mail_2: await this.resource.contact_mail_2, contact_mail_3: await this.resource.contact_mail_3, membership: await this.resource.membership, - last_contribution_year: await this.resource.last_contribution_year, + last_contribution_year: await this.resource.last_contribution_year }; if("label" in this.element.attributes) { for(let ignore of this.element.attributes['label'].value.split(',')) { @@ -76,5 +77,90 @@ import("./utils.js").then((utils) => { this.element.innerHTML = render; }, }); + + core.Sib.register({ + name: "customtzcld-display-profile-widget", + use: [core.StoreMixin], + + empty() { + this.element.innerHTML = ""; + }, + + async populate() { + this.element.innerHTML = ` + <div class="loader"> + <div></div> + <div></div> + <div></div> + <div></div> + </div>`; + let tzcldprofile = { + description: await this.resource.description, + postal_code: await this.resource.postal_code, + address: await this.resource.address, + phone: await this.resource.phone, + position: await this.resource.position, + membership: await this.resource.membership, + last_contribution_year: await this.resource.last_contribution_year, + events: await this.resource["events.ldp:contains"], + orgs: await this.resource["orgs.ldp:contains"], + regions: await this.resource["regions.ldp:contains"] + }; + if("label" in this.element.attributes) { + for(let ignore of this.element.attributes['label'].value.split(',')) { + tzcldprofile[ignore.trim()] = null; + } + } + let render = "<div class='border-top margin-medium border-color-grey'></div>"; + if(tzcldprofile.description) { + render += `<div class="segment block"><span class="text-semibold text-uppercase text-color-heading">Description</span>: ${tzcldprofile.description}</div>`; + } + if(tzcldprofile.regions && tzcldprofile.regions.length > 0) { + render += `<div class="segment block"><span class="text-semibold text-uppercase text-color-heading">Région / Département</span>: `; + for(let region of tzcldprofile.regions) { + render += `${await region['name']}, `; + } + render = render.slice(0, -7); + render += `</div>`; + } + if(tzcldprofile.postal_code) { + render += `<div class="segment block"><span class="text-semibold text-uppercase text-color-heading">Code postal</span>: ${tzcldprofile.postal_code}</div>`; + } + if(tzcldprofile.address) { + render += `<div class="segment block"><span class="text-semibold text-uppercase text-color-heading">Adresse postale</span>: ${tzcldprofile.address}</div>`; + } + if(tzcldprofile.events && tzcldprofile.events.length > 0) { + render += `<div class="segment block"><span class="text-semibold text-uppercase text-color-heading">Évènements marquants</span>: `; + for(let event of tzcldprofile.events) { + render += `${await event['name']}, `; + } + render = render.slice(0, -7); + render += `</div>`; + } + if(tzcldprofile.orgs && tzcldprofile.orgs.length > 0) { + render += `<div class="segment block"><span class="text-semibold text-uppercase text-color-heading">Organisation ou Territoire</span>: `; + for(let org of tzcldprofile.orgs) { + render += `${await org['name']}, `; + } + render = render.slice(0, -7); + render += `</div>`; + } + if(tzcldprofile.position) { + render += `<div class="segment block"><span class="text-semibold text-uppercase text-color-heading">Poste occupé</span>: ${tzcldprofile.position}</div>`; + } + if(tzcldprofile.membership) { + render += `<div class="segment block"><span class="text-semibold text-uppercase text-color-heading">Adhésion</span>: <input type="checkbox" checked disabled /></div>`; + } + if(!tzcldprofile.membership) { + render += `<div class="segment block"><span class="text-semibold text-uppercase text-color-heading">Adhésion</span>: <input type="checkbox" disabled /></div>`; + } + if(tzcldprofile.last_contribution_year) { + render += `<div class="segment block"><span class="text-semibold text-uppercase text-color-heading">Année dernière cotisation</span>: ${tzcldprofile.last_contribution_year}</div>`; + } + render += "<div class='border-top margin-medium border-color-grey'></div>"; + this.element.innerHTML = render; + }, + }); + }); }); -- GitLab