From 55d72fe6c56d417141c0c535517ce0bdb88c9329 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Tue, 26 Sep 2023 22:54:37 +0300 Subject: [PATCH 01/56] Add createFarm in chain & client --- packages/grid_client/scripts/create_farm.ts | 11 +++++++++ packages/grid_client/src/modules/farms.ts | 8 ++++++- packages/grid_client/src/modules/models.ts | 11 +++++++++ packages/tfchain_client/src/client.ts | 4 ++-- packages/tfchain_client/src/farms.ts | 25 +++++++++++++++++++-- 5 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 packages/grid_client/scripts/create_farm.ts diff --git a/packages/grid_client/scripts/create_farm.ts b/packages/grid_client/scripts/create_farm.ts new file mode 100644 index 0000000000..254bce268c --- /dev/null +++ b/packages/grid_client/scripts/create_farm.ts @@ -0,0 +1,11 @@ +import { getClient } from "./client_loader"; + +async function main() { + const grid3 = await getClient(); + + await grid3.farms.create({ name: "test-farm" }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/src/modules/farms.ts b/packages/grid_client/src/modules/farms.ts index b358cdd388..8a723afa94 100644 --- a/packages/grid_client/src/modules/farms.ts +++ b/packages/grid_client/src/modules/farms.ts @@ -2,7 +2,7 @@ import { TFClient } from "../clients/tf-grid/client"; import { GridClientConfig } from "../config"; import { expose } from "../helpers/expose"; import { validateInput } from "../helpers/validator"; -import { FarmIdModel } from "./models"; +import { CreateFarmModel, FarmIdModel } from "./models"; class Farms { client: TFClient; @@ -11,6 +11,12 @@ class Farms { this.client = new TFClient(config.substrateURL, config.mnemonic, config.storeSecret, config.keypairType); } + @expose + @validateInput + async create(options: CreateFarmModel) { + return (await this.client.farms.create(options)).apply(); + } + @expose @validateInput async getFarmByID(options: FarmIdModel) { diff --git a/packages/grid_client/src/modules/models.ts b/packages/grid_client/src/modules/models.ts index fb8923f5ed..7b056e786c 100644 --- a/packages/grid_client/src/modules/models.ts +++ b/packages/grid_client/src/modules/models.ts @@ -642,6 +642,16 @@ class FarmIdModel { @Expose() @IsInt() @IsNotEmpty() @Min(1) id: number; } +class FarmPublicIPsModel { + @Expose() @IsOptional() @IsIP() ip?: number; + @Expose() @IsOptional() gw?: number; +} + +class CreateFarmModel { + @Expose() @IsString() @IsNotEmpty() @MaxLength(NameLength) name: string; + @Expose() @IsOptional() publicIps?: FarmPublicIPsModel; +} + class pingFarmModel { @Expose() @IsInt() @IsNotEmpty() @Min(1) farmId: number; } @@ -777,6 +787,7 @@ export { ZOSNodeModel, NodePowerModel, FarmIdModel, + CreateFarmModel, pingFarmModel, CreateServiceContractModel, ServiceContractApproveModel, diff --git a/packages/tfchain_client/src/client.ts b/packages/tfchain_client/src/client.ts index a27c821483..4bb674cdcd 100644 --- a/packages/tfchain_client/src/client.ts +++ b/packages/tfchain_client/src/client.ts @@ -12,7 +12,7 @@ import { validateMnemonic } from "bip39"; import { Balances, QueryBalances } from "./balances"; import { Contracts, QueryContracts } from "./contracts"; import { Dao, QueryDao } from "./dao"; -import { QueryFarms } from "./farms"; +import { Farms, QueryFarms } from "./farms"; import { KVStore } from "./kvstore"; import { Nodes, QueryNodes } from "./nodes"; import { QueryPricingPolicies } from "./pricing_policies"; @@ -230,10 +230,10 @@ class Client extends QueryClient { termsAndConditions: TermsAndConditions = new TermsAndConditions(this); kvStore: KVStore = new KVStore(this); twins: Twins = new Twins(this); + farms: Farms = new Farms(this); dao: Dao = new Dao(this); tftBridge: Bridge = new Bridge(this); - declare url: string; mnemonicOrSecret?: string; keypairType: KeypairType; diff --git a/packages/tfchain_client/src/farms.ts b/packages/tfchain_client/src/farms.ts index be497ab285..77c83eac05 100644 --- a/packages/tfchain_client/src/farms.ts +++ b/packages/tfchain_client/src/farms.ts @@ -1,4 +1,4 @@ -import { QueryClient } from "./client"; +import { Client, QueryClient } from "./client"; import { PublicIp } from "./types"; import { checkConnection } from "./utils"; @@ -32,6 +32,14 @@ interface QueryFarmsGetOptions { id: number; } +interface CreateFarmOptions { + name: string; + publicIps?: { + ip?: number; + gw?: number; + }; +} + class QueryFarms { constructor(public client: QueryClient) { this.client = client; @@ -44,4 +52,17 @@ class QueryFarms { } } -export { QueryFarms, Farm, Certification, FarmingPolicyLimits }; +class Farms extends QueryFarms { + constructor(public client: Client) { + super(client); + this.client = client; + } + + @checkConnection + async create(options: CreateFarmOptions) { + const extrinsic = this.client.api.tx.tfgridModule.createFarm(options.name, options.publicIps); + return this.client.patchExtrinsic(extrinsic); + } +} + +export { QueryFarms, Farms, Farm, Certification, FarmingPolicyLimits }; From 770047867fb3e80efce09cd7420c40bd21253858 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Tue, 26 Sep 2023 22:59:13 +0300 Subject: [PATCH 02/56] Add farms page layout & route --- .../dashboard/portal/farm_nodes.vue | 12 +++++++++ .../dashboard/portal/user_farms.vue | 12 +++++++++ packages/playground/src/portal/farms_view.vue | 27 +++++++++++++++++++ packages/playground/src/router/index.ts | 5 ++++ 4 files changed, 56 insertions(+) create mode 100644 packages/playground/src/components/dashboard/portal/farm_nodes.vue create mode 100644 packages/playground/src/components/dashboard/portal/user_farms.vue create mode 100644 packages/playground/src/portal/farms_view.vue diff --git a/packages/playground/src/components/dashboard/portal/farm_nodes.vue b/packages/playground/src/components/dashboard/portal/farm_nodes.vue new file mode 100644 index 0000000000..9f327c19f8 --- /dev/null +++ b/packages/playground/src/components/dashboard/portal/farm_nodes.vue @@ -0,0 +1,12 @@ + + + diff --git a/packages/playground/src/components/dashboard/portal/user_farms.vue b/packages/playground/src/components/dashboard/portal/user_farms.vue new file mode 100644 index 0000000000..d32e51970e --- /dev/null +++ b/packages/playground/src/components/dashboard/portal/user_farms.vue @@ -0,0 +1,12 @@ + + + diff --git a/packages/playground/src/portal/farms_view.vue b/packages/playground/src/portal/farms_view.vue new file mode 100644 index 0000000000..3373594f4e --- /dev/null +++ b/packages/playground/src/portal/farms_view.vue @@ -0,0 +1,27 @@ + + + diff --git a/packages/playground/src/router/index.ts b/packages/playground/src/router/index.ts index 427aecd1bb..cbe983017b 100644 --- a/packages/playground/src/router/index.ts +++ b/packages/playground/src/router/index.ts @@ -37,6 +37,11 @@ const router = createRouter({ component: () => import("../portal/transfer_view.vue"), meta: { title: "Transfer" }, }, + { + path: "farms", + component: () => import("../portal/farms_view.vue"), + meta: { title: "Farms" }, + }, ], }, From 88929858617f85a04e2fd8e48bebc7c3cc313e43 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Tue, 26 Sep 2023 23:21:56 +0300 Subject: [PATCH 03/56] Add getUserFarms --- .../scripts/{create_farm.ts => farms.ts} | 2 ++ packages/grid_client/src/modules/capacity.ts | 6 ++++++ packages/grid_client/src/modules/models.ts | 5 +++++ packages/grid_client/src/primitives/nodes.ts | 14 ++++++++++++++ 4 files changed, 27 insertions(+) rename packages/grid_client/scripts/{create_farm.ts => farms.ts} (68%) diff --git a/packages/grid_client/scripts/create_farm.ts b/packages/grid_client/scripts/farms.ts similarity index 68% rename from packages/grid_client/scripts/create_farm.ts rename to packages/grid_client/scripts/farms.ts index 254bce268c..7e892fa754 100644 --- a/packages/grid_client/scripts/create_farm.ts +++ b/packages/grid_client/scripts/farms.ts @@ -4,6 +4,8 @@ async function main() { const grid3 = await getClient(); await grid3.farms.create({ name: "test-farm" }); + const farms = await grid3.capacity.getUserFarms({ twinId: 89 }); + console.log(farms); await grid3.disconnect(); } diff --git a/packages/grid_client/src/modules/capacity.ts b/packages/grid_client/src/modules/capacity.ts index 5960a84a6a..ec1ae5bc83 100644 --- a/packages/grid_client/src/modules/capacity.ts +++ b/packages/grid_client/src/modules/capacity.ts @@ -13,6 +13,7 @@ import { NodeFreeResourcesModel, NodesByFarmIdModel, NodesGetModel, + UserFarmsGetModel, } from "./models"; class Capacity { @@ -37,6 +38,11 @@ class Capacity { return await this.nodes.getAllFarms(); } + @expose + async getUserFarms(options: UserFarmsGetModel): Promise { + return await this.nodes.getUserFarms(options.twinId); + } + @expose async getAllNodes(): Promise { return await this.nodes.getAllNodes(); diff --git a/packages/grid_client/src/modules/models.ts b/packages/grid_client/src/modules/models.ts index 7b056e786c..2332e106bd 100644 --- a/packages/grid_client/src/modules/models.ts +++ b/packages/grid_client/src/modules/models.ts @@ -529,6 +529,10 @@ class FarmsGetModel { @Expose() @IsInt() @Min(1) @IsOptional() maxResult?: number; // default 50 } +class UserFarmsGetModel { + @Expose() @IsInt() @Min(1) @IsNotEmpty() twinId: number; +} + class NodesGetModel extends FarmsGetModel {} class FarmHasFreePublicIPsModel { @@ -802,4 +806,5 @@ export { GetDedicatedNodePriceModel, SwapToStellarModel, ListenToMintCompletedModel, + UserFarmsGetModel, }; diff --git a/packages/grid_client/src/primitives/nodes.ts b/packages/grid_client/src/primitives/nodes.ts index eec2300530..e216079fed 100644 --- a/packages/grid_client/src/primitives/nodes.ts +++ b/packages/grid_client/src/primitives/nodes.ts @@ -166,6 +166,20 @@ class Nodes { }); } + async getUserFarms(twinId: number, page = 1, pageSize = 50, url = ""): Promise { + let r: string; + if (url) r = url; + else r = this.proxyURL; + + return send("get", urlJoin(r, `/farms?twin_id=${twinId}&page=${page}&size=${pageSize}`), "", {}) + .then(res => { + return res; + }) + .catch(err => { + throw Error(`Error listing farms for twin id ${twinId}: ${err}`); + }); + } + async getAllFarms(url = ""): Promise { try { const farmsCount = await this.gqlClient.getItemTotalCount("farms", "(orderBy: farmID_ASC)"); From 153d4c5276976009ce337334d7d9d30d352d3ebf Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Wed, 27 Sep 2023 01:19:46 +0300 Subject: [PATCH 04/56] Implement addFarmIP, removeFarmIP, addPublicConfig, addStellarAddress in chain & client --- packages/grid_client/src/modules/farms.ts | 20 +++++++++++++- packages/grid_client/src/modules/models.ts | 32 ++++++++++++++++++++++ packages/grid_client/src/modules/nodes.ts | 12 ++++++-- packages/tfchain_client/src/farms.ts | 32 ++++++++++++++++++++++ packages/tfchain_client/src/nodes.ts | 20 ++++++++++++++ 5 files changed, 112 insertions(+), 4 deletions(-) diff --git a/packages/grid_client/src/modules/farms.ts b/packages/grid_client/src/modules/farms.ts index 8a723afa94..1ac48bbdbc 100644 --- a/packages/grid_client/src/modules/farms.ts +++ b/packages/grid_client/src/modules/farms.ts @@ -2,7 +2,7 @@ import { TFClient } from "../clients/tf-grid/client"; import { GridClientConfig } from "../config"; import { expose } from "../helpers/expose"; import { validateInput } from "../helpers/validator"; -import { CreateFarmModel, FarmIdModel } from "./models"; +import { AddFarmIPModel, AddStellarModel, CreateFarmModel, FarmIdModel, RemoveFarmIPModel } from "./models"; class Farms { client: TFClient; @@ -17,6 +17,24 @@ class Farms { return (await this.client.farms.create(options)).apply(); } + @expose + @validateInput + async addFarmIp(options: AddFarmIPModel) { + return (await this.client.farms.addFarmIp(options)).apply(); + } + + @expose + @validateInput + async removeFarmIp(options: RemoveFarmIPModel) { + return (await this.client.farms.removeFarmIp(options)).apply(); + } + + @expose + @validateInput + async addStellarAddress(options: AddStellarModel) { + return (await this.client.farms.addStellarAddress(options)).apply(); + } + @expose @validateInput async getFarmByID(options: FarmIdModel) { diff --git a/packages/grid_client/src/modules/models.ts b/packages/grid_client/src/modules/models.ts index 2332e106bd..ec66aca386 100644 --- a/packages/grid_client/src/modules/models.ts +++ b/packages/grid_client/src/modules/models.ts @@ -651,6 +651,34 @@ class FarmPublicIPsModel { @Expose() @IsOptional() gw?: number; } +class AddFarmIPModel { + @Expose() @IsInt() @IsNotEmpty() @Min(1) farmId: number; + @Expose() @IsInt() @IsNotEmpty() @IsIP() ip: number; + @Expose() @IsInt() @IsNotEmpty() gw: number; +} + +class PublicConfigModel { + @Expose() @IsInt() @IsNotEmpty() @IsIP() ip?: number; + @Expose() @IsInt() @IsNotEmpty() gw?: number; + @Expose() @IsInt() @IsNotEmpty() @IsIP() ip6?: number; + @Expose() @IsString() @IsNotEmpty() domain?: string; +} +class AddPublicConfig { + @Expose() @IsInt() @IsNotEmpty() @Min(1) farmId: number; + @Expose() @IsInt() @IsNotEmpty() @Min(1) nodeId: number; + @Expose() @IsNotEmpty() publicConfig: PublicConfigModel; +} + +class RemoveFarmIPModel { + @Expose() @IsInt() @IsNotEmpty() @Min(1) farmId: number; + @Expose() @IsInt() @IsNotEmpty() @IsIP() ip: number; +} + +class AddStellarModel { + @Expose() @IsInt() @IsNotEmpty() @Min(1) farmId: number; + @Expose() @IsString() @IsNotEmpty() stellarAddress: string; +} + class CreateFarmModel { @Expose() @IsString() @IsNotEmpty() @MaxLength(NameLength) name: string; @Expose() @IsOptional() publicIps?: FarmPublicIPsModel; @@ -807,4 +835,8 @@ export { SwapToStellarModel, ListenToMintCompletedModel, UserFarmsGetModel, + AddFarmIPModel, + RemoveFarmIPModel, + AddStellarModel, + AddPublicConfig, }; diff --git a/packages/grid_client/src/modules/nodes.ts b/packages/grid_client/src/modules/nodes.ts index c4edfa1c31..bf1c6f8b34 100644 --- a/packages/grid_client/src/modules/nodes.ts +++ b/packages/grid_client/src/modules/nodes.ts @@ -1,10 +1,9 @@ -import urlJoin from "url-join"; - import { TFClient } from "../clients"; import { GridClientConfig } from "../config"; -import { events, send, validateInput } from "../helpers"; +import { events, validateInput } from "../helpers"; import { expose } from "../helpers/expose"; import { + AddPublicConfig, NodeGetModel, NodePowerModel, RentContractCreateModel, @@ -79,6 +78,13 @@ class Nodes { async setNodePower(options: NodePowerModel) { return (await this.client.nodes.setPower(options)).apply(); } + + @expose + @validateInput + @checkBalance + async addNodePublicConfig(options: AddPublicConfig) { + return (await this.client.nodes.addNodePublicConfig(options)).apply(); + } } export { Nodes as nodes }; diff --git a/packages/tfchain_client/src/farms.ts b/packages/tfchain_client/src/farms.ts index 77c83eac05..745678d7f4 100644 --- a/packages/tfchain_client/src/farms.ts +++ b/packages/tfchain_client/src/farms.ts @@ -39,7 +39,21 @@ interface CreateFarmOptions { gw?: number; }; } +interface AddFarmIPOptions { + farmId: number; + ip: number; + gw: number; +} + +interface RemoveFarmIPOptions { + farmId: number; + ip: number; +} +interface AddStellarOptions { + farmId: number; + stellarAddress: string; +} class QueryFarms { constructor(public client: QueryClient) { this.client = client; @@ -63,6 +77,24 @@ class Farms extends QueryFarms { const extrinsic = this.client.api.tx.tfgridModule.createFarm(options.name, options.publicIps); return this.client.patchExtrinsic(extrinsic); } + + @checkConnection + async addFarmIp(options: AddFarmIPOptions) { + const extrinsic = this.client.api.tx.tfgridModule.addFarmIp(options.farmId, options.ip, options.gw); + return this.client.patchExtrinsic(extrinsic); + } + + @checkConnection + async removeFarmIp(options: RemoveFarmIPOptions) { + const extrinsic = this.client.api.tx.tfgridModule.removeFarmIp(options.farmId, options.ip); + return this.client.patchExtrinsic(extrinsic); + } + + @checkConnection + async addStellarAddress(options: AddStellarOptions) { + const extrinsic = this.client.api.tx.tfgridModule.addStellaPayoutV2address(options.farmId, options.stellarAddress); + return this.client.patchExtrinsic(extrinsic); + } } export { QueryFarms, Farms, Farm, Certification, FarmingPolicyLimits }; diff --git a/packages/tfchain_client/src/nodes.ts b/packages/tfchain_client/src/nodes.ts index ca0cb88113..d4fa3ede4d 100644 --- a/packages/tfchain_client/src/nodes.ts +++ b/packages/tfchain_client/src/nodes.ts @@ -53,6 +53,16 @@ interface NodeLocation { longitude: number; } +interface AddNodePublicConfigOptions { + farmId: number; + nodeId: number; + publicConfig: { + ip?: number; + gw?: number; + ip6?: number; + domain?: string; + }; +} export interface QueryNodesGetOptions { id: number; } @@ -93,6 +103,16 @@ class Nodes extends QueryNodes { const extrinsic = await this.client.api.tx.tfgridModule.changePowerTarget(options.nodeId, powerTarget); return this.client.patchExtrinsic(extrinsic); } + + @checkConnection + async addNodePublicConfig(options: AddNodePublicConfigOptions) { + const extrinsic = this.client.api.tx.tfgridModule.addNodePublicConfig( + options.farmId, + options.nodeId, + options.publicConfig, + ); + return this.client.patchExtrinsic(extrinsic); + } } export { Nodes, QueryNodes }; From 63ba81b9a9f50b3c6987e8719cb17ebf126f32f2 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Wed, 27 Sep 2023 17:31:50 +0300 Subject: [PATCH 05/56] Create grid store & set it in profile store --- packages/playground/src/App.vue | 4 +++- .../dashboard/portal/farm_nodes.vue | 2 +- .../dashboard/portal/user_farms.vue | 24 ++++++++++++++++--- packages/playground/src/stores/grid.ts | 24 +++++++++++++++++++ packages/playground/src/stores/index.ts | 1 + .../playground/src/stores/profile_manager.ts | 3 +++ 6 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 packages/playground/src/stores/grid.ts diff --git a/packages/playground/src/App.vue b/packages/playground/src/App.vue index 094405a526..a1f19aeae5 100644 --- a/packages/playground/src/App.vue +++ b/packages/playground/src/App.vue @@ -123,7 +123,7 @@
- +
@@ -141,11 +141,13 @@ import { computed, ref, watch } from "vue"; import { useRoute, useRouter } from "vue-router"; +import { useGrid } from "./stores/grid"; import { useProfileManager } from "./stores/profile_manager"; const $route = useRoute(); const $router = useRouter(); const profileManager = useProfileManager(); +const gridStore = useGrid(); const network = process.env.NETWORK || (window as any).env.NETWORK; const openProfile = ref(true); diff --git a/packages/playground/src/components/dashboard/portal/farm_nodes.vue b/packages/playground/src/components/dashboard/portal/farm_nodes.vue index 9f327c19f8..096579926f 100644 --- a/packages/playground/src/components/dashboard/portal/farm_nodes.vue +++ b/packages/playground/src/components/dashboard/portal/farm_nodes.vue @@ -2,7 +2,7 @@ this is farm nodes - diff --git a/packages/playground/src/stores/grid.ts b/packages/playground/src/stores/grid.ts new file mode 100644 index 0000000000..0be9263423 --- /dev/null +++ b/packages/playground/src/stores/grid.ts @@ -0,0 +1,24 @@ +import type { GridClient } from "@threefold/grid_client"; +import { defineStore } from "pinia"; + +import { getGrid } from "@/utils/grid"; + +import type { Profile } from "./profile_manager"; + +interface IGrid { + grid: GridClient; +} + +const useGrid = defineStore("grid-client", { + state: (): IGrid => { + return { grid: null as any }; + }, + + actions: { + async set(profile: Profile | null) { + this.grid = profile ? ((await getGrid(profile)) as any) : null; + }, + }, +}); + +export { useGrid }; diff --git a/packages/playground/src/stores/index.ts b/packages/playground/src/stores/index.ts index 9dd3c8e953..538dd04ac0 100644 --- a/packages/playground/src/stores/index.ts +++ b/packages/playground/src/stores/index.ts @@ -1 +1,2 @@ export { useProfileManager } from "./profile_manager"; +export { useGrid } from "./grid"; diff --git a/packages/playground/src/stores/profile_manager.ts b/packages/playground/src/stores/profile_manager.ts index ecab50cf82..8bb993379e 100644 --- a/packages/playground/src/stores/profile_manager.ts +++ b/packages/playground/src/stores/profile_manager.ts @@ -1,5 +1,7 @@ import { defineStore } from "pinia"; +import { useGrid } from "./grid"; + export interface Profile { mnemonic: string; ssh: string; @@ -21,6 +23,7 @@ const useProfileManager = defineStore("profile-manager", { actions: { set(profile: Profile | null) { this.profile = profile; + useGrid().set(profile); }, updateSSH(ssh: string) { if (this.profile) { From 21b5a0cf0193d9694ed553fb05cb90fd5b55ca2a Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Thu, 28 Sep 2023 10:30:59 +0300 Subject: [PATCH 06/56] add getUserNodes --- packages/grid_client/src/modules/capacity.ts | 6 ++ packages/grid_client/src/modules/models.ts | 3 + packages/grid_client/src/primitives/nodes.ts | 14 +++++ packages/playground/src/App.vue | 4 +- .../dashboard/portal/farm_nodes.vue | 17 +++++- .../dashboard/portal/user_farms.vue | 59 +++++++++++++++---- 6 files changed, 88 insertions(+), 15 deletions(-) diff --git a/packages/grid_client/src/modules/capacity.ts b/packages/grid_client/src/modules/capacity.ts index ec1ae5bc83..66586ce9b0 100644 --- a/packages/grid_client/src/modules/capacity.ts +++ b/packages/grid_client/src/modules/capacity.ts @@ -14,6 +14,7 @@ import { NodesByFarmIdModel, NodesGetModel, UserFarmsGetModel, + UserNodesGetModel, } from "./models"; class Capacity { @@ -43,6 +44,11 @@ class Capacity { return await this.nodes.getUserFarms(options.twinId); } + @expose + async getUserNodes(options: UserNodesGetModel): Promise { + return await this.nodes.getUserNodes(options.twinId); + } + @expose async getAllNodes(): Promise { return await this.nodes.getAllNodes(); diff --git a/packages/grid_client/src/modules/models.ts b/packages/grid_client/src/modules/models.ts index ec66aca386..0b6981f93a 100644 --- a/packages/grid_client/src/modules/models.ts +++ b/packages/grid_client/src/modules/models.ts @@ -533,6 +533,8 @@ class UserFarmsGetModel { @Expose() @IsInt() @Min(1) @IsNotEmpty() twinId: number; } +class UserNodesGetModel extends UserFarmsGetModel {} + class NodesGetModel extends FarmsGetModel {} class FarmHasFreePublicIPsModel { @@ -839,4 +841,5 @@ export { RemoveFarmIPModel, AddStellarModel, AddPublicConfig, + UserNodesGetModel, }; diff --git a/packages/grid_client/src/primitives/nodes.ts b/packages/grid_client/src/primitives/nodes.ts index e216079fed..e20821afc3 100644 --- a/packages/grid_client/src/primitives/nodes.ts +++ b/packages/grid_client/src/primitives/nodes.ts @@ -180,6 +180,20 @@ class Nodes { }); } + async getUserNodes(twinId: number, page = 1, pageSize = 50, url = ""): Promise { + let r: string; + if (url) r = url; + else r = this.proxyURL; + + return send("get", urlJoin(r, `/nodes?twin_id=${twinId}&page=${page}&size=${pageSize}`), "", {}) + .then(res => { + return res; + }) + .catch(err => { + throw Error(`Error listing nodes for twin id ${twinId}: ${err}`); + }); + } + async getAllFarms(url = ""): Promise { try { const farmsCount = await this.gqlClient.getItemTotalCount("farms", "(orderBy: farmID_ASC)"); diff --git a/packages/playground/src/App.vue b/packages/playground/src/App.vue index a1f19aeae5..094405a526 100644 --- a/packages/playground/src/App.vue +++ b/packages/playground/src/App.vue @@ -123,7 +123,7 @@
- +
@@ -141,13 +141,11 @@ import { computed, ref, watch } from "vue"; import { useRoute, useRouter } from "vue-router"; -import { useGrid } from "./stores/grid"; import { useProfileManager } from "./stores/profile_manager"; const $route = useRoute(); const $router = useRouter(); const profileManager = useProfileManager(); -const gridStore = useGrid(); const network = process.env.NETWORK || (window as any).env.NETWORK; const openProfile = ref(true); diff --git a/packages/playground/src/components/dashboard/portal/farm_nodes.vue b/packages/playground/src/components/dashboard/portal/farm_nodes.vue index 096579926f..c9db5786dd 100644 --- a/packages/playground/src/components/dashboard/portal/farm_nodes.vue +++ b/packages/playground/src/components/dashboard/portal/farm_nodes.vue @@ -3,10 +3,25 @@ diff --git a/packages/playground/src/components/dashboard/portal/user_farms.vue b/packages/playground/src/components/dashboard/portal/user_farms.vue index ae20fa3541..47a257ff22 100644 --- a/packages/playground/src/components/dashboard/portal/user_farms.vue +++ b/packages/playground/src/components/dashboard/portal/user_farms.vue @@ -1,29 +1,66 @@ diff --git a/packages/playground/src/components/dashboard/portal/user_farms.vue b/packages/playground/src/components/dashboard/portal/user_farms.vue index 47a257ff22..aaa94d7c15 100644 --- a/packages/playground/src/components/dashboard/portal/user_farms.vue +++ b/packages/playground/src/components/dashboard/portal/user_farms.vue @@ -1,8 +1,33 @@ diff --git a/packages/playground/src/portal/farms_view.vue b/packages/playground/src/portal/farms_view.vue index 3373594f4e..86677b8501 100644 --- a/packages/playground/src/portal/farms_view.vue +++ b/packages/playground/src/portal/farms_view.vue @@ -5,19 +5,19 @@ Farms - + - + diff --git a/packages/playground/src/components/dashboard/portal/user_farms.vue b/packages/playground/src/components/dashboard/portal/user_farms.vue index aaa94d7c15..453ae685fc 100644 --- a/packages/playground/src/components/dashboard/portal/user_farms.vue +++ b/packages/playground/src/components/dashboard/portal/user_farms.vue @@ -1,22 +1,22 @@ -