Skip to content

Commit 97d77c7

Browse files
authored
Merge pull request #510 from mulesoft/demo
Demos and tests
2 parents 45267e8 + 563e9da commit 97d77c7

File tree

12 files changed

+335
-43
lines changed

12 files changed

+335
-43
lines changed

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"undef": true,
1515
"unused": true,
1616
"newcap": false,
17+
"mocha": true,
1718
"globals": {
1819
"Polymer": true,
1920
"ArcBehaviors": true,

api-console-request.html

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,33 +105,19 @@
105105
],
106106

107107
properties: {
108-
/**
109-
* Current path to the resource / method / documentation.
110-
* This is updated when the user select a specific node in the RAML JSON structure that
111-
* represents one of this properties. When changed from the outside (by the app) it will
112-
* update the view to display selected path.
113-
*/
114-
path: {
115-
type: String,
116-
notify: true
117-
},
118108
// Selected object in the navigation menu and parsed by the
119109
// `raml-path-selector` element
120110
selectedObject: {
121111
type: Object,
122112
observer: '_selectedObjectChanged'
123113
},
124-
// A parent endpoint of selected method object (if any).
125-
selectedParent: Object,
126114
// If true it will display a narrow layout.
127115
narrow: {
128116
type: Boolean,
129117
notify: true
130118
},
131119
// The RAML definition JSON object
132-
raml: {
133-
type: Object
134-
},
120+
raml: Object,
135121
// OAuth2 redirect URL
136122
redirectUrl: String,
137123
/**
@@ -156,7 +142,6 @@
156142
// Computed value, true, when the response object is set.
157143
hasResponse: {
158144
type: Boolean,
159-
value: false,
160145
computed: '_computeHasResponse(response)'
161146
},
162147
// Response full loading time.
@@ -226,7 +211,10 @@
226211
* Location of the `bower_components` folder.
227212
* It should be a path from server's root path including bower_components.
228213
*/
229-
bowerLocation: String,
214+
bowerLocation: {
215+
type: String,
216+
observer: '_updateRedirectUrl'
217+
},
230218
/**
231219
* Hides the URL editor from the view.
232220
* Note that the editor is still in the DOM. This property just hiddes
@@ -240,13 +228,14 @@
240228
},
241229

242230
ready: function() {
243-
this._setRedirectUrl();
231+
if (!this.redirectUrl) {
232+
this._updateRedirectUrl(this.bowerLocation);
233+
}
244234
this._initExtensionBanner();
245235
},
246236
// Sets OAuth 2 redirect URL for the authorization panel
247-
_setRedirectUrl: function() {
237+
_updateRedirectUrl: function(location) {
248238
var a = document.createElement('a');
249-
var location = this.bowerLocation;
250239
if (!location) {
251240
location = 'bower_components/';
252241
}

api-console.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,8 @@
146146
no-extension-banner="[[noExtensionBanner]]"
147147
narrow="[[narrow]]"
148148
name="request"
149-
page="[[page]]"
150149
scroll-target="[[scrollTarget]]"
151150
selected-object="[[selectedObject]]"
152-
selected-parent="[[selectedParent]]"
153-
path="{{path}}"
154151
append-headers="[[_computeAppendHeaders(appendHeaders)]]"
155152
proxy="[[proxy]]"
156153
proxy-encode-url="[[proxyEncodeUrl]]"

bower.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,20 @@
4747
},
4848
"devDependencies": {
4949
"iron-component-page": "polymerelements/iron-component-page#1.0.0",
50-
"web-component-tester": "^4.0.0",
50+
"web-component-tester": "^6.0.0",
5151
"paper-styles": "polymerelements/paper-styles#^1.0.2",
5252
"iron-demo-helpers": "PolymerElements/iron-demo-helpers#^1.0.0",
53-
"iron-test-helpers": "PolymerElements/iron-test-helpers#^1.0.0",
54-
"test-fixture": "PolymerElements/test-fixture#^1.0.0",
53+
"iron-test-helpers": "PolymerElements/iron-test-helpers#^1.4.0",
54+
"test-fixture": "PolymerElements/test-fixture#^3.0.0",
5555
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0",
5656
"arc-demo-helpers": "advanced-rest-client/arc-demo-helpers#^1.0.4",
5757
"paper-dropdown-menu": "PolymerElements/paper-dropdown-menu#^1.4.3",
5858
"paper-listbox": "polymerelements/paper-listbox#^1.1.2",
5959
"paper-item": "PolymerElements/paper-item#^1.2.1",
6060
"raml-docs-helpers": "advanced-rest-client/raml-docs-helpers#^1.0.5",
6161
"app-route": "PolymerElements/app-route#^1.0.0",
62-
"raml-aware": "advanced-rest-client/raml-aware#^1.0.3"
62+
"raml-aware": "advanced-rest-client/raml-aware#^1.0.3",
63+
"paper-toggle-button": "PolymerElements/paper-toggle-button#<2"
6364
},
6465
"ignore": [
6566
"**/.*",

demo/app.html

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<title>API Console</title>
1818
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
1919
<link rel="import" href="../../raml-docs-helpers/raml-docs-parser.html">
20-
<link rel="import" href="../../paper-checkbox/paper-checkbox.html">
20+
<link rel="import" href="../../paper-toggle-button/paper-toggle-button.html">
2121
<link rel="import" href="../../app-route/app-location.html">
2222
<link rel="import" href="../api-console.html">
2323

@@ -43,18 +43,14 @@
4343

4444
.wrapper {
4545
position: relative;
46+
background-color: #fff;
4647
@apply(--layout-flex);
4748
}
4849

4950
api-console {
5051
background-color: #fff;
5152
}
5253

53-
:root {
54-
--paper-checkbox-unchecked-color: #fff;
55-
--paper-checkbox-label-color: #fff;
56-
}
57-
5854
.powered-by {
5955
@apply(--layout-horizontal);
6056
@apply(--layout-center-center);
@@ -66,13 +62,40 @@
6662
a img {
6763
text-underline: none;
6864
}
65+
66+
.console-controls {
67+
padding: 4px 12px;
68+
@apply --layout-horizontal;
69+
@apply --layout-center;
70+
}
71+
72+
.console-controls > * {
73+
margin-right: 12px;
74+
}
75+
76+
.console-controls paper-toggle-button {
77+
cursor: pointer;
78+
}
79+
80+
.console-controls {
81+
--paper-toggle-button-checked-button-color: #00A2DF;
82+
}
83+
84+
raml-docs-parser {
85+
margin: 4px 12px;
86+
}
6987
</style>
7088
</head>
7189

7290
<body unresolved>
7391
<app-location use-hash-as-path></app-location>
7492

7593
<div id="content">
94+
<div class="console-controls">
95+
<paper-toggle-button data-action="parser" checked>Display RAML parser</paper-toggle-button>
96+
<paper-toggle-button data-action="noTryIt">No try it</paper-toggle-button>
97+
<paper-toggle-button data-action="narrow">Render narrow</paper-toggle-button>
98+
</div>
7699
<raml-docs-parser></raml-docs-parser>
77100
<div class="wrapper">
78101
<api-console>

demo/app.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
apiconsole.app.setInitialRouteData();
3535
apiconsole.app.addParserListeners();
3636
apiconsole.app.observeRouteEvents();
37+
apiconsole.app.observeConsoleControls();
3738
};
3839

3940
apiconsole.app.setInitialRouteData = function() {
@@ -159,6 +160,32 @@
159160
};
160161
};
161162

163+
apiconsole.app.observeConsoleControls = function() {
164+
var toggles = document.querySelectorAll('.console-controls paper-toggle-button');
165+
for (var i = 0, len = toggles.length; i < len; i++) {
166+
toggles[i].addEventListener('checked-changed', apiconsole.app.consoleControlsChanged);
167+
}
168+
};
169+
170+
apiconsole.app.consoleControlsChanged = function(e) {
171+
var action = e.target.dataset.action;
172+
switch (action) {
173+
case 'parser':
174+
var parser = document.querySelector('raml-docs-parser');
175+
if (e.detail.value) {
176+
parser.removeAttribute('hidden');
177+
} else {
178+
parser.setAttribute('hidden', true);
179+
}
180+
break;
181+
case 'noTryIt':
182+
case 'narrow':
183+
var apiConsole = document.querySelector('api-console');
184+
apiConsole[action] = e.detail.value;
185+
break;
186+
}
187+
};
188+
162189
// Notifys user when something went wrong...
163190
apiconsole.app.notifyInitError = function(message) {
164191
window.alert('Cannot initialize API console. ' + message);

demo/index.html

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
1919
<link rel="import" href="../../raml-docs-helpers/raml-docs-parser.html">
2020
<link rel="import" href="../../paper-checkbox/paper-checkbox.html">
21+
<link rel="import" href="../../paper-toggle-button/paper-toggle-button.html">
2122
<link rel="import" href="../api-console.html">
2223
<link rel="import" href="../../font-roboto/roboto.html">
2324

@@ -43,6 +44,7 @@
4344

4445
.wrapper {
4546
position: relative;
47+
background-color: #fff;
4648
@apply(--layout-flex);
4749
}
4850

@@ -56,8 +58,8 @@
5658
}
5759

5860
.powered-by {
59-
@apply(--layout-horizontal);
60-
@apply(--layout-center-center);
61+
@apply --layout-horizontal;
62+
@apply --layout-center-center;
6163
padding: 12px 0px;
6264
border-top: 1px rgba(0,0,0,0.24) solid;
6365
margin: 8px 12px 0 12px;
@@ -66,18 +68,43 @@
6668
a img {
6769
text-underline: none;
6870
}
71+
72+
.console-controls {
73+
padding: 4px 12px;
74+
@apply --layout-horizontal;
75+
@apply --layout-center;
76+
}
77+
78+
.console-controls > * {
79+
margin-right: 12px;
80+
}
81+
82+
.console-controls paper-toggle-button {
83+
cursor: pointer;
84+
}
85+
86+
.console-controls {
87+
--paper-toggle-button-checked-button-color: #00A2DF;
88+
}
89+
90+
raml-docs-parser {
91+
margin: 4px 12px;
92+
}
6993
</style>
7094
</head>
7195

7296
<body unresolved>
7397
<template is="dom-bind" id="app">
7498

7599
<div id="content">
76-
<raml-docs-parser raml="{{raml}}"></raml-docs-parser>
100+
<div class="console-controls">
101+
<paper-toggle-button checked="{{parserEnabled}}">Display RAML parser</paper-toggle-button>
102+
<paper-toggle-button checked="{{noTryIt}}">No try it</paper-toggle-button>
103+
<paper-toggle-button checked="{{narrow}}">Render narrow</paper-toggle-button>
104+
</div>
105+
<raml-docs-parser raml="{{raml}}" hidden$="[[!parserEnabled]]"></raml-docs-parser>
77106
<div class="wrapper">
78107
<api-console raml="[[raml]]" append-headers="X-key: my-api-key\nOther-header:value" narrow="[[narrow]]" manual-navigation="[[manualNavigation]]" navigation-opened="{{navigationOpened}}" no-try-it="[[noTryIt]]">
79-
<paper-checkbox nav checked="{{noTryIt}}">No try it</paper-checkbox>
80-
<paper-checkbox nav checked="{{narrow}}">Render narrow</paper-checkbox>
81108
<paper-checkbox nav checked="{{manualNavigation}}">Manual navigation</paper-checkbox>
82109
<button nav hidden="[[!manualNavigation]]" on-tap="toggleNavigation">Toggle navigation</button>
83110
<div class="powered-by" nav-addon>
@@ -90,7 +117,7 @@
90117
<script>
91118
(function(scope) {
92119
'use strict';
93-
// scope.navigationOpened = false;
120+
scope.parserEnabled = true;
94121
scope.toggleNavigation = function() {
95122
if (scope.navigationOpened === undefined) {
96123
scope.navigationOpened = true;

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "CPAL-1.0",
55
"description": "The API console used in RAML platform.",
66
"devDependencies": {
7-
"polymer-cli": "^0.17.0"
7+
"polymer-cli": "^1.2.0"
88
},
99
"engines": {
1010
"node": ">=0.10.0"
@@ -19,8 +19,8 @@
1919
"scripts": {
2020
"serve": "node_modules/.bin/polymer serve",
2121
"lint": "node_modules/.bin/polymer lint api-console.html api-console-request.html",
22-
"test-sauce": "exit 0; node_modules/.bin/polymer test --plugin sauce --job-name \"api-console:local-test\"",
23-
"test": "node_modules/.bin/polymer test",
22+
"test-sauce": "node_modules/.bin/polymer test --plugin sauce --job-name \"api-console:local-test\"",
23+
"test": "node_modules/.bin/polymer test --plugin local",
2424
"deps": "npm i --quiet && bower install --quiet",
2525
"update-deps": "npm i --quiet && bower update --quiet"
2626
},

polymer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"lint": {
3+
"rules": ["polymer-1"]
4+
}
5+
}

test/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
'basic-test.html',
2525
'basic-test.html?dom=shadow',
2626
'raml-aware-test.html',
27-
'raml-aware-test.html?dom=shadow'
27+
'raml-aware-test.html?dom=shadow',
28+
'request-test.html',
29+
'request-test.html?dom=shadow'
2830
]);
2931
</script>
3032
</body>

0 commit comments

Comments
 (0)