Skip to content

Commit

Permalink
IBX-6398: UDW as standalone package
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasOsti committed Nov 14, 2023
1 parent 8ad1218 commit 0939498
Show file tree
Hide file tree
Showing 58 changed files with 1,557 additions and 1,146 deletions.
30 changes: 5 additions & 25 deletions src/bundle/Resources/encore/ibexa.js.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,9 @@ const fs = require('fs');
const translationsPath = path.resolve('./public/assets/translations/');
const fieldTypesPath = path.resolve(__dirname, '../public/js/scripts/fieldType/');
const layout = [
path.resolve(__dirname, '../public/js/scripts/helpers/icon.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/location.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/text.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/request.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/notification.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/timezone.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/content.type.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/user.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/tooltips.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/table.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/cookies.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/tag.view.select.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/pagination.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/object.instances.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/middle.ellipsis.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/form.validation.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/form.error.helper.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/system.helper.js'),
path.resolve(__dirname, '../../ui-dev/src/modules/universal-discovery/config.loader.js'),
path.resolve(__dirname, '../../ui-dev/src/modules/config.loader.js'),
path.resolve(__dirname, '../public/js/scripts/helpers/config.loader.js'),
path.resolve(__dirname, '../public/js/scripts/admin.format.date.js'),
path.resolve(__dirname, '../public/js/scripts/core/draggable.js'),
path.resolve(__dirname, '../public/js/scripts/core/dropdown.js'),
Expand Down Expand Up @@ -87,6 +72,7 @@ if (fs.existsSync(fieldTypesPath)) {

module.exports = (Encore) => {
Encore.addEntry('ibexa-admin-ui-layout-js', layout)
.addEntry('ibexa-test-udw-js', [path.resolve(__dirname, '../public/js/scripts/___udw.test.js')])
.addEntry('ibexa-admin-ui-error-page-js', [path.resolve(__dirname, '../public/js/scripts/admin.error.page.js')])
.addEntry('ibexa-admin-ui-bookmark-list-js', [
path.resolve(__dirname, '../public/js/scripts/button.state.toggle.js'),
Expand Down Expand Up @@ -186,13 +172,7 @@ module.exports = (Encore) => {
.addEntry('ibexa-admin-ui-modal-location-trash-single-asset-js', [
path.resolve(__dirname, '../public/js/scripts/button.state.radio.toggle.js'),
])
.addEntry('ibexa-admin-ui-dashboard-js', [
path.resolve(__dirname, '../public/js/scripts/udw/browse.js'),
path.resolve(__dirname, '../public/js/scripts/cotf/create.js'),
path.resolve(__dirname, '../public/js/scripts/button.content.edit.js'),
path.resolve(__dirname, '../public/js/scripts/admin.version.edit.conflict.js'),
path.resolve(__dirname, '../public/js/scripts/button.translation.edit.js'),
])
.addEntry('ibexa-admin-ui-dashboard-js', [path.resolve(__dirname, '../public/js/scripts/udw/browse.js')])
.addEntry('ibexa-admin-ui-link-manager-list-js', [path.resolve(__dirname, '../public/js/scripts/admin.linkmanager.list.js')])
.addEntry('ibexa-admin-ui-link-manager-view-js', [path.resolve(__dirname, '../public/js/scripts/button.content.edit.js')])
.addEntry('ibexa-admin-ui-url-wildcards-list-js', [path.resolve(__dirname, '../public/js/scripts/admin.urlwildcards.list.js')])
Expand Down
32 changes: 32 additions & 0 deletions src/bundle/Resources/public/js/scripts/___udw.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import assetsLibraryWidget from '../../../../../../../assets-library-widget/src/bundle/Resources/public/js/assets.library.widget';

(function (global, doc, React, ReactDOM) {
let udwRoot = null;
const container = doc.getElementById('react-udw');
const triggerElement = doc.querySelector('.ibexa-open-image-picker');
const closeUDW = () => udwRoot.unmount();
const openUdw = async () => {
const config = {
...JSON.parse(triggerElement.dataset.udwConfig),
title: 'test image picker',
activeTab: 'image_picker',
rootLocationId: 51,
onConfirm: () => {
console.log('confirm');
},
onCancel: closeUDW,
restInfo: {
token: 'f72e8ac375def2c346d5d3e7057a.u0r1YnqgMyL6zbfVE5Mxdi3yA6TaXKZTmAALD7BzFTM.iH-qKyzHa3Oshv2ya6Z7B36xZfeqFskQwGYmTOo0cGDSL6RSKNV6dL6j1A',
siteaccess: 'admin',
},
};

udwRoot = ReactDOM.createRoot(container);
udwRoot.render(React.createElement(assetsLibraryWidget, config));
};

triggerElement.addEventListener('click', openUdw, false);
// setTimeout(() => {
// openUdw();
// }, 100);
})(window, window.document, window.React, window.ReactDOM);
48 changes: 26 additions & 22 deletions src/bundle/Resources/public/js/scripts/admin.format.date.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
import { formatICU } from './helpers/timezone.helper';

(function (moment, ibexa) {
const { backOfficeLanguage } = ibexa.adminUiConfig;

moment.locale(backOfficeLanguage);

/*
([yqLdDeEcaZ])\1* -> find any pattern of one or repeated one of these characters
or
\'([^\']|(\'\'))*\' -> find any string in ' ' quotes
*/
// moment.fn.formatICU = function (format) {
// return formatICU(format);
// };
// /*
// ([yqLdDeEcaZ])\1* -> find any pattern of one or repeated one of these characters
// or
// \'([^\']|(\'\'))*\' -> find any string in ' ' quotes
// */
const formatICUEx = /([yqLdDeEcaZ])\1*|'([^']|(''))*'/g;
/*
Allowed formats:
y, yy, yyyy, Y, YY, YYYY,
q, Q,
M, MM, MMM, MMMM, L, LL, LLL, LLLL,
w, WW,
d, dd,
D, DDD,
E, EE, EEE, EEEE, EEEEEE, e, ee, eee, eeee, eeeeee, c, cc, ccc, cccc, cccccc,
a,
h, hh, H, HH, k, kk,
m, mm,
s, ss, S...,
Z, ZZ, ZZZ, ZZZZZ
*/
// /*
// Allowed formats:
// y, yy, yyyy, Y, YY, YYYY,
// q, Q,
// M, MM, MMM, MMMM, L, LL, LLL, LLLL,
// w, WW,
// d, dd,
// D, DDD,
// E, EE, EEE, EEEE, EEEEEE, e, ee, eee, eeee, eeeeee, c, cc, ccc, cccc, cccccc,
// a,
// h, hh, H, HH, k, kk,
// m, mm,
// s, ss, S...,
// Z, ZZ, ZZZ, ZZZZZ
// */
const formatICUMap = {
y: 'Y',
yy: 'YY',
Expand Down Expand Up @@ -78,7 +82,7 @@
if (formatICUMap[icuStr] === undefined) {
return icuStr;
}

console.log('AAAAA', this);
return typeof formatICUMap[icuStr] === 'function' ? formatICUMap[icuStr].call(this) : formatICUMap[icuStr];
});

Expand Down
85 changes: 85 additions & 0 deletions src/bundle/Resources/public/js/scripts/helpers/config.loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { getContentTypeIconUrl, getContentTypeName } from './content.type.helper';
import { getCookie, setCookie, setBackOfficeCookie } from './cookies.helper';
import { formatErrorLine, validateIsEmptyField } from './form.validation.helper';
import { getIconPath } from './icon.helper';
import { removeRootFromPathString, findLocationsByIds, buildLocationsBreadcrumbs } from './location.helper';
import { getJsonFromResponse, getTextFromResponse, getStatusFromResponse } from './request.helper';
import { parse as parseTooltips, hideAll as hideAllTooltips, observe as observerTooltips } from './tooltips.helper';
import { convertDateToTimezone, formatFullDateTime, formatShortDateTime, getBrowserTimezone } from './timezone.helper';
import {
showNotification,
showInfoNotification,
showSuccessNotification,
showWarningNotification,
showErrorNotification,
} from './notification.helper';
import { parse as parseMiddleEllipsis, parseAll as parseAllMiddleEllipsis, update as updateMiddleEllipsis } from './middle.ellipsis';
import { setInstance, getInstance, clearInstance } from './object.instances';
import { computePages } from './pagination.helper';
import {
isWindows,
isMac,
isLinux,
isUndoPressed,
isRedoPressed,
isSavePressed,
isCopyPressed,
isCutPressed,
isPastePressed,
isPrintPressed,
isSelectAllPressed,
} from './system.helper';
import { parseCheckbox as parseCheckboxTable } from './table.helper';
import { buildItemsFromUDWResponse } from './tag.view.select.helper';
import { escapeHTML } from './text.helper';
import { getId as getUserId } from './user.helper';

(function (ibexa) {
ibexa.addConfig('helpers.contentType', { getContentTypeIconUrl, getContentTypeName });
ibexa.addConfig('helpers.cookies', { getCookie, setCookie, setBackOfficeCookie });
ibexa.addConfig('helpers.formValidation', { formatErrorLine, validateIsEmptyField });
ibexa.addConfig('helpers.icon', { getIconPath });
ibexa.addConfig('helpers.location', { removeRootFromPathString, findLocationsByIds, buildLocationsBreadcrumbs });
ibexa.addConfig('helpers.request', { getJsonFromResponse, getTextFromResponse, getStatusFromResponse });
ibexa.addConfig('helpers.tooltips', {
parse: parseTooltips,
hideAll: hideAllTooltips,
observe: observerTooltips,
});
ibexa.addConfig('helpers.timezone', { convertDateToTimezone, formatFullDateTime, formatShortDateTime, getBrowserTimezone });
ibexa.addConfig('helpers.notification', {
showNotification,
showInfoNotification,
showSuccessNotification,
showWarningNotification,
showErrorNotification,
});
ibexa.addConfig('helpers.ellipsis.middle', {
parse: parseMiddleEllipsis,
parseAll: parseAllMiddleEllipsis,
update: updateMiddleEllipsis,
});
ibexa.addConfig('helpers.objectInstances', {
setInstance,
getInstance,
clearInstance,
});
ibexa.addConfig('helpers.pagination', { computePages });
ibexa.addConfig('helpers.system', {
isWindows: isWindows(),
isMac: isMac(),
isLinux: isLinux(),
isUndoPressed,
isRedoPressed,
isSavePressed,
isCopyPressed,
isCutPressed,
isPastePressed,
isPrintPressed,
isSelectAllPressed,
});
ibexa.addConfig('helpers.table', { parseCheckbox: parseCheckboxTable });
ibexa.addConfig('helpers.tagViewSelect', { buildItemsFromUDWResponse });
ibexa.addConfig('helpers.text', { escapeHTML });
ibexa.addConfig('helpers.user', { getId: getUserId });
})(window.ibexa);
119 changes: 58 additions & 61 deletions src/bundle/Resources/public/js/scripts/helpers/content.type.helper.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,60 @@
(function (global, doc, ibexa) {
let contentTypesDataMap = null;

/**
* Creates map with content types identifiers as keys for faster lookup
*
* @function createContentTypeDataMap
* @returns {Object} contentTypesDataMap
*/
const createContentTypeDataMap = () =>
Object.values(ibexa.adminUiConfig.contentTypes).reduce((contentTypeDataMap, contentTypeGroup) => {
for (const contentTypeData of contentTypeGroup) {
contentTypeDataMap[contentTypeData.identifier] = contentTypeData;
}

return contentTypeDataMap;
}, {});

/**
* Returns an URL to a content type icon
*
* @function getContentTypeIcon
* @param {String} contentTypeIdentifier
* @returns {String|null} url to icon
*/
const getContentTypeIconUrl = (contentTypeIdentifier) => {
if (!contentTypesDataMap) {
contentTypesDataMap = createContentTypeDataMap();
import { getContext as getHelpersContext } from './helpers.service';

let contentTypesDataMap = null;

/**
* Creates map with content types identifiers as keys for faster lookup
*
* @function createContentTypeDataMap
* @returns {Object} contentTypesDataMap
*/
const createContentTypeDataMap = () =>
Object.values(getHelpersContext().contentTypes).reduce((contentTypeDataMap, contentTypeGroup) => {
for (const contentTypeData of contentTypeGroup) {
contentTypeDataMap[contentTypeData.identifier] = contentTypeData;
}

if (!contentTypeIdentifier || !contentTypesDataMap[contentTypeIdentifier]) {
return null;
}

const iconUrl = contentTypesDataMap[contentTypeIdentifier].thumbnail;

return iconUrl;
};

/**
* Returns contentType name from contentType identifier
*
* @function getContentTypeName
* @param {String} contentTypeIdentifier
* @returns {String|null} contentType name
*/
const getContentTypeName = (contentTypeIdentifier) => {
if (!contentTypesDataMap) {
contentTypesDataMap = createContentTypeDataMap();
}

if (!contentTypeIdentifier || !contentTypesDataMap[contentTypeIdentifier]) {
return null;
}

return contentTypesDataMap[contentTypeIdentifier].name;
};

ibexa.addConfig('helpers.contentType', {
getContentTypeIconUrl,
getContentTypeName,
});
})(window, window.document, window.ibexa);
return contentTypeDataMap;
}, {});

/**
* Returns an URL to a content type icon
*
* @function getContentTypeIcon
* @param {String} contentTypeIdentifier
* @returns {String|null} url to icon
*/
const getContentTypeIconUrl = (contentTypeIdentifier) => {
if (!contentTypesDataMap) {
contentTypesDataMap = createContentTypeDataMap();
}

if (!contentTypeIdentifier || !contentTypesDataMap[contentTypeIdentifier]) {
return null;
}

const iconUrl = contentTypesDataMap[contentTypeIdentifier].thumbnail;

return iconUrl;
};

/**
* Returns contentType name from contentType identifier
*
* @function getContentTypeName
* @param {String} contentTypeIdentifier
* @returns {String|null} contentType name
*/
const getContentTypeName = (contentTypeIdentifier) => {
if (!contentTypesDataMap) {
contentTypesDataMap = createContentTypeDataMap();
}

if (!contentTypeIdentifier || !contentTypesDataMap[contentTypeIdentifier]) {
return null;
}

return contentTypesDataMap[contentTypeIdentifier].name;
};

export { getContentTypeIconUrl, getContentTypeName };
Loading

0 comments on commit 0939498

Please sign in to comment.