Skip to content

Commit

Permalink
Merge pull request #1095 from himdel/toolbar-digest
Browse files Browse the repository at this point in the history
ToolbarController - always $digest after Rx message
(cherry picked from commit 2128ff1)

https://bugzilla.redhat.com/show_bug.cgi?id=1444178
https://bugzilla.redhat.com/show_bug.cgi?id=1444037
  • Loading branch information
Martin Povolny authored and simaishi committed May 11, 2017
1 parent 7054117 commit 2e2c060
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions app/assets/javascripts/controllers/toolbar_controller.js
@@ -1,5 +1,4 @@
(function(){

(function() {
function isButton(item) {
return item.type === 'button';
}
Expand All @@ -17,15 +16,20 @@
if (event.rowSelect) {
this.onRowSelect(event.rowSelect);
} else if (event.redrawToolbar) {
this.onUpdateToolbar(event.redrawToolbar);
this.onUpdateToolbar(event.redrawToolbar);
} else if (event.update) {
this.onUpdateItem(event);
}

// sync changes
if (! this.$scope.$$phase) {
this.$scope.$digest();
}
}.bind(this),
function (err) {
function(err) {
console.error('Angular RxJs Error: ', err);
},
function () {
function() {
console.debug('Angular RxJs subject completed, no more events to catch.');
});
}
Expand Down Expand Up @@ -63,9 +67,6 @@
*/
ToolbarController.prototype.onRowSelect = function(data) {
this.MiQToolbarSettingsService.checkboxClicked(data.checked);
if(!this.$scope.$$phase) {
this.$scope.$digest();
}
}

/**
Expand Down Expand Up @@ -93,11 +94,8 @@
this.toolbarItems = toolbarItems.items;
this.dataViews = toolbarItems.dataViews;
}.bind(this));
}
};

/**
*
*/
ToolbarController.prototype.setClickHandler = function() {
var buttons = _
.chain(this.toolbarItems)
Expand All @@ -106,7 +104,7 @@
return (item && item.hasOwnProperty('items')) ? item.items : item;
})
.flatten()
.filter(function(item){
.filter(function(item) {
return item.type &&
(isButton(item) || isButtonTwoState(item))
})
Expand All @@ -116,11 +114,11 @@
}
})
.value();
}
};

/**
* Public method for changing view over data.
*/
/**
* Public method for changing view over data.
*/
ToolbarController.prototype.onViewClick = function(item, $event) {
if (item.url.indexOf('/') === 0) {
var delimiter = (item.url === '/') ? '' : '/';
Expand All @@ -130,37 +128,31 @@
} else {
miqToolbarOnClick.bind($event.delegateTarget)($event);
}
}
};

ToolbarController.prototype.initObject = function(toolbarString) {
subscribeToSubject.bind(this)();
this.updateToolbar(JSON.parse(toolbarString));
}
};

ToolbarController.prototype.onUpdateToolbar = function(toolbarObject) {
this.updateToolbar(toolbarObject);
if(!this.$scope.$$phase) {
this.$scope.$digest();
}
}
};

ToolbarController.prototype.onUpdateItem = function(updateData) {
var toolbarItem = _.find(_.flatten(this.toolbarItems), {id: updateData.update});
if (toolbarItem && toolbarItem.hasOwnProperty(updateData.type)) {
toolbarItem[updateData.type] = updateData.value;
if(!this.$scope.$$phase) {
this.$scope.$digest();
}
}
}
};

ToolbarController.prototype.updateToolbar = function(toolbarObject) {
toolbarItems = this.MiQToolbarSettingsService.generateToolbarObject(toolbarObject);
this.toolbarItems = toolbarItems.items;
this.dataViews = toolbarItems.dataViews;
this.defaultViewUrl();
this.setClickHandler();
}
};

ToolbarController.$inject = ['MiQToolbarSettingsService', 'MiQEndpointsService', '$scope', '$location'];
miqHttpInject(angular.module('ManageIQ.toolbar'))
Expand Down

0 comments on commit 2e2c060

Please sign in to comment.