From 0b420710b0bf65d5651019f788a9f58ba227f7e4 Mon Sep 17 00:00:00 2001 From: Eric Harris-Braun Date: Tue, 19 Dec 2023 08:22:22 -0500 Subject: [PATCH] update tree and add flags for under-construction --- dnas/how/zomes/coordinator/how/src/tree.rs | 7 +- dnas/how/zomes/coordinator/how/src/unit.rs | 29 +- dnas/how/zomes/integrity/how/src/lib.rs | 6 + ui/src/elements/how-node.ts | 12 +- ui/src/elements/how-tree.ts | 2 +- ui/src/elements/how-unit.ts | 26 +- ui/src/initHolochain.ts | 296 ++++++++++++++++++++- ui/src/types.ts | 9 +- 8 files changed, 350 insertions(+), 37 deletions(-) diff --git a/dnas/how/zomes/coordinator/how/src/tree.rs b/dnas/how/zomes/coordinator/how/src/tree.rs index f7e50f5..4dee374 100644 --- a/dnas/how/zomes/coordinator/how/src/tree.rs +++ b/dnas/how/zomes/coordinator/how/src/tree.rs @@ -9,6 +9,7 @@ pub struct UnitInfo { pub hash: EntryHash, pub version: String, pub state: String, + pub flags: String, } #[derive(Clone, Serialize, Deserialize, Debug, Default, PartialEq)] @@ -40,11 +41,13 @@ fn get_entry_hashes(path: &Path) -> ExternResult<(Vec,Vec)> match link_type { LinkTypes::Document => documents.push(target), LinkTypes::Unit => { - let (state, version) = convert_tag(l.tag)?; + let (state, version, flags) = convert_tag(l.tag)?; units.push(UnitInfo{ hash: target, version, - state}); + state, + flags, + }); }, _ => (), }; diff --git a/dnas/how/zomes/coordinator/how/src/unit.rs b/dnas/how/zomes/coordinator/how/src/unit.rs index f34eaba..377716f 100644 --- a/dnas/how/zomes/coordinator/how/src/unit.rs +++ b/dnas/how/zomes/coordinator/how/src/unit.rs @@ -56,13 +56,13 @@ pub fn delete_unit_links(hash: EntryHash, tree_paths: Vec) -> ExternResul Ok(()) } -pub fn create_unit_links(hash: EntryHash, tree_paths: Vec, state: &str, version: &str) -> ExternResult<()> { +pub fn create_unit_links(hash: EntryHash, tree_paths: Vec, state: &str, version: &str, flags: &str) -> ExternResult<()> { let path = get_units_path(); let typed_path = path.clone().into_typed(ScopedLinkType::try_from(LinkTypes::Tree)?); typed_path.ensure()?; let anchor_hash = path.path_entry_hash()?; - let tag = LinkTag::new(String::from(format!("{}-{}", state, version))); + let tag = LinkTag::new(String::from(format!("{}-{}-{}", state, version, flags))); create_link(anchor_hash, hash.clone(), LinkTypes::Unit, tag.clone())?; for path in tree_paths { @@ -82,12 +82,13 @@ pub fn create_unit_inner(input: Unit, state: &str) -> ExternResult { "Could not get the record created just now" ))))?; //emit_signal(&SignalPayload::new(hash.clone().into(), Message::NewUnit(record)))?; - create_unit_links(hash.clone(), tree_paths, state, &input.version)?; + create_unit_links(hash.clone(), tree_paths, state, &input.version, input.flags_str())?; Ok(UnitOutput { info: UnitInfo { hash, state: state.into(), - version: input.version + version: input.version.clone(), + flags: String::from(input.flags_str()), }, record, }) @@ -110,16 +111,17 @@ fn get_units(_: ()) -> ExternResult> { Ok(units) } -pub fn convert_tag(tag: LinkTag) -> ExternResult<(String,String)> { +pub fn convert_tag(tag: LinkTag) -> ExternResult<(String,String,String)> { let tag_string = String::from_utf8(tag.into_inner()) .map_err(|_e| wasm_error!(WasmErrorInner::Guest(String::from("could not convert link tag to string"))))?; let x : Vec<&str>= tag_string.split("-").collect(); - if x.len() != 2 { + if x.len() != 3 { return Err(wasm_error!(WasmErrorInner::Guest(format!("Badly formed link: {:?}", tag_string)))); } let state = x[0].into(); - let version = x[1].into(); - Ok((state,version)) + let version: String = x[1].into(); + let flags: String = x[2].into(); + Ok((state,version,flags)) } fn get_units_inner(base: EntryHash) -> HowResult> { @@ -127,13 +129,15 @@ fn get_units_inner(base: EntryHash) -> HowResult> { let mut unit_infos: HashMap = HashMap::new(); for link in links.clone() { - let (state, version) = convert_tag(link.tag.clone())?; + let (state, version, flags) = convert_tag(link.tag.clone())?; let hash = EntryHash::try_from(link.target).map_err(|e| HowError::HashConversionError)?; unit_infos.insert(hash.clone(), UnitInfo { hash, version, - state}); + state, + flags, + }); } let mut get_input= vec!(); @@ -178,7 +182,8 @@ pub fn advance_state(input: AdvanceStateInput) -> ExternResult { hash: input.document_hash.clone(), path: unit.path_str()?, document: input.document })?; delete_unit_links(hash.clone(), unit.tree_paths())?; - create_unit_links(hash,unit.tree_paths(), &input.new_state, &unit.version)?; + + create_unit_links(hash,unit.tree_paths(), &input.new_state, &unit.version, unit.flags_str())?; return Ok(new_doc_hash); } @@ -235,7 +240,7 @@ pub fn reparent_unit(unit_info: &UnitInfo, from: String, to: String) -> ExternR } let new_unit_hash = update_unit(record.action_address().clone(), &unit)?; - create_unit_links(new_unit_hash.clone(), unit.tree_paths(), &unit_info.state, &unit_info.version)?; + create_unit_links(new_unit_hash.clone(), unit.tree_paths(), &unit_info.state, &unit_info.version, unit.flags_str())?; Ok((new_unit_hash,unit)) } diff --git a/dnas/how/zomes/integrity/how/src/lib.rs b/dnas/how/zomes/integrity/how/src/lib.rs index 82b30c0..b2aec5a 100644 --- a/dnas/how/zomes/integrity/how/src/lib.rs +++ b/dnas/how/zomes/integrity/how/src/lib.rs @@ -23,6 +23,12 @@ pub struct Unit { } impl Unit { + pub fn flags_str(&self) -> &str { + match self.meta.get("flags") { + Some(flags) => flags, + None => "", + } + } pub fn path_str(&self) -> ExternResult { let x = self.tree_paths(); let v = x[0].as_ref(); diff --git a/ui/src/elements/how-node.ts b/ui/src/elements/how-node.ts index 75c28a4..ecadb09 100644 --- a/ui/src/elements/how-node.ts +++ b/ui/src/elements/how-node.ts @@ -2,7 +2,7 @@ import {css, html, LitElement} from "lit"; import {property, query} from "lit/decorators.js"; import { consume } from '@lit/context'; import {sharedStyles} from "../sharedStyles"; -import {Unit, DocType, howContext, Document, DocumentOutput, SysState, Progress} from "../types"; +import {Unit, DocType, howContext, Document, DocumentOutput, SysState, Progress, UnitFlags} from "../types"; import {HowStore} from "../how.store"; import {ScopedElementsMixin} from "@open-wc/scoped-elements"; import { StoreSubscriber } from "@holochain-open-dev/stores"; @@ -51,6 +51,7 @@ export class HowNode extends ScopedElementsMixin(LitElement) { } @property() unit:Unit|undefined; @property() state:string = ""; + @property() flags:string = ""; @property() progress:Progress| undefined = undefined; @consume({ context: howContext }) @@ -126,10 +127,11 @@ export class HowNode extends ScopedElementsMixin(LitElement) { if (this.state == SysState.Alive) { return html` - ` +
+ ` } else { return html` -
${this.circle(segments)}
+
${this.circle(segments)}
` } } else { @@ -148,6 +150,10 @@ export class HowNode extends ScopedElementsMixin(LitElement) { img { width: 100%; } + .placeholder { + background-color: lightyellow; + border-radius: 50%; + } `, ]; } diff --git a/ui/src/elements/how-tree.ts b/ui/src/elements/how-tree.ts index 30b54c6..719be29 100644 --- a/ui/src/elements/how-tree.ts +++ b/ui/src/elements/how-tree.ts @@ -57,7 +57,7 @@ export class HowTree extends ScopedElementsMixin(LitElement) {
  • this.select(nodeId)}>
    - +
    ${node.id=="0" ? this._store.treeName : node.val.name}