1+ //MMM-Navigate.js:
2+
3+ Module . register ( "MMM-Navigate" , {
4+ // Default module config.
5+ defaults : {
6+ Alias : [ 'Seite vorwärts' , 'Seite zurück' ] ,
7+ Action : [ { type : "notification" , title : 'Good morning!' } , { type : "notification" , title : 'Good morning!' } ] ,
8+ GPIOPins : [ 26 , 20 , 19 ] //rotary cw, rotary ccw, rotary press (BCM Numbering)
9+ } ,
10+
11+ getStyles : function ( ) {
12+ return [
13+ this . file ( 'MMM-Navigate.css' ) , // css laden
14+ ]
15+ } ,
16+
17+ sendAction : function ( description ) {
18+ this . show ( 0 , { force : true } ) ;
19+ this . sendNotification ( description . notification , description . payload ) ;
20+ this . hide ( 10000 ) ;
21+ } ,
22+
23+ // Define start sequence.
24+ start : function ( ) {
25+ Log . info ( "Starting module: " + this . name ) ;
26+ this . sendConfig ( ) ; //pass config to node_helper.js
27+ //Helper to test connection to node_helper.js
28+ //this.sendSocketNotification('START', {message: 'Starte Verbindung node_helper für ' + this.name});
29+ } ,
30+
31+ // Override dom generator.
32+ getDom : function ( ) {
33+ //Div for loading
34+ if ( this . loading ) {
35+ var loading = document . createElement ( "div" ) ;
36+ loading . innerHTML = this . translate ( "LOADING" ) ;
37+ loading . className = "dimmed light small" ;
38+ wrapper . appendChild ( loading ) ;
39+ return wrapper
40+ }
41+
42+ var self = this ; //makes variables usable in functions
43+ //Div after loading
44+ var parent = document . createElement ( "div" ) ;
45+ parent . className = "xsmall bright" ;
46+ parent . setAttribute ( 'tabindex' , 0 ) ; //set tabindex on div for focus purposes
47+
48+ //build navigation from array
49+ for ( let index = 0 ; index < this . config . Action . length ; index ++ ) {
50+ var naviItem = document . createElement ( "li" ) ;
51+ var link = document . createElement ( 'a' ) ;
52+ link . setAttribute ( 'href' , '' ) ;
53+ link . setAttribute ( 'target' , 'iframe_a' ) ;
54+ link . innerHTML = this . config . Alias [ index ] ;
55+ naviItem . setAttribute ( 'id' , index )
56+ if ( index == 0 ) { //first li gets class="selected"
57+ naviItem . setAttribute ( 'class' , 'selected' ) ;
58+ }
59+ naviItem . append ( link ) ;
60+ parent . append ( naviItem ) ;
61+ }
62+ return parent
63+ } ,
64+
65+ sendConfig : function ( ) {
66+ this . sendSocketNotification ( "BUTTON_CONFIG" , {
67+ config : this . config
68+ } ) ;
69+ } ,
70+
71+ naviaction : function ( payload ) {
72+ var self = this ;
73+ var selectedid = '' ;
74+ var test = '' ;
75+
76+ if ( payload . inputtype === 'CW' ) {
77+ self . show ( 0 ) ;
78+ selectedid = fselectedid ( ) ;
79+ //console.log('FCW, selectedid: '+selectedid);
80+
81+ if ( selectedid == '' ) { //first li gets class="selected"
82+ document . getElementsByTagName ( 'li' ) [ 0 ] . setAttribute ( 'class' , 'selected' ) ;
83+ } else if ( selectedid == self . config . Action . length - 1 ) { //last entry reached, set mark on first entry
84+ document . getElementsByTagName ( 'li' ) [ selectedid ] . setAttribute ( 'class' , '' ) ;
85+ document . getElementsByTagName ( 'li' ) [ 0 ] . setAttribute ( 'class' , 'selected' ) ;
86+ } else { //delete mark of selected id and mark next one
87+ document . getElementsByTagName ( 'li' ) [ selectedid ] . setAttribute ( 'class' , '' ) ;
88+ document . getElementsByTagName ( 'li' ) [ parseInt ( selectedid ) + 1 ] . setAttribute ( 'class' , 'selected' ) ;
89+ }
90+ } else if ( payload . inputtype === 'CCW' ) {
91+ self . show ( 0 ) ;
92+ selectedid = fselectedid ( ) ;
93+
94+ if ( selectedid == '' ) {
95+ document . getElementsByTagName ( 'li' ) [ self . config . Action . length - 1 ] . setAttribute ( 'class' , 'selected' ) ;
96+ } else if ( selectedid == 0 ) { //first entry reached, set mark on last entry
97+ document . getElementsByTagName ( 'li' ) [ selectedid ] . setAttribute ( 'class' , '' ) ;
98+ document . getElementsByTagName ( 'li' ) [ self . config . Action . length - 1 ] . setAttribute ( 'class' , 'selected' ) ;
99+ } else { //delete mark of selected id and mark previous one
100+ document . getElementsByTagName ( 'li' ) [ selectedid ] . setAttribute ( 'class' , '' ) ;
101+ document . getElementsByTagName ( 'li' ) [ parseInt ( selectedid ) - 1 ] . setAttribute ( 'class' , 'selected' ) ;
102+ }
103+ } else if ( payload . inputtype === 'pressed' ) {
104+ //console.log('Lockstring: ',this.lockStrings,' xxx ',this.hidden);
105+ self . show ( 0 , { force : true } ) ;
106+ selectedid = fselectedid ( ) ;
107+ //console.log('Alex, Payload: ', self.config.Action[selectedid].notification,' xxx ',self.config.Action[selectedid].payload);
108+ self . sendAction ( self . config . Action [ selectedid ] ) ;
109+ }
110+
111+ function fselectedid ( ) { //get ID and return it
112+ for ( let index = 0 ; index < self . config . Action . length ; index ++ ) {
113+ var test = document . getElementsByTagName ( 'li' ) [ index ] . getAttribute ( 'class' ) ;
114+
115+ if ( test == 'selected' ) {
116+ var selectedid = document . getElementsByTagName ( 'li' ) [ index ] . getAttribute ( 'id' ) ;
117+ }
118+ }
119+ return selectedid ;
120+ }
121+ return parent
122+ } ,
123+
124+ // socketNotificationReceived from helper
125+ socketNotificationReceived : function ( notification , payload ) {
126+ if ( notification === "{{MODULE_NAME}}-NOTIFICATION_TEST" ) {
127+ // set dataNotification
128+ this . dataNotification = payload ;
129+ this . updateDom ( ) ;
130+ } else if ( notification === 'MSG' ) {
131+ //Log.info('MSG Testnofication von node_helper für MMM-Navigate erhalten, Payload: '+payload.message);
132+ } else if ( notification === 'CW' ) {
133+ //console.log('Rotary Info CW erhalten');
134+ this . naviaction ( payload ) ;
135+ } else if ( notification === 'CCW' ) {
136+ //console.log('Rotary Info CCW erhalten');
137+ this . naviaction ( payload ) ;
138+ } else if ( notification === 'pressed' ) {
139+ //console.log('Rotary Info pressed erhalten');
140+ this . naviaction ( payload ) ;
141+ }
142+ } ,
143+
144+ } ) ;
0 commit comments