AngularJS by Google has been built to offer front-end developers all the tools they may need to turn a website into a modern web application. AngularJS is a great JavaScript framework that provides many features (directives, routes, modules, etc.) to turn your HTML pages into dynamic views. This answers your front-end needs. But your application also needs a serious back end that will allow you to build your application quickly and concentrate on features without reinventing the wheel. This is what the Nuxeo Platform will provide you with. When users browse your web application, it will actually call the Nuxeo Platform through its REST API in order to handle and retrieve content.
AngularJS has some specific needs that need to be taken care of. This motivated us to write a specific client, in order to get a clean implementation. A wrapper around the existing Nuxeo JavaScript client has therefore been developed. This is the angular-nuxeo project.
The angular-nuxeo project brings some AngularJS-related improvements over the regular Nuxeo JavaScript client:
- The client can be installed as an AngularJS module, that can easily be installed through bower.
- Ajax calls are handled through AngularJS's promises mechanism. Any call you do will therefore let you use a callback function when it succeeds, and a separate one when an error occurs.
Bootstrapping an AngularJS Project With Nuxeo
This section will help you getting started with an AngularJS project. This will be covered in three steps:
- Installing prerequisites
- Using Yeoman's generator and Nuxeo Angular sample to get an AngularJS application running
- Building a Nuxeo Package that can be deployed on a Nuxeo Platform instance
Step 1 - Installing Prerequisites
In order to get a clean installation, we will make use of Yeoman's angular generator. So let's install it along with its prerequisites:
- Install Git.
- Install node.js.
In a terminal, use
npm
to install the generator:npm install -g grunt-cli bower yo generator-karma generator-angular
Step 2 - Building an AngularJS Application from the Nuxeo Angular Sample Project
- Clone the Nuxeo Angular Sample project.
- Using a terminal
cd
to the project'snuxeo-angular-sample-front/src/main/yo
folder. Run the following command:
yo angular [yourAppName]
When prompted, answer:
- Would you like to use Sass (with Compass)? (Y/n) You decide
- Would you like to include Bootstrap? (Y/n) You decide
- Which modules would you like to include? You decide
- Overwrite package.json? (Y/n) Y At that point, you get a ready to use AngularJS application. It is time to add the nuxeo module.
Add the angular-nuxeo dependency by running the following:
bower install https://github.com/nuxeo-sandbox/angular-nuxeo.git --save
Edit the
app/scripts/app.js
file to add the nuxeo module. The file should look somewhat like this:angular .module('someModule', '...', 'nuxeo' ])
Adapt the project to your needs:
- Go to the
nuxeo-angular-sample-front/src/main/yo
folder. Edit the
Grunfile.js
file to configure the dist folder as below. Replacemyapp
with the folder name you want to put your application into:// Configurable paths for the application var appConfig = { app: require('./bower.json').appPath || 'app', // Replace dist: 'dist' by the line below. Put your app folder name instead of myapp. dist: '../../../target/classes/web/nuxeo.war/myapp' }; ...
Go to the
nuxeo-angular-sample-front/src/main/resources/OSGI-INF
folder.- In the
authentication-contrib.xml
anddeployment-fragment.xml
files, replacemyapp
with your application's folder name. The goal of this step is to make sure that when requesting a URL which is part of your application, people will be asked for authentication, then redirected to your application once logged in.
- Go to the
- Go to the
nuxeo-angular-sample-front/src/main/yo
folder. Init your app
bower install npm install
You are now free to reference the nuxeo module into your controllers.
Run
grunt serve
from your terminal and enjoy the result!
For detailed usage of the nuxeo angular client, take a look at its GitHub documentation. Note that as your application will be deployed in an existing instance, users will be asked for authentication by the Nuxeo Platform. Therefore, you do not need the client to send any authentication and actual testing can be done by installing a Nuxeo Platform locally on your machine. You can use grunt to preview your application by running grunt serve
from a terminal.
Step 3 - Deploying the AngularJS Application in a Nuxeo Instance
Deploying an embedded application consists in putting your AngularJS application into the Nuxeo Platform's nuxeo.war
folder. By doing so, people will be able to access it using a URL like http://mynuxeoinstanceurl/nuxeo/myapp. See the section Deployment options.
The good news is the Nuxeo Angular Sample project already provides you with everything you need to deploy the application in a clean fashion, through a Nuxeo Package. Quick reminder: Nuxeo Packages allow you to deploy bundles, resources, libraries and much more on your server easily. They are versioned and can be installed, upgraded, uninstalled either from the graphical interface or the command line. All of this makes life easier for developers and sysadmins alike. See the page Installing a New Package on Your Instance.
Build the Nuxeo Package by following these instructions:
- Using a terminal,
cd
to thenuxeo-angular-sample
folder. Run:
mvn clean install
The Nuxeo Package is now built and available into the nuxeo-angular-sample/marketplace-nuxeo-angular-sample/marketplace/target folder. if you did not change its configuration, it will be called marketplace-nuxeo-angular-sample-0.1-SNAPSHOT.zip by default.
Install the Nuxeo Package in your Nuxeo Platform instance.
- Go to http://mynuxeoinstanceurl/nuxeo/myapp and enjoy your brand new AngularJS application.
Deployment Options
There are two possible ways to deploy your application.
- Embedded mode: having your AngularJS application into your Nuxeo Platform instance.
- Isolated mode: keep your AngularJS web application separated from your Nuxeo Platform instance.
We are always eager to receive feedback on our projects. Please report bugs, wishes or anything related to the nuxeo-angular-sample project at answers.nuxeo.com