From 331846ecf7faa43b022a1fa65df9139f136cdb80 Mon Sep 17 00:00:00 2001 From: Eric Harris-Braun Date: Mon, 2 Sep 2024 17:18:36 -0400 Subject: [PATCH] adds bunches and things --- dnas/ziptest/workdir/dna.yaml | 2 +- .../zomes/coordinator/ziptest/src/lib.rs | 1 + .../zomes/coordinator/ziptest/src/thing.rs | 58 ++++-- .../zomes/coordinator/ziptest/src/utils.rs | 27 +++ ui/src/Bunch.svelte | 115 ++++++++++++ ui/src/Controller.svelte | 1 + ui/src/ControllerStream.svelte | 1 - ui/src/ThingsPane.svelte | 171 +++++++++++++----- ui/src/store.ts | 62 ++----- ui/src/thingStore.ts | 6 +- 10 files changed, 336 insertions(+), 108 deletions(-) create mode 100644 dnas/ziptest/zomes/coordinator/ziptest/src/utils.rs create mode 100644 ui/src/Bunch.svelte diff --git a/dnas/ziptest/workdir/dna.yaml b/dnas/ziptest/workdir/dna.yaml index 34e3269..33de56c 100644 --- a/dnas/ziptest/workdir/dna.yaml +++ b/dnas/ziptest/workdir/dna.yaml @@ -18,7 +18,7 @@ coordinator: - name: ziptest bundled: ../../../target/wasm32-unknown-unknown/release/ziptest.wasm dependencies: - - name: profiles_integrity + - name: ziptest_integrity - name: profiles bundled: ../../../target/wasm32-unknown-unknown/release/profiles.wasm dependencies: diff --git a/dnas/ziptest/zomes/coordinator/ziptest/src/lib.rs b/dnas/ziptest/zomes/coordinator/ziptest/src/lib.rs index 845d14b..c9eabaa 100644 --- a/dnas/ziptest/zomes/coordinator/ziptest/src/lib.rs +++ b/dnas/ziptest/zomes/coordinator/ziptest/src/lib.rs @@ -1,4 +1,5 @@ pub mod thing; +pub mod utils; use ziptest_integrity::*; use hdk::prelude::*; diff --git a/dnas/ziptest/zomes/coordinator/ziptest/src/thing.rs b/dnas/ziptest/zomes/coordinator/ziptest/src/thing.rs index 2ee9428..93c6404 100644 --- a/dnas/ziptest/zomes/coordinator/ziptest/src/thing.rs +++ b/dnas/ziptest/zomes/coordinator/ziptest/src/thing.rs @@ -1,19 +1,50 @@ use hdk::prelude::*; use ziptest_integrity::*; +use crate::utils::*; + +#[derive(Serialize, Deserialize, Debug)] +pub struct CreateThingInput { + pub thing: Thing, + pub bunch: String, + pub reps: Option, + pub tag: Option, +} #[hdk_extern] -pub fn create_thing(thing: Thing) -> ExternResult { - let thing_hash = create_entry(&EntryTypes::Thing(thing.clone()))?; - let record = get(thing_hash.clone(), GetOptions::default())? - .ok_or( - wasm_error!( - WasmErrorInner::Guest(String::from("Could not find the newly created Thing")) - ), - )?; - let path = Path::from("all_things"); - create_link(path.path_entry_hash()?, thing_hash.clone(), LinkTypes::AllThings, ())?; - Ok(record) +pub fn create_thing(input: CreateThingInput) -> ExternResult> { + let mut i = 0; + let mut results = Vec::new(); + let mut reps = 1; + if let Some(r) = input.reps { + reps = r; + } + while i LinkTag::from(str), + None => LinkTag::from(()) + }; + create_link_relaxed(path.path_entry_hash()?, thing_hash.clone(), LinkTypes::AllThings, tag)?; + results.push(record); + i+=1; + } + Ok(results) } + #[hdk_extern] pub fn get_thing(original_thing_hash: ActionHash) -> ExternResult> { let input = GetLinksInputBuilder::try_new(original_thing_hash.clone(), LinkTypes::ThingUpdates)?.build(); @@ -60,10 +91,9 @@ pub fn delete_thing(original_thing_hash: ActionHash) -> ExternResult } #[hdk_extern] -pub fn get_things(_: ()) -> ExternResult> { - let path = Path::from("all_things"); +pub fn get_things(bunch: String) -> ExternResult> { + let path = Path::from(bunch.clone()); let input = GetLinksInputBuilder::try_new(path.path_entry_hash()?, LinkTypes::AllThings)?.build(); let links = get_links(input)?; - Ok(links) } \ No newline at end of file diff --git a/dnas/ziptest/zomes/coordinator/ziptest/src/utils.rs b/dnas/ziptest/zomes/coordinator/ziptest/src/utils.rs new file mode 100644 index 0000000..5d3dcea --- /dev/null +++ b/dnas/ziptest/zomes/coordinator/ziptest/src/utils.rs @@ -0,0 +1,27 @@ +use hdk::prelude::*; + +pub fn create_link_relaxed( + base_address: impl Into, + target_address: impl Into, + link_type: T, + tag: impl Into +) -> ExternResult +where +ScopedLinkType: TryFrom, + WasmError: From, +{ + let ScopedLinkType { + zome_index, + zome_type: link_type, + } = link_type.try_into()?; + HDK.with(|h| { + h.borrow().create_link(CreateLinkInput::new( + base_address.into(), + target_address.into(), + zome_index, + link_type, + tag.into(), + ChainTopOrdering::Relaxed, + )) + }) +} \ No newline at end of file diff --git a/ui/src/Bunch.svelte b/ui/src/Bunch.svelte new file mode 100644 index 0000000..99f5bfd --- /dev/null +++ b/ui/src/Bunch.svelte @@ -0,0 +1,115 @@ + + +
+ {#if bunchRecord} +
+ {#if allFound} + All {expected} things found after {seconds} seconds. + {:else} + Seconds elapsed: : {seconds} + {/if} +
+ Start: {start} +
+
+
{expected}
+ {#each moments as moment,i} +
+ {moment} +
+ {i} + +
+ {/each} +
{expected}
+
+
+ {:else} + + {/if} +
+ + diff --git a/ui/src/Controller.svelte b/ui/src/Controller.svelte index ab31a3e..b90bee2 100644 --- a/ui/src/Controller.svelte +++ b/ui/src/Controller.svelte @@ -387,6 +387,7 @@ } .test-type { padding: 5px; + border: solid 1px darkgray; cursor: pointer; } .test-type:hover, .selected { diff --git a/ui/src/ControllerStream.svelte b/ui/src/ControllerStream.svelte index c5411b3..1a715ad 100644 --- a/ui/src/ControllerStream.svelte +++ b/ui/src/ControllerStream.svelte @@ -11,7 +11,6 @@ import type { WeaveClient } from "@lightningrodlabs/we-applet"; import StreamPane from "./StreamPane.svelte"; import type { EntryRecord } from "@holochain-open-dev/utils"; - import { mdiAlertPlusOutline } from "@mdi/js"; export let roleName = ""; export let client: AppClient; diff --git a/ui/src/ThingsPane.svelte b/ui/src/ThingsPane.svelte index f8fb9ce..88dc3da 100644 --- a/ui/src/ThingsPane.svelte +++ b/ui/src/ThingsPane.svelte @@ -1,85 +1,160 @@ - {#if $things.status == "complete" } -
-
- - - - createThing()} - > - -
-
- Thing Count: {$things.value.length} -
+ +
+
+ + + + (disabled = !e.target.value || !inputElement.value)} + label="Message" + > + + createBunch()} + > + +
+
+ Bunches Count: {bunches ? bunches.length: "?"}
- {/if} + {#if !bunches} + + {:else} + +
+ {#each bunches as link} + {@const bunch = tag2Bunch(link.tag)} +
{ + if (bunch != activeBunch) { + activeBunch = bunch + } + else { + activeBunch = '' + } + }}>{bunch2BunchName(bunch)}
+ {#if bunch == activeBunch} + + {/if} + {/each} +
+ {/if} +