Migrated docbuilder code to an angularjs controller