176 lines
5.4 KiB
JavaScript
176 lines
5.4 KiB
JavaScript
/*-
|
|
* ~~~~~~licensing~~~~~~
|
|
* entaxy-management-plugin
|
|
* ==========
|
|
* Copyright (C) 2020 - 2023 EmDev LLC
|
|
* ==========
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
* ~~~~~~/licensing~~~~~~
|
|
*/
|
|
var Entaxy;
|
|
(function (Entaxy) {
|
|
|
|
const MODAL_MODES = {
|
|
VIEW: 'View',
|
|
EDIT: 'Edit',
|
|
ADD: 'Add'
|
|
};
|
|
Entaxy.MODAL_MODES = MODAL_MODES;
|
|
|
|
function getButtonTitleByMode(mode) {
|
|
switch (mode) {
|
|
case MODAL_MODES.ADD:
|
|
return 'Add';
|
|
case MODAL_MODES.EDIT:
|
|
return 'Save';
|
|
case MODAL_MODES.VIEW:
|
|
return 'Ok';
|
|
}
|
|
}
|
|
Entaxy.getButtonTitleByMode = getButtonTitleByMode;
|
|
|
|
function capitalize(string) {
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
}
|
|
Entaxy.capitalize = capitalize;
|
|
|
|
function uncapitalize(string) {
|
|
return string.charAt(0).toLowerCase() + string.slice(1);
|
|
}
|
|
Entaxy.uncapitalize = uncapitalize;
|
|
|
|
function getChildrenRecursive(folder) {
|
|
let children = folder.children;
|
|
if (children) {
|
|
folder.children.forEach(child => {
|
|
if (child.children) {
|
|
children = children.concat(getChildrenRecursive(child));
|
|
}
|
|
});
|
|
}
|
|
return children;
|
|
}
|
|
Entaxy.getChildrenRecursive = getChildrenRecursive;
|
|
|
|
function compareBy(fieldName) {
|
|
return function(a, b) {
|
|
let valueA = a[fieldName].toLowerCase();
|
|
let valueB = b[fieldName].toLowerCase();
|
|
if (valueA < valueB) {
|
|
return -1;
|
|
}
|
|
if (valueA > valueB) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
Entaxy.compareBy = compareBy;
|
|
|
|
function convertToHtmlInputType(javaType) {
|
|
if (!javaType || javaType.startsWith('entaxy.runtime')) {
|
|
return javaType;
|
|
}
|
|
switch (javaType) {
|
|
case 'xml:route':
|
|
return javaType;
|
|
case 'boolean':
|
|
case 'Boolean':
|
|
case 'java.lang.Boolean':
|
|
return 'checkbox';
|
|
case 'number':
|
|
case 'int':
|
|
case 'long':
|
|
case 'java.lang.Integer':
|
|
case 'java.lang.Long':
|
|
return 'number';
|
|
default:
|
|
return 'text';
|
|
}
|
|
}
|
|
Entaxy.convertToHtmlInputType = convertToHtmlInputType;
|
|
|
|
function createTableFromResponse(response) {
|
|
let tableHtml = `<table class="entaxy-result-table">`;
|
|
tableHtml +=
|
|
`
|
|
<tr>
|
|
<th>Step</th>
|
|
<th>Step name</th>
|
|
<th>Step result</th>
|
|
</tr>
|
|
`;
|
|
_.forEach(JSON.parse(response), (step) => {
|
|
let iconName = step['Step result'] === 'OK' ? 'ok' : 'error-circle-o';
|
|
tableHtml += `<tr><td>` + step['Step'] + `</td><td>` + step['Step name'] + `</td>`;
|
|
tableHtml += `<td><span class="pficon pficon-${iconName}"></span></td></tr>`;
|
|
});
|
|
tableHtml += `</table>`;
|
|
return tableHtml;
|
|
}
|
|
Entaxy.createTableFromResponse = createTableFromResponse;
|
|
|
|
function notification(type, message, duration) {
|
|
|
|
let visibleToastElem = null;
|
|
let timeoutId;
|
|
|
|
let toastHtml = `
|
|
<div class="toast-pf alert alert-${type} alert-dismissable">
|
|
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">
|
|
<span class="pficon pficon-close"></span>
|
|
</button>
|
|
<span class="pficon pficon-${resolveToastIcon(type)}"></span>
|
|
<div class="toast-pf-content">
|
|
${message}
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
let toastFrag = document.createRange().createContextualFragment(toastHtml);
|
|
let toastElem = toastFrag.querySelector('div');
|
|
|
|
let bodyElem = document.querySelector('body');
|
|
|
|
// if toast element is in the DOM
|
|
if (visibleToastElem && visibleToastElem.parentNode) {
|
|
clearTimeout(timeoutId);
|
|
bodyElem.removeChild(visibleToastElem);
|
|
}
|
|
visibleToastElem = bodyElem.appendChild(toastElem);
|
|
|
|
if (duration || (type === 'success' || type === 'info')) {
|
|
timeoutId = window.setTimeout(() => {
|
|
if (toastElem.parentNode) {
|
|
bodyElem.removeChild(toastElem);
|
|
}
|
|
}, duration || 8000);
|
|
}
|
|
}
|
|
Entaxy.notification = notification;
|
|
|
|
function resolveToastIcon(type) {
|
|
switch (type) {
|
|
case 'success':
|
|
return 'ok';
|
|
case 'warning':
|
|
return 'warning-triangle-o';
|
|
case 'danger':
|
|
return 'error-circle-o';
|
|
default:
|
|
return 'info';
|
|
}
|
|
}
|
|
|
|
})(Entaxy || (Entaxy = {}));
|