log.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Copyright (c) 2012, Robin Appelman <icewind1991@gmail.com>
  3. * Copyright (c) 2013, Morris Jobke <morris.jobke@gmail.com>
  4. * This file is licensed under the Affero General Public License version 3 or later.
  5. * See the COPYING-README file.
  6. */
  7. OC.Log={
  8. reload:function(count){
  9. if(!count){
  10. count=OC.Log.loaded;
  11. }
  12. OC.Log.loaded=0;
  13. $('#log tbody').empty();
  14. OC.Log.getMore(count);
  15. },
  16. levels:['Debug','Info','Warning','Error','Fatal'],
  17. loaded:3,//are initially loaded
  18. getMore:function(count){
  19. count = count || 10;
  20. $.get(OC.filePath('settings','ajax','getlog.php'),{offset:OC.Log.loaded,count:count},function(result){
  21. if(result.status === 'success'){
  22. OC.Log.addEntries(result.data);
  23. if(!result.remain){
  24. $('#moreLog').hide();
  25. }
  26. $('#lessLog').show();
  27. }
  28. });
  29. },
  30. showLess:function(count){
  31. count = count || 10;
  32. //calculate remaining items - at least 3
  33. OC.Log.loaded = Math.max(3,OC.Log.loaded-count);
  34. $('#moreLog').show();
  35. // remove all non-remaining items
  36. $('#log tr').slice(OC.Log.loaded).remove();
  37. if(OC.Log.loaded <= 3) {
  38. $('#lessLog').hide();
  39. }
  40. },
  41. addEntries:function(entries){
  42. for(var i=0;i<entries.length;i++){
  43. var entry=entries[i];
  44. var row=$('<tr/>');
  45. var levelTd=$('<td/>');
  46. levelTd.text(OC.Log.levels[entry.level]);
  47. row.append(levelTd);
  48. var appTd=$('<td/>');
  49. appTd.text(entry.app);
  50. row.append(appTd);
  51. var messageTd=$('<td/>');
  52. messageTd.text(entry.message);
  53. row.append(messageTd);
  54. var timeTd=$('<td/>');
  55. if(isNaN(entry.time)){
  56. timeTd.text(entry.time);
  57. } else {
  58. timeTd.text(formatDate(entry.time*1000));
  59. }
  60. row.append(timeTd);
  61. $('#log').append(row);
  62. }
  63. OC.Log.loaded += entries.length;
  64. }
  65. }
  66. $(document).ready(function(){
  67. $('#moreLog').click(function(){
  68. OC.Log.getMore();
  69. })
  70. $('#lessLog').click(function(){
  71. OC.Log.showLess();
  72. })
  73. });