UNPKG

@fleetbase/fleetops-engine

Version:

Fleet & Transport Management Extension for Fleetbase

49 lines (43 loc) 1.6 kB
import Component from '@glimmer/component'; import { action } from '@ember/object'; import { inject as service } from '@ember/service'; import { task } from 'ember-concurrency'; export default class DeviceFormComponent extends Component { @service fetch; @service currentUser; @service notifications; get isTelematicLocked() { const resource = this.args.resource; const hasTelematic = Boolean(resource?.telematic_uuid || resource?.telematic?.id); return Boolean(hasTelematic && resource?.isNew === false); } @action selectTelematic(telematic) { this.args.resource.setProperties({ telematic, telematic_uuid: telematic.id, provider: telematic.provider, }); } @task *handlePhotoUpload(file) { try { yield this.fetch.uploadFile.perform( file, { path: `uploads/${this.currentUser.companyId}/devices/${this.args.resource.id}`, subject_uuid: this.args.resource.id, subject_type: 'fleet-ops:device', type: 'device_photo', }, (uploadedFile) => { this.args.resource.setProperties({ photo_uuid: uploadedFile.id, photo_url: uploadedFile.url, photo: uploadedFile, }); } ); } catch (err) { this.notifications.error('Unable to upload photo: ' + err.message); } } }