diff --git a/app/static/app.css b/app/static/app.css index 8967784..f8b989f 100644 --- a/app/static/app.css +++ b/app/static/app.css @@ -573,7 +573,7 @@ kbd { two halves split the width, so the choice is one target each rather than two words pushed against the edge. */ .seg { display: flex; } -#sort { padding: 0 .3rem; } +#sort, #f-track { padding: 0 .3rem; } #rail .seg button { flex: 1; text-align: center; font-size: .8rem; padding: .18rem .55rem; @@ -644,13 +644,12 @@ kbd { .rail-fields { display: flex; flex-direction: column; gap: .45rem; padding-top: .6rem; } .rail-fields input[type="text"], .rail-fields select { width: auto; } .rail-fields .check { padding: 0 .3rem; white-space: normal; } -/* A filter and what widens it: Seniority's heading, its levels and "no - level"; Pay's select and "no pay". Closer together than the fields. */ +/* A filter and what widens it: Seniority's heading, its From and To, the + track and "no level"; Pay's select and "no pay". Closer together than the + fields. */ .rail-facet { display: flex; flex-direction: column; gap: .3rem; } .rail-fields .rail-field { margin: .25rem .3rem 0; } .rail-facet .check { font-size: .84rem; } -/* The levels are the tags' chips, and wrap as they do. */ -#f-seniority:not(:empty) { display: flex; flex-wrap: wrap; gap: .25rem; padding: 0 .3rem; } /* `?company=` and `?place=` from another page's link: a plain chip under its field, which takes it off. */ .rail-legacy { padding: 0 .3rem; } diff --git a/app/static/roles.js b/app/static/roles.js index 2fa4bd0..7814ac4 100644 --- a/app/static/roles.js +++ b/app/static/roles.js @@ -37,7 +37,7 @@ * * The filters are in the query string, so a reload or a link keeps them, and * each one set is a history entry, so back takes it off again: a tag, the - * period, Show read, a select, a checkbox, a seniority level, a company or + * period, Show read, a select, a checkbox, a seniority bound or track, a company or * place chip picked or removed, Clear, and a company's name. Text is the * exception: the search box replaces the entry, or back would step through a * search a letter at a time. Who is viewing and the @@ -70,8 +70,11 @@ * `region:skane`), several joined by OR. `?company=` and `?place=`, the * substrings of the links from other pages, still filter and show as a chip * of their own to take off; nothing in the rail types a new one. Seniority + * (a From and a To rung and a Track, `level_from`, `level_to` and `track`) * and Pay carry the counts of `/api/roles/facets`, asked after each reload - * with the feed's own parameters, so each says what a click would add. + * with the feed's own parameters, so each says what a click would add. The + * rungs and which level is on which come from the page (`ROLEDESK_LADDER`), + * an old `?seniority=` is ignored. * * The list is paged: 60 rows, then 60 more each time the end of the list comes * within 600px of the screen, with the offset the rows already shown. Back to @@ -101,6 +104,17 @@ const VIEWING = "roledesk.agent"; const number = new Intl.NumberFormat("en"); + // The seniority ladder from the page: `rungs` in order and, for each level + // word, its rung (an index into them) and track (`app.models.LADDER`). + const LADDER = window.ROLEDESK_LADDER; + // What each rung is called on each side of the ladder, [individual, people]. + // The rungs below Staff have no side and are named as they are. + const RUNG_SIDES = { + staff: ["Staff", "Manager"], principal: ["Principal", "Senior Manager"], + distinguished: ["Distinguished", "Director"], + }; + const TRACKS = { "": "Both", ic: "Individual", people: "People" }; + // What the list is in the order of. Best first is the viewing agent's // score, moved by its votes; Newest first is first seen. const SORTS = { score: "Best first", time: "Newest first" }; @@ -120,26 +134,27 @@ // Everything `clearFilters` has to put back, in one place, so a new filter // added here cannot be forgotten there. `company` and `place` are the // substrings of links from other pages; `companyKeys` and `places` are the - // rail's chips. `seniorityUnknown` and `payUnknown` are the "and roles - // with no level / no pay" boxes, asked only while a level or a pay option - // is picked. + // rail's chips. `levelFrom`, `levelTo` and `track` are the seniority range; + // `seniorityUnknown` and `payUnknown` are the "and roles with no level / no + // pay" boxes, asked only while a range, a track or a pay option is picked. function blankFilter() { return { sort: "score", agent: null, period: "all", tags: new Set(), showRead: true, company: "", place: "", function: "", remote: "", judged: "", pay: "", showMuted: false, gated: false, companyKeys: [], places: [], - seniority: [], seniorityUnknown: true, payUnknown: false, + levelFrom: "", levelTo: "", track: "", seniorityUnknown: true, payUnknown: false, }; } /** How many filters are on, for the burger; `more` counts only the ones - under "More filters", for its summary. A chip or a level is one each, - as a tag is; the "no level" and "no pay" boxes widen a filter already + under "More filters", for its summary. A chip, a bound or the track is + one each, as a tag is; the "no level" and "no pay" boxes widen a filter already counted. */ function filtersOn(f = state.filter, { more = false } = {}) { const folded = [f.company.trim(), f.place.trim(), f.function, f.remote, f.pay, f.judged, f.showMuted, sortShown() === "score" && f.gated].filter(Boolean).length - + f.companyKeys.length + f.places.length + f.seniority.length; + + f.companyKeys.length + f.places.length + + [f.levelFrom, f.levelTo, f.track].filter(Boolean).length; if (more) return folded; return folded + [!f.showRead, f.period !== "all"].filter(Boolean).length + f.tags.size; } @@ -189,6 +204,9 @@ const sortShown = () => (state.filter.sort === "score" && state.filter.agent !== null ? "score" : "time"); + /** Whether a bound or a track is set, which is what "no level" asks about. */ + const seniorityOn = (f = state.filter) => Boolean(f.levelFrom || f.levelTo || f.track); + /** The feed's query for a filter, the one on screen unless told. */ function feedParams(f = state.filter, q = state.q) { const p = new URLSearchParams(); @@ -202,9 +220,11 @@ f.tags.forEach((t) => p.append("tags", t)); f.companyKeys.forEach((key) => p.append("company_keys", key)); f.places.forEach((token) => p.append("places", token)); - f.seniority.forEach((level) => p.append("seniority", level)); + for (const [param, key] of [["level_from", "levelFrom"], ["level_to", "levelTo"], ["track", "track"]]) { + if (f[key]) p.set(param, f[key]); + } // Each box is sent only off its default, and only while its filter is on. - if (f.seniority.length && !f.seniorityUnknown) p.set("seniority_unknown", "false"); + if (seniorityOn(f) && !f.seniorityUnknown) p.set("seniority_unknown", "false"); if (f.pay && f.payUnknown) p.set("pay_unknown", "true"); if (f.agent !== null) { p.set("agent", String(f.agent)); @@ -236,7 +256,10 @@ f.tags = new Set(q.getAll("tags")); f.companyKeys = [...new Set(q.getAll("company_keys").filter(Boolean))]; f.places = [...new Set(q.getAll("places").filter(Boolean))]; - f.seniority = [...new Set(q.getAll("seniority").filter(Boolean))]; + // A name the ladder does not know is dropped, rather than sent for a 422. + f.levelFrom = LADDER.rungs.includes(q.get("level_from")) ? q.get("level_from") : ""; + f.levelTo = LADDER.rungs.includes(q.get("level_to")) ? q.get("level_to") : ""; + f.track = q.get("track") in TRACKS ? q.get("track") : ""; f.seniorityUnknown = q.get("seniority_unknown") !== "false"; f.payUnknown = q.get("pay_unknown") === "true"; if (!view) return; @@ -688,8 +711,6 @@ el.querySelector("button").onclick = () => setFilter({ [key]: "" }); } - const levelLabel = (level) => level.charAt(0).toUpperCase() + level.slice(1); - /* Which of the facet's pay states each Pay option keeps (`Store.PAY`), so the option's count is theirs added up: 'stated' in the facet is a line with no figure, the option "stated_only". */ @@ -698,33 +719,50 @@ normalised: ["normalised"], stated_only: ["stated"], }; - /* Seniority and Pay with their counts. The levels are the facet's, in the - server's order; until it answers, the ones pressed, so a level read from - the address can be taken off at once. Built again only when a level, - a count or a press changed, so a pressed button keeps its focus. */ + /* A rung's name on the track chosen: with both, the two sides together. */ + function rungLabel(rung, track) { + const sides = RUNG_SIDES[rung]; + if (!sides) return rung.charAt(0).toUpperCase() + rung.slice(1); + return track === "ic" ? sides[0] : track === "people" ? sides[1] : sides.join(" / "); + } + + /* How many roles a rung holds on the track chosen, the facet's per-level + counts added up: a level with no track counts on either. Undefined + until the facet answers. */ + function rungCount(facets, rung, track) { + if (!facets) return undefined; + const at = LADDER.rungs.indexOf(rung); + return facets.seniority.reduce((sum, x) => { + const place = LADDER.levels[x.value]; + return place && place[0] === at && (!track || !place[1] || place[1] === track) + ? sum + x.count : sum; + }, 0); + } + + /* Seniority and Pay with their counts. The rungs of both selects are the + ladder's, worded for the track; the option is set only when its text + changed, since the rail is drawn again on every filter and rewriting an + open select shuts it. */ function renderFacets() { const f = state.filter; const facets = state.facets; const countOf = (list, value) => list?.find((x) => x.value === value)?.count; const shown = (n) => (n === undefined ? "" : number.format(n)); - const levels = facets ? facets.seniority.map((x) => x.value).filter(Boolean) : []; - for (const level of f.seniority) if (!levels.includes(level)) levels.push(level); - const row = $("#f-seniority"); - const counts = levels.map((level) => countOf(facets?.seniority, level)); - const sig = JSON.stringify([levels, counts, f.seniority]); - if (row.dataset.key !== sig) { - row.dataset.key = sig; - row.innerHTML = levels.map((level, i) => ` - `).join(""); - row.querySelectorAll("[data-level]").forEach((b) => { - b.onclick = () => toggleLevel(b.dataset.level); + for (const [id, key] of [["f-level-from", "levelFrom"], ["f-level-to", "levelTo"]]) { + const select = document.getElementById(id); + LADDER.rungs.forEach((rung, i) => { + const n = rungCount(facets, rung, f.track); + const text = rungLabel(rung, f.track) + (n === undefined ? "" : ` ยท ${shown(n)}`); + const option = select.options[i + 1]; + if (option.textContent !== text) option.textContent = text; }); + setValue(id, f[key]); } - $("#f-seniority-unknown-row").hidden = !f.seniority.length; + $("#f-track").querySelectorAll("[data-track]").forEach((b) => { + b.setAttribute("aria-pressed", String(f.track === b.dataset.track)); + }); + $("#f-seniority-unknown-row").hidden = !seniorityOn(f); setValue("f-seniority-unknown", f.seniorityUnknown); $("#f-seniority-unknown-count").textContent = shown(countOf(facets?.seniority, "")); @@ -740,13 +778,11 @@ $("#f-pay-unknown-count").textContent = shown(countOf(facets?.pay, "")); } - /* A level pressed or let go, pushed as a filter. The last one let go + /* A bound or the track set, pushed as a filter. The last one taken off ticks "no level" again, which is how the box starts for the next. */ - function toggleLevel(level) { - const f = state.filter; - const next = f.seniority.includes(level) - ? f.seniority.filter((l) => l !== level) : [...f.seniority, level]; - setFilter({ seniority: next, seniorityUnknown: next.length ? f.seniorityUnknown : true }); + function setSeniority(patch) { + const next = { ...state.filter, ...patch }; + setFilter({ ...patch, seniorityUnknown: seniorityOn(next) ? next.seniorityUnknown : true }); } /* Viewing as: a select of the enabled agents, also when there is one, and @@ -1636,6 +1672,17 @@ })); $("#f-pay-unknown").addEventListener("change", (e) => setFilter({ payUnknown: e.target.checked })); + // From and To hold "" and the rungs; the options are the ladder's. + for (const [id, key] of [["f-level-from", "levelFrom"], ["f-level-to", "levelTo"]]) { + $(`#${id}`).innerHTML = `` + LADDER.rungs.map((rung) => + ``).join(""); + $(`#${id}`).addEventListener("change", (e) => setSeniority({ [key]: e.target.value })); + } + $("#f-track").innerHTML = Object.entries(TRACKS).map(([key, label]) => + ``).join(""); + $("#f-track").querySelectorAll("[data-track]").forEach((b) => { + b.onclick = () => { if (b.dataset.track !== state.filter.track) setSeniority({ track: b.dataset.track }); }; + }); $("#f-seniority-unknown").addEventListener("change", (e) => setFilter({ seniorityUnknown: e.target.checked })); $("#f-show-muted").addEventListener("change", diff --git a/app/templates/roles.html b/app/templates/roles.html index 1966cb9..1e191d0 100644 --- a/app/templates/roles.html +++ b/app/templates/roles.html @@ -78,12 +78,18 @@
- {# The levels come with their counts from /api/roles/facets, so the - server's list is the one shown. "No level" is a question only - once a level is pressed. #} + {# From and to are the rungs of `app.models.RUNGS`, drawn by roles.js + from `ROLEDESK_LADDER` with counts from + /api/roles/facets; the track says which side of the ladder + counts. "No level" is a question only once a bound or a track is + set. #}
Seniority -
+ + + + +