API Docs for: 0.6.0
Show:

File: src/logger.js

  1.  
  2. /**
  3. * Handles all logging, either to console or designated HTML
  4. * container.
  5. *
  6. * Needs more work.
  7. *
  8. * @class sgvizler.logger
  9. * @static
  10. */
  11. S.logger = (function () {
  12.  
  13. /*global $, console*/
  14.  
  15. // Module dependencies:
  16. //var util = S.util,
  17. var
  18. /**
  19. * The timestamp for the load start of the current running
  20. * version of sgvizler. Used to calculate time elapse of
  21. * future events.
  22. * @property start
  23. * @type number
  24. * @private
  25. * @since 0.6.0
  26. **/
  27. startTime = Date.now(),
  28.  
  29. /**
  30. * @method timeElapsed
  31. * @private
  32. * @return {number} The number of seconds elapsed since
  33. * this sgvizler got loaded.
  34. * @since 0.6.0
  35. **/
  36. elapsedTime = function () {
  37. return (Date.now() - startTime) / 1000;
  38. },
  39.  
  40. /**
  41. * @property waitingCharts
  42. * @type number
  43. * @private
  44. * @beta
  45. **/
  46. waitingCharts = 0;
  47.  
  48. return {
  49.  
  50. /**
  51. * Logs a message.
  52. * @method log
  53. * @protected
  54. * @param {string} message The message to log.
  55. * @beta
  56. */
  57. log: function (message) {
  58. console.log(elapsedTime() + "s: " + message);
  59. },
  60.  
  61. // TODO
  62. loadingChart: function () {
  63. waitingCharts += 1;
  64. if (!$('body,html').css('cursor', 'progress')) {
  65. $('body,html').css('cursor', 'progress');
  66. }
  67. },
  68. doneLoadingChart: function () {
  69. waitingCharts -= 1;
  70. if (waitingCharts === 0 && $('body,html').css('cursor', 'progress')) {
  71. $('body,html').css('cursor', 'default');
  72. }
  73. }
  74.  
  75. // TODO
  76. // displayFeedback: function (query, messageName) {
  77. // var message,
  78. // container = query.logContainer();
  79.  
  80. // if (query.loglevel() === 0) {
  81. // message = "";
  82. // } else if (query.loglevel() === 1) {
  83. // if (messageName === "LOADING") {
  84. // message = "Loading...";
  85. // } else if (messageName === "ERROR_ENDPOINT" || messageName === "ERROR_UNKNOWN") {
  86. // message = "Error.";
  87. // }
  88. // } else {
  89. // if (messageName === "LOADING") {
  90. // message = "Sending query ...";
  91. // } else if (messageName === "ERROR_ENDPOINT") {
  92. // message = "Error querying endpoint. Possible errors:" +
  93. // util.html.ul(
  94. // util.html.a(query.endpoint(), "SPARQL endpoint") + " down? " +
  95. // util.html.a(query.endpoint() + query.endpointQueryURL + query.encodedQuery(),
  96. // "Check if query runs at the endpoint") + ".",
  97. // "Malformed SPARQL query? " +
  98. // util.html.a(query.validatorQueryURL() + query.encodedQuery(), "Check if it validates") + ".",
  99. // "CORS supported and enabled? Read more about " +
  100. // util.html.a(S.homepage + "/wiki/Compatibility", "CORS and compatibility") + ".",
  101. // "Is your " + util.html.a(S.homepage + "/wiki/Compatibility", "browser support") + "ed?",
  102. // "Hmm.. it might be a bug! Please file a report to " +
  103. // util.html.a(S.homepage + "/issues/", "the issues") + "."
  104. // );
  105. // } else if (messageName === "ERROR_UNKNOWN") {
  106. // message = "Unknown error.";
  107. // } else if (messageName === "NO_RESULTS") {
  108. // message = "Query returned no results.";
  109. // } else if (messageName === "DRAWING") {
  110. // message = "Received " + query.noRows + " rows. Drawing chart...<br/>" +
  111. // util.html.a(query.endpoint + query.endpoint_query_url + query.encodedQuery,
  112. // "View query results", "target='_blank'") + " (in new window).";
  113. // }
  114. // }
  115. // if (message) {
  116. // $('#' + container).append(util.html.tag("p", message));
  117. // }
  118. // }
  119. };
  120. }());
  121.