From 06db393f1cbabff7fa7e663e6737482f481ead3f Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Wed, 20 Dec 2017 12:38:08 +0100 Subject: [PATCH] W.I.P. migrating of Collabeditor (webodf): - Migrate database part into Collabeditor setup - Fix create new action - Disable new button if there's no filemanager-editor installed --- collabeditor/js/app.js | 18 +++++++++++++ collabeditor/setup/setup.inc.php | 2 ++ .../setup/tables_current.inc.php | 9 +++---- .../setup/tables_update.inc.php | 23 ++++++---------- collabeditor/src/Bo.php | 6 ++--- collabeditor/src/So.php | 27 +++++++++++-------- collabeditor/src/Ui.php | 12 ++++----- .../inc/class.filemanager_hooks.inc.php | 18 ++----------- filemanager/js/app.js | 27 ++++++++++++++----- filemanager/setup/setup.inc.php | 2 -- 10 files changed, 79 insertions(+), 65 deletions(-) rename {filemanager => collabeditor}/setup/tables_current.inc.php (93%) rename {filemanager => collabeditor}/setup/tables_update.inc.php (88%) diff --git a/collabeditor/js/app.js b/collabeditor/js/app.js index 00e5874cb7..10c9c1e87d 100644 --- a/collabeditor/js/app.js +++ b/collabeditor/js/app.js @@ -159,6 +159,24 @@ app.classes.collabeditor = AppJS.extend({ }).sendRequest(); }, + /** + * Method to create a new document + * @param {object} _action either action or node + * @param {object} _selected either widget or selected row + * + * @return {boolean} returns true + */ + create_new: function (_action, _selected) { + var fe = egw.link_get_registry('filemanager-editor'); + if (fe && fe.edit) + { + egw.open_link(egw.link('/index.php', { + menuaction: fe.edit.menuaction + }), '', fe.popup_edit); + } + return true; + }, + /** * Function to leave the current editing session * and as result it will call client-side and server leave session. diff --git a/collabeditor/setup/setup.inc.php b/collabeditor/setup/setup.inc.php index 2731ed1bcc..795e1624c3 100644 --- a/collabeditor/setup/setup.inc.php +++ b/collabeditor/setup/setup.inc.php @@ -13,6 +13,8 @@ $setup_info['collabeditor']['app_order'] = 1; $setup_info['collabeditor']['enable'] = 2; $setup_info['collabeditor']['autoinstall'] = false; +$setup_info['collabeditor']['tables'] = array('egw_collab_member', 'egw_collab_op', 'egw_collab_session'); + $setup_info['collabeditor']['author'] = 'Hadi Nategh'; $setup_info['collabeditor']['maintainer'] = array( 'name' => 'EGroupware GmbH', diff --git a/filemanager/setup/tables_current.inc.php b/collabeditor/setup/tables_current.inc.php similarity index 93% rename from filemanager/setup/tables_current.inc.php rename to collabeditor/setup/tables_current.inc.php index ed71f6b5d0..59435ed478 100644 --- a/filemanager/setup/tables_current.inc.php +++ b/collabeditor/setup/tables_current.inc.php @@ -1,12 +1,11 @@ - * @package filemanager - * @subpackage setup - * @copyright (c) 2016 by Stylite AG + * @package collabeditor + * @author Hadi Nategh + * @copyright (c) 2016 by Hadi Nategh * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @version $Id$ */ diff --git a/filemanager/setup/tables_update.inc.php b/collabeditor/setup/tables_update.inc.php similarity index 88% rename from filemanager/setup/tables_update.inc.php rename to collabeditor/setup/tables_update.inc.php index 21b1da1857..af5d870c5c 100644 --- a/filemanager/setup/tables_update.inc.php +++ b/collabeditor/setup/tables_update.inc.php @@ -1,18 +1,16 @@ + * @copyright (c) 2016 by Hadi Nategh * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ */ -/** - * Creating colaboration tables - * - * @return string - */ -function filemanager_upgrade16_1() +function collabeditor_upgrade17_1() { $GLOBALS['egw_setup']->oProc->CreateTable('egw_collab_member', array( 'fd' => array( @@ -58,10 +56,5 @@ function filemanager_upgrade16_1() 'uc' => array() )); - return $GLOBALS['setup_info']['filemanager']['currentver'] = '16.2'; -} - -function filemanager_upgrade16_2() -{ - return $GLOBALS['setup_info']['filemanager']['currentver'] = '17.1'; -} + return $GLOBALS['setup_info']['collabeditor']['currentver'] = '17.1'; +} \ No newline at end of file diff --git a/collabeditor/src/Bo.php b/collabeditor/src/Bo.php index 0c0cea88ad..3728988b6f 100644 --- a/collabeditor/src/Bo.php +++ b/collabeditor/src/Bo.php @@ -297,7 +297,7 @@ class Bo extends So { * Check last active member in a session * * @param type $es_id - * @return array|boolean returns an array of active members, false in failure + * @return array|boolean returns an array of active members, false in failure */ function checkLastMember ($es_id) { @@ -322,7 +322,7 @@ class Bo extends So { $paths = explode('/webdav.php', $file_path); $right = $_right ? $_right : Vfs::WRITABLE; $allowed = Vfs::check_access($paths[1], $right) && - !preg_match('/\/api\/js\/webodf\/template.odf$/', $file_path); + !preg_match('/\/collabeditor\/assets\/template.odt$/', $file_path); return $allowed; } @@ -377,7 +377,7 @@ class Bo extends So { { return array ( 'es_id' => self::NEW_FILE_ES_ID, - 'genesis_url' => $GLOBALS['egw_info']['server']['webserver_url'].'/api/js/webodf/template.odt' + 'genesis_url' => $GLOBALS['egw_info']['server']['webserver_url'].'/collabeditor/assets/template.odt' ); } $session = $this->SESSION_Get($es_id); diff --git a/collabeditor/src/So.php b/collabeditor/src/So.php index f1bf79b225..1726b67d31 100644 --- a/collabeditor/src/So.php +++ b/collabeditor/src/So.php @@ -49,6 +49,11 @@ class So */ const EXCEPTION_MESSAGE_NO_OPS = 'ops need to be an array of op data, none array given!'; + /** + * Application name + */ + const APP_NAME = 'collabeditor'; + /** * Database object * @var Api\Db @@ -109,7 +114,7 @@ class So 'account_id' => $GLOBALS['egw_info']['user']['account_id'] ); - $this->db->insert(self::SESSION_TABLE, $data,false,__LINE__, __FILE__,'filemanager'); + $this->db->insert(self::SESSION_TABLE, $data,false,__LINE__, __FILE__,self::APP_NAME); } return $data; } @@ -162,7 +167,7 @@ class So array('collab_es_id' => $es_id), __LINE__, __FILE__, - 'filemanager'); + self::APP_NAME); $where_query = 'collab_es_id ="'.$es_id.'" AND collab_optype != "AddMember" AND'. ' collab_optype != "RemoveMember" AND collab_optype !="AddCursor" AND'. ' collab_optype !="RemoveCursor"'; @@ -172,7 +177,7 @@ class So $where_query, __LINE__, __FILE__, - 'filemanager' + self::APP_NAME ); return !$query? false: true; } @@ -255,14 +260,14 @@ class So array('collab_es_id' => $es_id), __LINE__, __FILE__, - 'filemanager' + self::APP_NAME ); $this->db->delete( self::OP_TABLE, array('collab_es_id' => $es_id), __LINE__, __FILE__, - 'filemanager' + self::APP_NAME ); $this->db->delete( self::SESSION_TABLE, @@ -310,7 +315,7 @@ class So __FILE__, FALSE, 'ORDER BY collab_seq DESC LIMIT 1', - 'filemanager' + self::APP_NAME ); $head_seq = $query->fetchRow(); return is_array($head_seq)? $head_seq['collab_seq']: ''; @@ -337,7 +342,7 @@ class So 'collab_es_id ="'. $es_id.'" AND collab_seq >'.$seq_head, __LINE__, __FILE__, - false, 'ORDER BY collab_seq ASC','filemanager'); + false, 'ORDER BY collab_seq ASC', self::APP_NAME); foreach ($query as $spec) { @@ -380,7 +385,7 @@ class So 'collab_optype' => $op['optype'], 'collab_opspec' => json_encode($op) ); - return $this->db->insert(self::OP_TABLE, $data,false,__LINE__, __FILE__,'filemanager'); + return $this->db->insert(self::OP_TABLE, $data,false,__LINE__, __FILE__, self::APP_NAME); } /** @@ -398,7 +403,7 @@ class So 'collab_color' => $color, 'collab_is_active' => 1 ); - $this->db->insert(self::MEMBER_TABLE, $data,false,__LINE__, __FILE__,'filemanager'); + $this->db->insert(self::MEMBER_TABLE, $data,false,__LINE__, __FILE__, self::APP_NAME); } /** @@ -419,7 +424,7 @@ class So 'collab_es_id ="'.$es_id.'" AND collab_member_id="'.$member_id.'"', __LINE__, __FILE__, - 'filemanager' + self::APP_NAME ); } @@ -440,7 +445,7 @@ class So array('collab_es_id' => $es_id, 'collab_is_active' => 1), __LINE__, __FILE__, - 'filemanager' + self::APP_NAME ); $members = $query->getRows(); return is_array($members)?self::db2id($members):true; diff --git a/collabeditor/src/Ui.php b/collabeditor/src/Ui.php index ca8be16b76..2f0d5165fb 100644 --- a/collabeditor/src/Ui.php +++ b/collabeditor/src/Ui.php @@ -156,7 +156,7 @@ class Ui { 'caption' => 'Save', 'icon' => 'apply', 'group' => ++$group, - 'onExecute' => 'javaScript:app.filemanager.editor_save', + 'onExecute' => 'javaScript:app.collabeditor.editor_save', 'allowOnMultiple' => false, 'toolbarDefault' => true ), @@ -164,7 +164,7 @@ class Ui { 'caption' => 'New', 'icon' => 'add', 'group' => ++$group, - 'onExecute' => 'javaScript:app.filemanager.create_new', + 'onExecute' => 'javaScript:app.collabeditor.create_new', 'allowOnMultiple' => false, 'toolbarDefault' => true ), @@ -172,7 +172,7 @@ class Ui { 'caption' => 'Close', 'icon' => 'close', 'group' => ++$group, - 'onExecute' => 'javaScript:app.filemanager.editor_close', + 'onExecute' => 'javaScript:app.collabeditor.editor_close', 'allowOnMultiple' => false, 'toolbarDefault' => true ), @@ -180,7 +180,7 @@ class Ui { 'caption' => 'Save As', 'icon' => 'save_all', 'group' => ++$group, - 'onExecute' => 'javaScript:app.filemanager.editor_save', + 'onExecute' => 'javaScript:app.collabeditor.editor_save', 'allowOnMultiple' => false, 'toolbarDefault' => true ), @@ -188,7 +188,7 @@ class Ui { 'caption' => 'Delete', 'icon' => 'delete', 'group' => ++$group, - 'onExecute' => 'javaScript:app.filemanager.editor_delete', + 'onExecute' => 'javaScript:app.collabeditor.editor_delete', 'allowOnMultiple' => false, 'toolbarDefault' => false ), @@ -196,7 +196,7 @@ class Ui { 'caption' => 'Discard', 'icon' => 'discard', 'group' => ++$group, - 'onExecute' => 'javaScript:app.filemanager.editor_discard', + 'onExecute' => 'javaScript:app.collabeditor.editor_discard', 'allowOnMultiple' => false, 'toolbarDefault' => false ) diff --git a/filemanager/inc/class.filemanager_hooks.inc.php b/filemanager/inc/class.filemanager_hooks.inc.php index 3c00cd2b94..b99c9d1de1 100644 --- a/filemanager/inc/class.filemanager_hooks.inc.php +++ b/filemanager/inc/class.filemanager_hooks.inc.php @@ -298,28 +298,14 @@ class filemanager_hooks static function getEditorLink() { $implemented = Api\Hooks::implemented('filemanager-editor-link'); - // default is CollabEditor - // TODO: CollabEditor needs to be migrated into an individual app, so its link - $link = array ( - 'edit' => array( - 'menuaction' => 'filemanager.filemanager_ui.editor', - ), - 'edit_popup' => '980x750', - 'mime' => array ( - 'application/vnd.oasis.opendocument.text' => array ( - 'mime_popup' => '' // try to avoid mime_open exception - ), - ) - ); foreach ($implemented as $app) { - - if ( \EGroupware\Api\Vfs\Links\StreamWrapper::check_app_rights($app) && + if (($access = \EGroupware\Api\Vfs\Links\StreamWrapper::check_app_rights($app)) && ($l = Api\Hooks::process('filemanager-editor-link',$app, true)) && $l[$app]) { $link = $l[$app]; } - if ($app == 'collabora') break; // collabora is default + if ($app == 'collabora' && $access) break; // collabora is default } return $link; } diff --git a/filemanager/js/app.js b/filemanager/js/app.js index 09bc4e6fdc..649171e3b0 100644 --- a/filemanager/js/app.js +++ b/filemanager/js/app.js @@ -105,9 +105,17 @@ app.classes.filemanager = AppJS.extend( if (name == 'filemanager.index') { - var new_options = this.et2.getArrayMgr('sel_options').getEntry('new'); + var fe = egw.link_get_registry('filemanager-editor'); var new_widget = this.et2.getWidgetById('new'); - new_widget.set_select_options(new_options); + if (fe && fe.edit) + { + var new_options = this.et2.getArrayMgr('sel_options').getEntry('new'); + new_widget.set_select_options(new_options); + } + else + { + new_widget.set_disabled(true); + } } }, @@ -768,6 +776,7 @@ app.classes.filemanager = AppJS.extend( var mime = this.et2._inst.widgetContainer.getWidgetById('$row'); // try to get mime widget DOM node out of the row DOM var mime_dom = jQuery(_senders[0].iface.getDOMNode()).find("span#filemanager-index_\\$row"); + var fe = egw.link_get_registry('filemanager-editor'); // symlinks dont have mime 'http/unix-directory', but server marks all directories with class 'isDir' if (data.data.mime == 'httpd/unix-directory' || data.data['class'] && data.data['class'].split(/ +/).indexOf('isDir') != -1) @@ -778,9 +787,9 @@ app.classes.filemanager = AppJS.extend( { mime_dom.click(); } - else if (mime && this.isEditable(_action, _senders)) + else if (mime && this.isEditable(_action, _senders) && fe && fe.edit) { - var fe = egw.link_get_registry('filemanager-editor'); + egw.open_link(egw.link('/index.php', { menuaction: fe.edit.menuaction, path: decodeURIComponent(data.data.download_url) @@ -1284,9 +1293,13 @@ app.classes.filemanager = AppJS.extend( * @return {boolean} returns true */ create_new: function (_action, _selected) { - egw.open_link(egw.link('/index.php', { - menuaction: 'filemanager.filemanager_ui.editor' - }), '', egw.link_get_registry('filemanager','view_popup')); + var fe = egw.link_get_registry('filemanager-editor'); + if (fe && fe.edit) + { + egw.open_link(egw.link('/index.php', { + menuaction: fe.edit.menuaction + }), '', fe.popup_edit); + } return true; } }); diff --git a/filemanager/setup/setup.inc.php b/filemanager/setup/setup.inc.php index 813830bed3..7b6fc25c4d 100755 --- a/filemanager/setup/setup.inc.php +++ b/filemanager/setup/setup.inc.php @@ -14,8 +14,6 @@ $setup_info['filemanager']['app_order'] = 6; $setup_info['filemanager']['enable'] = 1; $setup_info['filemanager']['index'] = 'filemanager.filemanager_ui.index&ajax=true'; -$setup_info['filemanager']['tables'] = array('egw_collab_member', 'egw_collab_op', 'egw_collab_session'); - $setup_info['filemanager']['author'] = $setup_info['filemanager']['maintainer'] = array( 'name' => 'Ralf Becker',