1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-22 14:11:39 +00:00

Closes #159: cancel routes + email at route step validation

This commit is contained in:
Benjamin Gamard
2018-02-02 17:18:34 +01:00
parent 5b8cd18128
commit 706d244ff8
28 changed files with 487 additions and 102 deletions

View File

@@ -149,6 +149,11 @@ angular.module('docs').controller('DocumentView', function ($scope, $state, $sta
comment: $scope.workflowComment
}).then(function (data) {
$scope.workflowComment = '';
var title = $translate.instant('document.view.workflow_validated_title');
var msg = $translate.instant('document.view.workflow_validated_message');
var btns = [{result: 'ok', label: $translate.instant('ok'), cssClass: 'btn-primary'}];
$dialog.messageBox(title, msg, btns);
if (data.readable) {
$scope.document.route_step = data.route_step;
} else {

View File

@@ -3,7 +3,10 @@
/**
* Document view workflow controller.
*/
angular.module('docs').controller('DocumentViewWorkflow', function ($scope, $stateParams, Restangular) {
angular.module('docs').controller('DocumentViewWorkflow', function ($scope, $stateParams, Restangular, $translate, $dialog) {
/**
* Load routes.
*/
$scope.loadRoutes = function () {
Restangular.one('route').get({
documentId: $stateParams.id
@@ -12,12 +15,9 @@ angular.module('docs').controller('DocumentViewWorkflow', function ($scope, $sta
});
};
// Load route models
Restangular.one('routemodel').get().then(function(data) {
$scope.routemodels = data.routemodels;
});
// Start the selected workflow
/**
* Start the selected workflow
*/
$scope.startWorkflow = function () {
Restangular.one('route').post('start', {
routeModelId: $scope.routemodel,
@@ -28,6 +28,34 @@ angular.module('docs').controller('DocumentViewWorkflow', function ($scope, $sta
});
};
/**
* Cancel the current workflow.
*/
$scope.cancelWorkflow = function () {
var title = $translate.instant('document.view.workflow.cancel_workflow_title');
var msg = $translate.instant('document.view.workflow.cancel_workflow_message');
var btns = [
{result: 'cancel', label: $translate.instant('cancel')},
{result: 'ok', label: $translate.instant('ok'), cssClass: 'btn-primary'}
];
$dialog.messageBox(title, msg, btns, function (result) {
if (result === 'ok') {
Restangular.one('route').remove({
documentId: $stateParams.id
}).then(function () {
delete $scope.document.route_step;
$scope.loadRoutes();
});
}
});
};
// Load route models
Restangular.one('routemodel').get().then(function(data) {
$scope.routemodels = data.routemodels;
});
// Load routes
$scope.loadRoutes();
});

View File

@@ -117,4 +117,11 @@ angular.module('docs').controller('SettingsWorkflowEdit', function($scope, $dial
}
});
};
/**
* Remove a route step.
*/
$scope.removeStep = function (step) {
$scope.workflow.steps.splice($scope.workflow.steps.indexOf(step), 1);
};
});

View File

@@ -94,6 +94,8 @@
"error_loading_comments": "Error loading comments",
"workflow_current": "Current workflow step",
"workflow_comment": "Add a workflow comment",
"workflow_validated_title": "Workflow step validated",
"workflow_validated_message": "The workflow step has been successfully validated.",
"content": {
"content": "Content",
"delete_file_title": "Delete file",
@@ -111,7 +113,10 @@
"workflow_start_label": "Which workflow to start?",
"add_more_workflow": "Add more workflows",
"start_workflow_submit": "Start workflow",
"full_name": "<strong>{{ name }}</strong> started on {{ create_date | date }}"
"full_name": "<strong>{{ name }}</strong> started on {{ create_date | date }}",
"cancel_workflow": "Cancel the current workflow",
"cancel_workflow_title": "Cancel the workflow",
"cancel_workflow_message": "Do you really want to cancel the current workflow?"
},
"permissions": {
"permissions": "Permissions",

View File

@@ -1,72 +1,76 @@
<p class="well-sm pull-right" ng-show="document.route_step && document.writable">
<span class="btn btn-danger" ng-click="cancelWorkflow()">
<span class="glyphicon glyphicon-trash"></span>
{{ 'document.view.workflow.cancel_workflow' | translate }}
</span>
</p>
<p class="well-sm">{{ 'document.view.workflow.message' | translate }}</p>
<form name="startWorkflowForm" class="form-horizontal" novalidate ng-show="!document.route_step">
<div class="form-group" ng-class="{ 'has-error': !startWorkflowForm.routemodel.$valid && startWorkflowForm.$dirty }">
<label for="inputRouteModel" class="col-sm-3">
{{ 'document.view.workflow.workflow_start_label' | translate }}
<p ng-if="userInfo.base_functions.indexOf('ADMIN') != -1">
<a href="#/settings/workflow">{{ 'document.view.workflow.add_more_workflow' | translate }}</a>
</p>
</label>
<div class="col-sm-6">
<select required class="form-control" id="inputRouteModel" name="routemodel" ng-model="routemodel">
<option ng-repeat="routemodel in routemodels" value="{{ routemodel.id }}">{{ routemodel.name }}</option>
</select>
</div>
<div class="col-sm-3">
<span class="help-block" ng-show="startWorkflowForm.routemodel.$error.required && startWorkflowForm.$dirty">{{ 'validation.required' | translate }}</span>
</div>
<div class="form-group" ng-class="{ 'has-error': !startWorkflowForm.routemodel.$valid && startWorkflowForm.$dirty }">
<label for="inputRouteModel" class="col-sm-3">
{{ 'document.view.workflow.workflow_start_label' | translate }}
<p ng-if="userInfo.base_functions.indexOf('ADMIN') != -1">
<a href="#/settings/workflow">{{ 'document.view.workflow.add_more_workflow' | translate }}</a>
</p>
</label>
<div class="col-sm-6">
<select required class="form-control" id="inputRouteModel" name="routemodel" ng-model="routemodel">
<option ng-repeat="routemodel in routemodels" value="{{ routemodel.id }}">{{ routemodel.name }}</option>
</select>
</div>
<div class="col-sm-3">
<span class="help-block" ng-show="startWorkflowForm.routemodel.$error.required && startWorkflowForm.$dirty">{{ 'validation.required' | translate }}</span>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-primary"
ng-disabled="!startWorkflowForm.$valid"
ng-click="startWorkflow()">
{{ 'document.view.workflow.start_workflow_submit' | translate }}
</button>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-primary"
ng-disabled="!startWorkflowForm.$valid"
ng-click="startWorkflow()">
{{ 'document.view.workflow.start_workflow_submit' | translate }}
</button>
</div>
</div>
</form>
<table class="table" ng-repeat="route in routes">
<caption translate="document.view.workflow.full_name"
translate-values="{ name: route.name, create_date: route.create_date }"></caption>
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>For</th>
<th>Validation</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="step in route.steps" ng-class="{
'bg-success': step.transition == 'VALIDATED' || step.transition == 'APPROVED',
'bg-danger': step.transition == 'REJECTED'
}">
<td>
<span class="glyphicon glyphicon-transfer" ng-if="step.type == 'APPROVE'"></span>
<span class="glyphicon glyphicon-ok-circle" ng-if="step.type == 'VALIDATE'"></span>
{{ 'workflow_type.' + step.type | translate }}
</td>
<td>{{ step.name }}</td>
<td>
<acl data="step.target"></acl>
</td>
<td>
<span ng-show="step.end_date">
{{ 'workflow_transition.' + step.transition | translate }}
{{ step.end_date | timeAgo: dateTimeFormat }}
by
<a href="#/user/{{ step.validator_username }}" class="label label-default">{{ step.validator_username }}</a>
<span ng-show="step.comment" class="text-">
<br/>
<em>{{ step.comment }}</em>
</span>
</span>
</td>
</tr>
</tbody>
<caption translate="document.view.workflow.full_name"
translate-values="{ name: route.name, create_date: route.create_date }"></caption>
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>For</th>
<th>Validation</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="step in route.steps" ng-class="{
'bg-success': step.transition == 'VALIDATED' || step.transition == 'APPROVED',
'bg-danger': step.transition == 'REJECTED'
}">
<td>
<span class="glyphicon glyphicon-transfer" ng-if="step.type == 'APPROVE'"></span>
<span class="glyphicon glyphicon-ok-circle" ng-if="step.type == 'VALIDATE'"></span>
{{ 'workflow_type.' + step.type | translate }}
</td>
<td>{{ step.name }}</td>
<td>
<acl data="step.target"></acl>
</td>
<td>
<span ng-show="step.end_date">
{{ 'workflow_transition.' + step.transition | translate }}
{{ step.end_date | timeAgo: dateTimeFormat }}
by
<a href="#/user/{{ step.validator_username }}" class="label label-default">{{ step.validator_username }}</a>
<span ng-show="step.comment" class="text-">
<br/><em>{{ step.comment }}</em>
</span>
</span>
</td>
</tr>
</tbody>
</table>

View File

@@ -43,7 +43,7 @@
</div>
</div>
<div class="row">
<div class="col-xs-6">
<div class="col-xs-5">
<div class="input-group">
<span class="input-group-addon">
<span class="glyphicon glyphicon-transfer" ng-if="step.type == 'APPROVE'"></span>
@@ -63,6 +63,9 @@
typeahead-editable="false"
typeahead-wait-ms="200" />
</div>
<div class="col-xs-1">
<span class="btn btn-link glyphicon glyphicon-trash" ng-click="removeStep(step)"></span>
</div>
</div>
<div class="row mt-10">
<div class="col-xs-12" ng-class="{ 'has-error': !editWorkflowForm['name-' + $index].$valid && editWorkflowForm.$dirty }">