Skip to content

Commit

Permalink
update tree and add flags for under-construction
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed Dec 19, 2023
1 parent d70b26e commit 0b42071
Show file tree
Hide file tree
Showing 8 changed files with 350 additions and 37 deletions.
7 changes: 5 additions & 2 deletions dnas/how/zomes/coordinator/how/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -40,11 +41,13 @@ fn get_entry_hashes(path: &Path) -> ExternResult<(Vec<UnitInfo>,Vec<EntryHash>)>
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,
});
},
_ => (),
};
Expand Down
29 changes: 17 additions & 12 deletions dnas/how/zomes/coordinator/how/src/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ pub fn delete_unit_links(hash: EntryHash, tree_paths: Vec<Path>) -> ExternResul
Ok(())
}

pub fn create_unit_links(hash: EntryHash, tree_paths: Vec<Path>, state: &str, version: &str) -> ExternResult<()> {
pub fn create_unit_links(hash: EntryHash, tree_paths: Vec<Path>, 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 {
Expand All @@ -82,12 +82,13 @@ pub fn create_unit_inner(input: Unit, state: &str) -> ExternResult<UnitOutput> {
"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,
})
Expand All @@ -110,30 +111,33 @@ fn get_units(_: ()) -> ExternResult<Vec<UnitOutput>> {
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<Vec<UnitOutput>> {
let links = get_links(base, LinkTypes::Unit, None)?;

let mut unit_infos: HashMap<EntryHash,UnitInfo> = 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!();
Expand Down Expand Up @@ -178,7 +182,8 @@ pub fn advance_state(input: AdvanceStateInput) -> ExternResult<EntryHashB64> {
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);
}

Expand Down Expand Up @@ -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))
}
Expand Down
6 changes: 6 additions & 0 deletions dnas/how/zomes/integrity/how/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
let x = self.tree_paths();
let v = x[0].as_ref();
Expand Down
12 changes: 9 additions & 3 deletions ui/src/elements/how-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -126,10 +127,11 @@ export class HowNode extends ScopedElementsMixin(LitElement) {

if (this.state == SysState.Alive) {
return html`
<img src=${aliveImage}>`
<div class="${this.flags.includes(UnitFlags.Placeholder)?" placeholder":""}"><img src=${aliveImage}></div>
`
} else {
return html`
<div class="circle">${this.circle(segments)}</div>
<div class="${this.flags.includes(UnitFlags.Placeholder)?" placeholder":""}">${this.circle(segments)}</div>
`
}
} else {
Expand All @@ -148,6 +150,10 @@ export class HowNode extends ScopedElementsMixin(LitElement) {
img {
width: 100%;
}
.placeholder {
background-color: lightyellow;
border-radius: 50%;
}
`,
];
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/elements/how-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class HowTree extends ScopedElementsMixin(LitElement) {
<li class="${this.treeType}">
<span class="${nodeId == this.currentNode ? "current" : ""}" @click=${()=>this.select(nodeId)}>
<div class="progress" title=${`document count: ${node.val.documents.length}`}>
<how-node .unit=${this._units.value[nodeId]} state=${state}> </how-node>
<how-node .unit=${this._units.value[nodeId]} state=${state} flags=${unitInfo?.flags}> </how-node>
</div>
${node.id=="0" ? this._store.treeName : node.val.name}
<!-- <mwc-button icon="add_circle" @click=${
Expand Down
26 changes: 14 additions & 12 deletions ui/src/elements/how-unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {property, query, state} from "lit/decorators.js";
import { StoreSubscriber } from '@holochain-open-dev/stores';

import {sharedStyles} from "../sharedStyles";
import {Unit, DocType, howContext, SysState, Document, UnitInfo} from "../types";
import {Unit, DocType, howContext, SysState, Document, UnitInfo, UnitFlags} from "../types";
import {HowStore} from "../how.store";
import { HowUnitDetails } from "./how-unit-details";
import { SvgButton } from "./svg-button";
Expand Down Expand Up @@ -214,25 +214,27 @@ export class HowUnit extends ScopedElementsMixin(LitElement) {
return html`
<div class="unit row">
<div class="column">
<info-item size="26px" .item=${unit.shortName} name="short name"></info-item>
<info-item .item=${unit.version.slice(4)} .name=${`version (${unit.version.substring(1,4)})`}></info-item>
<info-item .item=${unit.pathAbbreviation} name="path"></info-item>
<info-item
.title=${`Created on ${created} by ${creator ? creator.nickname : creatorHash}`}
.item=${created.toLocaleDateString('en-us', { year:"numeric", month:"short", day:"numeric"})} name="created">
</info-item>
${ updated ? html`<info-item title=${`Last modified ${updated}`} .item=${updated.toLocaleDateString('en-us', { year:"numeric", month:"short", day:"numeric"})} name="modified"></info-item>`:''}
<div class="info-item">${stewardsHTML}
<div class="info-item-name">stewards</div></div>
<info-item size="26px" .item=${unit.shortName} name="short name"></info-item>
<info-item .item=${unit.version.slice(4)} .name=${`version (${unit.version.substring(1,4)})`}></info-item>
<info-item .item=${unit.pathAbbreviation} name="path"></info-item>
<info-item
.title=${`Created on ${created} by ${creator ? creator.nickname : creatorHash}`}
.item=${created.toLocaleDateString('en-us', { year:"numeric", month:"short", day:"numeric"})} name="created">
</info-item>
${ updated ? html`<info-item title=${`Last modified ${updated}`} .item=${updated.toLocaleDateString('en-us', { year:"numeric", month:"short", day:"numeric"})} name="modified"></info-item>`:''}
<div class="info-item">${stewardsHTML}
<div class="info-item-name">stewards</div>
</div>
</div>
<div class="column">
<svg-button class="question-button"
.click=${() => this._detailsElem!.open()}
.button=${"question"}>
</svg-button>
</svg-button>
<div class="progress">
<how-node .unit=${unit} .state=${stateName} .progress=${docInfo?.content.getProgress()}> </how-node>
</div>
${unit.meta.flags.includes(UnitFlags.Placeholder) ? html`<span style="margin:auto;background:yellow;border: 1px solid;">Under Construction</span>` : ""}
${stateHTML}
<div class="column unit-controls">
${controlsHTML}
Expand Down
Loading

0 comments on commit 0b42071

Please sign in to comment.