Commit 0e2faceb authored by julienmege's avatar julienmege Committed by benjaminParisel

feat(last update date) improve last update date managment

- Do not save page if no modification (on Save / export / Preview )

closes[BS-18204](https://bonitasoft.atlassian.net/browse/BS-18204)
parent 047e47f4
......@@ -3,7 +3,7 @@
'use strict';
class EditorHeaderCtrl {
constructor(mode, artifact, artifactRepo, $uibModal, $stateParams, $state, $window, $localStorage, browserHistoryService, keyBindingService, $scope, $timeout) {
constructor(mode, artifact, artifactRepo, $uibModal, $stateParams, $state, $window, $localStorage, browserHistoryService, keyBindingService, $scope, $timeout, $q) {
'ngInject';
this.mode = mode;
this.page = artifact;
......@@ -14,6 +14,7 @@
this.$window = $window;
this.$localStorage = $localStorage;
this.$timeout = $timeout;
this.$q = $q;
this.browserHistoryService = browserHistoryService;
this.pristine = true;
this.dirty = false;
......@@ -42,6 +43,11 @@
}
save(page) {
if (!this.isPageDirty(page)) {
let defer = this.$q.defer();
defer.resolve();
return defer.promise;
}
return this.artifactRepo.save(page)
.then(response => {
this.dirty = false;
......
......@@ -62,6 +62,17 @@
expect(scope.$broadcast).toHaveBeenCalledWith('saved');
});
it('should not save a page if not dirty', function() {
spyOn(pageRepo, 'save');
spyOn(pageRepo, 'needSave').and.returnValue(false);
var page = { id: 'person', name: 'person'};
controller.save(page);
scope.$apply();
expect(pageRepo.save).not.toHaveBeenCalled();
});
it('should save a page changing its name', function() {
let expectedHeaders = (headerName) => {
let headers = {location : '/rest/pages/person'};
......@@ -115,6 +126,22 @@
expect($window.location).toBe('export/page/person');
});
it('should avoid save then export if page is not dirty', function() {
$localStorage.bonitaUIDesigner = { doNotShowExportMessageAgain: true };
spyOn($uibModal, 'open').and.returnValue(modalInstance);
spyOn(pageRepo, 'save');
spyOn(pageRepo, 'exportUrl').and.returnValue('export/page/person');
var page = { id: 'person' };
spyOn(pageRepo, 'needSave').and.returnValue(false);
controller.saveAndExport(page);
scope.$apply();
expect($uibModal.open).not.toHaveBeenCalled();
expect(pageRepo.save).not.toHaveBeenCalled();
expect($window.location).toBe('export/page/person');
});
it('should save a page as ...', function() {
spyOn($uibModal, 'open').and.returnValue(modalInstance);
spyOn(pageRepo, 'create').and.returnValue($q.when({}));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment