Skip to content

Commit

Permalink
available to download pod
Browse files Browse the repository at this point in the history
  • Loading branch information
doljko committed Jun 4, 2024
1 parent 876eee0 commit 994f78c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
30 changes: 14 additions & 16 deletions addon/controllers/operations/orders/index/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
23 changes: 20 additions & 3 deletions addon/templates/operations/orders/index/view.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,31 @@
<div class="field-info-container space-y-2">
<div class="field-name">{{t "fleet-ops.operations.orders.index.view.proof-of-delivery"}}</div>
<div class="field-value">{{n-a (smart-humanize @model.pod_method)}}</div>
<div class="p-2 rounded-md bg-white">
<img src={{concat "data:image/png;base64," @model.pod_required.raw_data}} class="w-18 h-18" alt={{@model.public_id}} />
</div>
</div>
{{/if}}
</div>
</ContentPanel>

{{#if this.proof}}
<ContentPanel
@title={{t "fleet-ops.operations.orders.index.view.proof-of-delivery"}}
@prefixTitleRight={{@model.pod_method}}
@isLoading={{not this.loadOrderRelations.isIdle}}
@open={{true}}
@pad={{true}}
@panelBodyClass="bg-white dark:bg-gray-800"
>
<div class="mb-4 flex justify-end">
<Button @size="xs" @type="default" {{on "click" this.downloadImage}}>{{t "fleet-ops.operations.orders.index.view.download"}}</Button>
</div>
<div class="flex flex-row ml-6">
<div class="p-2 rounded-md bg-white">
<img src={{this.proof.raw_data}} class="w-40 h-16" alt={{@model.public_id}} />
</div>
</div>
</ContentPanel>
{{/if}}

{{#if @model.order_config}}
{{#each this.customFieldGroups as |group|}}
<ContentPanel @title={{group.name}} @open={{true}} @pad={{true}} @panelBodyClass="bg-white dark:bg-gray-800">
Expand Down
6 changes: 3 additions & 3 deletions server/src/Http/Controllers/Internal/v1/ProofController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
2 changes: 1 addition & 1 deletion server/src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 994f78c

Please sign in to comment.