Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "loopback"
}
5 changes: 0 additions & 5 deletions .jshintignore

This file was deleted.

24 changes: 0 additions & 24 deletions .jshintrc

This file was deleted.

20 changes: 20 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
2016-07-13, Version 1.8.0
=========================

* Expose configured properties on LoopBackResource (Matteo Padovano)

* Describe model schema in generated $resource (Miroslav Bajtos)

* update copyright notices and license (Ryan Graham)

* Clear user data when logout returns error response (Matteo Padovano)

* Lint generated code (David Cheung)

* Use ESlint in replace of jshint (David Cheung)

* added test for LoopBackResourceProvider.getAuthHeader() method. (Martin Juhasz)

* Added getter for AuthHeader value in LoopBackResource (Martin Juhasz)


2016-02-24, Version 1.7.0
=========================

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ Contributing to `loopback-sdk-angular` is easy. In a few simple steps:
inaccurate in any respect. Email us at callback@strongloop.com.
```

[Google C++ Style Guide]: https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
[Google Javascript Style Guide]: https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
[Google C++ Style Guide]: https://google.github.io/styleguide/cppguide.html
[Google Javascript Style Guide]: https://google.github.io/styleguide/javascriptguide.xml
25 changes: 25 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) IBM Corp. 2014,2015. All Rights Reserved.
Node module: loopback-sdk-angular
This project is licensed under the MIT License, full text below.

--------

MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
9 changes: 0 additions & 9 deletions LICENSE.md

This file was deleted.

6 changes: 6 additions & 0 deletions apidocs/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../.eslintrc",
"rules": {
"quotes": ["off"]
}
}
8 changes: 7 additions & 1 deletion apidocs/describe-builtin-models.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Copyright IBM Corp. 2014,2016. All Rights Reserved.
// Node module: loopback-sdk-angular
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

/* eslint quotes: ["error", "single"] */
var fs = require('fs');
var path = require('path');

Expand All @@ -6,7 +12,7 @@ var loopbackCoreJs = path.resolve(__dirname, 'loopback-core.js');
try {
var generator = require('..');
var loopback = require('loopback');
} catch(err) {
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND' && fs.existsSync(loopbackCoreJs)) {
console.log('Cannot load the generator, node_modules were not installed.');
console.log('Ignoring the error since the output file is already there.');
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// Copyright IBM Corp. 2014,2015. All Rights Reserved.
// Node module: loopback-sdk-angular
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

exports.services = require('./lib/services');
11 changes: 8 additions & 3 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright IBM Corp. 2014,2016. All Rights Reserved.
// Node module: loopback-sdk-angular
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

// Karma configuration
// Generated on Fri Jan 17 2014 19:17:51 GMT+0100 (CET)

Expand All @@ -20,7 +25,7 @@ module.exports = function(config) {
{ pattern: 'test.e2e/**/*.js', included: false },

// Include lib/ files to let Karma watch for changes there
{ pattern: 'lib/**/*.js', included: false }
{ pattern: 'lib/**/*.js', included: false },
],

// list of files to exclude
Expand All @@ -35,7 +40,7 @@ module.exports = function(config) {

// CI friendly test output
junitReporter: {
outputFile: 'karma-xunit.xml'
outputFile: 'karma-xunit.xml',
},


Expand Down Expand Up @@ -73,6 +78,6 @@ module.exports = function(config) {

// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
singleRun: false,
});
};
102 changes: 78 additions & 24 deletions lib/services.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// Copyright IBM Corp. 2014,2016. All Rights Reserved.
// Node module: loopback-sdk-angular
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

var fs = require('fs');
var ejs = require('ejs');
var extend = require('util')._extend;

ejs.filters.q = function(obj) {
return JSON.stringify(obj, null, 2 );
return JSON.stringify(obj, null, 2);
};

/**
Expand All @@ -12,37 +18,59 @@ ejs.filters.q = function(obj) {
* var generateServices = require('loopback-sdk-angular').services;
* var app = require('./server/server');
*
* var client = generateServices(app, 'lbServices', '/api');
* var client = generateServices(app, {
* ngModuleName: 'lbServices',
* apiUrl: '/api'
* });
* require('fs').writeFileSync('client/loopback.js', client, 'utf-8');
* ```
*
* To preserve backwards compatibility, the three-arg variant is still
* supported:
*
* ```js
* var client = generateServices(app, 'lbServices', '/api');
* ```
*
* @param {Object} app The loopback application created via `app = loopback()`.
* @options {Object} options
* @param {string=} ngModuleName A name for the generated Angular module.
* Default: `lbServices`.
* @param {string=} apiUrl The URL where the client can access the LoopBack
* server app. Default: `/`.
* @param {Boolean} includeSchema Include model definition.
* @returns {string} The generated javascript code.
* @header generateServices
*/
module.exports = function generateServices(app, ngModuleName, apiUrl) {
ngModuleName = ngModuleName || 'lbServices';
apiUrl = apiUrl || '/';
module.exports = function generateServices(app, options) {
if (typeof options === 'string') {
// legacy API: generateServices(app, ngModuleName, apiUrl)
options = {
ngModuleName: arguments[1],
apiUrl: arguments[2],
};
}

var models = describeModels(app);
options = extend({
ngModuleName: 'lbServices',
apiUrl: '/',
}, options);

var models = describeModels(app, options);

var servicesTemplate = fs.readFileSync(
require.resolve('./services.template.ejs'),
{ encoding: 'utf-8' }
);

return ejs.render(servicesTemplate, {
moduleName: ngModuleName,
moduleName: options.ngModuleName,
models: models,
urlBase: apiUrl.replace(/\/+$/, '')
urlBase: options.apiUrl.replace(/\/+$/, ''),
});
};

function describeModels(app) {
function describeModels(app, options) {
var result = {};
app.handler('rest').adapter.getClasses().forEach(function(c) {
var name = c.name;
Expand All @@ -60,25 +88,25 @@ function describeModels(app) {
// the sharedCtor parameters should be added to the parameters
// of prototype methods.
c.methods.forEach(function fixArgsOfPrototypeMethods(method, key) {
if (method.name=='create') {
if (method.name == 'create') {
var createMany = Object.create(method);
createMany.name = 'createMany';
createMany.isReturningArray = function() { return true; };
c.methods.splice(key+1, 0, createMany);
createMany.name = 'createMany';
createMany.isReturningArray = function() { return true; };
c.methods.splice(key + 1, 0, createMany);
}
var ctor = method.restClass.ctor;
if (!ctor || method.sharedMethod.isStatic) return;
method.accepts = ctor.accepts.concat(method.accepts);

if(!method.accepts) return;
if (!method.accepts) return;

// Any extra http action arguments in the path need to be added to the
// angular resource actions as params
method.accepts.forEach(function findResourceParams(arg) {
if(!arg.http) return;
if (!arg.http) return;

if(arg.http.source === 'path' && arg.arg !== 'id') {
if(!method.resourceParams) {
if (arg.http.source === 'path' && arg.arg !== 'id') {
if (!method.resourceParams) {
method.resourceParams = [];
method.hasResourceParams = true;
}
Expand All @@ -94,6 +122,10 @@ function describeModels(app) {

buildScopes(result);

if (options.includeSchema) {
buildSchemas(result, app);
}

return result;
}

Expand Down Expand Up @@ -152,7 +184,7 @@ function buildScopeMethod(models, modelName, method) {

modelClass.scopes[scopeName] = {
methods: {},
targetClass: targetClass
targetClass: targetClass,
};
} else if (modelClass.scopes[scopeName] === null) {
// Skip the scope, the warning was already reported
Expand Down Expand Up @@ -184,18 +216,18 @@ function buildScopeMethod(models, modelName, method) {

var reverseModel = findModelByName(models, targetClass);
reverseModel.methods.push(reverseMethod);
if(reverseMethod.name.match(/create/)){
if (reverseMethod.name.match(/create/)) {
var createMany = Object.create(reverseMethod);
createMany.name = createMany.name.replace(
createMany.name = createMany.name.replace(
/create/,
'createMany'
);
createMany.internal = createMany.internal.replace(
createMany.internal = createMany.internal.replace(
/create/,
'createMany'
);
createMany.isReturningArray = function() { return true; };
reverseModel.methods.push(createMany);
createMany.isReturningArray = function() { return true; };
reverseModel.methods.push(createMany);
}

var scopeMethod = Object.create(method);
Expand All @@ -204,7 +236,7 @@ function buildScopeMethod(models, modelName, method) {
scopeMethod.deprecated = false;
scopeMethod.internal = false;
modelClass.scopes[scopeName].methods[apiName] = scopeMethod;
if(scopeMethod.name.match(/create/)){
if (scopeMethod.name.match(/create/)) {
var scopeCreateMany = Object.create(scopeMethod);
scopeCreateMany.name = scopeCreateMany.name.replace(
/create/,
Expand All @@ -222,3 +254,25 @@ function findModelByName(models, name) {
return models[n];
}
}

function buildSchemas(models, app) {
for (var modelName in models) {
var modelProperties = app.models[modelName].definition.properties;
var schema = {};
for (var prop in modelProperties) { // eslint-disable-line one-var
schema[prop] = extend({}, modelProperties[prop]);
// normalize types - convert from ctor (function) to name (string)
var type = schema[prop].type;
if (typeof type === 'function') {
type = type.modelName || type.name;
}
// TODO - handle array types
schema[prop].type = type;
}

models[modelName].modelSchema = {
name: modelName,
properties: schema,
};
}
}
Loading