Skip to content

Commit

Permalink
fix all errors in test/
Browse files Browse the repository at this point in the history
  • Loading branch information
saharj committed Mar 31, 2016
1 parent c3f5258 commit a710723
Show file tree
Hide file tree
Showing 20 changed files with 192 additions and 210 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
module.exports = {
extends: 'google'
extends: 'google',
globals: {
SwaggerEditor: false
},
env: {
browser: true
}
};
8 changes: 0 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@
"worker-loader": "^0.7.0",
"yaml-js": "^0.1.3"
},
"eslintConfig": {
"globals": {
"window": true
},
"env": {
"browser": true
}
},
"engines": {
"node": ">=5.8.0"
},
Expand Down
104 changes: 51 additions & 53 deletions scripts/controllers/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal,
$stateParams, $state, $rootScope, Storage, Builder, FileLoader, Editor,
Codegen, Preferences, YAML, defaults, strings, $localStorage) {

if ($stateParams.path) {
$scope.breadcrumbs = [{ active: true, name: $stateParams.path }];
$scope.breadcrumbs = [{active: true, name: $stateParams.path}];
} else {
$scope.breadcrumbs = [];
$scope.breadcrumbs = [];
}

// var statusTimeout;
$rootScope.$watch('progressStatus', function (progressStatus) {
$rootScope.$watch('progressStatus', function(progressStatus) {
var status = strings.stausMessages[progressStatus];
var statusClass = null;

Expand Down Expand Up @@ -41,20 +40,20 @@ SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal,
$scope.disableCodeGen = defaults.disableCodeGen;

if (!defaults.disableCodeGen) {
Codegen.getServers().then(function (servers) {
Codegen.getServers().then(function(servers) {
$scope.servers = servers;
}, function () {
}, function() {
$scope.serversNotAvailable = true;
});

Codegen.getClients().then(function (clients) {
Codegen.getClients().then(function(clients) {
$scope.clients = clients;
}, function () {
}, function() {
$scope.clientsNotAvailable = true;
});
}

$scope.getSDK = function (type, language) {
$scope.getSDK = function(type, language) {
Codegen.getSDK(type, language).then(noop, showCodegenError);
};

Expand All @@ -64,7 +63,7 @@ SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal,
controller: 'GeneralModal',
size: 'large',
resolve: {
data: function () {
data: function() {
if (resp.data) {
return resp.data;
}
Expand All @@ -75,60 +74,60 @@ SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal,
});
}

$scope.showFileMenu = function () {
$scope.showFileMenu = function() {
return !defaults.disableFileMenu;
};

$scope.showHeaderBranding = function () {
$scope.showHeaderBranding = function() {
return defaults.headerBranding;
};

$scope.newProject = function () {
FileLoader.loadFromUrl('spec-files/guide.yaml').then(function (value) {
$scope.newProject = function() {
FileLoader.loadFromUrl('spec-files/guide.yaml').then(function(value) {
$rootScope.editorValue = value;
Storage.save('yaml', value);
$state.go('home', {tags: null});
});
};

$scope.onFileMenuOpen = function () {
$scope.onFileMenuOpen = function() {
assignDownloadHrefs();
$rootScope.$broadcast('toggleWatchers', false);
};

$scope.openImportFile = function () {
$scope.openImportFile = function() {
$uibModal.open({
templateUrl: 'templates/file-import.html',
controller: 'FileImportCtrl',
size: 'large'
});
};

$scope.openImportUrl = function () {
$scope.openImportUrl = function() {
$uibModal.open({
templateUrl: 'templates/url-import.html',
controller: 'UrlImportCtrl',
size: 'large'
});
};

$scope.openPasteJSON = function () {
$scope.openPasteJSON = function() {
$uibModal.open({
templateUrl: 'templates/paste-json.html',
controller: 'PasteJSONCtrl',
size: 'large'
});
};

$scope.openAbout = function () {
$scope.openAbout = function() {
$uibModal.open({
templateUrl: 'templates/about.html',
size: 'large',
controller: 'ModalCtrl'
});
};

$rootScope.toggleAboutEditor = function (value) {
$rootScope.toggleAboutEditor = function(value) {
$rootScope.showAbout = value;
$localStorage.showIntro = value;
};
Expand All @@ -137,32 +136,31 @@ SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal,
$scope.resetSettings = Editor.resetSettings;
$scope.adjustFontSize = Editor.adjustFontSize;

$scope.openExamples = function () {
$scope.openExamples = function() {
$uibModal.open({
templateUrl: 'templates/open-examples.html',
controller: 'OpenExamplesCtrl',
size: 'large'
});
};

$scope.openPreferences = function () {
$scope.openPreferences = function() {
$uibModal.open({
templateUrl: 'templates/preferences.html',
controller: 'PreferencesCtrl',
size: 'large'
});
};

$scope.isLiveRenderEnabled = function () {
return !!Preferences.get('liveRender');
$scope.isLiveRenderEnabled = function() {
return Boolean(Preferences).get('liveRender');
};

function assignDownloadHrefs() {
var MIME_TYPE = 'text/plain';

var yaml = $rootScope.editorValue;
YAML.load(yaml, function (error, json) {

YAML.load(yaml, function(error, json) {
// Don't assign if there is an error
if (error) {
return;
Expand All @@ -176,15 +174,7 @@ SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal,
jsonParseError = error;
}

if (!jsonParseError) {
YAML.dump(json, function (error, yamlStr) {
assign(yamlStr, json);
});
} else {
assign(yaml, json);
}

function assign(yaml, json) {
var assign = function (yaml, json) {
// swagger and version should be a string to comfort with the schema
if (json.info.version) {
json.info.version = String(json.info.version);
Expand Down Expand Up @@ -214,39 +204,47 @@ SwaggerEditor.controller('HeaderCtrl', function HeaderCtrl($scope, $uibModal,
'swagger.yaml',
$scope.yamlDownloadHref
].join(':');
};

if (jsonParseError) {
assign(yaml, json);
} else {
YAML.dump(json, function(error, yamlStr) {
assign(yamlStr, json);
});
}
});
}

$scope.capitalizeGeneratorName = function (name) {
$scope.capitalizeGeneratorName = function(name) {
var names = {
jaxrs: 'JAX-RS',
nodejs: 'Node.js',
scalatra: 'Scalatra',
'jaxrs': 'JAX-RS',
'nodejs': 'Node.js',
'scalatra': 'Scalatra',
'spring-mvc': 'Spring MVC',
android: 'Android',
'android': 'Android',
'async-scala': 'Async Scala',
csharp: 'C#',
CsharpDotNet2: 'C# .NET 2.0',
qt5cpp: 'Qt 5 C++',
java: 'Java',
objc: 'Objective-C',
php: 'PHP',
python: 'Python',
ruby: 'Ruby',
scala: 'Scala',
'csharp': 'C#',
'CsharpDotNet2': 'C# .NET 2.0',
'qt5cpp': 'Qt 5 C++',
'java': 'Java',
'objc': 'Objective-C',
'php': 'PHP',
'python': 'Python',
'ruby': 'Ruby',
'scala': 'Scala',
'dynamic-html': 'Dynamic HTML',
html: 'HTML',
swagger: 'Swagger JSON',
'html': 'HTML',
'swagger': 'Swagger JSON',
'swagger-yaml': 'Swagger YAML',
tizen: 'Tizen'
'tizen': 'Tizen'
};

if (names[name]) {
return names[name];
}

return name.split(/\s+|\-/).map(function (word) {
return name.split(/\s+|\-/).map(function(word) {
return word[0].toUpperCase() + word.substr(1);
}).join(' ');
};
Expand Down
16 changes: 9 additions & 7 deletions scripts/controllers/import-file.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
'use strict';

var angular = require("angular");

SwaggerEditor.controller('FileImportCtrl', function FileImportCtrl($scope,
$uibModalInstance, $rootScope, $localStorage, $state, FileLoader, Storage) {
var results;

$scope.fileChanged = function ($fileContent) {
FileLoader.load($fileContent).then(function (res) {
$scope.$apply(function () {
$scope.fileChanged = function($fileContent) {
FileLoader.load($fileContent).then(function(res) {
$scope.$apply(function() {
results = res;
});
});
};

$scope.ok = function () {
$scope.ok = function() {
if (angular.isString(results)) {
$rootScope.editorValue = results;
Storage.save('yaml', results);
Expand All @@ -21,12 +23,12 @@ SwaggerEditor.controller('FileImportCtrl', function FileImportCtrl($scope,
$uibModalInstance.close();
};

$scope.isInvalidFile = function () {
$scope.isInvalidFile = function() {
return results === null;
};

$scope.isFileSelected = function () {
return !!results;
$scope.isFileSelected = function() {
return Boolean(results);
};

$scope.cancel = $uibModalInstance.close;
Expand Down
12 changes: 7 additions & 5 deletions scripts/controllers/importurl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var angular = require('angular');

SwaggerEditor.controller('UrlImportCtrl', function FileImportCtrl($scope,
$uibModalInstance, $localStorage, $rootScope, $state, FileLoader, Storage) {
var results;
Expand All @@ -16,14 +18,14 @@ SwaggerEditor.controller('UrlImportCtrl', function FileImportCtrl($scope,

if (_.startsWith(url, 'http')) {
$scope.fetching = true;
FileLoader.loadFromUrl(url, !$scope.opts.useProxy).then(function (data) {
$scope.$apply(function () {
FileLoader.loadFromUrl(url, !$scope.opts.useProxy).then(function(data) {
$scope.$apply(function() {
results = data;
$scope.canImport = true;
$scope.fetching = false;
});
}).catch(function (error) {
$scope.$apply(function () {
}).catch(function(error) {
$scope.$apply(function() {
$scope.error = error;
$scope.canImport = false;
$scope.fetching = false;
Expand All @@ -36,7 +38,7 @@ SwaggerEditor.controller('UrlImportCtrl', function FileImportCtrl($scope,

$scope.fetch = _.throttle(fetch, 200);

$scope.ok = function () {
$scope.ok = function() {
if (angular.isString(results)) {
Storage.save('yaml', results);
$rootScope.editorValue = results;
Expand Down
Loading

0 comments on commit a710723

Please sign in to comment.