Skip to content

Commit

Permalink
Added a service for reloading the dataSet object. Changing the permis…
Browse files Browse the repository at this point in the history
…sion, i.e. sharing or unsharing data sets, causes a hard reset / reload of the data set list to see changes immediately.
  • Loading branch information
flekschas committed Jun 30, 2015
1 parent d00bb44 commit 7f7b2e7
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 14 deletions.
27 changes: 19 additions & 8 deletions refinery/ui/src/js/dashboard/controllers/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ function DashboardCtrl (
dashboardDataSetService,
dashboardDataSetListService,
dashboardDataSetSearchService,
dashboardDataSetSourceService) {
dashboardDataSetSourceService,
dashboardDataSetReloadService) {
// Store the context.
var that = this;

Expand All @@ -35,6 +36,7 @@ function DashboardCtrl (
that.dashboardDataSetListService = dashboardDataSetListService;
that.dashboardDataSetSearchService = dashboardDataSetSearchService;
that.dashboardDataSetSourceService = dashboardDataSetSourceService;
that.dashboardDataSetReloadService = dashboardDataSetReloadService;

// Construct class variables
that.dataSetServiceLoading = false;
Expand Down Expand Up @@ -84,6 +86,20 @@ function DashboardCtrl (
// Initilize data set source
that.setDataSetSource();

// Set reloader
that.dashboardDataSetReloadService.setReload(function (hardReset) {
if (hardReset) {
that.dataSets.resetCache(undefined, hardReset);
}
// Reset current list and reload uiScroll
if (that.dataSetsAdapter) {
that.dataSetsAdapter.applyUpdates(function (item, scope) {
return [];
});
that.dataSetsAdapter.reload();
}
});

$rootScope.$on('$stateChangeSuccess', function () {
$timeout(window.sizing, 0);
});
Expand Down Expand Up @@ -135,13 +151,7 @@ DashboardCtrl.prototype.setDataSetSource = function (searchQuery) {
that.dataSets.resetCache();
}

// Reset current list and reload uiScroll
if (that.dataSetsAdapter) {
that.dataSetsAdapter.applyUpdates(function (item, scope) {
return [];
});
that.dataSetsAdapter.reload();
}
that.dashboardDataSetReloadService.reload();
};

DashboardCtrl.prototype.getProjects = function (limit, offset) {
Expand Down Expand Up @@ -228,5 +238,6 @@ angular
'dashboardDataSetListService',
'dashboardDataSetSearchService',
'dashboardDataSetSourceService',
'dashboardDataSetReloadService',
DashboardCtrl
]);
12 changes: 10 additions & 2 deletions refinery/ui/src/js/dashboard/controllers/PermissionEditor.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
function PermissionEditorCtrl ($http, $modalInstance, _, sharingService, config) {
function PermissionEditorCtrl (
$modalInstance,
_,
sharingService,
dashboardDataSetReloadService,
config) {
var that = this;

this._ = _;
this.config = config;
this.$modalInstance = $modalInstance;
this.sharingService = sharingService;
this.dashboardDataSetReloadService = dashboardDataSetReloadService;

this.getPermissions(
this.config.model,
Expand All @@ -15,6 +21,7 @@ function PermissionEditorCtrl ($http, $modalInstance, _, sharingService, config)
console.error(error);
});

// Used as a shorthand to avoid complicated permission checking in `ngRepeat`
this.permissionLevel = {
none: {
read: false,
Expand Down Expand Up @@ -118,6 +125,7 @@ PermissionEditorCtrl.prototype.save = function () {
})
.$promise
.then(function () {
that.dashboardDataSetReloadService.reload(true);
that.$modalInstance.dismiss('saved');
})
.catch(function (error) {
Expand All @@ -131,10 +139,10 @@ PermissionEditorCtrl.prototype.save = function () {
angular
.module('refineryDashboard')
.controller('PermissionEditorCtrl', [
'$http',
'$modalInstance',
'_',
'sharingService',
'dashboardDataSetReloadService',
'config',
PermissionEditorCtrl
]);
12 changes: 8 additions & 4 deletions refinery/ui/src/js/dashboard/services/dataSets.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,15 @@ angular
/**
* Reset the cache
*/
resetCache: function (id) {
resetCache: function (id, hardReset) {
id = id || dataSets.cache.defaultId;
// Cache current cache store.
// (Yes we cache the cache!)
cacheStore.put(this.cache.id, this.cache.items);
if (hardReset) {
cacheStore.removeAll();
} else {
// Cache current cache store.
// (Yes we cache the cache!)
cacheStore.put(this.cache.id, this.cache.items);
}
// Restore former cache or reset cache.
this.cache.items = cacheStore.get(id) || {};
// Set new id
Expand Down
23 changes: 23 additions & 0 deletions refinery/ui/src/js/dashboard/services/dataSetsReload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
angular
.module('refineryDashboard')
.factory('dashboardDataSetReloadService', ['$q',
function ($q) {
return {
/**
* Interface for the getter
* @param {number} offset First item returned by the API.
* @param {number} limit Number of items returned by the API.
* @return {object} Angular promise.
*/
reload: function () {},
/**
* Switch getter with a custom function.
* @param {function} sourceFunction The actualy source function, e.g.
*
*/
setReload: function (sourceFunction) {
this.reload = sourceFunction;
}
};
}
]);
Empty file.

0 comments on commit 7f7b2e7

Please sign in to comment.