Skip to content

Commit

Permalink
share api expanded by tags (owncloud#26583)
Browse files Browse the repository at this point in the history
* share api expanded by tags

* Modified files_sharing JS Unit tests

* modified tests. renamed request parameter. refactoring

* Update Share20OCS.php

Added missing function description

* Update Helper.php

Added missing function description

* Update Helper.php

implicit boolean conversion to !empty()

* Update Share20OCSTest.php
  • Loading branch information
mjobst-necls authored and elie195 committed Nov 13, 2016
1 parent aa4ab0a commit 5914bda
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 126 deletions.
1 change: 0 additions & 1 deletion apps/files/ajax/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
$files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
}

$files = \OCA\Files\Helper::populateTags($files);
$data['directory'] = $dir;
$data['files'] = \OCA\Files\Helper::formatFileInfos($files);
$data['permissions'] = $permissions;
Expand Down
7 changes: 5 additions & 2 deletions apps/files/js/tagsplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@

allowedLists: [
'files',
'favorites'
'favorites',
'systemtags',
'shares.self',
'shares.others',
'shares.link'
],

_extendFileActions: function(fileActions) {
Expand Down Expand Up @@ -238,4 +242,3 @@
})(OCA);

OC.Plugins.register('OCA.Files.FileList', OCA.Files.TagsPlugin);

27 changes: 24 additions & 3 deletions apps/files/lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,40 @@ public static function getFiles($dir, $sortAttribute = 'name', $sortDescending =
* Populate the result set with file tags
*
* @param array $fileList
* @param string $fileIdentifier identifier attribute name for values in $fileList
* @return array file list populated with tags
*/
public static function populateTags(array $fileList) {
public static function populateTags(array $fileList, $fileIdentifier = 'fileid') {
$filesById = [];
foreach ($fileList as $fileData) {
$filesById[$fileData['fileid']] = $fileData;
$filesById[$fileData[$fileIdentifier]] = $fileData;
}
$tagger = \OC::$server->getTagManager()->load('files');
$tags = $tagger->getTagsForObjects(array_keys($filesById));
if ($tags) {

if (!is_array($tags)) {
throw new \UnexpectedValueException('$tags must be an array');
}

if (!empty($tags)) {
foreach ($tags as $fileId => $fileTags) {
$filesById[$fileId]['tags'] = $fileTags;
}

foreach ($filesById as $key => $fileWithTags) {
foreach($fileList as $key2 => $file){
if( $file[$fileIdentifier] == $key){
$fileList[$key2] = $fileWithTags;
}
}
}

foreach ($fileList as $key => $file) {
if (!array_key_exists('tags', $file)) {
$fileList[$key]['tags'] = [];
}
}

}
return $fileList;
}
Expand Down
15 changes: 9 additions & 6 deletions apps/files_sharing/js/sharedfilelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
if (options && options.linksOnly) {
this._linksOnly = true;
}
OC.Plugins.attach('OCA.Sharing.FileList', this);
},

_renderRow: function() {
Expand All @@ -83,7 +82,7 @@
// add row with expiration date for link only shares - influenced by _createRow of filelist
if (this._linksOnly) {
var expirationTimestamp = 0;
if(fileData.shares[0].expiration !== null) {
if(fileData.shares && fileData.shares[0].expiration !== null) {
expirationTimestamp = moment(fileData.shares[0].expiration).valueOf();
}
$tr.attr('data-expiration', expirationTimestamp);
Expand Down Expand Up @@ -169,7 +168,8 @@
/* jshint camelcase: false */
data: {
format: 'json',
shared_with_me: !!this._sharedWithUser
shared_with_me: !!this._sharedWithUser,
include_tags: true
},
type: 'GET',
beforeSend: function(xhr) {
Expand All @@ -183,7 +183,8 @@
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares',
/* jshint camelcase: false */
data: {
format: 'json'
format: 'json',
include_tags: true
},
type: 'GET',
beforeSend: function(xhr) {
Expand Down Expand Up @@ -238,7 +239,8 @@
type: share.type,
id: share.file_id,
path: OC.dirname(share.mountpoint),
permissions: share.permissions
permissions: share.permissions,
tags: share.tags || []
};

file.shares = [{
Expand Down Expand Up @@ -276,7 +278,8 @@
var file = {
id: share.file_source,
icon: OC.MimeType.getIconUrl(share.mimetype),
mimetype: share.mimetype
mimetype: share.mimetype,
tags: share.tags || []
};
if (share.item_type === 'folder') {
file.type = 'dir';
Expand Down
Loading

0 comments on commit 5914bda

Please sign in to comment.