Skip to content

Commit

Permalink
move under construction to state and add UI for switching to UC and a…
Browse files Browse the repository at this point in the history
…live
  • Loading branch information
zippy committed Dec 27, 2023
1 parent 09043e2 commit 926f4c9
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 268 deletions.
461 changes: 255 additions & 206 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ opt-level = "z"
members = ["dnas/*/zomes/coordinator/*", "dnas/*/zomes/integrity/*"]

[workspace.dependencies]
hdi = "=0.3.1"
hdk = "=0.2.1"
serde = "=1.0.145"
hdi = "0.3"
hdk = "0.2"
serde = "1"

[workspace.dependencies.file_storage]
path = "dnas/how/zomes/coordinator/file_storage"
Expand Down
9 changes: 7 additions & 2 deletions dnas/how/zomes/coordinator/how/src/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,13 @@ pub fn advance_state(input: AdvanceStateInput) -> ExternResult<EntryHashB64> {
.to_app_option().map_err(|err| wasm_error!(err))?

.ok_or(wasm_error!(WasmErrorInner::Guest(String::from("Malformed unit"))))?;
let new_doc_hash = update_document(UpdateDocumentInput {
hash: input.document_hash.clone(), path: unit.path_str()?, document: input.document })?;
let mut document = input.document;
// let now = Timestamp::now().as_micros();
// document.meta.insert("timestamp".to_string(),now.to_string());
let new_document = UpdateDocumentInput {
hash: input.document_hash.clone(), path: unit.path_str()?, document };
debug!("Updating Doc {:?}", new_document);
let new_doc_hash = update_document(new_document)?;

delete_unit_links(hash.clone(), unit.tree_paths())?;

Expand Down
32 changes: 16 additions & 16 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/src/elements/how-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { state, property, query } from "lit/decorators.js";
import { get } from "svelte/store";

import { sharedStyles } from "../sharedStyles";
import {howContext, Unit, Dictionary, Initialization, DocumentOutput, Document, DocType, Node, Section, DocumentInitializer} from "../types";
import {howContext, Unit, Dictionary, Initialization, DocumentOutput, Document, DocType, Node, Section, DocumentInitializer, UnitFlags} from "../types";
import { HowStore } from "../how.store";
import { HowUnit } from "./how-unit";
import { HowTree } from "./how-tree";
Expand Down
5 changes: 3 additions & 2 deletions ui/src/elements/how-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { CommentControl, Control } from "../controls";

@property() currentDocumentEh = "";
@property() path = "";
@property() readOnly = false;
@property() readOnly: boolean = false;
@state() commentingOn : Section|undefined = undefined;
@state() highlitRange : HilightRange | undefined;
@state() overlapping : Comment[] | undefined
Expand Down Expand Up @@ -433,7 +433,7 @@ import { CommentControl, Control } from "../controls";
.section=${section}
.index=${index}
.highlitRange=${this.highlitRange && this.highlitRange.sectionName == section.name ? this.highlitRange: undefined}
.editable=${doc.isEditable(section.name) && !this.readOnly}
.readOnly=${this.readOnly}
.comments=${comments}
>
</how-section>
Expand Down Expand Up @@ -524,6 +524,7 @@ import { CommentControl, Control } from "../controls";
tasksHTML = tasksHTML.concat(control.tasks(this._store.myAgentPubKey, doc))
})
return html`
state: ${this._documents.value[this.currentDocumentEh].state}
<div id="header">
${tasksHTML.length>0 ? html`<div class="tasks">${tasksHTML}</div>`:''}
${affordancesHTML.length>0 ? html`<div class="affordances">${affordancesHTML}</div>`:''}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/elements/how-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class HowNode extends ScopedElementsMixin(LitElement) {
i+=1
}

if (this.flags.includes(UnitFlags.UnderConstruction)) {
if (this.state == SysState.UnderConstruction) {
return html`
<img src=${underConstructionImage}>`

Expand Down
9 changes: 7 additions & 2 deletions ui/src/elements/how-section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class HowSection extends ScopedElementsMixin(LitElement) {

@property() section: Section | undefined;
@property() index = 0
@property() editable = false;
@property() readOnly = false;
@property() click = ()=>{};
@property() highlitRange: HilightRange | undefined = undefined;
@property() comments:Array<Comment> = []
Expand All @@ -48,6 +48,11 @@ export class HowSection extends ScopedElementsMixin(LitElement) {
@query('#how-selection-element')
private _elem!: HTMLElement;

isEdiable() {
return this.document && this.section ? (this.document.isEditable(this.section.name) && !this.readOnly) : false
}


private sectionTypeMarker(section: Section) {
switch (section.sectionType) {
case SectionType.Content: return ""; break;
Expand Down Expand Up @@ -268,7 +273,7 @@ export class HowSection extends ScopedElementsMixin(LitElement) {
infoPosition="right"
.click=${() => this.editing=false}
></svg-button>`)
} else if (this.editable) {
} else if (this.isEdiable()) {
controls.push(html`<svg-button
button="edit"
info="edit"
Expand Down
40 changes: 29 additions & 11 deletions ui/src/elements/how-unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ export class HowUnit extends ScopedElementsMixin(LitElement) {
let message = ""
if (newState == SysState.Defunct) {
message = "Are you sure you want to move this item to Defunct? This can not be undone."
} else {
} else if (newState == SysState.Alive && this._unitsInfos.value[this.currentUnitEh].state == SysState.UnderConstruction) {
message = "Are you sure you want to move this under construction unit to Alive?"
} else if (newState == SysState.UnderConstruction) {
message = "Are you sure you want to move this unit to under construction?"
}
else {
const unit: Unit = this._units.value[this.currentUnitEh]
const unitInfo: UnitInfo = this._unitsInfos.value[this.currentUnitEh]
const process_path = unit.processPathForState(unitInfo.state)
Expand Down Expand Up @@ -124,8 +129,6 @@ export class HowUnit extends ScopedElementsMixin(LitElement) {
const unitInfo: UnitInfo = this._unitsInfos.value[this.currentUnitEh]
const action: Action = this._unitsActions.value[this.currentUnitEh]

const underConstruction = unit.meta.flags && unit.meta.flags.includes(UnitFlags.UnderConstruction)

const path = this.getPath()
const docInfo = this._store.getCurrentDocument(path, this.currentUnitEh)
let allDocs = this._store.getDocumentsFiltered(path, this.currentUnitEh , DocType.Document, false)
Expand All @@ -147,12 +150,12 @@ export class HowUnit extends ScopedElementsMixin(LitElement) {
let controlsHTML:any[] = []

let updated: Date |undefined
let state
let state
if (docInfo) {
updated = new Date(docInfo.updated)
const document = docInfo.content
state = document.state
if (!underConstruction && isSteward && document.getStats().emptySections == 0) {
if (state != SysState.UnderConstruction && isSteward && document.getStats().emptySections == 0) {
controlsHTML = controlsHTML.concat(unit
.nextStatesFrom(document.state)
.map(
Expand All @@ -163,11 +166,20 @@ export class HowUnit extends ScopedElementsMixin(LitElement) {
.button=${nextState == SysState.Defunct ? "defunct" : "move"}>
</svg-button>`
))
}
controlsHTML.push(html`
<svg-button
.click=${() => this.confirmAdvance(this.currentUnitEh, SysState.UnderConstruction)}
.info=${"move to construction"}
.button=${"move"}>
</svg-button>
</div>
`)

}
} else {
state = unitInfo.state
}
if ( (underConstruction || state == SysState.Alive) && isSteward) {
if ( (state == SysState.UnderConstruction || state == SysState.Alive) && isSteward) {
controlsHTML.push(html`
<svg-button
.click=${() => this.dispatchEvent(new CustomEvent('add-child', { detail: this.currentUnitEh, bubbles: true, composed: true }))}
Expand All @@ -176,17 +188,22 @@ export class HowUnit extends ScopedElementsMixin(LitElement) {
</svg-button>
</div>
`)
if (underConstruction && isSteward) {
if (state == SysState.UnderConstruction && isSteward) {
controlsHTML.push(html`
<svg-button
.click=${() => this.dispatchEvent(new CustomEvent('reparent', { detail: this.currentUnitEh, bubbles: true, composed: true }))}
.info=${"reparent"}
.button=${"reparent"}>
</svg-button>
<svg-button
.click=${() => this.confirmAdvance(this.currentUnitEh, SysState.Alive)}
.info=${"make alive"}
.button=${"move"}>
</svg-button>
</div>
`)
}
if (!underConstruction) {
if (state != SysState.UnderConstruction ) {
if (updated) {
stateHTML = html`<info-item title=${`Alive as of ${updated}`} item="Alive" .name=${`as of ${updated.toLocaleDateString('en-us', { year:"numeric", month:"short", day:"numeric"})}`}></info-item>`
} else {
Expand Down Expand Up @@ -222,6 +239,7 @@ export class HowUnit extends ScopedElementsMixin(LitElement) {
</div>`
}
return html`
state:${state}
<div class="unit row">
<div class="column">
<info-item size="26px" .item=${unit.shortName} name="short name"></info-item>
Expand All @@ -242,11 +260,11 @@ export class HowUnit extends ScopedElementsMixin(LitElement) {
.button=${"question"}>
</svg-button>
<div class="progress">
${ underConstruction ?
${ state == SysState.UnderConstruction ?
html`<img style="width: 100%;" src=${underConstructionImage}>` :
html`<how-node .unit=${unit} .state=${stateName} .progress=${docInfo?.content.getProgress()}> </how-node>`}
</div>
${underConstruction ? html`<span style="margin:auto;background:yellow;border: 1px solid;padding:5px">Under Construction</span>` : ""}
${state == SysState.UnderConstruction ? html`<span style="margin:auto;background:yellow;border: 1px solid;padding:5px">Under Construction</span>` : ""}
${stateHTML}
<div class="column unit-controls">
${controlsHTML}
Expand Down
3 changes: 1 addition & 2 deletions ui/src/how.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export class HowStore {
// get all of the sections needed for a specific process by getting the template contents
// for that proccess hierarchy
async getSectionsFromHierarcy(path: string, start: number, sectionType: SectionType): Promise<Array<Section>> {
console.log(`looking for ${sectionType} in ${path}`)
path = `.${path}`
let sections: Array<Section> = []
let segments = path.split(".")
Expand Down Expand Up @@ -278,10 +277,10 @@ export class HowStore {
if (documentOutput) {
let doc = cloneDeep(documentOutput.content)
doc.state = state

const processPath = unit.processPathForState(state)
doc.appendSections(await this.getSectionsFromHierarcy(processPath, 2, SectionType.Process))

doc.meta.date = `${new Date()}` // we need to do this to make sure that content is distinct in case of moving state back and forth for history.
const newDocumentHash = await this.service.advanceState({
newState: state,
unitHash: decodeHashFromBase64(unitHash),
Expand Down
Loading

0 comments on commit 926f4c9

Please sign in to comment.