diff --git a/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php b/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php index afb91cb23e..7fcddb0b28 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/LazaretController.php @@ -70,7 +70,7 @@ class LazaretController extends Controller public function getElement($file_id) { $ret = ['success' => false, 'message' => '', 'result' => []]; - + /* @var LazaretFile $lazaretFile */ $lazaretFile = $this->getLazaretFileRepository()->find($file_id); @@ -126,6 +126,16 @@ class LazaretController extends Controller $ret = $lazaretManipulator->add($file_id, $keepAttributes, $attributesToKeep); + try{ + // get the new record + $record = \Collection::getByBaseId($this->app, $request->request->get('bas_id'))->get_databox()->get_record($ret['result']['record_id']); + $postStatus = (array) $request->request->get('status'); + // update status + $this->updateRecordStatus($record, $postStatus); + }catch(\Exception $e){ + $ret['message'] = $this->app->trans('An error occured when wanting to change status!'); + } + return $this->app->json($ret); } @@ -216,6 +226,7 @@ class LazaretController extends Controller return $this->app->json($ret); } + $postStatus = (array) $request->request->get('status'); $path = $this->app['tmp.lazaret.path'] . '/'; $lazaretFileName = $path .$lazaretFile->getFilename(); @@ -233,6 +244,9 @@ class LazaretController extends Controller '' ); + // update status + $this->updateRecordStatus($record, $postStatus); + //Delete lazaret file $manager = $this->getEntityManager(); $manager->remove($lazaretFile); @@ -278,6 +292,35 @@ class LazaretController extends Controller ); } + /** + * @param Request $request + * @param $databox_id + * @param $record_id + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + public function getDestinationStatus(Request $request, $databox_id, $record_id) + { + if (!$request->isXmlHttpRequest()) { + $this->app->abort(400); + } + $record = new \record_adapter($this->app, (int) $databox_id, (int) $record_id); + $databox = $this->findDataboxById($databox_id); + $statusStructure = $databox->getStatusStructure(); + $recordsStatuses = []; + foreach ($statusStructure as $status) { + // make the key as a string for the json usage in javascript + $bit = "'".$status['bit']."'"; + if (!isset($recordsStatuses[$bit])) { + $recordsStatuses[$bit] = $status; + } + $statusSet = \databox_status::bitIsSet($record->getStatusBitField(), $status['bit']); + if (!isset($recordsStatuses[$bit]['flag'])) { + $recordsStatuses[$bit]['flag'] = (int) $statusSet; + } + } + return $this->app->json(['status' => $recordsStatuses]); + } + /** * @return LazaretFileRepository */ @@ -293,4 +336,32 @@ class LazaretController extends Controller { return $this->app['border-manager']; } + + /** + * Set new status to selected record + * + * @param \record_adapter $record + * @param array $postStatus + * @return array|null + */ + private function updateRecordStatus(\record_adapter $record, array $postStatus) + { + $sbasId = $record->getDataboxId(); + if (isset($postStatus[$sbasId]) && is_array($postStatus[$sbasId])) { + $postStatus = $postStatus[$sbasId]; + $currentStatus = strrev($record->getStatus()); + $newStatus = ''; + foreach (range(0, 31) as $i) { + $newStatus .= isset($postStatus[$i]) ? ($postStatus[$i] ? '1' : '0') : $currentStatus[$i]; + } + $record->setStatus(strrev($newStatus)); + $this->getDataboxLogger($record->getDatabox()) + ->log($record, \Session_Logger::EVENT_STATUS, '', ''); + return [ + 'current_status' => $currentStatus, + 'new_status' => $newStatus, + ]; + } + return null; + } } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php index 16081d7f14..53c2804fce 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Prod/Lazaret.php @@ -82,6 +82,11 @@ class Lazaret implements ControllerProviderInterface, ServiceProviderInterface ->assert('file_id', '\d+') ->bind('lazaret_thumbnail'); + $controllers->get('/{databox_id}/{record_id}/status', 'controller.prod.lazaret:getDestinationStatus') + ->assert('databox_id', '\d+') + ->assert('record_id', '\d+') + ->bind('lazaret_destination_status'); + return $controllers; } } diff --git a/lib/Alchemy/Phrasea/Model/Entities/LazaretFile.php b/lib/Alchemy/Phrasea/Model/Entities/LazaretFile.php index 9355acc471..221027e28e 100644 --- a/lib/Alchemy/Phrasea/Model/Entities/LazaretFile.php +++ b/lib/Alchemy/Phrasea/Model/Entities/LazaretFile.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\Model\Entities; use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Border\Attribute\AttributeInterface; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; use \record_adapter; @@ -474,4 +475,32 @@ class LazaretFile return $merged; } + /** + * @param Application $app + * @return array|null + */ + public function getStatus(Application $app) + { + /**@var LazaretAttribute $atribute*/ + foreach ($this->attributes as $atribute) { + if ($atribute->getName() == AttributeInterface::NAME_STATUS) { + $databox = $this->getCollection($app)->get_databox(); + $statusStructure = $databox->getStatusStructure(); + $recordsStatuses = []; + foreach ($statusStructure as $status) { + $bit = $status['bit']; + if (!isset($recordsStatuses[$bit])) { + $recordsStatuses[$bit] = $status; + } + $statusSet = \databox_status::bitIsSet(bindec($atribute->getValue()), $bit); + if (!isset($recordsStatuses[$bit]['flag'])) { + $recordsStatuses[$bit]['flag'] = (int) $statusSet; + } + } + return $recordsStatuses; + } + } + return null; + } + } diff --git a/lib/Alchemy/Phrasea/Model/Manipulator/LazaretManipulator.php b/lib/Alchemy/Phrasea/Model/Manipulator/LazaretManipulator.php index fff97be4bd..3c86fe91e3 100644 --- a/lib/Alchemy/Phrasea/Model/Manipulator/LazaretManipulator.php +++ b/lib/Alchemy/Phrasea/Model/Manipulator/LazaretManipulator.php @@ -226,6 +226,8 @@ class LazaretManipulator $this->entityManager->remove($lazaretFile); $this->entityManager->flush(); + $ret['result']['record_id'] = $record->getRecordId(); + $ret['success'] = true; } catch (\Exception $e) { $ret['message'] = $this->app->trans('An error occured'); diff --git a/resources/www/common/images/icons/icon-right-arrow.svg b/resources/www/common/images/icons/icon-right-arrow.svg new file mode 100644 index 0000000000..c3fabe9a03 --- /dev/null +++ b/resources/www/common/images/icons/icon-right-arrow.svg @@ -0,0 +1,31 @@ + + + + 5609DDD5-6B9C-411B-B926-EEA284949013 + Created with sketchtool. + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/web/prod/upload/lazaret.html.twig b/templates/web/prod/upload/lazaret.html.twig index 29bad734c0..eb0c9f19d0 100644 --- a/templates/web/prod/upload/lazaret.html.twig +++ b/templates/web/prod/upload/lazaret.html.twig @@ -35,7 +35,7 @@ @@ -48,56 +48,56 @@ - {% macro lazaretElement(app, file) %} {% import "common/thumbnail.html.twig" as thumb %} {% set records = file.getRecordsToSubstitute(app, true) %}
+
{{ "Last uploaded version" | trans }}
@@ -369,11 +579,11 @@ {% if record_count > 0 %}
- {% if record_count <= 1 %} - {% trans %}A record matches the unique identifier :{% endtrans %} - {% else %} - {% trans with {'%record_count%' : record_count} %}%record_count% records match the unique identifier :{% endtrans %} - {% endif %} + {% if record_count <= 1 %} + {% trans %}A record matches the unique identifier :{% endtrans %} + {% else %} + {% trans with {'%record_count%' : record_count} %}%record_count% records match the unique identifier :{% endtrans %} + {% endif %}