diff --git a/@types/Module/index.d.ts b/@types/Module/index.d.ts index d4aa9a3..db466e0 100644 --- a/@types/Module/index.d.ts +++ b/@types/Module/index.d.ts @@ -7,11 +7,11 @@ declare module Module { getTranslations: Function; getTemplate: Function; getTemplateData: Function; - getHeader: Function; start: Function; scheduleUpdate: Function; loadData: Function; socketNotificationReceived: Function; + getHeader?: Function; } ): void; } diff --git a/MMM-Jast.js b/MMM-Jast.js index db442ce..81d3069 100644 --- a/MMM-Jast.js +++ b/MMM-Jast.js @@ -1 +1 @@ -(()=>{"use strict";var e={429:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{constructor(e){this.config=e,this.currentValueStyle={style:e.showCurrency?"currency":"decimal",useGrouping:e.useGrouping,currencyDisplay:e.currencyStyle,minimumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8},this.changeValueStyle={style:e.showChangeValueCurrency?"currency":"decimal",useGrouping:e.useGrouping,currencyDisplay:e.currencyStyle,minimumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8},this.percentStyle={style:"percent",useGrouping:e.useGrouping,minimumFractionDigits:e.numberDecimalsPercentages<=8?e.numberDecimalsPercentages:8}}getStockChange(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketChange}getStockChangePercent(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketChangePercent}getCurrentValue(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketPrice}getStockChangeAsString(e){return this.getStockChange(e).toLocaleString(this.config.locale,Object.assign(this.changeValueStyle,{currency:e.summaryDetail.currency}))}getStockChangePercentAsString(e){return this.getStockChangePercent(e).toLocaleString(this.config.locale,this.percentStyle)}getCurrentValueAsString(e){return this.getCurrentValue(e).toLocaleString(this.config.locale,Object.assign(this.currentValueStyle,{currency:e.summaryDetail.currency}))}getStockName(e){return e.meta.name||e.price.longName}getDepotValueAsString(e){return e.value.toLocaleString(this.config.locale,Object.assign(this.currentValueStyle,{currency:e.currency}))}getDepotChangeAsString(e){return(e.value-e.oldValue).toLocaleString(this.config.locale,Object.assign(this.currentValueStyle,{currency:e.currency}))}getDepotChangePercentAsString(e){return((e.value-e.oldValue)/e.oldValue).toLocaleString(this.config.locale,this.percentStyle)}getDepot(e){var t,n,r;let a=[];for(const s of e)try{const e=null===(t=this.config.stocks)||void 0===t?void 0:t.find((e=>{var t;return e.symbol===(null===(t=s.meta)||void 0===t?void 0:t.symbol)}));if(null==e?void 0:e.quantity){const t=(null===(n=s.price)||void 0===n?void 0:n.regularMarketPrice)*e.quantity,o=(null===(r=s.price)||void 0===r?void 0:r.regularMarketPreviousClose)*e.quantity,c=a.find((e=>e.currency===s.price.currency));console.log("add",t,o,s.meta.name),c?(c.value=c.value+t,c.oldValue=c.oldValue+o):a.push({value:t,oldValue:o,currency:s.price.currency})}}catch(e){console.warn("There was a problem calculating the detpot growth",e)}return console.log("depot",a),a}}}},t={};function n(r){var a=t[r];if(void 0!==a)return a.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}(()=>{const e=n(429);Module.register("MMM-Jast",{defaults:{header:null,locale:config.locale||"en-GB",updateIntervalInSeconds:600,useGrouping:!1,currencyStyle:"code",fadeSpeedInSeconds:3.5,stocks:[{name:"BASF",symbol:"BAS.DE",quantity:100},{name:"SAP",symbol:"SAP.DE",quantity:200},{name:"Henkel",symbol:"HEN3.DE"},{name:"AbbVie",symbol:"4AB.DE"},{name:"Bitcoin",symbol:"BTC-EUR"},{name:"Alibaba",symbol:"BABA"}],scroll:"vertical",maxWidth:"100%",numberDecimalsValues:2,numberDecimalsPercentages:1,showColors:!0,showCurrency:!0,showChangePercent:!0,showChangeValue:!1,showChangeValueCurrency:!1,showDepot:!1,showDepotGrowth:!1,showDepotGrowthPercent:!1},getStyles:()=>["MMM-Jast.css"],getTranslations:()=>({en:"translations/en.json",de:"translations/de.json"}),getTemplate:()=>"templates/MMM-Jast.njk",getTemplateData(){const t=new e.default(this.config);return{config:this.config,stocks:this.stocks,utils:t}},getHeader(){return this.config.header},start(){this.nunjucksEnvironment().loaders[0].async=!1,this.nunjucksEnvironment().loaders[0].useCache=!0,this.stocks=[],this.loadData(),this.scheduleUpdate(),this.updateDom()},scheduleUpdate(){const e=this;this.config.updateIntervalInSeconds=this.config.updateIntervalInSeconds<120?120:this.config.updateIntervalInSeconds,setInterval((()=>{e.loadData()}),1e3*this.config.updateIntervalInSeconds)},loadData(){this.sendSocketNotification("GET_STOCKS",this.config)},socketNotificationReceived(e,t){"STOCKS_RESULT"===e&&(this.stocks=t,this.updateDom(),console.log("Stock results",this.stocks))}})})()})(); \ No newline at end of file +(()=>{"use strict";var e={429:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{constructor(e){this.config=e,this.currentValueStyle={style:e.showCurrency?"currency":"decimal",useGrouping:e.useGrouping,currencyDisplay:e.currencyStyle,minimumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8},this.changeValueStyle={style:e.showChangeValueCurrency?"currency":"decimal",useGrouping:e.useGrouping,currencyDisplay:e.currencyStyle,minimumFractionDigits:e.numberDecimalsValues<=8?e.numberDecimalsValues:8},this.percentStyle={style:"percent",useGrouping:e.useGrouping,minimumFractionDigits:e.numberDecimalsPercentages<=8?e.numberDecimalsPercentages:8}}getStockChange(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketChange}getStockChangePercent(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketChangePercent}getCurrentValue(e){var t;return null===(t=e.price)||void 0===t?void 0:t.regularMarketPrice}getStockChangeAsString(e){return this.getStockChange(e).toLocaleString(this.config.locale,Object.assign(this.changeValueStyle,{currency:e.summaryDetail.currency}))}getStockChangePercentAsString(e){return this.getStockChangePercent(e).toLocaleString(this.config.locale,this.percentStyle)}getCurrentValueAsString(e){return this.getCurrentValue(e).toLocaleString(this.config.locale,Object.assign(this.currentValueStyle,{currency:e.summaryDetail.currency}))}getStockName(e){return e.meta.name||e.price.longName}getDepotValueAsString(e){return e.value.toLocaleString(this.config.locale,Object.assign(this.currentValueStyle,{currency:e.currency}))}getDepotChangeAsString(e){return(e.value-e.oldValue).toLocaleString(this.config.locale,Object.assign(this.currentValueStyle,{currency:e.currency}))}getDepotChangePercentAsString(e){return((e.value-e.oldValue)/e.oldValue).toLocaleString(this.config.locale,this.percentStyle)}getDepot(e){var t,n,r;let a=[];for(const s of e)try{const e=null===(t=this.config.stocks)||void 0===t?void 0:t.find((e=>{var t;return e.symbol===(null===(t=s.meta)||void 0===t?void 0:t.symbol)}));if(null==e?void 0:e.quantity){const t=(null===(n=s.price)||void 0===n?void 0:n.regularMarketPrice)*e.quantity,c=(null===(r=s.price)||void 0===r?void 0:r.regularMarketPreviousClose)*e.quantity,o=a.find((e=>e.currency===s.price.currency));o?(o.value=o.value+t,o.oldValue=o.oldValue+c):a.push({value:t,oldValue:c,currency:s.price.currency})}}catch(e){console.warn("There was a problem calculating the detpot growth",e)}return console.debug("Depot",a),a}}}},t={};function n(r){var a=t[r];if(void 0!==a)return a.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}(()=>{const e=n(429);Module.register("MMM-Jast",{defaults:{locale:config.locale||"en-GB",updateIntervalInSeconds:600,useGrouping:!1,currencyStyle:"code",fadeSpeedInSeconds:3.5,stocks:[{name:"BASF",symbol:"BAS.DE",quantity:100},{name:"SAP",symbol:"SAP.DE",quantity:200},{name:"Henkel",symbol:"HEN3.DE"},{name:"AbbVie",symbol:"4AB.DE"},{name:"Bitcoin",symbol:"BTC-EUR"},{name:"Alibaba",symbol:"BABA"}],scroll:"vertical",maxWidth:"100%",numberDecimalsValues:2,numberDecimalsPercentages:1,showColors:!0,showCurrency:!0,showChangePercent:!0,showChangeValue:!1,showChangeValueCurrency:!1,showDepot:!1,showDepotGrowth:!1,showDepotGrowthPercent:!1},getStyles:()=>["MMM-Jast.css"],getTranslations:()=>({en:"translations/en.json",de:"translations/de.json"}),getTemplate:()=>"templates/MMM-Jast.njk",getTemplateData(){const t=new e.default(this.config);return{config:this.config,stocks:this.stocks,utils:t}},start(){this.nunjucksEnvironment().loaders[0].async=!1,this.nunjucksEnvironment().loaders[0].useCache=!0,this.stocks=[],this.loadData(),this.scheduleUpdate(),this.updateDom()},scheduleUpdate(){const e=this;this.config.updateIntervalInSeconds=this.config.updateIntervalInSeconds<120?120:this.config.updateIntervalInSeconds,setInterval((()=>{e.loadData()}),1e3*this.config.updateIntervalInSeconds)},loadData(){this.sendSocketNotification("GET_STOCKS",this.config)},socketNotificationReceived(e,t){"STOCKS_RESULT"===e&&(this.stocks=t,this.updateDom(),console.debug("Stocks",this.stocks))}})})()})(); \ No newline at end of file diff --git a/src/client/Client.ts b/src/client/Client.ts index 73123db..e63d992 100644 --- a/src/client/Client.ts +++ b/src/client/Client.ts @@ -3,7 +3,6 @@ import { Config } from "../models/Config"; Module.register("MMM-Jast", { defaults: { - header: null, locale: config.locale || "en-GB", updateIntervalInSeconds: 600, useGrouping: false, @@ -55,10 +54,6 @@ Module.register("MMM-Jast", { }; }, - getHeader() { - return this.config.header; - }, - start() { // Override defaults this.nunjucksEnvironment().loaders[0].async = false; @@ -88,7 +83,7 @@ Module.register("MMM-Jast", { if (notificationIdentifier === "STOCKS_RESULT") { this.stocks = payload; this.updateDom(); - console.log("Stock results", this.stocks); + console.debug("Stocks", this.stocks); } } }); diff --git a/src/client/Utils.ts b/src/client/Utils.ts index 3122893..d76f9c2 100644 --- a/src/client/Utils.ts +++ b/src/client/Utils.ts @@ -134,7 +134,7 @@ export default class JastUtils { const existingCurrency = depot.find( (growth) => growth.currency === stock.price.currency ) - console.log("add", currentStockValue, lastStockValue, stock.meta.name) + if (existingCurrency) { existingCurrency.value = existingCurrency.value + currentStockValue existingCurrency.oldValue = existingCurrency.oldValue + lastStockValue @@ -151,7 +151,7 @@ export default class JastUtils { } } - console.log("depot", depot) + console.debug("Depot", depot) return depot } }