diff --git a/ui/src/lib/CommitmentModal.svelte b/ui/src/lib/CommitmentModal.svelte index 3de6877..ae52657 100644 --- a/ui/src/lib/CommitmentModal.svelte +++ b/ui/src/lib/CommitmentModal.svelte @@ -22,14 +22,16 @@ export let selectedCommitmentId: string | undefined export let process: any[] | undefined; export let commitments: any[] + export let agents: Agent[]; + export let resourceSpecifications: any[]; + export let units: any[]; + const dispatch = createEventDispatcher(); let name = '' let note = '' - let agents: Agent[]; - let resourceSpecifications: any[]; - let units: any[]; let saveCost: boolean = false; + let finished: boolean = false; $: saveCost; @@ -56,110 +58,110 @@ } } - const GET_UNITS = gql` - query GetUnits { - units { - edges { - cursor - node { - id - label - symbol - } - } - } - } - ` - - const GET_ALL_AGENTS = gql` - query { - agents(last: 100000) { - edges { - cursor - node { - id - name - } - } - } - } - ` - -const GET_ALL_RESOURCE_SPECIFICATIONS = gql` - ${RESOURCE_SPECIFICATION_CORE_FIELDS} - ${UNIT_CORE_FIELDS} - query { - resourceSpecifications(last: 100000) { - edges { - cursor - node { - ...ResourceSpecificationCoreFields - defaultUnitOfResource { - ...UnitCoreFields - } - } - } - } - } - ` - - interface QueryResponse { - agents: AgentConnection & RelayConn - } - - interface RspecResponse { - resourceSpecifications: AgentConnection & RelayConn - } - - - interface UnitsQueryResponse { - units: UnitConnection & RelayConn //& RelayConn | null | undefined - } - - let getUnits: ReadableQuery = query(GET_UNITS) +// const GET_UNITS = gql` +// query GetUnits { +// units { +// edges { +// cursor +// node { +// id +// label +// symbol +// } +// } +// } +// } +// ` + +// const GET_ALL_AGENTS = gql` +// query { +// agents(last: 100000) { +// edges { +// cursor +// node { +// id +// name +// } +// } +// } +// } +// ` + +// const GET_ALL_RESOURCE_SPECIFICATIONS = gql` +// ${RESOURCE_SPECIFICATION_CORE_FIELDS} +// ${UNIT_CORE_FIELDS} +// query { +// resourceSpecifications(last: 100000) { +// edges { +// cursor +// node { +// ...ResourceSpecificationCoreFields +// defaultUnitOfResource { +// ...UnitCoreFields +// } +// } +// } +// } +// } +// ` + +// interface QueryResponse { +// agents: AgentConnection & RelayConn +// } + +// interface RspecResponse { +// resourceSpecifications: AgentConnection & RelayConn +// } + + +// interface UnitsQueryResponse { +// units: UnitConnection & RelayConn //& RelayConn | null | undefined +// } + +// let getUnits: ReadableQuery = query(GET_UNITS) - // map component state - let agentsQuery: ReadableQuery = query(GET_ALL_AGENTS) - - let resourceSpecificationsQuery: ReadableQuery = query(GET_ALL_RESOURCE_SPECIFICATIONS) - - async function fetchUnits() { - getUnits.getCurrentResult() - getUnits.refetch().then((r) => { - if (r.data?.units.edges.length > 0) { - units = flattenRelayConnection(r.data?.units) - } - }) - } - - async function fetchAgents() { - await agentsQuery.getCurrentResult() - const a = await agentsQuery.refetch() - agents = flattenRelayConnection(a.data?.agents).map((a) => { - return { - ...a, - } - }) - console.log(agents) - } - - async function fetchResourceSpecifications() { - await resourceSpecificationsQuery.getCurrentResult() - let r = await resourceSpecificationsQuery.refetch() - resourceSpecifications = flattenRelayConnection(r.data?.resourceSpecifications).map((a) => { - return { - ...a, - defaultUnitOfResourceId: a.defaultUnitOfResource?.id, - } - }) - console.log(resourceSpecifications) - } +// // map component state +// let agentsQuery: ReadableQuery = query(GET_ALL_AGENTS) + +// let resourceSpecificationsQuery: ReadableQuery = query(GET_ALL_RESOURCE_SPECIFICATIONS) + +// async function fetchUnits() { +// getUnits.getCurrentResult() +// getUnits.refetch().then((r) => { +// if (r.data?.units.edges.length > 0) { +// units = flattenRelayConnection(r.data?.units) +// } +// }) +// } + +// async function fetchAgents() { +// await agentsQuery.getCurrentResult() +// const a = await agentsQuery.refetch() +// agents = flattenRelayConnection(a.data?.agents).map((a) => { +// return { +// ...a, +// } +// }) +// console.log(agents) +// } + +// async function fetchResourceSpecifications() { +// await resourceSpecificationsQuery.getCurrentResult() +// let r = await resourceSpecificationsQuery.refetch() +// resourceSpecifications = flattenRelayConnection(r.data?.resourceSpecifications).map((a) => { +// return { +// ...a, +// defaultUnitOfResourceId: a.defaultUnitOfResource?.id, +// } +// }) +// console.log(resourceSpecifications) +// } onMount(async() => { window.addEventListener('keydown', checkKey) - await fetchUnits(); - await fetchAgents(); - await fetchResourceSpecifications(); + // await fetchUnits(); + // await fetchAgents(); + // await fetchResourceSpecifications(); }) // let selectedCommitment: any; @@ -539,6 +541,24 @@ const GET_ALL_RESOURCE_SPECIFICATIONS = gql` {/if} + {#if selectedCommitmentId} +
+ { + selectedCommitment.finished = e.target.checked + console.log(selectedCommitment.finished) + }} + bind:checked={finished} + class="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500" + > + + +
+ {/if} +
- } - - interface RspecResponse { - resourceSpecifications: AgentConnection & RelayConn - } - - - interface UnitsQueryResponse { - units: UnitConnection & RelayConn //& RelayConn | null | undefined - } - - let getUnits: ReadableQuery = query(GET_UNITS) +// const GET_UNITS = gql` +// query GetUnits { +// units { +// edges { +// cursor +// node { +// id +// label +// symbol +// } +// } +// } +// } +// ` + +// const GET_ALL_AGENTS = gql` +// query { +// agents(last: 100000) { +// edges { +// cursor +// node { +// id +// name +// } +// } +// } +// } +// ` + +// const GET_ALL_RESOURCE_SPECIFICATIONS = gql` +// ${RESOURCE_SPECIFICATION_CORE_FIELDS} +// ${UNIT_CORE_FIELDS} +// query { +// resourceSpecifications(last: 100000) { +// edges { +// cursor +// node { +// ...ResourceSpecificationCoreFields +// defaultUnitOfResource { +// ...UnitCoreFields +// } +// } +// } +// } +// } +// ` + +// interface QueryResponse { +// agents: AgentConnection & RelayConn +// } + +// interface RspecResponse { +// resourceSpecifications: AgentConnection & RelayConn +// } + + +// interface UnitsQueryResponse { +// units: UnitConnection & RelayConn //& RelayConn | null | undefined +// } + +// let getUnits: ReadableQuery = query(GET_UNITS) - // map component state - let agentsQuery: ReadableQuery = query(GET_ALL_AGENTS) - - let resourceSpecificationsQuery: ReadableQuery = query(GET_ALL_RESOURCE_SPECIFICATIONS) - - async function fetchUnits() { - getUnits.getCurrentResult() - getUnits.refetch().then((r) => { - if (r.data?.units.edges.length > 0) { - units = flattenRelayConnection(r.data?.units) - } - }) - } - - async function fetchAgents() { - await agentsQuery.getCurrentResult() - const a = await agentsQuery.refetch() - agents = flattenRelayConnection(a.data?.agents).map((a) => { - return { - ...a, - } - }) - console.log(agents) - } - - async function fetchResourceSpecifications() { - await resourceSpecificationsQuery.getCurrentResult() - let r = await resourceSpecificationsQuery.refetch() - resourceSpecifications = flattenRelayConnection(r.data?.resourceSpecifications).map((a) => { - return { - ...a, - defaultUnitOfResourceId: a.defaultUnitOfResource?.id, - } - }) - console.log(resourceSpecifications) - } +// // map component state +// let agentsQuery: ReadableQuery = query(GET_ALL_AGENTS) + +// let resourceSpecificationsQuery: ReadableQuery = query(GET_ALL_RESOURCE_SPECIFICATIONS) + +// async function fetchUnits() { +// getUnits.getCurrentResult() +// getUnits.refetch().then((r) => { +// if (r.data?.units.edges.length > 0) { +// units = flattenRelayConnection(r.data?.units) +// } +// }) +// } + +// async function fetchAgents() { +// await agentsQuery.getCurrentResult() +// const a = await agentsQuery.refetch() +// agents = flattenRelayConnection(a.data?.agents).map((a) => { +// return { +// ...a, +// } +// }) +// console.log(agents) +// } + +// async function fetchResourceSpecifications() { +// await resourceSpecificationsQuery.getCurrentResult() +// let r = await resourceSpecificationsQuery.refetch() +// resourceSpecifications = flattenRelayConnection(r.data?.resourceSpecifications).map((a) => { +// return { +// ...a, +// defaultUnitOfResourceId: a.defaultUnitOfResource?.id, +// } +// }) +// console.log(resourceSpecifications) +// } onMount(async() => { window.addEventListener('keydown', checkKey) - await fetchUnits(); - await fetchAgents(); - await fetchResourceSpecifications(); + // await fetchUnits(); + // await fetchAgents(); + // await fetchResourceSpecifications(); }) let newCommitmentTemplate = { @@ -480,7 +480,7 @@ const GET_ALL_RESOURCE_SPECIFICATIONS = gql` selectedCommitment.finished = e.target.checked console.log(selectedCommitment.finished) }} - bind:checked={finished} + bind:checked={selectedCommitment.finished} class="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500" > diff --git a/ui/src/lib/Nav.svelte b/ui/src/lib/Nav.svelte index f8c8200..d9c57f7 100644 --- a/ui/src/lib/Nav.svelte +++ b/ui/src/lib/Nav.svelte @@ -237,14 +237,14 @@ tabindex="-1" id="user-menu-item-1">Facets - + > -->
diff --git a/ui/src/lib/PlanModal.svelte b/ui/src/lib/PlanModal.svelte index 610e437..b3f8182 100644 --- a/ui/src/lib/PlanModal.svelte +++ b/ui/src/lib/PlanModal.svelte @@ -20,12 +20,12 @@ export let commitments: any; export let allColumns: any[]; export let commitmentsToDelete: any[] = []; - let agents: any[]; + export let units: Unit[]; + export let agents: any[]; + export let resourceSpecifications: any[]; + export let processSpecifications: any[]; let savingPlan: boolean = false; const delay = ms => new Promise(res => setTimeout(res, ms)); - let resourceSpecifications: any[]; - let processSpecifications: any[]; - let units: Unit[]; let commitmentsToSaveCount: number = 0; let commitmentsSavedCount: number = 0; let error: any; @@ -41,20 +41,20 @@ } } - const GET_UNITS = gql` - query GetUnits { - units { - edges { - cursor - node { - id - label - symbol - } - } - } - } - ` + // const GET_UNITS = gql` + // query GetUnits { + // units { + // edges { + // cursor + // node { + // id + // label + // symbol + // } + // } + // } + // } + // ` const CREATE_PLAN = gql` mutation($rs: PlanCreateParams!) { @@ -154,69 +154,69 @@ } ` - const GET_ALL_RESOURCE_SPECIFICATIONS = gql` - ${RESOURCE_SPECIFICATION_CORE_FIELDS} - query { - resourceSpecifications(last: 100000) { - edges { - cursor - node { - ...ResourceSpecificationCoreFields - } - } - } - } - ` - - const GET_ALL_PROCESS_SPECIFICATIONS = gql` - ${PROCESS_SPECIFICATION_CORE_FIELDS} - query { - processSpecifications(last: 100000) { - edges { - cursor - node { - ...ProcessSpecificationCoreFields - } - } - } - } - ` - - const GET_ALL_AGENTS = gql` - ${AGENT_CORE_FIELDS} - query { - agents(last: 100000) { - edges { - cursor - node { - id - name - classifiedAs - } - } - } - } - ` - - interface QueryResponse { - resourceSpecifications: AgentConnection & RelayConn - } - - interface ProcessQueryResponse { - processSpecifications: AgentConnection & RelayConn - } - - interface AgentQueryResponse { - agents: AgentConnection & RelayConn - } - - interface UnitsQueryResponse { - units: UnitConnection & RelayConn //& RelayConn | null | undefined - } - let getUnits: ReadableQuery = query(GET_UNITS) - let resourceSpecificationsQuery: ReadableQuery = query(GET_ALL_RESOURCE_SPECIFICATIONS) - let processSpecificationsQuery: ReadableQuery = query(GET_ALL_PROCESS_SPECIFICATIONS) - let agentsQuery: ReadableQuery = query(GET_ALL_AGENTS) + // const GET_ALL_RESOURCE_SPECIFICATIONS = gql` + // ${RESOURCE_SPECIFICATION_CORE_FIELDS} + // query { + // resourceSpecifications(last: 100000) { + // edges { + // cursor + // node { + // ...ResourceSpecificationCoreFields + // } + // } + // } + // } + // ` + + // const GET_ALL_PROCESS_SPECIFICATIONS = gql` + // ${PROCESS_SPECIFICATION_CORE_FIELDS} + // query { + // processSpecifications(last: 100000) { + // edges { + // cursor + // node { + // ...ProcessSpecificationCoreFields + // } + // } + // } + // } + // ` + + // const GET_ALL_AGENTS = gql` + // ${AGENT_CORE_FIELDS} + // query { + // agents(last: 100000) { + // edges { + // cursor + // node { + // id + // name + // classifiedAs + // } + // } + // } + // } + // ` + + // interface QueryResponse { + // resourceSpecifications: AgentConnection & RelayConn + // } + + // interface ProcessQueryResponse { + // processSpecifications: AgentConnection & RelayConn + // } + + // interface AgentQueryResponse { + // agents: AgentConnection & RelayConn + // } + + // interface UnitsQueryResponse { + // units: UnitConnection & RelayConn //& RelayConn | null | undefined + // } + // let getUnits: ReadableQuery = query(GET_UNITS) + // let resourceSpecificationsQuery: ReadableQuery = query(GET_ALL_RESOURCE_SPECIFICATIONS) + // let processSpecificationsQuery: ReadableQuery = query(GET_ALL_PROCESS_SPECIFICATIONS) + // let agentsQuery: ReadableQuery = query(GET_ALL_AGENTS) let addPlan: any = mutation(CREATE_PLAN) let updatePlan: any = mutation(UPDATE_PLAN) @@ -235,7 +235,7 @@ name: process.name, note: process.note, plannedWithin: process.plannedWithin, - basedOn: processSpecifications.find((rs) => rs.node.name === process.based_on.name).node.id, + basedOn: processSpecifications.find((rs) => rs.name === process.based_on.name).id, } let p = await addProcess({ variables: { @@ -309,24 +309,24 @@ finished: commitment.finished, note: commitment.note, hasBeginning: new Date(Date.now()), - resourceConformsTo: resourceSpecifications.find((rs) => rs.node.name === commitment.resourceConformsTo.name).node.id, + resourceConformsTo: resourceSpecifications.find((rs) => rs.name === commitment.resourceConformsTo.name).id, resourceQuantity: { hasNumericalValue: Number(commitment?.resourceQuantity?.hasNumericalValue), hasUnit: commitment?.resourceQuantity?.hasUnit?.id }, } - const defaultAgent = agents.find((a) => a.node.classifiedAs[2] === "Network").node + const defaultAgent = agents.find((a) => a.classifiedAs[2] === "Network") try { - o.provider = agents.find((a) => a.node.name === commitment.provider.name).node.id + o.provider = agents.find((a) => a.name === commitment.provider.name).id } catch (e) { console.log("can't find receiver", e) o.provider = defaultAgent.id console.log("saved by setting default agent", defaultAgent) } try { - o.receiver = agents.find((a) => a.node.name === commitment.receiver.name).node.id + o.receiver = agents.find((a) => a.name === commitment.receiver.name).id } catch (e) { console.log("can't find provider", e) o.receiver = defaultAgent.id @@ -398,10 +398,11 @@ // SAVE INDEPENDENT DEMANDS (commitments with no input or output) for (const c of commitments) { console.log(c) + console.log("agents", agents) let o = { ...c, // provider is carbon farm network - provider: agents.find((a) => a.node.classifiedAs[2] === "Network").node.id, + provider: agents.find((a) => a.classifiedAs[2] === "Network").id, // reciever is agent for request plannedWithin: p.data.res.plan.id, // references plan with independentDemandOf @@ -452,7 +453,7 @@ c.clauseOf = a.data.createAgreement.agreement.id // save cost commitment - const dollars = resourceSpecifications.find((rs) => rs.node.name === "USD") + const dollars = resourceSpecifications.find((rs) => rs.name === "USD") console.log("dollars", dollars) let payment: CommitmentCreateParams = { clauseOf: a.data.createAgreement.agreement.id, @@ -462,7 +463,7 @@ provider: c.receiver, receiver: c.provider, plannedWithin: p.data.res.plan.id, - resourceConformsTo: dollars.node, + resourceConformsTo: dollars, resourceQuantity: { hasNumericalValue: Number(c.agreement.commitment.resourceQuantity.hasNumericalValue), }, @@ -611,28 +612,28 @@ } - async function fetchUnits() { - getUnits.getCurrentResult() - getUnits.refetch().then((r) => { - if (r.data?.units.edges.length > 0) { - units = flattenRelayConnection(r.data?.units) - } - }) - } + // async function fetchUnits() { + // getUnits.getCurrentResult() + // getUnits.refetch().then((r) => { + // if (r.data?.units.edges.length > 0) { + // units = flattenRelayConnection(r.data?.units) + // } + // }) + // } onMount(async () => { - await fetchUnits(); - 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("loaded process specifications", processSpecifications) - const y = await agentsQuery.refetch() - console.log(y) - agents = y.data.agents.edges - console.log("loaded agents", agents) + // await fetchUnits(); + // 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("loaded process specifications", processSpecifications) + // const y = await agentsQuery.refetch() + // console.log(y) + // agents = y.data.agents.edges + // console.log("loaded agents", agents) window.addEventListener('keydown', checkKey) }) diff --git a/ui/src/routes/plans/new/+page.svelte b/ui/src/routes/plans/new/+page.svelte index f9d8497..a621eaa 100644 --- a/ui/src/routes/plans/new/+page.svelte +++ b/ui/src/routes/plans/new/+page.svelte @@ -8,22 +8,28 @@ import PlanModal from '$lib/PlanModal.svelte' import CommitmentModal from '$lib/CommitmentModal.svelte' import { Trash, Pencil, PlusCircle } from '$lib/icons' + // import plan from '$lib/data/plan.json' import Header from '$lib/Header.svelte' import { goto } from '$app/navigation' import { gql } from 'graphql-tag' import { PROPOSAL_CORE_FIELDS, INTENT_CORE_FIELDS, PROPOSED_INTENT_CORE_FIELDS, PROPOSAL_RETURN_FIELDS } from '$lib/graphql/proposal.fragments' + import { RESOURCE_SPECIFICATION_CORE_FIELDS, UNIT_CORE_FIELDS } from '$lib/graphql/resource_specification.fragments' + import { PROCESS_SPECIFICATION_CORE_FIELDS } from '$lib/graphql/process_specification.fragments' import { flattenRelayConnection } from '$lib/graphql/helpers' import { mutation, query } from 'svelte-apollo' import { onMount } from 'svelte' import { browser } from '$app/environment' import type { RelayConn } from '$lib/graphql/helpers' import type { ReadableQuery } from 'svelte-apollo' - import type { Unit, AgentConnection, Agent, Proposal, ProposalCreateParams, IntentCreateParams, IntentUpdateParams, UnitConnection, ResourceSpecification, ProposalConnection, ProposalUpdateParams, Intent, PlanCreateParams, PlanConnection } from '@valueflows/vf-graphql' + import type { Unit, AgentConnection, Agent, Proposal, ProposalCreateParams, IntentCreateParams, IntentUpdateParams, UnitConnection, ResourceSpecification, ProposalConnection, ProposalUpdateParams, Intent, PlanCreateParams, PlanConnection, ProcessConnection, CommitmentConnection } from '@valueflows/vf-graphql' import { dragscroll } from '@svelte-put/dragscroll'; let agents: Agent[] = [] + let units: Unit[] = [] + let resourceSpecifications: ResourceSpecification[] = [] + let processSpecifications: any[] = [] let commitmentModalProcess: number | undefined; let commitmentModalColumn: number | undefined; let commitmentModalSide: string | undefined; @@ -42,6 +48,53 @@ // currentProcess = allColumns[commitmentModalColumn][commitmentModalProcess][commitmentModalSide]; // } + const GET_UNITS = gql` + query GetUnits { + units { + edges { + cursor + node { + id + label + symbol + } + } + } + } + ` + + const GET_ALL_RESOURCE_SPECIFICATIONS = gql` + ${RESOURCE_SPECIFICATION_CORE_FIELDS} + ${UNIT_CORE_FIELDS} + query { + resourceSpecifications(last: 100000) { + edges { + cursor + node { + ...ResourceSpecificationCoreFields + defaultUnitOfResource { + ...UnitCoreFields + } + } + } + } + } + ` + + const GET_ALL_PROCESS_SPECIFICATIONS = gql` + ${PROCESS_SPECIFICATION_CORE_FIELDS} + query { + processSpecifications(last: 100000) { + edges { + cursor + node { + ...ProcessSpecificationCoreFields + } + } + } + } + ` + const GET_All_PROPOSALS = gql` ${PROPOSAL_RETURN_FIELDS} query { @@ -84,9 +137,75 @@ agents: AgentConnection & RelayConn } + interface ProcessQueryResponse { + processSpecifications: AgentConnection & RelayConn + } + + interface PlanQueryResponse { + plan: PlanConnection & RelayConn + } + + interface ProcessQueryResponse { + process: ProcessConnection & RelayConn + } + + interface RspecResponse { + resourceSpecifications: AgentConnection & RelayConn + } + + interface UnitsQueryResponse { + units: UnitConnection & RelayConn //& RelayConn | null | undefined + } + let getProposals: ReadableQuery = query(GET_All_PROPOSALS) let agentsQuery: ReadableQuery = query(GET_ALL_AGENTS) + let getUnits: ReadableQuery = query(GET_UNITS) + let resourceSpecificationsQuery: ReadableQuery = query(GET_ALL_RESOURCE_SPECIFICATIONS) + let processSpecificationsQuery: ReadableQuery = query(GET_ALL_PROCESS_SPECIFICATIONS) + async function fetchUnits() { + getUnits.getCurrentResult() + getUnits.refetch().then((r) => { + if (r.data?.units.edges.length > 0) { + units = flattenRelayConnection(r.data?.units) + } + }) + } + + async function fetchAgents() { + await agentsQuery.getCurrentResult() + const a = await agentsQuery.refetch() + agents = flattenRelayConnection(a.data?.agents).map((a) => { + return { + ...a, + } + }) + console.log(agents) + } + + async function fetchResourceSpecifications() { + await resourceSpecificationsQuery.getCurrentResult() + let r = await resourceSpecificationsQuery.refetch() + resourceSpecifications = flattenRelayConnection(r.data?.resourceSpecifications).map((a) => { + return { + ...a, + defaultUnitOfResourceId: a.defaultUnitOfResource?.id, + } + }) + console.log(resourceSpecifications) + } + + async function fetchProcessSpecifications() { + await processSpecificationsQuery.getCurrentResult() + let r = await processSpecificationsQuery.refetch() + processSpecifications = flattenRelayConnection(r.data?.processSpecifications).map((a) => { + return { + ...a, + } + }) + console.log(processSpecifications) + } + async function fetchProposals() { await getProposals.getCurrentResult() await getProposals.refetch().then((r) => { @@ -111,6 +230,10 @@ onMount(async () => { if (browser) { + await fetchUnits() + await fetchResourceSpecifications() + await fetchProcessSpecifications() + await fetchAgents() const y = await agentsQuery.refetch() agents = y.data.agents.edges.map((it) => {return {...it.node, role: it.node.classifiedAs[2]}}) console.log("agents", agents) @@ -658,7 +781,15 @@ - + { console.log(event.detail) diff --git a/ui/src/routes/plans/update/[plan_id]/+page.svelte b/ui/src/routes/plans/update/[plan_id]/+page.svelte index fb130f1..42b40d3 100644 --- a/ui/src/routes/plans/update/[plan_id]/+page.svelte +++ b/ui/src/routes/plans/update/[plan_id]/+page.svelte @@ -16,13 +16,15 @@ import { gql } from 'graphql-tag' import { PROPOSAL_CORE_FIELDS, INTENT_CORE_FIELDS, PROPOSED_INTENT_CORE_FIELDS, PROPOSAL_RETURN_FIELDS } from '$lib/graphql/proposal.fragments' import { COMMITMENT_RETURN_FIELDS, PLAN_RETURN_FIELDS, PROCESS_RETURN_FIELDS, SIMPLIFIED_PLAN_RETURN_FIELDS } from '$lib/graphql/plan.fragments' + import { RESOURCE_SPECIFICATION_CORE_FIELDS, UNIT_CORE_FIELDS } from '$lib/graphql/resource_specification.fragments' + import { PROCESS_SPECIFICATION_CORE_FIELDS } from '$lib/graphql/process_specification.fragments' import { flattenRelayConnection } from '$lib/graphql/helpers' import { mutation, query } from 'svelte-apollo' import { onMount } from 'svelte' import { browser } from '$app/environment' import type { RelayConn } from '$lib/graphql/helpers' import type { ReadableQuery } from 'svelte-apollo' - import type { Unit, AgentConnection, Agent, Proposal, Plan, ProposalCreateParams, IntentCreateParams, IntentUpdateParams, UnitConnection, ResourceSpecification, ProposalConnection, CommitmentConnection, ProposalUpdateParams, Intent, PlanCreateParams, PlanConnection, EconomicEventCreateParams, ProcessConnection, FulfillmentCreateParams } from '@valueflows/vf-graphql' + import type { Unit, AgentConnection, Agent, Proposal, Plan, ProposalCreateParams, IntentCreateParams, IntentUpdateParams, UnitConnection, ResourceSpecification, ProcessSpecification, ProposalConnection, CommitmentConnection, ProposalUpdateParams, Intent, PlanCreateParams, PlanConnection, EconomicEventCreateParams, ProcessConnection, FulfillmentCreateParams } from '@valueflows/vf-graphql' import { dragscroll } from '@svelte-put/dragscroll'; const delay = ms => new Promise(res => setTimeout(res, ms)); @@ -37,6 +39,10 @@ let selectedProcessId: string | undefined = undefined; let error: any; let yellow: any[] = [] + let units: Unit[] = [] + let agents: Agent[] = [] + let resourceSpecifications: ResourceSpecification[] = [] + let processSpecifications: ProcessSpecification[] = [] let processImages = { "Pick Up": "/farm.svg", @@ -60,6 +66,68 @@ let allColumns: any = [] $: loadingPlan, currentProcess + const GET_UNITS = gql` + query GetUnits { + units { + edges { + cursor + node { + id + label + symbol + } + } + } + } + ` + + const GET_ALL_AGENTS = gql` + query { + agents(last: 100000) { + edges { + cursor + node { + id + name + } + } + } + } + ` + + const GET_ALL_RESOURCE_SPECIFICATIONS = gql` + ${RESOURCE_SPECIFICATION_CORE_FIELDS} + ${UNIT_CORE_FIELDS} + query { + resourceSpecifications(last: 100000) { + edges { + cursor + node { + ...ResourceSpecificationCoreFields + defaultUnitOfResource { + ...UnitCoreFields + } + } + } + } + } + ` + + const GET_ALL_PROCESS_SPECIFICATIONS = gql` + ${PROCESS_SPECIFICATION_CORE_FIELDS} + query { + processSpecifications(last: 100000) { + edges { + cursor + node { + ...ProcessSpecificationCoreFields + } + } + } + } + ` + + const GET_All_PROPOSALS = gql` ${PROPOSAL_RETURN_FIELDS} query { @@ -150,6 +218,10 @@ let addFulfillment: any = mutation(CREATE_FULFILLMENT) let updateCommitment: any = mutation(UPDATE_COMMITMENT) + interface ProcessQueryResponse { + processSpecifications: AgentConnection & RelayConn + } + interface ProposalsQueryResponse { proposals: ProposalConnection & RelayConn } @@ -166,12 +238,74 @@ commitment: CommitmentConnection & RelayConn } + interface QueryResponse { + agents: AgentConnection & RelayConn + } + + interface RspecResponse { + resourceSpecifications: AgentConnection & RelayConn + } + + interface UnitsQueryResponse { + units: UnitConnection & RelayConn //& RelayConn | null | undefined + } + + let getUnits: ReadableQuery = query(GET_UNITS) + // map component state + let agentsQuery: ReadableQuery = query(GET_ALL_AGENTS) + let resourceSpecificationsQuery: ReadableQuery = query(GET_ALL_RESOURCE_SPECIFICATIONS) + let processSpecificationsQuery: ReadableQuery = query(GET_ALL_PROCESS_SPECIFICATIONS) let getProposals: ReadableQuery = query(GET_All_PROPOSALS) let getPlan: ReadableQuery = query(GET_PLAN); let getSimplifiedPlan: ReadableQuery = query(GET_SIMPLIFIED_PLAN); let getProcess: ReadableQuery = query(GET_PROCESS); let getCommitment: ReadableQuery = query(GET_COMMITMENT); + + async function fetchUnits() { + getUnits.getCurrentResult() + getUnits.refetch().then((r) => { + if (r.data?.units.edges.length > 0) { + units = flattenRelayConnection(r.data?.units) + } + }) + } + + async function fetchAgents() { + await agentsQuery.getCurrentResult() + const a = await agentsQuery.refetch() + agents = flattenRelayConnection(a.data?.agents).map((a) => { + return { + ...a, + } + }) + console.log(agents) + } + + async function fetchResourceSpecifications() { + await resourceSpecificationsQuery.getCurrentResult() + let r = await resourceSpecificationsQuery.refetch() + resourceSpecifications = flattenRelayConnection(r.data?.resourceSpecifications).map((a) => { + return { + ...a, + defaultUnitOfResourceId: a.defaultUnitOfResource?.id, + } + }) + console.log(resourceSpecifications) + } + + async function fetchProcessSpecifications() { + await processSpecificationsQuery.getCurrentResult() + let r = await processSpecificationsQuery.refetch() + processSpecifications = flattenRelayConnection(r.data?.processSpecifications).map((a) => { + return { + ...a, + } + }) + console.log(processSpecifications) + } + + async function fetchProposals() { try { await getProposals.getCurrentResult() @@ -380,6 +514,11 @@ // getPlan.setVariables({ // id: planId // }); + await fetchUnits() + await fetchAgents() + await fetchResourceSpecifications() + await fetchProcessSpecifications() + getSimplifiedPlan.setVariables({ id: planId }); @@ -529,7 +668,16 @@ {#if plan} - + {/if} {#if economicEventModalOpen} @@ -539,6 +687,10 @@ bind:open={economicEventModalOpen} {commitmentModalProcess} {commitmentModalColumn} {commitmentModalSide} + {units} + {agents} + {resourceSpecifications} + {processSpecifications} process = {currentProcess} bind:commitments on:submit={(event) => { @@ -557,6 +709,9 @@ bind:open={economicEventModalOpen} {commitmentModalProcess} {commitmentModalColumn} {commitmentModalSide} + {units} + {agents} + {resourceSpecifications} process = {currentProcess} bind:commitments on:submit={(event) => { @@ -879,7 +1034,8 @@ Loading processes ({processesLoadedCount}/{processesToLoadCount})