Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a defaultSort option for item lists. #928

Merged
merged 1 commit into from
Aug 12, 2022
Merged
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
29 changes: 29 additions & 0 deletions docs/girder_config_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,32 @@ This is used to specify how items appear in item lists. There are two settings,
# the length of arrays.
value: gloms.length
title: Number of Gloms
defaultSort:
# The default lists a sort order for sortable columns. This must have
# type, value, and dir for each entry, where dir is either "up" or
# "down".
-
type: metadata
value: Stain
dir: up
-
type: record
value: name
dir: down
itemListDialog:
# Show these columns
columns:
-
type: image
value: thumbnail
title: Thumbnail
-
type: record
value: name
-
type: metadata
value: Stain
format: text
-
type: record
value: size
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ul.g-item-list.li-item-list
if showSizes
.g-item-size= formatSize(item.get('size'))
else if column.type === 'image' && item.get('largeImage')
.large_image_thumbnail(extra-image=column.value !== 'thumbnail' ? column.value : undefined, style=column.width ? `width: ${column.width}px` : undefined, g-item-cid=column.value === 'thumbnail' ? item.cid : undefined)
.large_image_thumbnail(extra-image=column.value !== 'thumbnail' ? column.value : undefined, style=`width: ${column.width || 160}px; height: ${column.height || 100}px`, g-item-cid=column.value === 'thumbnail' ? item.cid : undefined)
- var imageName = column.value === 'thumbnail' ? column.value : `images/${column.value}`;
img.waiting(deferred-src=`${apiRoot}/item/${item.id}/tiles/${imageName}?width=${column.width || 160}&height=${column.height || 100}`)
else if column.type === 'metadata'
Expand Down
23 changes: 16 additions & 7 deletions girder/girder_large_image/web_client/views/itemList.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,22 @@ wrap(ItemListWidget, 'render', function (render) {
return this._liconfig ? (this.$el.closest('.modal-dialog').length ? this._liconfig.itemListDialog : this._liconfig.itemList) : undefined;
};

this._setSort = () => {
this.collection.offset = 0;
this.collection.comparator = _.constant(0);
this.collection.sortField = JSON.stringify(this._lastSort.map((e) => [
(e.type === 'metadata' ? 'meta.' : '') + e.value,
e.dir === 'down' ? 1 : -1
]));
this.collection.fetch({folderId: this.parentView.parentModel.id});
};

function itemListRender() {
if (!this._lastSort && this._confList() && this._confList().defaultSort && this._confList().defaultSort.length) {
this._lastSort = this._confList().defaultSort;
this._setSort();
return;
}
this.$el.html(ItemListTemplate({
items: this.collection.toArray(),
isParentPublic: this.public,
Expand Down Expand Up @@ -199,13 +214,7 @@ function sortColumn(evt) {
}
this._lastSort = this._lastSort.filter((e) => e.type !== entry.type || e.value !== entry.value);
this._lastSort.unshift(entry);
this.collection.offset = 0;
this.collection.comparator = _.constant(0);
this.collection.sortField = JSON.stringify(this._lastSort.map((e) => [
(e.type === 'metadata' ? 'meta.' : '') + e.value,
e.dir === 'down' ? 1 : -1
]));
this.collection.fetch({folderId: this.parentView.parentModel.id});
this._setSort();
}

export default ItemListWidget;
9 changes: 9 additions & 0 deletions test/test_files/.large_image_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ access:
-
type: record
value: controls
defaultSort:
-
type: metadata
value: Classification
dir: up
-
type: record
value: name
dir: down
itemListDialog:
# Show these columns
columns:
Expand Down