more of new tiers buttons..

This commit is contained in:
Marcell Mars 2021-08-21 12:28:52 +02:00
parent f5af0012f0
commit 6339510cb8
2 changed files with 57 additions and 77 deletions

View file

@ -187,7 +187,7 @@ select {
background-color: #ffccbc; background-color: #ffccbc;
} }
#newtier { .newtiers {
display: none; display: none;
} }

View file

@ -23,6 +23,17 @@
} }
} }
function reckonHasesCandidates() {
return diffArrr(hases, [
...frontmatter["triad"].map((t) => {
return t.fmKey;
}),
...frontmatter["ascriptions"].map((t) => {
return t.fmKey;
}),
]);
}
function diffArrr(arr, arrr) { function diffArrr(arr, arrr) {
let diff = new Set(arr); let diff = new Set(arr);
for (let e of arrr) { for (let e of arrr) {
@ -31,25 +42,29 @@
return Array.from(diff); return Array.from(diff);
} }
function newTier(fmKeyType, fmKey, fmValue = "") { function newTier(fmKeyType, fmKey, fmValue) {
console.log("newTier", fmKeyType, fmKey); let tiers = [];
let candidates = [];
if (fmKeyType == "ascriptions" && fmKey == "_new") { if (fmKey == "_new") {
hasesCandidates = [... new Set(reckonHasesCandidates())] hasesCandidates = [... new Set(reckonHasesCandidates())]
if (hasesCandidates.length > 0) { if (hasesCandidates.length > 0) {
fmKey = hasesCandidates[0] fmKey = hasesCandidates[0]
console.log(hasesCandidates, fmKey)
} }
} }
let tiers = [];
let candidates = []; if (fmKey != "_new") {
if (fmValue) {
METASP[fmKey].tiers.forEach((t) => { METASP[fmKey].tiers.forEach((t) => {
if (fmValue.includes(t.file)) { if (fmValue.includes(t.file)) {
tiers.push(t); tiers.push(t);
} else { } else {
candidates.push(t); candidates.push(t);
} }
}); })
} else {
tiers = [];
candidates = METASP[fmKey].tiers;
}
frontmatter[fmKeyType].push({ frontmatter[fmKeyType].push({
fmKey: fmKey, fmKey: fmKey,
tiers: tiers, tiers: tiers,
@ -57,31 +72,8 @@
}); });
frontmatter = { ...frontmatter }; frontmatter = { ...frontmatter };
} }
function newHasTiers(arrgs) {
let [fmKeyType, index, oldFmKey, newFmKey] = arrgs.detail;
hasesCandidates = [... new Set(reckonHasesCandidates())] hasesCandidates = [... new Set(reckonHasesCandidates())]
console.log(hasesCandidates) toggleNewTiersButtons()
if (fmKeyType=="triad" && oldFmKey == "_new") {
if (hasesCandidates.length > 0) {
newFmKey = hasesCandidates[0];
if (hasesCandidates.length > 1) {
oldFmKey = hasesCandidates[1]
}
} else {
return
}
}
frontmatter[fmKeyType][index] = {
fmKey: newFmKey,
tiers: [],
candidates: METASP[newFmKey].tiers,
};
hasesCandidates = hasesCandidates.filter((h) => h != newFmKey);
hasesCandidates = [...hasesCandidates, oldFmKey];
toggleNewTriadButton();
} }
function loadHugoPageMetadata(editHash) { function loadHugoPageMetadata(editHash) {
@ -131,22 +123,12 @@
const tkey = Object.keys(repo.frontmatter).filter((t) => t.toLowerCase() == "title")[0]; const tkey = Object.keys(repo.frontmatter).filter((t) => t.toLowerCase() == "title")[0];
title = repo.frontmatter[tkey]; title = repo.frontmatter[tkey];
toggleNewTriadButton(); toggleNewTiersButtons();
}; };
el.src = `../js/repo/${editHash}.js`; el.src = `../js/repo/${editHash}.js`;
document.body.appendChild(el); document.body.appendChild(el);
} }
function reckonHasesCandidates() {
return diffArrr(hases, [
...frontmatter["triad"].map((t) => {
return t.fmKey;
}),
...frontmatter["ascriptions"].map((t) => {
return t.fmKey;
}),
]);
}
function addToCandidatesRemoveFromTiers(arrgs) { function addToCandidatesRemoveFromTiers(arrgs) {
const [fmKeyType, index, fmKey, tier] = arrgs.detail; const [fmKeyType, index, fmKey, tier] = arrgs.detail;
frontmatter[fmKeyType][index]["fmKey"] = fmKey; frontmatter[fmKeyType][index]["fmKey"] = fmKey;
@ -186,25 +168,23 @@
} }
} }
function newFrontmatter() { function toggleNewTiersButtons() {
return Object.entries(frontmatter) hasesCandidates = [... new Set(reckonHasesCandidates())]
.filter((val) => val[1].length == 0)
.map((key) => key[0]);
}
function toggleNewTriadButton() { if (hasesCandidates.length == 0) {
const ct = Object.entries(frontmatter).filter((i) => i[1].length == 0 && i[0] == "triad"); document.querySelectorAll(".newtiers").forEach((button)=> {
if (document.getElementById("newtier")) { button.style.display = "none";
if (ct.length == 0) { })
document.getElementById("newtier").style.display = "none";
} else { } else {
document.getElementById("newtier").style.display = "block"; document.querySelectorAll(".newtiers").forEach((button)=> {
} button.style.display = "block";
} })
} }
function newTriad() { const ct = Object.entries(frontmatter).filter((i) => i[1].length == 0 && i[0] == "triad")[0];
newHasTiers({ detail: ["triad", 0, "_new", ""] }); if (!ct) {
document.getElementById("newtriad").style.display = "none";
}
} }
function dispatchHash() { function dispatchHash() {
@ -214,14 +194,14 @@
loadHugoPageMetadata(editHash); loadHugoPageMetadata(editHash);
} else { } else {
let newPage = searchParams.get("new"); let newPage = searchParams.get("new");
console.log(newPage); console.log({newPage});
} }
} }
onMount(() => { onMount(() => {
dispatchHash(); dispatchHash();
// loadHugoPageMetadata(); // loadHugoPageMetadata();
console.dir(frontmatter); console.dir({frontmatter});
}); });
$: hashChanged = () => dispatchHash(); $: hashChanged = () => dispatchHash();
@ -244,7 +224,7 @@
{fmItem} {fmItem}
{hases} {hases}
{hasesCandidates} {hasesCandidates}
on:hasTiersSelected={newHasTiers} on:hasTiersSelected={newTier}
/> />
<SpTiers <SpTiers
@ -265,8 +245,8 @@
{/each} {/each}
{/each} {/each}
<div class="buttons news"> <div class="buttons news">
<div id="newtier" class="button" on:click={newTriad}>NEW TIER</div> <div id="newtriad" class="newtiers button" on:click={()=> newTier("triad", "_new", null)}>NEW TIER</div>
<div id="newascription" class="button" on:click={() => newTier("ascriptions", "_new")}> <div id="newascription" class="newtiers button" on:click={() => newTier("ascriptions", "_new", null)}>
NEW ASCRIPTION NEW ASCRIPTION
</div> </div>
</div> </div>