Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for OC10 admin menu #73

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions drawio/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@

use OCP\App;

App::registerAdmin("drawio", "settings");

$app = new Application();
4 changes: 2 additions & 2 deletions drawio/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<repository type="git">https://github.com/pawelrojek/nextcloud-drawio.git</repository>
<dependencies>
<nextcloud min-version="11" max-version="15"/>
<owncloud min-version="10.0" max-version="10.1" />
<owncloud min-version="10" max-version="10" />
</dependencies>
<settings>
<admin>OCA\Drawio\AdminSettings</admin>
<admin>OCA\Drawio\Settings\AdminSettings</admin>
</settings>
</info>
3 changes: 2 additions & 1 deletion drawio/controller/editorcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ private function getFile($fileId)
return [null, $this->trans->t("FileId is empty")];
}

$files = $this->root->getById($fileId);
//$files = $this->root->getById($fileId);
$files = \OC::$server->getUserFolder()->getById($fileId);
if (empty($files))
{
return [null, $this->trans->t("File not found")];
Expand Down
102 changes: 102 additions & 0 deletions drawio/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,106 @@
}
window.addEventListener("message", receiver);
}

OCA.DrawIO.EditFileWImport = function (editWindow, filePath, origin) {
var ncClient = OC.Files.getClient();
var supportedExtension = "drawio"

// Check extension
var isSupportedExt = filePath.split('.').pop() == supportedExtension
// Response arraybuffer for non XML files
if (isSupportedExt) {
var responseType = ""
var fileToSave = filePath
} else {
var responseType = "arraybuffer"
var date = new Date()
var datetime = "Opened_" +
date.getDate() + "-" +
(date.getMonth()+1) + "-" +
date.getFullYear() + "_T" +
date.getHours() + "." +
date.getMinutes()
var fileToSave = filePath + "_" + datetime + "." + supportedExtension
}

var receiver = function (evt) {
if (evt.data.length > 0 && origin.includes(evt.origin)) {
var payload = JSON.parse(evt.data);
if (payload.event === "init") {
var loadMsg = OC.Notification.show(t(OCA.DrawIO.AppName, "Loading, please wait."));
ncClient.getFileContentsRT(filePath, null, responseType)
.then(function (status, contents) {
if(isSupportedExt) {
if (contents === " ") {
editWindow.postMessage(JSON.stringify({
action: "template",
name: filePath
}), "*");
} else if (contents.indexOf("mxGraphModel") !== -1) {
// TODO: show error to user
OCA.DrawIO.Cleanup(receiver, filePath);
} else {
editWindow.postMessage(JSON.stringify({
action: "load",
xml: contents
}), "*");
}
} else {
blob = new Blob([contents], {type: "application/vnd.visio"})

reader = new FileReader();
reader.onloadend = function() {
editWindow.postMessage(JSON.stringify({
action: "load",
title: fileToSave,
xml: reader.result
}), "*");
}
reader.readAsDataURL(blob);
}
})
.fail(function (status) {
console.log("Status Error: " + status);
// TODO: show error on failed read
OCA.DrawIO.Cleanup(receiver, filePath);
})
.done(function () {
OC.Notification.hide(loadMsg);
});
} else if (payload.event === "load") {
// TODO: notify user of loaded
} else if (payload.event === "export") {
// TODO: handle export event
} else if (payload.event === "save") {
var saveMsg = OC.Notification.show(t(OCA.DrawIO.AppName, "Saving..."));
ncClient.putFileContents(
fileToSave,
payload.xml, {
contentType: "x-application/drawio",
overwrite: false
}
)
.then(function (status) {
OC.Notification.showTemporary(t(OCA.DrawIO.AppName, "File saved as " + fileToSave));
})
.fail(function (status) {
// TODO: handle on failed write
OC.Notification.showTemporary(t(OCA.DrawIO.AppName, "File not saved!"));
})
.done(function () {
OC.Notification.hide(saveMsg);
});
} else if (payload.event === "exit") {
OCA.DrawIO.Cleanup(receiver, filePath);
} else {
console.log("DrawIO Integration: unknown event " + payload.event);
console.dir(payload);
}
} else {
console.log("DrawIO Integration: bad origin " + evt.origin);
}
}
window.addEventListener("message", receiver);
}
})(OCA);
4 changes: 2 additions & 2 deletions drawio/lib/appconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class AppConfig {

private $predefDrawioUrl = "https://www.draw.io";
private $predefDrawioUrl = "https://embed.diagrams.net";
private $predefOverrideXML = "yes";
private $predefOfflineMode = "no";
private $predefTheme = "kennedy"; //kennedy, minimal, atlas, dark
Expand Down Expand Up @@ -123,4 +123,4 @@ public function GetLang()
"drawio" => [ "mime" => "application/x-drawio", "type" => "text" ]
];

}
}