diff --git a/controllers/file_cache.go b/controllers/file_cache.go
index ea78ba7..45659cd 100644
--- a/controllers/file_cache.go
+++ b/controllers/file_cache.go
@@ -8,11 +8,61 @@ import (
)
var cacheDir = "C:/casbase_cache"
+var cacheMap = map[string]string{}
+
+func getCachePrefix(filename string) string {
+ if !strings.HasPrefix(filename, "ECG_") && !strings.HasPrefix(filename, "EEG_") && !strings.HasPrefix(filename, "Impedance_") {
+ return ""
+ }
+
+ tokens := strings.SplitN(filename, "_", 2)
+ res := tokens[0]
+ return res
+}
func addFileToCache(key string, filename string, bs []byte) {
- if strings.HasPrefix(filename, "ECG_") || strings.HasPrefix(filename, "EEG_") || strings.HasPrefix(filename, "Impedance_") {
- path := fmt.Sprintf("%s/%s/%s", cacheDir, key, filename)
- util.EnsureFileFolderExists(path)
- util.WriteBytesToPath(bs, path)
+ prefix := getCachePrefix(filename)
+ if prefix == "" {
+ return
+ }
+
+ path := fmt.Sprintf("%s/%s/%s", cacheDir, key, filename)
+ util.EnsureFileFolderExists(path)
+ util.WriteBytesToPath(bs, path)
+}
+
+func (c *ApiController) ActivateFile() {
+ _, ok := c.RequireSignedIn()
+ if !ok {
+ return
+ }
+
+ key := c.Input().Get("key")
+ filename := c.Input().Get("filename")
+
+ prefix := getCachePrefix(filename)
+ if prefix == "" {
+ c.Data["json"] = false
+ c.ServeJSON()
+ return
}
+
+ path := fmt.Sprintf("%s/%s", cacheDir, key)
+ cacheMap[prefix] = path
+ fmt.Printf("%v\n", cacheMap)
+
+ c.Data["json"] = true
+ c.ServeJSON()
+}
+
+func (c *ApiController) GetActiveFile() {
+ prefix := c.Input().Get("prefix")
+
+ res := ""
+ if v, ok := cacheMap[prefix]; ok {
+ res = v
+ }
+
+ c.Data["json"] = res
+ c.ServeJSON()
}
diff --git a/routers/router.go b/routers/router.go
index 8e5a4c1..46b0925 100644
--- a/routers/router.go
+++ b/routers/router.go
@@ -55,6 +55,8 @@ func initAPI() {
beego.Router("/api/update-file", &controllers.ApiController{}, "POST:UpdateFile")
beego.Router("/api/add-file", &controllers.ApiController{}, "POST:AddFile")
beego.Router("/api/delete-file", &controllers.ApiController{}, "POST:DeleteFile")
+ beego.Router("/api/activate-file", &controllers.ApiController{}, "POST:ActivateFile")
+ beego.Router("/api/get-active-file", &controllers.ApiController{}, "GET:GetActiveFile")
beego.Router("/api/get-permissions", &controllers.ApiController{}, "GET:GetPermissions")
beego.Router("/api/get-permission", &controllers.ApiController{}, "GET:GetPermission")
diff --git a/web/src/FileTree.js b/web/src/FileTree.js
index 483c3cf..ba86227 100644
--- a/web/src/FileTree.js
+++ b/web/src/FileTree.js
@@ -11,7 +11,6 @@ import * as PermissionBackend from "./backend/PermissionBackend";
import * as PermissionUtil from "./PermissionUtil";
import * as Conf from "./Conf";
import FileTable from "./FileTable";
-import DataChart from "./DataChart";
import {Controlled as CodeMirror} from "react-codemirror2";
import "codemirror/lib/codemirror.css";
@@ -231,6 +230,16 @@ class FileTree extends React.Component {
)
}
+ getCachePrefix(filename) {
+ if (!filename.startsWith("ECG_") && !filename.startsWith("EEG_") && !filename.startsWith("Impedance_")) {
+ return "";
+ }
+
+ const tokens = filename.split("_");
+ const res = tokens[0];
+ return res;
+ }
+
renderTree(store) {
const onSelect = (selectedKeys, info) => {
if (!this.isFileReadable(info.node)) {
@@ -239,26 +248,47 @@ class FileTree extends React.Component {
}
if (selectedKeys.length !== 0) {
- const path = selectedKeys[0];
- const ext = Setting.getExtFromPath(path);
- if (ext !== "") {
- const url = `${store.domain}/${path}`;
-
- if (!this.isExtForDocViewer((ext) && !this.isExtForFileViewer(ext))) {
- this.setState({
- loading: true,
- });
-
- fetch(url, {method: 'GET'})
- .then(res => res.text())
- .then(res => {
- this.setState({
- text: res,
- loading: false,
+ const fetchFile = () => {
+ const path = selectedKeys[0];
+ const ext = Setting.getExtFromPath(path);
+ if (ext !== "") {
+ const url = `${store.domain}/${path}`;
+
+ if (!this.isExtForDocViewer((ext) && !this.isExtForFileViewer(ext))) {
+ this.setState({
+ loading: true,
+ });
+
+ fetch(url, {method: 'GET'})
+ .then(res => res.text())
+ .then(res => {
+ this.setState({
+ text: res,
+ loading: false,
+ });
});
- });
+ }
}
}
+
+ const key = info.node.key;
+ const filename = info.node.title;
+ if (this.getCachePrefix(filename) !== "") {
+ FileBackend.activateFile(key, filename)
+ .then((res) => {
+ if (res === true) {
+ // Setting.showMessage("success", `File activated successfully`);
+ fetchFile();
+ } else {
+ Setting.showMessage("error", `File failed to activate: ${res}`);
+ }
+ })
+ .catch(error => {
+ Setting.showMessage("error", `File failed to activate: ${error}`);
+ });
+ } else {
+ fetchFile();
+ }
}
this.setState({
@@ -546,10 +576,10 @@ class FileTree extends React.Component {
const ext = Setting.getExtFromPath(path);
const url = `${store.domain}/${path}`;
- if (this.isDataFile(filename)) {
- const appName = "ecg_1";
+ const prefix = this.getCachePrefix(filename);
+ if (prefix !== "") {
return (
-
+
//
)
} else if (this.isExtForDocViewer(ext)) {
diff --git a/web/src/backend/FileBackend.js b/web/src/backend/FileBackend.js
index a58c28f..2f20d2c 100644
--- a/web/src/backend/FileBackend.js
+++ b/web/src/backend/FileBackend.js
@@ -25,3 +25,10 @@ export function deleteFile(storeId, key, isLeaf) {
credentials: 'include',
}).then(res => res.json());
}
+
+export function activateFile(key, filename) {
+ return fetch(`${Setting.ServerUrl}/api/activate-file?key=${key}&filename=${filename}`, {
+ method: 'POST',
+ credentials: 'include',
+ }).then(res => res.json());
+}