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;
|
2017-01-16 06:51:10 +08:00
|
|
|
|
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;
|
2017-01-16 06:51:10 +08:00
|
|
|
|
2014-02-24 17:56:02 +08:00
|
|
|
$scope.border_color_for_color = border_color_for_color;
|
2013-12-07 15:42:43 +08:00
|
|
|
|
2020-07-07 07:24:44 +08:00
|
|
|
$scope.interpret_color = interpret_color;
|
|
|
|
|
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;
|
|
|
|
}
|
2017-01-16 06:51:10 +08:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2017-01-16 06:51:10 +08:00
|
|
|
|
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);
|
|
|
|
}
|
2017-01-16 06:51:10 +08:00
|
|
|
|
2014-02-24 17:56:02 +08:00
|
|
|
$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;
|
2021-12-14 04:28:16 +08:00
|
|
|
$scope.selectedColorScheme["colordata-" + $scope.selectedColorSetting].color = 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
|
|
|
|
2019-10-16 14:18:18 +08:00
|
|
|
$scope.sampleTerminalBackgroundColors = ['white', '#' + solarized.base3, '#300', '#003', '#' + solarized.base03, '#232323', '#'+nord.nord0, 'black'];
|
2013-10-13 01:48:52 +08:00
|
|
|
|
2013-10-02 21:40:40 +08:00
|
|
|
/* Array of FishColorSchemes */
|
2021-07-10 01:45:03 +08:00
|
|
|
$scope.colorSchemes = [];
|
|
|
|
|
2021-07-10 02:30:54 +08:00
|
|
|
isValidColor = function(col) {
|
2021-12-14 03:21:34 +08:00
|
|
|
if (col == "normal") return true;
|
2021-07-10 02:30:54 +08:00
|
|
|
var s = new Option().style;
|
|
|
|
s.color = col;
|
|
|
|
return !!s.color;
|
|
|
|
}
|
|
|
|
|
2021-07-10 01:45:03 +08:00
|
|
|
$scope.getThemes = function() {
|
2020-06-23 01:51:44 +08:00
|
|
|
$http.get("colors/").then(function(arg) {
|
2021-07-10 01:45:03 +08:00
|
|
|
for (var scheme of arg.data) {
|
|
|
|
var currentScheme = { "name": "Current", "colors":[], "preferred_background": "black" };
|
|
|
|
currentScheme["name"] = scheme["theme"];
|
2021-09-03 23:37:54 +08:00
|
|
|
if (scheme["name"]) currentScheme["name"] = scheme["name"];
|
2021-07-10 01:45:03 +08:00
|
|
|
var data = scheme["colors"];
|
2021-07-10 02:30:54 +08:00
|
|
|
if (scheme["preferred_background"]) {
|
|
|
|
if (isValidColor(scheme["preferred_background"])) {
|
|
|
|
currentScheme["preferred_background"] = scheme["preferred_background"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (scheme["url"]) currentScheme["url"] = scheme["url"];
|
|
|
|
|
2021-12-14 04:28:16 +08:00
|
|
|
var cols = [];
|
2021-07-10 01:45:03 +08:00
|
|
|
for (var i in data) {
|
2021-07-10 02:30:54 +08:00
|
|
|
if (isValidColor(data[i].color)) {
|
|
|
|
currentScheme[data[i].name] = data[i].color;
|
2021-12-14 04:28:16 +08:00
|
|
|
// HACK: For some reason the colors array is cleared later
|
|
|
|
// So we cheesily encode the actual objects as colordata-, so we can send them.
|
|
|
|
// TODO: We should switch to keeping the objects, and also displaying them
|
|
|
|
// with underlines and such.
|
|
|
|
currentScheme["colordata-" + data[i].name] = data[i];
|
2021-07-10 02:30:54 +08:00
|
|
|
}
|
2021-07-10 01:45:03 +08:00
|
|
|
}
|
|
|
|
$scope.colorSchemes.push(currentScheme);
|
2013-10-20 16:58:40 +08:00
|
|
|
}
|
2021-07-10 01:45:03 +08:00
|
|
|
$scope.changeSelectedColorScheme($scope.colorSchemes[0]);
|
2020-06-22 04:05:12 +08:00
|
|
|
})};
|
2013-10-13 16:20:21 +08:00
|
|
|
|
2016-03-03 07:02:28 +08:00
|
|
|
$scope.saveThemeButtonTitle = "Set Theme";
|
2017-01-16 06:51:10 +08:00
|
|
|
|
2014-02-24 17:56:02 +08:00
|
|
|
$scope.noteThemeChanged = function() {
|
2016-03-03 07:02:28 +08:00
|
|
|
$scope.saveThemeButtonTitle = "Set Theme";
|
2014-02-24 17:56:02 +08:00
|
|
|
}
|
|
|
|
|
2013-10-13 02:25:37 +08:00
|
|
|
$scope.setTheme = function() {
|
2018-11-29 21:49:12 +08:00
|
|
|
var settingNames = ["normal",
|
|
|
|
"command",
|
|
|
|
"quote",
|
|
|
|
"redirection",
|
|
|
|
"end",
|
|
|
|
"error",
|
|
|
|
"param",
|
|
|
|
"comment",
|
|
|
|
"match",
|
|
|
|
"selection",
|
|
|
|
"search_match",
|
|
|
|
"history_current",
|
|
|
|
"operator",
|
|
|
|
"escape",
|
|
|
|
"cwd",
|
|
|
|
"cwd_root",
|
|
|
|
"valid_path",
|
|
|
|
"autosuggestion",
|
|
|
|
"user",
|
|
|
|
"host",
|
2018-11-29 22:18:00 +08:00
|
|
|
"cancel",
|
2021-12-14 03:21:34 +08:00
|
|
|
// Cheesy hardcoded variable names ahoy!
|
|
|
|
// These are all the pager vars,
|
|
|
|
// we should really just save all these in a dictionary.
|
|
|
|
"fish_pager_color_background",
|
|
|
|
"fish_pager_color_prefix",
|
|
|
|
"fish_pager_color_progress",
|
2018-11-29 22:18:00 +08:00
|
|
|
"fish_pager_color_completion",
|
|
|
|
"fish_pager_color_description",
|
2021-12-14 03:21:34 +08:00
|
|
|
"fish_pager_color_selected_background",
|
|
|
|
"fish_pager_color_selected_prefix",
|
|
|
|
"fish_pager_color_selected_completion",
|
|
|
|
"fish_pager_color_selected_description",
|
|
|
|
// TODO: Setting these to empty currently makes them weird. Figure out why!
|
|
|
|
/*
|
|
|
|
"fish_pager_color_secondary_background",
|
|
|
|
"fish_pager_color_secondary_prefix",
|
|
|
|
"fish_pager_color_secondary_completion",
|
|
|
|
"fish_pager_color_secondary_description",
|
|
|
|
*/
|
2018-11-29 21:49:12 +08:00
|
|
|
];
|
2014-02-24 17:56:02 +08:00
|
|
|
var remaining = settingNames.length;
|
2021-12-13 04:32:32 +08:00
|
|
|
var postdata = {
|
2021-07-10 00:24:41 +08:00
|
|
|
"theme" : $scope.selectedColorScheme["name"],
|
|
|
|
"colors": [],
|
|
|
|
}
|
2021-12-13 04:32:32 +08:00
|
|
|
for (var name of settingNames) {
|
2018-12-05 16:52:36 +08:00
|
|
|
var selected;
|
2021-12-14 04:28:16 +08:00
|
|
|
var realname = "colordata-" + name;
|
2018-11-29 21:49:12 +08:00
|
|
|
// Skip colors undefined in the current theme
|
2018-12-05 16:52:36 +08:00
|
|
|
// js is dumb - the empty string is false,
|
|
|
|
// but we want that to mean unsetting a var.
|
2021-12-14 04:28:16 +08:00
|
|
|
if (!$scope.selectedColorScheme[realname] && $scope.selectedColorScheme[realname] !== '') {
|
2021-11-09 00:38:05 +08:00
|
|
|
selected = '';
|
2018-12-05 16:52:36 +08:00
|
|
|
} else {
|
2021-12-14 04:28:16 +08:00
|
|
|
selected = $scope.selectedColorScheme[realname];
|
2018-11-29 21:49:12 +08:00
|
|
|
}
|
2021-07-10 00:24:41 +08:00
|
|
|
postdata.colors.push({
|
|
|
|
"what" : name,
|
|
|
|
"color" : selected,
|
|
|
|
});
|
2013-10-13 02:25:37 +08:00
|
|
|
}
|
2021-07-10 00:24:41 +08:00
|
|
|
$http.post("set_color/", postdata, { headers: {'Content-Type': 'application/json'} }).then(function(arg) {
|
|
|
|
if (arg.status == 200) {
|
|
|
|
$scope.saveThemeButtonTitle = "Theme Set!";
|
|
|
|
}
|
|
|
|
})
|
2013-10-13 02:25:37 +08:00
|
|
|
};
|
2013-10-20 16:58:40 +08:00
|
|
|
|
2021-07-10 01:45:03 +08:00
|
|
|
$scope.getThemes();
|
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() {
|
2020-06-23 01:51:44 +08:00
|
|
|
$http.get("sample_prompts/").then(function(arg) {
|
|
|
|
$scope.samplePrompts = arg.data;
|
2013-11-09 20:56:44 +08:00
|
|
|
|
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) {
|
2020-06-23 01:51:44 +08:00
|
|
|
$scope.selectedPrompt = prompt;
|
2017-01-16 06:51:10 +08:00
|
|
|
|
2014-07-30 02:00:39 +08:00
|
|
|
$scope.savePromptButtonTitle = "Set Prompt";
|
2013-08-17 02:32:58 +08:00
|
|
|
}
|
|
|
|
|
2013-08-18 22:18:32 +08:00
|
|
|
$scope.setNewPrompt = function(selectedPrompt) {
|
2020-06-23 01:51:44 +08:00
|
|
|
$http.post("set_prompt/", {'fish_prompt': selectedPrompt.function,}).then(function(arg){
|
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;
|
2021-04-15 01:25:48 +08:00
|
|
|
$scope.samplePrompts[0].right = selectedPrompt.right;
|
2013-11-09 20:56:44 +08:00
|
|
|
$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;
|
2017-01-16 06:51:10 +08:00
|
|
|
$scope.functionDefinition = "";
|
2013-08-17 02:32:58 +08:00
|
|
|
|
|
|
|
$scope.selectFunction = function(fun) {
|
|
|
|
$scope.selectedFunction = fun;
|
|
|
|
$scope.fetchFunctionDefinition($scope.selectedFunction);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.fetchFunctions= function() {
|
2020-06-23 01:51:44 +08:00
|
|
|
$http.get("functions/").then(function(arg) {
|
|
|
|
$scope.functions = arg.data;
|
2013-08-17 02:32:58 +08:00
|
|
|
$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. */
|
2021-12-13 04:32:32 +08:00
|
|
|
var lines = contents ? contents.split('\n') : [];
|
|
|
|
var rx = /^[\t ]+/
|
2013-09-08 01:27:25 +08:00
|
|
|
for (var i=0; i < lines.length; i++) {
|
2021-12-13 04:32:32 +08:00
|
|
|
var line = lines[i]
|
2013-09-08 01:27:25 +08:00
|
|
|
/* Get leading tabs and spaces */
|
2021-12-13 04:32:32 +08:00
|
|
|
var whitespace_arr = rx.exec(line)
|
2013-09-08 01:27:25 +08:00
|
|
|
if (whitespace_arr) {
|
|
|
|
/* Replace four spaces with two spaces, and tabs with two spaces */
|
|
|
|
var whitespace = whitespace_arr[0]
|
2021-12-13 04:32:32 +08:00
|
|
|
var new_whitespace = whitespace.replace(/( )|(\t)/g, ' ')
|
2013-09-08 01:27:25 +08:00
|
|
|
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) {
|
2020-06-23 01:51:44 +08:00
|
|
|
$http.post("get_function/","what=" + name, { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).then(function(arg) {
|
|
|
|
$scope.functionDefinition = $scope.cleanupFishFunction(arg.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() {
|
2020-06-23 01:51:44 +08:00
|
|
|
$http.get("variables/").then(function(arg) {
|
|
|
|
$scope.variables = arg.data;
|
2013-08-17 02:32:58 +08:00
|
|
|
})};
|
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) {
|
2018-09-09 15:26:38 +08:00
|
|
|
// All history items, as strings.
|
|
|
|
$scope.allItems = [];
|
|
|
|
// How many items per page.
|
|
|
|
$scope.itemsPerPage = 50;
|
|
|
|
// Filtered items grouped into pages. A list of lists. Never empty.
|
|
|
|
$scope.filteredItemPages = [[]];
|
|
|
|
// The current page index (0 based).
|
|
|
|
$scope.currentPage = 0;
|
|
|
|
// The filter query.
|
|
|
|
$scope.query = "";
|
|
|
|
// The items which are selected.
|
2013-10-22 02:12:16 +08:00
|
|
|
$scope.selectedItems = [];
|
2013-10-12 20:17:43 +08:00
|
|
|
|
2018-09-09 15:26:38 +08:00
|
|
|
// Filter all of our items, and group them into pages.
|
|
|
|
$scope.filterAndGroup = function () {
|
|
|
|
// Filter items.
|
|
|
|
var filteredItems;
|
|
|
|
if ($scope.query && $scope.query.length > 0) {
|
|
|
|
filteredItems = $scope.allItems.filter(function(item) {
|
|
|
|
return item.indexOf($scope.query) >= 0;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
filteredItems = $scope.allItems;
|
2013-10-12 20:17:43 +08:00
|
|
|
}
|
|
|
|
|
2018-09-09 15:26:38 +08:00
|
|
|
// Group them by pages. Ensure our pages are never empty.
|
|
|
|
var pages = [];
|
|
|
|
for (var start = 0; start < filteredItems.length; start += $scope.itemsPerPage) {
|
|
|
|
var end = Math.min(start + $scope.itemsPerPage, filteredItems.length);
|
|
|
|
pages.push(filteredItems.slice(start, end));
|
2013-10-12 20:17:43 +08:00
|
|
|
}
|
2018-09-09 15:26:38 +08:00
|
|
|
if (pages.length == 0) {
|
|
|
|
pages.push([]);
|
|
|
|
}
|
|
|
|
$scope.filteredItemPages = pages;
|
|
|
|
};
|
2013-10-12 20:17:43 +08:00
|
|
|
|
2018-09-09 15:26:38 +08:00
|
|
|
$scope.currentPageDescription = function() {
|
|
|
|
if ($scope.filteredItemPages[0].length === 0) {
|
|
|
|
return "None";
|
|
|
|
}
|
2018-09-20 06:28:40 +08:00
|
|
|
return ($scope.currentPage + 1) + " / " + $scope.filteredItemPages.length;
|
2018-09-09 15:26:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.prevPage = function () {
|
|
|
|
$scope.currentPage = Math.max($scope.currentPage - 1, 0);
|
|
|
|
};
|
2021-01-01 01:27:47 +08:00
|
|
|
|
2018-09-09 15:26:38 +08:00
|
|
|
$scope.nextPage = function () {
|
|
|
|
$scope.currentPage = Math.min($scope.currentPage + 1,
|
|
|
|
$scope.filteredItemPages.length - 1);
|
|
|
|
};
|
2013-10-12 20:17:43 +08:00
|
|
|
|
2013-10-22 02:12:16 +08:00
|
|
|
$scope.selectItem = function(item) {
|
|
|
|
var index = $scope.selectedItems.indexOf(item);
|
2018-09-09 15:26:38 +08:00
|
|
|
if (index >= 0) {
|
|
|
|
// Deselect.
|
2013-10-22 02:12:16 +08:00
|
|
|
$scope.selectedItems.splice(index,1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$scope.selectedItems.push(item);
|
|
|
|
}
|
|
|
|
}
|
2018-09-09 15:26:38 +08:00
|
|
|
|
2013-10-12 20:17:43 +08:00
|
|
|
// Get history from server
|
2013-08-17 02:32:58 +08:00
|
|
|
$scope.fetchHistory = function() {
|
2020-06-23 01:51:44 +08:00
|
|
|
$http.get("history/").then(function(arg) {
|
|
|
|
$scope.allItems = arg.data;
|
2018-09-09 15:26:38 +08:00
|
|
|
$scope.filterAndGroup();
|
|
|
|
});
|
|
|
|
};
|
2013-08-17 02:32:58 +08:00
|
|
|
|
2013-08-18 22:18:32 +08:00
|
|
|
$scope.deleteHistoryItem = function(item) {
|
2018-09-09 15:26:38 +08:00
|
|
|
index = $scope.allItems.indexOf(item);
|
2020-06-23 01:51:44 +08:00
|
|
|
$http.post("delete_history_item/","what=" + encodeURIComponent(item), { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }).then(function(arg) {
|
2018-09-09 15:26:38 +08:00
|
|
|
$scope.allItems.splice(index, 1);
|
|
|
|
$scope.filterAndGroup();
|
2013-08-18 22:18:32 +08:00
|
|
|
})};
|
|
|
|
|
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;
|
2018-09-09 15:26:38 +08:00
|
|
|
$scope.filterAndGroup();
|
|
|
|
$scope.currentPage = 0;
|
2013-10-23 02:15:32 +08:00
|
|
|
}, 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() {
|
2020-06-23 01:51:44 +08:00
|
|
|
$http.get("bindings/").then(function(arg) {
|
|
|
|
$scope.bindings = arg.data;
|
2013-10-13 21:06:46 +08:00
|
|
|
})};
|
|
|
|
|
|
|
|
$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
|
2021-12-13 04:32:32 +08:00
|
|
|
var hasBlank = {hasBlank: false}
|
2014-10-17 10:27:13 +08:00
|
|
|
angular.forEach($scope.abbreviations, function(value, key) {
|
|
|
|
if (value.phrase === "" && value.word === "") {
|
|
|
|
this.hasBlank = true;
|
|
|
|
}
|
|
|
|
}, hasBlank);
|
2020-06-22 04:05:12 +08:00
|
|
|
if (!$scope.abbreviations) $scope.abbreviations = [];
|
2014-10-17 10:27:13 +08:00
|
|
|
if (! hasBlank.hasBlank) {
|
|
|
|
$scope.abbreviations.push({phrase: "", word: "", editable: true})
|
|
|
|
}
|
|
|
|
}
|
2014-10-05 12:19:57 +08:00
|
|
|
$scope.fetchAbbreviations = function() {
|
2020-06-23 01:51:44 +08:00
|
|
|
$http.get("abbreviations/").then(function(arg) {
|
|
|
|
$scope.abbreviations = arg.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) {
|
2020-06-23 01:51:44 +08:00
|
|
|
$http.post("save_abbreviation/", abbreviation).then(function(arg) {
|
2014-10-17 10:27:13 +08:00
|
|
|
abbreviation.editable = false;
|
|
|
|
$scope.addBlank();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeAbbreviation = function(abbreviation) {
|
|
|
|
if (abbreviation.word) {
|
2020-06-23 01:51:44 +08:00
|
|
|
$http.post("remove_abbreviation/", abbreviation).then(function(arg) {
|
2014-10-17 10:27:13 +08:00
|
|
|
$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
|
|
|
});
|