-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathextension.js
More file actions
98 lines (85 loc) · 3.21 KB
/
Copy pathextension.js
File metadata and controls
98 lines (85 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import Jupyter from 'base/js/namespace';
import $ from 'jquery';
import dialog from 'base/js/dialog';
import scripts from './scripts';
import methods from './methods';
import baseHTML from './templates/sidebar.html';
import api from './api';
import './templates/sidebar.css';
/*
This function populates all the data onto the sidebar and registers appropriate event handlers.
*/
function init(dir) {
scripts.package_view(dir);
scripts.search_view();
methods.update_packages(dir);
methods.delete_packages(dir);
methods.install_packages(dir);
}
/*
This function is the entry point to the extension.
*/
function load_ipython_extension() {
if (!Jupyter.notebook_list) return;
console.log('[PACKAGE MANAGER] Loading nbextension');
}
/*
This is the function that will be invoked on clicking the cog button on SWAN.
A new sidebar will be created each time corresponding to the project from where it is called.
*/
function show_button(project) {
// Configure Sidebar
var modal = dialog.modal({
draggable: false,
title: 'Configure Project',
body: $.parseHTML(baseHTML)
}).attr('id', 'package-manager-modal').addClass('right full-body');
modal.find(".modal-header").unbind("mousedown");
modal.on('shown.bs.modal', function (e) {
init(project);
});
}
/*
This function filters the avaialble kernels and displays only the one corresponding to the current project.
*/
function filter_kernel(project) {
api.get_info(project, function (info) {
var env = info.env;
var arr = $("#new-menu > li").map(function () { return this.id });
var idList = arr.get();
for (var i = 0; i < idList.length; i++) {
if (idList[i].startsWith('kernel-conda-env-swanproject')) {
$('#' + idList[i]).css("display", "block");
var name = idList[i].substring(17);
// The first 17 characters correspond to 'kernel-conda-env-'
name = name.slice(0, -3);
// This will remove the '-py' at the end of the string
if (env != name) {
$('#' + idList[i]).css("display", "none");
}
else {
var toRem = "[conda env:" + name + "]";
// Substring to remove from the entry
var kernelText = $('#' + idList[i]).find('a').text();
kernelText = kernelText.replace(toRem, '');
$('#' + idList[i]).find('a').text(kernelText);
var kernelTitle = $('#' + idList[i]).find('a').attr('title');
kernelTitle = kernelTitle.replace(toRem, '');
$('#' + idList[i]).find('a').attr('title', kernelTitle);
}
}
if (idList[i].startsWith('kernel-python')) {
// This hides the default python kernels that might appear
// TODO: Check for any exceptions and handle accordingly
$('#' + idList[i]).css("display", "none");
}
}
// This hides the conda root environment
$('#kernel-conda-root-py').css("display", "none");
});
}
export {
load_ipython_extension,
show_button,
filter_kernel
}