]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix grid view toggle 34071/head
authorVincent Petry <vincent@nextcloud.com>
Wed, 14 Sep 2022 10:03:13 +0000 (12:03 +0200)
committernextcloud-command <nextcloud-command@users.noreply.github.com>
Wed, 14 Sep 2022 12:52:01 +0000 (12:52 +0000)
Move grid view logic to the files app itself because the button does not
belong to any specific file list.

Then inject the grid view state when switching file lists.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
apps/files/js/app.js
apps/files/js/filelist.js

index f7863de09bea312d94c40973a83d22e9efe5e452..26a0ed9c084527c13b70ebbef3759f23241f8f34 100644 (file)
                        var cropImagePreviews = $('#cropImagePreviews').val() === "1";
                        this.$cropImagePreviews.prop('checked', cropImagePreviews);
 
+                       // Toggle for grid view
+                       this.$showGridView = $('input#showgridview');
+                       this.$showGridView.on('change', _.bind(this._onGridviewChange, this));
+                       $('#view-toggle').tooltip({placement: 'bottom', trigger: 'hover'});
+
                        if ($('#fileNotFound').val() === "1") {
                                OC.Notification.show(t('files', 'File could not be found'), {type: 'error'});
                        }
                 * @param {OCA.Files.FileList} newFileList -
                 */
                updateCurrentFileList: function(newFileList) {
+                       if (this.currentFileList === newFileList) {
+                               return
+                       }
+
                        this.currentFileList = newFileList;
+                       if (this.currentFileList !== null) {
+                               // update grid view to the current value
+                               const isGridView = this.$showGridView.is(':checked');
+                               this.currentFileList.setGridView(isGridView);
+                       }
                },
 
                /**
                        } else {
                                OC.Util.History.pushState(this._makeUrlParams(params));
                        }
-               }
+               },
+
+               /**
+                * Toggle showing gridview by default or not
+                *
+                * @returns {undefined}
+                */
+               _onGridviewChange: function() {
+                       const isGridView = this.$showGridView.is(':checked');
+                       // only save state if user is logged in
+                       if (OC.currentUser) {
+                               $.post(OC.generateUrl('/apps/files/api/v1/showgridview'), {
+                                       show: isGridView,
+                               });
+                       }
+                       this.$showGridView.next('#view-toggle')
+                               .removeClass('icon-toggle-filelist icon-toggle-pictures')
+                               .addClass(isGridView ? 'icon-toggle-filelist' : 'icon-toggle-pictures')
+                       this.$showGridView.next('#view-toggle').attr(
+                               'data-original-title',
+                               isGridView ? t('files', 'Show list view') : t('files', 'Show grid view'),
+                       )
+
+                       if (this.currentFileList) {
+                               this.currentFileList.setGridView(isGridView);
+                       }
+               },
+
        };
 })();
 
index 77f67c64ed7dc5442553be801e9d61517c0e1ad6..ee596dd417ecf30c00f24c3d5b86c1366499eb47 100644 (file)
                 * @return {number} page size
                 */
                pageSize: function() {
-                       var isGridView = this.$showGridView.is(':checked');
+                       var isGridView = this.$table.hasClass('view-grid');
                        var columns = 1;
                        var rows = Math.ceil(this.$container.height() / 50);
                        if (isGridView) {
 
                        this.$el.find('thead th .columntitle').click(_.bind(this._onClickHeader, this));
 
-                       // Toggle for grid view, only register once
-                       this.$showGridView = $('input#showgridview:not(.registered)');
-                       this.$showGridView.on('change', _.bind(this._onGridviewChange, this));
-                       this.$showGridView.addClass('registered');
-                       $('#view-toggle').tooltip({placement: 'bottom', trigger: 'hover'});
-
                        this._onResize = _.debounce(_.bind(this._onResize, this), 250);
                        $('#app-content').on('appresized', this._onResize);
                        $(window).resize(this._onResize);
                        this.breadcrumb._resize();
                },
 
-               /**
-                * Toggle showing gridview by default or not
-                *
-                * @returns {undefined}
-                */
-               _onGridviewChange: function() {
-                       const isGridView = this.$showGridView.is(':checked');
-                       // only save state if user is logged in
-                       if (OC.currentUser) {
-                               $.post(OC.generateUrl('/apps/files/api/v1/showgridview'), {
-                                       show: isGridView,
-                               });
-                       }
-                       this.$showGridView.next('#view-toggle')
-                               .removeClass('icon-toggle-filelist icon-toggle-pictures')
-                               .addClass(isGridView ? 'icon-toggle-filelist' : 'icon-toggle-pictures')
-                       this.$showGridView.next('#view-toggle').attr(
-                               'data-original-title',
-                               isGridView ? t('files', 'Show list view') : t('files', 'Show grid view'),
-                       )
-
+               setGridView: function(isGridView) {
                        this.$table.toggleClass('view-grid', isGridView);
                        if (isGridView) {
                                // If switching into grid view from list view, too few files might be displayed