...
This commit is contained in:
@@ -4,8 +4,6 @@ import freeflowuniverse.herolib.core.base
|
|||||||
import freeflowuniverse.herolib.core.playbook { PlayBook }
|
import freeflowuniverse.herolib.core.playbook { PlayBook }
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import time
|
|
||||||
|
|
||||||
__global (
|
__global (
|
||||||
heroprompt_global map[string]&Workspace
|
heroprompt_global map[string]&Workspace
|
||||||
@@ -18,32 +16,13 @@ __global (
|
|||||||
pub struct ArgsGet {
|
pub struct ArgsGet {
|
||||||
pub mut:
|
pub mut:
|
||||||
name string = 'default'
|
name string = 'default'
|
||||||
path string
|
|
||||||
fromdb bool // will load from filesystem
|
fromdb bool // will load from filesystem
|
||||||
create bool // default will not create if not exist
|
create bool // default will not create if not exist
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(args ArgsGet) !&Workspace {
|
pub fn new(args ArgsGet) !&Workspace {
|
||||||
// validate
|
|
||||||
if args.name.len == 0 {
|
|
||||||
return error('workspace name is required')
|
|
||||||
}
|
|
||||||
mut base_path := ''
|
|
||||||
if args.path.len > 0 {
|
|
||||||
if !os.exists(args.path) {
|
|
||||||
return error('workspace path does not exist: ${args.path}')
|
|
||||||
}
|
|
||||||
if !os.is_dir(args.path) {
|
|
||||||
return error('workspace path is not a directory: ${args.path}')
|
|
||||||
}
|
|
||||||
base_path = os.real_path(args.path)
|
|
||||||
}
|
|
||||||
mut obj := Workspace{
|
mut obj := Workspace{
|
||||||
name: args.name
|
name: args.name
|
||||||
base_path: base_path
|
|
||||||
created: time.now()
|
|
||||||
updated: time.now()
|
|
||||||
is_saved: false
|
|
||||||
}
|
}
|
||||||
set(obj)!
|
set(obj)!
|
||||||
return get(name: args.name)!
|
return get(name: args.name)!
|
||||||
@@ -57,7 +36,7 @@ pub fn get(args ArgsGet) !&Workspace {
|
|||||||
if r.hexists('context:heroprompt', args.name)! {
|
if r.hexists('context:heroprompt', args.name)! {
|
||||||
data := r.hget('context:heroprompt', args.name)!
|
data := r.hget('context:heroprompt', args.name)!
|
||||||
if data.len == 0 {
|
if data.len == 0 {
|
||||||
return error('Workspace with name: ${args.name} does not exist, prob bug.')
|
return error('Workspace with name: heroprompt does not exist, prob bug.')
|
||||||
}
|
}
|
||||||
mut obj := json.decode(Workspace, data)!
|
mut obj := json.decode(Workspace, data)!
|
||||||
set_in_mem(obj)!
|
set_in_mem(obj)!
|
||||||
@@ -65,7 +44,7 @@ pub fn get(args ArgsGet) !&Workspace {
|
|||||||
if args.create {
|
if args.create {
|
||||||
new(args)!
|
new(args)!
|
||||||
} else {
|
} else {
|
||||||
return error("Workspace with name '${args.name}' does not exist")
|
return error("Workspace with name 'heroprompt' does not exist")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return get(name: args.name)! // no longer from db nor create
|
return get(name: args.name)! // no longer from db nor create
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ fn obj_init(mycfg_ Workspace) !Workspace {
|
|||||||
/////////////NORMALLY NO NEED TO TOUCH
|
/////////////NORMALLY NO NEED TO TOUCH
|
||||||
|
|
||||||
pub fn heroscript_loads(heroscript string) !Workspace {
|
pub fn heroscript_loads(heroscript string) !Workspace {
|
||||||
mut obj := encoderhero.decode[Workspace](heroscript)!
|
// TODO: go from heroscript to object
|
||||||
|
$dbg;
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import veb
|
|||||||
import os
|
import os
|
||||||
import net.http
|
import net.http
|
||||||
|
|
||||||
|
|
||||||
// Public Context type for veb
|
// Public Context type for veb
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
veb.Context
|
veb.Context
|
||||||
@@ -38,41 +39,6 @@ pub mut:
|
|||||||
port int
|
port int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global registry (multi-instance support by name)
|
|
||||||
__global (
|
|
||||||
uireg map[string]&App
|
|
||||||
)
|
|
||||||
|
|
||||||
// Create a new app (does not start the server)
|
|
||||||
pub fn new(args FactoryArgs) !&App {
|
|
||||||
name := if args.name.len == 0 { 'default' } else { args.name }
|
|
||||||
if app := uireg[name] {
|
|
||||||
return app
|
|
||||||
}
|
|
||||||
mut app := &App{
|
|
||||||
title: args.title
|
|
||||||
menu: if args.menu.len > 0 { args.menu } else { default_menu() }
|
|
||||||
port: args.port
|
|
||||||
}
|
|
||||||
uireg[name] = app
|
|
||||||
return app
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get a named app
|
|
||||||
pub fn get(name string) !&App {
|
|
||||||
mut app := uireg[name] or {
|
|
||||||
return error('ui: app "${name}" not found, call ui.new(...) first')
|
|
||||||
}
|
|
||||||
return app
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get default app (creates if not existing)
|
|
||||||
pub fn default() !&App {
|
|
||||||
if uireg.len == 0 {
|
|
||||||
return new(port: 8080)!
|
|
||||||
}
|
|
||||||
return get('default')!
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the webserver (blocking)
|
// Start the webserver (blocking)
|
||||||
pub fn start(args FactoryArgs) ! {
|
pub fn start(args FactoryArgs) ! {
|
||||||
|
|||||||
Reference in New Issue
Block a user