1
0

userLog.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. let clicks = [];
  2. let inRebuildMode = false;
  3. export const ActionTypes = Object.freeze({
  4. // registerUserEvent payload:
  5. // (function_name, insert action)
  6. INSERT_FUNCTION:"INSERT_FUNCTION",
  7. // (function_name, remove action)
  8. REMOVE_FUNCTION:"REMOVE_FUNCTION",
  9. // (var_name,insert action, type, dim)
  10. INSERT_GLOBAL_VAR:"INSERT_GLOBAL_VAR",
  11. // (var name, remove action)
  12. REMOVE_GLOBAL_VAR:"REMOVE_GLOBAL_VAR",
  13. // (old function name, rename action, new function name)
  14. RENAME_FUNCTION:"RENAME_FUNCTION",
  15. // (old var name, rename action. new var name)
  16. RENAME_GLOBAL_VAR:"RENAME_GLOBAL_VAR",
  17. // (var name, set const action)
  18. SET_GLOBAL_CONST:"SET_GLOBAL_CONST",
  19. // (function name, change return action, type, dim)
  20. CHANGE_FUNCTION_RETURN:"CHANGE_FUNCTION_RETURN",
  21. // (var name, change type action, type, dim, rows?, columns?)
  22. CHANGE_GLOBAL_TYPE:"CHANGE_GLOBAL_TYPE",
  23. // (var name, change value action, value)
  24. CHANGE_GLOBAL_VALUE:"CHANGE_GLOBAL_VALUE",
  25. // (function name, insert param action, param varname, type, dim)
  26. INSERT_FUNCTION_PARAM:"INSERT_FUNCTION_PARAM",
  27. // (function name, remove param action, param varname)
  28. REMOVE_FUNCTION_PARAM:"REMOVE_FUNCTION_PARAM",
  29. // (function name, change param type action, type, dim)
  30. CHANGE_PARAM_TYPE:"CHANGE_PARAM_TYPE",
  31. // (function name, rename param action, old param name, new param name)
  32. RENAME_FUNCTION_PARAM:"RENAME_FUNCTION_PARAM",
  33. // (function name, insert var action, var name, type, dim)
  34. INSERT_FUNCTION_VAR:"INSERT_FUCNTION_VAR",
  35. // (function name, remove var action, var name)
  36. REMOVE_FUNCTION_VAR:"REMOVE_FUNCTION_VAR",
  37. // (function name, rename var action, old var name, new var name)
  38. RENAME_FUNCTION_VAR:"RENAME_FUNCTION_VAR",
  39. // (function name, change var type action, var name, type, dim, rows?, columns?)
  40. CHANGE_VAR_TYPE:"CHANGE_VAR_TYPE",
  41. // (function name, change var value action, var name, value)
  42. CHANGE_VAR_VALUE:"CHANGE_VAR_VALUE",
  43. // (function name, insert command action, command, path)
  44. INSERT_COMMAND:"INSERT_COMMAND",
  45. // (function name, remove command action, path)
  46. REMOVE_COMMAND:"REMOVE_COMMAND",
  47. // (function name, change command exp action, path, exp)
  48. CHANGE_COMMAND_EXP:"CHANGE_COMMAND_EXP",
  49. // (function name, change attrib exp action, path, exp)
  50. CHANGE_ATTRIB_EXP:"CHANGE_ATTRIB_EXP",
  51. // (function name, change attrib var action, path, var name, row_exp?, column_exp?)
  52. CHANGE_ATTRIB_VAR:"CHANGE_ATTRIB_VAR",
  53. // (function name, move command action, old path, new path)
  54. MOVE_COMMAND:"MOVE_COMMAND",
  55. // (function name, enter change name action, var name)
  56. ENTER_CHANGE_VAR_NAME:'ENTER_CHANGE_VAR_NAME',
  57. // (function name, enter change value action, var name)
  58. ENTER_CHANGE_VAR_VALUE:'ENTER_CHANGE_VAR_VALUE',
  59. // (var name, enter change name action)
  60. ENTER_CHANGE_GLOBAL_NAME:'ENTER_CHANGE_GLOBAL_NAME',
  61. // (var name, enter change value action)
  62. ENTER_CHANGE_GLOBAL_VALUE:'ENTER_CHANGE_GLOBAL_VALUE',
  63. // (function name, enter change name action, param name)
  64. ENTER_CHANGE_PARAM_NAME:'ENTER_CHANGE_PARAM_NAME',
  65. });
  66. export function registerClick (x, y, details) {
  67. if (inRebuildMode) {
  68. return;
  69. }
  70. clicks.push([x, y, Date.now(), details]);
  71. }
  72. export function registerUserEvent (command, action, ...params) {
  73. registerEvent('user_event', command, action, params);
  74. }
  75. export function registerSystemEvent (command, action, ...params) {
  76. registerEvent('system_event', command, action, params);
  77. }
  78. function registerEvent (tag, command, action, params) {
  79. if (inRebuildMode) {
  80. return;
  81. }
  82. const event = {context: command, action: action, params:params};
  83. clicks.push([tag, Date.now(), event]);
  84. }
  85. export function getLogs () {
  86. return clicks;
  87. }
  88. export function setRebuildMode (flag) {
  89. inRebuildMode = flag;
  90. }
  91. export function getLogsAsString () {
  92. return JSON.stringify(clicks);
  93. }
  94. export function parseLogs (logData) {
  95. clicks = JSON.parse(logData);
  96. }