From 983dda8ecf767b3040950a9d35d569db3fac4ca0 Mon Sep 17 00:00:00 2001 From: Doljinsuren Enkhbayar Date: Fri, 17 May 2024 17:56:31 +0800 Subject: [PATCH 01/29] WIP: Import of resource implementation --- addon/controllers/management/drivers/index.js | 53 +++++++++++++++++++ addon/templates/management/drivers/index.hbs | 1 + .../Internal/v1/DriverController.php | 38 +++++++++++++ server/src/Imports/VehicleExport.php | 18 +++++++ server/src/routes.php | 2 + translations/en-us.yaml | 4 ++ 6 files changed, 116 insertions(+) create mode 100644 server/src/Imports/VehicleExport.php diff --git a/addon/controllers/management/drivers/index.js b/addon/controllers/management/drivers/index.js index a7edc926..922812b7 100644 --- a/addon/controllers/management/drivers/index.js +++ b/addon/controllers/management/drivers/index.js @@ -36,6 +36,13 @@ export default class ManagementDriversIndexController extends BaseController { */ @service crud; + /** + * Inject the `modalsManager` service + * + * @var {Service} + */ + @service modalsManager; + /** * Inject the `driverActions` service * @@ -130,6 +137,10 @@ export default class ManagementDriversIndexController extends BaseController { */ @tracked sort = '-created_at'; + @tracked uploadQueue = []; + + @tracked isMultipleDropoffOrder = false; + /** * The filterable param `public_id` * @@ -207,6 +218,10 @@ export default class ManagementDriversIndexController extends BaseController { */ @tracked layout = 'table'; + @tracked payload = this.store.createRecord('payload'); + + @tracked isUploadingFile = false; + /** * True if the current layout style is grid. * @@ -441,6 +456,7 @@ export default class ManagementDriversIndexController extends BaseController { }, ]; + /** * The search task. * @@ -511,6 +527,43 @@ export default class ManagementDriversIndexController extends BaseController { this.crud.export('driver'); } + @action removeFile(file) { + return file.destroyRecord(); + } + + @action queueFile(file) { + // since we have dropzone and upload button within dropzone validate the file state first + // as this method can be called twice from both functions + if (['queued', 'failed', 'timed_out', 'aborted'].indexOf(file.state) === -1) { + return; + } + + // Queue and upload immediatley + this.uploadQueue.pushObject(file); + this.fetch.uploadFile.perform( + file, + { + path: 'uploads/fleet-ops/order-files', + type: 'order_file', + }, + (uploadedFile) => { + this.order.files.pushObject(uploadedFile); + this.uploadQueue.removeObject(file); + }, + () => { + this.uploadQueue.removeObject(file); + // remove file from queue + if (file.queue && typeof file.queue.remove === 'function') { + file.queue.remove(file); + } + } + ); + } + + @action import() { + this.crud.import('driver'); + } + /** * View a `driver` details in modal * diff --git a/addon/templates/management/drivers/index.hbs b/addon/templates/management/drivers/index.hbs index 91390c79..07ffbad0 100644 --- a/addon/templates/management/drivers/index.hbs +++ b/addon/templates/management/drivers/index.hbs @@ -28,6 +28,7 @@ {{/if}}