Merge pull request #2372 from 0xF013/feature/17263-save-button-conditions-fix

fix save button display conditions
pull/2381/merge
Alex Coles 10 years ago
commit 6d88d71c81
  1. 8
      frontend/app/models/query.js
  2. 2
      frontend/app/services/query-service.js
  3. 2
      frontend/app/work_packages/controllers/work-packages-list-controller.js
  4. 3
      frontend/app/work_packages/directives/options-dropdown-directive.js
  5. 4
      frontend/public/templates/work_packages.list.html
  6. 6
      frontend/tests/unit/tests/models/query-test.js
  7. 24
      frontend/tests/unit/tests/services/query-service-test.js

@ -116,8 +116,6 @@ module.exports = function(Filter, Sortation, UrlParamsHelper, INITIALLY_SELECTED
this.setRawFilters(queryData.filters);
}
if(queryData.sortCriteria) this.setSortation(queryData.sortCriteria);
this.dirty = true;
return this;
},
@ -159,9 +157,9 @@ module.exports = function(Filter, Sortation, UrlParamsHelper, INITIALLY_SELECTED
this.availableWorkPackageFilters = availableFilters;
if (this.project_id){
delete this.availableWorkPackageFilters["project_id"];
delete this.availableWorkPackageFilters['project_id'];
} else {
delete this.availableWorkPackageFilters["subproject_id"];
delete this.availableWorkPackageFilters['subproject_id'];
}
// TODO RS: Need to assertain if there are any sub-projects and remove filter if not.
// The project will have to be fetched prior to this.
@ -354,7 +352,7 @@ module.exports = function(Filter, Sortation, UrlParamsHelper, INITIALLY_SELECTED
},
isDirty: function() {
return this.isNew() || this.dirty;
return this.dirty;
},
hasName: function() {

@ -318,7 +318,7 @@ module.exports = function(Query, Sortation, $http, PathHelper, $q, AVAILABLE_WOR
return QueryService.doQuery(url, query.toUpdateParams(), 'PUT', function(response){
QueryService.fetchAvailableGroupedQueries(query.project_id);
query.dirty = false;
return angular.extend(response.data, { status: { text: I18n.t('js.notice_successful_update') }} );
});
},

@ -237,6 +237,8 @@ module.exports = function($scope, $rootScope, $state, $location, latestTab,
$rootScope.$on('queryStateChange', function(event, message) {
$scope.maintainUrlQueryState();
$scope.maintainBackUrl();
$scope.query.dirty = true;
});
$rootScope.$on('workPackagesRefreshRequired', function(event, message) {

@ -44,6 +44,9 @@ module.exports = function(I18n, columnsModal, exportModal, saveModal, settingsMo
});
scope.saveQuery = function(event){
if (!scope.query.dirty) {
return;
}
if(scope.query.isNew()){
if( allowQueryAction(event, 'create') ){
scope.$emit('hideAllDropdowns');

@ -100,8 +100,8 @@
</li>
<li class="dropdown-divider"></li>
<li><a href="" ng-click="saveQuery($event)"
inaccessible-by-tab="(!query.isDirty() && cannot('query', 'update')) || (query.isNew() && cannot('query', 'create'))"
ng-class="{'inactive': (!query.isDirty() && cannot('query', 'update')) || (query.isNew() && cannot('query', 'create'))}">
inaccessible-by-tab="!query.isDirty() || (!query.isNew() && cannot('query', 'update')) || (query.isNew() && cannot('query', 'create'))"
ng-class="{'inactive': !query.isDirty() || (!query.isNew() && cannot('query', 'update')) || (query.isNew() && cannot('query', 'create'))}">
<i class="icon-action-menu icon-save1"></i>{{ I18n.t('js.toolbar.settings.save') }}</a>
</li>
<li><a href="" ng-click="showSaveAsModal($event)"

@ -52,12 +52,12 @@ describe('Query', function() {
query = Factory.build('Query');
});
context('query is dirty', function() {
context('query is not dirty', function() {
beforeEach(function() {
query.id = 1;
query.dirty = true;
});
it("should contain accept_empty_query_fields as true", function() {
it('should contain accept_empty_query_fields as true', function() {
expect(query.toParams())
.to.have.property('accept_empty_query_fields')
.and.equal(true);
@ -72,7 +72,7 @@ describe('Query', function() {
query.id = 1;
query.dirty = false;
});
it("should contain accept_empty_query_fields as true", function() {
it('should contain accept_empty_query_fields as false', function() {
expect(query.toParams())
.to.have.property('accept_empty_query_fields')
.and.equal(false);

@ -119,7 +119,7 @@ describe('QueryService', function() {
});
});
describe('loadAvailableGroupedQueries', function() {
describe('async part', function() {
var projectIdentifier = 'test_project',
$httpBackend,
$rootScope,
@ -145,6 +145,27 @@ describe('QueryService', function() {
$httpBackend.when('GET', path).respond(200, groupedQueries);
}));
describe('saveQuery', function() {
beforeEach(function() {
$httpBackend
.when('GET', PathHelper.apiCustomFieldsPath())
.respond(200, { data: {} });
$httpBackend
.when('GET', PathHelper.apiGroupedQueriesPath())
.respond(200, { data: {} });
var putPath = new RegExp(PathHelper.apiQueriesPath() + '/*');
$httpBackend.when('PUT', putPath).respond(200, { data: { } });
});
it('should set the query pristine', function() {
query = QueryService.initQuery(1, queryData);
query.dirty = true;
QueryService.saveQuery();
$httpBackend.flush();
expect(query.isDirty()).to.be.false;
});
});
describe('loadAvailableGroupedQueries', function() {
describe('when called for the first time', function() {
it('triggers an http request', function() {
$httpBackend.expectGET(path);
@ -168,6 +189,7 @@ describe('QueryService', function() {
$httpBackend.verifyNoOutstandingRequest();
});
});
});
});
});

Loading…
Cancel
Save