1
0
mirror of https://github.com/bingohuang/docker-labs.git synced 2025-07-14 18:27:25 +08:00

Add .editorconfig file for consistent styling (#76)

This should take effect when editors with [EditorConfig](http://editorconfig.org/) support are used.

Signed-off-by: Antonis Kalipetis <akalipetis@gmail.com>
This commit is contained in:
Antonis Kalipetis 2017-01-03 19:47:04 +02:00 committed by Marcos Nils
parent 1af2b3665f
commit fd52a544d1
2 changed files with 123 additions and 109 deletions

14
.editorconfig Normal file
View File

@ -0,0 +1,14 @@
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
# Tab indentation (no size specified)
[{Makefile,*.go}]
indent_style = tab

View File

@ -1,7 +1,7 @@
(function () { (function() {
'use strict'; 'use strict';
var app = angular.module('DockerPlay', ['ngMaterial']); var app = angular.module('DockerPlay', ['ngMaterial']);
// Automatically redirects user to a new session when bypassing captcha. // Automatically redirects user to a new session when bypassing captcha.
// Controller keeps code/logic separate from the HTML // Controller keeps code/logic separate from the HTML
@ -12,42 +12,42 @@
}, 500); }, 500);
}]); }]);
app.controller('PlayController', ['$scope', '$log', '$http', '$location', '$timeout', '$mdDialog', '$window', function($scope, $log, $http, $location, $timeout, $mdDialog, $window) { app.controller('PlayController', ['$scope', '$log', '$http', '$location', '$timeout', '$mdDialog', '$window', function($scope, $log, $http, $location, $timeout, $mdDialog, $window) {
$scope.sessionId = window.location.pathname.replace('/p/', ''); $scope.sessionId = window.location.pathname.replace('/p/', '');
$scope.instances = []; $scope.instances = [];
$scope.idx = {}; $scope.idx = {};
$scope.selectedInstance = null; $scope.selectedInstance = null;
$scope.isAlive = true; $scope.isAlive = true;
$scope.ttl = '--:--:--'; $scope.ttl = '--:--:--';
$scope.connected = true; $scope.connected = true;
angular.element($window).bind('resize', function(){ angular.element($window).bind('resize', function() {
if ($scope.selectedInstance) { if ($scope.selectedInstance) {
$scope.resize($scope.selectedInstance.term.proposeGeometry()); $scope.resize($scope.selectedInstance.term.proposeGeometry());
}
});
$scope.showAlert = function(title, content, parent) {
$mdDialog.show(
$mdDialog.alert()
.parent(angular.element(document.querySelector(parent || '#popupContainer')))
.clickOutsideToClose(true)
.title(title)
.textContent(content)
.ok('Got it!')
);
} }
});
$scope.resize = function(geometry) {
$scope.socket.emit('viewport resize', geometry.cols, geometry.rows);
}
$scope.showAlert = function(title, content, parent) { $scope.closeSession = function() {
$mdDialog.show( $scope.socket.emit('session close');
$mdDialog.alert() }
.parent(angular.element(document.querySelector(parent || '#popupContainer')))
.clickOutsideToClose(true)
.title(title)
.textContent(content)
.ok('Got it!')
);
}
$scope.resize = function(geometry) { $scope.upsertInstance = function(info) {
$scope.socket.emit('viewport resize', geometry.cols, geometry.rows);
}
$scope.closeSession = function() {
$scope.socket.emit('session close');
}
$scope.upsertInstance = function(info) {
var i = info; var i = info;
if (!$scope.idx[i.name]) { if (!$scope.idx[i.name]) {
$scope.instances.push(i); $scope.instances.push(i);
@ -59,27 +59,27 @@
} }
return $scope.idx[i.name]; return $scope.idx[i.name];
} }
$scope.newInstance = function() { $scope.newInstance = function() {
$http({ $http({
method: 'POST', method: 'POST',
url: '/sessions/' + $scope.sessionId + '/instances', url: '/sessions/' + $scope.sessionId + '/instances',
}).then(function(response) { }).then(function(response) {
var i = $scope.upsertInstance(response.data); var i = $scope.upsertInstance(response.data);
$scope.showInstance(i); $scope.showInstance(i);
}, function(response) { }, function(response) {
if (response.status == 409) { if (response.status == 409) {
$scope.showAlert('Max instances reached', 'Maximum number of instances reached') $scope.showAlert('Max instances reached', 'Maximum number of instances reached')
} }
}); });
} }
$scope.getSession = function(sessionId) { $scope.getSession = function(sessionId) {
$http({ $http({
method: 'GET', method: 'GET',
url: '/sessions/' + $scope.sessionId, url: '/sessions/' + $scope.sessionId,
}).then(function(response) { }).then(function(response) {
if (response.data.created_at) { if (response.data.created_at) {
$scope.expiresAt = moment(response.data.expires_at); $scope.expiresAt = moment(response.data.expires_at);
setInterval(function() { setInterval(function() {
@ -87,14 +87,14 @@
$scope.$apply(); $scope.$apply();
}, 1000); }, 1000);
} }
var socket = io({path: '/sessions/' + sessionId + '/ws'}); var socket = io({ path: '/sessions/' + sessionId + '/ws' });
socket.on('terminal out', function(name, data) { socket.on('terminal out', function(name, data) {
var instance = $scope.idx[name]; var instance = $scope.idx[name];
if (!instance) { if (!instance) {
// instance is new and was created from another client, we should add it // instance is new and was created from another client, we should add it
$scope.upsertInstance({name: name}); $scope.upsertInstance({ name: name });
instance = $scope.idx[name]; instance = $scope.idx[name];
} }
if (!instance.term) { if (!instance.term) {
@ -105,7 +105,7 @@
}); });
socket.on('session end', function() { socket.on('session end', function() {
$scope.showAlert('Session timed out!', 'Your session has expired and all of your instances have been deleted.', '#sessionEnd') $scope.showAlert('Session timed out!', 'Your session has expired and all of your instances have been deleted.', '#sessionEnd')
$scope.isAlive = false; $scope.isAlive = false;
}); });
@ -113,7 +113,7 @@
}); });
socket.on('new instance', function(name, ip, hostname) { socket.on('new instance', function(name, ip, hostname) {
$scope.upsertInstance({name: name, ip: ip, hostname: hostname}); $scope.upsertInstance({ name: name, ip: ip, hostname: hostname });
$scope.$apply(function() { $scope.$apply(function() {
if ($scope.instances.length == 1) { if ($scope.instances.length == 1) {
$scope.showInstance($scope.instances[0]); $scope.showInstance($scope.instances[0]);
@ -151,22 +151,22 @@
$scope.socket = socket; $scope.socket = socket;
var i = response.data; var i = response.data;
for (var k in i.instances) { for (var k in i.instances) {
var instance = i.instances[k]; var instance = i.instances[k];
$scope.instances.push(instance); $scope.instances.push(instance);
$scope.idx[instance.name] = instance; $scope.idx[instance.name] = instance;
} }
if ($scope.instances.length) { if ($scope.instances.length) {
$scope.showInstance($scope.instances[0]); $scope.showInstance($scope.instances[0]);
} }
}, function(response) { }, function(response) {
if (response.status == 404) { if (response.status == 404) {
document.write('session not found'); document.write('session not found');
return return
} }
}); });
} }
$scope.getProxyUrl = function(instance, port) { $scope.getProxyUrl = function(instance, port) {
var url = window.location.protocol + '//ip' + instance.ip.replace(/\./g, '_') + '-' + port + '.' + window.location.host; var url = window.location.protocol + '//ip' + instance.ip.replace(/\./g, '_') + '-' + port + '.' + window.location.host;
@ -202,63 +202,63 @@
} }
} }
$scope.deleteInstance = function(instance) { $scope.deleteInstance = function(instance) {
$http({ $http({
method: 'DELETE', method: 'DELETE',
url: '/sessions/' + $scope.sessionId + '/instances/' + instance.name, url: '/sessions/' + $scope.sessionId + '/instances/' + instance.name,
}).then(function(response) { }).then(function(response) {
$scope.removeInstance(instance.name); $scope.removeInstance(instance.name);
}, function(response) { }, function(response) {
console.log('error', response); console.log('error', response);
}); });
} }
$scope.getSession($scope.sessionId); $scope.getSession($scope.sessionId);
function createTerminal(instance, cb) { function createTerminal(instance, cb) {
if (instance.term) { if (instance.term) {
return instance.term; return instance.term;
}
var terminalContainer = document.getElementById('terminal-'+ instance.name);
var term = new Terminal({
cursorBlink: false
});
term.attachCustomKeydownHandler(function (e) {
// Ctrl + Alt + C
if (e.ctrlKey && e.altKey && (e.keyCode == 67)) {
document.execCommand('copy');
return false;
} }
});
term.open(terminalContainer); var terminalContainer = document.getElementById('terminal-' + instance.name);
// Set geometry during the next tick, to avoid race conditions. var term = new Terminal({
setTimeout(function() { cursorBlink: false
$scope.resize(term.proposeGeometry()); });
}, 4);
term.on('data', function(d) { term.attachCustomKeydownHandler(function(e) {
$scope.socket.emit('terminal in', instance.name, d); // Ctrl + Alt + C
}); if (e.ctrlKey && e.altKey && (e.keyCode == 67)) {
document.execCommand('copy');
return false;
}
});
instance.term = term; term.open(terminalContainer);
if (instance.buffer) { // Set geometry during the next tick, to avoid race conditions.
term.write(instance.buffer); setTimeout(function() {
instance.buffer = ''; $scope.resize(term.proposeGeometry());
} }, 4);
if (cb) { term.on('data', function(d) {
cb(); $scope.socket.emit('terminal in', instance.name, d);
} });
instance.term = term;
if (instance.buffer) {
term.write(instance.buffer);
instance.buffer = '';
}
if (cb) {
cb();
}
} }
}]) }])
.config(['$mdIconProvider', function($mdIconProvider) { .config(['$mdIconProvider', function($mdIconProvider) {
$mdIconProvider.defaultIconSet('../assets/social-icons.svg', 24); $mdIconProvider.defaultIconSet('../assets/social-icons.svg', 24);
}]); }]);
})(); })();