From 752801b8ebfb0242513885e7c53c994e3fad822c Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Feb 27 2019 21:09:30 +0000 Subject: Ticket 50215 - UI - implement Database Tab in reachJS Description: Implement database tab in ReactJS. https://pagure.io/389-ds-base/issue/50215 Reviewed by: spichugi & firstyear (Thanks!!) --- diff --git a/src/cockpit/389-console/.eslintrc.json b/src/cockpit/389-console/.eslintrc.json index ee0a235..11a82c8 100644 --- a/src/cockpit/389-console/.eslintrc.json +++ b/src/cockpit/389-console/.eslintrc.json @@ -44,8 +44,7 @@ "eqeqeq": "off", "import/no-webpack-loader-syntax": "off", "object-property-newline": "off", - "react/jsx-no-bind": "off", - "max-len": ["error", { "code": 100 }] + "react/jsx-no-bind": "off" }, "globals": { "require": false, diff --git a/src/cockpit/389-console/src/backend.html b/src/cockpit/389-console/src/backend.html deleted file mode 100644 index c209f96..0000000 --- a/src/cockpit/389-console/src/backend.html +++ /dev/null @@ -1,1007 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/cockpit/389-console/src/backend.js b/src/cockpit/389-console/src/backend.js deleted file mode 100644 index f396b89..0000000 --- a/src/cockpit/389-console/src/backend.js +++ /dev/null @@ -1,956 +0,0 @@ -var prev_tree_node = null; -var ref_del_html = ""; -var attr_encrypt_del_html = ""; -var index_btn_html = - ''; - - -var chaining_attr_map = { - 'nsbindconnectionslimit': '--conn-bind-limit', - 'nsoperationconnectionslimit': '--conn-op-limit', - 'nsabandonedsearchcheckinterval': '--abandon-check-interval', - 'nsconcurrentbindlimit': '--bind-limit', - 'nsconcurrentoperationslimit': '--op-limit', - 'nsproxiedauthorization': '--proxied-auth', - 'nsconnectionlife': '--conn-lifetime', - 'nsbindtimeout': '--bind-timeout', - 'nsreferralonscopedsearch': '--return-ref', - 'nschecklocalaci': '--check-aci', - 'nsbindretrylimit': '--bind-attempts', - 'nsslapd-sizelimit': '--size-limit', - 'nsslapd-timelimit': '--time-limit', - 'nshoplimit': '--hop-limit', - 'nsmaxresponsedelay': '--response-delay', - 'nsmaxtestresponsedelay': '--test-response-delay', - 'nsusestarttls':'--use-starttls' , - 'nsfarmserverurl': '--server-url', - 'nsbindmechanism': '--bind-mech', - 'nsmultiplexorbinddn': '--bind-dn', - 'nsmultiplexorcredentials': '--bind-pw' -}; - -function customMenu (node) { - var dblink_items = { - "delete_link": { - "label": "Delete DB Link", - "icon": "glyphicon glyphicon-trash", - "action": function (data) { - popup_confirm("Are you sure you want to delete this Database Link?", "Confirmation", function (yes) { - if (yes) { - - // TODO Delete db link - } - }); - } - } - }; - - var suffix_items = { - 'import': { - "label": "Initialize Suffix", - "icon": "glyphicon glyphicon-circle-arrow-right", - "action": function (data) { - var suffix_id = $(node).attr('id'); - var parent_suffix = suffix_id.substring(suffix_id.indexOf('-')+1); - $("#root-suffix-import").val(parent_suffix); - $("#import-ldif-file").val(""); - $("#import-ldif-form").modal('toggle'); - } - }, - 'export': { - "label": "Export Suffix", - "icon": "glyphicon glyphicon-circle-arrow-left", - "action": function (data) { - var suffix_id = $(node).attr('id'); - var parent_suffix = suffix_id.substring(suffix_id.indexOf('-')+1); - $("#root-suffix-export").val(parent_suffix); - $("#export-ldif-file").val(""); - $("#export-ldif-form").modal('toggle'); - } - }, - 'reindex': { - "label": "Reindex Suffix", - "icon": "glyphicon glyphicon-wrench", - "action": function (data) { - popup_confirm("This will impact DB performance during the indexing. Are you sure you want to reindex all attributes?", "Confirmation", function (yes) { - if (yes) { - // TODO Reindex suffix - } - }); - } - }, - "create_db_link": { - "label": "Create Database Link", - "icon": "glyphicon glyphicon-link", - "action": function (data) { - var suffix_id = $(node).attr('id'); - var parent_suffix = suffix_id.substring(suffix_id.indexOf('-')+1); - //clear_chaining_form(); //TODO - $("#create-db-link-form").modal('toggle'); - } - }, - "create_sub_suffix": { - "label": "Create Sub-Suffix", - "icon": "glyphicon glyphicon-triangle-bottom", - "action": function (data) { - var suffix_id = $(node).attr('id'); - var parent_suffix = suffix_id.substring(suffix_id.indexOf('-')+1); - $("#parent-suffix").html('Parent Suffix:  ' + parent_suffix); - $("#add-subsuffix-dn").val(' ,' + parent_suffix); - $("#add-subsuffix-form").modal('toggle'); - } - }, - 'delete_suffix': { - "label": "Delete Suffix", - "icon": "glyphicon glyphicon-remove", - "action": function (data) { - popup_confirm("Are you sure you want to delete suffix?", "Confirmation", function (yes) { - if (yes) { - // TODO - } - }); - } - } - }; - - if ( $(node).attr('id').startsWith('suffix') ){ - return suffix_items; - } else { - // chaining - return dblink_items; - } -}; - -function get_encoded_ref () { - var ref_encoded = $("#ref-protocol").val() + $("#ref-hostname").val(); - var ref_port = $("#ref-port").val(); - var ref_suffix = $("#ref-suffix").val(); - var ref_attrs = $("#ref-attrs").val(); - var ref_filter = $("#ref-filter").val(); - var ref_scope = $("#ref-scope").val(); - - $("#preview-ref-btn").blur(); - - if (ref_port != ""){ - ref_encoded += ":" + ref_port; - } - - if (ref_suffix == "" && (ref_attrs != "" || ref_filter != "" || ref_scope != "")) { - popup_msg("Attention!", "Missing suffix - you can not set the attributes, scope, or filter without a suffix."); - return; - } - if (ref_suffix != "" || ref_attrs != "" || ref_filter != "" || ref_scope != "") { - ref_encoded += "/" + encodeURIComponent(ref_suffix); - if ( ref_attrs != "" ) { - ref_encoded += "?" + encodeURIComponent(ref_attrs); - } else if ( ref_filter != "" || ref_scope != "" ) { - ref_encoded += "?"; - } - if ( ref_scope != "" ) { - ref_encoded += "?" + encodeURIComponent(ref_scope); - } else if ( ref_filter != "" ) { - ref_encoded += "?"; - } - if ( ref_filter != "") { - ref_encoded += "?" + encodeURIComponent(ref_filter); - } - } - return ref_encoded; -} - -function load_jstree() { - $('#db-tree').jstree({ - "plugins": [ "contextmenu", "wholerow", "sort" ], - "contextmenu": { - "items" : customMenu - }, - "core": { - "check_callback": true - } - }); - - $('#db-tree').jstree('select_node', 'ul > li:first'); - - - $('#db-tree').on("changed.jstree", function (e, data) { - var node_type = data.selected[0]; - var suffix = data.instance.get_node(data.selected[0]).text.replace(/(\r\n|\n|\r)/gm,""); - - if (node_type.startsWith("dblink")) { - var parent_suffix = node_type.substring(node_type.indexOf('-')+1); - $(".all-pages").hide(); - $("#database-content").show(); - $("#db-page").show(); - $("#chaining-header").html("Database Chaining Configuration (" + parent_suffix + ")"); - $("#chaining-page").show(); - } else { - // suffix - $(".all-pages").hide(); - $("#database-content").show(); - $("#db-page").show(); - $("#suffix-header").html("Suffix Configuration (" + suffix + ")"); - $("#suffix-page").show(); - } - }); -}; - -function clear_ref_form () { - $("#ref-scope").prop('selectedIndex',0); - $("#ref-protocol").prop('selectedIndex',0); - $("#ref-suffix").val(""); - $("#ref-filter").val(""); - $("#ref-hostname").val(""); - $("#ref-port").val(""); - $("#ref-attrs").val(""); - $("#ref-preview-field").val(""); -} - -function clear_index_form () { - $("#index-list-select").prop('selectedIndex',0); - $("#add-index-type-eq").prop('checked', false); - $("#add-index-type-pres").prop('checked', false); - $("#add-index-type-sub").prop('checked', false); - $("#add-index-type-approx").prop('checked', false); - $("#add-index-matchingrules").val(""); -} - -function clear_attr_encrypt_form() { - $("#attr-encrypt-list").prop('selectedIndex',0); - $("#nsencryptionalgorithm").prop('selectedIndex',0); -} - -$(document).ready( function() { - $("#database-content").load("backend.html", function () { - load_jstree(); - - $(".ds-suffix-panel").toggle("active"); - $(".ds-suffix-panel").css('display','none'); - - $("#create-ref-btn").on("click", function () { - clear_ref_form(); - }); - - $("#db-chaining-btn").on("click", function() { - $(".all-pages").hide(); - $("#database-content").show(); - $("#db-chaining-settings-page").show(); - }); - $("#db-global-btn").on("click", function() { - $(".all-pages").hide(); - $("#database-content").show(); - $("#db-global-page").show(); - }); - $("#db-suffix-btn").on("click", function() { - $(".all-pages").hide(); - $("#database-content").show(); - $("#db-page").show(); - $("#suffix-page").show(); - }); - - $("#chaining-adv-accordion").on("click", function() { - this.classList.toggle("active"); - var panel = this.nextElementSibling; - if (panel.style.display === "block") { - var show = "► Show Advanced Database Link Settings "; - $(this).html(show); - panel.style.display = "none"; - $(this).blur(); - } else { - var hide = "▼ Hide Advanced Database Link Settings"; - $(this).html(hide); - panel.style.display = "block"; - $(this).blur(); - } - }); - - - $("#db-system-index-accordion").on("click", function() { - this.classList.toggle("active"); - var panel = this.nextElementSibling; - if (panel.style.display === "block") { - var show = "► Show System Indexes "; - $(this).html(show); - panel.style.display = "none"; - $(this).blur(); - } else { - var hide = "▼ Hide System Indexes "; - $(this).html(hide); - panel.style.display = "block"; - $(this).blur(); - } - }); - - $("#db-index-accordion").on("click", function() { - this.classList.toggle("active"); - var panel = this.nextElementSibling; - if (panel.style.display === "block") { - var show = "► Show Database Indexes "; - $(this).html(show); - panel.style.display = "none"; - $(this).blur(); - } else { - var hide = "▼ Hide Database Indexes "; - $(this).html(hide); - panel.style.display = "block"; - $(this).blur(); - } - }); - - $("#suffix-attrencrypt-accordion").on("click", function() { - this.classList.toggle("active"); - var panel = this.nextElementSibling; - if (panel.style.display === "block") { - var show = "► Show Encrypted Attributes "; - $(this).html(show); - panel.style.display = "none"; - $(this).blur(); - } else { - var hide = "▼ Hide Encrypted Attributes "; - $(this).html(hide); - panel.style.display = "block"; - $(this).blur(); - } - }); - - - /* - We need logic to see if autocaching (import and db) is being used, and disable fields, - and set radio buttons, et - */ - - var ref_table = $('#referral-table').DataTable( { - "paging": false, - "searching": false, - "bInfo" : false, - "bAutoWidth": false, - "dom": '<"pull-left"f><"pull-right"l>tip', - "language": { - "emptyTable": "No Referrals" - }, - "columnDefs": [ - { - "targets": 1, - "orderable": false, - }, - { - "targets": 1, - "className": "ds-center" - } - ] - }); - - - $('#system-index-table').DataTable( { - "paging": true, - "bAutoWidth": false, - "dom": '<"pull-left"f><"pull-right"l>tip', - "lengthMenu": [ 10, 25, 50, 100], - "language": { - "search": "Search", - "emptyTable": "No System Indexes" - }, - "columns": [ - { "width": "10%" }, - { "width": "20px" }, - { "width": "20px" }, - { "width": "20px" }, - { "width": "20px" }, - { "width": "20%" } - ], - }); - var index_table = $('#index-table').DataTable( { - "paging": true, - "bAutoWidth": false, - "dom": '<"pull-left"f><"pull-right"l>tip', - "lengthMenu": [ 10, 25, 50, 100], - "language": { - "search": "Search", - "emptyTable": "No Indexes" - }, - "columns": [ - { "width": "10%" }, - { "width": "15px" }, - { "width": "15px" }, - { "width": "15px" }, - { "width": "15px" }, - { "width": "20%" }, - { "width": "76px" } - ], - "columnDefs": [ { - "targets": 6, - "orderable": false - } ] - }); - - - - - var attr_encrypt_table = $('#attr-encrypt-table').DataTable( { - "paging": true, - "bAutoWidth": false, - "searching": true, - "dom": '<"pull-left"f><"pull-right"l>tip', - "lengthMenu": [ 10, 25, 50, 100], - "language": { - "search": "Search", - "emptyTable": "No Encrypted Attributes" - }, - "columnDefs": [ { - "targets": 2, - "orderable": false - } ] - }); - - // Accordion opening/closings - $(".ds-accordion-panel").css('display','none'); - - var suffix_acc = document.getElementsByClassName("suffix-accordion"); - for (var i = 0; i < suffix_acc.length; i++) { - suffix_acc[i].onclick = function() { - this.classList.toggle("active"); - var panel = this.nextElementSibling; - if (panel.style.display === "block") { - panel.style.display = "none"; - } else { - panel.style.display = "block"; - } - } - } - - $("#db-accordion").on("click", function() { - this.classList.toggle("active"); - var panel = this.nextElementSibling; - if (panel.style.display === "block") { - var show = "► Show Advanced Settings"; - $(this).html(show); - panel.style.display = "none"; - $(this).blur(); - } else { - var hide = "▼ Hide Advanced Settings "; - $(this).html(hide); - panel.style.display = "block"; - $(this).blur(); - } - }); - - var db_acc = document.getElementsByClassName("db-accordion"); - for (var i = 0; i < db_acc.length; i++) { - db_acc[i].onclick = function() { - this.classList.toggle("active"); - var panel = this.nextElementSibling; - if (panel.style.display === "block") { - panel.style.display = "none"; - } else { - panel.style.display = "block"; - } - } - } - - var cache_acc = document.getElementsByClassName("cache-accordion"); - for (var i = 0; i < cache_acc.length; i++) { - cache_acc[i].onclick = function() { - this.classList.toggle("active"); - var panel = this.nextElementSibling; - if (panel.style.display === "block") { - panel.style.display = "none"; - } else { - panel.style.display = "block"; - } - } - } - - - $(".index-type").attr('readonly', true); - - if ( $("#manual-cache").is(":checked") ){ - $("#auto-cache-form").hide(); - $("#manual-cache-form").show(); - $("#nsslapd-dncachememsize").prop('disabled', false); - $("#nsslapd-dncachememsize").val(''); - $("#nsslapd-cachememsize").prop('disabled', false); - $("#nsslapd-cachememsize").val(''); - $("#nsslapd-cachesize").prop('disabled', false); - $("#nsslapd-cachesize").val(''); - } else { - $("#manual-cache-form").hide(); - $("#auto-cache-form").show(); - $("#nsslapd-dncachememsize").prop('disabled', true); - $("#nsslapd-dncachememsize").val('AUTOTUNED'); - $("#nsslapd-cachememsize").prop('disabled', true); - $("#nsslapd-cachememsize").val('AUTOTUNED'); - $("#nsslapd-cachesize").prop('disabled', true); - $("#nsslapd-cachesize").val('AUTOTUNED'); - } - - if ( $("#manual-import-cache").is(":checked") ){ - $("#auto-import-cache-form").hide(); - $("#manual-import-cache-form").show(); - } else { - $("#manual-import-cache-form").hide(); - $("#auto-import-cache-form").show(); - } - - $(".cache-role").on("change", function() { - var cache_role = $("input[name=cache-role]:checked").val(); - if (cache_role == "manual-cache") { - $("#auto-cache-form").hide(); - $("#manual-cache-form").show(); - } else { - // auto cache - $("#manual-cache-form").hide(); - $("#auto-cache-form").show(); - } - }); - - $(document).on('click', '.del-ref-btn', function(e) { - e.preventDefault(); - var data = ref_table.row( $(this).parents('tr') ).data(); - var del_ref_name = data[0]; - var ref_row = $(this); // Store element for callback - popup_confirm("Are you sure you want to delete referral: " + del_ref_name + "", "Confirmation", function (yes) { - if (yes) { - // TODO Delete mapping from DS - - // Update html table - ref_table.row( ref_row.parents('tr') ).remove().draw( false ); - } - }); - }); - - $("#backend-config-save-btn").on("click", function () { - var role = $("input[name=cache-role]:checked").val(); - if (role == "manual-cache") { - // TODO - need to get cache values and fields (overwrite AUTOTUNED) - $("#nsslapd-dncachememsize").prop('disabled', false); - $("#nsslapd-dncachememsize").val('') - $("#nsslapd-cachememsize").prop('disabled', false); - $("#nsslapd-cachememsize").val(''); - $("#nsslapd-cachesize").prop('disabled', false); - $("#nsslapd-cachesize").val(''); - } else { - // auto cache - $("#nsslapd-dncachememsize").prop('disabled', true); - $("#nsslapd-dncachememsize").val('AUTOTUNED'); - $("#nsslapd-cachememsize").prop('disabled', true); - $("#nsslapd-cachememsize").val('AUTOTUNED'); - $("#nsslapd-cachesize").prop('disabled', true); - $("#nsslapd-cachesize").val('AUTOTUNED'); - } - }); - - $(".import-cache-role").on("change", function() { - var role = $("input[name=import-cache-role]:checked").val(); - if (role == "manual-import-cache") { - $("#auto-import-cache-form").hide(); - $("#manual-import-cache-form").show(); - } else { - // auto cache - $("#manual-import-cache-form").hide(); - $("#auto-import-cache-form").show(); - } - }); - - // Based on the db-link connection type change the agmt-auth options - $("#dblink-conn").change(function() { - var ldap_opts = {"Simple": "Simple", - "SASL/DIGEST-MD5": "SASL/DIGEST-MD5", - "SASL/GSSAPI": "SASL/GSSAPI"}; - var ldaps_opts = {"Simple": "Simple", - "SSL Client Authentication": "SSL Client Authentication", - "SASL/DIGEST-MD5": "SASL/DIGEST-MD5"}; - var $auth = $("#nsbindmechanism"); - $auth.empty(); - var conn = $('#dblink-conn').val(); - if (conn == "LDAP"){ - $.each(ldap_opts, function(key, value) { - $auth.append($("").attr("value", value).text(key)); - }); - } else { - // TLS options - $.each(ldaps_opts, function(key, value) { - $auth.append($("").attr("value", value).text(key)); - }); - } - $("#nsmultiplexorbinddn").prop('disabled', false); - $("#nsmultiplexorcredentials").prop('disabled', false); - $("#nsmultiplexorcredentials-confirm").prop('disabled', false); - }); - - // Check for auth changes and disable/enable bind DN & password for db-links - $("#nsbindmechanism").change(function() { - var authtype = $('#nsbindmechanism').val(); - if (authtype == "SSL Client Authentication") { - $("#nsmultiplexorbinddn").prop('disabled', true); - $("#nsmultiplexorcredentials").prop('disabled', true); - $("#nsmultiplexorcredentials-confirm").prop('disabled', true); - } else { - $("#nsmultiplexorbinddn").prop('disabled', false); - $("#nsmultiplexorcredentials").prop('disabled', false); - $("#nsmultiplexorcredentials-confirm").prop('disabled', false); - } - }); - - // - // Modal Forms - // - - // Chaining OIDS - $("#chaining-oid-button").on("click", function() { - $(this).blur(); - }); - $("#chaining-oid-save").on("click", function() { - // Update oids - var chaining_oids = $("#avail-chaining-oid-list").val(); - for (var i = 0; chaining_oids && i < chaining_oids.length; i++) { - $('#chaining-oid-list').append($('