From 93d7d98ad77d3ae01a62214240a02c0dff44787b Mon Sep 17 00:00:00 2001
From: Roman Gotsiy 
Date: Wed, 21 Oct 2015 12:20:14 +0300
Subject: [PATCH] Added responses list
---
 lib/components/Method/method.css              |  4 ++
 lib/components/Method/method.html             |  2 +
 lib/components/Method/method.js               |  3 +-
 lib/components/ParamsList/params-list.css     |  1 +
 lib/components/ParamsList/params-list.html    | 10 ++---
 .../ResponsesList/responses-list.css          | 32 ++++++++++++++
 .../ResponsesList/responses-list.html         | 22 ++++++++++
 .../ResponsesList/responses-list.js           | 42 +++++++++++++++++++
 8 files changed, 110 insertions(+), 6 deletions(-)
 create mode 100644 lib/components/ResponsesList/responses-list.css
 create mode 100644 lib/components/ResponsesList/responses-list.html
 create mode 100644 lib/components/ResponsesList/responses-list.js
diff --git a/lib/components/Method/method.css b/lib/components/Method/method.css
index a7eaef25..2a61ce42 100644
--- a/lib/components/Method/method.css
+++ b/lib/components/Method/method.css
@@ -1,3 +1,7 @@
+responses-list, params-list {
+  display: block;
+}
+
 h2 {
   font-size: 32px;
   font-weight: 200;
diff --git a/lib/components/Method/method.html b/lib/components/Method/method.html
index 52818d37..1037f3e3 100644
--- a/lib/components/Method/method.html
+++ b/lib/components/Method/method.html
@@ -7,3 +7,5 @@
   {{data.methodInfo.description}}
 
  
+
+ 
diff --git a/lib/components/Method/method.js b/lib/components/Method/method.js
index 58e29f9f..b0798da3 100644
--- a/lib/components/Method/method.js
+++ b/lib/components/Method/method.js
@@ -3,12 +3,13 @@
 import {JsonPointer} from '../../utils/JsonPointer';
 import {RedocComponent, BaseComponent} from '../base';
 import {ParamsList} from '../ParamsList/params-list';
+import {ResponsesList} from '../ResponsesList/responses-list';
 
 @RedocComponent({
   selector: 'method',
   templateUrl: './lib/components/Method/method.html',
   styleUrls: ['./lib/components/Method/method.css'],
-  directives: [ParamsList]
+  directives: [ParamsList, ResponsesList]
 })
 export class Method extends BaseComponent {
   constructor(schemaMgr) {
diff --git a/lib/components/ParamsList/params-list.css b/lib/components/ParamsList/params-list.css
index 66aa56c4..a7af38cb 100644
--- a/lib/components/ParamsList/params-list.css
+++ b/lib/components/ParamsList/params-list.css
@@ -5,6 +5,7 @@ h4 {
 }
 
 table {
+  width: 100%;
   border-spacing: 0;
   border: 2px solid #1976D3;
 }
diff --git a/lib/components/ParamsList/params-list.html b/lib/components/ParamsList/params-list.html
index 9dc431b2..358f82ac 100644
--- a/lib/components/ParamsList/params-list.html
+++ b/lib/components/ParamsList/params-list.html
@@ -1,24 +1,24 @@
  No parameters 
 
-
+
   
     
       | Parameters | 
     
       | Name- | Type | Description+ | Type | 
   
   
     
       
         | {{param.name}}- | -          {{param.type}}
- | {{param.description}}+ | +          {{param.type}}
+ | 
     
diff --git a/lib/components/ResponsesList/responses-list.css b/lib/components/ResponsesList/responses-list.css
new file mode 100644
index 00000000..f2c90766
--- /dev/null
+++ b/lib/components/ResponsesList/responses-list.css
@@ -0,0 +1,32 @@
+table {
+  width: 100%;
+  border-spacing: 0;
+  border: 2px solid green;
+}
+
+thead tr:first-child {
+  background: green;
+  color: #fff;
+  border: none;
+}
+
+thead tr:last-child th {
+  border-bottom: 3px solid #ddd;
+}
+
+tbody tr:last-child td {
+  border: none;
+}
+tbody td {
+  border-bottom: 1px solid #ddd;
+}
+
+td, th {
+  vertical-align: top;
+  padding: 10px 15px;
+  font-size: 12px;
+}
+
+th {
+  text-align: left;
+}
diff --git a/lib/components/ResponsesList/responses-list.html b/lib/components/ResponsesList/responses-list.html
new file mode 100644
index 00000000..53b0fd50
--- /dev/null
+++ b/lib/components/ResponsesList/responses-list.html
@@ -0,0 +1,22 @@
+
+  
+    
+      | Responses+ | 
+    
+      | Response code+ | Description+ | Response schema+ | 
+  
+  
+    
+      | {{response.code}}+ | {{response.description}}+ | +        
+        
++ | 
+  
+
diff --git a/lib/components/ResponsesList/responses-list.js b/lib/components/ResponsesList/responses-list.js
new file mode 100644
index 00000000..1dcdb159
--- /dev/null
+++ b/lib/components/ResponsesList/responses-list.js
@@ -0,0 +1,42 @@
+'use strict';
+
+import {RedocComponent, BaseComponent} from '../base';
+import {JsonPointer} from '../../utils/JsonPointer';
+import {JsonSchemaView} from '../JsonSchemaView/json-schema-view';
+
+function isNumeric(n) {
+  return (!isNaN(parseFloat(n)) && isFinite(n));
+}
+
+@RedocComponent({
+  selector: 'responses-list',
+  templateUrl: './lib/components/ResponsesList/responses-list.html',
+  styleUrls: ['./lib/components/ResponsesList/responses-list.css'],
+  directives: [JsonSchemaView]
+})
+export class ResponsesList extends BaseComponent {
+  constructor(schemaMgr) {
+    super(schemaMgr);
+  }
+
+  prepareModel() {
+    this.data = {};
+    let responses = this.componentSchema;
+    responses = Object.keys(responses).filter(respCode => {
+      // only response-codes and "default"
+      return ( isNumeric(respCode) || (respCode === 'default'));
+    }).map(respCode => {
+      let resp = responses[respCode];
+      resp.pointer = JsonPointer.join(this.pointer, respCode);
+      if (resp.$ref) {
+        let ref = resp.$ref;
+        resp = this.schemaMgr.byPointer(resp.$ref);
+        resp.pointer = ref;
+      }
+
+      resp.code = respCode;
+      return resp;
+    });
+    this.data.responses = responses;
+  }
+}