An unfinished system to manage all your paper documentation in an easy way.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

autodoc.js 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /* AutoDoc Javascript */
  2. var conf = {
  3. default_hash: "home",
  4. openapi: "/v1",
  5. pageinit: {
  6. home: "page_load_home()"
  7. },
  8. home: {
  9. width: 4,
  10. curpage: 0,
  11. end: 0
  12. }
  13. };
  14. var temp = {
  15. upload: [],
  16. documentid: null
  17. };
  18. $(document).ready(function () {
  19. change_page();
  20. upload_zone_init();
  21. $(document).scroll(function () {
  22. page_home_scroll();
  23. });
  24. });
  25. $(window).bind("hashchange", function () {
  26. change_page();
  27. });
  28. function change_page() {
  29. var hash = document.location.hash.substr(1) || conf.default_hash;
  30. if (!$("#autodoc_tab_" + hash).length) {
  31. hash = conf.default_hash;
  32. }
  33. /* change menu highlights and content visibility */
  34. $("#autodoc_navbar")
  35. .find("a")
  36. .each(function (id, obj) {
  37. var curhash = $(obj)
  38. .attr("href")
  39. .substr(1);
  40. if (curhash == hash) {
  41. $(obj)
  42. .parent()
  43. .addClass("active");
  44. $("#autodoc_tab_" + curhash).removeClass("d-none");
  45. } else {
  46. $(obj)
  47. .parent()
  48. .removeClass("active");
  49. $("#autodoc_tab_" + curhash).addClass("d-none");
  50. }
  51. });
  52. if (conf.pageinit[hash]) {
  53. eval(conf.pageinit[hash]);
  54. }
  55. }
  56. function isvisible(obj) {
  57. var top_of_fileent = $(obj).offset().top;
  58. var bottom_of_fileent = $(obj).offset().top + $(obj).outerHeight();
  59. var bottom_of_screen = $(window).scrollTop() + $(window).innerHeight();
  60. var top_of_screen = $(window).scrollTop();
  61. if (bottom_of_screen > top_of_fileent && top_of_screen < bottom_of_fileent) {
  62. return true;
  63. }
  64. return false;
  65. }
  66. function page_load_home() {
  67. document_load();
  68. }
  69. function document_load() {
  70. if (conf.home.curpage == 0) {
  71. $("#autodoc_home_body").html("");
  72. }
  73. var tmpl = $("#autodoc_template_home");
  74. var row = $(tmpl)
  75. .find(".autodoc_template_home_row")
  76. .clone();
  77. $.getJSON(
  78. conf.openapi +
  79. "/documents?pageSize=" +
  80. conf.home.width +
  81. "&pageIndex=" +
  82. conf.home.curpage,
  83. null,
  84. function (data, textStatus, jqXHR) {
  85. // last document was loaded, stop scrolling
  86. if (data.length < conf.home.width) {
  87. conf.home.end = 1;
  88. }
  89. $.each(data, function (id, doc) {
  90. var col = $(tmpl)
  91. .find(".autodoc_template_home_col")
  92. .clone();
  93. $(col)
  94. .find(".autodoc_template_home_img")
  95. .attr(
  96. "src",
  97. conf.openapi +
  98. "/documents/" +
  99. doc.id +
  100. "/image?maxWidth=" +
  101. Math.floor(1000 / conf.home.width)
  102. );
  103. $(col)
  104. .find(".autodoc_template_home_owner")
  105. .html(doc.owner);
  106. $(col)
  107. .find(".autodoc_template_home_created")
  108. .html(doc.created);
  109. $(col)
  110. .find(".autodoc_template_home_name")
  111. .html(doc.name);
  112. $.each(doc.tags, function (id, tag) {
  113. $(col)
  114. .find(".autodoc_template_home_tag")
  115. .after(
  116. $(col)
  117. .find(".autodoc_template_home_tag")
  118. .clone()
  119. .html(tag)
  120. );
  121. });
  122. $(row).append(col);
  123. });
  124. $("#autodoc_home_body").append(row);
  125. // continue to load until out of browser.
  126. page_home_scroll();
  127. }
  128. );
  129. }
  130. function page_home_scroll() {
  131. // don't scroll if we've loaded the last document
  132. if (conf.home.end) {
  133. return;
  134. }
  135. if (isvisible($(".autodoc_template_home_col").last())) {
  136. console.log("scroll to page " + conf.home.curpage);
  137. conf.home.curpage++;
  138. document_load();
  139. }
  140. }
  141. function upload_zone_init() {
  142. $(window).on("dragover dragleave drop", function (e) { e.preventDefault() });
  143. $('.autodoc_upload_zone').on({
  144. dragenter: upload_zone_highlight,
  145. dragleave: upload_zone_normal,
  146. dragover: upload_zone_over,
  147. drop: upload_zone_drop
  148. });
  149. }
  150. function upload_zone_highlight(e) {
  151. $(e.target).addClass('autodoc_upload_zone_hover');
  152. }
  153. function upload_zone_over(e) {
  154. return true;
  155. }
  156. function upload_zone_normal(e) {
  157. $(e.target).removeClass('autodoc_upload_zone_hover');
  158. }
  159. function upload_zone_drop(e) {
  160. var ev = e.originalEvent;
  161. $.each(ev.dataTransfer.files, function (id, file) {
  162. console.log(file);
  163. var fileid = temp.upload.length;
  164. temp.upload.push({
  165. progress: 0,
  166. error: null,
  167. obj: file
  168. });
  169. });
  170. upload_handler();
  171. }
  172. function upload_handler() {
  173. if (temp.documentid == null) {
  174. $.post(conf.openapi + "/documents", {}, function (data) {
  175. temp.documentid = data.id;
  176. });
  177. }
  178. else {
  179. for(var id=0; id<temp.upload.length; id++) {
  180. var file = temp.upload[id];
  181. if ( file.progress != 100 ) {
  182. if ( file.progress == 0 ) {
  183. if (file.obj.type != 'application/pdf' && file.obj.type != 'image/png' && file.obj.type != 'image/jpeg') {
  184. file['progress'] = 100;
  185. file['error'] = 'invalid file type';
  186. }
  187. else {
  188. var reader = new FileReader();
  189. file['progress'] = 1;
  190. $(reader).on('load', id, upload_read_event);
  191. $(reader).on('loadstart', id, upload_read_event);
  192. $(reader).on('loadend', id, upload_read_event);
  193. $(reader).on('progress', id, upload_read_event);
  194. $(reader).on('error', id, upload_read_event);
  195. $(reader).on('abort', id, upload_read_event);
  196. reader.readAsArrayBuffer(file.obj);
  197. }
  198. }
  199. break;
  200. }
  201. }
  202. }
  203. setTimeout("upload_handler", 1000);
  204. }
  205. function upload_read_event(e) {
  206. if ( e.type == 'progress' ) {
  207. if ( e.lengthComputable ) {
  208. var progress = Math.floor(e.originalEvent.loaded / e.originalEvent.total * 50);
  209. if ( progress < 1 ) { progress = 1; }
  210. if ( progress > 49 ) { progress = 49; }
  211. temp.upload[e.data]['progress'] = progress;
  212. }
  213. }
  214. else if ( e.type == 'load' ) {
  215. temp.upload[e.data]['progress'] = 50;
  216. console.log(e.target.result);
  217. $.ajax({
  218. type: 'POST',
  219. url: conf.openapi + "/documents/" + temp.documentid + "/data",
  220. data: e.target.result,
  221. contentType: temp.upload[e.data].obj.type,
  222. context: e.data,
  223. processData: false,
  224. xhr: function()
  225. {
  226. var xhr = new window.XMLHttpRequest();
  227. xhr.upload.addEventListener("progress", function(evt){
  228. if (evt.lengthComputable) {
  229. var percentComplete = evt.loaded / evt.total;
  230. console.log("upload_progress_event", evt);
  231. }
  232. }, false);
  233. return xhr;
  234. },
  235. success: function(data, status, xhr){
  236. console.log("upload_complete",data, status, xhr);
  237. }
  238. });
  239. }
  240. console.log(e);
  241. }
  242. function upload_status() {
  243. console.log("upload_status");
  244. $.each(temp.upload, function (id, file) {
  245. if ($('.autodoc_upload_status_' + id) === 'undefined') {
  246. var obj = $(".autodoc_template_progress").children().clone();
  247. $('.autodoc_upload_status').append(obj);
  248. }
  249. var obj = $('.autodoc_upload_status_' + id).children();
  250. if (file.error != null) {
  251. $(obj).html(file.obj.name + ': ' + file.error);
  252. $(obj).css('width', '100%');
  253. $(obj).addClass('bg-danger');
  254. $(obj).removeClass("progress-bar-animated");
  255. }
  256. else if (file.progress == 100) {
  257. $(obj).html(file.obj.name);
  258. $(obj).addClass('bg-success');
  259. $(obj).removeClass('progress-bar-animated');
  260. $(obj).css('width', '100%');
  261. }
  262. else if (file.progress < 50) {
  263. $(obj).html(file.obj.name + ': ' + 'reading file');
  264. $(obj).css('width', file.progress + '%');
  265. }
  266. else {
  267. $(obj).html(file.obj.name + ': ' + 'sending file');
  268. $(obj).css('width', file.progress + '%');
  269. }
  270. });
  271. setTimeout("upload_status", 100);
  272. }