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

EZP-23012: As a developer, I want to be able to extend the application view services #98

Merged
merged 1 commit into from Jul 28, 2014

Conversation

dpobel
Copy link
Contributor

@dpobel dpobel commented Jul 10, 2014

JIRA: https://jira.ez.no/browse/EZP-23012

Description

The idea is to make possible to extend view services (and later others types of components) with the YUI Plugin system. Basically, the developer will be able to register plugins for some components in a global registry and those plugins will be dynamically added. Together with the configuration system proposed in #95, this will allow to cleanly extend almost anything in the Platform UI App. This will also be useful for us to decouple components into smaller pieces.

View service plugins

The view service plugin can enhance the view service in the following ways:

  • by adding a custom parallelLoad method in the plugin, it's possible to asynchronously load some data in parallel with the loading done by the view service (and others plugins)
  • by adding a custom afterLoad method in the plugin, it's possible to asynchronously load some data after the loading done by the view service (other the others plugin). For instance, the developer wants to fetch something by using what is loaded before.
  • the view associated with the service get the result of the merge between the view service and the plugin getViewParameters implementations

In addition, the view service plugins are normal YUI plugins so from a plugin you can subscribe to any event the service get (that's what is done in this PR in the content tree and object relation load plugins) and you can also enhance any method implemented by the service by adding your own behavior before or after the original method execution.

Tasks

  • implement a plugin registry
  • define a base class for the view service plugins and change base view service to take plugins into account
  • reorganize existing view service code in plugins
    • object relation related code in location view view service
    • content tree related code in discovery bar view service
  • if time, add the same concepts to others types of components (apps, views, ...) (will be implemented in EZP-23147)

Tests

unit tests + manual tests

@dpobel dpobel changed the title [WIP] EZP-23012: As a developer, I want to be able to extend the application view services EZP-23012: As a developer, I want to be able to extend the application view services Jul 21, 2014
@dpobel
Copy link
Contributor Author

dpobel commented Jul 21, 2014

Ready to be reviewed!

@@ -16,7 +17,8 @@ module.exports = function(grunt) {
],
testFiles = [
"./Tests/js/*/*/*.js",
"./Tests/js/*/*/*/*.js"
"./Tests/js/*/*/*/*.js",
"./Tests/js/*/*/*/*/*.js",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use the following: ".Tests/js/*/.js" instead of these four lines above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point and good question :-)
As far as I can remember, a former colleague had issues with that in Windows... But I guess, we can use this syntax now and see if someone shouts about it :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using the shorter syntax since I started to use Grunt and I have never had any problems with it, no matter what system I worked on.

@sunpietro
Copy link
Contributor

What about adding view templates into shell.html.twig file?

@dpobel
Copy link
Contributor Author

dpobel commented Jul 22, 2014

for the templates: it's planned but one step at a time :) The next step is to apply more or less the same system to others components (view, apps, model maybe, ...) and then the question about templates and CSS files will arise.

}
Y.Array.each(components, function (identifier) {
plugins[identifier] = plugins[identifier] || [];
plugins[identifier].push(constructor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason you're checking whether the plugins[identifier] is existing? As far as I can see in the Firebug, there I always assigned an empty array, so it could be just this: plugins[identifier] = [];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, if you do that you won't be able to register several plugins for a given component as the plugins array will be reseted. (there's a unit test for that and its fails with your suggestion)

@bdunogier
Copy link
Member

+0

var ns1 = 'pluginNs1',
ns2 = 'pluginNs2',
plugin1 = _generatePlugin(ns1),
plugin2 = _generatePlugin(ns2),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Wouldn't it be better to use _generatePlugin() function once and accept an array as parameter?

@dpobel
Copy link
Contributor Author

dpobel commented Jul 28, 2014

Self note: s/user strict/use strict/ after merging, see https://github.com/ezsystems/PlatformUIBundle/pull/98/files#r15453365

@sunpietro
Copy link
Contributor

Apart from the comments I made earlier: +1
It would be a good thing to create a simplified tutorial, some usage example.

EZP-23147: As a developer, I want to be able to write plugins for views
@dpobel dpobel merged commit a47e187 into master Jul 28, 2014
@dpobel dpobel deleted the ezp-23012_extend_view_services branch July 28, 2014 12:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
3 participants