Skip to content
Snippets Groups Projects
Verified Commit 05fc35e4 authored by Damien's avatar Damien
Browse files

[REFACTORING] actions + mode

parent 26470ee8
No related branches found
No related tags found
No related merge requests found
......@@ -25,24 +25,21 @@ VALUES ('SIGNATURE', 'Signatures utilisateurs', 'N', 50000000000, 0, '/opt/maarc
------------
TRUNCATE TABLE status;
ALTER SEQUENCE status_id_seq RESTART WITH 1;
INSERT INTO status (reference, label) VALUES ('ANNOT', 'Annotation');
INSERT INTO status (reference, label) VALUES ('SIGN', 'Parapheur');
INSERT INTO status (reference, label) VALUES ('VAL', 'Validé');
INSERT INTO status (reference, label) VALUES ('REF', 'Refusé');
INSERT INTO status (reference, label) VALUES ('SIGNED', 'Signé');
INSERT INTO status (reference, label) VALUES ('REFSIGNED', 'Signature refusée');
INSERT INTO status (id, reference, label) VALUES (1, 'NEW', 'En cours');
INSERT INTO status (id, reference, label) VALUES (2 ,'VAL', 'Validé');
INSERT INTO status (id, reference, label) VALUES (3, 'REF', 'Refusé');
------------
--ACTION
--ACTIONS
------------
TRUNCATE TABLE action;
ALTER SEQUENCE action_id_seq RESTART WITH 1;
INSERT INTO action (id, label, color, logo, event, previous_status_id, next_status_id) VALUES (1, 'Refuser signature', '#e74c3c', 'fas fa-backspace', 'openDialog', 2, 6);
INSERT INTO action (id, label, color, logo, event, previous_status_id, next_status_id) VALUES (2, 'Refuser', '#e74c3c', 'fas fa-backspace', 'openDialog', 1, 4);
INSERT INTO action (id, label, color, logo, event, previous_status_id, next_status_id) VALUES (3, 'Parapher', '#000', '', 'openDrawer', 2, null);
INSERT INTO action (id, label, color, logo, event, previous_status_id, next_status_id) VALUES (4, 'Annoter', '#2ecc71', '', 'openDrawer', 1, null);
INSERT INTO action (id, label, color, logo, event, previous_status_id, next_status_id) VALUES (5, 'Valider', '#2ecc71', 'fas fa-check-circle', 'confirmDialog', 1, 3);
INSERT INTO action (id, label, color, logo, event, previous_status_id, next_status_id) VALUES (6, 'Valider signature', '#2ecc71', 'fas fa-check-circle', 'confirmDialog', 2, 5);
TRUNCATE TABLE actions;
ALTER SEQUENCE actions_id_seq RESTART WITH 1;
INSERT INTO actions (id, label, color, logo, event, mode, next_status_id) VALUES (1, 'Refuser', '#e74c3c', 'fas fa-backspace', 'openDialog', 'SIGN', 6);
INSERT INTO actions (id, label, color, logo, event, mode, next_status_id) VALUES (2, 'Refuser', '#e74c3c', 'fas fa-backspace', 'openDialog', 'NOTE', 4);
INSERT INTO actions (id, label, color, logo, event, mode, next_status_id) VALUES (3, 'Parapher', '#000', '', 'openDrawer', 'SIGN', null);
INSERT INTO actions (id, label, color, logo, event, mode, next_status_id) VALUES (4, 'Annoter', '#2ecc71', '', 'openDrawer', 'NOTE', null);
INSERT INTO actions (id, label, color, logo, event, mode, next_status_id) VALUES (5, 'Valider', '#2ecc71', 'fas fa-check-circle', 'confirmDialog', 'SIGN', 3);
INSERT INTO actions (id, label, color, logo, event, mode, next_status_id) VALUES (6, 'Valider', '#2ecc71', 'fas fa-check-circle', 'confirmDialog', 'NOTE', 5);
-----
-- Password management
......
......@@ -14,8 +14,9 @@ DROP TABLE IF EXISTS main_documents;
CREATE TABLE main_documents
(
id serial NOT NULL,
reference CHARACTER VARYING(255),
reference CHARACTER VARYING(64),
subject text NOT NULL,
mode CHARACTER VARYING(16) NOT NULL,
status INTEGER NOT NULL,
processing_user INTEGER NOT NULL,
sender text NOT NULL,
......@@ -34,7 +35,7 @@ CREATE TABLE attachments
(
id serial NOT NULL,
main_document_id bigint NOT NULL,
reference character varying(255),
reference character varying(64),
subject text,
creation_date timestamp without time zone NOT NULL DEFAULT NOW(),
modification_date timestamp without time zone DEFAULT NOW(),
......@@ -53,17 +54,17 @@ CREATE TABLE status
)
WITH (OIDS=FALSE);
DROP TABLE IF EXISTS action;
CREATE TABLE action
DROP TABLE IF EXISTS actions;
CREATE TABLE actions
(
id serial,
label character varying(50) NOT NULL,
color character varying(50),
logo character varying(50),
event character varying(128),
previous_status_id bigint NOT NULL,
next_status_id bigint,
CONSTRAINT action_pkey PRIMARY KEY (id)
label character varying(64) NOT NULL,
color character varying(8) NOT NULL,
logo character varying(64),
event character varying(128) NOT NULL,
mode CHARACTER VARYING(16) NOT NULL,
next_status_id INTEGER,
CONSTRAINT actions_pkey PRIMARY KEY (id)
)
WITH (OIDS=FALSE);
......
......@@ -26,7 +26,7 @@ class ActionModel
$actions = DatabaseModel::select([
'select' => $aArgs['select'],
'table' => ['action'],
'table' => ['actions'],
'where' => empty($aArgs['where']) ? [] : $aArgs['where'],
'data' => empty($aArgs['data']) ? [] : $aArgs['data']
]);
......@@ -42,7 +42,7 @@ class ActionModel
$action = DatabaseModel::select([
'select' => $aArgs['select'],
'table' => ['action'],
'table' => ['actions'],
'where' => ['id = ?'],
'data' => [$aArgs['id']]
]);
......
......@@ -72,14 +72,6 @@ class DocumentController
return $response->withStatus(400)->withJson(['errors' => 'Document does not exist']);
}
$status = StatusModel::getById(['select' => ['label'], 'id' => $document['status']]);
$document['statusDisplay'] = $status['label'];
$actions = ActionModel::get(['select' => ['id', 'label', 'color', 'logo', 'event'], 'where' => ['previous_status_id = ?'], 'data' => [$document['status']]]);
$document['actionsAllowed'] = $actions;
$document['processingUserDisplay'] = UserModel::getLabelledUserById(['id' => $document['processing_user']]);
$adr = AdrModel::getDocumentsAdr([
'select' => ['path', 'filename', 'fingerprint'],
'where' => ['main_document_id = ?', 'type = ?'],
......@@ -103,6 +95,9 @@ class DocumentController
// }
$document['encodedDocument'] = base64_encode(file_get_contents($pathToDocument));
$document['statusDisplay'] = StatusModel::getById(['select' => ['label'], 'id' => $document['status']])['label'];
$document['actionsAllowed'] = ActionModel::get(['select' => ['id', 'label', 'color', 'logo', 'event'], 'where' => ['mode = ?'], 'data' => [$document['mode']]]);
$document['processingUserDisplay'] = UserModel::getLabelledUserById(['id' => $document['processing_user']]);
$document['attachments'] = AttachmentModel::getByDocumentId(['select' => ['id'], 'documentId' => $args['id']]);
return $response->withJson(['document' => $document]);
......@@ -115,7 +110,7 @@ class DocumentController
$check = DocumentController::controlData([
['type' => 'string', 'value' => $data['encodedZipDocument']],
['type' => 'string', 'value' => $data['subject']],
['type' => 'string', 'value' => $data['status']],
['type' => 'string', 'value' => $data['mode']],
['type' => 'int', 'value' => $data['processing_user']],
['type' => 'string', 'value' => $data['sender']],
]);
......@@ -146,7 +141,7 @@ class DocumentController
return $response->withStatus(500)->withJson(['errors' => $storeInfos['errors']]);
}
$status = StatusModel::get(['select' => ['id'], 'where' => ['reference = ?'], 'data' => [$data['status']]]);
$status = StatusModel::get(['select' => ['id'], 'where' => ['reference = ?'], 'data' => ['NEW']]);
$data['status'] = $status[0]['id'];
DatabaseModel::beginTransaction();
......@@ -295,9 +290,9 @@ class DocumentController
]);
DocumentModel::update([
'set' => ['status' => $action['next_status_id']],
'set' => ['status' => $action['next_status_id']],
'where' => ['id = ?'],
'data' => [$args['id']]
'data' => [$args['id']]
]);
HistoryController::add([
......@@ -348,12 +343,13 @@ class DocumentController
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$document = DocumentModel::getById(['select' => ['status'], 'id' => $args['id']]);
$document = DocumentModel::getById(['select' => ['status', 'mode'], 'id' => $args['id']]);
if (empty($document)) {
return $response->withStatus(400)->withJson(['errors' => 'Document does not exist']);
}
$status = StatusModel::getById(['select' => ['id', 'reference', 'label'], 'id' => $document['status']]);
$satus['mode'] = $document['mode'];
return $response->withJson(['status' => $status]);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment