Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

share api expanded by tags #26583

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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