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

Remove no longer used code; adjust item list slightly. #1651

Merged
merged 1 commit into from
Sep 26, 2024
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
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
16 changes: 16 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,22 @@ 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
87 changes: 9 additions & 78 deletions girder/girder_large_image/web_client/views/itemList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Backbone from 'backbone';

import {wrap} from '@girder/core/utilities/PluginUtils';
import {getApiRoot} from '@girder/core/rest';
import {getCurrentUser} from '@girder/core/auth';
import {AccessType} from '@girder/core/constants';
import {formatSize, parseQueryString, splitRoute} from '@girder/core/misc';
import HierarchyWidget from '@girder/core/views/widgets/HierarchyWidget';
Expand Down Expand Up @@ -73,16 +72,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 +131,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 +187,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 +293,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 @@ -431,7 +386,6 @@ wrap(ItemListWidget, 'render', function (render) {

largeImageConfig.getSettings((settings) => {
var items = this.collection.toArray();
var parent = this.$el;
this._hasAnyLargeImage = !!_.some(items, function (item) {
return item.has('largeImage');
});
Expand All @@ -442,29 +396,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
Loading