Created
          March 2, 2013 03:28 
        
      - 
      
- 
        Save ae6rt/5069569 to your computer and use it in GitHub Desktop. 
    Angular tail function
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $scope.tail = function (tailbag) { | |
| if (tailbag.processid.length === 0) { | |
| console.log("Cannot tail " + tailbag.whoami + " because there is no processid"); | |
| return; | |
| } | |
| $http.get("tail", {params: {"processid": tailbag.processid, "start": tailbag.currentStart, "limit": tailbag.pageSize}}) | |
| .success(function (data, status, headers, config) { | |
| tailbag.currentStart = tailbag.currentStart + data.page.length; | |
| for (k = 0; k < data.page.length; ++k) { | |
| tailbag.text = tailbag.text + data.page[k] + "\n"; | |
| } | |
| if (data.status == "completed" && data.page.length < tailbag.pageSize) { | |
| // process is finished producing output on the server side | |
| console.log("tail cancelled because process was finished"); | |
| $timeout.cancel(tailbag.promise); | |
| } else { | |
| tailbag.promise = $timeout(function () { | |
| $scope.tail(tailbag); | |
| }, 1500); | |
| } | |
| }) | |
| .error(function (data, status, headers, config) { | |
| console.log(tailbag.whoami + " tail error"); | |
| if (tailbag.promise != -1) { | |
| $timeout.cancel(tailbag.promise); | |
| console.log("Cancelled tail for " + tailbag.whoami); | |
| } | |
| }); | |
| }; | |
| html: | |
| <div id="pager"> | |
| <pre> | |
| {{slurperbag.text}} | |
| </pre> | |
| </div> | |
| css: | |
| #pager { | |
| width: 1200px; | |
| height: 200px; | |
| background-color: #dfe2ca; | |
| overflow-y: scroll; | |
| max-width: 1200px; | |
| max-height: 800px; | |
| border: 1px solid black; | |
| border-radius: 10px; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment