@fleetbase/fleetops-engine
Version:
Fleet & Transport Management Extension for Fleetbase
49 lines (43 loc) • 1.6 kB
JavaScript
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 {
fetch;
currentUser;
notifications;
get isTelematicLocked() {
const resource = this.args.resource;
const hasTelematic = Boolean(resource?.telematic_uuid || resource?.telematic?.id);
return Boolean(hasTelematic && resource?.isNew === false);
}
selectTelematic(telematic) {
this.args.resource.setProperties({
telematic,
telematic_uuid: telematic.id,
provider: telematic.provider,
});
}
*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);
}
}
}