Skip to content

Commit

Permalink
Merge pull request #36 from fleetbase/dev-v0.1.18
Browse files Browse the repository at this point in the history
fixed and added relations for vendor and contact, standardizes place …
  • Loading branch information
roncodes authored Oct 2, 2024
2 parents e385e8e + 9824e4f commit 748cb40
Show file tree
Hide file tree
Showing 20 changed files with 9,042 additions and 6,593 deletions.
8 changes: 6 additions & 2 deletions addon/models/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ export default class ContactModel extends Model {
/** @ids */
@attr('string') public_id;
@attr('string') company_uuid;
@attr('string') user_uuid;
@attr('string') photo_uuid;
@attr('string') place_uuid;
@attr('string') internal_id;

/** @relationships */
@belongsTo('file') photo;
@belongsTo('place') address;
@hasMany('place') addresses;
@belongsTo('user') user;
@belongsTo('place') place;
@hasMany('place') places;

/** @attributes */
@attr('string') name;
@attr('string') title;
@attr('string') email;
@attr('string') phone;
@attr('string') address;
@attr('string') address_street;
@attr('string') type;
@attr('string', {
defaultValue: 'https://s3.ap-southeast-1.amazonaws.com/flb-assets/static/no-avatar.png',
Expand Down
35 changes: 14 additions & 21 deletions addon/models/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { getOwner } from '@ember/application';
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';
import isRelationMissing from '@fleetbase/ember-core/utils/is-relation-missing';
import isValidCoordinates from '@fleetbase/ember-core/utils/is-valid-coordinates';
import isLatitude from '@fleetbase/ember-core/utils/is-latitude';
import isLongitude from '@fleetbase/ember-core/utils/is-longitude';
import config from 'ember-get-config';

export default class DriverModel extends Model {
Expand Down Expand Up @@ -123,33 +121,24 @@ export default class DriverModel extends Model {
return formatDate(this.created_at, 'dd, MMM');
}

@computed('location') get latitude() {
if (this.location) {
let x = get(this.location, 'coordinates.0');
let y = get(this.location, 'coordinates.1');

return isLatitude(x) ? x : y;
}

return 0;
}

@computed('location') get longitude() {
if (this.location) {
let x = get(this.location, 'coordinates.0');
let y = get(this.location, 'coordinates.1');

return isLongitude(y) ? y : x;
}
return get(this.location, 'coordinates.0');
}

return 0;
@computed('location') get latitude() {
return get(this.location, 'coordinates.1');
}

@computed('latitude', 'longitude') get coordinates() {
// eslint-disable-next-line ember/no-get
return [get(this, 'latitude'), get(this, 'longitude')];
}

@computed('latitude', 'longitude') get positionString() {
// eslint-disable-next-line ember/no-get
return `${get(this, 'latitude')} ${get(this, 'longitude')}`;
}

@computed('latitude', 'longitude') get latlng() {
return {
// eslint-disable-next-line ember/no-get
Expand All @@ -168,7 +157,11 @@ export default class DriverModel extends Model {
};
}

@computed('coordinates') get hasValidCoordinates() {
@computed('coordinates', 'latitude', 'longitude') get hasValidCoordinates() {
if (this.longitude === 0 || this.latitude === 0) {
return false;
}

return isValidCoordinates(this.coordinates);
}

Expand Down
Loading

0 comments on commit 748cb40

Please sign in to comment.