Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.1.7 #25

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions addon/models/place.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { computed, get } from '@ember/object';
import { not } from '@ember/object/computed';
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';
import isValidCoordinates from '@fleetbase/ember-core/utils/is-valid-coordinates';
import extractCoordinates from '@fleetbase/ember-core/utils/extract-coordinates';

export default class PlaceModel extends Model {
/** @ids */
Expand Down Expand Up @@ -85,19 +84,6 @@ export default class PlaceModel extends Model {
return [get(this, 'latitude'), get(this, 'longitude')];
}

@computed('coordinates') get extractedCoordinates() {
return extractCoordinates(this.coordinates);
}

@computed('extractedCoordinates') get extractedLatLng() {
const [latitude, longitude] = this.extractedCoordinates;

return {
lat: latitude,
lng: longitude,
};
}

@computed('latitude', 'longitude') get latlng() {
return {
// eslint-disable-next-line ember/no-get
Expand Down
21 changes: 6 additions & 15 deletions addon/models/service-area.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Model, { attr, hasMany } from '@ember-data/model';
import { computed } from '@ember/object';
import { format as formatDate, isValid as isValidDate, formatDistanceToNow } from 'date-fns';
import extractCoordinates from '@fleetbase/ember-core/utils/extract-coordinates';
import getWithDefault from '@fleetbase/ember-core/utils/get-with-default';
import first from '@fleetbase/ember-core/utils/first';

Expand All @@ -22,6 +21,7 @@ export default class ServiceAreaModel extends Model {
@attr('string') stroke_color;
@attr('string') status;
@attr('multi-polygon') border;
@attr('point') center;

/** @dates */
@attr('date') deleted_at;
Expand All @@ -34,26 +34,17 @@ export default class ServiceAreaModel extends Model {
const coordinates = getWithDefault(polygon, 'coordinates', []);
const bounds = first(coordinates);

return bounds.map((coord) => extractCoordinates(coord));
return bounds.map((coord) => {
let [longitude, latitude] = coord;

return [latitude, longitude];
});
}

@computed('border.coordinates.[]') get boundaries() {
return getWithDefault(this.border, 'coordinates', []);
}

@computed('bounds') get firstCoordinatePair() {
return first(this.bounds) ?? [0, 0];
}

@computed('bounds') get centerCoordinates() {
const x = this.bounds.map((xy) => xy[0]);
const y = this.bounds.map((xy) => xy[1]);
const cx = (Math.min(...x) + Math.max(...x)) / 2;
const cy = (Math.min(...y) + Math.max(...y)) / 2;

return [cx, cy];
}

@computed('updated_at') get updatedAgo() {
if (!isValidDate(this.updated_at)) {
return null;
Expand Down
49 changes: 20 additions & 29 deletions addon/models/zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,33 @@ export default class ZoneModel extends Model {
@attr('string') stroke_color;
@attr('string') status;
@attr('polygon') border;
@attr('array') coordinates;
@attr('point') center;

/** @dates */
@attr('date') deleted_at;
@attr('date') created_at;
@attr('date') updated_at;

/** @computed */
@computed('border.coordinates', 'isNew') get locations() {
let coordinates = getWithDefault(this.border, 'coordinates', []);
let isCoordinatesWrapped = isArray(coordinates) && isArray(coordinates[0]) && coordinates[0].length > 2;
// hotfix patch when coordinates are wrapped in array
if (isCoordinatesWrapped) {
coordinates = first(coordinates);
}

if (this.isNew) {
return coordinates;
}

return coordinates.map((coord) => {
let [longitude, latitude] = coord;

return [latitude, longitude];
});
}

@computed('updated_at') get updatedAgo() {
if (!isValidDate(this.updated_at)) {
return null;
Expand Down Expand Up @@ -69,32 +88,4 @@ export default class ZoneModel extends Model {
}
return formatDate(this.created_at, 'PP');
}

@computed('border.coordinates', 'isNew') get locations() {
let coordinates = getWithDefault(this.border, 'coordinates', []);

// hotfix patch when coordinates are wrapped in array
if (isArray(coordinates) && isArray(coordinates[0]) && coordinates[0].length > 2) {
coordinates = first(coordinates);
}

if (this.isNew) {
return coordinates;
}

return coordinates.map((coord) => coord.reverse());
}

@computed('bounds') get firstCoordinatePair() {
return first(this.bounds) ?? [0, 0];
}

@computed('locations') get centerCoordinates() {
const x = this.locations.map((xy) => xy[0]);
const y = this.locations.map((xy) => xy[1]);
const cx = (Math.min(...x) + Math.max(...x)) / 2;
const cy = (Math.min(...y) + Math.max(...y)) / 2;

return [cx, cy];
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/fleetops-data",
"version": "0.1.6",
"version": "0.1.7",
"description": "Fleetbase Fleet-Ops based models, serializers, transforms, adapters and GeoJson utility functions.",
"keywords": [
"fleetbase-data",
Expand Down
Loading