client.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  6. <meta name="description" content="">
  7. <meta name="author" content="">
  8. <link rel="icon" href="favicon.ico">
  9. <title>Fraud API client</title>
  10. <!-- Bootstrap core CSS -->
  11. <link href="dist/css/bootstrap.min.css" rel="stylesheet">
  12. <!-- Custom styles for this template -->
  13. <link href="dist/css/album.css" rel="stylesheet">
  14. </head>
  15. <body>
  16. <header>
  17. <div class="navbar navbar-dark bg-dark box-shadow">
  18. <div class="container d-flex justify-content-between">
  19. <a href="#" class="navbar-brand d-flex align-items-center">
  20. <strong>Fraud API client</strong>
  21. </a>
  22. <span class="btn btn-primary" id="new_doc" style="float:right;top:0;">New document</span>
  23. <span class="btn btn-warning" id="clear_btn" style="float:right;top:0;">Clear</span>
  24. </div>
  25. </div>
  26. </header>
  27. <main role="main">
  28. <div class="album py-5 bg-light">
  29. <div class="container">
  30. <div class="row" id="notification_container">
  31. </div>
  32. </div>
  33. </div>
  34. </main>
  35. <div class="modal modal-lg fade" id="fraud_check_modal" tabindex="-1" role="dialog" aria-labelledby="fraud_check" aria-hidden="true">
  36. <div class="modal-dialog" role="document">
  37. <div class="modal-content">
  38. <div class="modal-header">
  39. <h5 class="modal-title">Send document to fraud check</h5>
  40. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  41. <span aria-hidden="true">&times;</span>
  42. </button>
  43. </div>
  44. <div class="modal-body">
  45. <form>
  46. <div class="form-group">
  47. <label>Document name</label>
  48. <input type="text" class="form-control" placeholder="example.pdf" id="doc_name">
  49. </div>
  50. <div class="form-group">
  51. <label>Owner email</label>
  52. <input type="email" class="form-control" placeholder="owner@email.com" id="doc_owner">
  53. </div>
  54. <div class="form-group">
  55. <label>Content</label>
  56. <textarea class="form-control" rows="5" id="doc_content">Text goes here...</textarea>
  57. </div>
  58. </form>
  59. </div>
  60. <div class="modal-footer">
  61. <span class="btn btn-primary" onclick="send_document();" data-dismiss="modal">Send</span>
  62. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. <!-- Bootstrap core JavaScript
  68. ================================================== -->
  69. <!-- Placed at the end of the document so the pages load faster -->
  70. <script src="assets/js/vendor/jquery-slim.min.js"></script>
  71. <script src="assets/js/vendor/popper.min.js"></script>
  72. <script src="dist/js/bootstrap.min.js"></script>
  73. <script src="assets/js/vendor/holder.min.js"></script>
  74. <script>
  75. $(document).ready(function(){
  76. $('#new_doc').click(function(){$("#fraud_check_modal").modal().show();});
  77. $('#clear_btn').click(function(){clear_notifications();});
  78. get_notifications();
  79. setInterval(get_notifications, 1000);
  80. });
  81. function get_notifications(){
  82. $.get('http://127.0.0.1:8080/api/v1/notifications', function(data) {
  83. $('#notification_container').html('');
  84. data.forEach((item, i) => {
  85. $(notification_assembler(item)).appendTo($('#notification_container'));
  86. });
  87. });
  88. }
  89. function notification_assembler(item){
  90. return $.parseHTML(`<div class="col-md-4">
  91. <div class="card mb-4 box-shadow ${item.fraud ? 'alert alert-danger' : 'alert alert-success'}">
  92. <span class="card-text">${item.date}</span>
  93. <span class="card-text">${item.fraud ? '<span>Fraud detected in document:</span>' : '<span>No fraud detected in document:</span>'}</span>
  94. <div class="card-body">
  95. <strong class="card-text">${item.document.name}</strong><br>
  96. <span class="card-text">${item.document.owner}</span>
  97. </div>
  98. <span>${item.document.content.slice(0,270)}...</span>
  99. </div>
  100. </div>`);
  101. }
  102. function send_document(){
  103. $.ajax({
  104. contentType: 'application/json',
  105. data: JSON.stringify({name:$('#doc_name').val(), content:$('#doc_content').val(), owner:$('#doc_owner').val()}),
  106. dataType: 'json',
  107. type: 'POST',
  108. url: 'http://127.0.0.1:8080/api/v1/documents'
  109. });
  110. $("#fraud_check_modal").modal().hide();
  111. }
  112. function clear_notifications(){
  113. $.ajax({
  114. url: 'http://127.0.0.1:8080/api/v1/notifications',
  115. type: 'DELETE'
  116. });
  117. }
  118. </script>
  119. </body>
  120. </html>