@fleetbase/fleetops-engine
Version:
Fleet & Transport Management Extension for Fleetbase
55 lines (49 loc) • 1.79 kB
JavaScript
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { task } from 'ember-concurrency';
export default class VehicleFormComponent extends Component {
store;
fetch;
currentUser;
notifications;
modalsManager;
statusOptions = ['available', 'pending'];
updateAvatarUrl(option) {
this.args.resource.avatar_url = option.key === 'custom_avatar' ? option.value : [option.value];
}
updateSelectedImage(url) {
this.args.resource.avatar_url = url;
}
assignDriver(driver) {
this.args.resource.driver = driver;
// trigger modified attributes via meta
const meta = this.args.resource.meta ?? {};
this.args.resource.meta = {
...meta,
};
}
*handlePhotoUpload(file) {
try {
yield this.fetch.uploadFile.perform(
file,
{
path: `uploads/${this.currentUser.companyId}/vehicles/${this.args.resource.id}`,
subject_uuid: this.args.resource.id,
subject_type: 'fleet-ops:vehicle',
type: 'vehicle_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);
}
}
}