Skip to content

Commit

Permalink
GIT-72 express trains (#79)
Browse files Browse the repository at this point in the history
* GIT-72: feat(express): Add isExpress check

* GIT-72: bug(css): Fix alignment of express icon

* GIT-72: build(lint): add stylelint & prettier

* GIT-72: build(lint): update eslint

* docs(semver): patch bump
  • Loading branch information
Elaniobro authored Feb 24, 2022
1 parent 67a03e3 commit ccddc83
Show file tree
Hide file tree
Showing 7 changed files with 1,425 additions and 410 deletions.
22 changes: 22 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
root: true,
env: {
browser: true,
node: true,
},
parserOptions: {
requireConfigFile: false,
},
parser: '@babel/eslint-parser',
extends: ['prettier'],
plugins: ['prettier'],
// add your custom rules here
rules: {
'no-console': 'off',
'space-before-function-paren': 'off',
curly: 'off',
'arrow-parens': 'off',
'vue/html-self-closing': 'off',
'vue/singleline-html-element-content-newline': 'off',
},
}
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": false,
"arrowParens": "always",
"singleQuote": true,
"endOfLine":"auto"
}
31 changes: 27 additions & 4 deletions MMM-nyc-transit.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}

.mta__train {
color: #fff;
color: #ffffff;
height: 30px;
width: 30px;
border-radius: 50%;
Expand All @@ -35,6 +35,10 @@
text-align: left;
}

.mta__train--item-express {
margin: 3px 0;
}

.mta__train--marquee .mta__train--list {
list-style: none;
}
Expand All @@ -59,7 +63,7 @@
}

.mta__train--time {
color: #fff;
color: #ffffff;
}

.mta__train--line-a,
Expand All @@ -81,7 +85,7 @@

.mta__train--line-j,
.mta__train--line-z {
background: #963;
background: #996633;
}

.mta__train--line-l {
Expand All @@ -102,7 +106,7 @@
.mta__train--line-1,
.mta__train--line-2,
.mta__train--line-3 {
background: #ee352E
background: #ee352e
}

.mta__train--line-4,
Expand All @@ -111,6 +115,25 @@
background: #00933c;
}

.mta__train--line-express {
transform: rotate(45deg);
height: 20px;
width: 20px;
border-radius: 0;
margin: 0 17px 0 4px;
padding: 0 1px;
}

.mta__train--line-express .express {
transform: rotate(-45deg);
display: table-cell;
vertical-align: middle;
height: 20px;
width: 20px;
line-height: 0;
font-size: 18px;
}

.mta__train--line-7 {
background: #b933ad;
}
Expand Down
177 changes: 98 additions & 79 deletions MMM-nyc-transit.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Module.register('MMM-nyc-transit', { /*eslint-disable-line*/
// call back function for mutation observer
var callback = function (mutationsList, observer) { /*eslint-disable-line*/
// Use traditional 'for loops' for IE 11
for (let mutation of mutationsList) {
for (var mutation of mutationsList) {
if (mutation.type === 'childList') {
var trainTimes = document.querySelectorAll('.mta__train--time span')

Expand Down Expand Up @@ -125,33 +125,37 @@ Module.register('MMM-nyc-transit', { /*eslint-disable-line*/
for (var dKey in trainHashMap.downTown) {
var dHtml = ''
var downTownListItem = document.createElement('li')

dHtml = dHtml +
'<span class="mta mta__train mta__train--logo mta__train--line-' +
dKey.toLowerCase() +
'">' +
dKey +
'</span>' +
trainHashMap.downTown[dKey].dest +
'<span class="mta mta_train mta__train--time mta__train-time__' +
dKey.toLowerCase() +
'"> ' +
trainHashMap.downTown[dKey].time
.slice(0, 3)
.map(
(trainTime, i) =>
'<span data-walking-time=\'' +
trainHashMap.downTown[dKey].walkingTime +
'\' class=\'train-time__downTown-' +
dKey.toLowerCase() +
'--' +
i +
'\'> ' +
trainTime +
'min</span>'
) +
" </span>"; /*eslint-disable-line*/
downTownListItem.className = 'mta__train--item'
dHtml =
dHtml +
'<span class="mta mta__train mta__train--logo mta__train--line-' +
dKey.toLowerCase().split("")[0] +
" mta__train--line-" +
this.isExpress(dKey) +
'"><span class="' +
this.isExpress(dKey) +
'">' +
dKey.toLowerCase().split("")[0] +
"</span></span>" +
trainHashMap.downTown[dKey].dest +
'<span class="mta mta_train mta__train--time mta__train-time__' +
dKey.toLowerCase() +
'"> ' +
trainHashMap.downTown[dKey].time
.slice(0, 3)
.map(
(trainTime, i) =>
"<span data-walking-time='" +
trainHashMap.downTown[dKey].walkingTime +
"' class='train-time__downTown-" +
dKey.toLowerCase() +
"--" +
i +
"'> " +
trainTime +
"min</span>"
) +
" </span>"; /*eslint-disable-line*/
downTownListItem.className = 'mta__train--item mta__train--item-' + this.isExpress(dKey)
downTownListItem.innerHTML = dHtml

list.appendChild(downTownListItem)
Expand All @@ -175,33 +179,36 @@ Module.register('MMM-nyc-transit', { /*eslint-disable-line*/
var uHtml = ''
var upTownListItem = document.createElement('li')

uHtml = uHtml +
'<span class="mta mta__train mta__train--logo mta__train--line-' +
uKey.toLowerCase() +
'">' +
uKey +
'</span>' +
trainHashMap.upTown[uKey].dest +
'<span class="mta mta_train mta__train--time mta_train-time__' +
uKey.toLowerCase() +
'"> ' +
trainHashMap.upTown[uKey].time
.slice(0, 3)
.map(
(trainTime, i) =>
'<span data-walking-time=\'' +
trainHashMap.upTown[uKey].walkingTime +
'\' class=\'train-time__upTown-' +
uKey.toLowerCase() +
'--' +
i +
'\'> ' +
trainTime +
'min</span>'
) +
" </span>"; /*eslint-disable-line*/

upTownListItem.className = 'mta__train--item'
uHtml =
uHtml +
'<span class="mta mta__train mta__train--logo mta__train--line-' +
uKey.toLowerCase().split("")[0] +
" mta__train--line-" +
this.isExpress(uKey) +
'"><span class="' + this.isExpress(uKey) + '">' +
uKey.toLowerCase().split("")[0] +
"</span></span>" +
trainHashMap.upTown[uKey].dest +
'<span class="mta mta_train mta__train--time mta_train-time__' +
uKey.toLowerCase() +
'"> ' +
trainHashMap.upTown[uKey].time
.slice(0, 3)
.map(
(trainTime, i) =>
"<span data-walking-time='" +
trainHashMap.upTown[uKey].walkingTime +
"' class='train-time__upTown-" +
uKey.toLowerCase() +
"--" +
i +
"'> " +
trainTime +
"min</span>"
) +
" </span>"; /*eslint-disable-line*/

upTownListItem.className = 'mta__train--item mta__train--item-' + this.isExpress(uKey);
upTownListItem.innerHTML = uHtml

list.appendChild(upTownListItem)
Expand All @@ -221,11 +228,14 @@ Module.register('MMM-nyc-transit', { /*eslint-disable-line*/
var upMarHtml = ''
var upTownMarListItem = document.createElement('span')


upMarHtml = upMarHtml +
'<span class="mta mta__train mta__train--logo mta__train--line-' +
upTown[upMarKey].routeId.toLowerCase() +
'">' +
upTown[upMarKey].routeId.toLowerCase() +
upTown[upMarKey].routeId.toLowerCase().split("")[0] +
' mta__train--line-' + this.isExpress(upTown[upMarKey].routeId) + '">' +
'<span class="' + this.isExpress(upTown[upMarKey].routeId) + '">' +
upTown[upMarKey].routeId.toLowerCase().split("")[0] +
"</span></span>" +
'</span><span class=\'mta mta_train mta__train--time mta_train-time__\'' +
(parseFloat(upMarKey) + 4) +
'">' +
Expand Down Expand Up @@ -261,26 +271,33 @@ Module.register('MMM-nyc-transit', { /*eslint-disable-line*/
var downMarHtml = ''
var downTownMarListItem = document.createElement('span')

downMarHtml = downMarHtml +
'<span class="mta mta__train mta__train--logo mta__train--line-' +
downTown[downMarKey].routeId.toLowerCase() +
'">' +
downTown[downMarKey].routeId.toLowerCase() +
'</span><span class=\'mta mta_train mta__train--time mta_train-time__\'' +
(parseFloat(downMarKey) + 4) +
'">' +
'<span class="mta mta_train mta__train--time mta__train-time__' +
downMarKey.toLowerCase() +
'"> ' +
'<span data-walking-time=\'' +
downTown[downMarKey].walkingTime +
'\' class=\'train-time__downTown-' +
downTown[downMarKey].routeId.toLowerCase() +
'--' +
downMarKey.toLowerCase() +
'\'> ' +
downTown[downMarKey].time +
'min</span>';
downMarHtml =
downMarHtml +
'<span class="mta mta__train mta__train--logo mta__train--line-' +
downTown[downMarKey].routeId.toLowerCase().split("")[0] +
" mta__train--line-" +
this.isExpress(downTown[downMarKey].routeId) +
'">' +
'<span class="' +
this.isExpress(downTown[downMarKey].routeId) +
'">' +
downTown[downMarKey].routeId.toLowerCase().split("")[0] +
"</span></span>" +
"</span><span class='mta mta_train mta__train--time mta_train-time__'" +
(parseFloat(downMarKey) + 4) +
'">' +
'<span class="mta mta_train mta__train--time mta__train-time__' +
downMarKey.toLowerCase() +
'"> ' +
"<span data-walking-time='" +
downTown[downMarKey].walkingTime +
"' class='train-time__downTown-" +
downTown[downMarKey].routeId.toLowerCase() +
"--" +
downMarKey.toLowerCase() +
"'> " +
downTown[downMarKey].time +
"min</span>";

(" </span>"); /*eslint-disable-line*/

Expand All @@ -299,7 +316,9 @@ Module.register('MMM-nyc-transit', { /*eslint-disable-line*/

return wrapper
},

isExpress: function (id) {
return id.split('').length === 2 ? 'express' : ''
},
isSIR: function (id) {
return id === 'SI' ? 'SIR' : id === 'SS' ? 'SIR' : id
},
Expand Down
18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elaniobro/mmm-nyc-transit",
"version": "5.0.0",
"version": "5.1.0",
"description": "New York City realtime transit module for magic mirror",
"main": "MMM-nyc-transit.js",
"publishConfig": {
Expand All @@ -9,7 +9,9 @@
},
"scripts": {
"cm": "cz",
"lint": "eslint **/*.js --ignore-pattern node_modules/",
"lint:js": "eslint **/*.js --ignore-pattern node_modules/",
"lint:style": "stylelint **/*.css",
"lint": "yarn lint:js && yarn lint:style",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Expand All @@ -33,13 +35,21 @@
},
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.17.5",
"@babel/eslint-parser": "^7.17.0",
"chalk": "^2.4.1",
"commitizen": "^4.2.4",
"cz-conventional-changelog": "3.3.0",
"eslint": "^6.0.1",
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.4.0",
"eslint-plugin-prettier": "^4.0.0",
"fs-extra": "^7.0.0",
"husky": "^3.0.0",
"mta-realtime-subway-departures": "^1.2.0"
"mta-realtime-subway-departures": "^1.2.0",
"prettier": "^2.5.1",
"stylelint": "^14.5.3",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-standard": "^25.0.0"
},
"husky": {
"hooks": {
Expand Down
Loading

0 comments on commit ccddc83

Please sign in to comment.