Group shares by type
This commit is contained in:
parent
6ebc436505
commit
9baf47c2b4
|
@ -21,13 +21,6 @@
|
||||||
FileList.prototype = _.extend({}, OCA.Files.FileList.prototype, {
|
FileList.prototype = _.extend({}, OCA.Files.FileList.prototype, {
|
||||||
appName: 'Shares',
|
appName: 'Shares',
|
||||||
|
|
||||||
SHARE_TYPE_TEXT: [
|
|
||||||
t('files_sharing', 'User'),
|
|
||||||
t('files_sharing', 'Group'),
|
|
||||||
t('files_sharing', 'Unknown'),
|
|
||||||
t('files_sharing', 'Public')
|
|
||||||
],
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the list shows the files shared with the user (true) or
|
* Whether the list shows the files shared with the user (true) or
|
||||||
* the files that the user shared with others (false).
|
* the files that the user shared with others (false).
|
||||||
|
@ -45,30 +38,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Compare two shares
|
|
||||||
* @param share1 first share
|
|
||||||
* @param share2 second share
|
|
||||||
* @return 1 if share2 should come before share1, -1
|
|
||||||
* if share1 should come before share2, 0 if they
|
|
||||||
* are identical.
|
|
||||||
*/
|
|
||||||
_shareCompare: function(share1, share2) {
|
|
||||||
var result = OCA.Files.FileList.Comparators.name(share1, share2);
|
|
||||||
if (result === 0) {
|
|
||||||
return share2.shareType - share1.shareType;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
|
|
||||||
_createRow: function(fileData) {
|
_createRow: function(fileData) {
|
||||||
// TODO: hook earlier and render the whole row here
|
// TODO: hook earlier and render the whole row here
|
||||||
var $tr = OCA.Files.FileList.prototype._createRow.apply(this, arguments);
|
var $tr = OCA.Files.FileList.prototype._createRow.apply(this, arguments);
|
||||||
$tr.find('.filesize').remove();
|
$tr.find('.filesize').remove();
|
||||||
var $sharedWith = $('<td class="sharedWith"></td>').text(fileData.shareWithDisplayName);
|
var $sharedWith = $('<td class="sharedWith"></td>')
|
||||||
var $shareType = $('<td class="shareType"></td>').text(this.SHARE_TYPE_TEXT[fileData.shareType] ||
|
.text(fileData.shareColumnInfo);
|
||||||
t('files_sharing', 'Unkown'));
|
$tr.find('td.date').before($sharedWith);
|
||||||
$tr.find('td.date').before($sharedWith).before($shareType);
|
|
||||||
$tr.find('td.filename input:checkbox').remove();
|
$tr.find('td.filename input:checkbox').remove();
|
||||||
$tr.attr('data-path', fileData.path);
|
$tr.attr('data-path', fileData.path);
|
||||||
return $tr;
|
return $tr;
|
||||||
|
@ -125,22 +101,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
|
||||||
// FIXME
|
|
||||||
/*
|
|
||||||
var $el = $('<thead><tr>' +
|
|
||||||
'<th>' + t('files', 'Name') + '</th>' +
|
|
||||||
'<th>' + t('files', 'Shared with') + '</th>' +
|
|
||||||
'<th>' + t('files', 'Type') + '</th>' +
|
|
||||||
'<th>' + t('files', 'Shared since') + '</th>' +
|
|
||||||
'</tr></thead>' +
|
|
||||||
'<tbody class="fileList"></tbody>' +
|
|
||||||
'<tfoot></tfoot>');
|
|
||||||
this.$el.empty().append($el);
|
|
||||||
this.$fileList = this.$el.find('tbody');
|
|
||||||
*/
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the OCS API share response data to a file info
|
* Converts the OCS API share response data to a file info
|
||||||
* list
|
* list
|
||||||
|
@ -150,39 +110,78 @@
|
||||||
_makeFilesFromShares: function(data) {
|
_makeFilesFromShares: function(data) {
|
||||||
var self = this;
|
var self = this;
|
||||||
// OCS API uses non-camelcased names
|
// OCS API uses non-camelcased names
|
||||||
/* jshint camelcase: false */
|
var files = _.chain(data)
|
||||||
var files = _.map(data, function(share) {
|
// cOnvert share data to file data
|
||||||
var file = {
|
.map(function(share) {
|
||||||
id: share.id,
|
/* jshint camelcase: false */
|
||||||
mtime: share.stime * 1000,
|
var file = {
|
||||||
permissions: share.permissions
|
id: share.file_source,
|
||||||
};
|
mtime: share.stime * 1000,
|
||||||
if (share.item_type === 'folder') {
|
permissions: share.permissions
|
||||||
file.type = 'dir';
|
};
|
||||||
}
|
if (share.item_type === 'folder') {
|
||||||
else {
|
file.type = 'dir';
|
||||||
file.type = 'file';
|
}
|
||||||
// force preview retrieval as we don't have mime types,
|
else {
|
||||||
// the preview endpoint will fall back to the mime type
|
file.type = 'file';
|
||||||
// icon if no preview exists
|
// force preview retrieval as we don't have mime types,
|
||||||
file.isPreviewAvailable = true;
|
// the preview endpoint will fall back to the mime type
|
||||||
file.icon = true;
|
// icon if no preview exists
|
||||||
}
|
file.isPreviewAvailable = true;
|
||||||
file.shareType = share.share_type;
|
file.icon = true;
|
||||||
file.shareWith = share.share_with;
|
}
|
||||||
if (self._sharedWithUser) {
|
file.share = {
|
||||||
file.shareWithDisplayName = share.displayname_owner;
|
id: share.id,
|
||||||
file.name = OC.basename(share.file_target);
|
type: share.share_type,
|
||||||
file.path = OC.dirname(share.file_target);
|
target: share.share_with
|
||||||
}
|
};
|
||||||
else {
|
if (self._sharedWithUser) {
|
||||||
file.shareWithDisplayName = share.share_with_displayname;
|
file.share.ownerDisplayName = share.displayname_owner;
|
||||||
file.name = OC.basename(share.path);
|
file.name = OC.basename(share.file_target);
|
||||||
file.path = OC.dirname(share.path);
|
file.path = OC.dirname(share.file_target);
|
||||||
}
|
}
|
||||||
return file;
|
else {
|
||||||
});
|
file.share.targetDisplayName = share.share_with_displayname;
|
||||||
return files.sort(this._shareCompare);
|
file.name = OC.basename(share.path);
|
||||||
|
file.path = OC.dirname(share.path);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
})
|
||||||
|
// Group all files and have a "shares" array with
|
||||||
|
// the share info for each file.
|
||||||
|
//
|
||||||
|
// This uses a hash memo to cumulate share information
|
||||||
|
// inside the same file object (by file id).
|
||||||
|
.reduce(function(memo, file) {
|
||||||
|
var data = memo[file.id];
|
||||||
|
if (!data) {
|
||||||
|
data = memo[file.id] = file;
|
||||||
|
data.shares = [file.share];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
data.shares.push(file.share);
|
||||||
|
}
|
||||||
|
// format the share column info output string
|
||||||
|
if (!data.shareColumnInfo) {
|
||||||
|
data.shareColumnInfo = '';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
data.shareColumnInfo += ', ';
|
||||||
|
}
|
||||||
|
// TODO. more accurate detection of name based on type
|
||||||
|
// TODO: maybe better formatting, like "link + 3 users" when more than 1 user
|
||||||
|
data.shareColumnInfo += (file.share.ownerDisplayName || file.share.targetDisplayName || 'link');
|
||||||
|
delete file.share;
|
||||||
|
return memo;
|
||||||
|
}, {})
|
||||||
|
// Retrieve only the values of the returned hash
|
||||||
|
.values()
|
||||||
|
// Sort by expected sort comparator
|
||||||
|
.sortBy(this._sortComparator)
|
||||||
|
// Finish the chain by getting the result
|
||||||
|
.value();
|
||||||
|
|
||||||
|
return files;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,6 @@
|
||||||
<th id="headerSharedWith" class="hidden column-mtime">
|
<th id="headerSharedWith" class="hidden column-mtime">
|
||||||
<a id="sharedwith" class="columntitle" data-sort="shareWith"><span><?php p($l->t( 'Shared with' )); ?></span><span class="sort-indicator"></span></a>
|
<a id="sharedwith" class="columntitle" data-sort="shareWith"><span><?php p($l->t( 'Shared with' )); ?></span><span class="sort-indicator"></span></a>
|
||||||
</th>
|
</th>
|
||||||
<th id="headerSharedWith" class="hidden column-mtime">
|
|
||||||
<a id="shareType" class="columntitle" data-sort="shareType"><span><?php p($l->t( 'Type' )); ?></span><span class="sort-indicator"></span></a>
|
|
||||||
</th>
|
|
||||||
<th id="headerDate" class="hidden column-mtime">
|
<th id="headerDate" class="hidden column-mtime">
|
||||||
<a id="modified" class="columntitle" data-sort="mtime"><span><?php p($l->t( 'Shared since' )); ?></span><span class="sort-indicator"></span></a>
|
<a id="modified" class="columntitle" data-sort="mtime"><span><?php p($l->t( 'Shared since' )); ?></span><span class="sort-indicator"></span></a>
|
||||||
</th>
|
</th>
|
||||||
|
|
Loading…
Reference in New Issue