An unfinished system to manage all your paper documentation in an easy way.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

autodoc.js 9.6KB

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