mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-21 23:43:17 +01:00
W.I.P. collab editor:
- Implement genesis url and saving mechanism
This commit is contained in:
parent
845f9aee36
commit
b44961ba4c
@ -40,15 +40,11 @@ class filemanager_collab extends filemanager_collab_bo {
|
||||
*/
|
||||
function join_session ($es_id)
|
||||
{
|
||||
$paths = explode('/webdav.php', $es_id);
|
||||
if (Api\Vfs::check_access($paths[1], Api\Vfs::READABLE))
|
||||
{
|
||||
$response = $this->initSession($es_id);
|
||||
$response['success'] = true;
|
||||
}
|
||||
$response = $this->initSession($es_id);
|
||||
$response += array (
|
||||
'id' => $GLOBALS['egw_info']['user']['account_id'],
|
||||
'full_name' => $GLOBALS['egw_info']['user']['account_fullname']
|
||||
'full_name' => $GLOBALS['egw_info']['user']['account_fullname'],
|
||||
'success' => true
|
||||
);
|
||||
|
||||
return $response;
|
||||
@ -84,7 +80,6 @@ class filemanager_collab extends filemanager_collab_bo {
|
||||
$response = array();
|
||||
if (is_array($params))
|
||||
{
|
||||
$paths = explode('/webdav.php', $params['args']['es_id']);
|
||||
switch ($params['command'])
|
||||
{
|
||||
case 'join_session':
|
||||
@ -103,7 +98,7 @@ class filemanager_collab extends filemanager_collab_bo {
|
||||
{
|
||||
$client_ops = $params['args']['client_ops']? $params['args']['client_ops']: [];
|
||||
$current_seq_head = $this->OP_getHeadSeq($es_id);
|
||||
if ($seq_head == $current_seq_head && $this->is_collabAllowed($es_id)) {
|
||||
if ($seq_head == $current_seq_head) {
|
||||
|
||||
if (count($client_ops)>0)
|
||||
{
|
||||
@ -181,11 +176,46 @@ class filemanager_collab extends filemanager_collab_bo {
|
||||
}
|
||||
}
|
||||
|
||||
function is_collabAllowed ($es_id)
|
||||
|
||||
function is_collabAllowed ($file_path, $_right)
|
||||
{
|
||||
$paths = explode('/webdav.php', $es_id);
|
||||
$allowed = Api\Vfs::check_access($paths[1], Api\Vfs::WRITABLE) &&
|
||||
!preg_match('/\/api\/js\/webodf\/template.odf$/', $es_id);
|
||||
$paths = explode('/webdav.php', $file_path);
|
||||
$right = $_right ? $_right : Api\Vfs::WRITABLE;
|
||||
$allowed = Api\Vfs::check_access($paths[1], $right) &&
|
||||
!preg_match('/\/api\/js\/webodf\/template.odf$/', $file_path);
|
||||
return $allowed;
|
||||
}
|
||||
|
||||
function ajax_getGenesisUrl ($file_path)
|
||||
{
|
||||
$result = array();
|
||||
$es_id = md5($file_path);
|
||||
|
||||
$paths = explode('/webdav.php', $file_path);
|
||||
$dir_parts = explode('/',$paths[1]);
|
||||
array_pop($dir_parts);
|
||||
$dir = join('/', $dir_parts);
|
||||
$response = Api\Json\Response::get();
|
||||
$session = $this->SESSION_Get($es_id);
|
||||
|
||||
if ($session && $session['genesis_url'] !== '')
|
||||
{
|
||||
$result = array (
|
||||
'es_id' => $session['es_id'],
|
||||
'genesis_url' => $session['genesis_url']
|
||||
);
|
||||
}
|
||||
else if ($this->is_collabAllowed($file_path))
|
||||
{
|
||||
$genesis_file = $dir.'/.'.$es_id.'.webodf.odt';
|
||||
$genesis_url = $paths[0].'/webdav.php'.$genesis_file;
|
||||
$result = array (
|
||||
'es_id' => $es_id,
|
||||
'genesis_url' => $genesis_url
|
||||
);
|
||||
Api\Vfs::copy($paths[1], $genesis_file);
|
||||
$this->SESSION_add2Db($es_id, $genesis_url);
|
||||
}
|
||||
$response->data($result);
|
||||
}
|
||||
}
|
@ -94,18 +94,17 @@ class filemanager_collab_bo
|
||||
* Add session data with provided session id into DB
|
||||
*
|
||||
* @param string $es_id session id
|
||||
*
|
||||
* @param string $genesis_url generated url out of genesis temp file
|
||||
* @return array returns an array contains of session data
|
||||
*/
|
||||
protected function SESSION_add2Db ($es_id)
|
||||
protected function SESSION_add2Db ($es_id, $genesis_url='')
|
||||
{
|
||||
if ($es_id)
|
||||
{
|
||||
$data = array (
|
||||
'collab_es_id' => $es_id,
|
||||
'collab_genesis_url' => '',
|
||||
'collab_genesis_hash' => '',
|
||||
'collab_last_saved' => self::getTimeStamp(),
|
||||
'collab_genesis_url' => $genesis_url,
|
||||
'collab_last_save' => self::getTimeStamp(),
|
||||
'account_id' => $GLOBALS['egw_info']['user']['account_id']
|
||||
);
|
||||
|
||||
@ -166,6 +165,28 @@ class filemanager_collab_bo
|
||||
return !$query? false: true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get session information based on session id
|
||||
*
|
||||
* @param string $es_id session id
|
||||
*
|
||||
* @return array|boolean return session info or false if nothing found
|
||||
* @throws Exception
|
||||
*/
|
||||
public function SESSION_Get($es_id)
|
||||
{
|
||||
if (!$es_id) throw new Exception (self::EXCEPTION_MESSAGE_NO_SESSION);
|
||||
$query = $this->db->select(
|
||||
self::SESSION_TABLE,
|
||||
'*',
|
||||
array('collab_es_id' => $es_id),
|
||||
__LINE__,
|
||||
__FILE__
|
||||
);
|
||||
$session = $query->fetchrow();
|
||||
return is_array($session)? self::db2id($session): false;
|
||||
}
|
||||
|
||||
/**
|
||||
* OP addMember function is backend equivalent to addMember from frontend
|
||||
*
|
||||
|
@ -1492,6 +1492,15 @@ class filemanager_ui
|
||||
Api\Framework::includeCSS('/api/js/webodf/collab/wodotexteditor.css');
|
||||
Api\Framework::includeJS('/filemanager/js/collab.js',null, 'filemanager');
|
||||
|
||||
if (!$content)
|
||||
{
|
||||
if ($file_path)
|
||||
{
|
||||
$content['es_id'] = md5 ($file_path);
|
||||
$content['file_path'] = $file_path;
|
||||
}
|
||||
}
|
||||
|
||||
$actions = self::getActions_edit();
|
||||
if (!Api\Vfs::check_access($paths[1], Api\Vfs::WRITABLE))
|
||||
{
|
||||
@ -1499,7 +1508,7 @@ class filemanager_ui
|
||||
unset ($actions['delete']);
|
||||
}
|
||||
$tmpl->setElementAttribute('tools', 'actions', $actions);
|
||||
$preserve = $content = array('file_path' => $file_path);
|
||||
$preserve = $content;
|
||||
$tmpl->exec('filemanager.filemanager_ui.editor',$content,array(),array(),$preserve,2);
|
||||
}
|
||||
|
||||
|
@ -118,42 +118,43 @@ app.classes.filemanager = app.classes.filemanager.extend({
|
||||
*/
|
||||
_init_odf_collab_editor: function ()
|
||||
{
|
||||
var self = this;
|
||||
|
||||
var widgetFilePath = this.et2.getWidgetById('file_path'),
|
||||
file_path = widgetFilePath.value;
|
||||
|
||||
|
||||
var serverOptions = {
|
||||
"serverParams": {
|
||||
url:egw.link('/index.php?', {
|
||||
menuaction: 'filemanager.filemanager_collab.poll'
|
||||
}),
|
||||
genesisUrl:egw.webserverUrl+file_path
|
||||
},
|
||||
"sessionId": this.editor_getSessionId(),
|
||||
editorOptions: {
|
||||
allFeaturesEnabled: true,
|
||||
userData: {
|
||||
fullName: egw.user('account_fullName'),
|
||||
color: 'blue'
|
||||
egw.json('filemanager.filemanager_collab.ajax_getGenesisUrl',[this.editor_getFilePath()], function (_data){
|
||||
var serverOptions = {
|
||||
serverParams: {
|
||||
url:egw.link('/index.php?', {
|
||||
menuaction: 'filemanager.filemanager_collab.poll'
|
||||
}),
|
||||
genesisUrl:_data.genesis_url
|
||||
},
|
||||
sessionId: _data.es_id,
|
||||
editorOptions: {
|
||||
allFeaturesEnabled: true,
|
||||
userData: {
|
||||
fullName: egw.user('account_fullName'),
|
||||
color: 'blue'
|
||||
}
|
||||
}
|
||||
};
|
||||
var editor = self.et2.getWidgetById('odfEditor');
|
||||
if (editor)
|
||||
{
|
||||
self.create_collab_editor(serverOptions);
|
||||
}
|
||||
};
|
||||
var editor = this.et2.getWidgetById('odfEditor');
|
||||
if (editor)
|
||||
{
|
||||
this.create_collab_editor(serverOptions);
|
||||
}
|
||||
}).sendRequest();
|
||||
},
|
||||
|
||||
/**
|
||||
* Function to leave the current editing session
|
||||
* and as result it will call client-side and server leave session.
|
||||
*
|
||||
* @param {function} _successCallback function to gets called after leave session is successful
|
||||
*/
|
||||
editor_leaveSession: function ()
|
||||
editor_leaveSession: function (_successCallback)
|
||||
{
|
||||
this.editor.leaveSession(function(){});
|
||||
this.collab_server.server.leaveSession(this.collab_server.es_id, this.collab_server.memberid);
|
||||
this.collab_server.server.leaveSession(this.collab_server.es_id, this.collab_server.memberid, _successCallback);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -232,7 +233,7 @@ app.classes.filemanager = app.classes.filemanager.extend({
|
||||
success: function(data) {
|
||||
egw(window).message(egw.lang('Document %1 successfully has been saved.', filename[1]));
|
||||
self.editor.setDocumentModified(false);
|
||||
egw.json('filemanager.filemanager_collab.ajax_actions',[self.editor_getSessionId(), 'save']).sendRequest();
|
||||
egw.json('filemanager.filemanager_collab.ajax_actions',[self.editor_getFilePath(), 'save']).sendRequest();
|
||||
},
|
||||
error: function () {},
|
||||
data: blob,
|
||||
@ -264,9 +265,10 @@ app.classes.filemanager = app.classes.filemanager.extend({
|
||||
// Add odt extension if not exist
|
||||
if (!file_path.match(/\.odt$/,'ig')) file_path += '.odt';
|
||||
widgetFilePath.set_value(file_path);
|
||||
self.editor_leaveSession();
|
||||
self.editor.getDocumentAsByteArray(saveByteArrayLocally);
|
||||
self._init_odf_collab_editor();
|
||||
self.editor_leaveSession(function(){
|
||||
self._init_odf_collab_editor();
|
||||
});
|
||||
egw.refresh('','filemanager');
|
||||
}
|
||||
});
|
||||
@ -351,16 +353,16 @@ app.classes.filemanager = app.classes.filemanager.extend({
|
||||
},
|
||||
|
||||
/**
|
||||
* Function to generate session id
|
||||
* Function to get full file path
|
||||
*
|
||||
* @returns {String} retruns session id
|
||||
* @returns {String} retruns file path
|
||||
*/
|
||||
editor_getSessionId: function ()
|
||||
editor_getFilePath: function ()
|
||||
{
|
||||
var widgetFilePath = this.et2.getWidgetById('file_path'),
|
||||
file_path = widgetFilePath.value,
|
||||
es_id = egw.webserverUrl+file_path;
|
||||
return es_id;
|
||||
path = egw.webserverUrl+file_path;
|
||||
return path;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -45,8 +45,6 @@ $phpgw_baseline = array(
|
||||
'fd' => array(
|
||||
'collab_es_id' => array('type' => 'varchar','precision' => '64','nullable' => False, 'comment' => 'Editing session id'),
|
||||
'collab_genesis_url' => array('type' => 'varchar','precision' => '512', 'comment' => 'Relative to owner documents storage /template.odt'),
|
||||
'collab_genesis_hash' => array('type' => 'varchar','precision' => '128','nullable' => False, 'comment' => 'To be sure the genesis did not change'),
|
||||
'collab_file_id' => array('type' => 'varchar','precision' => '512', 'comment' => 'Relative to storage e.g. /template.odt'),
|
||||
'account_id' => array('type' => 'int','meta' => 'user','precision' => '4','nullable' => False, 'comment' => 'user who created the session'),
|
||||
'collab_last_save' => array('type' => 'int','meta' => 'timestamp','precision' => '8','comment' => 'timestamp of the last save')
|
||||
),
|
||||
|
@ -50,8 +50,6 @@ function filemanager_upgrade16_1()
|
||||
'fd' => array(
|
||||
'collab_es_id' => array('type' => 'varchar','precision' => '64','nullable' => False, 'comment' => 'Editing session id'),
|
||||
'collab_genesis_url' => array('type' => 'varchar','precision' => '512', 'comment' => 'Relative to owner documents storage /template.odt'),
|
||||
'collab_genesis_hash' => array('type' => 'varchar','precision' => '128','nullable' => False, 'comment' => 'To be sure the genesis did not change'),
|
||||
'collab_file_id' => array('type' => 'varchar','precision' => '512', 'comment' => 'Relative to storage e.g. /template.odt'),
|
||||
'account_id' => array('type' => 'int','meta' => 'user','precision' => '4','nullable' => False, 'comment' => 'user who created the session'),
|
||||
'collab_last_save' => array('type' => 'int','meta' => 'timestamp','precision' => '8','comment' => 'timestamp of the last save')
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user