Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

WORK IN PROGRESS -- Add support for async requests #771

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 9 additions & 3 deletions src/js/cilantro/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ define([
// The selector of the element views will be rendered within.
main: '#cilantro-main',


/*
* Sessions
*
Expand Down Expand Up @@ -84,13 +83,20 @@ define([
* concept names, operators and values to make filters more readable.
*/
styleFilters: false,
/*

/*
* Automatically refresh count statistics for context when filters
* change.
*/
distinctCountAutoRefresh: true,

/*
* When set to true, endpoints that support async requests will be
* used in an asynchronous fashion. When false, all endpoints will be
* used in their normal forms with blocking requests.
*/
useAsyncRequests: false,

/*
* Timeouts
*
Expand Down
16 changes: 12 additions & 4 deletions src/js/cilantro/models/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

define([
'underscore',
'./base'
], function(_, base) {
'../core',
'../utils',
'./base',
], function(_, c, utils, base) {

var parseTitle = function(uri) {
if (!uri) return 'Untitled';
Expand Down Expand Up @@ -36,6 +38,9 @@ define([
});


var AsyncExporterCollection = base.Collection.extend({});


var ExporterCollection = base.Collection.extend({
model: ExporterModel,

Expand All @@ -57,8 +62,11 @@ define([
});

return {
ExporterModel: ExporterModel,
ExporterCollection: ExporterCollection
ExporterCollection: utils.chooseByRequestType(
AsyncExporterCollection,
ExporterCollection,
c.config.get('useAsyncRequests')
)
};

});
12 changes: 10 additions & 2 deletions src/js/cilantro/models/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ define([
'../core',
'../constants',
'../structs',
'../utils',
'./base',
'./paginator'
], function(_, Backbone, c, constants, structs, paginator) {
], function(_, Backbone, c, constants, structs, utils, base, paginator) {

var ResultsPage = structs.Frame.extend({
idAttribute: 'page_num',
Expand Down Expand Up @@ -161,8 +163,14 @@ define([
// Set the custom model for this Paginator.
Results.prototype.model = ResultsPage;

var AsyncResults = base.Collection.extend({});

return {
Results: Results
Results: utils.chooseByRequestType(
AsyncResults,
Results,
c.config.get('useAsyncRequests')
)
};

});
30 changes: 27 additions & 3 deletions src/js/cilantro/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ define([
'underscore',
'backbone',
'./models',
'./utils',
'./router',
'./core'
], function($, _, Backbone, models, utils, router, c) {
], function($, _, Backbone, models, router, c) {

var events = {
SESSION_OPENING: 'session:opening',
Expand Down Expand Up @@ -144,13 +143,38 @@ define([
_parseLinks: function(model, xhr) {
models.Model.prototype._parseLinks.call(this, model, xhr);

var Collection;

// Iterate over the available resource links and initialize
// the corresponding collection with the URL.
this.data = {};

var ASYNC_PREFIX = 'async_',
Collection;
_.each(model.links, function(url, name) {
if (c.config.get('useAsyncRequests')) {
// If this is an asynchronous endpoint and we are using
// asynchronous requests then we should alter the name to
// match the synchronous name. This will guarantee that we
// are always construction this.data in a consistent format
// regarding naming no matter which request type we
// are using.
if (name.startsWith(ASYNC_PREFIX)) {
name = name.replace(ASYNC_PREFIX, '');
}
// At this point, we know we are dealing with a synchronous
// endpoint and we are using asynchronous requests. If this
// named endpoint also exists in asynchronous form, we
// should ignore it.
else if (ASYNC_PREFIX + name in this.links) {
return;
}
}
else if (name.startsWith(ASYNC_PREFIX)) {
// If this named endpoint is asynchronous, then we should
// ignore it when using synchronous requests.
return;
}

if ((Collection = collectionLinkMap[name])) {
this.data[name] = new Collection();
this.data[name].url = url;
Expand Down
11 changes: 9 additions & 2 deletions src/js/cilantro/ui/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ define([
'underscore',
'backbone',
'marionette',
'../utils',
'./base',
'./core'
], function($, _, Backbone, Marionette, base, c) {
], function($, _, Backbone, Marionette, utils, base, c) {

var ExportOption = Marionette.ItemView.extend({
tagName: 'label',
Expand Down Expand Up @@ -399,8 +400,14 @@ define([
}
});

var AsyncExporterDialog = Marionette.Layout.extend({});

return {
ExporterDialog: ExporterDialog
ExporterDialog: utils.chooseByRequestType(
AsyncExporterDialog,
ExporterDialog,
c.config.get('useAsyncRequests')
)
};

});
12 changes: 9 additions & 3 deletions src/js/cilantro/ui/workflows/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ define([
'jquery',
'underscore',
'marionette',
'../../utils',
'../core',
'../paginator',
'../numbers',
'../tables'
], function($, _, Marionette, c, paginator, numbers, tables) {
], function($, _, Marionette, utils, c, paginator, numbers, tables) {


var ResultCount = Marionette.ItemView.extend({
Expand Down Expand Up @@ -295,8 +296,13 @@ define([
}
});

var AsyncResultsWorkflow = Marionette.Layout.extend({});

return {
ResultCount: ResultCount,
ResultsWorkflow: ResultsWorkflow
ResultsWorkflow: utils.chooseByRequestType(
AsyncResultsWorkflow,
ResultsWorkflow,
c.config.get('useAsyncRequests')
)
};
});
14 changes: 14 additions & 0 deletions src/js/cilantro/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,21 @@ define([
console.log(JSON.stringify(obj, null, 4));
};

// Returns the supplied async or sync parameter based on the value
// of the supplied `useAsyncRequests` param. When `useAsyncRequests` is
// true, the async parameter will be returned. When it is false, the sync
// parameter is returned.
var chooseByRequestType = function(async, sync, useAsyncRequests) {
if (useAsyncRequests) {
return async;
}
else {
return sync;
}
};

mods.unshift({
chooseByRequestType: chooseByRequestType,
pprint: pprint,
getDotProp: getDotProp,
getCookie: getCookie,
Expand Down