Skip to content

Commit

Permalink
Switch content selector to default tree-structure #4933
Browse files Browse the repository at this point in the history
  • Loading branch information
vbradnitski committed Jun 28, 2017
1 parent 2fcc65d commit 6cda60f
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 26 deletions.
Expand Up @@ -1346,11 +1346,11 @@ public List<ContentTreeSelectorJson> treeSelectorQuery( final ContentTreeSelecto
final ContentPath parentPath = contentQueryJson.getParentPath();
final Integer parentPathSize = parentPath != null ? parentPath.elementCount() : 0;

final ContentPaths layerPaths = ContentPaths.from( contents.stream().
final List<ContentPath> layerPaths = contents.stream().
filter( content -> parentPath != null ? content.getPath().isChildOf( parentPath ) : true ).
map( content -> content.getPath().getParentPath( content.getPath().elementCount() - parentPathSize - 1 ) ) );
map( content -> content.getPath().getParentPath( content.getPath().elementCount() - parentPathSize - 1 ) ).collect( Collectors.toList());

final Contents layerContents = contentService.getByPaths( layerPaths );
final Contents layerContents = contentService.getByPaths( ContentPaths.from( layerPaths) );

return layerContents.stream().map(
content -> new ContentTreeSelectorJson( new ContentJson( content, contentIconUrlResolver, principalsResolver ),
Expand Down
Expand Up @@ -158,7 +158,9 @@ module api.ui.selector {
}
if (selectedOption) {
let row = this.dropdownGrid.getRowByValue(selectedOption.value);
this.dropdownGrid.navigateToRow(row);
if(row != undefined) {
this.dropdownGrid.navigateToRow(row);
}
} else {
this.dropdownGrid.navigateToFirstRow();
}
Expand Down
Expand Up @@ -100,7 +100,7 @@ module api.ui.selector {
}

isEmptyNode(node: TreeNode<Option<OPTION_DISPLAY_VALUE>>): boolean {
return !node.getData().displayValue;
return !(node.getData() && node.getData().displayValue);
}

fetch(node: TreeNode<Option<OPTION_DISPLAY_VALUE>>, dataId?: string): wemQ.Promise<Option<OPTION_DISPLAY_VALUE>> {
Expand Down
Expand Up @@ -247,7 +247,12 @@ module api.ui.selector.combobox {

const inputEl = this.input.getEl();
const parent = restrainToBody(this.getScrollableParent(inputEl));
const dropdown = this.comboBoxDropdown.getDropdownGrid().getElement().getEl();

let dropdown = this.comboBoxDropdown.getDropdownGrid().getGrid().getEl();

if(!dropdown.isVisible()) {
dropdown = this.comboBoxDropdown.getEmptyDropdown().getEl();
}

// If the page is in iframe page is not scrollable and fully rendered
// The height of the iframe should be used instead
Expand Down Expand Up @@ -286,15 +291,15 @@ module api.ui.selector.combobox {
}

private placeDropdownBelow() {
let dropdown = this.comboBoxDropdown.getDropdownGrid().getElement().getEl();
let dropdown = this.comboBoxDropdown.getDropdownGrid().getGrid().getEl();
dropdown.removeClass('reverted');

let inputEl = this.input.getEl();
this.comboBoxDropdown.setTopPx(inputEl.getHeightWithBorder() - inputEl.getBorderBottomWidth());
}

private placeDropdownAbove() {
let dropdown = this.comboBoxDropdown.getDropdownGrid().getElement().getEl();
let dropdown = this.comboBoxDropdown.getDropdownGrid().getGrid().getEl();
let placeholder = this.comboBoxDropdown.getEmptyDropdown().getEl();

dropdown.setTopPx(-dropdown.getHeightWithBorder()).addClass('reverted');
Expand Down Expand Up @@ -749,7 +754,10 @@ module api.ui.selector.combobox {
this.handleRowSelected(event.getRow());
});

this.comboBoxDropdown.onRowCountChanged(() => this.comboBoxDropdown.markSelections(this.getSelectedOptions() || []));
this.comboBoxDropdown.onRowCountChanged(() => {
this.comboBoxDropdown.markSelections(this.getSelectedOptions() || []);
this.doUpdateDropdownTopPositionAndWidth();
});

this.dropdownHandle.onClicked((event: MouseEvent) => {
event.preventDefault();
Expand Down Expand Up @@ -1030,7 +1038,7 @@ module api.ui.selector.combobox {
}

private notifyExpanded(expanded: boolean) {
const grid: api.dom.Element = <api.dom.Element>this.comboBoxDropdown.getDropdownGrid().getElement();
const grid: api.dom.Element = <api.dom.Element>this.comboBoxDropdown.getDropdownGrid().getGrid();
const event = new api.ui.selector.DropdownExpandedEvent(grid, expanded);
this.expandedListeners.forEach((listener: (event: api.ui.selector.DropdownExpandedEvent) => void) => {
listener(event);
Expand Down
Expand Up @@ -110,5 +110,13 @@
padding-left: 10px;
margin-right: 10px;
}

.selected {
.@{_COMMON_PREFIX}names-view {
.@{_COMMON_PREFIX}main-name {
color: white;
}
}
}
}
}
Expand Up @@ -91,6 +91,12 @@ public Builder addNodePath( final NodePath nodePath )
return this;
}

public Builder addNodePaths( final Collection<NodePath> nodePaths )
{
this.nodePaths.addAll( nodePaths );
return this;
}

public NodePaths build()
{
return new NodePaths( this );
Expand Down
@@ -1,5 +1,6 @@
package com.enonic.xp.node;

import java.util.Collection;
import java.util.Set;

import com.google.common.annotations.Beta;
Expand Down Expand Up @@ -43,6 +44,12 @@ public Builder add( final NodeVersionId nodeVersionId )
return this;
}

public Builder addAll( final Collection<NodeVersionId> nodeVersionIds )
{
this.nodeVersionIds.addAll( nodeVersionIds );
return this;
}


public NodeVersionIds build()
{
Expand Down
Expand Up @@ -28,10 +28,11 @@ public static NodePath translateContentPathToNodePath( final ContentPath content
public static NodePaths translateContentPathsToNodePaths( final ContentPaths contentPaths )
{
final NodePaths.Builder builder = NodePaths.create();
for ( final ContentPath contentPath : contentPaths )
{
builder.addNodePath( ContentNodeHelper.translateContentPathToNodePath( contentPath ) );
}

builder.addNodePaths(
contentPaths.stream().map( ( contentPath -> ContentNodeHelper.translateContentPathToNodePath( contentPath ) ) ).collect(
Collectors.toList() )
);

return builder.build();
}
Expand Down
@@ -1,5 +1,6 @@
package com.enonic.xp.repo.impl.branch.storage;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -155,17 +156,9 @@ public NodeBranchEntry get( final NodePath nodePath, final InternalContext conte
@Override
public NodeBranchEntries get( final NodePaths nodePaths, final InternalContext context )
{
Set<NodeBranchEntry> nodeBranchEntries = Sets.newHashSet();

for ( final NodePath nodePath : nodePaths )
{
final NodeBranchEntry branchVersion = doGetByPath( nodePath, context );

if ( branchVersion != null )
{
nodeBranchEntries.add( branchVersion );
}
}
final List<NodeBranchEntry> nodeBranchEntries = nodePaths.stream().
map( nodePath -> doGetByPath( nodePath, context ) ).
filter( branchVersion -> branchVersion != null ).collect( Collectors.toList() );

return NodeBranchEntries.from( nodeBranchEntries );
}
Expand Down
@@ -1,5 +1,7 @@
package com.enonic.xp.repo.impl.storage;

import java.util.stream.Collectors;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

Expand Down Expand Up @@ -342,7 +344,8 @@ private void storeVersionMetadata( final Node node, final InternalContext contex
private Nodes doReturnNodes( final NodeBranchEntries nodeBranchEntries )
{
final NodeVersionIds.Builder builder = NodeVersionIds.create();
nodeBranchEntries.forEach( ( nodeBranchVersion ) -> builder.add( nodeBranchVersion.getVersionId() ) );

builder.addAll( nodeBranchEntries.stream().map( nodeBranchVersion -> nodeBranchVersion.getVersionId() ).collect( Collectors.toList() ));

final NodeVersions nodeVersions = nodeVersionService.get( builder.build() );

Expand Down

0 comments on commit 6cda60f

Please sign in to comment.