From 876eee04599a64b7950b2f599254d16158b99389 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Mon, 3 Jun 2024 18:38:29 +0800 Subject: [PATCH 01/12] created get api --- .../operations/orders/index/view.js | 24 +++++++++++++++++++ .../operations/orders/index/view.hbs | 3 +++ .../Internal/v1/ProofController.php | 14 +++++++++++ server/src/routes.php | 6 ++++- 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/addon/controllers/operations/orders/index/view.js b/addon/controllers/operations/orders/index/view.js index 5c8de1fc..6a157e81 100644 --- a/addon/controllers/operations/orders/index/view.js +++ b/addon/controllers/operations/orders/index/view.js @@ -842,6 +842,30 @@ export default class OperationsOrdersIndexViewController extends BaseController fileReader.readAsDataURL(blob); } + /** + * View proof label + */ + @action async viewProofLabel() { + // render dialog to display label within + + + // load the pdf label from base64 + // eslint-disable-next-line no-undef + const fileReader = new FileReader(); + const image = await this.fetch.get('drivers/query').then((res) => res.raw_data); + + 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); + } + /** * Reloads tracking activity for this order. * diff --git a/addon/templates/operations/orders/index/view.hbs b/addon/templates/operations/orders/index/view.hbs index 37225500..cd19a3a3 100644 --- a/addon/templates/operations/orders/index/view.hbs +++ b/addon/templates/operations/orders/index/view.hbs @@ -280,6 +280,9 @@
{{t "fleet-ops.operations.orders.index.view.proof-of-delivery"}}
{{n-a (smart-humanize @model.pod_method)}}
+
+ {{@model.public_id}} +
{{/if}} diff --git a/server/src/Http/Controllers/Internal/v1/ProofController.php b/server/src/Http/Controllers/Internal/v1/ProofController.php index 5cd1a65e..83c9cf33 100644 --- a/server/src/Http/Controllers/Internal/v1/ProofController.php +++ b/server/src/Http/Controllers/Internal/v1/ProofController.php @@ -136,4 +136,18 @@ public function captureSignature(string $publicId, Request $request) 'proof' => $proof->public_id, ]); } + + /** + * get proof code. + * + * @return void + */ + public function getProof() + { + $proof = Proof::all()->map(function ($data) { + return $data->toArray(); + }); + return response()->json($proof); + } + } diff --git a/server/src/routes.php b/server/src/routes.php index 62c56a60..ee2c1f4f 100644 --- a/server/src/routes.php +++ b/server/src/routes.php @@ -365,7 +365,11 @@ function ($router, $controller) { $router->post('import', $controller('import'))->middleware([Spatie\ResponseCache\Middlewares\DoNotCacheResponse::class]); } ); - $router->fleetbaseRoutes('proofs'); + $router->fleetbaseRoutes( + 'proofs', + function ($router, $controller) { + $router->get('query', $controller('getProof'))->middleware([Spatie\ResponseCache\Middlewares\DoNotCacheResponse::class]); + }); $router->fleetbaseRoutes('purchase-rates'); $router->fleetbaseRoutes('routes'); $router->fleetbaseRoutes( From 994f78c03eeaba665590f20ae47cf305383261ea Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Tue, 4 Jun 2024 11:01:44 +0800 Subject: [PATCH 02/12] 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. From fe6f606afe03739823ae55dc2457d98d5284ef70 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Tue, 4 Jun 2024 15:46:21 +0800 Subject: [PATCH 03/12] fix width --- addon/templates/operations/orders/index/view.hbs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/templates/operations/orders/index/view.hbs b/addon/templates/operations/orders/index/view.hbs index 74b0859b..bf7df158 100644 --- a/addon/templates/operations/orders/index/view.hbs +++ b/addon/templates/operations/orders/index/view.hbs @@ -297,9 +297,9 @@
-
+
- {{@model.public_id}} + {{@model.public_id}}
From 3c583f6b19bd84013c178575bb6e677edf9eef48 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Wed, 5 Jun 2024 13:24:21 +0800 Subject: [PATCH 04/12] removed unused line --- addon/controllers/operations/orders/index/view.js | 1 - 1 file changed, 1 deletion(-) diff --git a/addon/controllers/operations/orders/index/view.js b/addon/controllers/operations/orders/index/view.js index 1ad5fda8..2a954f86 100644 --- a/addon/controllers/operations/orders/index/view.js +++ b/addon/controllers/operations/orders/index/view.js @@ -849,7 +849,6 @@ export default class OperationsOrdersIndexViewController extends BaseController */ @task *viewProofLabel(orderId) { // eslint-disable-next-line no-undef - const fileReader = new FileReader(); const image = yield this.fetch.get(`proofs/query/${orderId}`).then((res) => res[0]); this.proof = image; } From 5082dc7d8fe22ffa8e8d1b90307edba34d9cec27 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Wed, 5 Jun 2024 14:51:27 +0800 Subject: [PATCH 05/12] fixed proof request --- .../operations/orders/index/view.js | 2 +- .../operations/orders/index/view.hbs | 27 +++++-------------- .../Internal/v1/ProofController.php | 14 ---------- server/src/routes.php | 6 +---- 4 files changed, 9 insertions(+), 40 deletions(-) diff --git a/addon/controllers/operations/orders/index/view.js b/addon/controllers/operations/orders/index/view.js index 2a954f86..7b81adaa 100644 --- a/addon/controllers/operations/orders/index/view.js +++ b/addon/controllers/operations/orders/index/view.js @@ -849,7 +849,7 @@ export default class OperationsOrdersIndexViewController extends BaseController */ @task *viewProofLabel(orderId) { // eslint-disable-next-line no-undef - const image = yield this.fetch.get(`proofs/query/${orderId}`).then((res) => res[0]); + const image = yield this.fetch.get('proofs', { subject_uuid: orderId }); this.proof = image; } diff --git a/addon/templates/operations/orders/index/view.hbs b/addon/templates/operations/orders/index/view.hbs index bf7df158..7a2f8ee2 100644 --- a/addon/templates/operations/orders/index/view.hbs +++ b/addon/templates/operations/orders/index/view.hbs @@ -280,31 +280,18 @@
{{t "fleet-ops.operations.orders.index.view.proof-of-delivery"}}
{{n-a (smart-humanize @model.pod_method)}}
+ {{#if this.proof}} +
+ +
+ {{/if}}
{{/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 d4d15f68..5cd1a65e 100644 --- a/server/src/Http/Controllers/Internal/v1/ProofController.php +++ b/server/src/Http/Controllers/Internal/v1/ProofController.php @@ -136,18 +136,4 @@ public function captureSignature(string $publicId, Request $request) 'proof' => $proof->public_id, ]); } - - /** - * get proof code. - * - * @return void - */ - public function getProof(Request $request, string $orderId) - { - $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 05f4691b..62c56a60 100644 --- a/server/src/routes.php +++ b/server/src/routes.php @@ -365,11 +365,7 @@ function ($router, $controller) { $router->post('import', $controller('import'))->middleware([Spatie\ResponseCache\Middlewares\DoNotCacheResponse::class]); } ); - $router->fleetbaseRoutes( - 'proofs', - function ($router, $controller) { - $router->get('query/{orderId}', $controller('getProof'))->middleware([Spatie\ResponseCache\Middlewares\DoNotCacheResponse::class]); - }); + $router->fleetbaseRoutes('proofs'); $router->fleetbaseRoutes('purchase-rates'); $router->fleetbaseRoutes('routes'); $router->fleetbaseRoutes( From 305e45f29905b678f304d6e9a131dfefdb255a72 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Wed, 5 Jun 2024 15:57:40 +0800 Subject: [PATCH 06/12] fixed image download --- addon/controllers/operations/orders/index/view.js | 8 ++++---- addon/templates/operations/orders/index/view.hbs | 8 +++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/addon/controllers/operations/orders/index/view.js b/addon/controllers/operations/orders/index/view.js index 7b81adaa..d80759eb 100644 --- a/addon/controllers/operations/orders/index/view.js +++ b/addon/controllers/operations/orders/index/view.js @@ -848,13 +848,13 @@ export default class OperationsOrdersIndexViewController extends BaseController * View proof label */ @task *viewProofLabel(orderId) { - // eslint-disable-next-line no-undef - const image = yield this.fetch.get('proofs', { subject_uuid: orderId }); - this.proof = image; + const response = yield this.fetch.get('proofs', { subject_uuid: orderId }); + const proofs = response.proofs; + this.proof = proofs[0]; } @action downloadImage() { - const base64Data = this.proof.raw_data; + const base64Data = this.proof.raw; const link = document.createElement('a'); link.href = base64Data; link.download = 'downloaded_image.png'; diff --git a/addon/templates/operations/orders/index/view.hbs b/addon/templates/operations/orders/index/view.hbs index 7a2f8ee2..b906dce3 100644 --- a/addon/templates/operations/orders/index/view.hbs +++ b/addon/templates/operations/orders/index/view.hbs @@ -281,11 +281,9 @@
{{t "fleet-ops.operations.orders.index.view.proof-of-delivery"}}
{{n-a (smart-humanize @model.pod_method)}}
{{#if this.proof}} -
- -
+ {{/if}} {{/if}} From 8e1830f3253e4cfdf48622f10e674d5ec80970ff Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Wed, 5 Jun 2024 16:37:10 +0800 Subject: [PATCH 07/12] showed date --- addon/templates/operations/orders/index/view.hbs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addon/templates/operations/orders/index/view.hbs b/addon/templates/operations/orders/index/view.hbs index b906dce3..32ff5dd7 100644 --- a/addon/templates/operations/orders/index/view.hbs +++ b/addon/templates/operations/orders/index/view.hbs @@ -280,10 +280,12 @@
{{t "fleet-ops.operations.orders.index.view.proof-of-delivery"}}
{{n-a (smart-humanize @model.pod_method)}}
- {{#if this.proof}} + {{#if this.proof.raw}} + {{else}} +
{{format-date this.proof.created_at "d MMM yyyy"}}
{{/if}}
{{/if}} From 560ed05b680bbc49d37b41e22e10ba8e6a790400 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Wed, 5 Jun 2024 18:16:21 +0800 Subject: [PATCH 08/12] checked waypoint --- .../operations/orders/index/view.hbs | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/addon/templates/operations/orders/index/view.hbs b/addon/templates/operations/orders/index/view.hbs index 32ff5dd7..993300f9 100644 --- a/addon/templates/operations/orders/index/view.hbs +++ b/addon/templates/operations/orders/index/view.hbs @@ -280,12 +280,33 @@
{{t "fleet-ops.operations.orders.index.view.proof-of-delivery"}}
{{n-a (smart-humanize @model.pod_method)}}
- {{#if this.proof.raw}} - + {{#if this.isMultiDropOrder}} + {{#each this.waypoints as |waypoint|}} +
+
{{format-date waypoint.proof.created_at "d MMM yyyy"}}
+ {{#if waypoint.proof.raw}} + + {{else}} +
{{format-date waypoint.proof.created_at "d MMM yyyy"}}
+ {{/if}} +
+ {{/each}} {{else}} -
{{format-date this.proof.created_at "d MMM yyyy"}}
+
{{format-date this.proof.created_at "d MMM yyyy"}}
+ {{#if this.proof.raw}} + + {{else}} +
{{format-date this.proof.created_at "d MMM yyyy"}}
+ {{/if}} {{/if}}
{{/if}} From c52f905f822f34e6497eb96ee5feda48bcecfc10 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Thu, 6 Jun 2024 11:17:29 +0800 Subject: [PATCH 09/12] checked pod download --- .../operations/orders/index/view.js | 10 +++---- .../operations/orders/index/view.hbs | 29 ++++--------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/addon/controllers/operations/orders/index/view.js b/addon/controllers/operations/orders/index/view.js index d80759eb..03eb4f93 100644 --- a/addon/controllers/operations/orders/index/view.js +++ b/addon/controllers/operations/orders/index/view.js @@ -116,7 +116,7 @@ export default class OperationsOrdersIndexViewController extends BaseController @tracked commentInput = ''; @tracked customFieldGroups = []; @tracked customFields = []; - @tracked proof; + @tracked proofs; @tracked uploadQueue = []; acceptedFileTypes = [ 'application/vnd.ms-excel', @@ -849,12 +849,12 @@ export default class OperationsOrdersIndexViewController extends BaseController */ @task *viewProofLabel(orderId) { const response = yield this.fetch.get('proofs', { subject_uuid: orderId }); - const proofs = response.proofs; - this.proof = proofs[0]; + + this.proofs = response.proofs; } - @action downloadImage() { - const base64Data = this.proof.raw; + @action downloadImage(proof) { + const base64Data = proof.raw; const link = document.createElement('a'); link.href = base64Data; link.download = 'downloaded_image.png'; diff --git a/addon/templates/operations/orders/index/view.hbs b/addon/templates/operations/orders/index/view.hbs index 993300f9..6e696ec7 100644 --- a/addon/templates/operations/orders/index/view.hbs +++ b/addon/templates/operations/orders/index/view.hbs @@ -280,31 +280,14 @@
{{t "fleet-ops.operations.orders.index.view.proof-of-delivery"}}
{{n-a (smart-humanize @model.pod_method)}}
- {{#if this.isMultiDropOrder}} - {{#each this.waypoints as |waypoint|}} -
-
{{format-date waypoint.proof.created_at "d MMM yyyy"}}
- {{#if waypoint.proof.raw}} - - {{else}} -
{{format-date waypoint.proof.created_at "d MMM yyyy"}}
- {{/if}} -
- {{/each}} - {{else}} -
{{format-date this.proof.created_at "d MMM yyyy"}}
- {{#if this.proof.raw}} - - {{else}} + {{/each}} + {{else}} + {{#if this.proof.created_at}}
{{format-date this.proof.created_at "d MMM yyyy"}}
{{/if}} {{/if}} From 97ea92d4afa073bd89b3d75669c40d472baaad24 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Thu, 6 Jun 2024 11:29:29 +0800 Subject: [PATCH 10/12] showed download when pic, sign --- addon/templates/operations/orders/index/view.hbs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/addon/templates/operations/orders/index/view.hbs b/addon/templates/operations/orders/index/view.hbs index 6e696ec7..1b1069af 100644 --- a/addon/templates/operations/orders/index/view.hbs +++ b/addon/templates/operations/orders/index/view.hbs @@ -282,14 +282,15 @@
{{n-a (smart-humanize @model.pod_method)}}
{{#if this.proofs}} {{#each this.proofs as |proof|}} - + {{#if proof.raw}} + + {{else}} +
{{format-date proof.created_at "d MMM yyyy"}}
+ + {{/if}} {{/each}} - {{else}} - {{#if this.proof.created_at}} -
{{format-date this.proof.created_at "d MMM yyyy"}}
- {{/if}} {{/if}}
{{/if}} From 076f9ec6c0bb85d26d879f422094bbf7c440693f Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Thu, 6 Jun 2024 11:30:55 +0800 Subject: [PATCH 11/12] removd space --- addon/controllers/operations/orders/index/view.js | 1 - 1 file changed, 1 deletion(-) diff --git a/addon/controllers/operations/orders/index/view.js b/addon/controllers/operations/orders/index/view.js index 03eb4f93..65ed286a 100644 --- a/addon/controllers/operations/orders/index/view.js +++ b/addon/controllers/operations/orders/index/view.js @@ -849,7 +849,6 @@ export default class OperationsOrdersIndexViewController extends BaseController */ @task *viewProofLabel(orderId) { const response = yield this.fetch.get('proofs', { subject_uuid: orderId }); - this.proofs = response.proofs; } From 89d920ece49be74cf68787a10fe3ecaf8dd70483 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Tue, 18 Jun 2024 10:07:13 +0800 Subject: [PATCH 12/12] need to review further and test more later --- addon/controllers/operations/orders/index/view.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addon/controllers/operations/orders/index/view.js b/addon/controllers/operations/orders/index/view.js index 1ad5fda8..bacb560e 100644 --- a/addon/controllers/operations/orders/index/view.js +++ b/addon/controllers/operations/orders/index/view.js @@ -848,10 +848,14 @@ export default class OperationsOrdersIndexViewController extends BaseController * View proof label */ @task *viewProofLabel(orderId) { + console.log('[viewProofLabel]', orderId); // eslint-disable-next-line no-undef const fileReader = new FileReader(); - const image = yield this.fetch.get(`proofs/query/${orderId}`).then((res) => res[0]); - this.proof = image; + try { + this.proof = yield this.fetch.get(`proofs/query/${orderId}`).then((res) => res[0]); + } catch (error) { + console.log(error); + } } @action downloadImage() {