Skip to content

Commit

Permalink
Consolidate last_reading_at in timeUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
oscgonfer committed Feb 28, 2024
1 parent 4067148 commit 8a67d03
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/app/core/constructors/device/device.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';

angular.module('app.components')
.factory('Device', ['deviceUtils', function(deviceUtils) {
.factory('Device', ['deviceUtils', 'timeUtils', function(deviceUtils, timeUtils) {

/**
* Device constructor.
Expand Down Expand Up @@ -39,9 +39,9 @@
this.userTags = deviceUtils.parseUserTags(object);
this.isPrivate = deviceUtils.isPrivate(object);
this.notifications = deviceUtils.parseNotifications(object);
this.lastReadingAt = deviceUtils.parseDate(object.last_reading_at);
this.createdAt = deviceUtils.parseDate(object.created_at);
this.updatedAt = deviceUtils.parseDate(object.updated_at);
this.lastReadingAt = timeUtils.parseDate(object.last_reading_at);
this.createdAt = timeUtils.parseDate(object.created_at);
this.updatedAt = timeUtils.parseDate(object.updated_at);

// Location
this.location = object.location;
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/constructors/marker/marker.constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';

angular.module('app.components')
.factory('Marker', ['deviceUtils', 'markerUtils', '$state', function(deviceUtils, markerUtils, $state) {
.factory('Marker', ['deviceUtils', 'markerUtils', 'timeUtils', '$state', function(deviceUtils, markerUtils, timeUtils, $state) {
/**
* Marker constructor
* @constructor
Expand Down Expand Up @@ -31,7 +31,7 @@
deviceUtils.parseHardwareName(deviceData) +
'</p><p class="popup_time"><md-icon class="popup_icon" ' +
'md-svg-src="./assets/images/update_icon.svg"></md-icon>' +
deviceUtils.parseLastReadingAt(deviceData, true) + '</p>' + linkEnd + '</div>' +
timeUtils.parseDate(deviceData.last_reading_at).ago + '</p>' + linkEnd + '</div>' +
'<div class="popup_bottom"><p class="popup_location">' +
'<md-icon class="popup_icon" ' +
'md-svg-src="./assets/images/location_icon_dark.svg"></md-icon>' +
Expand Down
15 changes: 0 additions & 15 deletions src/app/core/utils/deviceUtils.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
parseUserTags: parseUserTags,
classify: classify,
parseNotifications: parseNotifications,
parseLastReadingAt: parseLastReadingAt,
parseOwner: parseOwner,
parseName: parseName,
parseString: parseString,
Expand Down Expand Up @@ -97,20 +96,6 @@
return object.name;
}

function parseLastReadingAt(object, fromNow=false) {
var time = object.last_reading_at;
if(!time) {
if (fromNow) {
return 'No time'
}
return;
}
if(fromNow){
return moment(time).fromNow();
}
return time;
}

function parseHardware(object) {
if (!object.hardware) {
return;
Expand Down

0 comments on commit 8a67d03

Please sign in to comment.