MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    This might be a daft question, but...

    Scheduled Pinned Locked Moved Development
    27 Posts 6 Posters 18.3k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • MitchfarinoM Offline
      Mitchfarino Module Developer
      last edited by

      @strawberry-3-141 I saw you were online, so I’m shamelessly tagging you in my post in the hopes of some guidance :-(

      1 Reply Last reply Reply Quote 0
      • strawberry 3.141S Offline
        strawberry 3.141 Project Sponsor Module Developer @Mitchfarino
        last edited by

        @Mitchfarino

        getDom: function () {
            var wrapper = document.createElement("div");
            var table = document.createElement("table");
        
            $.getJSON(this.url,
                function (data) {
                    for (var i = 0; i < data.length; i++) {
                        var row = document.createElement("tr");
                        var name = document.createElement("td");
                        name.innerHTML = data[i].name;
                        row.appendChild(name);
                        table.appendChild(row);
                    }
                    wrapper.appendChild(table);
                    return wrapper;
                });
        

        but I’m pretty sure that this will not work, because the return is in an asynchronous callback, i would do a different structure call your url in an interval somewhere else and save your data into an module variable and call the updateDom function after a result, then in getDom you iterate over the data.

        Please create a github issue if you need help, so I can keep track

        MitchfarinoM 1 Reply Last reply Reply Quote 0
        • MitchfarinoM Offline
          Mitchfarino Module Developer @strawberry 3.141
          last edited by

          @strawberry-3.141 Thanks very much, I’ll have a play with it over the weekend and hopefully I get can something working

          I’ve not done anything like this before really, so just jumping in and seeing what happens :-)

          strawberry 3.141S 1 Reply Last reply Reply Quote 0
          • strawberry 3.141S Offline
            strawberry 3.141 Project Sponsor Module Developer @Mitchfarino
            last edited by

            @Mitchfarino

            url: "", //Insert your url here
            result: false,
            
            defaults: {
                updateInterval: 30 * 60 * 1000 //Every 30 mins
            },
            
            start: function(){
                this.getData();
                setInterval(()=>{
                    this.getData();
                }, this.config.updateInterval);
            },
            
            getDom: function() {
                var wrapper = document.createElement("div");
                if(this.result){
                    var table = document.createElement("table");
                    for (var i = 0; i < this.result.length; i++) {
                        var row = document.createElement("tr");
                        var name = document.createElement("td");
                        name.innerHTML = this.result[i].name;
                        row.appendChild(name);
                        table.appendChild(row);
                    }
                    wrapper.appendChild(table);
                } else {
                    wrapper.innerHTML = "No data to show!";
                }
                return wrapper;
            },
            
            getData: function(){
                $.getJSON(this.url, (data) => {
                    this.result = data;
                    this.updateDom();
                });
            }
            

            Please create a github issue if you need help, so I can keep track

            MitchfarinoM 1 Reply Last reply Reply Quote 1
            • MitchfarinoM Offline
              Mitchfarino Module Developer @strawberry 3.141
              last edited by

              @strawberry-3.141 Thanks for this, I’ll see if I can get it working

              MitchfarinoM 1 Reply Last reply Reply Quote 0
              • MitchfarinoM Offline
                Mitchfarino Module Developer @Mitchfarino
                last edited by

                @strawberry-3-141 once I’ve got some code, how do I test it on my mirror?

                Just copy the folder to the modules folder and add it to the config, or is there something else I need to do?

                Thanks

                paviroP 1 Reply Last reply Reply Quote 0
                • paviroP Offline
                  paviro Admin @Mitchfarino
                  last edited by

                  @Mitchfarino no that’s it :)

                  We're all stories in the end. Just make it a good one, eh?

                  – The Doctor

                  MitchfarinoM 1 Reply Last reply Reply Quote 1
                  • MitchfarinoM Offline
                    Mitchfarino Module Developer @paviro
                    last edited by

                    @paviro Awesome, thank you!

                    I’m stumbling my way through, hopefully I’ll have something working soon :)

                    paviroP 1 Reply Last reply Reply Quote 0
                    • paviroP Offline
                      paviro Admin @Mitchfarino
                      last edited by

                      @Mitchfarino good luck! :)

                      We're all stories in the end. Just make it a good one, eh?

                      – The Doctor

                      MitchfarinoM 1 Reply Last reply Reply Quote 0
                      • MitchfarinoM Offline
                        Mitchfarino Module Developer @paviro
                        last edited by

                        @paviro Just one more question…

                        Why would I need to run npm install for some modules?

                        1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 3
                        • 2 / 3
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Sam, technical setup by Karsten.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy