Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
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
18 changes: 18 additions & 0 deletions packages/composer-common/lib/businessnetworkdefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,24 @@ class BusinessNetworkDefinition {
return this.queryManager;
}

/**
* Set the readme file within the BusinessNetworkMetadata
* @param {String} readme the readme in markdown for the business network
* @private
*/
setReadme(readme) {
this.metadata = new BusinessNetworkMetadata(this.metadata.getPackageJson(), readme);
}

/**
* Set the packageJson within the BusinessNetworkMetadata
* @param {object} packageJson the JS object for package.json
* @private
*/
setPackageJson(packageJson) {
this.metadata = new BusinessNetworkMetadata(packageJson, this.metadata.getREADME());
}

}

module.exports = BusinessNetworkDefinition;
19 changes: 18 additions & 1 deletion packages/composer-common/test/businessnetworkdefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,26 @@ describe('BusinessNetworkDefinition', () => {
});
});

describe('#archives', () => {
describe('#setters', () => {

it('should be able set a Readme', () => {
let newReadme = 'Read the readme';
businessNetworkDefinition.setReadme(newReadme);
businessNetworkDefinition.getMetadata().getREADME().should.equal(newReadme);
});

it('should be able set packageJson', () => {
let packageJson = {};
packageJson.name = businessNetworkDefinition.getName();
packageJson.version = businessNetworkDefinition.getVersion();
packageJson.description = 'new description';
businessNetworkDefinition.setPackageJson(packageJson);

businessNetworkDefinition.getMetadata().getPackageJson().should.deep.equal(packageJson);
});
});

describe('#archives', () => {

it('should be able to correctly create a business network from a plain directory', () => {

Expand Down
83 changes: 51 additions & 32 deletions packages/composer-playground/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,59 @@
<nav class="indexnav">
<div class="navcontent">
<div class="navlogo">
<p><b>Hyperledger</b> Composer Playground</p>
<p><b>{{ composerBanner[0] }}</b> {{ composerBanner[1] }}</p>
<div class="tooltiptext">{{ composerBanner[0] }} {{ composerBanner[1] }}</div>
</div>
<div *ngIf="showHeaderLinks" class="flex-container flex">
<ul class="links navleft">
<li>
<button id='app_definebutton' class="action" [routerLink]="['editor']" [routerLinkActive]="['active']">Define</button>
</li>
<li>
<button id='app_testbutton' class="action" [routerLink]="['test']" [routerLinkActive]="['active']">Test</button>
</li>
</ul>
<ul class="links navright">
<li class="withseparator">
<button class="action" [routerLink]="['identity']" [routerLinkActive]="['active']">
<span class="currentid" title="{{ identityService.currentIdentity | async }}">{{ identityService.currentIdentity | async }}</span>
</button>
</li>
<li *ngIf="!usingLocally">
<a href="https://hyperledger.github.io/composer/installing/using-playground-locally.html"
target="_blank">
<svg class="nav-icon" aria-hidden="true">
<use xlink:href="#icon-simple_docker"></use>
</svg>
<span>Get local version</span>
</a>
</li>
<li *ngIf="usingLocally">
<button class="action" [routerLink]="['profile']" [routerLinkActive]="['active']">
<svg class="nav-icon" aria-hidden="true">
<use xlink:href="#icon-world_24"></use>
</svg>
</button>
</li>
</ul>
<ul class="links navleft">
<li>
<button class="action" [routerLink]="['editor']" [routerLinkActive]="['active']">Define</button>
</li>
<li>
<button class="action" [routerLink]="['test']" [routerLinkActive]="['active']">Test</button>
</li>
</ul>
<ul class="links navright" *ngIf="!usingLocally">
<li class="withseparator">
<button class="action" [routerLink]="['identity']" [routerLinkActive]="['active']">
<span class="currentid" title="{{ identityService.currentIdentity | async }}">{{ identityService.currentIdentity | async }}</span>
</button>
</li>
<li>
<a href="https://hyperledger.github.io/composer/installing/using-playground-locally.html"
target="_blank">
<svg class="nav-icon" aria-hidden="true">
<use xlink:href="#icon-simple_docker"></use>
</svg>
<span>Get local version</span>
</a>
</li>
</ul>
<div class="drop-select" *ngIf="usingLocally">
<div class="drop-select-item flex-container flex">
<div ngbDropdown class="d-inline-block">
<button type="button" class="action" id="dropdownMenu1" ngbDropdownToggle>
<span title="{{ identityService.currentIdentity | async }}">{{ identityService.currentIdentity | async }}</span>
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu1">
<button id="content" class="dropdown-item action" [routerLink]="['identity']" *ngFor="let profile of connectionProfiles">
<div class="flex-container flex" style="justify-content:space-between">
<div style="margin-right:10px">ID Repository</div>
<div style="flex:1; color:#8c9696; font-style: italic">{{ profile.name }}</div>
</div>
</button>
<button id="footer" class="dropdown-item action" (click)="logout()">
<div class="flex-container flex" style="justify-content:center">
<div style="margin-right:20px"><svg class="ibm-icon" aria-hidden="true">
<use xlink:href="#icon-chevron-left"></use>
</svg></div>
<div>Log Out</div>
</div>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</nav>
Expand Down
35 changes: 14 additions & 21 deletions packages/composer-playground/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ describe('AppComponent', () => {
it('should check version and open version modal', fakeAsync(() => {
let checkVersionStub = sinon.stub(component, 'checkVersion').returns(Promise.resolve(false));
let openVersionModalStub = sinon.stub(component, 'openVersionModal');
mockClientService.ensureConnected.returns(Promise.resolve());
mockClientService.getBusinessNetworkName.returns('bob');
mockConnectionProfileService.getCurrentConnectionProfile.returns('$default');

routerStub.eventParams = {url: '/bob', nav: 'end'};

Expand All @@ -314,6 +317,9 @@ describe('AppComponent', () => {
it('should check version and not open version modal', fakeAsync(() => {
let checkVersionStub = sinon.stub(component, 'checkVersion').returns(Promise.resolve(true));
let openVersionModalStub = sinon.stub(component, 'openVersionModal');
mockClientService.ensureConnected.returns(Promise.resolve());
mockClientService.getBusinessNetworkName.returns('bob');
mockConnectionProfileService.getCurrentConnectionProfile.returns('$default');

routerStub.eventParams = {url: '/bob', nav: 'end'};

Expand Down Expand Up @@ -343,6 +349,9 @@ describe('AppComponent', () => {
it('should show header links if logged in', fakeAsync(() => {
let checkVersionStub = sinon.stub(component, 'checkVersion').returns(Promise.resolve(true));
routerStub.eventParams = {url: '/editor', nav: 'end'};
mockClientService.ensureConnected.returns(Promise.resolve());
mockClientService.getBusinessNetworkName.returns('bob');
mockConnectionProfileService.getCurrentConnectionProfile.returns('$default');

updateComponent();

Expand Down Expand Up @@ -412,14 +421,14 @@ describe('AppComponent', () => {

component['usingLocally'] = true;
component['showHeaderLinks'] = true;
component['connectionProfiles'] = [{name: 'test_name'}];

updateComponent();

links.length.should.equal(4);
links.length.should.equal(3);
links[0].linkParams.should.deep.equal(['editor']);
links[1].linkParams.should.deep.equal(['test']);
links[2].linkParams.should.deep.equal(['identity']);
links[3].linkParams.should.deep.equal(['profile']);
});

it('should not show links when not logged in', () => {
Expand Down Expand Up @@ -474,23 +483,6 @@ describe('AppComponent', () => {

testLink.navigatedTo.should.deep.equal(['identity']);
});

it('can click profile link in template', () => {
component['showHeaderLinks'] = true;
component['usingLocally'] = true;

updateComponent();

const testLinkDe = linkDes[3];
const testLink = links[3];

should.not.exist(testLink.navigatedTo);

testLinkDe.triggerEventHandler('click', null);
fixture.detectChanges();

testLink.navigatedTo.should.deep.equal(['profile']);
});
});

describe('queryParamsUpdated', () => {
Expand All @@ -511,6 +503,7 @@ describe('AppComponent', () => {
it('should load the connection profiles when local and logged in', fakeAsync(() => {

component['showHeaderLinks'] = true;
component['connectionProfiles'] = [{name: 'test_name'}];
mockIdentityService.getCurrentIdentity.returns(Promise.resolve('bob'));
mockInitializationService.isWebOnly.returns(Promise.resolve(false));
let updateConnectionDataMock = sinon.stub(component, 'updateConnectionData').returns(Promise.resolve());
Expand All @@ -531,16 +524,16 @@ describe('AppComponent', () => {

component['usingLocally'].should.equal(true);

links.length.should.equal(4);
links.length.should.equal(3);
links[0].linkParams.should.deep.equal(['editor']);
links[1].linkParams.should.deep.equal(['test']);
links[2].linkParams.should.deep.equal(['identity']);
links[3].linkParams.should.deep.equal(['profile']);
}));

it('should load the connection profiles when web only and logged in', fakeAsync(() => {

component['showHeaderLinks'] = true;
component['connectionProfiles'] = [{name: 'test_name'}];
mockIdentityService.getCurrentIdentity.returns(Promise.resolve('bob'));
mockInitializationService.isWebOnly.returns(Promise.resolve(true));
let updateConnectionDataMock = sinon.stub(component, 'updateConnectionData').returns(Promise.resolve());
Expand Down
13 changes: 11 additions & 2 deletions packages/composer-playground/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ export class AppComponent implements OnInit, OnDestroy {

private usingLocally = false;
private showHeaderLinks = false;
private showWelcome = true;

private composerRuntimeVersion = '<none>';
private participantFQI = '<none>';
private composerBanner = ['Hyperledger', 'Composer Playground'];

private busyModalRef = null;

Expand Down Expand Up @@ -99,14 +101,15 @@ export class AppComponent implements OnInit, OnDestroy {
this.identityService.setCurrentIdentity(null);
this.connectionProfileService.setCurrentConnectionProfile(null);
this.identityService.setLoggedIn(false);
this.composerBanner = ['Hyperledger', 'Composer Playground'];
this.showWelcome = false;

return this.router.navigate(['/login']);

}

processRouteEvent(event): Promise<void> {
let welcomePromise;
if (event['url'] === '/login') {
if (event['url'] === '/login' && this.showWelcome) {
welcomePromise = this.openWelcomeModal();
} else {
welcomePromise = this.checkVersion().then((success) => {
Expand All @@ -120,6 +123,12 @@ export class AppComponent implements OnInit, OnDestroy {
this.showHeaderLinks = false;
} else {
this.showHeaderLinks = true;
this.clientService.ensureConnected()
.then(() => {
let profileName = this.connectionProfileService.getCurrentConnectionProfile() === '$default' ? 'Web' : this.connectionProfileService.getCurrentConnectionProfile();
let busNetName = this.clientService.getBusinessNetworkName();
this.composerBanner = [profileName, busNetName];
});
}

return welcomePromise;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ <h1>Editing package.json</h1>
<div *ngIf="!editActive && !editingPackage" class="business-network-details">
<div style="flex-shrink:1;align-self: center">
<h1 *ngIf="currentFile && fileType(currentFile)!='Readme'" class="margin-right">{{ fileType(currentFile) }} File</h1>
<h1 id="editor_deployedPackageName" *ngIf="currentFile && fileType(currentFile)=='Readme'" class="margin-right">{{ deployedPackageName }}</h1>
<h1 id="editor_deployedPackageName" *ngIf="currentFile && fileType(currentFile)=='Readme'" class="business-network-description"><p>{{ deployedPackageDescription }}</p><div class="tooltiptext">{{ deployedPackageDescription }}</div></h1>
</div>
<div *ngIf="currentFile && fileType(currentFile)!='Readme'" style="flex-shrink:1;align-self:center" class="business-network-version small">{{currentFile.displayID}}</div>
<div *ngIf="currentFile && fileType(currentFile)=='Readme'" style="flex-shrink:1;align-self:center" class="business-network-version small">{{deployedPackageVersion}}</div>
<div *ngIf="currentFile && fileType(currentFile)=='Readme'" style="flex-shrink:1;align-self:center" class="business-network-version small">v{{deployedPackageVersion}}</div>
<div *ngIf="(currentFile && !preventNameEdit(currentFile))" class="edit_icon">
<button id="editFileButton" type="button" class="action" (click)="toggleEditActive()">
<svg class="ibm-icon vertical-top" aria-hidden="true">
Expand All @@ -79,9 +79,7 @@ <h1 id="editor_deployedPackageName" *ngIf="currentFile && fileType(currentFile)=
</div>
</div>
<div *ngIf="editActive && fileType(currentFile)=='Readme'" class="business-network-details">
<label class="edit-label margin-right" for="editName">Name</label>
<input class="margin-right" id="editName" type="text" (blur)="editPackageName()" [(ngModel)]="inputPackageName">
<label class="edit-label margin-right" for="editVersion">Version</label>
<label class="edit-label margin-right" for="editVersion">Version: </label>
<input class="margin-right" id="editVersion" type="text" (blur)="editPackageVersion()"
[(ngModel)]="inputPackageVersion">
<div class="edit-package-text margin-right">
Expand Down
26 changes: 23 additions & 3 deletions packages/composer-playground/src/app/editor/editor.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,31 @@ app-editor {
.business-network-details {
display: flex;
height:50px;
margin-bottom: 0.2rem;
margin-bottom: 0rem;

.business-network-description {
margin-right: $space-smedium;
max-width: 20rem;
color: $secondary-text;
position: relative;
p {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}

.business-network-description .tooltiptext {
top : 1.5rem;
}

.business-network-description:hover .tooltiptext {
visibility: visible;
}

.business-network-version {
margin-right: $space-smedium;
margin-bottom: 0.3rem;
color: $secondary-text;
}

Expand All @@ -62,8 +83,7 @@ app-editor {
.edit-label{
line-height: 2.5rem;
font-weight:bold;
flex-shrink:1;
margin-top: 0.2rem;
flex:0 0 auto;
}

.edit-file-hidden{
Expand Down
Loading