feat: Add directory listing functionality

- Add `list_dir` function to `Workspace` struct
- Implement path handling and directory scanning logic
- Refine struct formatting for `Node`, `ComputeSlice`, `StorageSlice`
- Update `StorageSlice.pricing_policy` comment
- Adjust whitespace in CSS styles
This commit is contained in:
Mahmoud-Emad
2025-08-24 12:00:12 +03:00
parent 3050433cfd
commit 6098f166bb
5 changed files with 60 additions and 56 deletions

View File

@@ -220,6 +220,44 @@ pub:
typ string @[json: 'type']
}
pub fn (wsp &Workspace) list_dir(rel_path string) ![]ListItem {
mut dir := if rel_path.len > 0 {
if os.is_abs_path(rel_path) {
rel_path
} else {
os.join_path(wsp.base_path, rel_path)
}
} else {
wsp.base_path
}
if dir.len == 0 {
return error('workspace base_path not set')
}
if !os.is_abs_path(dir) {
dir = os.join_path(wsp.base_path, dir)
}
entries := os.ls(dir) or { return error('cannot list directory') }
mut out := []ListItem{}
for e in entries {
full := os.join_path(dir, e)
if os.is_dir(full) {
out << ListItem{
name: e
typ: 'directory'
}
} else if os.is_file(full) {
out << ListItem{
name: e
typ: 'file'
}
}
}
return out
}
pub fn (wsp &Workspace) list() ![]ListItem {
mut dir := wsp.base_path
if dir.len == 0 {

View File

@@ -3,18 +3,18 @@ module datamodel
@[heap]
pub struct Node {
pub mut:
id int
nodegroupid int
uptime int // 0..100
computeslices []ComputeSlice
storageslices []StorageSlice
devices DeviceInfo
country string // 2 letter code as specified in lib/data/countries/data/countryInfo.txt, use that library for validation
capacity NodeCapacity // Hardware capacity details
provisiontime u32 // lets keep it simple and compatible
pubkey string
signature_node string //signature done on node to validate pubkey with privkey
signature_farmer string //signature as done by farmers to validate their identity
id int
nodegroupid int
uptime int // 0..100
computeslices []ComputeSlice
storageslices []StorageSlice
devices DeviceInfo
country string // 2 letter code as specified in lib/data/countries/data/countryInfo.txt, use that library for validation
capacity NodeCapacity // Hardware capacity details
provisiontime u32 // lets keep it simple and compatible
pubkey string
signature_node string // signature done on node to validate pubkey with privkey
signature_farmer string // signature as done by farmers to validate their identity
}
pub struct DeviceInfo {
@@ -78,35 +78,6 @@ pub mut:
vcores int // Total virtual cores
}
// typically 1GB of memory, but can be adjusted based based on size of machine
pub struct ComputeSlice {
pub mut:
nodeid u32 // the node in the grid, there is an object describing the node
id int // the id of the slice in the node
mem_gb f64
storage_gb f64
passmark int
vcores int
cpu_oversubscription int
storage_oversubscription int
price_range []f64 = [0.0, 0.0]
gpus u8 // nr of GPU's see node to know what GPU's are
price_cc f64 // price per slice (even if the grouped one)
pricing_policy PricingPolicy
sla_policy SLAPolicy
}
// 1GB of storage
pub struct StorageSlice {
pub mut:
nodeid u32 // the node in the grid
id int // the id of the slice in the node, are tracked in the node itself
price_cc f64 // price per slice (even if the grouped one)
pricing_policy PricingPolicy
sla_policy SLAPolicy
}
fn (mut n Node) check() ! {
// todo calculate NodeCapacity out of the devices on the Node
}

View File

@@ -1,7 +1,5 @@
module datamodel
// typically 1GB of memory, but can be adjusted based based on size of machine
@[heap]
pub struct ComputeSlice {

View File

@@ -1,16 +1,12 @@
module datamodel
// 1GB of storage
@[heap]
pub struct StorageSlice {
pub mut:
nodeid u32 // the node in the grid
id int // the id of the slice in the node, are tracked in the node itself
price_cc f64 // price per slice (even if the grouped one)
pricing_policy PricingPolicy //copied from node which is part of nodegroup
nodeid u32 // the node in the grid
id int // the id of the slice in the node, are tracked in the node itself
price_cc f64 // price per slice (even if the grouped one)
pricing_policy PricingPolicy // copied from node which is part of nodegroup
sla_policy SLAPolicy
}

View File

@@ -262,6 +262,7 @@ code {
/* Print styles */
@media print {
.sidebar,
.header,
.theme-toggle {