history.js.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: history.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: history.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>/**
  20. * An object for displaying the user's coding logs (their history).
  21. * A lightweight component, its only job is to open a dialog.
  22. *
  23. * @constructor
  24. * @this {BlockPyHistory}
  25. * @param {Object} main - The main BlockPy instance
  26. */
  27. function BlockPyHistory(main) {
  28. this.main = main;
  29. }
  30. var monthNames = [
  31. "Jan", "Feb", "Mar",
  32. "Apr", "May", "June", "July",
  33. "Aug", "Sept", "Oct",
  34. "Nov", "Dec"
  35. ];
  36. var weekDays = [
  37. "Sun", "Mon", "Tue",
  38. "Wed", "Thu", "Fri",
  39. "Sat"
  40. ];
  41. /**
  42. * Helper function to parse a date/time string and rewrite it as something
  43. * more human readable.
  44. * @param {String} timeString - the string representation of time ("YYYYMMDD HHMMSS")
  45. * @returns {String} - A human-readable time string.
  46. */
  47. function prettyPrintDateTime(timeString) {
  48. var year = timeString.slice(0, 4),
  49. month = parseInt(timeString.slice(4, 6), 10)-1,
  50. day = timeString.slice(6, 8),
  51. hour = timeString.slice(9, 11),
  52. minutes = timeString.slice(11, 13),
  53. seconds = timeString.slice(13, 15);
  54. var date = new Date(year, month, day, hour, minutes, seconds);
  55. var dayStr = weekDays[date.getDay()];
  56. var monthStr = monthNames[date.getMonth()];
  57. var yearFull = date.getFullYear();
  58. var complete = dayStr+", "+monthStr+" "+date.getDate()+", "+yearFull+" at "+date.toLocaleTimeString();
  59. return complete;
  60. }
  61. /**
  62. * Opens the history dialog box. This requires a trip to the server and
  63. * occurs asynchronously. The users' code is shown in preformatted text
  64. * tags (no code highlighting currently) along with the timestamp.
  65. */
  66. BlockPyHistory.prototype.openDialog = function() {
  67. var dialog = this.main.components.dialog;
  68. var body = "&lt;pre>a = 0&lt;/pre>";
  69. this.main.components.server.getHistory(function (data) {
  70. body = data.reverse().reduce(function (complete, elem) {
  71. var complete_str = prettyPrintDateTime(elem.time);
  72. var new_line = "&lt;b>"+complete_str+"&lt;/b>&lt;br>&lt;pre>"+elem.code+"&lt;/pre>";
  73. return complete+"\n"+new_line;
  74. }, "");
  75. dialog.show("Work History", body, function() {});
  76. });
  77. };</code></pre>
  78. </article>
  79. </section>
  80. </div>
  81. <nav>
  82. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BlockPy.html">BlockPy</a></li><li><a href="BlockPyCorgis.html">BlockPyCorgis</a></li><li><a href="BlockPyDialog.html">BlockPyDialog</a></li><li><a href="BlockPyEditor.html">BlockPyEditor</a></li><li><a href="BlockPyEngine.html">BlockPyEngine</a></li><li><a href="BlockPyEnglish.html">BlockPyEnglish</a></li><li><a href="BlockPyFeedback.html">BlockPyFeedback</a></li><li><a href="BlockPyHistory.html">BlockPyHistory</a></li><li><a href="BlockPyPresentation.html">BlockPyPresentation</a></li><li><a href="BlockPyPrinter.html">BlockPyPrinter</a></li><li><a href="BlockPyServer.html">BlockPyServer</a></li><li><a href="BlockPyToolbar.html">BlockPyToolbar</a></li><li><a href="LocalStorageWrapper.html">LocalStorageWrapper</a></li><li><a href="PythonToBlocks.html">PythonToBlocks</a></li></ul><h3>Global</h3><ul><li><a href="global.html#BlockPyInterface">BlockPyInterface</a></li><li><a href="global.html#cloneNode">cloneNode</a></li><li><a href="global.html#encodeHTML">encodeHTML</a></li><li><a href="global.html#expandArray">expandArray</a></li><li><a href="global.html#EXTENDED_ERROR_EXPLANATION">EXTENDED_ERROR_EXPLANATION</a></li><li><a href="global.html#indent">indent</a></li><li><a href="global.html#instructor_module">instructor_module</a></li><li><a href="global.html#prettyPrintDateTime">prettyPrintDateTime</a></li><li><a href="global.html#randomInteger">randomInteger</a></li><li><a href="global.html#set_button_loaded">set_button_loaded</a></li><li><a href="global.html#timerGuard">timerGuard</a></li></ul>
  83. </nav>
  84. <br class="clear">
  85. <footer>
  86. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Sun Mar 26 2017 09:45:03 GMT-0400 (Eastern Daylight Time)
  87. </footer>
  88. <script> prettyPrint(); </script>
  89. <script src="scripts/linenumber.js"> </script>
  90. </body>
  91. </html>