Skip to content

Commit

Permalink
Merge pull request #56 from fewieden/develop
Browse files Browse the repository at this point in the history
2.1.2
  • Loading branch information
fewieden authored Dec 28, 2020
2 parents ca15312 + 6e691de commit 82b2fa7
Show file tree
Hide file tree
Showing 11 changed files with 1,122 additions and 1,642 deletions.
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Thanks for contributing to this module!

Please create pull requests to the branch `develop`.

To hold one code style and standard there are several linters and tools in this project set. Make sure you fullfill the requirements.
Also there will be automatically analysis performed once you created the pull request.
To hold one code style and standard there are several linters and tools in this project set. Make sure you fulfill the requirements.
Also, there will be automatically analysis performed once you created the pull request.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: node_js
node_js:
- "stable"
- "8"
- "10"
- "12"
- "14"
script:
- npm run lint
cache:
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# MMM-Fuel Changelog

## [2.1.2]

### Added

* Config option `showDistance` https://github.com/fewieden/MMM-Fuel/pull/49
* Missing jsdoc documentation

### Changed

* Dependency update

### Fixed

* Deinit map had a harcoded index for markers.

## [2.1.1]

### Fixed
Expand Down
31 changes: 27 additions & 4 deletions MMM-Fuel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @see https://github.com/fewieden/MMM-Fuel
*/

/* global Module Log google */
/* global google */

/**
* @external Module
Expand All @@ -33,7 +33,6 @@
* @requires external:google
*/
Module.register('MMM-Fuel', {

/** @member {Object} units - Is used to determine the unit symbol of the global config option units. */
units: {
imperial: 'ml',
Expand Down Expand Up @@ -64,6 +63,7 @@ Module.register('MMM-Fuel', {
* @property {boolean|int} shortenText - Max characters to be shown for name and address.
* @property {boolean} showAddress - Flag to show the gas stations address.
* @property {boolean} showOpenOnly - Flag to show only open gas stations or all.
* @property {boolean} showDistance - Flag to show the distance to your specified position.
* @property {boolean} iconHeader - Flag to display the car icon in the header.
* @property {boolean} rotate - Flag to enable/disable rotation between sort by price and distance.
* @property {string[]} types - Fuel types to show.
Expand All @@ -85,6 +85,7 @@ Module.register('MMM-Fuel', {
shortenText: false,
showAddress: true,
showOpenOnly: false,
showDistance: true,
iconHeader: true,
rotate: true,
types: ['diesel'],
Expand Down Expand Up @@ -152,7 +153,7 @@ Module.register('MMM-Fuel', {
* @description Data that gets rendered in the nunjuck template.
* @override
*
* @returns {string} Data for the nunjuck template.
* @returns {Object} Data for the nunjuck template.
*/
getTemplateData() {
let gasStations;
Expand All @@ -175,6 +176,8 @@ Module.register('MMM-Fuel', {
* @description Appends Google Map script to the body, if the config option map_api_key is defined. Calls
* createInterval and sends the config to the node_helper.
* @override
*
* @returns {void}
*/
start() {
Log.info(`Starting module: ${this.name}`);
Expand All @@ -184,6 +187,11 @@ Module.register('MMM-Fuel', {
this.config.sortBy = this.config.types[0];
}

if (this.config.rotate && !this.config.showDistance) {
Log.error('Config option rotate does not work if distance is hidden! Falling back to no rotation.');
this.config.rotate = false;
}

this.addGlobals();
this.addFilters();
// Add script manually, getScripts doesn't work for it!
Expand All @@ -199,6 +207,7 @@ Module.register('MMM-Fuel', {
/**
* @function createInterval
* @description Creates an interval if config option rotate is set.
*
* @returns {?Interval} The Interval toggles sortByPrice between true and false.
*/
createInterval() {
Expand Down Expand Up @@ -304,6 +313,14 @@ Module.register('MMM-Fuel', {
}
},

/**
* @function initMap
* @description Initializes the map, markers and layers.
*
* @param {boolean} success - Only initialize the map if success is truthy.
*
* @returns {void}
*/
initMap(success) {
if (!success || this.map) {
return;
Expand Down Expand Up @@ -334,6 +351,12 @@ Module.register('MMM-Fuel', {
}
},

/**
* @function deinitMap
* @description Deinitializes the map, markers and layers.
*
* @returns {void}
*/
deinitMap() {
if (!this.map) {
return;
Expand All @@ -343,7 +366,7 @@ Module.register('MMM-Fuel', {
this.trafficLayer = null;

for (let i = 0; i < this.markers.length; i += 1) {
this.markers[1].setMap(null);
this.markers[i].setMap(null);
}

this.markers = [];
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Gas Station Price Module for MagicMirror<sup>2</sup>
| `shortenText` | `false` | Integer of characters to be shown for name and address. Default shows all. |
| `showAddress` | `true` | Boolean to show the gas stations address. |
| `showOpenOnly` | `false` | Boolean to show only open gas stations or all. |
| `showDistance` | `true` | Boolean to show the distance to your specified position. |
| `iconHeader` | `true` | Boolean to display the car icon in the header. |
| `rotate` | `true` | Boolean to enable/disable rotation between sort by price and distance. |
| `rotateInterval` | `60000` (1 min) | How fast the sorting should be switched between byPrice and byDistance. |
Expand All @@ -79,6 +80,7 @@ No API key required.

| **Option** | **Default** | **Description** |
| --- | --- | --- |
| `provider` | `"tankerkoenig"` | Make sure you set it to `"spritpreisrechner"`. |
| `types` | `["diesel"]` | Valid options are `diesel`, `e5` and `gas`. |
| `radius` | `5` | Valid range not tested yet. |
| `max` | `5` | The API provider returns maximum of 5 valid datasets. |
Expand All @@ -91,6 +93,7 @@ Config options should be set accordingly `open`: false and `showOpenOnly`: false
| **Option** | **Default** | **Description** |
| --- | --- | --- |
| `api_key` | REQUIRED | Get an API key for free access to the data of [api.nsw](https://api.nsw.gov.au/). |
| `provider` | `"tankerkoenig"` | Make sure you set it to `"nsw"`. |
| `secret` | REQUIRED | You also need to add the secret visible in your dashboard on [api.nsw](https://api.nsw.gov.au/). |
| `types` | `["diesel"]` | Valid options are `diesel`, `e5`. |
| `radius` | `5` | Valid range not tested yet. |
Expand Down
2 changes: 2 additions & 0 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module.exports = NodeHelper.create({
* @function start
* @description Logs a start message to the console.
* @override
*
* @returns {void}
*/
start() {
console.log(`Starting module helper: ${this.name}`);
Expand Down
Loading

0 comments on commit 82b2fa7

Please sign in to comment.