Skip to content
This repository

A Grails plugin for scaffolding views using Angular.js

branch: master
readme.md

This is a Grails plugin that allows you to use Angular.js based scaffolding.

Usage

After installing the plugin run:

grails ng-install-templates

This will install the Angular JS scaffolding templates into your project under src/templates/scaffolding. It will also copy some common HTML template files that will be shared by all scaffolded views into web-app/ng-templates.

Static scaffolding

To generate the controller and views for a domain class run:

grails ng-generate-all _domain class name_

Dynamic scaffolding

Dynamic scaffolding is only supported for the controller. Currently you will need to generate the views for each domain class.

To generate only the views and use a dynamically scaffolded controller run:

grails ng-generate-views _domain class name_

How it works

Instead of the Grails controller rendering a view for each page using a GSP the controller's index action serves up an initial framework page containing the JavaScript resources required by Angular JS. The remaining controller actions simply return JSON data.

Each 'page' in the CRUD interface for a particular domain class is accessed using a URL fragment; #/list, #/create, etc. The page content is rendered by Angular JS using an HTML template and the data to populate the page is retrieved from the controller using an AJAX call.

The HTML templates need to be generated individually for each domain class as they contain the markup needed to represent the properties of that class in a list or a form. However, the JavaScript used for the CRUD interface is the same for all domain classes.

Customizing

Enable optimistic locking check

By default, the JSON converter does not send the object's "version" field generated by Hibernate. Because of that, the controller does not check when concurrent modifications occur. To enable optimistic locking check, simply add the following in your Config.groovy:

grails.converters.json.domain.include.version = true

Using Grails RESTful URL mappings

By default Grails uses a non-RESTful URL scheme where the controller action representing the verb is part of the URL. In the Grails documentation there is a section on configuring RESTful URL mappings. If you want to use such a URL scheme with this plugin you will need to override the web-app/js/grails-default.js file that configures an Angular $resource service that maps to your Grails controllers.

Limitations

This is an experimental work-in-progress. See the issues list for outstanding features.

Demo

There is a demo of this plugin running on Cloud Foundry.

The demo application is also included under test/apps/grails-ng in this project.

Tests

There are some end-to-end tests that use Casper JS. To run the tests:

cd test/apps/grails-ng
grails run-app

Then in another terminal:

casperjs test --includes=test/casper/includes/casper-angular.coffee test/casper/specs/
Something went wrong with that request. Please try again.