Extending PlatformUI
eZ Conference 2015 workshop
Plan
Introduction to PlatformUI
PlatformUI quick intro
Content management vs. Admin part
Architecture
Quick demo
Extending PlatformUI
Expected result
9 steps
Questions
Single Page Application
JavaScript MV* based on YUI
2 different parts
Content management part
Admin part
Different feature wise
Different code wise
Content management vs. Admin part
Content management part
Heavily uses the Platform REST API
Calls the Repository
Gives JSON data (Location, Content, ...)
Fully rendered in the browser
JavaScript code (App, View, Models, ...)
Handlebars template
Content management vs. Admin part
Admin part
Partly rendered server side
PJAX
Symfony controllers to generate the HTML code
Symfony/Twig/Public API or whatever PHP API
JavaScript
to integrate the HTML in the application
to enhance the UI
We'll try to analyze/expirement both!
Architecture
Application
Models: Content, Location, Content Type, Content Info, ...
Views (and sub-views)
display and interact with the user
View services
Plugins
* back and forth with the architecture schema
Quick demo
Open dev tools
Login
Display a content
Go to the admin part
Expected extension
As an editor, I want to be able to browse the content with a flat list
As an editor, I want to be able to filter this list by content type
VIDEO
9 steps to get there
Create the Bundle
Setup the configuration
Alter the application routing
Define the view
Add the link in the navigation menu
Get the content list (2 ways)
Pagination
Filter by content types
Enhancements / bug fixes
A normal Symfony bundle
Auto-generated with the bundle generator
$ ezpublish/console generate:bundle \
--namespace=EzSystems/ExtendingPlatformUIConferenceBundle \
--dir=src --format=yml --no-interaction
Add the bundle to the kernel
Import the routing.yml
Result: tag 1_bundle | See the diff | Browse the code
2. Configuration
2 specific configuration files
yui.yml
(View on Github )
List the available modules
Module ≃ a file defining a component + its dependencies
css.yml
(View on Github )
List the CSS files to load
A typical PlatformUI extension will need both
open the files in the browse
explain modules
2. Configuration
Tweak the ExtendingPlatformUIConferenceExtension class
to load yui.yml
and css.yml
to process the configuration
Configure the bundle to provide assets
3. App routing
Takes the hash into account
Matches a route (Route list )
Route properties:
path
(or regexp) to match
view
to use render something in the browser
list of middlewares to execute
[optionally] name
to generate links
[optionally] sideViews
configuration
[optionally] view service
open the route definition
shows the different route + explain middlewares
3. App routing
App plugin to add our own route
declare the plugin module in yui.yml
set this module as a dependencyOf
the application module
write a plugin for the application
add the route on the application (the host
object)
4. Main view
Each route defines a view to render
View responsibility
Generating the UI
Handling user input (click, keyboard, ...)
This view can have an arbitrary number of sub-views
Good practice to use small views
4. Main view
Create a very basic view for the list
Make sure the route is configured to use it
Change the view to use a Handlebars template
Add a stylesheet
5. Navigation
Navigation hub: top menu
4 Navigation zones: Content, Page, Performance and Admin Panel
n Navigation Items in each zone:
a View
typically generates a link to a route
responsible for handling its selected state
3 existing implementations
structure defined in the eZ.NavigationHubViewService
5. Navigation
Add a eZ.NavigationItemView
for our route
Plugin for the NavigationHubViewService
to add it
Create the plugin
Add the navigation item for our list route
6. Content list
2 ways to build pages
Let's try both
Rendered fully in the browser: REST + JavaScript + Handlebars
Partially rendered on the server: Symfony/PHP/Public API + Twig + JavaScript
6.1. Client side Content list
Add a view service to load the list with the REST API
Change the route to use this service
Location search with the REST API
Give this list to the list view
Render this list in the view
6.2. Server side Content list
Regular AJAX call(s)
Response is structured to be easily usable in JavaScript
title
: to generate the window title
html
: to get the HTML code to use in the application
notification
: to generate application notification
This can be reused in extensions
6.2. Server side Content list
Implement a Symfony controller/action to generate the list
Fetch the HTML code in the view service
Give the generated code to the view
Render the list inside the view
Handle the links so the list is usable in PlatformUI
DOM event handler in the view
Application level event + Event bubbling
By default the search returns 25 results
Need pagination!
Add an offset
parameter to the server side code
Add an offset
parameter to the app route
Pass the client side offset to the server side
Add the previous/next links in the server response
Enhance those links to navigate in the application
8. Filter by Content Type
Add a type
parameter to the server side code
Add a type
parameter to the app route
Pass the client side type to the server side
Handle the pagination links
Add a drop down list to select the content type
Handle the drop down list selection
9. Bug (fixes) / Enhancements
Improve the look and feel and output (13d5a0b2 )
Reload only the table not the full view when filtering
Sorting
More filters, more columns ...
The server side code deserves to be refactored
Unit tests
[bug] Highlight is buggy in navigation
[bug] 'eng-GB' hardcoded when getting Content Type name
Other than that, it works :)
Question(s) ?
Want to help or to learn more ?
1
Extending PlatformUI
eZ Conference 2015 workshop
Damien Pobel
Lead Engineer UI
dp@ez.no
@dpobel
This presentation is online:
http://j.mp/extending-platformui
ExtendingPlatformUIConferenceBundle is available on Github