diff --git a/README.md b/README.md new file mode 100644 index 0000000..112382f --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Draw.io +Create, edit and share drawio diagrams right within ownCloud! + +![Screenshot of drawio editor](screenshot.png?raw=true "Embedded drawio editor") + +Author: Tom Needham + +### Configuration + +You can set the drawio hostname to use a self hosted instance using `occ`: + +`occ config:app:set drawio host_url https://my.draw.io.host.com` \ No newline at end of file diff --git a/appinfo/app.php b/appinfo/app.php index 5e0857f..8098de1 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -22,5 +22,7 @@ new \OCA\Drawio\Application( \OC::$server->getEventDispatcher(), - \OC::$server->getUserSession() + \OC::$server->getUserSession(), + \OC::$server->getConfig() ); + diff --git a/appinfo/routes.php b/appinfo/routes.php index 6543b03..33ea797 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -22,7 +22,8 @@ $app = new \OCA\Drawio\Application( \OC::$server->getEventDispatcher(), - \OC::$server->getUserSession() + \OC::$server->getUserSession(), + \OC::$server->getConfig() ); $app->registerRoutes( $this, [ diff --git a/js/editor.js b/js/editor.js index bfdab9e..e4980cb 100644 --- a/js/editor.js +++ b/js/editor.js @@ -29,6 +29,15 @@ }; } + OCA.Drawio.LoadPublicFileHandler = function(eventHandler, downloadPath, editWindow) { + $.get( downloadPath, function( data ) { + editWindow.postMessage(JSON.stringify({ + action: "load", + xml: data + }), "*"); + }); + }; + OCA.Drawio.LoadEditorHandler = function(eventHandler, path, editWindow) { // Handle the load event at the start of the page load var loadMsg = OC.Notification.show(t(OCA.Drawio.AppName, "Loading diagram...")); diff --git a/js/public.js b/js/public.js new file mode 100644 index 0000000..59479ef --- /dev/null +++ b/js/public.js @@ -0,0 +1,41 @@ +var eventHandler = function (evt) { + // Only on public page + if ($('#isPublic').val()) { + if (evt.data.length > 0) { + var payload = JSON.parse(evt.data); + if (payload.event === "init") { + OCA.Drawio.LoadPublicFileHandler( + eventHandler, + $('#downloadURL').val(), + $('#drawioEditor')[0].contentWindow); + } + } + } +}; +window.addEventListener("message", eventHandler); + +$(document).ready(function(){ + var mimes = [ + 'application/octet-stream', + 'application/xml' + ]; + if ($('#isPublic').val() && mimes.indexOf($('#mimetype').val()) !== -1 && $('#filename').val().split('.').pop() === 'drawio') { + var src = 'https://www.draw.io?embed=1&chrome=0&spin=1&stealth=1&proto=json'; + var html ='