Skip to content

Commit

Permalink
fix jslint problems and added config
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Dresser committed Jul 22, 2016
1 parent 23c4f76 commit bd509ff
Show file tree
Hide file tree
Showing 15 changed files with 553 additions and 603 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@
}
},
"scripts": {
"compile": "node ./node_modules/vscode/bin/compile -p ./",
"compile": "npm run lint && node ./node_modules/vscode/bin/compile -p ./",
"compile_watch": "node ./node_modules/vscode/bin/compile -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
"postinstall": "node ./node_modules/vscode/bin/install",
"lint": "tslint src/**/*.ts"
}
}
56 changes: 22 additions & 34 deletions src/controllers/connectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@
import vscode = require('vscode');
import Constants = require('../models/constants');
import Utils = require('../models/utils');
import { RecentConnections } from '../models/recentConnections';
import Interfaces = require('../models/interfaces');
import { ConnectionUI } from '../views/connectionUI'
import { ConnectionUI } from '../views/connectionUI';
import StatusView from '../views/statusView';

var mssql = require('mssql');
const mssql = require('mssql');

export default class ConnectionManager
{
export default class ConnectionManager {
private _context: vscode.ExtensionContext;
private _statusView: StatusView;
private _connection;
private _connectionCreds: Interfaces.IConnectionCredentials;
private _connectionUI: ConnectionUI;

constructor(context: vscode.ExtensionContext, statusView: StatusView)
{
constructor(context: vscode.ExtensionContext, statusView: StatusView) {
this._context = context;
this._statusView = statusView;
this._connectionUI = new ConnectionUI();
Expand All @@ -32,51 +29,44 @@ export default class ConnectionManager
return this._connection;
}

private get connectionUI() {
private get connectionUI(): ConnectionUI {
return this._connectionUI;
}

private get statusView() {
private get statusView(): StatusView {
return this._statusView;
}

get isConnected() {
get isConnected(): boolean {
return this._connection && this._connection.connected;
}

// close active connection, if any
public onDisconnect()
{
return new Promise<any>((resolve, reject) =>
{
if(this.isConnected) {
public onDisconnect(): Promise<any> {
return new Promise<any>((resolve, reject) => {
if (this.isConnected) {
this._connection.close();
}

this._connection = null;
this._connectionCreds = null;
this._connection = undefined;
this._connectionCreds = undefined;
this.statusView.notConnected();
resolve(true);
});
}

// let users pick from a picklist of connections
public onNewConnection()
{
public onNewConnection(): Promise<boolean> {
const self = this;
return new Promise<boolean>((resolve, reject) =>
{
return new Promise<boolean>((resolve, reject) => {
// show connection picklist
self.connectionUI.showConnections()
.then(function(connectionCreds)
{
.then(function(connectionCreds): void {
// close active connection
self.onDisconnect().then(function()
{
self.onDisconnect().then(function(): void {
// connect to the server/database
self.connect(connectionCreds)
.then(function()
{
.then(function(): void {
resolve(true);
});
});
Expand All @@ -85,25 +75,23 @@ export default class ConnectionManager
}

// create a new connection with the connectionCreds provided
public connect(connectionCreds: Interfaces.IConnectionCredentials)
{
public connect(connectionCreds: Interfaces.IConnectionCredentials): Promise<any> {
const self = this;
return new Promise<any>((resolve, reject) =>
{
return new Promise<any>((resolve, reject) => {
const connection = new mssql.Connection(connectionCreds);
self.statusView.connecting(connectionCreds);
connection.connect()
.then(function() {
.then(function(): void {
self._connectionCreds = connectionCreds;
self._connection = connection;
self.statusView.connectSuccess(connectionCreds);
resolve();
})
.catch(function(err) {
.catch(function(err): void {
self.statusView.connectError(connectionCreds, err);
Utils.showErrorMsg(Constants.gMsgError + err);
reject(err);
});
});
}
}
}
33 changes: 11 additions & 22 deletions src/controllers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,28 @@ export default class MainController implements vscode.Disposable {
private _statusview: StatusView;
private _connectionMgr: ConnectionManager;

constructor(context: vscode.ExtensionContext)
{
constructor(context: vscode.ExtensionContext) {
this._context = context;
}

private registerCommand(command: string)
{
private registerCommand(command: string): void {
const self = this;
this._context.subscriptions.push(vscode.commands.registerCommand(command, () => {
self._event.emit(command);
}));
}

dispose()
{
dispose(): void {
this.deactivate();
}

public deactivate()
{
public deactivate(): void {
Utils.logDebug(Constants.gExtensionDeactivated);
this.onDisconnect();
this._statusview.dispose();
}

public activate()
{
public activate(): void {
const self = this;

// register VS Code commands
Expand All @@ -68,29 +63,23 @@ export default class MainController implements vscode.Disposable {
}

// Close active connection, if any
private onDisconnect()
{
private onDisconnect(): Promise<any> {
return this._connectionMgr.onDisconnect();
}

// Let users pick from a list of connections
public onNewConnection()
{
public onNewConnection(): Promise<boolean> {
return this._connectionMgr.onNewConnection();
}

// get the T-SQL query from the editor, run it and show output
public onRunQuery()
{
if(!Utils.isEditingSqlFile())
{
public onRunQuery(): void {
if (!Utils.isEditingSqlFile()) {
Utils.showWarnMsg(Constants.gMsgOpenSqlFile);
}
else
{
} else {
const self = this;
let qr = new QueryRunner(self._connectionMgr, self._statusview, self._outputContentProvider);
qr.onRunQuery();
}
}
}
}
26 changes: 10 additions & 16 deletions src/controllers/localWebService.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
'use strict';
import vscode = require('vscode');
import path = require('path');
import fs = require('fs');
import Utils = require('../models/utils');
import Constants = require('../models/constants');
import Interfaces = require('../models/interfaces');
var express = require('express');
const express = require('express');

export default class LocalWebService
{
export default class LocalWebService {
private app = express();
static _servicePort: string;
static _vscodeExtensionPath: string;
static _htmlContentLocation = "src/views/htmlcontent";
static _htmlContentLocation = 'src/views/htmlcontent';
static _staticContentPath: string;

constructor(extensionPath: string)
{
constructor(extensionPath: string) {
// add static content for express web server to serve
LocalWebService._vscodeExtensionPath = extensionPath;
LocalWebService._staticContentPath = path.join(extensionPath, LocalWebService._htmlContentLocation);
Expand All @@ -37,20 +33,18 @@ export default class LocalWebService
return LocalWebService._vscodeExtensionPath;
}

static getEndpointUri(type: Interfaces.ContentType): string
{
return this.serviceUrl + "/" + Interfaces.ContentTypes[type];
static getEndpointUri(type: Interfaces.ContentType): string {
return this.serviceUrl + '/' + Interfaces.ContentTypes[type];
}

addHandler(type: Interfaces.ContentType, handler: (req, res) => void) {
let segment = "/" + Interfaces.ContentTypes[type];
addHandler(type: Interfaces.ContentType, handler: (req, res) => void): void {
let segment = '/' + Interfaces.ContentTypes[type];
this.app.get(segment, handler);
}

start()
{
start(): void {
const port = this.app.listen(0).address().port; // 0 = listen on a random port
Utils.logDebug(Constants.gMsgLocalWebserviceStarted + port);
LocalWebService._servicePort = port.toString();
}
}
}
Loading

0 comments on commit bd509ff

Please sign in to comment.