Skip to content
Closed
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
42 changes: 42 additions & 0 deletions apps/files_sharing/js/sharedfilelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,42 @@
var permission = parseInt($tr.attr('data-permissions')) | OC.PERMISSION_DELETE;
$tr.attr('data-permissions', permission);
}

// 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) {
expirationTimestamp = moment(fileData.shares[0].expiration).valueOf();
}
$tr.attr('data-expiration', expirationTimestamp);

// date column (1000 milliseconds to seconds, 60 seconds, 60 minutes, 24 hours)
// difference in days multiplied by 5 - brightest shade for expiry dates in more than 32 days (160/5)
var modifiedColor = Math.round((expirationTimestamp - (new Date()).getTime()) / 1000 / 60 / 60 / 24 * 5);
// ensure that the brightest color is still readable
if (modifiedColor >= 160) {
modifiedColor = 160;
}

if (expirationTimestamp > 0) {
formatted = OC.Util.formatDate(expirationTimestamp);
text = OC.Util.relativeModifiedDate(expirationTimestamp);
} else {
formatted = t('files_sharing', 'No expiration date set');
text = t('files_sharing', 'Never');
modifiedColor = 160;
}
td = $('<td></td>').attr({"class": "date"});
td.append($('<span></span>').attr({
"class": "modified",
"title": formatted,
"style": 'color:rgb(' + modifiedColor + ',' + modifiedColor + ',' + modifiedColor + ')'
}).text(text)
.tooltip({placement: 'top'})
);

$tr.append(td);
}
return $tr;
},

Expand All @@ -98,6 +134,11 @@
// root has special permissions
this.$el.find('#emptycontent').toggleClass('hidden', !this.isEmpty);
this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty);

// hide expiration date header for non link only shares
if (!this._linksOnly) {
this.$el.find('th.column-expiration').addClass('hidden');
}
}
else {
OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments);
Expand Down Expand Up @@ -249,6 +290,7 @@
type: share.share_type,
target: share.share_with,
stime: share.stime * 1000,
expiration: share.expiration,
};
if (self._sharedWithUser) {
file.shareOwner = share.displayname_owner;
Expand Down
3 changes: 3 additions & 0 deletions apps/files_sharing/templates/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<th id="headerDate" class="hidden column-mtime">
<a id="modified" class="columntitle" data-sort="mtime"><span><?php p($l->t( 'Share time' )); ?></span><span class="sort-indicator"></span></a>
</th>
<th class="hidden column-expiration">
<a class="columntitle"><span><?php p($l->t( 'Expiration date' )); ?></span></a>
</th>
</tr>
</thead>
<tbody id="fileList">
Expand Down
43 changes: 40 additions & 3 deletions apps/files_sharing/tests/js/sharedfilelistSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ describe('OCA.Sharing.FileList tests', function() {
'<th class="hidden column-mtime">' +
'<a class="columntitle" data-sort="mtime"><span class="sort-indicator"></span></a>' +
'</th>' +
'<th class="column-expiration">' +
'<a class="columntitle"><span>Expiration date</span></a>' +
'</th>' +
'</tr></thead>' +
'<tbody id="fileList"></tbody>' +
'<tfoot></tfoot>' +
Expand Down Expand Up @@ -512,6 +515,15 @@ describe('OCA.Sharing.FileList tests', function() {

fileList.reload();

var currentdate = new Date();
var expirationDateInADay =
+ currentdate.getFullYear() + "-"
+ ((currentdate.getMonth()+1 < 10) ? "0" : "") + (currentdate.getMonth()+1) + "-"
+ ((currentdate.getDate()+1 < 10) ? "0" : "") + (currentdate.getDate()+1) + " "
+ ((currentdate.getHours()+1 < 10) ? "0" : "") + currentdate.getHours() + ":"
+ ((currentdate.getMinutes()+1 < 10) ? "0" : "") + currentdate.getMinutes() + ":"
+ ((currentdate.getSeconds()+1 < 10) ? "0" : "") + currentdate.getSeconds();

/* jshint camelcase: false */
ocsResponse = {
ocs: {
Expand All @@ -528,12 +540,28 @@ describe('OCA.Sharing.FileList tests', function() {
path: '/local path/local name.txt',
permissions: 1,
stime: 11111,
expiration: null,
share_type: OC.Share.SHARE_TYPE_LINK,
share_with: null,
token: 'abc',
mimetype: 'text/plain',
uid_owner: 'user1',
displayname_owner: 'User One'
},{
id: 8,
item_type: 'file',
item_source: 50,
file_source: 50,
path: '/local path2/local name2.txt',
permissions: 1,
stime: 11112,
expiration: expirationDateInADay,
share_type: OC.Share.SHARE_TYPE_LINK,
share_with: null,
token: 'abcd',
mimetype: 'text/plain2',
uid_owner: 'user2',
displayname_owner: 'User One2'
}]
}
};
Expand Down Expand Up @@ -570,10 +598,10 @@ describe('OCA.Sharing.FileList tests', function() {
JSON.stringify(ocsResponse)
);

// only renders the link share entry
// only renders the link share entries
var $rows = fileList.$el.find('tbody tr');
var $tr = $rows.eq(0);
expect($rows.length).toEqual(1);
expect($rows.length).toEqual(2);
expect($tr.attr('data-id')).toEqual('49');
expect($tr.attr('data-type')).toEqual('file');
expect($tr.attr('data-file')).toEqual('local name.txt');
Expand All @@ -588,8 +616,17 @@ describe('OCA.Sharing.FileList tests', function() {
expect($tr.find('a.name').attr('href')).toEqual(
OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt'
);
expect($tr.attr('data-expiration')).toEqual('0');
expect($tr.find('td:last-child span').text()).toEqual('Never');

expect($tr.find('.nametext').text().trim()).toEqual('local name.txt');

// change to next row
$tr = $rows.eq(1);
expect($tr.attr('data-id')).toEqual('50');
expect($tr.attr('data-file')).toEqual('local name2.txt');
expect($tr.attr('data-expiration')).not.toEqual('0');
expect($tr.find('td:last-child span').text()).toEqual('in a day');
});
it('does not show virtual token recipient as recipient when password was set', function() {
/* jshint camelcase: false */
Expand All @@ -613,7 +650,7 @@ describe('OCA.Sharing.FileList tests', function() {
// only renders the link share entry
var $rows = fileList.$el.find('tbody tr');
var $tr = $rows.eq(0);
expect($rows.length).toEqual(1);
expect($rows.length).toEqual(2);
expect($tr.attr('data-id')).toEqual('49');
expect($tr.attr('data-type')).toEqual('file');
expect($tr.attr('data-file')).toEqual('local name.txt');
Expand Down