2013-10-19 14:32:00 +08:00
|
|
|
controllers = angular.module("controllers", []);
|
2013-08-17 02:32:58 +08:00
|
|
|
|
2013-10-19 14:32:00 +08:00
|
|
|
controllers.controller("main", function($scope, $location) {
|
2015-06-14 15:04:29 +08:00
|
|
|
// substr(1) strips a leading slash
|
|
|
|
$scope.currentTab = $location.path().substr(1) || "colors";
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.changeView = function(view) {
|
|
|
|
$location.path(view);
|
|
|
|
$scope.currentTab = view;
|
|
|
|
}
|
2013-10-20 02:24:51 +08:00
|
|
|
|
2013-08-17 02:32:58 +08:00
|
|
|
})
|
|
|
|
|
2013-10-19 14:32:00 +08:00
|
|
|
controllers.controller("colorsController", function($scope, $http) {
|
2013-10-13 02:25:37 +08:00
|
|
|
$scope.changeSelectedColorScheme= function(newScheme) {
|
2014-02-24 17:56:02 +08:00
|
|
|
$scope.selectedColorScheme = angular.copy(newScheme);
|
2013-10-13 02:25:37 +08:00
|
|
|
if ($scope.selectedColorScheme.preferred_background) {
|
|
|
|
$scope.terminalBackgroundColor = $scope.selectedColorScheme.preferred_background;
|
|
|
|
}
|
2014-02-24 17:56:02 +08:00
|
|
|
$scope.selectedColorSetting = false;
|
|
|
|
$scope.customizationActive = false;
|
|
|
|
$scope.csEditingType = false;
|
2013-10-13 02:25:37 +08:00
|
|
|
$scope.colorArraysArray = $scope.getColorArraysArray();
|
|
|
|
//TODO: Save button should be shown only when colors are changed
|
|
|
|
$scope.showSaveButton = true;
|
2014-02-24 17:56:02 +08:00
|
|
|
|
|
|
|
$scope.noteThemeChanged();
|
2013-10-13 02:25:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.changeTerminalBackgroundColor = function(color) {
|
|
|
|
$scope.terminalBackgroundColor = color;
|
|
|
|
}
|
|
|
|
|
2014-02-24 17:56:02 +08:00
|
|
|
$scope.text_color_for_color = text_color_for_color;
|
|
|
|
|
|
|
|
$scope.border_color_for_color = border_color_for_color;
|
2013-12-07 15:42:43 +08:00
|
|
|
|
2013-10-13 01:48:52 +08:00
|
|
|
$scope.getColorArraysArray = function() {
|
|
|
|
var result = null;
|
2013-10-20 16:58:40 +08:00
|
|
|
if ( $scope.selectedColorScheme.colors && $scope.selectedColorScheme.colors.length > 0)
|
2013-10-13 01:48:52 +08:00
|
|
|
result = get_colors_as_nested_array($scope.selectedColorScheme.colors, 32);
|
|
|
|
else
|
2013-10-20 02:24:51 +08:00
|
|
|
result = get_colors_as_nested_array(term_256_colors, 32);
|
2013-10-13 01:48:52 +08:00
|
|
|
return result;
|
|
|
|
}
|
2014-02-24 17:56:02 +08:00
|
|
|
|
|
|
|
$scope.beginCustomizationWithSetting = function(setting) {
|
|
|
|
if (! $scope.customizationActive) {
|
|
|
|
$scope.customizationActive = true;
|
|
|
|
$scope.selectedColorSetting = setting;
|
|
|
|
$scope.csEditingType = setting;
|
|
|
|
$scope.csUserVisibleTitle = user_visible_title_for_setting_name(setting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-13 01:48:52 +08:00
|
|
|
$scope.selectColorSetting = function(name) {
|
2014-02-24 17:56:02 +08:00
|
|
|
$scope.selectedColorSetting = name;
|
|
|
|
$scope.csEditingType = $scope.customizationActive ? name : '';
|
|
|
|
$scope.csUserVisibleTitle = user_visible_title_for_setting_name(name);
|
|
|
|
$scope.beginCustomizationWithSetting(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.toggleCustomizationActive = function() {
|
|
|
|
if (! $scope.customizationActive) {
|
|
|
|
$scope.beginCustomizationWithSetting($scope.selectedColorSetting || 'command');
|
|
|
|
} else {
|
|
|
|
$scope.customizationActive = false;
|
|
|
|
$scope.selectedColorSetting = '';
|
|
|
|
$scope.csEditingType = '';
|
|
|
|
}
|
2013-10-13 01:48:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.changeSelectedTextColor = function(color) {
|
|
|
|
$scope.selectedColorScheme[$scope.selectedColorSetting] = color;
|
2014-02-24 17:56:02 +08:00
|
|
|
$scope.noteThemeChanged();
|
2013-10-13 01:48:52 +08:00
|
|
|
}
|
2013-10-02 21:40:40 +08:00
|
|
|
|
2013-10-13 01:48:52 +08:00
|
|
|
$scope.sampleTerminalBackgroundColors = ['white', '#' + solarized.base3, '#300', '#003', '#' + solarized.base03, '#232323', 'black'];
|
|
|
|
|
2013-10-02 21:40:40 +08:00
|
|
|
/* Array of FishColorSchemes */
|
2013-10-20 02:24:51 +08: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 21:40:40 +08:00
|
|
|
for (var i=0; i < additional_color_schemes.length; i++)
|
2013-10-20 02:24:51 +08:00
|
|
|
$scope.colorSchemes.push(additional_color_schemes[i])
|
2013-10-02 21:40:40 +08:00
|
|
|
|
2013-10-20 16:58:40 +08:00
|
|
|
|
|
|
|
$scope.getCurrentTheme = function() {
|
2014-08-04 13:34:26 +08:00
|
|
|
$http.get("colors/").success(function(data, status, headers, config) {
|
2013-10-20 16:58:40 +08:00
|
|
|
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 16:20:21 +08:00
|
|
|
|
2016-01-10 10:06:34 +08:00
|
|
|
$scope.saveThemeButtonTitle = "Set Theme w/o Background Color";
|
2014-02-24 17:56:02 +08:00
|
|
|
|
|
|
|
$scope.noteThemeChanged = function() {
|
2016-01-10 10:06:34 +08:00
|
|
|
$scope.saveThemeButtonTitle = "Set Theme w/o Background Color";
|
2014-02-24 17:56:02 +08:00
|
|
|
}
|
|
|
|
|
2013-10-13 02:25:37 +08:00
|
|
|
$scope.setTheme = function() {
|
2013-10-13 16:20:21 +08:00
|
|
|
var settingNames = ["autosuggestion", "command", "param", "redirection", "comment", "error", "quote", "end"];
|
2014-02-24 17:56:02 +08:00
|
|
|
var remaining = settingNames.length;
|
2013-10-13 02:25:37 +08:00
|
|
|
for (name in settingNames) {
|
|
|
|
var postData = "what=" + settingNames[name] + "&color=" + $scope.selectedColorScheme[settingNames[name]] + "&background_color=&bold=&underline=";
|
2014-08-04 13:34:26 +08:00
|
|
|
$http.post("set_color/", postData, { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).success(function(data, status, headers, config) {
|
2014-02-24 17:56:02 +08:00
|
|
|
if (status == 200) {
|
|
|
|
remaining -= 1;
|
|
|
|
if (remaining == 0) {
|
|
|
|
/* All styles set! */
|
|
|
|
$scope.saveThemeButtonTitle = "Theme Set!";
|
|
|
|
}
|
|
|
|
}
|
2013-10-13 02:25:37 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
};
|
2013-10-20 16:58:40 +08:00
|
|
|
|
|
|
|
$scope.getCurrentTheme();
|
2013-10-02 21:40:40 +08:00
|
|
|
});
|
2013-08-17 02:32:58 +08:00
|
|
|
|
2013-10-19 14:32:00 +08:00
|
|
|
controllers.controller("promptController", function($scope, $http) {
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.selectedPrompt = null;
|
2014-07-30 02:00:39 +08:00
|
|
|
$scope.showSaveButton = true;
|
|
|
|
$scope.savePromptButtonTitle = "Set Prompt";
|
2013-09-08 02:52:43 +08:00
|
|
|
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.fetchSamplePrompts= function() {
|
2014-08-04 13:34:26 +08:00
|
|
|
$http.get("sample_prompts/").success(function(data, status, headers, config) {
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.samplePrompts = data;
|
2013-11-09 20:56:44 +08:00
|
|
|
$scope.samplePromptsArrayArray = get_colors_as_nested_array($scope.samplePrompts, 1);
|
|
|
|
|
2013-08-17 02:32:58 +08:00
|
|
|
if ($scope.selectedPrompt == null) {
|
|
|
|
$scope.selectPrompt($scope.samplePrompts[0]);
|
|
|
|
}
|
|
|
|
})};
|
2013-09-08 02:52:43 +08:00
|
|
|
|
2014-07-30 02:00:39 +08:00
|
|
|
$scope.selectPrompt = function(prompt) {
|
|
|
|
$scope.selectedPrompt= prompt;
|
|
|
|
|
|
|
|
$scope.savePromptButtonTitle = "Set Prompt";
|
2013-08-17 02:32:58 +08:00
|
|
|
}
|
|
|
|
|
2013-08-18 22:18:32 +08:00
|
|
|
$scope.setNewPrompt = function(selectedPrompt) {
|
2015-01-30 22:54:11 +08:00
|
|
|
$http.post("set_prompt/", {'fish_prompt': selectedPrompt.function,}).success(function(data, status, headers, config){
|
2013-11-09 20:56:44 +08:00
|
|
|
|
2013-11-09 23:13:19 +08:00
|
|
|
// Update attributes of current prompt and select it
|
2013-11-09 20:56:44 +08:00
|
|
|
$scope.samplePrompts[0].demo = selectedPrompt.demo;
|
|
|
|
$scope.samplePrompts[0].function = selectedPrompt.function;
|
|
|
|
$scope.samplePrompts[0].font_size = selectedPrompt.font_size;
|
2013-11-09 23:13:19 +08:00
|
|
|
$scope.selectedPrompt = $scope.samplePrompts[0];
|
2014-07-30 02:00:39 +08:00
|
|
|
|
|
|
|
// Note that we set it
|
|
|
|
$scope.savePromptButtonTitle = "Prompt Set!";
|
2013-08-18 22:18:32 +08:00
|
|
|
})};
|
2013-09-08 02:52:43 +08:00
|
|
|
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.fetchSamplePrompts();
|
2014-07-30 02:00:39 +08:00
|
|
|
|
|
|
|
$scope.setPrompt = function() {
|
|
|
|
if ($scope.selectedPrompt) {
|
|
|
|
$scope.setNewPrompt($scope.selectedPrompt);
|
|
|
|
}
|
|
|
|
}
|
2013-08-17 02:32:58 +08:00
|
|
|
});
|
|
|
|
|
2013-10-19 14:32:00 +08:00
|
|
|
controllers.controller("functionsController", function($scope, $http) {
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.selectedFunction = null;
|
|
|
|
$scope.functionDefinition = "";
|
|
|
|
|
|
|
|
$scope.selectFunction = function(fun) {
|
|
|
|
$scope.selectedFunction = fun;
|
|
|
|
$scope.fetchFunctionDefinition($scope.selectedFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.fetchFunctions= function() {
|
2014-08-04 13:34:26 +08:00
|
|
|
$http.get("functions/").success(function(data, status, headers, config) {
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.functions = data;
|
|
|
|
$scope.selectFunction($scope.functions[0]);
|
|
|
|
})};
|
|
|
|
|
2013-09-08 01:27:25 +08: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 21:40:40 +08:00
|
|
|
return lines.join('\n')
|
2013-09-08 01:27:25 +08:00
|
|
|
}
|
2013-09-08 02:52:43 +08:00
|
|
|
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.fetchFunctionDefinition = function(name) {
|
2014-08-04 13:34:26 +08:00
|
|
|
$http.post("get_function/","what=" + name, { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).success(function(data, status, headers, config) {
|
2013-09-08 01:27:25 +08:00
|
|
|
$scope.functionDefinition = $scope.cleanupFishFunction(data[0]);
|
2013-08-17 02:32:58 +08:00
|
|
|
})};
|
2013-09-08 02:52:43 +08:00
|
|
|
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.fetchFunctions();
|
|
|
|
});
|
|
|
|
|
2013-10-19 14:32:00 +08:00
|
|
|
controllers.controller("variablesController", function($scope, $http) {
|
2013-09-08 01:06:23 +08:00
|
|
|
$scope.query = null;
|
2013-09-08 02:52:43 +08:00
|
|
|
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.fetchVariables= function() {
|
2014-08-04 13:34:26 +08:00
|
|
|
$http.get("variables/").success(function(data, status, headers, config) {
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.variables = data;
|
|
|
|
})};
|
2013-09-08 01:06:23 +08:00
|
|
|
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.fetchVariables();
|
|
|
|
});
|
|
|
|
|
2013-10-19 14:32:00 +08:00
|
|
|
controllers.controller("historyController", function($scope, $http, $timeout) {
|
2013-10-12 20:17:43 +08:00
|
|
|
$scope.historyItems = [];
|
|
|
|
$scope.historySize = 0;
|
|
|
|
// Stores items which are yet to be added in history items
|
|
|
|
$scope.remainingItems = [];
|
2013-10-22 02:12:16 +08:00
|
|
|
$scope.selectedItems = [];
|
2013-10-12 20:17:43 +08:00
|
|
|
|
|
|
|
// Populate history items in parts
|
|
|
|
$scope.loadHistory = function() {
|
|
|
|
if ($scope.remainingItems.length <= 0) {
|
|
|
|
$scope.loadingText = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-20 16:58:40 +08:00
|
|
|
var toLoad = $scope.remainingItems.splice(0, 100);
|
|
|
|
for (i in toLoad) {
|
|
|
|
$scope.historyItems.push(toLoad[i]);
|
2013-10-12 20:17:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.loadingText = "Loading " + $scope.historyItems.length + "/" + $scope.historySize;
|
|
|
|
$timeout($scope.loadHistory, 100);
|
|
|
|
}
|
|
|
|
|
2013-10-22 02:12:16 +08:00
|
|
|
$scope.selectItem = function(item) {
|
|
|
|
var index = $scope.selectedItems.indexOf(item);
|
|
|
|
if ( index >= 0) {
|
|
|
|
$scope.selectedItems.splice(index,1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$scope.selectedItems.push(item);
|
|
|
|
}
|
|
|
|
}
|
2013-10-12 20:17:43 +08:00
|
|
|
// Get history from server
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.fetchHistory = function() {
|
2014-08-04 13:34:26 +08:00
|
|
|
$http.get("history/").success(function(data, status, headers, config) {
|
2013-10-12 20:17:43 +08:00
|
|
|
$scope.historySize = data.length;
|
|
|
|
$scope.remainingItems = data;
|
2013-10-20 02:24:51 +08:00
|
|
|
|
|
|
|
/* Call this function 10 times/second */
|
2013-10-12 20:17:43 +08:00
|
|
|
$timeout($scope.loadHistory, 100);
|
2013-08-17 02:32:58 +08:00
|
|
|
})};
|
|
|
|
|
2013-08-18 22:18:32 +08:00
|
|
|
$scope.deleteHistoryItem = function(item) {
|
|
|
|
index = $scope.historyItems.indexOf(item);
|
2014-08-04 13:34:26 +08:00
|
|
|
$http.post("delete_history_item/","what=" + encodeURIComponent(item), { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).success(function(data, status, headers, config) {
|
2013-08-18 22:18:32 +08:00
|
|
|
$scope.historyItems.splice(index, 1);
|
|
|
|
})};
|
|
|
|
|
2013-10-23 02:15:32 +08:00
|
|
|
var queryInputTimeout = null;
|
|
|
|
$scope.$watch("queryInput", function() {
|
|
|
|
if (queryInputTimeout){
|
|
|
|
$timeout.cancel(queryInputTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
queryInputTimeout = $timeout(function() {
|
|
|
|
$scope.query = $scope.queryInput;
|
|
|
|
}, 1000);
|
|
|
|
});
|
|
|
|
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.fetchHistory();
|
|
|
|
});
|
2013-10-13 21:06:46 +08:00
|
|
|
|
2013-10-19 14:32:00 +08:00
|
|
|
controllers.controller("bindingsController", function($scope, $http) {
|
2013-10-13 21:06:46 +08:00
|
|
|
$scope.bindings = [];
|
|
|
|
$scope.fetchBindings = function() {
|
2014-08-04 13:34:26 +08:00
|
|
|
$http.get("bindings/").success(function(data, status, headers, config) {
|
2013-10-13 21:06:46 +08:00
|
|
|
$scope.bindings = data;
|
|
|
|
})};
|
|
|
|
|
|
|
|
$scope.fetchBindings();
|
|
|
|
});
|
2014-10-05 12:19:57 +08:00
|
|
|
|
|
|
|
controllers.controller("abbreviationsController", function($scope, $http) {
|
|
|
|
$scope.abbreviations = [];
|
2014-10-17 10:27:13 +08:00
|
|
|
$scope.addBlank = function() {
|
|
|
|
// Add blank entry if it is missing
|
|
|
|
hasBlank = {hasBlank: false}
|
|
|
|
angular.forEach($scope.abbreviations, function(value, key) {
|
|
|
|
if (value.phrase === "" && value.word === "") {
|
|
|
|
this.hasBlank = true;
|
|
|
|
}
|
|
|
|
}, hasBlank);
|
|
|
|
if (! hasBlank.hasBlank) {
|
|
|
|
$scope.abbreviations.push({phrase: "", word: "", editable: true})
|
|
|
|
}
|
|
|
|
}
|
2014-10-05 12:19:57 +08:00
|
|
|
$scope.fetchAbbreviations = function() {
|
|
|
|
$http.get("abbreviations/").success(function(data, status, headers, config) {
|
|
|
|
$scope.abbreviations = data;
|
2014-10-17 10:27:13 +08:00
|
|
|
$scope.addBlank();
|
2014-10-05 12:19:57 +08:00
|
|
|
})};
|
|
|
|
|
2014-10-17 10:27:13 +08:00
|
|
|
$scope.editAbbreviation = function(abbreviation) {
|
|
|
|
abbreviation.editable = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.saveAbbreviation = function(abbreviation) {
|
|
|
|
if (abbreviation.word && abbreviation.phrase) {
|
|
|
|
$http.post("save_abbreviation/", abbreviation).success(function(data, status, headers, config) {
|
|
|
|
abbreviation.editable = false;
|
|
|
|
$scope.addBlank();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeAbbreviation = function(abbreviation) {
|
|
|
|
if (abbreviation.word) {
|
|
|
|
$http.post("remove_abbreviation/", abbreviation).success(function(data, status, headers, config) {
|
|
|
|
$scope.abbreviations.splice($scope.abbreviations.indexOf(abbreviation), 1);
|
|
|
|
$scope.addBlank();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-05 12:19:57 +08:00
|
|
|
$scope.fetchAbbreviations();
|
2014-10-17 10:27:13 +08:00
|
|
|
});
|