{#include main fluid=true}
{#style}
table {
table-layout:fixed;
width:100%;
}
td {
word-wrap:break-word;
word-break:break-all;
}
#tables{
margin-bottom: unset;
}
.mousePointer:hover {
cursor: pointer;
}
.formInputButton:hover {
color: #3366ac !important;
cursor: pointer;
}
#filterInputGroup {
padding-bottom: 10px;
}
{/style}
{#styleref}
{/styleref}
{#script}
$(document).ready(function(){
$("#filterInput").on("keyup", function() {
var value = $(this).val().toLowerCase();
$(".configTable tr").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
});
hideEmptyTables();
});
$(".configInput").on("keyup", function(event) {
event.preventDefault();
if (event.keyCode === 13) {
event.preventDefault();
changeInputValue(event.target.id);
}
});
$(function () {
$('[data-toggle="tooltip"]').tooltip()
});
});
function clearFilterInput(){
$("#filterInput").val("");
$(".configTable tr").each(function() {
$(this).toggle(true)
});
hideEmptyTables();
}
function changeSelectValue(element, name){
var $el = $("select[id='" + name + "']");
var $tr = $("tr[id='tr-" + name + "']");
var value = element.options[element.selectedIndex].text;
postChangeConfigValue(name, value, $el);
}
function changeCheckboxValue(element, name){
var $el = $("input[id='" + name + "']");
var $tr = $("tr[id='tr-" + name + "']");
var value = element.checked;
postChangeConfigValue(name, value, $el);
}
function changeInputValue(name){
var $el = $("input[id='" + name + "']");
var $tr = $("tr[id='tr-" + name + "']");
var value = $el.val();
postChangeConfigValue(name, value, $el);
}
function postChangeConfigValue(name, value, $el){
$el.prop('disabled', true);
$.post("",
{
action: "updateProperty",
name: name,
value: value
},
function(data, status){
if(status === "success"){
showToastMessage("Update", "Configuration update successful");
hideEmptyTables();
changeBackgroundColor("#76be6b", $el);
}else{
showToastMessage("Update", "Configuration update failed");
hideEmptyTables();
changeBackgroundColor("#ff6366", $el);
}
$el.prop('disabled', false);
});
}
function changeBackgroundColor(color, element){
var x = 3000;
var originalColor = element.css("background");
element.css("background", color);
setTimeout(function(){
element.css("background", originalColor);
}, x);
}
function showApplicationPropertiesFile(){
$(".application-properties-form").hide();
$(".application-properties-file").show();
reloadApplicationPropertiesFile();
}
function showApplicationPropertiesForm(){
reloadApplicationPropertiesForm();
$(".application-properties-file").hide();
$(".application-properties-form").show();
}
function saveApplicationPropertiesFile(){
var properties = editor.getDoc().getValue();
$.post("",
{
action: "updateProperties",
values: properties
},
function(data, status){
if(status === "success"){
showToastMessage("Update", "Configuration update successful");
}else{
showToastMessage("Update", "Configuration update failed");
}
hideEmptyTables();
reloadApplicationPropertiesFile();
});
}
function reloadApplicationPropertiesFile(){
$.get("config/all",
function(data, status){
if(status === "success"){
editor.getDoc().setValue(data);
}else{
showToastMessage("Properties file", "Failed to load properties");
}
});
}
function reloadApplicationPropertiesForm(){
$.get("config",
function(data, status){
if(status === "success"){
var formPart = $('#tables', data);
$('#tables').replaceWith(formPart);
}else{
showToastMessage("Properties file", "Failed to load properties");
}
});
}
function copyTestDevServices(){
copyDevServices("Test");
}
function copyProdDevServices(){
copyDevServices("Prod");
}
function copyDevServices(environment){
$.post("",
{
action: "copyDevServices",
environment: environment,
filter: configfilter
},
function(data, status){
if(status === "success"){
showToastMessage("DevServices", "All configuration automatically set by DevServices copied for " + environment);
}else{
showToastMessage("DevServices", "Failed to copied configuration for " + environment);
}
reloadApplicationPropertiesFile();
});
}
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: "properties",
styleActiveLine: true,
lineNumbers: true,
lineWrapping: true,
extraKeys: {"Ctrl-Space": "autocomplete"}
});
editor.setSize(null, getEditorHeight());
editor.on("blur", function(codeMirror) { codeMirror.save(); });
editor.refresh();
$('.application-properties-file').hide();
$('#application-properties-form').css('height',getFormHeight());
function getEditorHeight(){
let headerBar = document.querySelector('#stickyTopHeaderNavBar');
let headerBarHeight = headerBar.offsetHeight;
let editorBar = document.querySelector('#editorNavBar');
let editorBarHeight = editorBar.offsetHeight;
let footerBarHeight = 80;
return window.innerHeight-headerBarHeight - editorBarHeight - footerBarHeight;
}
function getFormHeight(){
let headerBar = document.querySelector('#stickyTopHeaderNavBar');
let headerBarHeight = headerBar.offsetHeight;
let filterInput = document.querySelector('#filterInputGroup');
let filterInputHeight = filterInput.offsetHeight;
let tableHeader = document.querySelector('#formTableHeader');
let tableHeaderHeight = tableHeader.offsetHeight;
let footerBarHeight = 95;
return window.innerHeight-headerBarHeight - filterInputHeight - tableHeaderHeight - footerBarHeight;
}
var configfilter = "";
$('#configCurrentFilter').hide();
const queryParams = new URLSearchParams(window.location.search);
var filterByExtensionName = "";
if(queryParams.has("filterByExtension")){
filterByExtensionName = queryParams.get("filterByExtension");
}
var filterConfigKeys = "";
if(queryParams.has("filterConfigKeys")){
filterConfigKeys = queryParams.get("filterConfigKeys");
}
if(filterConfigKeys!=="" && filterByExtensionName!==""){
filterByConfigExtension(filterByExtensionName,filterConfigKeys);
}
$('#configFilterModal').on('shown.bs.modal', function () {
$('#configFilterModalInput').trigger('focus');
});
configFilterModalInput.addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
event.preventDefault();
configFilterModalInputButton.click();
}
});
configFilterModalInputButton.addEventListener("click", applyConfigFilter);
function applyConfigFilter(){
filterByConfigExtension($('#configFilterModalInput').find(":selected").text(), $('#configFilterModalInput').find(":selected").val());
}
function filterByConfigExtension(configfilterText, configfilterKeys){
configfilter = configfilterKeys.split(",");
$('#configCurrentFilter').show();
configCurrentFilter.innerHTML = "" + configfilterText + " ";
$(".filterableConfigKey").each(function() {
var ck = $(this).text().trim();
var hide = true;
configfilter.forEach(function (item, index) {
if(ck.startsWith(item)){
hide = false;
}
});
if(hide){
$(this).parent().hide();
}
});
$('#configFilterModal').modal('hide');
showHideDevServicesButton();
hideEmptyTables();
}
function showHideDevServicesButton(){
// Check if there is any dev services visible on the page
var numberOfMagicConfig = $('.fa-magic:visible').length;
if(numberOfMagicConfig === 0){
$('.devservices').hide();
}else {
$('.devservices').show();
}
}
function hideEmptyTables(){
$('.filterableTable').filter(function(index){
var tableTrNumber = $(this).find('tr').length;
var tableTrHiddenNumber = $(this).find('tr:hidden').length + 1;
if(tableTrNumber == tableTrHiddenNumber){
$(this).hide();
}else{
$(this).show();
}
});
}
function clearConfigFilter(){
configfilter = "";
$("#configFilterModalInput").val("");
configCurrentFilter.innerHTML = "";
$('#configCurrentFilter').hide();
$(".filterableConfigKey").each(function() {
$(this).parent().show();
});
clearFilterInput();
showHideDevServicesButton();
}
{/script}
{#scriptref}
{/scriptref}
{#title}Config Editor{/title}
{#body}
{/body}
{/include}