BVB Source Codes

mongo-express Show collection.js Source code

Return Download mongo-express: download collection.js Source code - Download mongo-express Source code - Type:.js
  1. import $ from 'jquery';
  2. import renderjson from 'renderjson';
  3. import CodeMirror from './codeMirrorLoader';
  4.  
  5. const $document = $(document);
  6.  
  7. function getParameterByName(name) {
  8.   name = name.replace(/\[/, '\\[').replace(/[\]]/, '\\]');
  9.   const regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
  10.   const results = regex.exec(location.search);
  11.   return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
  12. }
  13.  
  14. $document.ready(function () {
  15.   $('#tabs').tab();
  16.   if (document.location.href.indexOf('query=') >= 0 && getParameterByName('query') !== '') {
  17.     $('#tabs a[href="#advanced"]').tab('show');
  18.   }
  19. });
  20.  
  21. const addDoc = CodeMirror.fromTextArea(document.getElementById('document'), {
  22.   mode: { name: 'javascript', json: true },
  23.   indentUnit: 4,
  24.   electricChars: true,
  25.   matchBrackets: true,
  26.   lineNumbers: true,
  27.   theme: ME_SETTINGS.codeMirrorEditorTheme,
  28. });
  29.  
  30. window.checkValidJSON = function () {
  31.   $.ajax({
  32.     type: 'POST',
  33.     url: `${ME_SETTINGS.baseHref}checkValid`,
  34.     data: {
  35.       document: addDoc.getValue(),
  36.     },
  37.   }).done((data) => {
  38.     if (data === 'Valid') {
  39.       $('#documentInvalidJSON').remove();
  40.       $('#addDocumentForm').submit();
  41.     } else if ($('#documentInvalidJSON').length === 0) {
  42.       $('.modal-body').parent().append('<div id="documentInvalidJSON" class="alert alert-danger"><strong>Invalid JSON</strong></div>');
  43.     }
  44.   });
  45.   return false;
  46. };
  47.  
  48. $('#addDocument').on('shown.bs.modal', function () {
  49.   addDoc.refresh();
  50.   addDoc.focus();
  51. });
  52.  
  53. if (ME_SETTINGS.collapsibleJSON) {
  54.   $(function () {
  55.     const $this = $(this);
  56.     // convert all objects to renderjson elements
  57.     $('div.tableContent pre').each(function () {
  58.       var text = $.trim($this.text());
  59.  
  60.       if (text) {
  61.         $this.html(renderjson(JSON.parse(text)));
  62.       }
  63.     });
  64.   });
  65.   renderjson.set_show_to_level(ME_SETTINGS.collapsibleJSONDefaultUnfold);
  66. }
  67.  
  68. function makeCollectionUrl() {
  69.   const st = ME_SETTINGS;
  70.   return `${st.baseHref}db/${st.dbName}/${st.collectionName}/`;
  71. }
  72.  
  73. window.loadDocument = function (id) {
  74.   location.href = `${makeCollectionUrl()}${encodeURIComponent(id)}`;
  75. };
  76.  
  77. $document.ready(function () {
  78.   const $tableWrapper = $('.tableWrapper');
  79.   if ($('.tableHeaderFooterBars').width() === $tableWrapper.width()) {
  80.     // table wrapper is the same width as the table itself, so not overflowing, so remove the white gradient
  81.     $('.fadeToWhite').remove();
  82.   } else {
  83.     $('.fadeToWhite').height($('.tableWrapper').height()); // limit the height only to the table div
  84.   }
  85.  
  86.   $('.deleteButtonCollection').tooltip({
  87.     title: 'Are you sure you want to delete this collection? All documents will be deleted.',
  88.   });
  89.  
  90.   $tableWrapper.scroll(function () {
  91.     const proximityToRightOfTable = $('.tableWrapper table').width() - $tableWrapper.scrollLeft() - $tableWrapper.width();
  92.     document.getElementById('fadeToWhiteID').style.opacity = Math.min(Math.max(proximityToRightOfTable - 50, 50) - 50, 100) / 100;
  93.   });
  94.  
  95.   $('.tooDamnBig').bind('click', function (e) {
  96.     e.preventDefault();
  97.     e.stopPropagation();
  98.  
  99.     const target = $(this);
  100.     const _id = target.attr('doc_id');
  101.     const prop = target.attr('doc_prop');
  102.     const spinner = `<img src="${ME_SETTINGS.baseHref}public/img/gears.gif" />`;
  103.     const leftScroll = $tableWrapper.scrollLeft();
  104.  
  105.     // Set the element with spinner for now
  106.     target.html(spinner);
  107.  
  108.     $.get(`${makeCollectionUrl()}${encodeURIComponent(_id)}/${prop}`, function (input) {
  109.  
  110.       // Images inline
  111.       if (
  112.         typeof input === 'string' &&
  113.         (
  114.           input.substr(0, 22) === 'data:image/png;base64,' ||
  115.           input.substr(0, 22) === 'data:image/gif;base64,' ||
  116.           input.substr(0, 22) === 'data:image/jpg;base64,' ||
  117.           input.substr(0, 23) === 'data:image/jpeg;base64,'
  118.         )
  119.       )  {
  120.         input = '<img src="' + input + '" style="max-height:100%; max-width:100%; "/>';
  121.       }
  122.  
  123.       // Audio inline
  124.       if (
  125.         typeof input === 'string' &&
  126.         (
  127.           input.substr(0, 22) === 'data:audio/ogg;base64,' ||
  128.           input.substr(0, 22) === 'data:audio/mp3;base64,'
  129.         )
  130.       )  {
  131.         input = '<audio controls style="width:45px;" src="' + input + '">Your browser does not support the audio element.</audio>';
  132.       }
  133.  
  134.       // Video inline
  135.       if (
  136.         typeof input === 'string' &&
  137.         (
  138.           input.substr(0, 23) === 'data:video/webm;base64,' ||
  139.           input.substr(0, 22) === 'data:video/mp4;base64,'  ||
  140.           input.substr(0, 22) === 'data:video/ogv;base64,'
  141.         )
  142.       )  {
  143.         input = '<video controls><source type="' + input.substring(input.indexOf(':') + 1, input.indexOf(';')) + '" src="' + input + '"/>' +
  144.           'Your browser does not support the video element.</video>';
  145.       }
  146.  
  147.       if (typeof input === 'object' && (input.toString() === '[object Object]' || input.toString().substr(0, 7) === '[object')) {
  148.         input = renderjson(input);
  149.       }
  150.  
  151.       // Set the element with gotten datas
  152.       target.parent().html(input);
  153.  
  154.       // Set original scroll position
  155.       $('.tableWrapper').scrollLeft(leftScroll);
  156.     });
  157.   });
  158.  
  159.   $('.deleteButtonDocument').on('click', function (e) {
  160.     const $form = $(this).closest('form');
  161.     e.stopPropagation();
  162.     e.preventDefault();
  163.  
  164.     $('#confirm-deletion-document').modal({ backdrop: 'static', keyboard: false }).one('click', '#delete', function () {
  165.       $form.trigger('submit'); // submit the form
  166.     });
  167.   });
  168.  
  169.   $('#deleteListConfirmButton').on('click', function () {
  170.     // we just need to POST the form, as all the query parameters are already embedded in the form action
  171.     $('#deleteListForm').trigger('submit');
  172.   });
  173.  
  174.   $('.deleteButtonCollection').on('click', function (event) {
  175.  
  176.     $('.deleteButtonCollection').tooltip('hide');
  177.  
  178.     event.preventDefault();
  179.  
  180.     const $target = $(this);
  181.     const $parentForm = $('#' + $target.attr('childof'));
  182.  
  183.     $('#confirmation-input').attr('shouldbe', $target.attr('collection-name'));
  184.     $('#modal-collection-name').text($target.attr('collection-name'));
  185.     $('#confirm-deletion-collection').modal({ backdrop: 'static', keyboard: false })
  186.       .one('shown.bs.modal', function () {
  187.         $('#confirmation-input').focus();
  188.       })
  189.       .one('click', '#delete', function () {
  190.         const $input = $('#confirmation-input');
  191.         if ($input.val().toLowerCase() === $input.attr('shouldbe').toLowerCase()) {
  192.           $parentForm.trigger('submit');
  193.         }
  194.       });
  195.   });
  196.  
  197.   const nextSort = {
  198.     1: -1,
  199.     '-1': 0,
  200.     0: 1,
  201.     undefined: 1,
  202.   };
  203.   $('.sorting-button').on('click', function () {
  204.     const $this = $(this);
  205.     const column = $this.data('column');
  206.     const direction = nextSort[$this.data('direction')];
  207.  
  208.     $('input.sort-' + column).val(direction).prop('checked', direction !== 0);
  209.  
  210.     const $form = $($('#tabs li.active a').attr('href') + ' form');
  211.     $form.find('button[type="submit"]').click();
  212.   });
  213. });
  214.  
downloadcollection.js Source code - Download mongo-express Source code
Related Source Codes/Software:
XCL-Charts - Android charting libraries (XCL-Charts is a free c... 2017-05-17
scrollMonitor - A simple and fast API to monitor elements as you s... 2017-05-16
XCDYouTubeKit - YouTube video player for iOS, tvOS and macOS 2017-05-16
rails-erd - Generate Entity-Relationship Diagrams for Rails ap... 2017-05-16
np - A better `npm publish` 2017-05-16
kaminari - A Scope & Engine based, clean, powerful, custo... 2017-06-04
python-fire - Python Fire is a library for automatically generat... 2017-06-04
Dapper - Dapper - a simple object mapper for .Net 2017-06-05
pkg - Package your Node.js project into an executable ... 2017-06-05
packer - Packer is a tool for creating identical machine im... 2017-06-05
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top