Commit 69cabf7e authored by abirembaut's avatar abirembaut Committed by julienmege

fix (task list) display message for task with contract but no form (#518)

- display a message instead of the default form in case a task has a contract defined but "no form" was selected in the form mapping

Covers [BPO-333](https://bonitasoft.atlassian.net/browse/BPO-333)
parent b0bf28d7
......@@ -188,6 +188,12 @@
data: data
});
};
userTaskAPI.getContract = function(taskId) {
return $http({
url: API_PATH + 'bpm/userTask/'+ taskId +'/contract',
method: 'GET'
});
};
return userTaskAPI;
});
......
......@@ -6,7 +6,7 @@
.module('org.bonitasoft.features.user.tasks.details')
.controller('TaskDetailsCtrl', TaskDetailsCtrl);
function TaskDetailsCtrl($scope, iframe, taskListStore, taskDetailsHelper, processAPI, formMappingAPI, TASK_FILTERS) {
function TaskDetailsCtrl($scope, iframe, taskListStore, taskDetailsHelper, processAPI, formMappingAPI, userTaskAPI, TASK_FILTERS) {
$scope.isAssignable = isAssignable;
$scope.isEditable = isEditable;
$scope.isInactive = isInactive;
......@@ -23,6 +23,7 @@
$scope.hasOverview = false;
$scope.hasForm = false;
$scope.hasContract = false;
// Watch the currentCase
$scope.$watch(function() {
......@@ -107,21 +108,46 @@
c: 1,
f: ['processDefinitionId=' + $scope.currentTask.processId, 'task=' + $scope.currentTask.name, 'type=TASK']
}).$promise.then(function (response) {
$scope.hasForm = hasFormMapping(response);
if ($scope.hasForm && !hideForm()) {
$scope.hasForm = hasFormMapping(response);
if (!hideForm()) {
if ($scope.hasForm) {
/*jshint camelcase: false*/
return processAPI
.get({
id: $scope.currentTask.processId
})
return processAPI.get({
id: $scope.currentTask.processId
})
.$promise.then(function (data) {
// Load the task informatioin for the iframe
$scope.formUrl = iframe.getTaskForm(data, $scope.currentTask, taskListStore.user.user_id, false);
})
.finally(function () {
$scope.loading = false;
});
} else {
fetchTaskContract();
}
})
} else {
$scope.loading = false;
}
})
.catch(function () {
$scope.hasForm = false;
fetchTaskContract();
});
}
/**
* Check the task has a contract not empty and set hasContract accordingly and loading to false
*/
function fetchTaskContract() {
userTaskAPI.getContract($scope.currentTask.id).then(function (response) {
if (response.data && response.data.inputs && response.data.inputs.length > 0) {
$scope.hasContract = true;
} else {
$scope.hasContract = false;
}
})
.catch(function () {
$scope.hasContract = false;
})
.finally(function () {
$scope.loading = false;
......
......@@ -41,18 +41,19 @@
<translate>Take</translate>
</button>
</div>
<bonita-iframe-viewer class="FormViewer"
<bonita-iframe-viewer class="FormViewer"
tabindex="0"
ng-if="!isInactive() && hasForm && !loading"
is-editable="isEditable()"
frame-url="formUrl">
</bonita-iframe-viewer>
<no-form class="FormViewer"
</bonita-iframe-viewer>
<no-form class="FormViewer"
ng-if="!hasForm && !loading"
current-task="currentTask"
editable="isEditable()"
inactive="isInactive()">
</no-form>
inactive="isInactive()"
has-contract="hasContract">
</no-form>
</div>
</tab>
......
......@@ -23,7 +23,8 @@
scope: {
currentTask: '=',
editable: '=',
inactive: '='
inactive: '=',
hasContract: '='
},
link: function(scope) {
......
<div class="Viewer-wrapper" ng-if="!inactive">
<h4>{{currentTask.displayName || currentTask.name}}</h4>
<p translate>No form is needed. You can enter a comment and confirm.</p>
<form role="form">
<div class="form-group">
<label for="task-comment" translate>Comment:</label>
<textarea ng-model="currentTask.comment" id="task-comment" class="form-control"></textarea>
</div>
<button ng-click="onExecuteTask()" class="btn btn-primary center-block" translate>Submit</button>
</form>
<div ng-if="!hasContract">
<p translate>No form is needed. You can enter a comment and confirm.</p>
<form role="form">
<div class="form-group">
<label for="task-comment" translate>Comment:</label>
<textarea ng-model="currentTask.comment" id="task-comment" class="form-control"></textarea>
</div>
<button ng-click="onExecuteTask()" class="btn btn-primary center-block" translate>Submit</button>
</form>
</div>
<div ng-if="hasContract">
<p class="alert alert-info TaskInfo" translate>This task cannot be executed from here.</p>
</div>
<div class="Viewer-overlay" ng-if="!editable"></div>
</div>
......@@ -4,11 +4,11 @@
describe('Task details controller', () => {
let taskListStore, taskDetailsHelper, processAPI, formMappingAPI, controller, scope, $q, $rootScope;
let taskListStore, taskDetailsHelper, processAPI, formMappingAPI, userTaskAPI, controller, scope, $q, $rootScope;
beforeEach(module('org.bonitasoft.features.user.tasks.details'));
beforeEach(inject(function(_taskListStore_, _taskDetailsHelper_, _processAPI_, _formMappingAPI_, $controller, _$q_, _$rootScope_) {
beforeEach(inject(function(_taskListStore_, _taskDetailsHelper_, _processAPI_, _formMappingAPI_, _userTaskAPI_, $controller, _$q_, _$rootScope_) {
$q = _$q_;
$rootScope = _$rootScope_;
taskListStore = _taskListStore_;
......@@ -24,11 +24,17 @@
formMappingAPI = _formMappingAPI_;
spyOn(formMappingAPI, 'search').and.callFake(function() {
var deferred = $q.defer();
deferred.resolve({resource: {0: {target: 'INTERNAL'}, pagination: {total: 1}}});
deferred.resolve({resource: {0: {target: 'NONE'}, pagination: {total: 1}}});
return {
$promise: deferred.promise
};
});
userTaskAPI = _userTaskAPI_;
spyOn(userTaskAPI, 'getContract').and.callFake(function() {
var deferred = $q.defer();
deferred.resolve({data: {inputs: [{type:'TEXT', description:null, name: 'input1', multiple:false, inputs:[]}]}});
return deferred.promise;
});
taskDetailsHelper = _taskDetailsHelper_;
spyOn(taskDetailsHelper, 'takeReleaseTask').and.callFake(function(task) {
var deferred = $q.defer();
......@@ -66,22 +72,26 @@
expect(scope.refresh).toHaveBeenCalled();
});
it('should not check mapping when the current task did not change', function() {
it('should not check mapping and contract when the current task did not change', function() {
/*jshint camelcase: false*/
$rootScope.$apply();
var formMappingCalls = formMappingAPI.search.calls.count();
var userTaskContractCalls = userTaskAPI.getContract.calls.count();
scope.currentTask = {id: 1, name: 'task1', selected: false, processId: 42, type: 'USER_TASK'};
$rootScope.$apply();
expect(formMappingAPI.search.calls.count()).toBe(formMappingCalls);
expect(userTaskAPI.getContract.calls.count()).toBe(userTaskContractCalls);
});
it('should check mapping when the current task changes', function() {
it('should check mapping and contract when the current task changes', function() {
/*jshint camelcase: false*/
$rootScope.$apply();
var formMappingCalls = formMappingAPI.search.calls.count();
var userTaskContractCalls = userTaskAPI.getContract.calls.count();
scope.currentTask = {id: 2, name: 'task2', selected: true, processId: 42, type: 'USER_TASK'};
$rootScope.$apply();
expect(formMappingAPI.search.calls.count()).toBe(formMappingCalls + 1);
expect(userTaskAPI.getContract.calls.count()).toBe(userTaskContractCalls + 1);
});
it('should select form tab by default', () => {
......
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