Skip to content

Commit

Permalink
Remove no longer used code; adjust item list slightly.
Browse files Browse the repository at this point in the history
With the addition of #1649, we always use the large_image itemList
rather than modifying the base girder item list.  We no longer need the
code that did that modification.

Don't display column titles on an empty list.

Make check boxes easier to click.

Allow long strings to break more efficiently.
  • Loading branch information
manthey committed Sep 26, 2024
1 parent af9a8a7 commit 1fe17a2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 92 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Better handle images without enough tile layers ([#1648](../../pull/1648))
- Add users option to config files; have a default config file ([#1649](../../pull/1649))
- Remove no longer used code; adjust item list slightly ([#1651](../../pull/1651))

### Bug Fixes

Expand Down
37 changes: 21 additions & 16 deletions girder/girder_large_image/web_client/templates/itemList.pug
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
ul.g-item-list.li-item-list(layout_mode=(itemList.layout || {}).mode || '')
- var colNames = [];
li.li-item-list-header
if checkboxes
span.li-item-list-header
for column, colidx in itemList.columns
if column.type !== 'image' || hasAnyLargeImage
span.li-item-list-header(
class=((column.type === 'record' && column.value !== 'controls') || column.type === 'metadata' ? 'sortable' : '') + ' ' + (sort && sort[0].type === column.type && ('' + sort[0].value === '' + column.value) ? sort[0].dir : ''),
column_type=column.type, column_value=column.value)
if column.title !== undefined
- colNames[colidx] = column.title
else
- colNames[colidx] = `${column.value.substr(0, 1).toUpperCase()}${column.value.substr(1)}`
= colNames[colidx]
if items.length
li.li-item-list-header
if checkboxes
span.li-item-list-header
for column, colidx in itemList.columns
if column.type !== 'image' || hasAnyLargeImage
span.li-item-list-header(
class=((column.type === 'record' && column.value !== 'controls') || column.type === 'metadata' ? 'sortable' : '') + ' ' + (sort && sort[0].type === column.type && ('' + sort[0].value === '' + column.value) ? sort[0].dir : ''),
column_type=column.type, column_value=column.value)
if column.title !== undefined
- colNames[colidx] = column.title
else
- colNames[colidx] = `${column.value.substr(0, 1).toUpperCase()}${column.value.substr(1)}`
= colNames[colidx]
each item in items
li.g-item-list-entry(class=(highlightItem && item.id === selectedItemId ? 'g-selected' : ''), public=(isParentPublic ? 'true' : 'false'), style=(itemList.layout || {}).mode == 'grid' ? ('max-width: ' + parseInt((itemList.layout || {})['max-width'] || 250) + 'px') : '')
if checkboxes
span.li-item-list-cell
input.g-list-checkbox(type="checkbox", g-item-cid=item.cid)
label.li-item-list-cell(for='g-item-cid-' + item.cid)
input.g-list-checkbox(type="checkbox", g-item-cid=item.cid, id='g-item-cid-' + item.cid)
for column, colidx in itemList.columns
if column.type !== 'image' || hasAnyLargeImage
-
Expand Down Expand Up @@ -86,7 +87,11 @@ ul.g-item-list.li-item-list(layout_mode=(itemList.layout || {}).mode || '')
input.input-sm.form-control.g-widget-metadata-value-input.g-widget-metadata-column(placeholder=column.description || "Value", value=value, title=column.description)
else
span.large_image_metadata
= value
if column.format === 'text' && value
//- allow long strings to be hyphenated at periods and underscores
!= String(value).replace(/&/g, '&amp;').replace(/</, '&lt;').replace(/>/, '&gt;').replace(/"/, '&quot').replace(/'/, '&#39;').replace(/\./g, '.&shy;').replace(/_/g, '_&shy;')
else
= value
if value
span.li-item-list-cell-filter(title="Only show items that match this metadata value exactly", filter-value=value, column-value=column.value)
i.icon-filter
Expand Down
14 changes: 14 additions & 0 deletions girder/girder_large_image/web_client/views/configView.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@ var ConfigView = View.extend({
callback(ConfigView._liconfig);
}
return val;
}).fail(() => {
// fallback matching server values
const li = {columns: [
{'type': 'record', 'value': 'name', 'title': 'Name'},
{'type': 'record', 'value': 'controls', 'title': 'Contols'},
{'type': 'record', 'value': 'size', 'title': 'Size'}]};
const val = {'itemList': li, 'itemListDialog': li};
ConfigView._lastliconfig = folderId;
ConfigView._liconfigSettingsRequest = null;
ConfigView._liconfig = val;
if (callback) {
callback(ConfigView._liconfig);
}
return val;
});
return ConfigView._liconfigSettingsRequest;
},
Expand Down
85 changes: 9 additions & 76 deletions girder/girder_large_image/web_client/views/itemList.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,19 @@ wrap(ItemListWidget, 'initialize', function (initialize, settings) {
};
});
update = true;
} else if (this._confList() && this._confList().defaultSort && this._confList().defaultSort.length) {
this._lastSort = this._confList().defaultSort;
}
if (query.filter || this._recurse) {
this._generalFilter = query.filter;
this._setFilter();
this._setFilter(false);
update = true;
}
if (update) {
this._setSort();
} else {
this.render();
}
this.render();
});
this.events['click .li-item-list-header.sortable'] = (evt) => sortColumn.call(this, evt);
this.events['click .li-item-list-cell-filter'] = (evt) => itemListCellFilter.call(this, evt);
Expand Down Expand Up @@ -129,55 +132,6 @@ wrap(ItemListWidget, 'render', function (render) {
}
}

function addLargeImageDetails(item, container, parent, extraInfo) {
var elem;
elem = $('<div class="large_image_thumbnail"/>');
elem.attr('g-item-cid', item.cid);
container.append(elem);
/* We store the desired src attribute in deferred-src until we actually
* load the image. */
elem.append($('<img class="waiting"/>').attr(
'deferred-src', getApiRoot() + '/item/' +
item.id + '/tiles/thumbnail?width=160&height=100'));
var access = item.getAccessLevel();
var extra = extraInfo[access] || extraInfo[AccessType.READ] || {};
if (!getCurrentUser()) {
extra = extraInfo.null || {};
}

/* Set the maximum number of columns we have so that we can let css
* perform alignment. */
var numColumns = Math.max((extra.images || []).length + 1, parent.attr('large_image_columns') || 0);
parent.attr('large_image_columns', numColumns);

_.each(extra.images || [], function (imageName) {
elem = $('<div class="large_image_thumbnail"/>');
container.append(elem);
elem.append($('<img class="waiting"/>').attr(
'deferred-src', getApiRoot() + '/item/' + item.id +
'/tiles/images/' + imageName + '?width=160&height=100&_=' + item.get('updated')
));
elem.attr('extra-image', imageName);
});

$('.large_image_thumbnail', container).each(function () {
var elem = $(this);
/* Handle images loading or failing. */
$('img', elem).one('error', function () {
$('img', elem).addClass('failed-to-load');
$('img', elem).removeClass('loading waiting');
elem.addClass('failed-to-load');
_loadMoreImages(parent);
});
$('img', elem).one('load', function () {
$('img', elem).addClass('loaded');
$('img', elem).removeClass('loading waiting');
_loadMoreImages(parent);
});
});
_loadMoreImages(parent);
}

this._confList = () => {
return this._liconfig ? (this.$el.closest('.modal-dialog').length ? this._liconfig.itemListDialog : this._liconfig.itemList) : undefined;
};
Expand Down Expand Up @@ -234,7 +188,7 @@ wrap(ItemListWidget, 'render', function (render) {
return val;
};

this._setFilter = () => {
this._setFilter = (update) => {
const val = this._generalFilter;
let filter;
const usedPhrases = {};
Expand Down Expand Up @@ -340,7 +294,9 @@ wrap(ItemListWidget, 'render', function (render) {
this._filter = filter;
this.collection.params = this.collection.params || {};
this.collection.params.text = this._filter;
this._setSort();
if (update !== false) {
this._setSort();
}
}
};

Expand Down Expand Up @@ -442,29 +398,6 @@ wrap(ItemListWidget, 'render', function (render) {
if (this._recurse && !((this.collection || {}).params || {}).text) {
this._setFilter();
this.render();
return;
}
render.call(this);
if (settings['large_image.show_thumbnails'] === false ||
this.$('.large_image_container').length > 0) {
return this;
}
if (this._hasAnyLargeImage) {
if (!this._confList()) {
_.each(items, (item) => {
var elem = $('<div class="large_image_container"/>');
if (item.get('largeImage')) {
item.getAccessLevel(() => {
if (!this._confList()) {
addLargeImageDetails(item, elem, parent, settings.extraInfo);
}
});
}
var inner = $('<span>').html($('a[g-item-cid="' + item.cid + '"]').html());
$('a[g-item-cid="' + item.cid + '"]', parent).first().empty().append(elem, inner);
_loadMoreImages(parent);
});
}
}
return this;
});
Expand Down

0 comments on commit 1fe17a2

Please sign in to comment.