Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
EdMoffatt authored Mar 7, 2017
2 parents a31156a + 6560fb2 commit a3194e7
Show file tree
Hide file tree
Showing 142 changed files with 1,540 additions and 3,103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ class LoopbackVisitor {
description: `An asset named ${assetDeclaration.getName()}`,
plural: assetDeclaration.getFullyQualifiedName(),
base: 'PersistedModel',
idInjection: true,
idInjection: false,
options: {
validateUpsert: true
validateUpsert: true,
composer: {
type: 'asset'
}
},
properties: {},
validations: [],
Expand Down Expand Up @@ -179,9 +182,12 @@ class LoopbackVisitor {
description: `A participant named ${participantDeclaration.getName()}`,
plural: participantDeclaration.getFullyQualifiedName(),
base: 'PersistedModel',
idInjection: true,
idInjection: false,
options: {
validateUpsert: true
validateUpsert: true,
composer: {
type: 'participant'
}
},
properties: {},
validations: [],
Expand Down Expand Up @@ -236,9 +242,12 @@ class LoopbackVisitor {
description: `A transaction named ${transactionDeclaration.getName()}`,
plural: transactionDeclaration.getFullyQualifiedName(),
base: 'PersistedModel',
idInjection: true,
idInjection: false,
options: {
validateUpsert: true
validateUpsert: true,
composer: {
type: 'transaction'
}
},
properties: {},
validations: [],
Expand Down Expand Up @@ -267,6 +276,13 @@ class LoopbackVisitor {
visitClassDeclarationCommon(classDeclaration, parameters, jsonSchema) {
debug('entering visitClassDeclarationCommon', classDeclaration.getName());

// Add information from the class declaration into the composer section.
if (jsonSchema.options && jsonSchema.options.composer) {
jsonSchema.options.composer.namespace = classDeclaration.getModelFile().getNamespace();
jsonSchema.options.composer.name = classDeclaration.getName();
jsonSchema.options.composer.fqn = classDeclaration.getFullyQualifiedName();
}

// Set the required properties into the schema.
Object.assign(jsonSchema, {
properties: {}
Expand Down
2 changes: 1 addition & 1 deletion packages/composer-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"docpub": "jsdoc --pedantic --recurse -c jsdoc.conf -t ./node_modules/ink-docstrap/template -a public,undefined -d ./out/public .",
"docpriv": "jsdoc --pedantic --recurse -c jsdoc.conf -t ./node_modules/ink-docstrap/template -a all -d ./out/private .",
"postdoc": "npm run browserify",
"browserify": "browserify ./index.js -t [ babelify --presets [ es2015 ] ] > ./out/concerto-common.js",
"browserify": "browserify ./index.js -t [ babelify --presets [ es2015 ] ] > ./out/composer-common.js",
"test": "./scripts/api-changelog.sh && mocha --recursive && istanbul cover --include-all-sources --report cobertura --report html ./node_modules/mocha/bin/_mocha -- --recursive",
"posttest": "istanbul check-coverage",
"systest": "mocha -t 0 systest && cucumber-js systest"
Expand Down
170 changes: 168 additions & 2 deletions packages/composer-common/test/codegen/loopbackvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
const FileWriter = require('../../lib/codegen/filewriter');
const fs = require('fs');
const LoopbackVisitor = require('../../lib/codegen/fromcto/loopback/loopbackvisitor');
const ModelFile = require('../../lib/introspect/modelfile');
const ModelManager = require('../../lib/modelmanager');
const path = require('path');

Expand Down Expand Up @@ -58,10 +59,10 @@ describe('LoopbackVisitor', () => {

});

it('should generate Loopback model files for each type in the Concerto model', () => {
it('should generate Loopback model files for each type when given a model manager', () => {

// Visit all of the loaded model files.
modelManager.accept(visitor, { fileWriter: mockFileWriter });
const schemas = modelManager.accept(visitor, { fileWriter: mockFileWriter });

// Check that the Loopback model files were generated, and extract the
// generated schemas from the stub writer.
Expand All @@ -76,6 +77,7 @@ describe('LoopbackVisitor', () => {
'org.acme.base.Person.json',
'org.acme.base.Bloke.json'
];
schemas.should.have.lengthOf(expectedFiles.length);
sinon.assert.callCount(mockFileWriter.openFile, expectedFiles.length);

expectedFiles.forEach((expectedFile) => {
Expand All @@ -84,6 +86,170 @@ describe('LoopbackVisitor', () => {

});

it('should generate Loopback model files for each type when given a model file', () => {

// Visit all of the loaded model files.
const modelFile = modelManager.getModelFile('org.acme.base');
const schemas = modelFile.accept(visitor, { fileWriter: mockFileWriter });

// Check that the Loopback model files were generated, and extract the
// generated schemas from the stub writer.
const expectedFiles = [
'org.acme.base.SimpleAsset.json',
'org.acme.base.BaseAsset.json',
'org.acme.base.DerivedAsset.json',
'org.acme.base.DerivedDerivedAsset.json',
'org.acme.base.MyBasicTransaction.json',
'org.acme.base.MyTransaction.json',
'org.acme.base.MyTransactionEx.json',
'org.acme.base.Person.json',
'org.acme.base.Bloke.json'
];
schemas.should.have.lengthOf(expectedFiles.length);
sinon.assert.callCount(mockFileWriter.openFile, expectedFiles.length);

expectedFiles.forEach((expectedFile) => {
sinon.assert.calledWith(mockFileWriter.openFile, expectedFile);
});

});

it('should generate a schema for an asset with just an identifier', () => {
const modelFile = new ModelFile(modelManager, `
namespace org.acme
asset MyAsset identified by assetId {
o String assetId
}
`);
const schemas = modelFile.accept(visitor, { fileWriter: mockFileWriter });
schemas.should.deep.equal([{
acls: [],
base: 'PersistedModel',
description: 'An asset named MyAsset',
idInjection: false,
methods: [],
name: 'MyAsset',
options: {
composer: {
type: 'asset',
namespace: 'org.acme',
name: 'MyAsset',
fqn: 'org.acme.MyAsset'
},
validateUpsert: true
},
plural: 'org.acme.MyAsset',
properties: {
$class: {
default: 'org.acme.MyAsset',
description: 'The class identifier for this type',
required: false,
type: 'string'
},
assetId: {
description: 'The instance identifier for this type',
id: true,
required: true,
type: 'string'
}
},
relations: {},
validations: []
}]);
});

it('should generate a schema for a participant with just an identifier', () => {
const modelFile = new ModelFile(modelManager, `
namespace org.acme
participant MyParticipant identified by participantId {
o String participantId
}
`);
const schemas = modelFile.accept(visitor, { fileWriter: mockFileWriter });
schemas.should.deep.equal([{
acls: [],
base: 'PersistedModel',
description: 'A participant named MyParticipant',
idInjection: false,
methods: [],
name: 'MyParticipant',
options: {
composer: {
type: 'participant',
namespace: 'org.acme',
name: 'MyParticipant',
fqn: 'org.acme.MyParticipant'
},
validateUpsert: true
},
plural: 'org.acme.MyParticipant',
properties: {
$class: {
default: 'org.acme.MyParticipant',
description: 'The class identifier for this type',
required: false,
type: 'string'
},
participantId: {
description: 'The instance identifier for this type',
id: true,
required: true,
type: 'string'
}
},
relations: {},
validations: []
}]);
});

it('should generate a schema for a transaction with just an identifier', () => {
const modelFile = new ModelFile(modelManager, `
namespace org.acme
transaction MyTransaction identified by transactionId {
o String transactionId
}
`);
const schemas = modelFile.accept(visitor, { fileWriter: mockFileWriter });
schemas.should.deep.equal([{
acls: [],
base: 'PersistedModel',
description: 'A transaction named MyTransaction',
idInjection: false,
methods: [],
name: 'MyTransaction',
options: {
composer: {
type: 'transaction',
namespace: 'org.acme',
name: 'MyTransaction',
fqn: 'org.acme.MyTransaction'
},
validateUpsert: true
},
plural: 'org.acme.MyTransaction',
properties: {
$class: {
default: 'org.acme.MyTransaction',
description: 'The class identifier for this type',
required: false,
type: 'string'
},
timestamp: {
required: true,
type: 'date'
},
transactionId: {
description: 'The instance identifier for this type',
id: true,
required: true,
type: 'string'
}
},
relations: {},
validations: []
}]);
});

});

});
7 changes: 7 additions & 0 deletions packages/composer-playground/config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ module.exports = function(config) {
'Chrome'
],

client : {
captureConsole : true
},
browserConsoleLogOptions: {
level: 'log'
},

customLaunchers: {
ChromeTravisCi: {
base: 'Chrome',
Expand Down
1 change: 1 addition & 0 deletions packages/composer-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"express": "^4.14.0",
"file-saver": "^1.3.3",
"is-docker": "^1.1.0",
"marked": "^0.3.6",
"octokat": "^0.6.2",
"opener": "^1.4.2",
"socket.io": "^1.7.2"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<div class="about">
<h2>About</h2>
<p>
{{playground.name}}: v{{playground.version}} <br>
{{common.name}}: v{{common.version}} <br>
{{client.name}}: v{{client.version}} <br>
{{admin.name}}: v{{admin.version}}
</p>
</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import '../../assets/styles/base/_colors.scss';
@import '../../assets/styles/base/_variables.scss';

.about {
about {
padding: 15px;
flex: 1 1 auto;
p {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ describe('AboutComponent', () => {
providers: [{ provide: AboutService, useClass: MockAboutService }]
});

fixture = TestBed.createComponent(AboutComponent);
fixture = TestBed.createComponent(AboutComponent);

// query for the title <h2> by CSS element selector
de = fixture.debugElement.query(By.css('h2'));
el = de.nativeElement;
// query for the title <h2> by CSS element selector
de = fixture.debugElement.query(By.css('h2'));
el = de.nativeElement;
});

it ('Should display the correct title for the AboutComponent', () => {
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
<div bsModal #modal="bs-modal" class="modal fade" tabindex="-1" (onShow)="onShow();" (onHidden)="onHidden();">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" (click)="modal.hide();">
<span>&times;</span>
</button>
<h4 class="modal-title">Add identity</h4>
</div>
<div class="modal-body">
<label for="userID">User ID</label>
<input class="form-control w-100" type="text" [(ngModel)]="userID" id="userID" autocomplete="off">
<label for="userSecret" class="mt-2">User secret</label>
<input class="form-control w-100" type="password" [(ngModel)]="userSecret" id="userSecret" autocomplete="off">
<button type="button" class="btn btn-primary mt-2" (click)="add(); modal.hide();" [disabled]="!userID || !userSecret">
<span>Add</span>
</button>
<button type="button" class="btn btn-primary mt-2" (click)="modal.hide();">
<span>Cancel</span>
</button>
</div>
</div>
<div class="add-identity">
<div class="modal-header">
<button type="button" class="close" (click)="modal.hide();">
<span>&times;</span>
</button>
<h4 class="modal-title">Add identity</h4>
</div>
<div class="modal-body">
<label for="userID">User ID</label>
<input type="text" [(ngModel)]="userID" id="userID" autocomplete="off">
<label for="userSecret">User secret</label>
<input type="password" [(ngModel)]="userSecret" id="userSecret" autocomplete="off">
</div>
<footer>
<button type="button" class="secondary" (click)="activeModal.dismiss();">
<span>Cancel</span>
</button>
<button type="button" (click)="add()" [disabled]="!userID || !userSecret">
<span>Add</span>
<div *ngIf="addInProgress" class="ibm-spinner-indeterminate small loop">
<div class="loader">
<svg class="circular" viewBox="25 25 50 50">
<circle class="circle-path" cx="50" cy="50" r="20"/>
</svg>
</div>
</div>
</button>
</footer>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@import '../../assets/styles/base/_colors.scss';
@import '../../assets/styles/base/_variables.scss';

add-identity-modal {
.add-identity {
footer {
.circle-path {
stroke: $white;
}

width: 100%;
}
}
}
Loading

0 comments on commit a3194e7

Please sign in to comment.