log.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. /* global formatDate */
  8. OC.Log = {
  9. reload: function (count) {
  10. if (!count) {
  11. count = OC.Log.loaded;
  12. }
  13. OC.Log.loaded = 0;
  14. $('#log tbody').empty();
  15. OC.Log.getMore(count);
  16. },
  17. levels: ['Debug', 'Info', 'Warning', 'Error', 'Fatal'],
  18. loaded: 3,//are initially loaded
  19. getMore: function (count) {
  20. count = count || 10;
  21. $.get(OC.generateUrl('/settings/admin/log/entries'), {offset: OC.Log.loaded, count: count}, function (result) {
  22. OC.Log.addEntries(result.data);
  23. if (!result.remain) {
  24. $('#moreLog').hide();
  25. }
  26. $('#lessLog').show();
  27. });
  28. },
  29. showLess: function (count) {
  30. count = count || 10;
  31. //calculate remaining items - at least 3
  32. OC.Log.loaded = Math.max(3, OC.Log.loaded - count);
  33. $('#moreLog').show();
  34. // remove all non-remaining items
  35. $('#log tr').slice(OC.Log.loaded).remove();
  36. if (OC.Log.loaded <= 3) {
  37. $('#lessLog').hide();
  38. }
  39. },
  40. addEntries: function (entries) {
  41. for (var i = 0; i < entries.length; i++) {
  42. var entry = entries[i];
  43. var row = $('<tr/>');
  44. var levelTd = $('<td/>');
  45. levelTd.text(OC.Log.levels[entry.level]);
  46. row.append(levelTd);
  47. var appTd = $('<td/>');
  48. appTd.text(entry.app);
  49. row.append(appTd);
  50. var messageTd = $('<td/>');
  51. messageTd.addClass('log-message');
  52. messageTd.text(entry.message);
  53. row.append(messageTd);
  54. var timeTd = $('<td/>');
  55. timeTd.addClass('date');
  56. if (isNaN(entry.time)) {
  57. timeTd.text(entry.time);
  58. } else {
  59. timeTd.text(formatDate(entry.time * 1000));
  60. }
  61. row.append(timeTd);
  62. var userTd = $('<td/>');
  63. userTd.text(entry.user);
  64. row.append(userTd);
  65. $('#log').append(row);
  66. }
  67. OC.Log.loaded += entries.length;
  68. }
  69. };
  70. $(document).ready(function () {
  71. $('#moreLog').click(function () {
  72. OC.Log.getMore();
  73. });
  74. $('#lessLog').click(function () {
  75. OC.Log.showLess();
  76. });
  77. });