Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #804 from ezsystems/ezp-26872_starting_location
Browse files Browse the repository at this point in the history
EZP-26872: Add support for starting Location id in the UDW Finder
  • Loading branch information
dpobel authored Feb 15, 2017
2 parents 24658ee + b16570b commit fb96bce
Show file tree
Hide file tree
Showing 12 changed files with 756 additions and 137 deletions.
38 changes: 33 additions & 5 deletions Resources/public/js/views/ez-universaldiscoveryview.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ YUI.add('ez-universaldiscoveryview', function (Y) {
*/
_updateMethods: function () {
var visibleMethod = this.get('visibleMethod'),
startingLocationId = this.get('startingLocationId');
startingLocationId = this.get('startingLocationId'),
startingLocation = this.get('startingLocation'),
virtualRootLocation = this.get('virtualRootLocation');

/**
* Stores a reference to the visible method view
Expand All @@ -282,9 +284,11 @@ YUI.add('ez-universaldiscoveryview', function (Y) {
var visible = (visibleMethod === method.get('identifier'));

method.setAttrs({
'virtualRootLocation': virtualRootLocation,
'multiple': this.get('multiple'),
'loadContent': true,
'startingLocationId': startingLocationId,
'startingLocation': startingLocation,
'visible': visible,
'isSelectable': Y.bind(this.get('isSelectable'), this),
'active': this.get('active'),
Expand Down Expand Up @@ -502,16 +506,36 @@ YUI.add('ez-universaldiscoveryview', function (Y) {
},

/**
* The location id that the UDW tree will select on start
* The id of a Location that should be considered as the starting
* point when discovering Content.
*
* @attribute startingLocationId
* @type {String}
* @default false if there is no starting location
*
*/
startingLocationId: {
value: false,
},

/**
* The Location that should be considered as the starting point when
* discovering Content.
*
* @attribute startingLocation
* @type {eZ.Location|false}
*/
startingLocation: {
value: false,
},

/**
* The virtual root Location object.
*
* @attribute virtualRootLocation
* @type {eZ.Location}
*/
virtualRootLocation: {},

/**
* Flag indicating whether the Content should be provided in the
* selection.
Expand Down Expand Up @@ -563,15 +587,19 @@ YUI.add('ez-universaldiscoveryview', function (Y) {
multiple: this.get('multiple'),
loadContent: true,
isAlreadySelected: Y.bind(this._isAlreadySelected, this),
startingLocationId: this.get('startingLocationId')
startingLocationId: this.get('startingLocationId'),
startingLocation: this.get('startingLocation'),
virtualRootLocation: this.get('virtualRootLocation'),
}),
new Y.eZ.UniversalDiscoverySearchView({
bubbleTargets: this,
priority: 200,
multiple: this.get('multiple'),
loadContent: true,
isAlreadySelected: Y.bind(this._isAlreadySelected, this),
startingLocationId: this.get('startingLocationId')
startingLocationId: this.get('startingLocationId'),
startingLocation: this.get('startingLocation'),
virtualRootLocation: this.get('virtualRootLocation'),
}),
];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,63 @@ YUI.add('ez-universaldiscoveryviewservice', function (Y) {
* @extends eZ.ViewService
*/
Y.eZ.UniversalDiscoveryViewService = Y.Base.create('universalDiscoveryViewService', Y.eZ.ViewService, [Y.eZ.SideViewService], {
/**
* Loads the starting location of the UDW if there is a provided starting location id.
* Else starting location is set to false.
*
* @method _load
* @protected
* @param {Function} callback
*/
_load: function (callback) {
var startingLocation,
parameters = this.get('parameters'),
app = this.get('app');

if ( parameters.startingLocationId ) {
startingLocation = new Y.eZ.Location();
startingLocation.set('id', parameters.startingLocationId);
app.set('loading', true);

this._loadStartingLocationPath(startingLocation, Y.bind(function(startingLoc) {
this.set('startingLocation', startingLoc);
app.set('loading', false);

callback();
}, this));
} else {
this.set('startingLocation', false);
callback();
}
},

/**
* Loads the path of the UDW starting Location.
*
* @method _loadStartingLocationPath
* @protected
* @param {eZ.Location} startingLocation
* @param {Function} callback Executed after loading the path. Takes the
* location containing the path in parameter or false if loading error.
*/
_loadStartingLocationPath: function (startingLocation, callback) {
var options = {api: this.get('capi')};

startingLocation.load(options, function (error) {
if (!error) {
startingLocation.loadPath(options, function (error) {
if (!error) {
callback(startingLocation);
} else {
callback(false);
}
});
} else {
callback(false);
}
});
},

/**
* Returns the value of the `parameters` attribute. This attribute is set
* when the app shows the universal discovery side view with the
Expand All @@ -31,7 +88,47 @@ YUI.add('ez-universaldiscoveryviewservice', function (Y) {
* @return mixed
*/
_getViewParameters: function () {
return this.get('parameters');
var params = Y.merge(this.get('parameters'));

params.virtualRootLocation = this.get('virtualRootLocation');
params.startingLocation = this.get('startingLocation');
return params;
},
}, {
ATTRS: {

/**
* Holds the starting location where the UDW will start.
* False if no starting location defined
*
* @attribute startingLocation
* @default false
* @type {eZ.Location|False}
*/
startingLocation: {
value: false,
},

/**
* Holds the virtual root location
*
* @attribute virtualRootLocation
* @type {eZ.Location}
*/
virtualRootLocation: {
valueFn: function () {
return new Y.eZ.Location({
id: '/api/ezp/v2/content/locations/1',
locationId: 1,
sortField: 'SECTION',
sortOrder: 'ASC',
// this is hardcoded but the actual value does not
// really matter, what matters is the fact the virtual
// root has at least a child.
childCount: 4,
});
},
},
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,28 @@ YUI.add('ez-universaldiscoveryfinderexplorerlevelview', function (Y) {
container.plug(Y.Plugin.ScrollInfo);
container.scrollInfo.on('scrollDown', this._handleScroll, this);

this.after('ownSelectedItemChange', function () {
if (!this.get('ownSelectedItem')) {
container.removeClass(HAS_SELECTED_ITEM);
} else {
container.addClass(HAS_SELECTED_ITEM);
}
});
this.after('ownSelectedItemChange', this._uiOwnSelectedItem);
this._uiOwnSelectedItem();
this._addDOMEventHandlers(events);
},

/**
* Adds or removes the has selected item class on the container
* depending on the `ownSelectedItem` attribute value.
*
* @method _uiOwnSelectedItem
* @protected
*/
_uiOwnSelectedItem: function () {
var container = this.get('container');

if (!this.get('ownSelectedItem')) {
container.removeClass(HAS_SELECTED_ITEM);
} else {
container.addClass(HAS_SELECTED_ITEM);
}
},

render: function () {
var container = this.get('container'),
itemsJSONified = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,55 @@ YUI.add('ez-universaldiscoveryfinderexplorerview', function (Y) {
Y.eZ.UniversalDiscoveryFinderExplorerView = Y.Base.create('universalDiscoveryFinderExplorerView', Y.eZ.TemplateBasedView, [], {
initializer: function () {
this.after('activeChange', function () {
if (this.get('active')) {
if ( this.get('active') ) {
this.wakeUp();
}
});
this.on('*:explorerNavigate', function(e) {
this._handleLevelViews(e.target, e.depth, e.location);
});
this.after('startingLocationChange', function (e) {
if ( e.newVal === e.prevVal ) {
// This is to avoid rebuilding the level views when a
// starting location is set and when switching to another
// method and getting back to the finder. In that, case
// `startingLocationChange` is fired even if the very same
// Location object is set...
return;
}
this._removeLevels();
this._getLevelViewPath().forEach(function (location, index, path) {
var next = path[index + 1];

if ( next ) {
this._addLevel(location, next.get('locationId'));
} else if ( location.get('childCount') !== 0 ) {
this._addLevel(location);
}
}, this);
});
},

/**
* Returns a Location array representing the path to display. This path
* includes the virtual root Location, the starting Location path and
* the starting Location (if there's a starting Location).
*
* @method _getLevelViewPath
* @protected
* @return {Array} of Location.
*/
_getLevelViewPath: function () {
var startingLocation = this.get('startingLocation'),
path = [];

if ( startingLocation ) {
path = startingLocation.get('path').concat();
path.push(startingLocation);
}

path.unshift(this.get('virtualRootLocation'));
return path;
},

/**
Expand All @@ -38,13 +80,8 @@ YUI.add('ez-universaldiscoveryfinderexplorerview', function (Y) {
* @method reset
*/
reset: function (name) {
var count;

if (name == 'levelViews') {
count = this.get('levelViews').length - 1;

this._removeLevels(count);
this.get('levelViews')[0].reset();
this._removeLevels();
} else {
this.constructor.superclass.reset.apply(this, arguments);
}
Expand Down Expand Up @@ -72,7 +109,7 @@ YUI.add('ez-universaldiscoveryfinderexplorerview', function (Y) {
*/
_handleLevelViews: function (levelView, depth, location) {
var count;

if (depth < this.get('levelViews').length) {
count = this.get('levelViews').length - depth;
this._removeLevels(count);
Expand Down Expand Up @@ -121,12 +158,15 @@ YUI.add('ez-universaldiscoveryfinderexplorerview', function (Y) {
},

/**
* Removes and destroy the last level views from the levelViews attribute.
* Removes and destroy level views.
*
* @method _removeLevels
* @param {Number} count the number of levelviews to remove.
* @param {Number} [count] the number of level views to remove. If
* omitted, the complete list is removed.
* @protected
*/
_removeLevels: function (count) {
count = count || this.get('levelViews').length;
for (var i=0; i < count; i++) {
this.get('levelViews').pop().destroy({remove: true});
}
Expand All @@ -138,11 +178,15 @@ YUI.add('ez-universaldiscoveryfinderexplorerview', function (Y) {
*
* @method _addLevel
* @param {Y.eZ.Location} location the parent location
* @param {Number} selectedLocationId the location id that should be
* selected in the level view
* @protected
*/
_addLevel: function (location) {
_addLevel: function (location, selectedLocationId) {
var LevelView = this.get('levelViewConstructor'),
levelView = new LevelView({
parentLocation: location,
selectLocationId: selectedLocationId,
depth: this.get('levelViews').length + 1,
});

Expand All @@ -169,20 +213,34 @@ YUI.add('ez-universaldiscoveryfinderexplorerview', function (Y) {
},
},

/**
* The starting Location if the UDW is configured with one.
*
* @attribute startingLocation
* @type {eZ.Location|false|Null}
* @default {Null}
*/
startingLocation: {
value: null,
},

/**
* The virtual root Location object
*
* @attribute virtualRootLocation
* @type {eZ.Location}
* @required
*/
virtualRootLocation: {},

/**
* The tab containing the universalDiscoveryFinderExplorerLevelViews to explore.
*
* @attribute levelViews
* @type Array
*/
levelViews: {
valueFn: function () {
return [new Y.eZ.UniversalDiscoveryFinderExplorerLevelView({
parentLocation: this.get('startingLocation'),
depth: 1,
bubbleTargets: this,
})];
}
value: [],
},
},
});
Expand Down
Loading

0 comments on commit fb96bce

Please # to comment.