Update query menu item name when the query name is changed

pull/1524/head
Till Breuer 10 years ago
parent 664a232659
commit fc2f696863
  1. 15
      app/assets/javascripts/angular/controllers/dialogs/settings.js
  2. 12
      app/assets/javascripts/angular/layout/query-menu-items.js
  3. 29
      karma/tests/layout/query-menu-item-directive-test.js

@ -36,8 +36,13 @@ angular.module('openproject.workPackages.controllers')
});
}])
.controller('SettingsModalController', ['$scope', 'settingsModal', 'QueryService',
function($scope, settingsModal, QueryService) {
.controller('SettingsModalController', [
'$scope',
'settingsModal',
'QueryService',
'$rootScope',
'QUERY_MENU_ITEM_TYPE',
function($scope, settingsModal, QueryService, $rootScope, QUERY_MENU_ITEM_TYPE) {
var query = QueryService.getQuery();
@ -51,6 +56,12 @@ angular.module('openproject.workPackages.controllers')
.then(function(data){
settingsModal.deactivate();
$scope.$emit('flashMessage', data.status);
$rootScope.$broadcast('openproject.layout.renameQueryMenuItem', {
itemType: QUERY_MENU_ITEM_TYPE,
queryId: query.id,
queryName: query.name
});
});
};
}]);

@ -44,7 +44,8 @@ angular.module('openproject.layout')
'$animate',
'$timeout',
'QUERY_MENU_ITEM_TYPE',
function(menuItemFactory, $stateParams, $animate, $timeout, QUERY_MENU_ITEM_TYPE) {
'QueryService',
function(menuItemFactory, $stateParams, $animate, $timeout, QUERY_MENU_ITEM_TYPE, QueryService) {
return menuItemFactory({
type: QUERY_MENU_ITEM_TYPE,
container: '#main-menu-work-packages-wrapper ~ .menu-children',
@ -68,6 +69,15 @@ angular.module('openproject.layout')
removeItem();
}
});
scope.$on('openproject.layout.renameQueryMenuItem', function(event, itemData) {
if (itemData.itemType === QUERY_MENU_ITEM_TYPE && itemData.queryId === scope.queryId) {
QueryService.updateHighlightName()
.then(function() {
element.html(itemData.queryName);
});
}
});
}
});
}])

@ -5,8 +5,21 @@ describe('queryMenuItem Directive', function() {
beforeEach(angular.mock.module('openproject.layout'));
beforeEach(module('templates', 'openproject.services', 'openproject.models'));
beforeEach(module('templates', function($provide) {
$provide.value('$stateParams', stateParams);
var QueryServiceMock = {
queryName: 'Default',
updateHighlightName: function() {
return {
then: function(callback) {
return callback(QueryServiceMock.queryName[1]);
}
};
}
};
$provide.value('QueryService', QueryServiceMock);
}));
beforeEach(inject(function($rootScope, $compile) {
@ -78,4 +91,20 @@ describe('queryMenuItem Directive', function() {
});
});
});
describe('when the renameQueryItem event is received', function() {
var queryName = 'A query to find them all';
beforeEach(function() {
rootScope.$broadcast('openproject.layout.renameQueryMenuItem', {
itemType: 'query-menu-item',
queryid: queryId,
queryName: queryName
});
});
it('resets the menu item title', function() {
expect(element.text()).to.equal(queryName);
});
});
});

Loading…
Cancel
Save