From 994f78c03eeaba665590f20ae47cf305383261ea Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Tue, 4 Jun 2024 11:01:44 +0800 Subject: [PATCH] available to download pod --- .../operations/orders/index/view.js | 30 +++++++++---------- .../operations/orders/index/view.hbs | 23 ++++++++++++-- .../Internal/v1/ProofController.php | 6 ++-- server/src/routes.php | 2 +- translations/en-us.yaml | 1 + 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/addon/controllers/operations/orders/index/view.js b/addon/controllers/operations/orders/index/view.js index 6a157e81..1ad5fda8 100644 --- a/addon/controllers/operations/orders/index/view.js +++ b/addon/controllers/operations/orders/index/view.js @@ -116,6 +116,7 @@ export default class OperationsOrdersIndexViewController extends BaseController @tracked commentInput = ''; @tracked customFieldGroups = []; @tracked customFields = []; + @tracked proof; @tracked uploadQueue = []; acceptedFileTypes = [ 'application/vnd.ms-excel', @@ -245,6 +246,7 @@ export default class OperationsOrdersIndexViewController extends BaseController yield order.loadPurchaseRate(); yield order.loadFiles(); this.loadCustomFields.perform(order); + this.viewProofLabel.perform(order.id); } /** @@ -845,25 +847,21 @@ export default class OperationsOrdersIndexViewController extends BaseController /** * View proof label */ - @action async viewProofLabel() { - // render dialog to display label within - - - // load the pdf label from base64 + @task *viewProofLabel(orderId) { // eslint-disable-next-line no-undef const fileReader = new FileReader(); - const image = await this.fetch.get('drivers/query').then((res) => res.raw_data); + const image = yield this.fetch.get(`proofs/query/${orderId}`).then((res) => res[0]); + this.proof = image; + } - console.log('image', JSON.stringify(image)); - // eslint-disable-next-line no-undef - const base64 = await fetch(`data:application/pdf;base64,${image}`); - const blob = await base64.blob(); - // load into file reader - fileReader.onload = (event) => { - const data = event.target.result; - // this.modalsManager.setOption('data', data); - }; - fileReader.readAsDataURL(blob); + @action downloadImage() { + const base64Data = this.proof.raw_data; + const link = document.createElement('a'); + link.href = base64Data; + link.download = 'downloaded_image.png'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); } /** diff --git a/addon/templates/operations/orders/index/view.hbs b/addon/templates/operations/orders/index/view.hbs index cd19a3a3..74b0859b 100644 --- a/addon/templates/operations/orders/index/view.hbs +++ b/addon/templates/operations/orders/index/view.hbs @@ -280,14 +280,31 @@
{{t "fleet-ops.operations.orders.index.view.proof-of-delivery"}}
{{n-a (smart-humanize @model.pod_method)}}
-
- {{@model.public_id}} -
{{/if}} + {{#if this.proof}} + +
+ +
+
+
+ {{@model.public_id}} +
+
+
+ {{/if}} + {{#if @model.order_config}} {{#each this.customFieldGroups as |group|}} diff --git a/server/src/Http/Controllers/Internal/v1/ProofController.php b/server/src/Http/Controllers/Internal/v1/ProofController.php index 83c9cf33..d4d15f68 100644 --- a/server/src/Http/Controllers/Internal/v1/ProofController.php +++ b/server/src/Http/Controllers/Internal/v1/ProofController.php @@ -142,12 +142,12 @@ public function captureSignature(string $publicId, Request $request) * * @return void */ - public function getProof() + public function getProof(Request $request, string $orderId) { - $proof = Proof::all()->map(function ($data) { + $proof = Proof::where('order_uuid', $orderId)->get()->map(function ($data) { return $data->toArray(); }); + return response()->json($proof); } - } diff --git a/server/src/routes.php b/server/src/routes.php index ee2c1f4f..05f4691b 100644 --- a/server/src/routes.php +++ b/server/src/routes.php @@ -368,7 +368,7 @@ function ($router, $controller) { $router->fleetbaseRoutes( 'proofs', function ($router, $controller) { - $router->get('query', $controller('getProof'))->middleware([Spatie\ResponseCache\Middlewares\DoNotCacheResponse::class]); + $router->get('query/{orderId}', $controller('getProof'))->middleware([Spatie\ResponseCache\Middlewares\DoNotCacheResponse::class]); }); $router->fleetbaseRoutes('purchase-rates'); $router->fleetbaseRoutes('routes'); diff --git a/translations/en-us.yaml b/translations/en-us.yaml index 17554497..dae96d28 100644 --- a/translations/en-us.yaml +++ b/translations/en-us.yaml @@ -1429,6 +1429,7 @@ fleet-ops: order-title: Order Label waypoint-title: Waypoint Label proof-of-delivery: Proof of Delivery + download: Download Image notes-placeholder: Enter order notes here.... save-order-note: Save Order Note order-notes-updated: Order notes updated.