Skip to content

Commit

Permalink
Disable local storage && Add prompt when generating code && update gu…
Browse files Browse the repository at this point in the history
…ide.yaml
  • Loading branch information
lqtian committed Sep 1, 2016
1 parent 2557054 commit 06cfae6
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 12 deletions.
15 changes: 15 additions & 0 deletions scripts/controllers/cross-prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

var _ = require('lodash');
var angular = require('angular');

SwaggerEditor.controller('CrossOriginPromptCtrl', function FileImportCtrl($scope,
$uibModalInstance, $rootScope) {

$scope.ok = function() {

$uibModalInstance.close();
};

$scope.cancel = $uibModalInstance.close;
});
18 changes: 17 additions & 1 deletion scripts/controllers/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,23 @@ SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal,
}

$scope.getSDK = function(type, language) {
Codegen.getSDK(type, language).then(noop, showCodegenError);
if(!!Preferences.get('simpleYAML') && language === 'csharp')
{
Codegen.getSDK(type, language).then(noop, showCodegenError);
return;
}
$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;
}
});
};

/**
Expand Down
4 changes: 2 additions & 2 deletions scripts/services/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var angular = require('angular');
* Code Generator service
*/
SwaggerEditor.service('Codegen', function Codegen($http, $location, defaults, simpleYaml, Preferences, Storage,
YAML) {
YAML, $rootScope) {
this.getServers = function() {
if (!defaults.codegen.servers) {
return new Promise(function(resolve) {
Expand Down Expand Up @@ -53,7 +53,7 @@ SwaggerEditor.service('Codegen', function Codegen($http, $location, defaults, si
}, reject);

} else {
Storage.load('yaml').then(function (yaml) {
Promise.resolve($rootScope.editorValue).then(function (yaml) {
YAML.load(yaml, function (error, spec) {
if (error) {
return reject(error);
Expand Down
3 changes: 2 additions & 1 deletion scripts/services/local-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ SwaggerEditor.service('LocalStorage', function LocalStorage($localStorage,

_.debounce(function() {
window.requestAnimationFrame(function() {
$localStorage[storageKey][key] = value;
// Disable local storage
// $localStorage[storageKey][key] = value;
});

if (key === 'yaml') {
Expand Down
24 changes: 16 additions & 8 deletions spec-files/guide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ root: # Required.
disallowInsert: [navigationProperty] # Optional
# Singleton
- name: Singleton # Required.
type: EntityType # Required.
type: ChildType # Required.
# Operation
- name: QueryFunction # Required.
params: # Optional
- name: userId # Required.
type: int32 # Optional. Default string.
type: integer # Optional. Default string.
returns: EntityType[] # Required.
- name: ExecuteAction
params: # Optional
Expand All @@ -58,17 +58,16 @@ types: # Required.
- name: enum2
value: 2 # Optional
# Complex type
- name: BaseType
- name: ComplexType
requiredProperties: # Optional
- name: price # Required.
type: decimal # Optional
isoCurrency: USD # Optional. The currency for this monetary amount as an ISO 4217 currency code
immutable: true # Optional. A value for this non-key property can be provided on insert and remains unchanged on update
- name: requiredProperty # Required.
type: string # Optional
optionalProperties: # Optional
- name: optionalProperty # Required. Default string type
# Entity type
- name: EntityType # Required.
key: # Required.
- name: id # Optional
baseType: BaseType # Optional
dynamic: true # Optional. dynamic type allows clients to add properties dynamically to instances of the type by specifying uniquely named values in the payload used to insert or update an instance of the type.
requiredProperties: # Optional
- name: name # Required.
Expand All @@ -84,6 +83,8 @@ types: # Required.
- name: navigationProperty # Required.
type: AnotherEntityType # Optional
containsTarget: true # Optional. Containment navigation properties define an implicit entity set for each instance of its declaring entity type. This implicit entity set is identified by the read URL of the navigation property for that entity.
- name: complexTypeProperty # Required.
type: ComplexType # Required
operations: # Optional
- name: BoundOperation # Required.
params: # Optional
Expand All @@ -103,3 +104,10 @@ types: # Required.
- name: parameterName # Required.
type: string # Optional
returns: AnotherEntityType # Optional
- name: ChildType
baseType: EntityType # Optional
requiredProperties: # Optional
- name: price # Required.
type: decimal # Optional
isoCurrency: USD # Optional. The currency for this monetary amount as an ISO 4217 currency code
immutable: true # Optional. A value for this non-key property can be provided on insert and remains unchanged on update
12 changes: 12 additions & 0 deletions templates/cross-origin-prompt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="modal-header">
<h3 class="modal-title">Prompt</h3>
</div>
<div class="modal-body">
<div class="form-group">
<label>We will send a document, which includes the data you input, to http://generator.swagger.io to generate codes. <br><br>Do you want to proceed?</label>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
<button class="btn btn-primary" ng-click="ok()">OK</button>
</div>

0 comments on commit 06cfae6

Please sign in to comment.