aboutsummaryrefslogtreecommitdiff
path: root/vfs/vfs.ts
diff options
context:
space:
mode:
Diffstat (limited to 'vfs/vfs.ts')
-rw-r--r--vfs/vfs.ts80
1 files changed, 40 insertions, 40 deletions
diff --git a/vfs/vfs.ts b/vfs/vfs.ts
index a39f0f1..7372166 100644
--- a/vfs/vfs.ts
+++ b/vfs/vfs.ts
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-export interface IVfsNode {
+export interface WuiVfsNodeInterface {
name: string
path: string
is_dir?: boolean
@@ -11,36 +11,36 @@ export interface IVfsNode {
mod_time_rfc3339?: string
size?: number
mode?: string
- childs?: IVfsNode[]
+ childs?: WuiVfsNodeInterface[]
content?: string
}
-export interface Response {
+export interface WuiVfsResponseInterface {
code: number
message?: string
- data?: IVfsNode | IPathNode
+ data?: WuiVfsNodeInterface | WuiPathNodeInterface
}
-export interface VfsOptions {
+export interface WuiVfsOptions {
id: string
- ListNodes: () => IPathNode
+ ListNodes: () => WuiPathNodeInterface
// OnClickNode define an handler that will be called everytime a node is
// clicked. The is_dir will be true, if the node is a directory.
OnClickNode(path: string, is_dir: boolean): void
}
-export class Vfs {
+export class WuiVfs {
private el!: HTMLElement
- private com_path!: VfsPath
- private com_list!: VfsList
- private path_node: PathNode = {}
+ private com_path!: WuiVfsPath
+ private com_list!: WuiVfsList
+ private path_node: WuiPathNode = {}
- constructor(public opts: VfsOptions) {
+ constructor(public opts: WuiVfsOptions) {
let el = document.getElementById(opts.id)
if (!el) {
- console.error("Vfs: element id", opts.id, "not found")
+ console.error("WuiVfs: element id", opts.id, "not found")
return
}
this.el = el
@@ -48,8 +48,8 @@ export class Vfs {
//
// (0) Fetch the list of nodes from remote server and store it in path_node.
- // (1) Create the VfsPath
- // (2) Create the VfsList
+ // (1) Create the WuiVfsPath
+ // (2) Create the WuiVfsList
// (3) Open the root "/"
//
private async init() {
@@ -60,8 +60,8 @@ export class Vfs {
}
for (const key in res_path_node) {
- const value = res_path_node[key] as IVfsNode
- const node = new VfsNode(value, (node: VfsNode) => {
+ const value = res_path_node[key] as WuiVfsNodeInterface
+ const node = new WuiVfsNode(value, (node: WuiVfsNode) => {
if (this.opts.OnClickNode) {
this.opts.OnClickNode(node.path, node.is_dir)
}
@@ -75,37 +75,37 @@ export class Vfs {
this.el.innerHTML = ""
// (1)
- this.com_path = new VfsPath((path: string) => {
+ this.com_path = new WuiVfsPath((path: string) => {
this.OpenPath(path)
})
this.el.appendChild(this.com_path.el)
// (2)
- this.com_list = new VfsList()
+ this.com_list = new WuiVfsList()
this.el.appendChild(this.com_list.el)
// (3)
this.open(this.path_node["/"])
}
- private open(node: VfsNode) {
- this.com_path.open(node)
- this.com_list.open(node)
+ private open(node: WuiVfsNode) {
+ this.com_path.Open(node)
+ this.com_list.Open(node)
}
// OpenPath is a handler that will be called when the directory name on
// top of UI clicked.
- public OpenPath(this: Vfs, path: string) {
+ OpenPath(this: WuiVfs, path: string) {
const node = this.path_node[path]
if (!node) {
- console.error("Vfs: OpenPath: invalid path: ", path)
+ console.error("WuiVfs: OpenPath: invalid path: ", path)
return
}
this.open(node)
}
}
-class VfsNode implements IVfsNode {
+class WuiVfsNode implements WuiVfsNodeInterface {
path: string
name: string
mod_time_epoch: number
@@ -113,11 +113,11 @@ class VfsNode implements IVfsNode {
size: number
mode: string
is_dir: boolean
- childs: VfsNode[]
+ childs: WuiVfsNode[]
el: HTMLElement
- constructor(opts: IVfsNode, onClick: NodeClickHandler) {
+ constructor(opts: WuiVfsNodeInterface, onClick: NodeClickHandler) {
this.path = opts.path || ""
this.name = opts.name || ""
this.mod_time_epoch = opts.mod_time_epoch || 0
@@ -129,7 +129,7 @@ class VfsNode implements IVfsNode {
this.childs = []
if (opts.childs !== undefined) {
for (let c of opts.childs) {
- this.childs.push(new VfsNode(c, onClick))
+ this.childs.push(new WuiVfsNode(c, onClick))
}
}
@@ -153,19 +153,19 @@ class VfsNode implements IVfsNode {
}
}
- onMouseOut(t: VfsNode) {
+ onMouseOut(t: WuiVfsNode) {
if (this.is_dir) {
this.el.style.backgroundColor = "cornsilk"
} else {
t.el.style.backgroundColor = "white"
}
}
- onMouseOver(t: VfsNode) {
+ onMouseOver(t: WuiVfsNode) {
t.el.style.backgroundColor = "aliceblue"
}
}
-class VfsList {
+class WuiVfsList {
el: HTMLElement
constructor() {
@@ -175,7 +175,7 @@ class VfsList {
this.el.style.borderColor = "silver"
}
- open(node: VfsNode) {
+ Open(node: WuiVfsNode) {
this.el.innerHTML = ""
if (node.childs === undefined) {
@@ -188,7 +188,7 @@ class VfsList {
}
}
-class VfsPath {
+class WuiVfsPath {
el: HTMLElement
private crumbs: string[]
private onClick: PathClickHandler
@@ -202,7 +202,7 @@ class VfsPath {
this.onClick = onClick
}
- open(node: VfsNode) {
+ Open(node: WuiVfsNode) {
this.el.innerHTML = ""
this.crumbs = []
let paths = []
@@ -245,21 +245,21 @@ class VfsPath {
}
}
- onMouseOut(crumb: HTMLElement, event: MouseEvent) {
+ private onMouseOut(crumb: HTMLElement, event: MouseEvent) {
crumb.style.backgroundColor = "white"
}
- onMouseOver(crumb: HTMLElement, event: MouseEvent) {
+ private onMouseOver(crumb: HTMLElement, event: MouseEvent) {
crumb.style.backgroundColor = "aliceblue"
}
}
-type IPathNode = {
- [key: string]: IVfsNode
+type WuiPathNode = {
+ [key: string]: WuiVfsNode
}
-type PathNode = {
- [key: string]: VfsNode
+type WuiPathNodeInterface = {
+ [key: string]: WuiVfsNodeInterface
}
-type NodeClickHandler = (node: VfsNode) => void
+type NodeClickHandler = (node: WuiVfsNode) => void
type PathClickHandler = (path: string) => void