2013-10-19 06:32:00 +00:00
|
|
|
controllers = angular.module("controllers", []);
|
2013-08-16 18:32:58 +00:00
|
|
|
|
2013-10-19 06:32:00 +00:00
|
|
|
controllers.controller("main", function($scope, $location) {
|
2013-08-16 18:32:58 +00:00
|
|
|
$scope.currentTab = "colors";
|
2013-09-07 18:52:43 +00:00
|
|
|
|
2013-08-16 18:32:58 +00:00
|
|
|
$scope.changeView = function(view) {
|
|
|
|
$location.path(view);
|
|
|
|
$scope.currentTab = view;
|
|
|
|
}
|
2013-10-19 18:24:51 +00:00
|
|
|
|
2013-08-16 18:32:58 +00:00
|
|
|
})
|
|
|
|
|
2013-10-19 06:32:00 +00:00
|
|
|
controllers.controller("colorsController", function($scope, $http) {
|
2013-10-12 18:25:37 +00:00
|
|
|
$scope.changeSelectedColorScheme= function(newScheme) {
|
|
|
|
$scope.selectedColorScheme = newScheme;
|
|
|
|
if ($scope.selectedColorScheme.preferred_background) {
|
|
|
|
$scope.terminalBackgroundColor = $scope.selectedColorScheme.preferred_background;
|
|
|
|
}
|
|
|
|
$scope.selectedColorSetting = 'command';
|
|
|
|
$scope.colorArraysArray = $scope.getColorArraysArray();
|
|
|
|
//TODO: Save button should be shown only when colors are changed
|
|
|
|
$scope.showSaveButton = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.changeTerminalBackgroundColor = function(color) {
|
|
|
|
$scope.terminalBackgroundColor = color;
|
|
|
|
}
|
|
|
|
|
2013-10-12 17:48:52 +00:00
|
|
|
$scope.getColorArraysArray = function() {
|
|
|
|
var result = null;
|
2013-10-20 08:58:40 +00:00
|
|
|
if ( $scope.selectedColorScheme.colors && $scope.selectedColorScheme.colors.length > 0)
|
2013-10-12 17:48:52 +00:00
|
|
|
result = get_colors_as_nested_array($scope.selectedColorScheme.colors, 32);
|
|
|
|
else
|
2013-10-19 18:24:51 +00:00
|
|
|
result = get_colors_as_nested_array(term_256_colors, 32);
|
2013-10-12 17:48:52 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.selectColorSetting = function(name) {
|
|
|
|
$scope.selectedColorSetting = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.changeSelectedTextColor = function(color) {
|
|
|
|
$scope.selectedColorScheme[$scope.selectedColorSetting] = color;
|
|
|
|
}
|
2013-10-02 13:40:40 +00:00
|
|
|
|
2013-10-12 17:48:52 +00:00
|
|
|
$scope.sampleTerminalBackgroundColors = ['white', '#' + solarized.base3, '#300', '#003', '#' + solarized.base03, '#232323', 'black'];
|
|
|
|
|
2013-10-02 13:40:40 +00:00
|
|
|
/* Array of FishColorSchemes */
|
2013-10-19 18:24:51 +00:00
|
|
|
$scope.colorSchemes = [color_scheme_fish_default, color_scheme_solarized_light, color_scheme_solarized_dark, color_scheme_tomorrow, color_scheme_tomorrow_night, color_scheme_tomorrow_night_bright];
|
2013-10-02 13:40:40 +00:00
|
|
|
for (var i=0; i < additional_color_schemes.length; i++)
|
2013-10-19 18:24:51 +00:00
|
|
|
$scope.colorSchemes.push(additional_color_schemes[i])
|
2013-10-02 13:40:40 +00:00
|
|
|
|
2013-10-20 08:58:40 +00:00
|
|
|
|
|
|
|
$scope.getCurrentTheme = function() {
|
|
|
|
$http.get("/colors/").success(function(data, status, headers, config) {
|
|
|
|
var currentScheme = { "name": "Current", "colors":[], "preferred_background": "" };
|
|
|
|
for (var i in data) {
|
|
|
|
currentScheme[data[i].name] = data[i].color;
|
|
|
|
}
|
|
|
|
$scope.colorSchemes.splice(0, 0, currentScheme);
|
|
|
|
$scope.changeSelectedColorScheme(currentScheme);
|
|
|
|
})};
|
2013-10-13 08:20:21 +00:00
|
|
|
|
2013-10-12 18:25:37 +00:00
|
|
|
$scope.setTheme = function() {
|
2013-10-13 08:20:21 +00:00
|
|
|
var settingNames = ["autosuggestion", "command", "param", "redirection", "comment", "error", "quote", "end"];
|
2013-10-12 18:25:37 +00:00
|
|
|
for (name in settingNames) {
|
|
|
|
var postData = "what=" + settingNames[name] + "&color=" + $scope.selectedColorScheme[settingNames[name]] + "&background_color=&bold=&underline=";
|
|
|
|
$http.post("/set_color/", postData, { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).success(function(data, status, headers, config) {
|
|
|
|
console.log(data);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
};
|
2013-10-20 08:58:40 +00:00
|
|
|
|
|
|
|
$scope.getCurrentTheme();
|
2013-10-02 13:40:40 +00:00
|
|
|
});
|
2013-08-16 18:32:58 +00:00
|
|
|
|
2013-10-19 06:32:00 +00:00
|
|
|
controllers.controller("promptController", function($scope, $http) {
|
2013-08-16 18:32:58 +00:00
|
|
|
$scope.selectedPrompt = null;
|
2013-09-07 18:52:43 +00:00
|
|
|
|
2013-08-18 14:18:32 +00:00
|
|
|
$scope.fetchCurrentPrompt = function(currenttPrompt) {
|
2013-08-16 18:32:58 +00:00
|
|
|
$http.get("/current_prompt/").success(function(data, status, headers, config) {
|
2013-08-18 14:18:32 +00:00
|
|
|
currenttPrompt.function = data.function;
|
2013-08-16 18:32:58 +00:00
|
|
|
})};
|
|
|
|
|
|
|
|
$scope.fetchSamplePrompts= function() {
|
|
|
|
$http.get("/sample_prompts/").success(function(data, status, headers, config) {
|
|
|
|
$scope.samplePrompts = data;
|
|
|
|
if ($scope.selectedPrompt == null) {
|
|
|
|
$scope.selectPrompt($scope.samplePrompts[0]);
|
|
|
|
}
|
|
|
|
})};
|
2013-09-07 18:52:43 +00:00
|
|
|
|
2013-08-18 14:18:32 +00:00
|
|
|
$scope.fetchSamplePrompt = function(selectedPrompt) {
|
|
|
|
console.log("Fetcing sample prompt");
|
|
|
|
$http.post("/get_sample_prompt/","what=" + encodeURIComponent(selectedPrompt.function), { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).success(function(data, status, headers, config) {
|
|
|
|
console.log("Data is " + JSON.stringify(data[0]));
|
|
|
|
$scope.demoText= data[0].demo;
|
|
|
|
$scope.demoTextFontSize = data[0].font_size;
|
|
|
|
console.log("Demo text is " + $scope.demoText);
|
|
|
|
})};
|
2013-08-16 18:32:58 +00:00
|
|
|
|
|
|
|
$scope.selectPrompt = function(promptt) {
|
|
|
|
$scope.selectedPrompt= promptt;
|
|
|
|
if ($scope.selectedPrompt.name == "Current") {
|
|
|
|
$scope.fetchCurrentPrompt($scope.selectedPrompt);
|
|
|
|
}
|
2013-08-18 14:18:32 +00:00
|
|
|
$scope.fetchSamplePrompt($scope.selectedPrompt);
|
2013-08-16 18:32:58 +00:00
|
|
|
}
|
|
|
|
|
2013-08-18 14:18:32 +00:00
|
|
|
$scope.setNewPrompt = function(selectedPrompt) {
|
|
|
|
console.log("Set new prompt" + selectedPrompt);
|
|
|
|
$http.post("/set_prompt/","what=" + encodeURIComponent(selectedPrompt.function), { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).success(function(data, status, headers, config){
|
|
|
|
console.log("Data is " + JSON.stringify(data));
|
|
|
|
})};
|
2013-09-07 18:52:43 +00:00
|
|
|
|
2013-08-16 18:32:58 +00:00
|
|
|
$scope.fetchSamplePrompts();
|
|
|
|
});
|
|
|
|
|
2013-10-19 06:32:00 +00:00
|
|
|
controllers.controller("functionsController", function($scope, $http) {
|
2013-08-16 18:32:58 +00:00
|
|
|
$scope.selectedFunction = null;
|
|
|
|
$scope.functionDefinition = "";
|
|
|
|
|
|
|
|
$scope.selectFunction = function(fun) {
|
|
|
|
$scope.selectedFunction = fun;
|
|
|
|
$scope.fetchFunctionDefinition($scope.selectedFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.fetchFunctions= function() {
|
|
|
|
$http.get("/functions/").success(function(data, status, headers, config) {
|
|
|
|
$scope.functions = data;
|
|
|
|
$scope.selectFunction($scope.functions[0]);
|
|
|
|
})};
|
|
|
|
|
2013-09-07 17:27:25 +00:00
|
|
|
$scope.cleanupFishFunction = function (contents) {
|
|
|
|
/* Replace leading tabs and groups of four spaces at the beginning of a line with two spaces. */
|
|
|
|
lines = contents.split('\n')
|
|
|
|
rx = /^[\t ]+/
|
|
|
|
for (var i=0; i < lines.length; i++) {
|
|
|
|
line = lines[i]
|
|
|
|
/* Get leading tabs and spaces */
|
|
|
|
whitespace_arr = rx.exec(line)
|
|
|
|
if (whitespace_arr) {
|
|
|
|
/* Replace four spaces with two spaces, and tabs with two spaces */
|
|
|
|
var whitespace = whitespace_arr[0]
|
|
|
|
new_whitespace = whitespace.replace(/( )|(\t)/g, ' ')
|
|
|
|
lines[i] = new_whitespace + line.slice(whitespace.length)
|
|
|
|
}
|
|
|
|
}
|
2013-10-02 13:40:40 +00:00
|
|
|
return lines.join('\n')
|
2013-09-07 17:27:25 +00:00
|
|
|
}
|
2013-09-07 18:52:43 +00:00
|
|
|
|
2013-08-16 18:32:58 +00:00
|
|
|
$scope.fetchFunctionDefinition = function(name) {
|
|
|
|
$http.post("/get_function/","what=" + name, { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).success(function(data, status, headers, config) {
|
2013-09-07 17:27:25 +00:00
|
|
|
$scope.functionDefinition = $scope.cleanupFishFunction(data[0]);
|
2013-08-16 18:32:58 +00:00
|
|
|
})};
|
2013-09-07 18:52:43 +00:00
|
|
|
|
2013-08-16 18:32:58 +00:00
|
|
|
$scope.fetchFunctions();
|
|
|
|
});
|
|
|
|
|
2013-10-19 06:32:00 +00:00
|
|
|
controllers.controller("variablesController", function($scope, $http) {
|
2013-09-07 17:06:23 +00:00
|
|
|
$scope.query = null;
|
2013-09-07 18:52:43 +00:00
|
|
|
|
2013-08-16 18:32:58 +00:00
|
|
|
$scope.fetchVariables= function() {
|
|
|
|
$http.get("/variables/").success(function(data, status, headers, config) {
|
|
|
|
$scope.variables = data;
|
|
|
|
})};
|
2013-09-07 17:06:23 +00:00
|
|
|
|
2013-08-16 18:32:58 +00:00
|
|
|
$scope.fetchVariables();
|
|
|
|
});
|
|
|
|
|
2013-10-19 06:32:00 +00:00
|
|
|
controllers.controller("historyController", function($scope, $http, $timeout) {
|
2013-10-12 12:17:43 +00:00
|
|
|
$scope.historyItems = [];
|
|
|
|
$scope.historySize = 0;
|
|
|
|
// Stores items which are yet to be added in history items
|
|
|
|
$scope.remainingItems = [];
|
|
|
|
|
|
|
|
// Populate history items in parts
|
|
|
|
$scope.loadHistory = function() {
|
|
|
|
if ($scope.remainingItems.length <= 0) {
|
|
|
|
$scope.loadingText = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-20 08:58:40 +00:00
|
|
|
var toLoad = $scope.remainingItems.splice(0, 100);
|
|
|
|
for (i in toLoad) {
|
|
|
|
$scope.historyItems.push(toLoad[i]);
|
2013-10-12 12:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.loadingText = "Loading " + $scope.historyItems.length + "/" + $scope.historySize;
|
|
|
|
$timeout($scope.loadHistory, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get history from server
|
2013-08-16 18:32:58 +00:00
|
|
|
$scope.fetchHistory = function() {
|
|
|
|
$http.get("/history/").success(function(data, status, headers, config) {
|
2013-10-12 12:17:43 +00:00
|
|
|
$scope.historySize = data.length;
|
|
|
|
$scope.remainingItems = data;
|
2013-10-19 18:24:51 +00:00
|
|
|
|
|
|
|
/* Call this function 10 times/second */
|
2013-10-12 12:17:43 +00:00
|
|
|
$timeout($scope.loadHistory, 100);
|
2013-08-16 18:32:58 +00:00
|
|
|
})};
|
|
|
|
|
2013-08-18 14:18:32 +00:00
|
|
|
$scope.deleteHistoryItem = function(item) {
|
|
|
|
index = $scope.historyItems.indexOf(item);
|
|
|
|
$http.post("/delete_history_item/","what=" + encodeURIComponent(item), { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).success(function(data, status, headers, config) {
|
|
|
|
$scope.historyItems.splice(index, 1);
|
|
|
|
})};
|
|
|
|
|
2013-08-16 18:32:58 +00:00
|
|
|
$scope.fetchHistory();
|
|
|
|
});
|
2013-10-13 13:06:46 +00:00
|
|
|
|
2013-10-19 06:32:00 +00:00
|
|
|
controllers.controller("bindingsController", function($scope, $http) {
|
2013-10-13 13:06:46 +00:00
|
|
|
$scope.bindings = [];
|
|
|
|
$scope.fetchBindings = function() {
|
|
|
|
$http.get("/bindings/").success(function(data, status, headers, config) {
|
|
|
|
$scope.bindings = data;
|
|
|
|
})};
|
|
|
|
|
|
|
|
$scope.fetchBindings();
|
|
|
|
});
|