• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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.

Is there a way to show specific compliments on specific dates?

Scheduled Pinned Locked Moved Troubleshooting
21 Posts 6 Posters 12.6k Views 6 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.
  • C Offline
    CyanKali @pauabaer
    last edited by Apr 27, 2017, 5:46 AM

    @pauabaer

    as you can see I don´t know much about coding, but have you tried just deleting all the default compliments and then adding the line that romain suggested?

    R 1 Reply Last reply Apr 27, 2017, 7:37 AM Reply Quote 0
    • R Offline
      romain @CyanKali
      last edited by Apr 27, 2017, 7:37 AM

      @CyanKali It should have replace all compliment. At that particular date.
      well, yesterday was the 26 right ? you let the 27 so I guess it just wasn’t the rigth date to activate.
      Try changing the date. (well, today must be the 27 so It should work today ahah).

      @pauabaer you could use the compliment module. add the thing I had and then go on the config.js file and replace all the compliments by empty strings so it will display nothing when not the date

                      {                                                                                                                                                                                                                            
                              module: "compliments",                                                                                                                                                                                               
                              position: "lower_third",                                                                                                                                                                                             
                              header: "",                                                                                                                                                                                                          
                              config: {                                                                                                                                                                                                            
                                      compliments: {                                                                                                                                                                                               
                                              anytime: [ "" ],                                                                                                                                                                                                   
                                              morning: [ "" ],                                                                                                                                                                                                   
                                              afternoon: [ "" ],                                                                                                                                                                                                   
                                              evening: [  "" ]                                                                                                                                                                                                    
                                      }                                                                                                                                                                                                            
                              }                                                                                                                                                                                                                    
                      },
      

      Or you could change the code so the module hide itself when the date isn’t right

              // Override dom generator.                                                                                                                                                                                                           
              getDom: function() {
                  var complimentText = this.randomCompliment();
                  if (moment().format('MMM D') == 'Apr 27')
                  {
                      this.show();
                      complimentText = "Happy birthday"
                  }
                  else
                      this.hide();
                  var compliment = document.createTextNode(complimentText);
                  var wrapper = document.createElement("div");
                  wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright";
                  wrapper.appendChild(compliment);
      
                      return wrapper;
              },
      
      C 1 Reply Last reply Apr 27, 2017, 8:31 PM Reply Quote 1
      • P Offline
        pauabaer
        last edited by Apr 27, 2017, 9:49 AM

        thanks @romain
        i think the second way will be mine. what do i have to write in the config.js file? how can i integrate a second date?

        R 1 Reply Last reply Apr 27, 2017, 10:18 AM Reply Quote 0
        • R Offline
          romain @pauabaer
          last edited by romain Apr 27, 2017, 10:21 AM Apr 27, 2017, 10:18 AM

          @pauabaer for the config file, you can just use the default one. we didn’t change much with that code.
          To add another date, just add as many else if () statement as needed. This isn’t a pretty solution but it will work.

                  // Override dom generator.                                                                                                                                                                                                           
                  getDom: function() {
                      var complimentText = this.randomCompliment();
                      if (moment().format('MMM D') == 'Apr 27')
                      {
                          this.show();
                          complimentText = "Happy birthday"
                      }
                   else if (moment().format('MMM D') == 'Apr 28') {
                           this.show();
                          complimentText = "Happy 28th day"
          
                   }  else
                          this.hide();
                      var compliment = document.createTextNode(complimentText);
                      var wrapper = document.createElement("div");
                      wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright";
                      wrapper.appendChild(compliment);
          
                          return wrapper;
                  },
          

          It’s not a pretty solution. I could made it prettier by creating a separate function with a while abd set a variable in the config section so you can add as many date as you want by editing the config.js. But I’m lazy so … yeah, not pretty solution.

          1 Reply Last reply Reply Quote 0
          • P Offline
            pauabaer
            last edited by Apr 27, 2017, 10:39 AM

            yeah @romain. sounds for me as if this solution is very easy at all. you dont blow up the code with two more else if-statements.

            But with a separate function you could pimp up the module.
            Think about annual festivals like:

            • eastern --> Happy Eastern
            • christmas --> Merry Christmas
            • birthdays --> Happy Birthday

            etc.

            Perhaps you can overcome the laziness :grin:

            R 1 Reply Last reply Apr 27, 2017, 12:06 PM Reply Quote 0
            • R Offline
              romain @pauabaer
              last edited by Apr 27, 2017, 12:06 PM

              @pauabaer Na, perhaps you can make it youself ;)
              It’s not that hard, just read about array and function in javascript.
              The idea is :
              -You creat a function.
              -You creat a variable in the config part. the variable should be an array. The easiest thing would be to make it an array of dictionnaries. So you can put a date and a message in each ones.
              -Inside the function you stock the value of moment().format(‘MMM D’) in a variable
              -Then you make a for that iterate on each element of the array an compare the value of moment().format(‘MMM D’) that you just got to the date part of each dictionary.
              -If there is a match, you return the associate message. if not, you just return an empty string.
              -In the getDom function you call that function instead of the randomCompliment

              And you should be fine.
              And hey, if you succeed you’ll could be proud to say you did a module yourself (sort of) !

              1 Reply Last reply Reply Quote 0
              • P Offline
                pauabaer
                last edited by Apr 27, 2017, 12:28 PM

                @romain sounds logic. but i dont have any knowledge about javascript. so i have to start from scratch. i dont know…i think for now your workaround sounds best :D

                S 1 Reply Last reply Apr 27, 2017, 12:32 PM Reply Quote 0
                • S Offline
                  strawberry 3.141 Project Sponsor Module Developer @pauabaer
                  last edited by Apr 27, 2017, 12:32 PM

                  @pauabaer as you dont have coding experience I guess you have neither experience with git. By modifying the files you will not be able to easily update the magicmirror.

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

                  1 Reply Last reply Reply Quote 0
                  • P Offline
                    pauabaer
                    last edited by Apr 27, 2017, 1:06 PM

                    @strawberry-3-141 you are right. i have read about this and i am aware of that fact. means a default function would be better. so i hope @romain can overcome the laziness :sunglasses:

                    ps @romain i hope you know how i meant this. you do what you want to do. because i dont have any coding experience i can only speak out some wishes/ features to make this project (for more people) a bit more “magically”.

                    R 1 Reply Last reply Apr 27, 2017, 1:25 PM Reply Quote 0
                    • R Offline
                      romain @pauabaer
                      last edited by Apr 27, 2017, 1:25 PM

                      @pauabaer sure, however, I have other projects to work on so I rather focus on them. I don’t have that much knowledge in javascipt either. (I do have some knowledge in other language though). When I do stuff it’s a lot a trial and error until that work (even for the tiny bit of code I made in this post required some research from me. Not a lot of it… but some. I never used the moments() function before)
                      This is your opportunity to gain knowledge.

                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 1 / 3
                      1 / 3
                      • First post
                        9/21
                        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