Skip to content

Commit 748cb40

Browse files
authored
Merge pull request #36 from fleetbase/dev-v0.1.18
fixed and added relations for vendor and contact, standardizes place …
2 parents e385e8e + 9824e4f commit 748cb40

20 files changed

+9042
-6593
lines changed

addon/models/contact.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@ export default class ContactModel extends Model {
66
/** @ids */
77
@attr('string') public_id;
88
@attr('string') company_uuid;
9+
@attr('string') user_uuid;
910
@attr('string') photo_uuid;
1011
@attr('string') place_uuid;
1112
@attr('string') internal_id;
1213

1314
/** @relationships */
1415
@belongsTo('file') photo;
15-
@belongsTo('place') address;
16-
@hasMany('place') addresses;
16+
@belongsTo('user') user;
17+
@belongsTo('place') place;
18+
@hasMany('place') places;
1719

1820
/** @attributes */
1921
@attr('string') name;
2022
@attr('string') title;
2123
@attr('string') email;
2224
@attr('string') phone;
25+
@attr('string') address;
26+
@attr('string') address_street;
2327
@attr('string') type;
2428
@attr('string', {
2529
defaultValue: 'https://s3.ap-southeast-1.amazonaws.com/flb-assets/static/no-avatar.png',

addon/models/driver.js

+14-21
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { getOwner } from '@ember/application';
55
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';
66
import isRelationMissing from '@fleetbase/ember-core/utils/is-relation-missing';
77
import isValidCoordinates from '@fleetbase/ember-core/utils/is-valid-coordinates';
8-
import isLatitude from '@fleetbase/ember-core/utils/is-latitude';
9-
import isLongitude from '@fleetbase/ember-core/utils/is-longitude';
108
import config from 'ember-get-config';
119

1210
export default class DriverModel extends Model {
@@ -123,33 +121,24 @@ export default class DriverModel extends Model {
123121
return formatDate(this.created_at, 'dd, MMM');
124122
}
125123

126-
@computed('location') get latitude() {
127-
if (this.location) {
128-
let x = get(this.location, 'coordinates.0');
129-
let y = get(this.location, 'coordinates.1');
130-
131-
return isLatitude(x) ? x : y;
132-
}
133-
134-
return 0;
135-
}
136-
137124
@computed('location') get longitude() {
138-
if (this.location) {
139-
let x = get(this.location, 'coordinates.0');
140-
let y = get(this.location, 'coordinates.1');
141-
142-
return isLongitude(y) ? y : x;
143-
}
125+
return get(this.location, 'coordinates.0');
126+
}
144127

145-
return 0;
128+
@computed('location') get latitude() {
129+
return get(this.location, 'coordinates.1');
146130
}
147131

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

137+
@computed('latitude', 'longitude') get positionString() {
138+
// eslint-disable-next-line ember/no-get
139+
return `${get(this, 'latitude')} ${get(this, 'longitude')}`;
140+
}
141+
153142
@computed('latitude', 'longitude') get latlng() {
154143
return {
155144
// eslint-disable-next-line ember/no-get
@@ -168,7 +157,11 @@ export default class DriverModel extends Model {
168157
};
169158
}
170159

171-
@computed('coordinates') get hasValidCoordinates() {
160+
@computed('coordinates', 'latitude', 'longitude') get hasValidCoordinates() {
161+
if (this.longitude === 0 || this.latitude === 0) {
162+
return false;
163+
}
164+
172165
return isValidCoordinates(this.coordinates);
173166
}
174167

0 commit comments

Comments
 (0)