From 0e8c45977c1fb2826d1b989f3dc96248e65d44a2 Mon Sep 17 00:00:00 2001 From: Carolina Wright Date: Tue, 30 May 2017 15:43:43 -0300 Subject: [PATCH] Cannot open root resource --- dist/scripts/api-console.js | 24 ++++++++++++++----- src/app/directives/documentation.js | 4 ++-- .../directives/resource-tree/id-generator.js | 11 +++++++++ .../directives/resource-tree/resource-id.js | 4 ++-- src/app/directives/root-documentation.js | 4 ++-- 5 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 src/app/directives/resource-tree/id-generator.js diff --git a/dist/scripts/api-console.js b/dist/scripts/api-console.js index 34e6e2cf5..f104825f4 100644 --- a/dist/scripts/api-console.js +++ b/dist/scripts/api-console.js @@ -153,7 +153,7 @@ return { restrict: 'E', templateUrl: 'directives/documentation.tpl.html', - controller: ['$scope', function($scope) { + controller: ['$scope', 'idGenerator', function($scope, idGenerator) { $scope.markedOptions = RAML.Settings.marked; $scope.$watch('securitySchemes', function() { @@ -393,7 +393,7 @@ }; $scope.getBodyId = function (bodyType) { - return jQuery.trim(bodyType.toString().replace(/\W/g, ' ')).replace(/\s+/g, '_'); + return idGenerator(bodyType.toString()); }; $scope.bodySelected = function (value) { @@ -1660,6 +1660,18 @@ .directive('resourcePanel', RAML.Directives.resourcePanel); })(); +(function () { + 'use strict'; + + angular.module('RAML.Directives') + .factory('idGenerator', [function idGenerator() { + return function(value) { + var id = jQuery.trim(value.replace(/\W/g, ' ')).replace(/\s+/g, '_'); + return id === '' ? '-' : id; + }; + }]); +})(); + (function () { 'use strict'; @@ -1699,9 +1711,9 @@ 'use strict'; angular.module('RAML.Directives') - .factory('resourceId', [function resourceId() { + .factory('resourceId', ['idGenerator', function resourceId(idGenerator) { return function(resource) { - return jQuery.trim(resource.pathSegments.toString().replace(/\W/g, ' ')).replace(/\s+/g, '_'); + return idGenerator(resource.pathSegments.toString()); }; }]); })(); @@ -2132,7 +2144,7 @@ restrict: 'E', templateUrl: 'directives/root-documentation.tpl.html', replace: true, - controller: ['$scope', '$timeout', function($scope, $timeout) { + controller: ['$scope', '$timeout', 'idGenerator', function($scope, $timeout, idGenerator) { $scope.markedOptions = RAML.Settings.marked; $scope.selectedSection = 'all'; @@ -2145,7 +2157,7 @@ }; $scope.generateDocId = function (path) { - return jQuery.trim(path.toString().replace(/\W/g, ' ')).replace(/\s+/g, '_').toLowerCase(); + return idGenerator(path.toString()); }; $scope.toggleSection = function ($event, key, section) { diff --git a/src/app/directives/documentation.js b/src/app/directives/documentation.js index 77f34a7cd..7af954d0e 100644 --- a/src/app/directives/documentation.js +++ b/src/app/directives/documentation.js @@ -5,7 +5,7 @@ return { restrict: 'E', templateUrl: 'directives/documentation.tpl.html', - controller: ['$scope', function($scope) { + controller: ['$scope', 'idGenerator', function($scope, idGenerator) { $scope.markedOptions = RAML.Settings.marked; $scope.$watch('securitySchemes', function() { @@ -245,7 +245,7 @@ }; $scope.getBodyId = function (bodyType) { - return jQuery.trim(bodyType.toString().replace(/\W/g, ' ')).replace(/\s+/g, '_'); + return idGenerator(bodyType.toString()); }; $scope.bodySelected = function (value) { diff --git a/src/app/directives/resource-tree/id-generator.js b/src/app/directives/resource-tree/id-generator.js new file mode 100644 index 000000000..07c8558b1 --- /dev/null +++ b/src/app/directives/resource-tree/id-generator.js @@ -0,0 +1,11 @@ +(function () { + 'use strict'; + + angular.module('RAML.Directives') + .factory('idGenerator', [function idGenerator() { + return function(value) { + var id = jQuery.trim(value.replace(/\W/g, ' ')).replace(/\s+/g, '_'); + return id === '' ? '-' : id; + }; + }]); +})(); diff --git a/src/app/directives/resource-tree/resource-id.js b/src/app/directives/resource-tree/resource-id.js index e7c1994fe..0a8e75782 100644 --- a/src/app/directives/resource-tree/resource-id.js +++ b/src/app/directives/resource-tree/resource-id.js @@ -2,9 +2,9 @@ 'use strict'; angular.module('RAML.Directives') - .factory('resourceId', [function resourceId() { + .factory('resourceId', ['idGenerator', function resourceId(idGenerator) { return function(resource) { - return jQuery.trim(resource.pathSegments.toString().replace(/\W/g, ' ')).replace(/\s+/g, '_'); + return idGenerator(resource.pathSegments.toString()); }; }]); })(); diff --git a/src/app/directives/root-documentation.js b/src/app/directives/root-documentation.js index 27948d570..7a59b36b7 100644 --- a/src/app/directives/root-documentation.js +++ b/src/app/directives/root-documentation.js @@ -6,7 +6,7 @@ restrict: 'E', templateUrl: 'directives/root-documentation.tpl.html', replace: true, - controller: ['$scope', '$timeout', function($scope, $timeout) { + controller: ['$scope', '$timeout', 'idGenerator', function($scope, $timeout, idGenerator) { $scope.markedOptions = RAML.Settings.marked; $scope.selectedSection = 'all'; @@ -19,7 +19,7 @@ }; $scope.generateDocId = function (path) { - return jQuery.trim(path.toString().replace(/\W/g, ' ')).replace(/\s+/g, '_').toLowerCase(); + return idGenerator(path.toString()); }; $scope.toggleSection = function ($event, key, section) {