From b3b8dffba3b6199f295db5b33c21ac1b0639f9ba Mon Sep 17 00:00:00 2001 From: rpidikiti Date: Wed, 19 Oct 2011 16:08:27 -0700 Subject: [PATCH] Updated UI to handle object structure for list allowed values --- build/index.html | 2 +- build/javascripts/swagger-service.js | 46 +++++++++++++++++++++++++-- build/javascripts/swagger-ui.js | 2 +- source/index.html.haml | 2 +- source/javascripts/swagger-service.js | 44 +++++++++++++++++++++++-- source/javascripts/swagger-ui.js | 2 +- 6 files changed, 89 insertions(+), 9 deletions(-) diff --git a/build/index.html b/build/index.html index ade6aaf9..bfc1cefe 100644 --- a/build/index.html +++ b/build/index.html @@ -123,7 +123,7 @@ {{if required == false }} {{/if}} - {{each allowableValues}} + {{each allowableValues.values}} {{if $value == defaultValue && required == true}} {{else}} diff --git a/build/javascripts/swagger-service.js b/build/javascripts/swagger-service.js index efc83e58..a178cf77 100644 --- a/build/javascripts/swagger-service.js +++ b/build/javascripts/swagger-service.js @@ -65,7 +65,7 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) { this.path_xml = this.path.replace("{format}", "xml"); this.baseUrl = apiHost; //execluded 9 letters to remove .{format} from name - this.name = this.path.substr(1, this.path.length - formatString.length - 1); + this.name = this.path.substr(1, this.path.length - formatString.length - 1).replace(/\//g, "_"); this.apiList = Api.sub(); this.modelList = ApiModel.sub(); }, @@ -219,17 +219,57 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) { if (atts) this.load(atts); this.name = this.name || this.dataType; + + if(this.allowableValues){ + var value = this.allowableValues; + if(value.valueType == "LIST"){ + this.allowableValues = AllowableListValues.sub(); + } else if (value.valueType == "RANGE"){ + this.allowableValues = AllowableRangeValues.sub(); + } + if (value) this.allowableValues = this.allowableValues.create(value); + } }, toString: function() { - if (this.allowableValues && this.allowableValues.length > 0) - return this.name + ": " + this.dataType + " [" + this.allowableValues + "]"; + if (this.allowableValues) + return this.name + ": " + this.dataType + " " + this.allowableValues; else return this.name + ": " + this.dataType; } }); + var AllowableListValues = Spine.Model.setup("AllowableListValues", ["valueType", "values"]); + AllowableListValues.include({ + init: function(atts) { + if (atts) this.load(atts); + this.name = "allowableValues"; + }, + toString: function() { + if (this.values) + return "["+this.values+"]"; + else + return ""; + } + }); + + var AllowableRangeValues = Spine.Model.setup("AllowableRangeValues", ["valueType", "inclusive", "min", "max"]); + AllowableRangeValues.include({ + init: function(atts) { + if (atts) this.load(atts); + this.name = "allowableValues"; + }, + + toString: function() { + if (this.min && this.max) + return "[" + min + "," + max + "]"; + else + return ""; + } + }); + + // Model: ApiModel var ApiModel = Spine.Model.setup("ApiModel", ["id", "fields"]); ApiModel.include({ diff --git a/build/javascripts/swagger-ui.js b/build/javascripts/swagger-ui.js index c93d7bd1..5aba7577 100644 --- a/build/javascripts/swagger-ui.js +++ b/build/javascripts/swagger-ui.js @@ -237,7 +237,7 @@ jQuery(function($) { templateName: function(){ var n = "#paramTemplate"; - if (this.allowableValues && this.allowableValues.length > 0) { + if (this.allowableValues && this.allowableValues.valueType == "LIST") { n += "Select"; } else { if (this.required) n += "Required"; diff --git a/source/index.html.haml b/source/index.html.haml index d0c2cd1b..c2d32553 100644 --- a/source/index.html.haml +++ b/source/index.html.haml @@ -80,7 +80,7 @@ {{if required == false }} %option{:value => "", :selected => 'selected'} {{/if}} - {{each allowableValues}} + {{each allowableValues.values}} {{if $value == defaultValue && required == true }} %option{:value => "${$value}", :selected => 'selected'} ${$value} {{else}} diff --git a/source/javascripts/swagger-service.js b/source/javascripts/swagger-service.js index 53b5b7fe..a178cf77 100644 --- a/source/javascripts/swagger-service.js +++ b/source/javascripts/swagger-service.js @@ -219,17 +219,57 @@ function SwaggerService(baseUrl, _apiKey, statusCallback) { if (atts) this.load(atts); this.name = this.name || this.dataType; + + if(this.allowableValues){ + var value = this.allowableValues; + if(value.valueType == "LIST"){ + this.allowableValues = AllowableListValues.sub(); + } else if (value.valueType == "RANGE"){ + this.allowableValues = AllowableRangeValues.sub(); + } + if (value) this.allowableValues = this.allowableValues.create(value); + } }, toString: function() { - if (this.allowableValues && this.allowableValues.length > 0) - return this.name + ": " + this.dataType + " [" + this.allowableValues + "]"; + if (this.allowableValues) + return this.name + ": " + this.dataType + " " + this.allowableValues; else return this.name + ": " + this.dataType; } }); + var AllowableListValues = Spine.Model.setup("AllowableListValues", ["valueType", "values"]); + AllowableListValues.include({ + init: function(atts) { + if (atts) this.load(atts); + this.name = "allowableValues"; + }, + toString: function() { + if (this.values) + return "["+this.values+"]"; + else + return ""; + } + }); + + var AllowableRangeValues = Spine.Model.setup("AllowableRangeValues", ["valueType", "inclusive", "min", "max"]); + AllowableRangeValues.include({ + init: function(atts) { + if (atts) this.load(atts); + this.name = "allowableValues"; + }, + + toString: function() { + if (this.min && this.max) + return "[" + min + "," + max + "]"; + else + return ""; + } + }); + + // Model: ApiModel var ApiModel = Spine.Model.setup("ApiModel", ["id", "fields"]); ApiModel.include({ diff --git a/source/javascripts/swagger-ui.js b/source/javascripts/swagger-ui.js index c93d7bd1..5aba7577 100644 --- a/source/javascripts/swagger-ui.js +++ b/source/javascripts/swagger-ui.js @@ -237,7 +237,7 @@ jQuery(function($) { templateName: function(){ var n = "#paramTemplate"; - if (this.allowableValues && this.allowableValues.length > 0) { + if (this.allowableValues && this.allowableValues.valueType == "LIST") { n += "Select"; } else { if (this.required) n += "Required";