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

This reverts commit 6d88d71c81, reversing
changes made to 0b6a2c7ad0.
pull/2396/head
Jens Ulferts 10 years ago
parent 6154c63abe
commit 4a60c2a7b2
  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. 54
      frontend/tests/unit/tests/services/query-service-test.js

@ -116,6 +116,8 @@ module.exports = function(Filter, Sortation, UrlParamsHelper, INITIALLY_SELECTED
this.setRawFilters(queryData.filters);
}
if(queryData.sortCriteria) this.setSortation(queryData.sortCriteria);
this.dirty = true;
return this;
},
@ -157,9 +159,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.
@ -352,7 +354,7 @@ module.exports = function(Filter, Sortation, UrlParamsHelper, INITIALLY_SELECTED
},
isDirty: function() {
return this.dirty;
return this.isNew() || 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,8 +237,6 @@ 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,9 +44,6 @@ 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() || (!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'))}">
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'))}">
<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 not dirty', function() {
context('query is 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 false', function() {
it("should contain accept_empty_query_fields as true", function() {
expect(query.toParams())
.to.have.property('accept_empty_query_fields')
.and.equal(false);

@ -119,7 +119,7 @@ describe('QueryService', function() {
});
});
describe('async part', function() {
describe('loadAvailableGroupedQueries', function() {
var projectIdentifier = 'test_project',
$httpBackend,
$rootScope,
@ -145,49 +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('when called for the first time', function() {
it('triggers an http request', function() {
$httpBackend.expectGET(path);
describe('loadAvailableGroupedQueries', function() {
describe('when called for the first time', function() {
it('triggers an http request', function() {
$httpBackend.expectGET(path);
loadAvailableGroupedQueries();
});
loadAvailableGroupedQueries();
});
it('stores the grouped queries', function() {
loadAvailableGroupedQueries();
it('stores the grouped queries', function() {
loadAvailableGroupedQueries();
expect(QueryService.getAvailableGroupedQueries()).to.deep.equal(groupedQueries);
});
expect(QueryService.getAvailableGroupedQueries()).to.deep.equal(groupedQueries);
});
});
describe('when called for the second time', function() {
it('does not do another http call', function() {
loadAvailableGroupedQueries();
QueryService.loadAvailableGroupedQueries(projectIdentifier);
$rootScope.$apply();
describe('when called for the second time', function() {
it('does not do another http call', function() {
loadAvailableGroupedQueries();
QueryService.loadAvailableGroupedQueries(projectIdentifier);
$rootScope.$apply();
$httpBackend.verifyNoOutstandingRequest();
});
$httpBackend.verifyNoOutstandingRequest();
});
});

Loading…
Cancel
Save