swapTiers...

This commit is contained in:
Marcell Mars 2021-08-25 02:31:34 +02:00
parent 2002471837
commit 1aaa952cce
3 changed files with 54 additions and 59 deletions

View file

@ -14,6 +14,7 @@
let hases = []; let hases = [];
let hasesCandidates = []; let hasesCandidates = [];
let frontmatter = {}; let frontmatter = {};
let formaction = "edit";
frontmatter["triad"] = []; frontmatter["triad"] = [];
frontmatter["ascription"] = []; frontmatter["ascription"] = [];
frontmatter["journal"] = []; frontmatter["journal"] = [];
@ -65,6 +66,12 @@
toggleNewTiersButtons(); toggleNewTiersButtons();
} }
function swapTier(arrg) {
const [fmKeyType, fmKey, oldFmKey] = arrg.detail;
removeTier(fmKeyType, oldFmKey);
newTier(fmKeyType, fmKey, null);
}
function newTier(fmKeyType, fmKey, fmValue) { function newTier(fmKeyType, fmKey, fmValue) {
let tiers = []; let tiers = [];
let candidates = []; let candidates = [];
@ -88,6 +95,7 @@
tiers = []; tiers = [];
candidates = METASP[fmKey].tiers; candidates = METASP[fmKey].tiers;
} }
frontmatter[fmKeyType].push({ frontmatter[fmKeyType].push({
fmKey: fmKey, fmKey: fmKey,
tiers: tiers, tiers: tiers,
@ -95,6 +103,7 @@
}); });
frontmatter = { ...frontmatter }; frontmatter = { ...frontmatter };
} }
hasesCandidates = [...new Set(reckonHasesCandidates())]; hasesCandidates = [...new Set(reckonHasesCandidates())];
toggleNewTiersButtons(); toggleNewTiersButtons();
} }
@ -109,7 +118,6 @@
relpath = repo.path; relpath = repo.path;
relpermalink = repo.relpermalink; relpermalink = repo.relpermalink;
protocol = document.location.protocol.substring(0, 4);
const notSelf = Object.entries(METASP).filter((n) => n[1].singular == relpath.split("/")[0])[0][0]; const notSelf = Object.entries(METASP).filter((n) => n[1].singular == relpath.split("/")[0])[0][0];
hases = Object.keys(METASP).filter((k) => k != notSelf); hases = Object.keys(METASP).filter((k) => k != notSelf);
Object.entries(repo.frontmatter).forEach(([fmKey, fmValue]) => { Object.entries(repo.frontmatter).forEach(([fmKey, fmValue]) => {
@ -198,7 +206,6 @@
function toggleNewTiersButtons() { function toggleNewTiersButtons() {
hasesCandidates = [...new Set(reckonHasesCandidates())]; hasesCandidates = [...new Set(reckonHasesCandidates())];
if (hasesCandidates.length == 0) { if (hasesCandidates.length == 0) {
document.querySelectorAll(".newtiers").forEach((button) => { document.querySelectorAll(".newtiers").forEach((button) => {
button.style.display = "none"; button.style.display = "none";
@ -216,13 +223,19 @@
} }
function dispatchHash() { function dispatchHash() {
protocol = document.location.protocol.substring(0, 4);
const searchParams = new URLSearchParams(location.search); const searchParams = new URLSearchParams(location.search);
const editHash = searchParams.get("edit"); const editHash = searchParams.get("edit");
if (editHash) { if (editHash) {
loadHugoPageMetadata(editHash); loadHugoPageMetadata(editHash);
} else { } else {
let newPage = searchParams.get("new"); let newPage = searchParams.get("new");
console.log({ newPage }); formaction = "new";
v = "waiting for your input here...";
title = "Please, change this title...";
relpath = `${newPage}/newfile.md`;
hases = Object.keys(METASP).filter((k) => k != newPage);
toggleNewTiersButtons();
} }
} }
@ -239,7 +252,7 @@
<main id="sandpoints"> <main id="sandpoints">
<form> <form>
<div class="formgrid"> <div class="formgrid">
<SpTitle {relpath} {title} /> <SpTitle {relpath} {title} {formaction} />
</div> </div>
<div id="fmicon" on:click={toggleFold} class="fmCollapse">Frontmatter</div> <div id="fmicon" on:click={toggleFold} class="fmCollapse">Frontmatter</div>
<span id="frontmatter" class="fmHidden"> <span id="frontmatter" class="fmHidden">
@ -257,12 +270,11 @@
</div> </div>
<div class="fmItem"> <div class="fmItem">
<SpKeys <SpKeys
index={i}
fmKeyType={fmItems[0]} fmKeyType={fmItems[0]}
{fmItem} {fmItem}
{hases} {hases}
{hasesCandidates} {hasesCandidates}
on:hasTiersSelected={newTier} on:hasTiersSelected={swapTier}
/> />
<SpTiers <SpTiers
on:addToCandidatesRemoveFromTiers={addToCandidatesRemoveFromTiers} on:addToCandidatesRemoveFromTiers={addToCandidatesRemoveFromTiers}
@ -327,7 +339,7 @@
</div> </div>
</span> </span>
<div class="formgrid"> <div class="formgrid">
<label for="pagecontent">Content:</label> <label for="pagecontent" class="labelcontent">Content:</label>
<textarea <textarea
id="pagecontent" id="pagecontent"
bind:value={v} bind:value={v}
@ -337,10 +349,9 @@
<label for="publish">Publish</label> <label for="publish">Publish</label>
<input type="checkbox" id="publish" name="publish" /> <input type="checkbox" id="publish" name="publish" />
{/if} {/if}
<label for="offline">Offline</label> <label for="offline" class="labeloffline">Offline</label>
<input type="checkbox" id="offline" name="offline" /> <input type="checkbox" id="offline" name="offline" checked={protocol == "file" ? true : false} />
<input type="hidden" name="relpermalink" bind:value={relpermalink} /> <input type="hidden" name="relpermalink" bind:value={relpermalink} />
<input type="hidden" name="relpath" bind:value={relpath} />
<input type="hidden" name="protocol" bind:value={protocol} /> <input type="hidden" name="protocol" bind:value={protocol} />
<button id="sandpointsButton">COMMIT/SAVE</button> <button id="sandpointsButton">COMMIT/SAVE</button>
</div> </div>

View file

@ -1,55 +1,38 @@
<script> <script>
import { createEventDispatcher } from "svelte"; import { createEventDispatcher } from "svelte";
import { onMount } from "svelte"; import { onMount } from "svelte";
export let fmItem; export let fmItem;
export let fmKeyType; export let fmKeyType;
export let index; export let hases;
export let hases; export let hasesCandidates;
export let hasesCandidates; let value;
let value; const dispatch = createEventDispatcher();
const dispatch = createEventDispatcher();
function optselName(has) { function optselName(has) {
return `_${has}_${fmKeyType}`; return `_${has}_${fmKeyType}`;
}
onMount(() => {
const selectEvent = document.getElementById(`${fmKeyType}_${fmItem.fmKey}`);
if (selectEvent) {
selectEvent.addEventListener("change", (e) => {
dispatch("hasTiersSelected", [fmKeyType, e.target.value.split("_")[1], fmItem]);
});
} }
});
onMount(() => {
const selectEvent = document.getElementById(
`${fmKeyType}_${fmItem.fmKey}`
);
if (selectEvent) {
selectEvent.addEventListener("change", (e) => {
dispatch("hasTiersSelected", [
fmKeyType,
index,
fmItem.fmKey,
e.target.value.split("_")[1],
]);
});
}
});
</script> </script>
<select id="{fmKeyType}_{fmItem.fmKey}" bind:value> <select id="{fmKeyType}_{fmItem.fmKey}" bind:value>
{#each hases as has} {#each hases as has}
{#if has == fmItem.fmKey} {#if has == fmItem.fmKey}
<option <option id={optselName(has)} class="hasoption" selected title={has} value={optselName(has)}
id={optselName(has)} >{"triad" == fmKeyType ? "Has " : ""}{has}:</option
class="hasoption" >
selected {/if}
title={has} {/each}
value={optselName(has)} {#each hasesCandidates as has}
>{"triad" == fmKeyType ? "Has " : ""}{has}:</option <option id={optselName(has)} class="hasoption" title={has} value={optselName(has)}
> >{"triad" == fmKeyType ? "Has " : ""}{has}:</option
{/if} >
{/each} {/each}
{#each hasesCandidates as has}
<option
id={optselName(has)}
class="hasoption"
title={has}
value={optselName(has)}
>{"triad" == fmKeyType ? "Has " : ""}{has}:</option
>
{/each}
</select> </select>

View file

@ -1,9 +1,10 @@
<script> <script>
export let title; export let title;
export let relpath; export let relpath;
export let formaction;
</script> </script>
<label for="relpath">File path:</label> <label for="relpath">File path:</label>
<input type="text" name="relpath" value={relpath} /> <input type="text" name="relpath" value={relpath} readonly={formaction == "new" ? false : true}/>
<label for="title">Title:</label> <label for="title">Title:</label>
<input type="text" name="title" value={title} /> <input type="text" name="title" value={title} />