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:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
module datamodel
|
||||
|
||||
|
||||
|
||||
// typically 1GB of memory, but can be adjusted based based on size of machine
|
||||
@[heap]
|
||||
pub struct ComputeSlice {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
module datamodel
|
||||
|
||||
|
||||
// 1GB of storage
|
||||
@[heap]
|
||||
pub struct StorageSlice {
|
||||
@@ -11,6 +10,3 @@ pub mut:
|
||||
pricing_policy PricingPolicy // copied from node which is part of nodegroup
|
||||
sla_policy SLAPolicy
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -262,6 +262,7 @@ code {
|
||||
|
||||
/* Print styles */
|
||||
@media print {
|
||||
|
||||
.sidebar,
|
||||
.header,
|
||||
.theme-toggle {
|
||||
|
||||
Reference in New Issue
Block a user