• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Advice on moving components / controllers / services out of userModule

    User help
    3
    37
    13.4k
    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.
    • MattFoxM
      MattFox
      last edited by

      You've got the right idea, the first thing I suggest is to see if you can even manually load the userModule from your web browser

      [mangoURL]/modules/mangoUI/web/dev/userModule.js

      if you can pull that, then try with the components directory

      Do not follow where the path may lead; go instead where there is no path.
      And leave a trail - Muriel Strode

      1 Reply Last reply Reply Quote 0
      • MattFoxM
        MattFox
        last edited by

        Hang on, your mango install is in /opt/mango36 ?
        Not in /opt/mango ?

        Do not follow where the path may lead; go instead where there is no path.
        And leave a trail - Muriel Strode

        1 Reply Last reply Reply Quote 0
        • B
          BobDay
          last edited by BobDay

          yes, but using Mango36 in the url... as in /opt/mango36/overrides/web/modules/mangoUI/web/dev/userModule.js

          hmmm... does it need to live in /mango?

          1 Reply Last reply Reply Quote 0
          • MattFoxM
            MattFox
            last edited by MattFox

            nope, just wanted to make sure you did have the files inside the mango's installation directory regardless of how it is named.

            Did the http requests from your browser work?

            If the mango is on localhost it'd be localhost/modules/mangoUI/web/dev/userModule.js

            Do not follow where the path may lead; go instead where there is no path.
            And leave a trail - Muriel Strode

            1 Reply Last reply Reply Quote 0
            • B
              BobDay
              last edited by

              nope. clearly have a path issue here...

              1 Reply Last reply Reply Quote 0
              • MattFoxM
                MattFox
                last edited by

                if you're in linux, can you navigate to the directory where your usermodule is and enter

                pwd
                

                otherwise if in windows, open a command prompt in the location and enter

                DIR
                

                to print the path

                Do not follow where the path may lead; go instead where there is no path.
                And leave a trail - Muriel Strode

                1 Reply Last reply Reply Quote 0
                • B
                  BobDay
                  last edited by

                  (osx)
                  pwd
                  /opt/mango36/overrides/web/modules/mangoUI/web/dev

                  1 Reply Last reply Reply Quote 0
                  • MattFoxM
                    MattFox
                    last edited by MattFox

                    nope that's definitely correct, check your directory permissions and the owner.
                    I'll wager mango itself may not have access to the file.
                    Whatever the user runs as in mango set that as your modules etc directories for a start.
                    up to web. everything inside that shouldn't matter.

                    We'll start with that and work our way up from there...

                    sudo chown [user]:[user] /opt/mango36/overrides -R
                    
                    sudo find /opt/mango36/overrides -type d -exec chmod 755 {} \;

                    Do not follow where the path may lead; go instead where there is no path.
                    And leave a trail - Muriel Strode

                    1 Reply Last reply Reply Quote 0
                    • B
                      BobDay
                      last edited by

                      @mattfox said in Advice on moving components / controllers / services out of userModule:

                      sudo find /opt/mango36/overrides -type d -exec chmod 755 {} ;

                      I assume it runs as root - I have to sudo to start it. In any event, the entire mango36 directory is recursively 755.

                      and still no joy.

                      1 Reply Last reply Reply Quote 0
                      • MattFoxM
                        MattFox
                        last edited by MattFox

                        ps aux | grep java
                        
                        

                        This will tell us what mango runs as. Also can you also print

                        ls -la /opt/mango36/overrides/web/modules/mangoUI/web/dev
                        

                        Do not follow where the path may lead; go instead where there is no path.
                        And leave a trail - Muriel Strode

                        1 Reply Last reply Reply Quote 0
                        • B
                          BobDay
                          last edited by

                          @mattfox said in Advice on moving components / controllers / services out of userModule:

                          ps aux | grep java

                          ▶ ps aux | grep java
                          
                          root             81841   1.4  5.1  8617284 855636 s000  S     1:51PM   4:13.58 /usr/bin/java -server -cp /opt/mango36/overrides/classes:/opt/mango36/classes:/opt/mango36/overrides/properties:/opt/mango36/overrides/lib/*:/opt/mango36/lib/* -Dma.home=/opt/mango36 -Djava.library.path=/opt/mango36/overrides/lib:/opt/mango36/lib:/usr/lib/jni/:/Users/bullit/.jenv/bin:/Users/bullit/local/n/bin/:/Users/bullit/local/n/bin/node:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/Users/bullit/bin:/Users/bullit/local/n/bin:/usr/bin/pear:/usr/local/bin/dayone com.serotonin.m2m2.Main
                          bullit           87269   0.0  0.0  2424612   1248 s001  R+    3:42PM   0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn java
                          

                          bullit has read/write access...

                          1 Reply Last reply Reply Quote 0
                          • B
                            BobDay
                            last edited by BobDay

                            mangoUI/web/dev
                            ▶ cat /opt/mango36/overrides/web/modules/mangoUI/web/dev/userModule.js
                            define(['angular', 'require','./components/pushLamp.js'],
                              function (angular, require, pushLamp) {
                                var userModule = angular.module('userModule', ['maUiApp']);
                            
                                userModule.filter('unsafe', ['$sce', function($sce) {
                                   return $sce.trustAsHtml;
                                }]);
                            
                                try
                                {
                                  userModule.component('pushLamp',pushLamp);
                                }
                                catch(e)
                                {
                                  console.log('error: ', e);
                                }
                            
                            });
                            

                            ...just checking

                            1 Reply Last reply Reply Quote 0
                            • MattFoxM
                              MattFox
                              last edited by MattFox

                              I know what i've done wrong....

                              I didn't return the user module!
                              So sorry man!

                              define(['angular', 'require','./components/pushLamp.js'],
                                function (angular, require, pushLamp) {
                                  var userModule = angular.module('userModule', ['maUiApp']);
                              
                                  userModule.filter('unsafe', ['$sce', function($sce) {
                                     return $sce.trustAsHtml;
                                  }]);
                              
                                  try
                                  {
                                    userModule.component('pushLamp',pushLamp);
                                  }
                                  catch(e)
                                  {
                                    console.log('error: ', e);
                                  }
                               return userModule; //MISSING THIS!!! aerghhh I hate mondays...
                              });
                              

                              Man I need a swift kick...

                              Do not follow where the path may lead; go instead where there is no path.
                              And leave a trail - Muriel Strode

                              1 Reply Last reply Reply Quote 1
                              • B
                                BobDay
                                last edited by

                                so WE did! same problem tho.

                                lets take this back to chat...

                                1 Reply Last reply Reply Quote 1
                                • MattFoxM
                                  MattFox
                                  last edited by

                                  Fixed, just mixed up the full path of the file with the userModule URL after closer inspection.

                                  Do not follow where the path may lead; go instead where there is no path.
                                  And leave a trail - Muriel Strode

                                  1 Reply Last reply Reply Quote 2
                                  • B
                                    BobDay
                                    last edited by

                                    ok, @MattFox... I feel like a post (as in dumb as one). Can you refresh me again as to how to now break out (and where to declare) the component's controller in its own file?

                                    userModule.js

                                    define(['angular', 'require','./push/pushLamp.js'],
                                      function (angular, require, pushLamp) {
                                        var userModule = angular.module('userModule', ['maUiApp']);
                                    
                                        userModule.filter('unsafe', ['$sce', function($sce) {
                                           return $sce.trustAsHtml;
                                        }]);
                                    
                                        try
                                        {
                                          userModule.component('pushLamp',pushLamp);
                                        }
                                        catch(e)
                                        {
                                          console.log('error: ', e);
                                        }
                                        return userModule.js;
                                    
                                    });
                                    

                                    pushLamp.js:

                                    define(['angular', 'require'], function (angular, require) {
                                    
                                      pushCtrl.$inject = ['$scope','$timeout'];
                                    
                                      function pushCtrl($scope,$timeout) {
                                    
                                        const $ctrl = this;
                                        $ctrl.$onChanges = function (changes) {
                                          if (changes.points && Array.isArray($ctrl.points)) {
                                    
                                            $ctrl.point = $ctrl.points.find(p => p.xid === 'DP_ind_' + $ctrl.target);
                                            $ctrl.switchPoint = $ctrl.points.find(p => p.xid === 'DP_sw_' + $ctrl.target);
                                    
                                            $ctrl.ptCSS = { // point css values for color and blink; ex, ng-class=""
                                              get color(){
                                                if ($ctrl.point.color < 10) {
                                                  return 0;
                                                }
                                                return Math.floor($ctrl.point.value / 10)},
                                              get blink(){return 'blink' + $ctrl.point.value % 10},
                                              get colStyle(){return 'color'+this.color}
                                            };
                                    
                                            $timeout(function() {
                                              console.log('color:', $ctrl.ptCSS.colStyle, 'blink:', $ctrl.ptCSS.blink );
                                            },1000);
                                          }
                                        };
                                    
                                        $ctrl.pushed = function() {
                                          console.log($ctrl.switchPoint.value);
                                            if ($ctrl.switchPoint) {
                                                $ctrl.switchPoint.toggleValue();
                                              console.log('switch ' + $ctrl.target + ' was switched.' );
                                           }
                                        };
                                      }
                                    
                                    return {
                                          templateUrl: '/modules/mangoUI/web/dev/push/push.html',
                                          bindings: {
                                            points: '<',
                                            target: '@'
                                          },
                                          controller: pushCtrl
                                        };
                                    
                                    });
                                    1 Reply Last reply Reply Quote 1
                                    • MattFoxM
                                      MattFox
                                      last edited by

                                      I'm a little confused as to why you'd want to go that far but I believe you'd do something along the lines of..
                                      /opt/mango36/overrides/web/modules/mangoUI/web/dev/controllers/pushCtrl.js

                                      define(['angular', 'require'], function (angular, require) {
                                      
                                        pushCtrl.$inject = ['$scope','$timeout'];
                                      
                                        function pushCtrl($scope,$timeout) 
                                        {
                                          const $ctrl = this;
                                          $ctrl.$onChanges = function (changes) {
                                            if (changes.points && Array.isArray($ctrl.points)) {
                                      
                                              $ctrl.point = $ctrl.points.find(p => p.xid === 'DP_ind_' + $ctrl.target);
                                              $ctrl.switchPoint = $ctrl.points.find(p => p.xid === 'DP_sw_' + $ctrl.target);
                                      
                                              $ctrl.ptCSS = { // point css values for color and blink; ex, ng-class=""
                                                get color(){
                                                  if ($ctrl.point.color < 10) {
                                                    return 0;
                                                  }
                                                  return Math.floor($ctrl.point.value / 10)},
                                                get blink(){return 'blink' + $ctrl.point.value % 10},
                                                get colStyle(){return 'color'+this.color}
                                              };
                                      
                                              $timeout(function() {
                                                console.log('color:', $ctrl.ptCSS.colStyle, 'blink:', $ctrl.ptCSS.blink );
                                              },1000);
                                            }
                                          };
                                      
                                          $ctrl.pushed = function() {
                                            console.log($ctrl.switchPoint.value);
                                              if ($ctrl.switchPoint) {
                                                  $ctrl.switchPoint.toggleValue();
                                                console.log('switch ' + $ctrl.target + ' was switched.' );
                                             }
                                          };
                                        }
                                      
                                      return pushCtrl;
                                      )};//define
                                      

                                      then pushLamp.js:

                                      define(['angular', 'require','/modules/web/mangoUI/web/dev/controllers/pushCtrl.js'], function (angular, require,pushCtrl) {
                                      
                                      return {
                                            templateUrl: '/modules/mangoUI/web/dev/push/push.html',
                                            bindings: {
                                              points: '<',
                                              target: '@'
                                            },
                                            controller: pushCtrl
                                          };
                                      
                                      });//define
                                      

                                      I'm confident you can leverage require in the userModule.js to shorten that controller call into a single word but I've not done a great deal of angularJS lately due to other work commitments....

                                      Fox

                                      Do not follow where the path may lead; go instead where there is no path.
                                      And leave a trail - Muriel Strode

                                      1 Reply Last reply Reply Quote 1
                                      • B
                                        BobDay
                                        last edited by

                                        Thanks. I tried that, but obviously suffered pilot error in the process. Good point why bother...

                                        1 Reply Last reply Reply Quote 0
                                        • Jared WiltshireJ
                                          Jared Wiltshire
                                          last edited by

                                          Just be careful with splitting out your user modules into too many files, you may hit the REST rate limiter and your page could fail to load. Test it out with cache disabled to make sure. You can adjust the rate limits in env.properties.

                                          As I mentioned in the other thread, you may want to consider using Webpack if your project becomes cumbersome.

                                          Developer at Radix IoT

                                          1 Reply Last reply Reply Quote 0
                                          • B
                                            BobDay
                                            last edited by

                                            yes - that occurred to me - might make things a little more straightforward. Thanks - didn't think about the REST rate issue. Is there anything about using Webpack with mango?

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post