Skip to content

Commit

Permalink
drawio: bump 2.0, show preview when readonly and in share page, remov…
Browse files Browse the repository at this point in the history
…e unnecessary share menu item on right click
  • Loading branch information
zhtengw committed Apr 27, 2020
1 parent c02f7c0 commit 50e4638
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 363 deletions.
50 changes: 28 additions & 22 deletions kodbox-plugins/drawio/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,38 @@ public function index() {

$config = $this->getConfig();

if (!empty($this->in['share'])) {
// Share Diagram
include($this->pluginPath.'/static/share.php');
} else {
// open editor
$serverAddr = $config['serverAddr'];

$theme = $config['theme'];
$lang = substr(I18n::getType(),0,2);
$url_params = '?embed=1&ui='.$theme.'&lang='.$lang.'&spin=1&proto=json';

$content = file_get_contents($fileUrl);
// 解析出文件里的diagram内容
$content = file_get_contents($fileUrl);
$xml = simplexml_load_string($content);
$diagram = json_decode(json_encode($xml),true)['diagram'];
if (empty($diagram)) {
$newfile = true;
}

if (empty($serverAddr)) {
if (file_exists($this->pluginPath.'static/draw/index.html')) {
$serverAddr = $this->pluginHost.'static/draw';
} else {
$serverAddr = 'https://www.draw.io';
}
// 获取服务器地址
$serverAddr = $config['serverAddr'];
if (empty($serverAddr)) {
if (file_exists($this->pluginPath.'static/draw/index.html')) {
$serverAddr = $this->pluginHost.'static/draw';
} else {
$serverAddr = 'https://www.draw.io';
}
$serverAddr .= $url_params;
}

if (!empty($this->in['newfile']) || empty($content) ) {
$newfile = true;
}
$theme = $config['theme'];
$lang = substr(I18n::getType(),0,2);
//可写权限检测
if (Action("explorer.auth")->fileCanWrite($path)) {
// 有写入权限的登录用户,显示嵌入编辑界面
$url_params = '?embed=1&ui='.$theme.'&lang='.$lang.'&spin=1&proto=json'.'&editable=false';
$serverAddr .= $url_params;
include($this->pluginPath.'/static/template.php');
} else {
// 无写入权限或者未登录用户,显示分享预览界面
$url_params = '?ui='.$theme.'&lang='.$lang.'&lightbox=1&highlight=0000ff&layers=1&nav=1#R';
$serverAddr .= $url_params;
header('Location:'.$serverAddr.($diagram));
}

}
}
2 changes: 1 addition & 1 deletion kodbox-plugins/drawio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id":"drawio",
"name":"{{LNG['drawio.meta.name']}}",
"title":"{{LNG['drawio.meta.title']}}",
"version":"1.1.1",
"version":"2.0",
"category":"file",
"source":{
"icon":"{{pluginHost}}static/images/icon.png",
Expand Down
74 changes: 0 additions & 74 deletions kodbox-plugins/drawio/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,80 +17,6 @@ kodReady.push(function() {
return val === v;
})
}
var shareDrawMenu = {
'shareDraw': {
name: "{{LNG['drawio.share.title']}}",
className: "shareDraw",
icon: "{{pluginHost}}static/images/icon.png",
callback: function(action, option) {
var param = kodApp.pathAction.makeParamItem();
var path = param.path;
var name = param.name;
var ext = pathTools.pathExt(name);
var args = new Array(path, ext, name);
core.openFile('{{pluginApi}}', "dialog", args, 'share=1');
}
}
}
// 右键菜单: 分享图表
Events.bind(
'[email protected]', function(menu, menuType) {
var name = kodApp.pathAction.makeParamItem().name;
var ext = pathTools.pathExt(name);
var allowExt = inArray("{{config.fileExt}}".split(","), ext);

if (menu.extendShareDraw) {
if (!allowExt) {
$.contextMenu.menuItemHide(menu, 'shareDraw');
} else {
$.contextMenu.menuItemShow(menu, 'shareDraw');
}
return;
} else {
if (!allowExt) return;
}
$.contextMenu.menuAdd(shareDrawMenu,menu, false, '.share');
menu.extendShareDraw = true;
});
Events.bind(
'[email protected]', function(menu, menuType) {
var name = kodApp.pathAction.makeParamItem().name;
var ext = pathTools.pathExt(name);
var allowExt = inArray("{{config.fileExt}}".split(","), ext);

if (menu.extendShareDraw) {
if (!allowExt) {
$.contextMenu.menuItemHide(menu, 'shareDraw');
} else {
$.contextMenu.menuItemShow(menu, 'shareDraw');
}
return;
} else {
if (!allowExt) return;
}
$.contextMenu.menuAdd(shareDrawMenu,menu, '.open-with', false);
menu.extendShareDraw = true;
});
Events.bind(
'[email protected]', function(menu, menuType) {
var name = kodApp.pathAction.makeParamItem().name;
var ext = pathTools.pathExt(name);
var allowExt = inArray("{{config.fileExt}}".split(","), ext);

if (menu.extendShareDraw) {
if (!allowExt) {
$.contextMenu.menuItemHide(menu, 'shareDraw');
} else {
$.contextMenu.menuItemShow(menu, 'shareDraw');
}
return;
} else {
if (!allowExt) return;
}
$.contextMenu.menuAdd(shareDrawMenu,menu, false, '.share');
menu.extendShareDraw = true;
});

// 菜单:新建图表
var newDrawMenu = {
'newDraw': {
Expand Down
103 changes: 0 additions & 103 deletions kodbox-plugins/drawio/static/share.php

This file was deleted.

52 changes: 30 additions & 22 deletions kodexplorer-plugins/drawio/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,42 @@ public function index() {
$newfile = false;

$config = $this->getConfig();

if (!empty($this->in['share'])) {
// Share Diagram
include($this->pluginPath.'/static/share.php');
} else {
// open editor
$serverAddr = $config['serverAddr'];

$theme = $config['theme'];
$lang = substr(I18n::getType(),0,2);
$url_params = '?embed=1&ui='.$theme.'&lang='.$lang.'&spin=1&proto=json';

$content = file_get_contents($fileUrl);
// 解析出文件里的diagram内容
$content = file_get_contents($fileUrl);
$xml = simplexml_load_string($content);
$diagram = json_decode(json_encode($xml),true)['diagram'];
if (empty($diagram)) {
$newfile = true;
}

if (empty($serverAddr)) {
if (file_exists($this->pluginPath.'static/draw/index.html')) {
$serverAddr = $this->pluginHost.'static/draw';
} else {
$serverAddr = 'https://www.draw.io';
}
// 获取服务器地址
$serverAddr = $config['serverAddr'];
if (empty($serverAddr)) {
if (file_exists($this->pluginPath.'static/draw/index.html')) {
$serverAddr = $this->pluginHost.'static/draw';
} else {
$serverAddr = 'https://www.draw.io';
}
$serverAddr .= $url_params;
}

if (!empty($this->in['newfile']) || empty($content)) {
$newfile = true;
}
$theme = $config['theme'];
$lang = substr(I18n::getType(),0,2);

//可写权限检测
if (check_file_writable_user($path)) {
// 有写入权限的登录用户,显示嵌入编辑界面
$url_params = '?embed=1&ui='.$theme.'&lang='.$lang.'&spin=1&proto=json'.'&editable=false';
$serverAddr .= $url_params;
include($this->pluginPath.'/static/template.php');
} else {
// 无写入权限或者未登录用户,显示分享预览界面
$url_params = '?ui='.$theme.'&lang='.$lang.'&lightbox=1&highlight=0000ff&layers=1&nav=1#R';
$serverAddr .= $url_params;
header('Location:'.$serverAddr.($diagram));
}

}


}
2 changes: 1 addition & 1 deletion kodexplorer-plugins/drawio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id":"drawio",
"name":"{{LNG.drawio.meta.name}}",
"title":"{{LNG.drawio.meta.title}}",
"version":"1.1",
"version":"2.0",
"category":"file",
"source":{
"icon":"{{pluginHost}}static/images/icon.png",
Expand Down
37 changes: 0 additions & 37 deletions kodexplorer-plugins/drawio/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,6 @@ kodReady.push(function() {
}
}
});
// 右键菜单:分享图表
$.contextMenu.menuAdd({
'shareDraw': {
name: "{{LNG.drawio.share.title}}",
className: "shareDraw",
icon: "{{pluginHost}}static/images/icon.png",
callback: function(action, option) {
var path;
if (action.path !== undefined) {
path = action.path;
} else {
path = ui.path.makeParam().path;
}
if ( !! path) {
var param = $(".context-menu-active").hasClass("menu-tree-file") ? ui.tree.makeParam() : ui.path.makeParam();
var ext = core.pathExt(param.path);
var url = '{{pluginApi}}&share=1&path=' + core.pathCommon(path);
core.openDialog(url, core.icon(ext), "{{LNG.drawio.share.title}}");
}
}
}
},
'.menu-file', false, '.share');
// 对于非draw.io支持的文件格式,隐藏分享图表菜单
Hook.bind("rightMenu.show.menu-file,rightMenu.show.menu-tree-file",
function($menuAt, $theMenu) {
var param = $(".context-menu-active").hasClass("menu-tree-file") ? ui.tree.makeParam() : ui.path.makeParam();
var ext = core.pathExt(param.path);
var allowExt = "{{config.fileExt}}";
var hideClass = "hidden";

if (inArray(allowExt.split(","), ext)) {
$theMenu.find(".shareDraw").removeClass(hideClass);
} else {
$theMenu.find(".shareDraw").addClass(hideClass);
}
});

// 菜单:新建图表
var newDrawMenu = {
Expand Down
Loading

0 comments on commit 50e4638

Please sign in to comment.