Skip to content

Commit

Permalink
select multiple techs from header (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahfossheim committed Aug 2, 2023
1 parent 70c76be commit a3d95e6
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 355 deletions.
78 changes: 73 additions & 5 deletions src/js/components/filters.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
function updateTechnologies(technologies, filters) {
const selectAll = document.querySelectorAll('select.tech');
/* Get existing tech selectors on the page */
const allTechSelectors = document.querySelectorAll('select.tech');

selectAll.forEach(select => {
select.innerHTML = '';
/* Update the options inside all of the selectors */
allTechSelectors.forEach(techSelector => {
techSelector.innerHTML = '';

/* Add one option per technology */
technologies.forEach((technology) => {
const optionTmpl = document.getElementById('filter-option').content.cloneNode(true);
const option = optionTmpl.querySelector('option');
const formattedTech = technology.app.replaceAll(" ", "-");
option.textContent = technology.app;
option.value = formattedTech;
if(formattedTech === select.getAttribute('data-selected')) {
if(formattedTech === techSelector.getAttribute('data-selected')) {
option.selected = true;
}
select.append(optionTmpl);
techSelector.append(optionTmpl);
});
})
}
Expand Down Expand Up @@ -50,7 +53,72 @@ function updateRank(ranks, filters) {
});
}

function bindFilterListener() {
const submit = document.getElementById('submit-form');
if(submit) {
submit.addEventListener('click', setFilter);
}

const add = document.getElementById('add-tech');
if(add) {
add.addEventListener('click', addTechnologySelector);
}
}

function addTechnologySelector(event) {
event.preventDefault();

const selectorTemplate = document.getElementById('tech-selector').content.cloneNode(true);
const selectElement = selectorTemplate.querySelector('select');
const labelElement = selectorTemplate.querySelector('label');
const techId = `tech-${document.querySelectorAll('select.tech[name="tech"]').length + 1}`;
selectElement.setAttribute('id', techId);
labelElement.setAttribute('for', techId);

selectElement.innerHTML = document.querySelector('select.tech').innerHTML;
const firstOption = selectElement.querySelector('option');
firstOption.selected = true;

const techs = document.getElementsByName('tech');
const last = techs[techs.length - 1];

last.after(selectorTemplate);
}

function setFilter(event) {
event.preventDefault();

const url = new URL(location.href);

/* Get the geo and rank filter */
const geo = document.getElementsByName('geo')[0].value;
const rank = document.getElementsByName('rank')[0].value;

/* Create a string of technologies */
let technologies = [];
document.getElementsByName('tech').forEach(technology => {
technologies.push(technology.value);
});
technologies.join(",");

/* Modify the URL with the tech */
url.searchParams.delete('tech');
url.searchParams.append('tech', technologies);

url.searchParams.delete('geo');
url.searchParams.append('geo', geo);

url.searchParams.delete('rank');
url.searchParams.append('rank', rank);


/* Update the url */
location.href = url;

}

export const Filters = {
bindFilterListener,
updateTechnologies,
updateGeo,
updateRank,
Expand Down
15 changes: 8 additions & 7 deletions src/js/techreport.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ class TechReport {

this.bindClientListener();
this.getAllData();

Filters.bindFilterListener();
}

bindClientListener() {
const select = document.getElementById('client-breakdown');
if(select) {
select.onchange = (event) => {
const client = event.target.value;
const allDataComponents = document.querySelectorAll('[data-scope]');
allDataComponents.forEach(component => {
component.setAttribute('client', client);
});
}
const client = event.target.value;
const allDataComponents = document.querySelectorAll('[data-scope]');
allDataComponents.forEach(component => {
component.setAttribute('client', client);
});
}
}
}

Expand Down Expand Up @@ -122,7 +124,6 @@ class TechReport {
});
}


updateComparisonComponents(data) {
const allDataComponents = document.querySelectorAll('[data-scope="all-data"]');

Expand Down
124 changes: 0 additions & 124 deletions templates/techreport/components/cwv_overview.html

This file was deleted.

50 changes: 0 additions & 50 deletions templates/techreport/components/filterbar.html

This file was deleted.

37 changes: 0 additions & 37 deletions templates/techreport/components/heading.html

This file was deleted.

11 changes: 0 additions & 11 deletions templates/techreport/components/summary_linked.html

This file was deleted.

34 changes: 0 additions & 34 deletions templates/techreport/components/table.html

This file was deleted.

Loading

0 comments on commit a3d95e6

Please sign in to comment.