Merge pull request #58 from pranavk/master

Don't load all documents when only one is clicked on from 'Files'
pull/1/head
Andras Timar 8 years ago committed by GitHub
commit 7dd4a8c58d

@ -30,6 +30,7 @@ $application->registerRoutes($this, [
['name' => 'document#create', 'url' => 'ajax/documents/create', 'verb' => 'POST'],
['name' => 'document#serve', 'url' => 'ajax/genesis/{esId}', 'verb' => 'GET'],
['name' => 'document#rename', 'url' => 'ajax/documents/rename/{fileId}', 'verb' => 'POST'],
['name' => 'document#get', 'url' => 'ajax/documents/get/{fileId}', 'verb' => 'GET'],
['name' => 'document#listAll', 'url' => 'ajax/documents/list', 'verb' => 'GET'],
['name' => 'document#download', 'url' => 'ajax/download.php', 'verb' => 'GET'],
//documents - for WOPI access

@ -140,6 +140,70 @@ class DocumentController extends Controller {
return $discovery;
}
/** Prepare document(s) structure
*/
private function prepareDocuments($rawDocuments){
$discovery_parsed = null;
try {
$discovery = $this->getDiscovery();
$loadEntities = libxml_disable_entity_loader(true);
$discovery_parsed = simplexml_load_string($discovery);
libxml_disable_entity_loader($loadEntities);
if ($discovery_parsed === false) {
$this->cache->remove('discovery.xml');
$wopiRemote = $this->settings->getAppValue('richdocuments', 'wopi_url');
return array(
'status' => 'error',
'message' => $this->l10n->t('Collabora Online: discovery.xml from "%s" is not a well-formed XML string.', array($wopiRemote)),
'hint' => $this->l10n->t('Please contact the "%s" administrator.', array($wopiRemote))
);
}
}
catch (ResponseException $e) {
return array(
'status' => 'error',
'message' => $e->getMessage(),
'hint' => $e->getHint()
);
}
$fileIds = array();
$documents = array();
$lolang = strtolower(str_replace('_', '-', $this->settings->getUserValue($this->uid, 'core', 'lang', 'en')));
foreach ($rawDocuments as $key=>$document) {
if (is_object($document)){
$documents[] = $document->getData();
} else {
$documents[$key] = $document;
}
$documents[$key]['icon'] = preg_replace('/\.png$/', '.svg', \OCP\Template::mimetype_icon($document['mimetype']));
$documents[$key]['hasPreview'] = \OC::$server->getPreviewManager()->isMimeSupported($document['mimetype']);
$documents[$key]['urlsrc'] = $this->getWopiSrcUrl($discovery_parsed, $document['mimetype'], 'edit');
$documents[$key]['lolang'] = $lolang;
$fileIds[] = $document['fileid'];
}
usort($documents, function($a, $b){
return @$b['mtime']-@$a['mtime'];
});
$session = new Db\Session();
$sessions = $session->getCollectionBy('file_id', $fileIds);
$members = array();
$member = new Db\Member();
foreach ($sessions as $session) {
$members[$session['es_id']] = $member->getActiveCollection($session['es_id']);
}
return array(
'status' => 'success', 'documents' => $documents,'sessions' => $sessions,'members' => $members
);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
@ -428,70 +492,22 @@ class DocumentController extends Controller {
/**
* @NoAdminRequired
* lists the documents the user has access to (including shared files, once the code in core has been fixed)
* also adds session and member info for these files
* Get file information about single document with fileId
*/
public function listAll(){
$found = Storage::getDocuments();
public function get($fileId){
$documents = array();
$documents[0] = Storage::getDocumentById($fileId);
$discovery_parsed = null;
try {
$discovery = $this->getDiscovery();
$loadEntities = libxml_disable_entity_loader(true);
$discovery_parsed = simplexml_load_string($discovery);
libxml_disable_entity_loader($loadEntities);
if ($discovery_parsed === false) {
$this->cache->remove('discovery.xml');
$wopiRemote = $this->settings->getAppValue('richdocuments', 'wopi_url');
return array(
'status' => 'error',
'message' => $this->l10n->t('Collabora Online: discovery.xml from "%s" is not a well-formed XML string.', array($wopiRemote)),
'hint' => $this->l10n->t('Please contact the "%s" administrator.', array($wopiRemote))
);
}
}
catch (ResponseException $e) {
return array(
'status' => 'error',
'message' => $e->getMessage(),
'hint' => $e->getHint()
);
}
$fileIds = array();
$documents = array();
$lolang = strtolower(str_replace('_', '-', $this->settings->getUserValue($this->uid, 'core', 'lang', 'en')));
foreach ($found as $key=>$document) {
if (is_object($document)){
$documents[] = $document->getData();
} else {
$documents[$key] = $document;
}
$documents[$key]['icon'] = preg_replace('/\.png$/', '.svg', \OCP\Template::mimetype_icon($document['mimetype']));
$documents[$key]['hasPreview'] = \OC::$server->getPreviewManager()->isMimeSupported($document['mimetype']);
$documents[$key]['urlsrc'] = $this->getWopiSrcUrl($discovery_parsed, $document['mimetype'], 'edit');
$documents[$key]['lolang'] = $lolang;
$fileIds[] = $document['fileid'];
}
usort($documents, function($a, $b){
return @$b['mtime']-@$a['mtime'];
});
$session = new Db\Session();
$sessions = $session->getCollectionBy('file_id', $fileIds);
return $this->prepareDocuments($documents);
}
$members = array();
$member = new Db\Member();
foreach ($sessions as $session) {
$members[$session['es_id']] = $member->getActiveCollection($session['es_id']);
}
return array(
'status' => 'success', 'documents' => $documents,'sessions' => $sessions,'members' => $members
);
/**
* @NoAdminRequired
* lists the documents the user has access to (including shared files, once the code in core has been fixed)
* also adds session and member info for these files
*/
public function listAll(){
return $this->prepareDocuments(Storage::getDocuments());
}
}

@ -12,9 +12,9 @@ $.widget('oc.documentGrid', {
},
render : function(){
render : function(fileId){
var that = this;
jQuery.when(this._load())
jQuery.when(this._load(fileId))
.then(function(){
that._render();
});
@ -78,10 +78,17 @@ $.widget('oc.documentGrid', {
}
},
_load : function (){
_load : function (fileId){
var that = this;
var def = new $.Deferred();
$.getJSON(OC.generateUrl('apps/richdocuments/ajax/documents/list'))
var url = 'apps/richdocuments/ajax/documents/list';
var dataObj = {};
if (fileId){
url = 'apps/richdocuments/ajax/documents/get/{fileId}';
dataObj = { fileId: fileId };
}
$.getJSON(OC.generateUrl(url, dataObj))
.done(function (result) {
if (!result || result.status === 'error') {
documentsMain.loadError = true;
@ -349,7 +356,7 @@ var documentsMain = {
}
}
documentsMain.show();
documentsMain.show(fileId);
if (fileId) {
documentsMain.overlay.documentOverlay('show');
@ -671,12 +678,12 @@ var documentsMain = {
}
},
show: function(){
show: function(fileId){
if (documentsMain.isGuest){
return;
}
documentsMain.UI.showProgress(t('richdocuments', 'Loading documents...'));
documentsMain.docs.documentGrid('render');
documentsMain.docs.documentGrid('render', fileId);
documentsMain.UI.hideProgress();
}
};

@ -72,6 +72,26 @@ class Storage {
return $list;
}
public static function getDocumentById($fileId){
$root = \OC::$server->getUserFolder();
$ret = array();
// If type of fileId is a string, then it
// doesn't work for shared documents, lets cast to int everytime
$document = $root->getById((int)$fileId)[0];
if ($document === null){
error_log('File with file id, ' . $fileId . ', not found');
return $ret;
}
$ret['mimetype'] = $document->getMimeType();
$ret['path'] = $root->getRelativePath($document->getPath());
$ret['name'] = $document->getName();
$ret['fileid'] = $fileId;
return $ret;
}
public static function resolvePath($fileId){
$list = array_filter(
self::searchDocuments(),

Loading…
Cancel
Save