log.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. $('#log').append(row);
  63. }
  64. OC.Log.loaded += entries.length;
  65. }
  66. };
  67. $(document).ready(function () {
  68. $('#moreLog').click(function () {
  69. OC.Log.getMore();
  70. });
  71. $('#lessLog').click(function () {
  72. OC.Log.showLess();
  73. });
  74. });