Skip to content

Commit

Permalink
got simple drilldown working
Browse files Browse the repository at this point in the history
  • Loading branch information
arvindrag committed Apr 17, 2024
1 parent 3490a1d commit fe34ce5
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 19 deletions.
10 changes: 10 additions & 0 deletions arneson/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
<a href="#!" class="brand-logo right"><i class="large material-icons">wallpaper</i>Arneson</a>
</div>
</nav>
<nav>
<div id="mycrumbs" class="nav-wrapper grey darken-2">
<div class="col s12">
<!-- <a href="#!" class="breadcrumb"> </a>
<a href="#!" class="breadcrumb">Second</a>
<a href="#!" class="breadcrumb">Third</a>
<a href="#!" class="breadcrumb">Fourth</a> -->
</div>
</div>
</nav>
</header>
<main id="main">
<div class="row">
Expand Down
70 changes: 52 additions & 18 deletions arneson/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class Card {
setText(text) {
this.text.innerHTML = text;
}
getText(text) {
return this.text.innerHTML
}
unFocus() {
if (this.cardElem.classList.contains("purple")) {
this.cardElem.classList.remove("purple");
Expand Down Expand Up @@ -123,12 +126,13 @@ class EditTextModal {
}
}
class CardsSet {
constructor(tree, parent_elem) {
constructor(tree, parent_elem, parent_card = null) {
this.tree = tree
this.elem = CARDS_SET.genElementAndAttach();
this.elem.cardsSet = this;
this.curFocus = null;
this.child = null
this.parent_card = parent_card
this.editTextModal = new EditTextModal(parent_elem);
this.editTagsModal = new EditTagsModal(parent_elem);
const active_tags_div = document.querySelector("#active_tags");
Expand All @@ -137,13 +141,16 @@ class CardsSet {
this
);
}
path(){
if(this.parent_card == null){
return [" "]
}
return [...this.parent_card.parent.path(),this.parent_card.getText()]
}
focus(){
curFocus
this.elem.classList.remove("hide")
}
unFocus(){
this.curFocus.child.hide()
}
hide(){
this.elem.classList.add("hide")
}
keyMap(e) {
Expand Down Expand Up @@ -182,13 +189,24 @@ class CardsSet {
if (e.key == "ArrowRight") {
if (!e.shiftKey) {
M.toast({ html: "<b>right: into</b>" });
// this.curFocus.focusNext();
if(this.curFocus.child != null){
this.tree.focus(this.curFocus.child)
}
} else {
M.toast({ html: "<b>shift+right: subtree</b>" });
this.tree.addChildCardSetAndFocus(this.curFocus)
if(this.curFocus.child == null){
this.tree.addChildCardSet(this.curFocus)
}
}
return;
}
if (e.key == "ArrowLeft") {
M.toast({ html: "<b>right: into</b>" });
if(this.parent_card != null){
this.tree.focus(this.parent_card.parent)
}
return;
}
if (e.key == "Enter") {
console.log("enter on nothing");
M.toast({ html: "<b>enter: edit</b>" });
Expand Down Expand Up @@ -224,24 +242,40 @@ class CardSetTree {
this.elem = elem;
this.root = new CardsSet(this, this.elem);
this.elem.appendChild(this.root.elem);
this.focus = this.root
this.curFocus = null
this.path = document.querySelector("#mycrumbs")
this.focus(this.root)
document.addEventListener("keyup", (e) => {
this.focusKeyMap(e)
});
}
setCrumbs(path){
this.path.textContent = ""
path.forEach((p)=>{
const crumb = {}
const c = CRUMB.genElementAndAttachAppend(this.path, crumb)
console.log(c)
c.innerHTML = p
})
}
focusKeyMap(e){
this.focus.keyMap(e);
this.curFocus.keyMap(e);
}
focus(thing){
this.focus.unfocus()
this.focus = thing
}
addChildCardSetAndFocus(parentCard){
const child = new CardsSet(this, this.elem)
child.addCard("And then")
parentCard.child = child
parentCard.parent.elem.after(child.elem)
this.focus(child)
if(this.curFocus != null){
this.curFocus.unFocus()
}
this.curFocus = thing
console.log(this.curFocus)
this.setCrumbs(this.curFocus.path())
this.curFocus.focus()
}
addChildCardSet(parent_card){
const childset = new CardsSet(this, this.elem, parent_card)
parent_card.child = childset
childset.addCard("And then")
this.elem.appendChild(childset.elem);
this.focus(childset)
}
}
const tree = new CardSetTree(document.querySelector("#cards"));
Expand Down
3 changes: 2 additions & 1 deletion arneson/src/static_html.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class StaticHTML{
genElement() {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(this.html_string, 'text/html');
return htmlDoc.querySelector("div")
return htmlDoc.querySelector(this.type_)
}
genElementAndAttach(attachTo) {
const elem = this.genElement()
Expand All @@ -27,6 +27,7 @@ class StaticHTML{
return elem
}
}
const CRUMB = new StaticHTML("a", `<a href="#!" class="breadcrumb ref_name"></a>`)
const CARDS_SET = new StaticHTML("div", `<div class="cardsset col s3"></div>`)
const CARD = new StaticHTML("div",
`<div class="row s12">
Expand Down

0 comments on commit fe34ce5

Please sign in to comment.