Skip to content

Commit

Permalink
adds act/sar and act/catalog pages
Browse files Browse the repository at this point in the history
renames companyType to organizationType in sar
  • Loading branch information
andreaskundig committed Jun 30, 2021
1 parent 0f8d223 commit a7955c1
Show file tree
Hide file tree
Showing 10 changed files with 590 additions and 0 deletions.
58 changes: 58 additions & 0 deletions conf/netlify/cms/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ collections:
widget: markdown, buttons: [bold, italic, link], editor_components: [], minimal: true}
- { label: Stories about, name: stories_about, required: true, i18n: true,
widget: markdown, buttons: [bold, italic, link], editor_components: [], minimal: true}
- label: SAR Form text fragments
name: sar-form
file: src/site/_data/i18n/assets/sar-form.json
i18n: true
fields:
- { label: App type name, name: app_type_name, required: true, widget: string, i18n: true }
- { label: Select placeholder, name: select_placeholder, required: true, widget: string, i18n: true }
- { label: Search placeholder, name: search_placeholder, required: true, widget: string, i18n: true }
- { label: Recipient, name: recipient, required: true, widget: string, i18n: true }
- { label: Subject, name: subject, required: true, widget: string, i18n: true }
- { label: Body, name: body, required: true, widget: string, i18n: true }
- { label: Body placeholder, name: body_placeholder, required: true, widget: string, i18n: true }
- { label: Copy button, name: copy_button, required: true, widget: string, i18n: true }
- { label: E-mail button, name: email_button, required: true, widget: string, i18n: true }
- { label: Preview of e-mail, name: preview_of_email, required: true, widget: string, i18n: true }
- { label: Preview of e-mail to, name: preview_of_email_to, required: true, widget: string, i18n: true }
- { label: Explanation, name: explanation, required: true, widget: string, i18n: true }
- { label: Parts to fill in, name: to_fill_in, required: true, widget: string, i18n: true }
- label: ‹Configuration›
name: configuration
files:
Expand Down Expand Up @@ -301,6 +319,46 @@ collections:
- { label: "Lead image caption", name: lead_image_caption, required: false, i18n: true,
widget: markdown, buttons: [bold, italic, link], editor_components: [], minimal: true }

- label: Act › SAR
name: sar
folder: src/site/act/sar
extension: md
editor:
preview: false
create: false
delete: false
i18n: true
preview_path: /en/act/sar/
fields:
- { label: "Browser tab title", name: title, required: false, widget: string, i18n: true }
- { label: Lead , name: lead, required: false, widget: markdown, i18n: true }
- { label: Lead image , name: lead_image, required: false, widget: image, i18n: true }
- { label: "Lead image caption", name: lead_image_caption, required: false, i18n: true,
widget: markdown, buttons: [bold, italic, link], editor_components: [], minimal: true }
- { label: Body , name: body, required: false, widget: markdown, i18n: true }
- { label: "SAR title" , name: sar_title , required: false, i18n: true,
widget: markdown, buttons: [bold, italic, link], editor_components: [], minimal: true}
- { label: "SAR subtitle" , name: sar_sub_title , required: false, i18n: true,
widget: markdown, buttons: [bold, italic, link], editor_components: [], minimal: true}
- { label: Personaldata.io organization type, name: organization_type, required: true, widget: string,
hint: "Online dating application: Q5066"}
- { label: Name of personaldata.io wikitext template, name: mailto_template_name, required: true, widget: string, i18n: true }

- label: Act › Catalog
name: catalog
folder: src/site/act/catalog
extension: md
editor:
preview: false
create: false
delete: false
i18n: true
preview_path: /en/catalog/
fields:
- { label: "Browser tab title", name: title, required: false, widget: string, i18n: true }
- { label: Lead , name: lead, required: false, widget: markdown, i18n: true }
- { label: Body , name: body, required: false, widget: markdown, i18n: true }

- label: Legal
name: legal
folder: src/site/legal
Expand Down
91 changes: 91 additions & 0 deletions src/components/sar-helper/personaldata-io.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
export const URL_WIKI_PERSONALDATA_IO = 'wiki.personaldata.io';
export const URL_PERSONALDATA_IO = 'query.personaldata.io/proxy/wdqs/bigdata/namespace/wdq/';

export const ITEM_ONLINE_DATING_APPLICATION = 'pdio:Q5066';
export const vocabulary = {
items: {
onlineDatingApplication: ITEM_ONLINE_DATING_APPLICATION,
},
properties: {
instanceOf: 'pdiot:P3',
country: 'pdiot:P55',
email: 'pdiot:P17',
collects: "pdiot:P10",
requires: "pdiot:P122",
}
};

export const TEMPLATE_MAILTO_ACCESS = 'MailtoAccess';
export const TEMPLATE_MAILTO_SWISS_ACCESS = 'MailtoSwissAccess';

// sorry for the dumb enum
export const templates = {
MailtoAccess: TEMPLATE_MAILTO_ACCESS,
MailtoSwissAccess: TEMPLATE_MAILTO_SWISS_ACCESS,
Access: 'Access',
SwissAccess: 'SwissAccess',
Mailto: 'Mailto'
};

const t = templates;
const {properties: p} = vocabulary;

const sparqlEmailAndItemsOfInstance = (item) =>
`SELECT ?item ?itemLabel ?mail WHERE {
?item ${p.instanceOf} ${item}.
?item ${p.email} ?mail.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} `;

export async function query(sparqlQuery, apiUrl) {
const response = await fetch(
`https://${apiUrl}?origin=*&query=${encodeURIComponent(sparqlQuery)}`,
{ "headers": { "Accept": "application/sparql-results+json" } }
);
return await response.json();
}

export async function expandTemplate(itemId, templateName, wikiUrl) {
let formData = new URLSearchParams();
formData.append('action', 'expandtemplates');
formData.append('text', `{{${templateName}|${itemId}}}`);
formData.append('format', `json`);
formData.append('prop', `wikitext`);
formData.append('origin', `*`);
const response = await fetch(`https://${wikiUrl}/w/api.php`,
{ body: formData, method: 'post'});
const data = await response.json();
return data.expandtemplates.wikitext;
}

export function bindingsAsKeyVals(result){
const {head: {vars}, results: {bindings}} = result;
return bindings.map(binding => {
return vars.reduce((keyVals, v) =>{
if(binding[v]){
keyVals[v] = binding[v].value;
}
return keyVals;
}, {} )
})
};

export async function fetchOrgsOfInstance(item){
const sparql =
sparqlEmailAndItemsOfInstance(item);
const data = await query(sparql, URL_PERSONALDATA_IO);
return bindingsAsKeyVals(data);
}

export async function fetchMailTo(item, template){
const entityId = item.split('/').pop();
const mailTo = await expandTemplate(entityId,
template || t.MailtoAccess,
URL_WIKI_PERSONALDATA_IO);
const url = new URL(mailTo);
const href = url.href;
const recipient = url.pathname;
const body = url.searchParams.get('body');
const subject = url.searchParams.get('subject');
return {recipient, body, subject, href};
}
Loading

0 comments on commit a7955c1

Please sign in to comment.