Skip to content

Commit

Permalink
Merge pull request #2 from kevinramage/develop
Browse files Browse the repository at this point in the history
feat: File explorer
  • Loading branch information
kevinramage authored Oct 5, 2024
2 parents b874843 + bee0f52 commit 712c88f
Show file tree
Hide file tree
Showing 16 changed files with 730 additions and 60 deletions.
43 changes: 43 additions & 0 deletions doc/mermaid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Mermaid support

- [ ] FlowChart
- [ ] Title
- [ ] Orientation
- [ ] Node positionning
- [ ] Node size
- [ ] Text size
- [ ] Markdown formatting
- [ ] Square node
- [ ] Round edge node
- [ ] Stadium shaped node
- [ ] Subroutine node
- [ ] Cylindrical node
- [ ] Circle node
- [ ] Asymmetric node
- [ ] Rhombus node
- [ ] Hexagon node
- [ ] Parallelogram node
- [ ] Parallelogram alt node
- [ ] Trapezoid node
- [ ] Trapezoid alt node
- [ ] Double circle node
- [ ] Link arrow head
- [ ] Link open link
- [ ] Link with text
- [ ] Dotted link
- [ ] Dotted link with text
- [ ] Thick link
- [ ] Thick link with text
- [ ] Invisible link
- [ ] Circle Edge link
- [ ] Cross Edge link
- [ ] Multi directionnal arrow link
- [ ] Length of link
- [ ] Sub graph
- [ ] Interaction
- [ ] Style and classes
- [ ] Fontawesome
- [ ] New shapes 11.3


[Source](https://mermaid.js.org/syntax/flowchart.html#a-stadium-shaped-node)
15 changes: 14 additions & 1 deletion doc/version.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,17 @@ This document help to understand the content of each versions
- [x] Instanciate default workspace with two file (index.md and example.md)
- [x] Open default workspace when window ready
- [x] List all file present in repository and show it in file exporer view
- [x] When click on a file, open markdown view (Editor view and renderer view)
- [x] When click on a file, open markdown view (Editor view and renderer view)

**V 0.0.2 - File explorer**

- [X] Create a new file
- [X] Delete a file
- [X] Update exiting file
- [X] Initialize Mermaid FlowChart rendering

**V 0.0.3 - Markdown toolbar**

- [ ] View directory in file explore
- [ ] Add markdown editor WYSIWYG for basic feature
- [ ] Add Mermaid FlowChart relationship rendering
58 changes: 57 additions & 1 deletion server/business/documentBusiness.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFile } from "fs/promises";
import { readFile, rename, unlink, writeFile } from "fs/promises";
import { fastify } from "../index.ts";
import { IDocument } from "../../common/document.ts";
import { basename } from "path";
Expand All @@ -23,4 +23,60 @@ export class DocumentBusiness {
});
});
}
public static addNewFile(path: string) {
return new Promise<IDocument>((resolve, reject) => {
fastify.log.info("DocumentBusiness.addNewFile - Call method");
writeFile(path, "").then(() => {
const document : IDocument = {
id: v4(),
path: path,
name: basename(path),
content: ""
}
resolve(document);
}).catch((err) => {
fastify.log.error("DocumentBusiness.addNewFile - An error occured: ", err);
reject(err);
})
});
}
public static updateFile(id: string, path: string, content: string) {
return new Promise<IDocument>((resolve, reject) => {
fastify.log.info("DocumentBusiness.updateFile - Call method");
writeFile(path, content).then(() => {
const document : IDocument = {
id: id,
path: path,
name: basename(path),
content: content
}
resolve(document);
}).catch((err) => {
fastify.log.error("DocumentBusiness.updateFile - An error occured: ", err);
reject(err);
})
});
}
public static deleteFile(path: string) {
return new Promise<void>((resolve, reject) => {
fastify.log.info("DocumentBusiness.deleteFile - Call method");
unlink(path).then(() => {
resolve();
}).catch((err) => {
fastify.log.error("DocumentBusiness.deleteFile - An error occured: ", err);
reject(err);
})
});
}
public static renameFile(oldPath: string, newPath: string) {
return new Promise<void>((resolve, reject) => {
fastify.log.info("DocumentBusiness.renameFile - Call method");
rename(oldPath, newPath).then(() => {
resolve();
}).catch((err) => {
fastify.log.error("DocumentBusiness.renameFile - An error occured: ", err);
reject(err);
})
});
}
}
32 changes: 30 additions & 2 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,39 @@ fastify.get('/api/v1/workspace/', async function handler (_, reply) {
});

// Read document from path
fastify.post('/api/v1/document/', async function handler(request, reply) {
fastify.post('/api/v1/document/read', async function handler(request, reply) {
const data = request.body as { path: string };
const document = await DocumentBusiness.readDocument(data.path);
return document;
})
});

// Rename file
fastify.post('/api/v1/document/rename', async function handler(request, reply) {
const data = request.body as { oldPath: string, newPath: string };
await DocumentBusiness.renameFile(data.oldPath, data.newPath);
return {};
});

// Add new file
fastify.post('/api/v1/document/', async function handler(request, reply) {
const data = request.body as { path: string };
const document = await DocumentBusiness.addNewFile(data.path);
return document;
});

// Update file
fastify.put('/api/v1/document/', async function handler(request, reply) {
const data = request.body as { id: string, path: string, content: string };
const document = await DocumentBusiness.updateFile(data.id, data.path, data.content);
return document;
});

// Delete file
fastify.delete('/api/v1/document/', async function handler(request, reply) {
const data = request.body as { path: string };
await DocumentBusiness.deleteFile(data.path);
return {};
});

fastify.get('/api/v1/ping', async function handler (request, reply) {
return { status: "OK" }
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name = "Knownledga"
version = "0.0.1"
description = ""
authors = ["you"]
license = ""
authors = ["Kevin RAMAGE"]
license = "MIT"
repository = ""
edition = "2021"
rust-version = "1.57"
Expand Down
7 changes: 2 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ function App() {

// Load default workspace
serviceManager.loadWorkspaceByName("default").then((workspace) => { setWorkspace(workspace); });

// Init event manager
eventManager.listen();
}, [])

return (
Expand All @@ -38,12 +35,12 @@ function App() {
<Panel className='panel' defaultSize={100}>
<PanelGroup direction='horizontal'>
<Panel className='panel' defaultSize={options.panels.left.size} minSize={10} maxSize={20}>
<FileExporerView workspace={workspace} />
<FileExporerView workspace={workspace} eventManager={eventManager} />
</Panel>
<PanelResizeHandle className='panelResize' />
<Panel className='panel'>
{ workspace.selectedDocument && (
<MarkdownView document={workspace.selectedDocument} />
<MarkdownView document={workspace.selectedDocument} eventManager={eventManager} />
)}
</Panel>
{ !options.panels.right.disable && (
Expand Down
137 changes: 116 additions & 21 deletions src/business/eventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,126 @@ export class EventManager {
this._workspace = workspace;
this._setWorkspace = setWorkspace;
}

public listen() {
document.addEventListener
document.addEventListener(SELECTDOCUMENT_EVENT, (e) => {
const customEvent = e as CustomEvent;
this.selectDocumentEvent(customEvent);
customEvent.stopImmediatePropagation()
}, true );
}

private selectDocumentEvent(e: CustomEvent) {
const document = e.detail.document as IDocument;
if (this._service) {
this._service.loadDocumentByPath(document.path).then((doc) => {
if (this._workspace && this._setWorkspace) {
this._setWorkspace({
...this._workspace,

public selectDocument(document: IDocument) {
return new Promise<IDocument|null>((resolve) => {
const workspace = this._workspace;
const setWorkspace = this._setWorkspace;
if (this._service && workspace && setWorkspace) {
this._service.loadDocumentByPath(document.path).then((doc) =>{
setWorkspace({
...workspace,
selectedDocument: doc,
documents: this._workspace.documents.map((d => {
if (d.path === doc.path) { return { ...d, content: doc.content }
documents: workspace.documents.map((d => {
if (document.path === doc.path) { return { ...d, content: doc.content }
} else { return d; }
}))
})
}
});
resolve(doc);
}).catch(() => {
resolve(null);
})
} else {
resolve(null);
}
});
}

public unSelectDocument() {
const workspace = this._workspace;
const setWorkspace = this._setWorkspace;
if (workspace && setWorkspace) {
setWorkspace({
...workspace,
selectedDocument: undefined
})
}
}

public addFile(newFileName: string) {
return new Promise<void>((resolve) => {
const workspace = this._workspace;
const setWorkspace = this._setWorkspace;
if (this._service && workspace && setWorkspace) {
this._service.addNewFile(newFileName).then((doc) => {
setWorkspace({
...workspace,
selectedDocument: doc,
documents: [ ...workspace.documents, doc ]
})
}).finally(() => {
resolve();
})
} else {
resolve();
}
});
}

public updateFile(id: string, path: string, content: string) {
return new Promise<void>((resolve) => {
const workspace = this._workspace;
const setWorkspace = this._setWorkspace;
if (this._service && workspace && setWorkspace) {
this._service.updateFileContent(id, path, content).then((doc) => {
setWorkspace({
...workspace,
documents: workspace.documents.map((d => {
if (d.path === path) { return doc }
else { return d }
}))
})
}).finally(() => {
resolve();
})
} else {
resolve();
}
});
}

public deleteFile(path: string) {
return new Promise<void>((resolve) => {
const service = this._service;
const workspace = this._workspace;
const setWorkspace = this._setWorkspace;
if (service && workspace && setWorkspace) {
service.deleteFile(path).then(() => {
setWorkspace({
...workspace,
documents: workspace.documents.filter(d => { return d.path !== path; })
})
}).finally(() => {
resolve();
})
} else {
resolve();
}
});
}

public renameFile(id: string, oldPath: string, newPath: string) {
return new Promise<void>((resolve) => {
const workspace = this._workspace;
const setWorkspace = this._setWorkspace;
if (this._service && workspace && setWorkspace) {
this._service.renameFile(oldPath, newPath).then(() => {
setWorkspace({
...workspace,
documents: workspace.documents.map(d => {
if (d.id === id) { return {
...d,
path: newPath
} }
else { return d; }
})
})
}).finally(() => {
resolve();
})
} else {
resolve();
}
});
}
}
Loading

0 comments on commit 712c88f

Please sign in to comment.