Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakeeyturner authored Mar 9, 2017
2 parents c3f128b + f5eab81 commit af7b1d4
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 70 deletions.
11 changes: 10 additions & 1 deletion packages/composer-cli/lib/cmds/network/lib/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,19 @@ class List {
return businessNetworkConnection.disconnect();
})
.catch(error => {
console.log(error);
console.log(List.getError(error));
});
}

/**
* Get message from an error object if one is given
* @param {Error|String} error Error to be examined
* @return {String} error message
*/
static getError(error) {
return error.message ? error.message : error;
}

/**
* Get default profile name
* @param {argv} argv program arguments
Expand Down
8 changes: 8 additions & 0 deletions packages/composer-common/lib/introspect/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ class Script {
return this.identifier;
}

/**
* Returns the identifier of the script
* @return {string} the identifier of the script
*/
getName() {
return this.identifier;
}

/**
* Returns the language of the script
* @return {string} the identifier of the script
Expand Down
12 changes: 5 additions & 7 deletions packages/composer-playground/src/app/about/about.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<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>
<h2>About</h2>
<p>
{{playground.name}}: v{{playground.version}} <br>
</p>

23 changes: 4 additions & 19 deletions packages/composer-playground/src/app/about/about.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,10 @@ import { AboutComponent } from './about.component';
import { AboutService } from '../services/about.service';

const MOCK_RETURN = {
'playground': {
name: 'playground',
version: '1'
},
'common': {
name: 'composer-common',
version: '2'
},
'client': {
name: 'composer-client',
version: '3'
},
'admin': {
name: 'composer-admin',
version: '4'
}
'playground': {
name: 'playground',
version: '1'
}
};

class MockAboutService {
Expand Down Expand Up @@ -62,8 +50,5 @@ describe('AboutComponent', () => {
tick();
fixture.detectChanges();
expect(fixture.componentInstance.playground).toBe(MOCK_RETURN.playground);
expect(fixture.componentInstance.common).toBe(MOCK_RETURN.common);
expect(fixture.componentInstance.client).toBe(MOCK_RETURN.client);
expect(fixture.componentInstance.admin).toBe(MOCK_RETURN.admin);
}));
});
12 changes: 3 additions & 9 deletions packages/composer-playground/src/app/about/about.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@ import { AboutService } from '../services/about.service';
@Component({
selector: 'about',
templateUrl: './about.component.html',
styleUrls: ['./about.component.scss'.toString()]
styleUrls: ['./about.component.scss'.toString()],
exportAs: 'child'
})

export class AboutComponent implements OnInit {

common;
admin;
client;
playground = this.common = this.client = this.admin = {name: '', version: ''};
playground = {name: '', version: ''};

constructor(private aboutService: AboutService) {}

ngOnInit() {
return this.aboutService.getVersions()
.then((modules) => {
this.playground = modules.playground;
this.common = modules.common;
this.client = modules.client;
this.admin = modules.admin;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,33 @@ <h1>Add a file</h1>
</div>
<section class="modal-body">
<span>Upload a file from your computer...</span>
<file-importer *ngIf="!currentFile || newFile" (dragFileAccepted)="fileAccepted($event)" [expandInput]="expandInput"
<file-importer *ngIf="!expandInput" (dragFileAccepted)="fileAccepted($event)" [expandInput]="expandInput"
[ngClass]="{'expandFile': expandInput}" [svgName]="'#icon-CTO_JS_Upload'"></file-importer>

<div class="chosen-file" *ngIf="expandInput && currentFile">
<div class="file-info">
<div class="flex-container">
<svg class="ibm-icon" aria-hidden="true">
<use xlink:href="#icon-JS_File" *ngIf="fileType === 'js'"></use>
<use xlink:href="#icon-CTO_File" *ngIf="fileType === 'cto'"></use>
<div class="file-info">
<div class="flex-container">
<svg class="ibm-icon" aria-hidden="true">
<use xlink:href="#icon-JS_File" *ngIf="fileType==='js'"></use>
<use xlink:href="#icon-CTO_File" *ngIf="fileType==='cto'"></use>
</svg>
<div class="file-title">
<div class="title">{{currentFileName}}</div>
<div *ngIf="fileType==='cto'">
<span>{{currentFile.getAssetDeclarations().length}} Assets</span>
<span>{{currentFile.getParticipantDeclarations().length}} Participants</span>
<span>{{currentFile.getTransactionDeclarations().length}} Transactions</span>
</div>
<div *ngIf="fileType==='js'">
<span>{{currentFile.getFunctionDeclarations().length}} Functions</span>
</div>
</div>
</div>
</div>
</div>
<div>
<button role="button" type="button" class="action" (click)="removeFile()">Remove File</button>
</div>
</div>
</div>
<form class="file-types-list" #f="ngForm" *ngIf="((!fileType && !currentFile) || (fileType && currentFile)) && !expandInput">
<form class="file-types-list" #f="ngForm" *ngIf="!expandInput">
<div class="file-types-list-item">
<input type="radio" id="file-type-cto" name="file-type" [(ngModel)]="fileType" value="cto"(change)="changeCurrentFileType()">
<label class="radio-label" for="file-type-cto">Model File (.cto)</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
@import '../../assets/styles/base/_variables.scss';

.import {
width: 660px;
height: 450px;

display: flex;
flex-direction: column;

.file-types-list {
max-height: 200px;
Expand Down Expand Up @@ -32,4 +37,84 @@
}
}
}

section {
font-size: 0.9em;

file-importer {
margin-top: $space-medium;
}

span {
color: $secondary-text;
}

.chosen-file {
flex: 1;
display: flex;
flex-direction: column;
background-color: $third-highlight;
padding: $space-medium;

.title {
font-weight: bold;
}

.file-info {
display: flex;
justify-content: space-between;
border-bottom: 1px solid $fifth-highlight;
padding-bottom: $space-medium;
align-items: center;

svg {
fill: $first-highlight;
width: 76px;
height: 76px;
margin-right: $space-medium;
}

.file-title {
display: flex;
flex-direction: column;
justify-content: center;

span {
color: $primary-text;
font-style: italic;
}
}
}

.file-content {
margin-top: $space-medium;
flex: 1;
display: flex;
justify-content: space-between;

.network-part {
margin-bottom: $space-smedium;
}
}
}

.github-spinner {
height: 200px;
width: 465px;
display: flex;
align-items: center;
justify-content: center;

.circle-path {
stroke: $first-highlight;
}
}

form {
max-height: 200px;
overflow-y: auto;
margin-top: $space-medium;
}
}
}

28 changes: 14 additions & 14 deletions packages/composer-playground/src/app/add-file/add-file.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AlertService } from '../services/alert.service';
templateUrl: './add-file.component.html',
styleUrls: ['./add-file.component.scss'.toString()]
})
export class AddFileComponent implements OnInit {b
export class AddFileComponent implements OnInit {

@Input() businessNetwork: BusinessNetworkDefinition;

Expand All @@ -31,12 +31,17 @@ export class AddFileComponent implements OnInit {b

constructor(private alertService: AlertService,
public activeModal: NgbActiveModal) {

}

ngOnInit() {
}

removeFile() {
this.expandInput = false;
this.currentFile = null;
this.currentFileName = null;
this.fileType = '';
}

fileDetected() {
this.expandInput = true;
}
Expand All @@ -46,7 +51,6 @@ export class AddFileComponent implements OnInit {b
}

fileAccepted(file: File): Promise<any> {
this.newFile = false;
let type = file.name.substr(file.name.lastIndexOf('.') + 1);
return this.getDataBuffer(file)
.then((data) => {
Expand Down Expand Up @@ -83,18 +87,16 @@ export class AddFileComponent implements OnInit {b
}

createScript(file: File, dataBuffer) {
this.newFile = true;
this.fileType = 'js';
let scriptManager = this.businessNetwork.getScriptManager();
this.currentFile = scriptManager.createScript(file.name, 'JS', dataBuffer.toString());
this.currentFile = scriptManager.createScript(file.name || this.addScriptFileName, 'JS', dataBuffer.toString());
this.currentFileName = this.currentFile.getIdentifier();
}

createModel(file: File, dataBuffer) {
this.newFile = true;
this.fileType = 'cto';
let modelManager = this.businessNetwork.getScriptManager();
this.currentFile = new ModelFile(modelManager, dataBuffer.toString(), file.name);
this.currentFile = new ModelFile(modelManager, dataBuffer.toString(), file.name || this.addModelFileName);
this.currentFileName = this.currentFile.getFileName();
}

Expand All @@ -103,20 +105,17 @@ export class AddFileComponent implements OnInit {b
this.alertService.errorStatus$.next(reason);
}

removeFile() {
this.expandInput = false;
this.currentFile = null;
}

changeCurrentFileType() {
changeCurrentFileType() {
this.newFile = true;
this.currentFile = null;
if (this.fileType === 'js') {
let code =
`/**
* New script file
*/`;
let scriptManager = this.businessNetwork.getScriptManager();
this.currentFile = scriptManager.createScript(this.addScriptFileName, 'JS', code);
this.currentFileName = this.currentFile.getIdentifier();
} else {
let code =
`/**
Expand All @@ -126,6 +125,7 @@ export class AddFileComponent implements OnInit {b
namespace ${this.addModelNamespace}`;
let modelManager = this.businessNetwork.getModelManager();
this.currentFile = new ModelFile(modelManager, code, this.addModelFileName);
this.currentFileName = this.currentFile.getFileName();
}
}
}
20 changes: 10 additions & 10 deletions packages/composer-rest-server/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ process.env.SUPPRESS_NO_CONFIG_WARNING = true;

const yargs = require('yargs')
.wrap(null)
.usage('Usage: $0 -p connection profile -b business network identifier -u participant id -s participant password')
.option('c', { alias: 'connectionProfile', describe: 'connection profile Name', type: 'string', default: process.env.COMPOSER_CONNECTION_PROFILE })
.option('b', { alias: 'businessNetwork', describe: 'business network identifier', type: 'string', default: process.env.COMPOSER_BUSINESS_NETWORK })
.option('i', { alias: 'participantId', describe: 'participant id', type: 'string', default: process.env.COMPOSER_ENROLLMENT_ID })
.option('p', { alias: 'participantPwd', describe: 'participant password', type: 'string', default: process.env.COMPOSER_ENROLLMENT_SECRET })
.usage('Usage: $0 [options]')
.option('n', { alias: 'businessNetworkName', describe: 'The business network identifier', type: 'string', default: process.env.COMPOSER_BUSINESS_NETWORK })
.option('p', { alias: 'connectionProfileName', describe: 'The connection profile name', type: 'string', default: process.env.COMPOSER_CONNECTION_PROFILE })
.option('i', { alias: 'enrollId', describe: 'The enrollment ID of the user', type: 'string', default: process.env.COMPOSER_ENROLLMENT_ID })
.option('s', { alias: 'enrollSecret', describe: 'The enrollment secret of the user', type: 'string', default: process.env.COMPOSER_ENROLLMENT_SECRET })
.help('h')
.alias('h', 'help')
.argv;

// see if we need to run interactively
let promise;
if (yargs.c === undefined && yargs.b === undefined && yargs.i === undefined && yargs.p === undefined) {
if (yargs.p === undefined && yargs.n === undefined && yargs.i === undefined && yargs.s === undefined) {
// Gather some args interactively
clear();
console.log(
Expand All @@ -60,15 +60,15 @@ if (yargs.c === undefined && yargs.b === undefined && yargs.i === undefined && y

} else {
// make sure we have args for all required parms otherwise error
if (yargs.c === undefined || yargs.b === undefined || yargs.i === undefined || yargs.p === undefined) {
if (yargs.p === undefined || yargs.n === undefined || yargs.i === undefined || yargs.s === undefined) {
console.log('Error: Missing parameter. Please run compposer-rest-server -h to see usage details');
process.exit(1);
} else {
promise = Promise.resolve({
connectionProfileName: yargs.c,
businessNetworkIdentifier: yargs.b,
connectionProfileName: yargs.p,
businessNetworkIdentifier: yargs.n,
participantId: yargs.i,
participantPwd: yargs.p
participantPwd: yargs.s
});
}
}
Expand Down

0 comments on commit af7b1d4

Please sign in to comment.