]> source.dussan.org Git - nextcloud-server.git/commitdiff
Hide favourite icon in details view if favourite action is not available 7742/head
authorDaniel Calviño Sánchez <danxuliu@gmail.com>
Fri, 5 Jan 2018 18:06:06 +0000 (19:06 +0100)
committerDaniel Calviño Sánchez <danxuliu@gmail.com>
Mon, 8 Jan 2018 16:44:55 +0000 (17:44 +0100)
When the favourite icon in the details view is clicked the "Favorite"
action is triggered. However, if the action name given to
"triggerAction" is not found then the "Download" action is triggered
instead. As the "Favorite" action is not available in some file lists
(like "Recents") the "Download" action was executed instead in those
cases, which was a strange behaviour. Now the favourite icon is
hidden if its action is not available.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
apps/files/js/mainfileinfodetailview.js
apps/files/tests/js/mainfileinfodetailviewSpec.js

index d703ca8371c6cac51aff7c2d48636867023a97f6..f7073b2e01d7f8869ba94b8ecab1fa3ae807ad0b 100644 (file)
                        '</a>' +
                '</div>' +
                '       <div class="file-details ellipsis">' +
+               '               {{#if hasFavoriteAction}}' +
                '               <a href="#" class="action action-favorite favorite permanent">' +
                '                       <span class="icon {{starClass}}" title="{{starAltText}}"></span>' +
                '               </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>' +
                '       </div>' +
                '</div>' +
 
                        if (this.model) {
                                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({
                                        type: this.model.isImage()? 'image': '',
                                        nameLabel: t('files', 'Name'),
                                        altDate: OC.Util.formatDate(this.model.get('mtime')),
                                        timestamp: this.model.get('mtime'),
                                        date: OC.Util.relativeModifiedDate(this.model.get('mtime')),
+                                       hasFavoriteAction: hasFavoriteAction,
                                        starAltText: isFavorite ? t('files', 'Favorited') : t('files', 'Favorite'),
                                        starClass: isFavorite ? 'icon-starred' : 'icon-star',
                                        permalink: this._makePermalink(this.model.get('id')),
index faf0faa8d8f5e08341b73bb478215cf38d0d53ad..956df29a650087b4621196e723388e403c74d8c2 100644 (file)
@@ -68,6 +68,12 @@ describe('OCA.Files.MainFileInfoDetailView tests', function() {
                                .toEqual(OC.getProtocol() + '://' + OC.getHost() + OC.generateUrl('/f/5'));
                });
                it('displays favorite icon', function() {
+                       fileActions.registerAction({
+                               name: 'Favorite',
+                               mime: 'all',
+                               permissions: OC.PERMISSION_READ
+                       });
+
                        testFileInfo.set('tags', [OC.TAG_FAVORITE]);
                        view.setFileInfo(testFileInfo);
                        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-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() {
                        // File
                        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');
                });
                it('rerenders when changes are made on the model', function() {
+                       // Show the "Favorite" icon
+                       fileActions.registerAction({
+                               name: 'Favorite',
+                               mime: 'all',
+                               permissions: OC.PERMISSION_READ
+                       });
+
                        view.setFileInfo(testFileInfo);
 
                        testFileInfo.set('tags', [OC.TAG_FAVORITE]);
@@ -196,11 +218,19 @@ describe('OCA.Files.MainFileInfoDetailView tests', function() {
                        expect(view.$el.find('.action-favorite > span').hasClass('icon-star')).toEqual(true);
                });
                it('unbinds change listener from model', function() {
+                       // Show the "Favorite" icon
+                       fileActions.registerAction({
+                               name: 'Favorite',
+                               mime: 'all',
+                               permissions: OC.PERMISSION_READ
+                       });
+
                        view.setFileInfo(testFileInfo);
                        view.setFileInfo(new OCA.Files.FileInfoModel({
                                id: 999,
                                name: 'test.txt',
-                               path: '/'
+                               path: '/',
+                               permissions: 31
                        }));
 
                        // set value on old model