From f7976503af111d7af44c51f10cc52f963f1251c8 Mon Sep 17 00:00:00 2001 From: Luqiang Tian Date: Wed, 2 Nov 2016 12:04:20 +0800 Subject: [PATCH] Disable generating codes from swagger codegen. --- scripts/components.js | 1 + scripts/controllers/CrossOriginPromptCtrl.js | 31 ++++++++++++++++++++ scripts/controllers/header.js | 13 +++----- templates/cross-origin-prompt.html | 11 +++---- 4 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 scripts/controllers/CrossOriginPromptCtrl.js diff --git a/scripts/components.js b/scripts/components.js index be31a8bf1e9..62f439af3d4 100644 --- a/scripts/components.js +++ b/scripts/components.js @@ -39,6 +39,7 @@ require('scripts/controllers/importurl.js'); require('scripts/controllers/main.js'); require('scripts/controllers/modal.js'); require('scripts/controllers/openexamples.js'); +require('scripts/controllers/CrossOriginPromptCtrl.js'); require('scripts/controllers/paste-json.js'); require('scripts/controllers/preferences.js'); require('scripts/controllers/preview.js'); diff --git a/scripts/controllers/CrossOriginPromptCtrl.js b/scripts/controllers/CrossOriginPromptCtrl.js new file mode 100644 index 00000000000..638ae906029 --- /dev/null +++ b/scripts/controllers/CrossOriginPromptCtrl.js @@ -0,0 +1,31 @@ +'use strict'; + + +SwaggerEditor.controller('CrossOriginPromptCtrl', function CrossOriginPromptCtrl($scope, + $uibModalInstance, $rootScope, simpleYaml,YAML) { + YAML.dump(simpleYaml.swagger, function(error, result){ + var yamlBlob = new Blob([result], {type: 'text/plain'}); + $scope.yamlDownloadHref = window.URL.createObjectURL(yamlBlob); + $scope.yamlDownloadUrl = [ + 'text/plain', + 'swagger.yaml', + $scope.yamlDownloadHref + ].join(':'); + + if(error) {$scope.swaggerSpec = "Error"; return;} + {$scope.swaggerSpec = result; return;} + }); + + $scope.copy=function(){ + var copyTextarea = document.querySelector('#prompt-swaggerspec'); + copyTextarea.select(); + + try { + var successful = document.execCommand('copy'); + var msg = successful ? 'successful' : 'unsuccessful'; + console.log('Copying text command was ' + msg); + } catch (err) { + console.log('Oops, unable to copy'); + } + }; +}); diff --git a/scripts/controllers/header.js b/scripts/controllers/header.js index c68b1814671..3f7c7c60631 100644 --- a/scripts/controllers/header.js +++ b/scripts/controllers/header.js @@ -2,7 +2,7 @@ SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal, $stateParams, $state, $rootScope, Storage, Builder, FileLoader, Editor, - Codegen, Preferences, YAML, defaults, strings, $localStorage) { + Codegen, Preferences, YAML, defaults, strings, $localStorage, simpleYaml) { if ($stateParams.path) { $scope.breadcrumbs = [{active: true, name: $stateParams.path}]; } else { @@ -53,6 +53,8 @@ SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal, }); } + $scope.swaggerSpec=''; + $scope.getSDK = function(type, language) { if(!!Preferences.get('simpleYAML') && language === 'csharp') { @@ -62,14 +64,7 @@ SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal, $uibModal.open({ template: require('templates/cross-origin-prompt.html'), size: 'large', - controller: function CrossOriginPromptCtrl($scope, - $uibModalInstance, $rootScope) { - $scope.ok = function() { - $uibModalInstance.close(); - Codegen.getSDK(type, language).then(noop, showCodegenError); - }; - $scope.cancel = $uibModalInstance.close; - } + controller: 'CrossOriginPromptCtrl' }); }; diff --git a/templates/cross-origin-prompt.html b/templates/cross-origin-prompt.html index 42aedf26736..cd420d5f780 100644 --- a/templates/cross-origin-prompt.html +++ b/templates/cross-origin-prompt.html @@ -3,12 +3,13 @@