api-console-assets
Version:
This repo only exists to publish api console components to npm
133 lines (123 loc) • 4.68 kB
HTML
<!--
@license
Copyright 2016 The Advanced REST client authors <arc@mulesoft.com>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../paper-item/paper-item.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../anypoint-icons/anypoint-icons.html">
<link rel="import" href="raml-tree-item-behavior.html">
<link rel="import" href="path-selector-behavior.html">
<link rel="import" href="raml-tree-item-styles.html">
<link rel="import" href="raml-resource-tree-item.html">
<link rel="import" href="raml-type-tree-item.html">
<link rel="import" href="path-selector-styles.html">
<!--
The `path-selector-resource` is a full screen display for the resources selector.
See demo (with narrow layout enabled) for an example.
## Styling
Custom property | Description | Default
----------------|-------------|----------
`--raml-path-selector-back-icon-color` | Color of the "back" icon | `rgba(0, 0, 0, 0.54)`
`--raml-path-selector-back-icon-color-hover` | Color of the "back" icon when hovered | `rgba(0, 0, 0, 0.87)`
@element path-selector-resource
@demo demo/index.html
-->
<dom-module id="path-selector-resource">
<template>
<style include="raml-tree-item-styles"></style>
<style include="path-selector-styles"></style>
<template is="dom-if" if="[[opened]]">
<div class="section-title">
<paper-icon-button on-tap="back" class="back-button" icon="anypoint:back" noink="[[noink]]"></paper-icon-button>
<h3>[[resourceName]]</h3>
</div>
<template is="dom-repeat" items="[[methods]]">
<paper-item data-path$="[[path]].methods.[[index]]" on-tap="_selectPath" class$="method-name-item [[_computeItemSelectableClass(selectedPath, path, index)]]" title$="[[item.method]] [[item.description]]">
<span class="indentable-content method-description">
<span class$="[[_computeMethodClass(item.method)]]">[[item.method]]</span>
<span class="method-display">[[item.displayName]]</span>
</span>
</paper-item>
</template>
<template is="dom-repeat" items="[[resources]]">
<raml-resource-tree-item indent="1" indent-size="[[indentSize]]" selected-path="[[selectedPath]]" resource="[[item]]" path="[[_computeSubresourcePath(path, index)]]" path="" opened="[[itemsOpened]]" narrow noink="noink"></raml-resource-tree-item>
</template>
</template>
</template>
<script>
Polymer({
is: 'path-selector-resource',
behaviors: [RamlBehaviors.RamlTreeItemBehavior, RamlBehaviors.PathSelectorBehavior],
properties: {
/**
* List of types nodes.
*/
resources: Array,
// List of methods in this resource
methods: Array,
itemsOpened: Boolean,
// Title to display.
resourceName: {
type: String,
value: function() {
return 'Resources';
}
},
// Item's path in the recursive structure
path: {
type: String,
value: function() {
return '';
}
},
/**
* If true, the element will not produce a ripple effect when interacted with via the pointer.
*/
noink: Boolean
},
/**
* Computes CSS class name for the HTTP method label.
*
* @param {String} method an HTTP method name.
* @return {String} CSS class name always starting with the `method` class.
*/
_computeMethodClass: function(method) {
if (!method) {
return;
}
method = method.toLowerCase();
var clazz = 'method ';
switch (method) {
case 'get':
case 'post':
case 'put':
case 'delete':
case 'patch':
clazz += method;
break;
}
return clazz;
},
// Computes a path for sub resource.
_computeSubresourcePath: function(path, index) {
var result = '';
if (path) {
result += path + '.';
}
result += path + 'resources.' + index;
return result;
}
});
</script>
</dom-module>