Merge pull request #7716 from nextcloud/hide-favourite-icon-in-details-view-if-favourite-action-is-not-available
Hide favourite icon in details view if favourite action is not available
This commit is contained in:
commit
9c3ac19b33
|
@ -20,9 +20,11 @@
|
||||||
'</a>' +
|
'</a>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
' <div class="file-details ellipsis">' +
|
' <div class="file-details ellipsis">' +
|
||||||
|
' {{#if hasFavoriteAction}}' +
|
||||||
' <a href="#" class="action action-favorite favorite permanent">' +
|
' <a href="#" class="action action-favorite favorite permanent">' +
|
||||||
' <span class="icon {{starClass}}" title="{{starAltText}}"></span>' +
|
' <span class="icon {{starClass}}" title="{{starAltText}}"></span>' +
|
||||||
' </a>' +
|
' </a>' +
|
||||||
|
' {{/if}}' +
|
||||||
' {{#if hasSize}}<span class="size" title="{{altSize}}">{{size}}</span>, {{/if}}<span class="date live-relative-timestamp" data-timestamp="{{timestamp}}" title="{{altDate}}">{{date}}</span>' +
|
' {{#if hasSize}}<span class="size" title="{{altSize}}">{{size}}</span>, {{/if}}<span class="date live-relative-timestamp" data-timestamp="{{timestamp}}" title="{{altDate}}">{{date}}</span>' +
|
||||||
' </div>' +
|
' </div>' +
|
||||||
'</div>' +
|
'</div>' +
|
||||||
|
@ -175,6 +177,12 @@
|
||||||
|
|
||||||
if (this.model) {
|
if (this.model) {
|
||||||
var isFavorite = (this.model.get('tags') || []).indexOf(OC.TAG_FAVORITE) >= 0;
|
var isFavorite = (this.model.get('tags') || []).indexOf(OC.TAG_FAVORITE) >= 0;
|
||||||
|
var availableActions = this._fileActions.get(
|
||||||
|
this.model.get('mimetype'),
|
||||||
|
this.model.get('type'),
|
||||||
|
this.model.get('permissions')
|
||||||
|
);
|
||||||
|
var hasFavoriteAction = 'Favorite' in availableActions;
|
||||||
this.$el.html(this.template({
|
this.$el.html(this.template({
|
||||||
type: this.model.isImage()? 'image': '',
|
type: this.model.isImage()? 'image': '',
|
||||||
nameLabel: t('files', 'Name'),
|
nameLabel: t('files', 'Name'),
|
||||||
|
@ -189,6 +197,7 @@
|
||||||
altDate: OC.Util.formatDate(this.model.get('mtime')),
|
altDate: OC.Util.formatDate(this.model.get('mtime')),
|
||||||
timestamp: this.model.get('mtime'),
|
timestamp: this.model.get('mtime'),
|
||||||
date: OC.Util.relativeModifiedDate(this.model.get('mtime')),
|
date: OC.Util.relativeModifiedDate(this.model.get('mtime')),
|
||||||
|
hasFavoriteAction: hasFavoriteAction,
|
||||||
starAltText: isFavorite ? t('files', 'Favorited') : t('files', 'Favorite'),
|
starAltText: isFavorite ? t('files', 'Favorited') : t('files', 'Favorite'),
|
||||||
starClass: isFavorite ? 'icon-starred' : 'icon-star',
|
starClass: isFavorite ? 'icon-starred' : 'icon-star',
|
||||||
permalink: this._makePermalink(this.model.get('id')),
|
permalink: this._makePermalink(this.model.get('id')),
|
||||||
|
|
|
@ -68,6 +68,12 @@ describe('OCA.Files.MainFileInfoDetailView tests', function() {
|
||||||
.toEqual(OC.getProtocol() + '://' + OC.getHost() + OC.generateUrl('/f/5'));
|
.toEqual(OC.getProtocol() + '://' + OC.getHost() + OC.generateUrl('/f/5'));
|
||||||
});
|
});
|
||||||
it('displays favorite icon', function() {
|
it('displays favorite icon', function() {
|
||||||
|
fileActions.registerAction({
|
||||||
|
name: 'Favorite',
|
||||||
|
mime: 'all',
|
||||||
|
permissions: OC.PERMISSION_NONE
|
||||||
|
});
|
||||||
|
|
||||||
testFileInfo.set('tags', [OC.TAG_FAVORITE]);
|
testFileInfo.set('tags', [OC.TAG_FAVORITE]);
|
||||||
view.setFileInfo(testFileInfo);
|
view.setFileInfo(testFileInfo);
|
||||||
expect(view.$el.find('.action-favorite > span').hasClass('icon-starred')).toEqual(true);
|
expect(view.$el.find('.action-favorite > span').hasClass('icon-starred')).toEqual(true);
|
||||||
|
@ -78,6 +84,15 @@ describe('OCA.Files.MainFileInfoDetailView tests', function() {
|
||||||
expect(view.$el.find('.action-favorite > span').hasClass('icon-starred')).toEqual(false);
|
expect(view.$el.find('.action-favorite > span').hasClass('icon-starred')).toEqual(false);
|
||||||
expect(view.$el.find('.action-favorite > span').hasClass('icon-star')).toEqual(true);
|
expect(view.$el.find('.action-favorite > span').hasClass('icon-star')).toEqual(true);
|
||||||
});
|
});
|
||||||
|
it('does not display favorite icon if favorite action is not available', function() {
|
||||||
|
testFileInfo.set('tags', [OC.TAG_FAVORITE]);
|
||||||
|
view.setFileInfo(testFileInfo);
|
||||||
|
expect(view.$el.find('.action-favorite').length).toEqual(0);
|
||||||
|
|
||||||
|
testFileInfo.set('tags', []);
|
||||||
|
view.setFileInfo(testFileInfo);
|
||||||
|
expect(view.$el.find('.action-favorite').length).toEqual(0);
|
||||||
|
});
|
||||||
it('displays mime icon', function() {
|
it('displays mime icon', function() {
|
||||||
// File
|
// File
|
||||||
var lazyLoadPreviewStub = sinon.stub(fileList, 'lazyLoadPreview');
|
var lazyLoadPreviewStub = sinon.stub(fileList, 'lazyLoadPreview');
|
||||||
|
@ -183,6 +198,13 @@ describe('OCA.Files.MainFileInfoDetailView tests', function() {
|
||||||
expect(view.$el.find('.fileName h3').attr('title')).toEqual('hello.txt');
|
expect(view.$el.find('.fileName h3').attr('title')).toEqual('hello.txt');
|
||||||
});
|
});
|
||||||
it('rerenders when changes are made on the model', function() {
|
it('rerenders when changes are made on the model', function() {
|
||||||
|
// Show the "Favorite" icon
|
||||||
|
fileActions.registerAction({
|
||||||
|
name: 'Favorite',
|
||||||
|
mime: 'all',
|
||||||
|
permissions: OC.PERMISSION_NONE
|
||||||
|
});
|
||||||
|
|
||||||
view.setFileInfo(testFileInfo);
|
view.setFileInfo(testFileInfo);
|
||||||
|
|
||||||
testFileInfo.set('tags', [OC.TAG_FAVORITE]);
|
testFileInfo.set('tags', [OC.TAG_FAVORITE]);
|
||||||
|
@ -196,6 +218,13 @@ describe('OCA.Files.MainFileInfoDetailView tests', function() {
|
||||||
expect(view.$el.find('.action-favorite > span').hasClass('icon-star')).toEqual(true);
|
expect(view.$el.find('.action-favorite > span').hasClass('icon-star')).toEqual(true);
|
||||||
});
|
});
|
||||||
it('unbinds change listener from model', function() {
|
it('unbinds change listener from model', function() {
|
||||||
|
// Show the "Favorite" icon
|
||||||
|
fileActions.registerAction({
|
||||||
|
name: 'Favorite',
|
||||||
|
mime: 'all',
|
||||||
|
permissions: OC.PERMISSION_NONE
|
||||||
|
});
|
||||||
|
|
||||||
view.setFileInfo(testFileInfo);
|
view.setFileInfo(testFileInfo);
|
||||||
view.setFileInfo(new OCA.Files.FileInfoModel({
|
view.setFileInfo(new OCA.Files.FileInfoModel({
|
||||||
id: 999,
|
id: 999,
|
||||||
|
|
Loading…
Reference in New Issue