Skip to content

Commit

Permalink
address latest github issues
Browse files Browse the repository at this point in the history
  • Loading branch information
LeosPrograms committed Feb 13, 2024
1 parent cc469c7 commit b13997c
Show file tree
Hide file tree
Showing 16 changed files with 375 additions and 134 deletions.
4 changes: 2 additions & 2 deletions ui/src/lib/CommitmentModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
export let commitmentModalProcess: number | undefined;
export let commitmentModalSide: string | undefined;
export let selectedCommitmentId: string | undefined
export let process: any[];
export let process: any[] | undefined;
export let commitments: any[]
const dispatch = createEventDispatcher();
Expand Down Expand Up @@ -199,7 +199,7 @@ const GET_ALL_RESOURCE_SPECIFICATIONS = gql`
$: {
if (selectedCommitmentId !== previousSelectedCommitmentId) {
previousSelectedCommitmentId = selectedCommitmentId;
if (selectedCommitmentId && commitmentModalColumn > -1) {
if (process && selectedCommitmentId && commitmentModalColumn > -1) {
selectedCommitment = JSON.parse(JSON.stringify(process.find(it => it.id == selectedCommitmentId)));
} else if (selectedCommitmentId && commitmentModalColumn == undefined) {
console.log(commitments)
Expand Down
13 changes: 12 additions & 1 deletion ui/src/lib/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@
export let description = 'this is the description'
</script>

<div class="h-full custom-background">
<!-- <div class="h-full custom-background">
<div class="max-w-7xl mx-auto px-2 sm:px-6 lg:px-8">
<h2 class="pt-1 text-white text-2xl">
{title}
</h2>
<p class="text-white text-xs">{description}</p>
</div>
</div> -->

<div class="custom-background" style="height: 15vh; margin-bottom: 6px">
<div class="mx-auto px-2 sm:px-6 lg:px-8">
<h2 class="pt-1 text-white text-3xl">
{title}
</h2>
<p class="text-white text-xs">
{description}
</p>
</div>
</div>

<style>
Expand Down
125 changes: 89 additions & 36 deletions ui/src/lib/PlanModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@
resourceSpecifications: AgentConnection & RelayConn<any>
}
interface QueryResponse {
interface ProcessQueryResponse {
processSpecifications: AgentConnection & RelayConn<any>
}
interface QueryResponse {
interface AgentQueryResponse {
agents: AgentConnection & RelayConn<any>
}
Expand Down Expand Up @@ -302,7 +302,7 @@
}
async function saveOrUpdateCommitment(commitment: CommitmentUpdateParams) {
console.log(commitment)
console.log("save or updated commitment", commitment.resourceConformsTo.name, resourceSpecifications)
let o: CommitmentCreateParams = {
plannedWithin: commitment.plannedWithin,
finished: commitment.finished,
Expand All @@ -314,18 +314,26 @@
hasUnit: commitment?.resourceQuantity?.hasUnit?.id
},
}
if (commitment.clauseOf !== undefined) {
o.clauseOf = commitment.clauseOf
}
if (o.provider == undefined) {
o.provider = agents.find((a) => a.node.name === "Carbon Farm Network").node.id
} else {
const defaultAgent = agents.find((a) => a.node.name === "Carbon Farm Network").node
try {
o.provider = agents.find((a) => a.node.name === commitment.provider.name).node.id
} catch (e) {
console.log("can't find receiver", e)
o.provider = defaultAgent.id
console.log("saved by setting default agent", defaultAgent)
}
if (o.receiver == undefined) {
o.receiver = agents.find((a) => a.node.name === "Carbon Farm Network").node.id
} else {
try {
o.receiver = agents.find((a) => a.node.name === commitment.receiver.name).node.id
} catch (e) {
console.log("can't find provider", e)
o.receiver = defaultAgent.id
console.log("saved by setting default agent", defaultAgent)
}
if (commitment.clauseOf !== undefined) {
o.clauseOf = commitment.clauseOf
}
if (commitment.outputOf !== undefined) {
o.outputOf = commitment.outputOf
Expand All @@ -336,17 +344,18 @@
if (commitment.independentDemandOf !== undefined) {
o.independentDemandOf = commitment.independentDemandOf
}
console.log("save or update commitment", commitment)
console.log("about to add or update commitment", commitment)
if (commitment.revisionId == undefined) {
o.action = commitment.action.label
console.log("adding commitment", o)
try {
await addCommitment({
const res = await addCommitment({
variables: {
cm: o
}
})
commitmentsSavedCount++
console.log("added commitment", res)
// commitmentsSavedCount++
} catch (e) {
console.log(e)
error = e
Expand All @@ -356,9 +365,12 @@
...o,
revisionId: commitment.revisionId,
}
if (com.clauseOf?.id) {
com.clauseOf = com.clauseOf.id
}
console.log("updating commitment", com)
try {
let res = await updateCommitment({
const res = await updateCommitment({
variables: {
cm: com
}
Expand Down Expand Up @@ -400,7 +412,7 @@
}
console.log("trying to add independent", o)
await saveOrUpdateCommitment(o)
// commitmentsSavedCount++
commitmentsSavedCount++
console.log('added independent', o)
}
Expand All @@ -410,11 +422,19 @@
// save process
const processId = await saveOrUpdateProcess(process)
console.log("compare ids", p, processId)
let agreementId: string;
// save everything else
async function handleCommitment(c: any) {
let agreementId: string;
// save cost if applicable
if (c.clauseOf) {
c.agreement = {
id: c.clauseOf.id,
commitment: c.clauseOf.commitments.find((cm) => cm.action.label === "transfer")
}
}
if (c.agreement !== undefined) {
console.log("agreement exists!!", c.agreement)
console.log("commitment for agreement: ", c)
// save agreement
let ag = c.agreement
let agCreateParams = {
Expand All @@ -426,43 +446,71 @@
ag: agCreateParams
}
})
console.log(a)
console.log("new agreement added", a)
agreementId = a.data.createAgreement.agreement.id
c.clauseOf = a.data.createAgreement.agreement.id
// save cost commitment
const dollars = resourceSpecifications.find((rs) => rs.node.name === "USD")
console.log("dollars", dollars)
let payment: CommitmentCreateParams = {
clauseOf: a.data.createAgreement.agreement.id,
action: "transfer",
provider: agents.find((a) => a.node.name === "Carbon Farm Network").node.id,
action: {
label: "transfer"
},
provider: c.receiver,
receiver: c.provider,
plannedWithin: p.data.res.plan.id,
receiver: agents.find((a) => a.node.name === "Carbon Farm Network").node.id,
resourceConformsTo: resourceSpecifications.find((rs) => rs.node.name === "USD").node.id,
resourceConformsTo: dollars.node,
resourceQuantity: {
hasNumericalValue: Number(c.agreement.commitment.resourceQuantity.hasNumericalValue),
},
finished: false,
note: c.agreement.commitment.note,
hasBeginning: new Date(Date.now()),
}
console.log("payment commitment 1", payment)
// try {
// payment.provider = agents.find((a) => a.node.name === c.receiver.name).node.id
// } catch (e) {
// console.log("can't find receiver", e)
// payment.provider = agents.find((a) => a.node.name === "Carbon Farm Network").node.id
// }
// try {
// payment.receiver = agents.find((a) => a.node.name === c.provider.name).node.id
// } catch (e) {
// console.log("can't find provider", e)
// payment.receiver = agents.find((a) => a.node.name === "Carbon Farm Network").node.id
// }
console.log("payment commitment 2", payment)
// try {
// c.agreement.commitment.
// } catch (e) {
// console.log("could not find unit", e)
// }
try {
let paymentCommitment = await addCommitment({
variables: {
cm: payment
}
})
// commitmentsSavedCount++
console.log("payment commitment", paymentCommitment)
// let paymentCommitment = await addCommitment({
// variables: {
// cm: payment
// }
// })
console.log("trying to save payment commitment", payment)
let paymentCommitment = await saveOrUpdateCommitment(payment)
commitmentsSavedCount++
console.log("payment commitment 3", paymentCommitment)
} catch (e) {
console.log("could not add payment commitment", e)
console.log(e)
}
}
// save primary commitment
// c.process = x.data.createProcess.process
c.plannedWithin = p.data.res.plan.id
console.log(c.process)
// console.log(c.process)
if (c.provider === undefined) {
c.provider = c.receiver
}
Expand Down Expand Up @@ -498,14 +546,18 @@
}
for (const input of process.committedInputs) {
console.log("input is", input)
await delay(30);
await handleCommitment({
...input,
inputOf: processId,
})
}
for (const input of process.committedOutputs) {
for (const output of process.committedOutputs) {
console.log("output is", output)
await delay(30);
await handleCommitment({
...input,
...output,
outputOf: processId,
})
Expand Down Expand Up @@ -568,12 +620,13 @@
console.log(planObject)
const x = await resourceSpecificationsQuery.refetch()
resourceSpecifications = x.data.resourceSpecifications.edges
console.log("loaded resource specifications", resourceSpecifications)
const z = await processSpecificationsQuery.refetch()
processSpecifications = z.data.processSpecifications.edges
console.log(resourceSpecifications)
console.log("loaded process specifications", processSpecifications)
const y = await agentsQuery.refetch()
agents = y.data.agents.edges
console.log(agents)
console.log("loaded agents", agents)
window.addEventListener('keydown', checkKey)
})
Expand Down
8 changes: 4 additions & 4 deletions ui/src/lib/data/recipes-with-exchanges.json
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@
"type": "recipe_process",
"process_conforms_to": {
"name": "Scour Fiber",
"image": "/mill.svg"
"image": "/washing-machine.svg"
},
"has_duration": {
"numeric_duration": 7,
Expand Down Expand Up @@ -670,7 +670,7 @@
"type": "recipe_process",
"process_conforms_to": {
"name": "Scour Fiber",
"image": "/mill.svg"
"image": "/washing-machine.svg"
},
"has_duration": {
"numeric_duration": 7,
Expand Down Expand Up @@ -742,7 +742,7 @@
"name": "Scour Gray Alpaca",
"process_conforms_to": {
"name": "Scour Fiber",
"image": "/mill.svg"
"image": "/washing-machine.svg"
},
"has_duration": {
"numeric_duration": 7,
Expand Down Expand Up @@ -814,7 +814,7 @@
"type": "recipe_process",
"process_conforms_to": {
"name": "Scour Fiber",
"image": "/mill.svg"
"image": "/washing-machine.svg"
},
"has_duration": {
"numeric_duration": 7,
Expand Down
1 change: 1 addition & 0 deletions ui/src/lib/graphql/plan.fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const COMMITMENT_RETURN_FIELDS = gql`
}
finished
clauseOf {
id
commitments {
id
action {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/routes/agents/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@
$: agents, modalOpen, editing, id, currentAgent, selectedFacets;
</script>

<div style="height: 8vh">
<!-- <div style="height: 8vh"> -->
<Header title="Agents" description="A list of all the people, organizations and ecological agents related to the network." />
</div>
<!-- </div> -->
<AgentModal bind:open={modalOpen} {name} {facets} {currentAgent} {editing} {selectedFacets} on:submit={fetchAgents} />

<div class="p-12">
Expand Down
4 changes: 2 additions & 2 deletions ui/src/routes/facets/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
</script>

<div style="height: 8vh">
<!-- <div style="height: 8vh"> -->
<Header title="Facets" description="A list of all the facets and their values for the facet group." />
</div>
<!-- </div> -->

{#if facetGroups && currentFacetGroup}
<FacetModal bind:facetGroups bind:open={modalOpen} bind:currentFacetGroup bind:currentFacet on:submit={fetchFacets} />
Expand Down
4 changes: 2 additions & 2 deletions ui/src/routes/offers/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@
$: currentProposal, currentIntent, currentProposedIntent, agents, units, resourceSpecifications, offersList, editing, modalOpen, name
</script>

<div style="height: 8vh">
<!-- <div style="height: 8vh"> -->
<Header title="Offers" description="The goods or services you are offering within the network, now or generally." />
</div>
<!-- </div> -->

<OfferModal on:submit={fetchOffers} bind:open={modalOpen} bind:editing bind:units bind:agents bind:resourceSpecifications bind:currentProposal bind:currentIntent bind:currentReciprocalIntent bind:currentProposedIntent />

Expand Down
4 changes: 2 additions & 2 deletions ui/src/routes/plans/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
</script>

<div style="height: 8vh">
<!-- <div style="height: 8vh"> -->
<Header title="Plans" description="Current operational planning" />
</div>
<!-- </div> -->

<div class="p-12">
<div class="sm:flex sm:items-center">
Expand Down
Loading

0 comments on commit b13997c

Please sign in to comment.