An unfinished system to manage all your paper documentation in an easy way.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 page_load_upload() {
  70. upload_status();
  71. }
  72. function document_load() {
  73. if (conf.home.curpage == 0) {
  74. $("#autodoc_home_body").html("");
  75. }
  76. var tmpl = $("#autodoc_template_home");
  77. var row = $(tmpl)
  78. .find(".autodoc_template_home_row")
  79. .clone();
  80. $.getJSON(
  81. conf.openapi +
  82. "/documents?pageSize=" +
  83. conf.home.width +
  84. "&pageIndex=" +
  85. conf.home.curpage,
  86. null,
  87. function (data, textStatus, jqXHR) {
  88. // last document was loaded, stop scrolling
  89. if (data.length < conf.home.width) {
  90. conf.home.end = 1;
  91. }
  92. $.each(data, function (id, doc) {
  93. var col = $(tmpl)
  94. .find(".autodoc_template_home_col")
  95. .clone();
  96. $(col)
  97. .find(".autodoc_template_home_img")
  98. .attr(
  99. "src",
  100. conf.openapi +
  101. "/documents/" +
  102. doc.id +
  103. "/image?maxWidth=" +
  104. Math.floor(1000 / conf.home.width)
  105. );
  106. $(col)
  107. .find(".autodoc_template_home_owner")
  108. .html(doc.owner);
  109. $(col)
  110. .find(".autodoc_template_home_created")
  111. .html(doc.created);
  112. $(col)
  113. .find(".autodoc_template_home_name")
  114. .html(doc.name);
  115. $.each(doc.tags, function (id, tag) {
  116. $(col)
  117. .find(".autodoc_template_home_tag")
  118. .after(
  119. $(col)
  120. .find(".autodoc_template_home_tag")
  121. .clone()
  122. .html(tag)
  123. );
  124. });
  125. $(row).append(col);
  126. });
  127. $("#autodoc_home_body").append(row);
  128. // continue to load until out of browser.
  129. page_home_scroll();
  130. }
  131. );
  132. }
  133. function page_home_scroll() {
  134. // don't scroll if we've loaded the last document
  135. if (conf.home.end) {
  136. return;
  137. }
  138. if (isvisible($(".autodoc_template_home_col").last())) {
  139. console.log("scroll to page " + conf.home.curpage);
  140. conf.home.curpage++;
  141. document_load();
  142. }
  143. }
  144. function upload_zone_init() {
  145. $(window).on("dragover dragleave drop", function (e) { e.preventDefault() });
  146. $('.autodoc_upload_zone').on({
  147. dragenter: upload_zone_highlight,
  148. dragleave: upload_zone_normal,
  149. dragover: upload_zone_over,
  150. drop: upload_zone_drop
  151. });
  152. }
  153. function upload_zone_highlight(e) {
  154. $(e.target).addClass('autodoc_upload_zone_hover');
  155. }
  156. function upload_zone_over(e) {
  157. return true;
  158. }
  159. function upload_zone_normal(e) {
  160. $(e.target).removeClass('autodoc_upload_zone_hover');
  161. }
  162. function upload_zone_drop(e) {
  163. var ev = e.originalEvent;
  164. $.each(ev.dataTransfer.files, function (id, file) {
  165. console.log(file);
  166. var fileid = temp.upload.length;
  167. temp.upload.push({
  168. progress: 0,
  169. error: null,
  170. obj: file
  171. });
  172. });
  173. upload_handler();
  174. }
  175. function upload_handler() {
  176. if (temp.documentid == null) {
  177. $.post(conf.openapi + "/documents", {}, function (data) {
  178. temp.documentid = data.id;
  179. });
  180. }
  181. else {
  182. for(var id=0; id<temp.upload.length; id++) {
  183. var file = temp.upload[id];
  184. if ( file.progress != 100 ) {
  185. if ( file.progress == 0 ) {
  186. if (file.obj.type != 'application/pdf' && file.obj.type != 'image/png' && file.obj.type != 'image/jpeg') {
  187. file['progress'] = 100;
  188. file['error'] = 'invalid file type';
  189. }
  190. else {
  191. var reader = new FileReader();
  192. file['progress'] = 1;
  193. $(reader).on('load', id, upload_read_event);
  194. $(reader).on('loadstart', id, upload_read_event);
  195. $(reader).on('loadend', id, upload_read_event);
  196. $(reader).on('progress', id, upload_read_event);
  197. $(reader).on('error', id, upload_read_event);
  198. $(reader).on('abort', id, upload_read_event);
  199. reader.readAsArrayBuffer(file.obj);
  200. }
  201. }
  202. break;
  203. }
  204. }
  205. }
  206. setTimeout("upload_handler", 1000);
  207. }
  208. function upload_read_event(e) {
  209. if ( e.type == 'progress' ) {
  210. if ( e.lengthComputable ) {
  211. var progress = Math.floor(e.originalEvent.loaded / e.originalEvent.total * 50);
  212. if ( progress < 1 ) { progress = 1; }
  213. if ( progress > 49 ) { progress = 49; }
  214. temp.upload[e.data]['progress'] = progress;
  215. }
  216. }
  217. else if ( e.type == 'load' ) {
  218. temp.upload[e.data]['progress'] = 50;
  219. console.log(e.target.result);
  220. $.ajax({
  221. type: 'POST',
  222. url: conf.openapi + "/documents/" + temp.documentid + "/data",
  223. data: e.target.result,
  224. contentType: temp.upload[e.data].obj.type,
  225. context: e.data,
  226. processData: false,
  227. xhr: function()
  228. {
  229. var xhr = new window.XMLHttpRequest();
  230. xhr.upload.addEventListener("progress", function(evt){
  231. if (evt.lengthComputable) {
  232. var percentComplete = evt.loaded / evt.total;
  233. console.log("upload_progress_event", evt);
  234. }
  235. }, false);
  236. return xhr;
  237. },
  238. success: function(data, status, xhr){
  239. console.log("upload_complete",data, status, xhr);
  240. }
  241. });
  242. }
  243. console.log(e);
  244. }
  245. function upload_status() {
  246. console.log("upload_status");
  247. $.each(temp.upload, function (id, file) {
  248. if ($('.autodoc_upload_status_' + id) === 'undefined') {
  249. var obj = $(".autodoc_template_progress").children().clone();
  250. $('.autodoc_upload_status').append(obj);
  251. }
  252. var obj = $('.autodoc_upload_status_' + id).children();
  253. if (file.error != null) {
  254. $(obj).html(file.obj.name + ': ' + file.error);
  255. $(obj).css('width', '100%');
  256. $(obj).addClass('bg-danger');
  257. $(obj).removeClass("progress-bar-animated");
  258. }
  259. else if (file.progress == 100) {
  260. $(obj).html(file.obj.name);
  261. $(obj).addClass('bg-success');
  262. $(obj).removeClass('progress-bar-animated');
  263. $(obj).css('width', '100%');
  264. }
  265. else if (file.progress < 50) {
  266. $(obj).html(file.obj.name + ': ' + 'reading file');
  267. $(obj).css('width', file.progress + '%');
  268. }
  269. else {
  270. $(obj).html(file.obj.name + ': ' + 'sending file');
  271. $(obj).css('width', file.progress + '%');
  272. }
  273. });
  274. setTimeout("upload_status", 100);
  275. }