From: Bill Erickson Date: Mon, 28 Oct 2013 13:10:32 +0000 (-0400) Subject: web staff : env supports ad-hoc loaders; more todo X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b4b18cac4f2ac267cbb020b78a6afa7d9a48e275;p=evergreen%2Fequinox.git web staff : env supports ad-hoc loaders; more todo Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/web/js/ui/default/staff/services/env.js b/Open-ILS/web/js/ui/default/staff/services/env.js index cd8cf8c01a..ca55f0896b 100644 --- a/Open-ILS/web/js/ui/default/staff/services/env.js +++ b/Open-ILS/web/js/ui/default/staff/services/env.js @@ -6,6 +6,23 @@ * returns, a pending-calls counter is decremented. Once * it reaches zero, the promise returned by load() / * loadAll() is resolved. + * + * App-supplied generic load commands are pushed onto the + * service.loaders array. Each item in the array is a + * function which returns a promise. Note that loaders in this + * array cannot have any dependencies on other startup loaders, + * since there is no guarantee which will complete first. + * + * egEnv.loaders.push(function() { + * return egNet.request(...) + * .then(function(stuff) { console.log('stuff!') }); + * + * Data requets that have requirements loaded by startup + * should run after startup directly in the application. + * + * TODO: marry egStartup and egEnv? + * TODO: support a post-org loader so that loaders can be + * added which rely on the org tree? */ angular.module('egCoreMod') @@ -18,10 +35,11 @@ function($cacheFactory) { // env fetcher .factory('egEnv', - ['$q', 'egEnvCache', 'egNet', 'egAuth', 'egPCRUD', +['$q', 'egEnvCache', 'egNet', 'egAuth', 'egPCRUD', function($q, egEnvCache, egNet, egAuth, egPCRUD) { var service = { + loaders : [], get : function(class_) { return egEnvCache.get(class_); } @@ -34,11 +52,14 @@ function($q, egEnvCache, egNet, egAuth, egPCRUD) { /* returns a promise, loads all of the specified classes */ service.load = function(classes) { - if (!classes) classes = Object.keys(this.loaders); + if (!classes) classes = Object.keys(this.classLoaders); this.deferred = $q.defer(); - this.in_flight = classes.length; + this.in_flight = classes.length + this.loaders.length; angular.forEach(classes, function(cls) { - service.loaders[cls]().then(function(){service.onload()}); + service.classLoaders[cls]().then(function(){service.onload()}); + }); + angular.forEach(this.loaders, function(loader) { + loader().then(function(){service.onload()}); }); return this.deferred.promise; }; @@ -68,7 +89,7 @@ function($q, egEnvCache, egNet, egAuth, egPCRUD) { /* Classes (by hint) to load, their loading routines, * and their result mungers */ - service.loaders = { + service.classLoaders = { aou : function() { return egPCRUD.search('aou', {parent_ou : null}, @@ -88,7 +109,7 @@ function($q, egEnvCache, egNet, egAuth, egPCRUD) { } // org unit settings, blah, blah - } + }; return service; }]);