Skip to content

Commit

Permalink
Merge pull request #1193 from girder/get-config-file
Browse files Browse the repository at this point in the history
Refactor reading the .large_image_config.yaml file
  • Loading branch information
manthey authored Jun 7, 2023
2 parents a7b672e + e7130a2 commit 5f30586
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Changes
- Change how extensions and fallback priorities interact ([#1192](../../pull/1192))
- Refactor reading the .large_image_config.yaml file on the girder client ([#1193](../../pull/1193))

## 1.22.2

Expand Down
53 changes: 53 additions & 0 deletions girder/girder_large_image/web_client/views/configView.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,59 @@ var ConfigView = View.extend({
}
},

/**
* Get the folder config file for the current user.
*
* @param {string} folderId the folder to get the config for.
* @param {boolean} reload if true, refetch the config file even if it was
* the last one fetched. Since config files can be changed by the
* user, this should be done based on the UI behavior.
* @param {function} callback a function to call after the config file is
* fetched. If the file is already fetched, this is called without
* any delay.
* @returns a promise that resolves to the config file values.
*/
getConfigFile: function (folderId, reload, callback) {
if (!folderId) {
const result = {};
if (callback) {
callback(result);
}
return $.Deferred().resolve({});
}
if (ConfigView._lastliconfig === folderId && !reload) {
if (callback) {
callback(ConfigView._liconfig);
}
return $.Deferred().resolve(ConfigView._liconfig);
}
if (ConfigView._liconfigSettingsRequest) {
if (ConfigView._nextliconfig === folderId) {
if (callback) {
ConfigView._liconfigSettingsRequest.done(() => {
callback(ConfigView._liconfig);
});
}
return ConfigView._liconfigSettingsRequest;
}
ConfigView._liconfigSettingsRequest.cancel();
}
ConfigView._nextliconfig = folderId;
ConfigView._liconfigSettingsRequest = restRequest({
url: `folder/${folderId}/yaml_config/.large_image_config.yaml`
}).done((val) => {
val = val || {};
ConfigView._lastliconfig = folderId;
ConfigView._liconfigSettingsRequest = null;
ConfigView._liconfig = val || {};
if (callback) {
callback(ConfigView._liconfig);
}
return val;
});
return ConfigView._liconfigSettingsRequest;
},

/**
* Clear the settings so that getSettings will refetch them.
*/
Expand Down
13 changes: 5 additions & 8 deletions girder/girder_large_image/web_client/views/itemList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import _ from 'underscore';
import Backbone from 'backbone';

import {wrap} from '@girder/core/utilities/PluginUtils';
import {getApiRoot, restRequest} from '@girder/core/rest';
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';
Expand Down Expand Up @@ -49,13 +49,10 @@ wrap(ItemListWidget, 'initialize', function (initialize, settings) {
const result = initialize.call(this, settings);
delete this._hasAnyLargeImage;

if (!settings.folderId) {
this._liconfig = {};
}
restRequest({
url: `folder/${settings.folderId}/yaml_config/.large_image_config.yaml`
}).done((val) => {
val = val || {};
largeImageConfig.getConfigFile(settings.folderId, true, (val) => {
if (!settings.folderId) {
this._liconfig = val;
}
if (_.isEqual(val, this._liconfig) && !this._recurse) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import events from '@girder/core/events';
import UserCollection from '@girder/core/collections/UserCollection';
import UploadWidget from '@girder/core/views/widgets/UploadWidget';
import View from '@girder/core/views/View';
import largeImageConfig from '@girder/large_image/views/configView';

import AnnotationCollection from '../collections/AnnotationCollection';

Expand Down Expand Up @@ -57,10 +58,8 @@ const AnnotationListWidget = View.extend({
error: null
}).done((createResp) => {
this.createResp = createResp;
restRequest({
url: `folder/${this.model.get('folderId')}/yaml_config/.large_image_config.yaml`
}).done((val) => {
this._liconfig = val || {};
largeImageConfig.getConfigFile(this.model.get('folderId')).done((val) => {
this._liconfig = val;
this._confList = this._liconfig.annotationList || {
columns: [{
type: 'record',
Expand Down

0 comments on commit 5f30586

Please sign in to comment.