This is a collection of helpers to develop views as Angular SPA.
These tools are designed to help develop a graphical view. They assume XOS is running on your system and responding at: localhost:9999. The xos/configurations/frontend is normally sufficient for GUI development.
XOS comes with a set of common libraries, as listed in bower.json:
These libraries are served through Django, so they are not included in your minified vendor file. To add a library and generate a new file (that will override the old one):
ngXosLib folderbower install [myPackage] --savegulp vendorNOTE before adding libraries please discuss it on the devel list to avoid this file becoming too big
XOS comes with a helper library that is automatically loaded in the Django template.
To use it, add xos.helpers to your required modules:
angular.module('xos.myView', [
'xos.helpers'
])
It will automatically add a token to all your requests. Eventually you can take advantage of some other services:
?no_hyperlinks=1 to your request, to tell Django to return ids instead of links./xos endpoints./xoslib endpoints./hpcapi endpoints.NOTE: for the API related service, check the documentation in Section Apigen.
In addition to auto-generated Django Admin Views and developer-defined Service Views, a set of custom views can be generate in XOS.
These views are based on AngularJs and they communicate with XOS through the REST APIs, providing a powerful and flexible way to present and manage data.
Before getting started with new views you should create a configuration file to define the backend environment to be used. This file have to be in views/env/default.js and it content have to be:
module.exports = {
host: 'XOS Url',
xoscsrftoken: 'CSRF Token',
xossessionid: 'Sessio ID'
};
You can define multiple environment creating other configurations (eg: views/env/production.js) with the same structure.
We have created a yeoman generator to help scaffold views.
As it is in an early stage of development, you should manually link it to your system. To do this enter
/views/ngXosLib/generator-xosand runnpm link.
From /views run yo xos. This command will create a new folder with the provided name in /views/ngXosViews that contains your application.
If you left View name empty it should be
/views/ngXosViews/sampleView
In your view folder run npm start.
This will install the required dependencies and start a local server with BrowserSync.
If you want to use a different backend environment you can call the command with an environment variable:
NODE_ENV=production.js npm start
Once your view is done, from your view root folder, run: npm run build.
This will build your application and copy files in the appropriate directories for use by Django.
At this point you can enter: http://localhost:9999/admin/core/dashboardview/add/ and add your custom view.
NOTE: url field should be
template:xosSampleView
You can easily set this as a default view in a configuration by editing the {config}.yml file for that configuration. Add these lines:
{TabName}:
type: tosca.nodes.DashboardView
properties:
url: template:{viewName}
Then edit the User section (normally it starts with padmin@vicci.org) as follows:
padmin@vicci.org:
type: tosca.nodes.User
properties:
firstname: XOS
lastname: admin
is_admin: true
requirements:
- tenant_dashboard:
node: Tenant
relationship: tosca.relationships.UsesDashboard
- {custom_dashboard}:
node: {TabName}
relationship: tosca.relationships.UsesDashboard
To install a local dependency use bower with --save. Common modules are saved in devDependencies as they already loaded in the Django template.
The npm start command watches your dependencies and will automatically inject it in your index.html.
A styleguide is enforced through EsLint and is checked during the build process. We highly recommend installing the linter in your editor to have realtime hints.
The generator sets up a test environment with a default test. To run it, execute: npm test