Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EAK-280] Add new Content Blueprints page template #298

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui.apps/src/main/content/META-INF/vault/filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

<filter root="/apps/etoolbox-authoring-kit/clientlib-injector"/>
<filter root="/apps/etoolbox-authoring-kit/components"/>
<filter root="/apps/etoolbox-authoring-kit/content-blueprints"/>
<filter root="/apps/etoolbox-authoring-kit/coral-overlay"/>
<filter root="/apps/etoolbox-authoring-kit/depends-on"/>
<filter root="/apps/etoolbox-authoring-kit/depends-on-injector"/>
<filter root="/apps/etoolbox-authoring-kit/install"/>
<filter root="/apps/etoolbox-authoring-kit/limit-parsys"/>
<filter root="/apps/etoolbox-authoring-kit/lists"/>

<!-- The following filters clear old directories in JCR content. They can be removed after v.2 release -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:ClientLibraryFolder"
categories="[cq.authoring.dialog]"
dependencies="[cq.authoring.dependson,cq.authoring.dependson.fixes,lists.item-dialog]"
dependencies="[cq.authoring.dependson,cq.authoring.dependson.fixes,lists.item-dialog,content-blueprints.toolbar-action,content-blueprints.limit-parsys]"
/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:granite="http://www.adobe.com/jcr/granite/1.0"
xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="cq:Page">
<createpagedialog
jcr:primaryType="nt:unstructured"
jcr:title="Create EToolbox Content Blueprint"
sling:resourceType="granite/ui/components/coral/foundation/dialog">
<items jcr:primaryType="nt:unstructured">
<form jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form"
action="/libs/wcm/core/content/sites/createpagewizard/jcr:content"
foundationForm="{Boolean}true"
method="post"
style="vertical">
<successresponse
jcr:primaryType="nt:unstructured"
jcr:title="Success"
sling:resourceType="granite/ui/components/coral/foundation/form/responses/openprompt"
open="/bin/wcmcommand?cmd=open&amp;_charset_=utf-8&amp;path={Path}"
text="Your page has been created."/>
<items jcr:primaryType="nt:unstructured">
<content jcr:primaryType="nt:unstructured"
jcr:title="Package setup"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
<items jcr:primaryType="nt:unstructured">
<column jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<charset
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="_charset_"
value="utf-8"/>
<parentPath
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="parentPath"
value="${requestPathInfo.suffix}"/>
<template
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="./cq:template"
value="/conf/etoolbox-authoring-kit/settings/wcm/templates/simple-content-blueprint"/>
<resourceType
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
name="./sling:resourceType"
value="/apps/etoolbox-authoring-kit/content-blueprints/components/structure/page-content-blueprint"/>
<pageProps
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/include"
resourceType="granite/ui/components/coral/foundation/container"
path="/apps/etoolbox-authoring-kit/content-blueprints/components/structure/page-content-blueprint/cq:dialog/content/items/tabs/items/mainConfig"/>
<create
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/button"
granite:class="lists-create-button"
text="Create"
type="submit"
variant="primary"/>
</items>
</column>
</items>
</content>
</items>
</form>
</items>
</createpagedialog>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:ClientLibraryFolder"
allowProxy="{Boolean}true"
categories="[content-blueprints.toolbar-action]"
jsProcessor="[min:gcc;languageIn=ECMASCRIPT_2015,compilationLevel=advanced,languageOut=ECMASCRIPT5]"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Import Toolbar Action to import "template" page content into current position
**/
(function ($document, author, ns) {
const IMPORT_ACTION = 'content-blueprint-import-action';

const JCR_CONTENT = '/jcr:content/';
const NEWPAR_TYPES = ['foundation/components/parsys/newpar', 'wcm/foundation/components/parsys/newpar', 'wcm/foundation/components/responsivegrid/new'];
const IMPORT_DIALOG_PATH = '/mnt/override/apps/etoolbox-authoring-kit/content-blueprints/components/content/toolbar/dialog/_cq_dialog.html';

function condition(editable) {
return author.pageInfoHelper.canModify() && editable.hasAction('INSERT');
}

function openImportDialog(editable) {
const target = editable.getParent();
const path = target.path;
const order = NEWPAR_TYPES.includes(editable.type) ? 'last' : `after ${editable.name}`;
const parentType = editable.getParent().type;

const page = path.substr(0, path.indexOf(JCR_CONTENT) + JCR_CONTENT.length);
const dialogPath = ns.EToolboxContentBlueprints.joinJCRPath(IMPORT_DIALOG_PATH, page);
const dialogConfig = {
src: ns.HTTP.externalize(dialogPath.replace(/\*\//, '')),
loadingMode: 'auto',
layout: 'auto'
};
const dlg = new author.ui.Dialog({
getConfig: () => dialogConfig,
getRequestData: () => ({ order, parentType, path }),
onSuccess: () => setTimeout(() => {
author.editableHelper.actions.REFRESH.execute(target);
}, 250)
});

author.DialogFrame.openDialog(dlg);
}

$document.off('cq-layer-activated.content-blueprint-import-action').on('cq-layer-activated.content-blueprint-import-action', function (ev) {
if (ev.layer === 'Edit') {
author.EditorFrame.editableToolbar.registerAction(IMPORT_ACTION, {
icon: 'coral-Icon--dataUpload',
text: Granite.I18n.get('Import from EToolbox Content Blueprint'),
handler: openImportDialog,
condition: condition,
isNonMulti: false
});
// Restore custom action after MSM
setTimeout(() => {
const action = author.EditorFrame.editableToolbar.config.actions[IMPORT_ACTION];
if (action && action.decoratedCondition) {
action.condition = action.decoratedCondition;
delete action.decoratedCondition;
console.log('Action "', action.name, '" undecorated');
}
});
}
});
})($(document), Granite.author, Granite);
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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.
*/
(function (author, ns) {
'use strict';

/**
* Join JCR path parts
* */
ns.joinJCRPath = function (path1, path2, ...rest) {
if (rest.length > 0) return ns.joinJCRPath(ns.joinJCRPath(path1, path2), ...rest);
return (path1 + '/' + path2).replace(/\/(\/)+/g, '/');
};

/**
* Join and normalize JCR path. Removes ending '/'
* */
ns.resolveJCRPath = function (path, ...rest) {
if (rest.length > 0) return ns.resolveJCRPath(ns.joinJCRPath(path, ...rest));
return path.replace(/\/$/, '').replace(/\/_jcr_content\//g, '/jcr:content/');
};

/**
* Resolve path to the JCR content
* */
ns.resolveJCRContentPath = function (path) {
return path ? ns.joinJCRPath(path, '/_jcr_content/') : '';
};

/**
* Check if the passed resource type can be placed inside of passed path
* */
ns.canInsert = function (resourceType, parentPath) {
if (!resourceType) return Granite.I18n.get('No component to insert');
if (!parentPath) return Granite.I18n.get('Insertion target is incorrect');

const component = author.components.find({ resourceType })[0];
if (!component) return Granite.I18n.get('Component resourceType is not is the list');

const componentPath = component.getPath();
const componentRelativePath = componentPath.replace(/^\/[a-z]+\//, '');
const componentGroup = 'group:' + component.getGroup();

const resolvedPath = ns.resolveJCRPath(parentPath);
const allowedComponents = author.components.allowedComponentsFor[resolvedPath];

if (!allowedComponents || !allowedComponents.length) {
return Granite.I18n.get('No allowed components found for {0}').replace('{0}', resolvedPath);
}

if (allowedComponents.indexOf(componentPath) === -1 &&
allowedComponents.indexOf(componentRelativePath) === -1 &&
allowedComponents.indexOf(componentGroup) === -1) {
return Granite.I18n.get('Component {0} is not allowed for current target').replace('{0}', component.getTitle());
}
return true;
};

const isValidComponentNode = (item) => {
return item && item['sling:resourceType'];
};

const findRootName = (content) => {
if (Object.hasOwnProperty.call(content, 'content-blueprints-parsys')) return 'content-blueprints-parsys';
return null;
};

/**
* Add ending '/' to the form action.
* @returns result path
* */
ns.setupInsertionFormTarget = function ($el, path) {
path = ns.joinJCRPath(path, '/');
$el.closest('form[action]').attr('action', path);
return path;
};

/**
* Fetch action successful response handler to resolve first content component
* */
ns.mapImportResourcePath = function (response, parentName, parentPath) {
try {
const rootName = findRootName(response);
if (!rootName) return '';
const root = response[rootName];
const nodeNames = Object.keys(root);
for (const name of nodeNames) {
const node = root[name];
if (!isValidComponentNode(node)) continue;
const path = ns.resolveJCRPath(parentPath, '/', rootName, '/', name);
const type = node['sling:resourceType'];
return JSON.stringify({ type, path, name });
}
} catch {
// no action
}
return '';
};
/** Fetch action unsuccessful response handler stub */
ns.mapImportResourcePathError = () => '';
}(Granite.author, Granite.EToolboxContentBlueprints = (Granite.EToolboxContentBlueprints || {})));
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import-helper.js
import-action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Component"/>
Loading