#159: workflow ui init

This commit is contained in:
Benjamin Gamard 2018-01-27 17:33:46 +01:00
parent 332ac9c109
commit 5f9094c540
8 changed files with 200 additions and 0 deletions

View File

@ -155,6 +155,33 @@ angular.module('docs',
}
}
})
.state('settings.workflow', {
url: '/workflow',
views: {
'settings': {
templateUrl: 'partial/docs/settings.workflow.html',
controller: 'SettingsWorkflow'
}
}
})
.state('settings.workflow.edit', {
url: '/edit/:id',
views: {
'workflow': {
templateUrl: 'partial/docs/settings.workflow.edit.html',
controller: 'SettingsWorkflowEdit'
}
}
})
.state('settings.workflow.add', {
url: '/add',
views: {
'workflow': {
templateUrl: 'partial/docs/settings.workflow.edit.html',
controller: 'SettingsWorkflowEdit'
}
}
})
.state('settings.group', {
url: '/group',
views: {

View File

@ -0,0 +1,27 @@
'use strict';
/**
* Settings workflow page controller.
*/
angular.module('docs').controller('SettingsWorkflow', function($scope, $state, Restangular) {
/**
* Load workflows from server.
*/
$scope.loadWorkflows = function() {
Restangular.one('routemodel').get({
sort_column: 1,
asc: true
}).then(function(data) {
$scope.workflows = data.workflows;
});
};
$scope.loadWorkflows();
/**
* Edit a user.
*/
$scope.editWorkflow = function(user) {
$state.go('settings.workflow.edit', { id: user.id });
};
});

View File

@ -0,0 +1,68 @@
'use strict';
/**
* Settings workflow edition page controller.
*/
angular.module('docs').controller('SettingsWorkflowEdit', function($scope, $dialog, $state, $stateParams, Restangular, $translate) {
/**
* Returns true if in edit mode (false in add mode).
*/
$scope.isEdit = function () {
return $stateParams.id;
};
/**
* In edit mode, load the current workflow.
*/
if ($scope.isEdit()) {
Restangular.one('routemodel', $stateParams.id).get().then(function (data) {
$scope.workflow = data;
});
}
/**
* Update the current workflow.
*/
$scope.edit = function () {
var promise = null;
var workflow = angular.copy($scope.workflow);
if ($scope.isEdit()) {
promise = Restangular
.one('routemodel', $stateParams.id)
.post('', workflow);
} else {
promise = Restangular
.one('routemodel')
.put(workflow);
}
promise.then(function () {
$scope.loadWorkflows();
$state.go('settings.workflow');
});
};
/**
* Delete the current workflow.
*/
$scope.remove = function () {
var title = $translate.instant('settings.workflow.edit.delete_workflow_title');
var msg = $translate.instant('settings.workflow.edit.delete_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('routemodel', $stateParams.id).remove().then(function () {
$scope.loadWorkflows();
$state.go('settings.workflow');
}, function() {
$state.go('settings.workflow');
});
}
});
};
});

View File

@ -74,6 +74,8 @@
<script src="app/docs/controller/settings/SettingsSecurityModalDisableTotp.js" type="text/javascript"></script>
<script src="app/docs/controller/settings/SettingsSession.js" type="text/javascript"></script>
<script src="app/docs/controller/settings/SettingsLog.js" type="text/javascript"></script>
<script src="app/docs/controller/settings/SettingsWorkflow.js" type="text/javascript"></script>
<script src="app/docs/controller/settings/SettingsWorkflowEdit.js" type="text/javascript"></script>
<script src="app/docs/controller/settings/SettingsUser.js" type="text/javascript"></script>
<script src="app/docs/controller/settings/SettingsUserEdit.js" type="text/javascript"></script>
<script src="app/docs/controller/settings/SettingsGroup.js" type="text/javascript"></script>

View File

@ -224,6 +224,7 @@
"menu_two_factor_auth": "Two-factor authentication",
"menu_opened_sessions": "Opened sessions",
"menu_general_settings": "General settings",
"menu_workflow": "Workflow",
"menu_users": "Users",
"menu_groups": "Groups",
"menu_vocabularies": "Vocabularies",
@ -255,6 +256,19 @@
"password_lost_sent_message": "A password reset email has been sent to <strong>{{ username }}</strong>"
}
},
"workflow": {
"title": "Workflow <small>configuration</small>",
"add_workflow": "Add a workflow",
"name": "Name",
"create_date": "Create date",
"edit": {
"delete_workflow_title": "Delete workflow",
"delete_workflow_message": "Do you really want to delete this workflow? Currently running workflows will not be deleted",
"edit_workflow_title": "<small>Edit</small> \"{{ name }}\"",
"add_workflow_title": "<small>Add a</small> workflow",
"name": "Name"
}
},
"security": {
"enable_totp": "Enable two-factor authentication",
"enable_totp_message": "Make sure you have a TOTP-compatible application on your phone ready to add a new account",

View File

@ -12,6 +12,7 @@
<div class="panel panel-default" ng-show="isAdmin">
<div class="panel-heading"><strong>{{ 'settings.menu_general_settings' | translate }}</strong></div>
<ul class="list-group">
<a class="list-group-item" ui-sref-active="{ active: 'settings.workflow.**' }" href="#/settings/workflow">{{ 'settings.menu_workflow' | translate }}</a>
<a class="list-group-item" ui-sref-active="{ active: 'settings.user.**' }" href="#/settings/user">{{ 'settings.menu_users' | translate }}</a>
<a class="list-group-item" ui-sref-active="{ active: 'settings.group.**' }" href="#/settings/group">{{ 'settings.menu_groups' | translate }}</a>
<a class="list-group-item" ui-sref-active="{ active: 'settings.vocabulary.**' }" href="#/settings/vocabulary">{{ 'settings.menu_vocabularies' | translate }}</a>

View File

@ -0,0 +1,33 @@
<img src="img/loader.gif" ng-show="!workflow && isEdit()" />
<div ng-show="workflow || !isEdit()">
<h2 ng-show="isEdit()" translate="settings.workflow.edit.edit_workflow_title" translate-values="{ name: workflow.name }"></h2>
<h2 ng-show="!isEdit()" translate="settings.workflow.edit.add_workflow_title"></h2>
<form class="form-horizontal" name="editWorkflowForm" novalidate>
<div class="form-group" ng-class="{ 'has-error': !editWorkflowForm.name.$valid && editWorkflowForm.$dirty, success: editWorkflowForm.name.$valid }">
<label class="col-sm-2 control-label" for="inputName">{{ 'settings.workflow.edit.name' | translate }}</label>
<div class="col-sm-7">
<input name="name" type="text" id="inputName" required ng-disabled="isEdit()" class="form-control"
ng-minlength="3" ng-maxlength="50" ng-attr-placeholder="{{ 'settings.workflow.edit.name' | translate }}" ng-model="workflow.name"/>
</div>
<div class="col-sm-3">
<span class="help-block" ng-show="editWorkflowForm.name.$error.required && editWorkflowForm.$dirty">{{ 'validation.required' | translate }}</span>
<span class="help-block" ng-show="editWorkflowForm.name.$error.minlength && editWorkflowForm.$dirty">{{ 'validation.too_short' | translate }}</span>
<span class="help-block" ng-show="editWorkflowForm.name.$error.maxlength && editWorkflowForm.$dirty">{{ 'validation.too_long' | translate }}</span>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary" ng-click="edit()" ng-disabled="!editWorkflowForm.$valid">
<span class="glyphicon glyphicon-pencil"></span> {{ isEdit() ? 'save' : 'add' | translate }}
</button>
<button type="button" class="btn btn-danger" ng-click="remove()" ng-show="isEdit()">
<span class="glyphicon glyphicon-trash"></span> {{ 'delete' | translate }}
</button>
</div>
</div>
</form>
</div>

View File

@ -0,0 +1,28 @@
<h1>
<span translate="settings.workflow.title"></span>
<a class="btn btn-primary" href="#/settings/workflow/add">{{ 'settings.workflow.add_workflow' | translate }}</a>
</h1>
<div class="row">
<div class="col-md-4 well">
<table class="table table-hover table-workflows">
<thead>
<tr>
<th>{{ 'settings.workflow.name' | translate }}</th>
<th>{{ 'settings.workflow.create_date' | translate }}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="workflow in workflows | orderBy: 'name'" ng-click="editWorkflow(workflow)"
ng-class="{ active: $stateParams.id == workflow.id }">
<td>{{ workflow.name }}</td>
<td>{{ workflow.create_date | date: dateFormat }}</td>
</tr>
</tbody>
</table>
</div>
<div class="col-md-8">
<div ui-view="workflow"></div>
</div>
</div>