Show More
@@ -1,112 +1,113 b'' | |||
|
1 | 1 | // Copyright (c) IPython Development Team. |
|
2 | 2 | // Distributed under the terms of the Modified BSD License. |
|
3 | 3 | |
|
4 | 4 | define([ |
|
5 | 5 | 'jquery', |
|
6 | 6 | 'base/js/namespace', |
|
7 | 7 | 'base/js/utils', |
|
8 | 8 | 'base/js/dialog', |
|
9 | 9 | ], function ($, IPython, utils, dialog) { |
|
10 | 10 | "use strict"; |
|
11 | 11 | |
|
12 | 12 | var NewNotebookWidget = function (selector, options) { |
|
13 | 13 | this.selector = selector; |
|
14 | 14 | this.base_url = options.base_url; |
|
15 | 15 | this.notebook_path = options.notebook_path; |
|
16 | 16 | this.contents = options.contents; |
|
17 | 17 | this.current_selection = null; |
|
18 | 18 | this.kernelspecs = {}; |
|
19 | 19 | if (this.selector !== undefined) { |
|
20 | 20 | this.element = $(selector); |
|
21 | 21 | this.request_kernelspecs(); |
|
22 | 22 | } |
|
23 | 23 | this.bind_events(); |
|
24 | 24 | }; |
|
25 | 25 | |
|
26 | 26 | NewNotebookWidget.prototype.bind_events = function () { |
|
27 | 27 | var that = this; |
|
28 | 28 | this.element.find('#new_notebook').click(function () { |
|
29 | 29 | that.new_notebook(); |
|
30 | 30 | }); |
|
31 | 31 | }; |
|
32 | 32 | |
|
33 | 33 | NewNotebookWidget.prototype.request_kernelspecs = function () { |
|
34 | 34 | /** request and then load kernel specs */ |
|
35 | 35 | var url = utils.url_join_encode(this.base_url, 'api/kernelspecs'); |
|
36 | 36 | utils.promising_ajax(url).then($.proxy(this._load_kernelspecs, this)); |
|
37 | 37 | }; |
|
38 | 38 | |
|
39 | 39 | NewNotebookWidget.prototype._load_kernelspecs = function (data) { |
|
40 | 40 | /** load kernelspec list */ |
|
41 | 41 | this.kernelspecs = {}; |
|
42 | 42 | var menu = this.element.find("#new-notebook-menu"); |
|
43 | 43 | for (var i = 0; i < data.length; i++) { |
|
44 | 44 | var ks = data[i]; |
|
45 | 45 | this.kernelspecs[ks.name] = ks; |
|
46 | 46 | var ksentry = $("<li>").attr("id", "kernel-" +ks.name).append($('<a>') |
|
47 | 47 | .attr('href', '#') |
|
48 | 48 | .click($.proxy(this.new_with_kernel, this, ks.name)) |
|
49 | 49 | .text(ks.display_name) |
|
50 | 50 | .attr('title', 'Create a new notebook with ' + ks.display_name) |
|
51 | 51 | ); |
|
52 | 52 | menu.append(ksentry); |
|
53 | 53 | } |
|
54 | 54 | this._load_default_kernelspec(); |
|
55 | 55 | }; |
|
56 | 56 | |
|
57 | 57 | NewNotebookWidget.prototype._load_default_kernelspec = function () { |
|
58 | 58 | /** load default kernelspec name from localStorage, if defined */ |
|
59 | 59 | this.select_kernel(localStorage.default_kernel_name); |
|
60 | 60 | }; |
|
61 | 61 | |
|
62 | 62 | NewNotebookWidget.prototype.select_kernel = function (kernel_name) { |
|
63 | 63 | /** select the current default kernel */ |
|
64 | 64 | this.current_selection = kernel_name; |
|
65 | 65 | var spec = this.kernelspecs[kernel_name]; |
|
66 | 66 | var display_name; |
|
67 | 67 | if (spec) { |
|
68 | 68 | display_name = spec.display_name; |
|
69 | 69 | localStorage.default_kernel_name = kernel_name; |
|
70 | this.element.find("#current-kernel").text(display_name); | |
|
70 | 71 | } else { |
|
71 | 72 | display_name = 'default kernel'; |
|
72 | 73 | delete localStorage.default_kernel_name; |
|
73 | 74 | } |
|
74 | 75 | this.element.find("#new_notebook").attr('title', |
|
75 | 76 | 'Create a new notebook with ' + display_name |
|
76 | 77 | ); |
|
77 | 78 | }; |
|
78 | 79 | |
|
79 | 80 | NewNotebookWidget.prototype.new_with_kernel = function (kernel_name) { |
|
80 | 81 | /** record current selection and open a new notebook */ |
|
81 | 82 | this.select_kernel(kernel_name); |
|
82 | 83 | this.new_notebook(kernel_name); |
|
83 | 84 | }; |
|
84 | 85 | |
|
85 | 86 | NewNotebookWidget.prototype.new_notebook = function (kernel_name) { |
|
86 | 87 | /** create and open a new notebook */ |
|
87 | 88 | var that = this; |
|
88 | 89 | kernel_name = kernel_name || this.current_selection; |
|
89 | 90 | var w = window.open(); |
|
90 | 91 | this.contents.new_untitled(that.notebook_path, {type: "notebook"}).then( |
|
91 | 92 | function (data) { |
|
92 | 93 | var url = utils.url_join_encode( |
|
93 | 94 | that.base_url, 'notebooks', data.path |
|
94 | 95 | ); |
|
95 | 96 | if (kernel_name) { |
|
96 | 97 | url += "?kernel_name=" + kernel_name; |
|
97 | 98 | } |
|
98 | 99 | w.location = url; |
|
99 | 100 | }, |
|
100 | 101 | function (error) { |
|
101 | 102 | w.close(); |
|
102 | 103 | dialog.modal({ |
|
103 | 104 | title : 'Creating Notebook Failed', |
|
104 | 105 | body : "The error was: " + error.message, |
|
105 | 106 | buttons : {'OK' : {'class' : 'btn-primary'}} |
|
106 | 107 | }); |
|
107 | 108 | } |
|
108 | 109 | ); |
|
109 | 110 | }; |
|
110 | 111 | |
|
111 | 112 | return {'NewNotebookWidget': NewNotebookWidget}; |
|
112 | 113 | }); |
@@ -1,152 +1,153 b'' | |||
|
1 | 1 | {% extends "page.html" %} |
|
2 | 2 | |
|
3 | 3 | {% block title %}{{page_title}}{% endblock %} |
|
4 | 4 | |
|
5 | 5 | |
|
6 | 6 | {% block stylesheet %} |
|
7 | 7 | {{super()}} |
|
8 | 8 | <link rel="stylesheet" href="{{ static_url("tree/css/override.css") }}" type="text/css" /> |
|
9 | 9 | {% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block params %} |
|
12 | 12 | |
|
13 | 13 | data-base-url="{{base_url}}" |
|
14 | 14 | data-notebook-path="{{notebook_path}}" |
|
15 | 15 | data-terminals-available="{{terminals_available}}" |
|
16 | 16 | |
|
17 | 17 | {% endblock %} |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | {% block site %} |
|
21 | 21 | |
|
22 | 22 | <div id="ipython-main-app" class="container"> |
|
23 | 23 | |
|
24 | 24 | <div id="tab_content" class="tabbable"> |
|
25 | 25 | <ul id="tabs" class="nav nav-tabs"> |
|
26 | 26 | <li class="active"><a href="#notebooks" data-toggle="tab">Notebooks</a></li> |
|
27 | 27 | <li><a href="#running" data-toggle="tab">Running</a></li> |
|
28 | 28 | {% if terminals_available %} |
|
29 | 29 | <li><a href="#terminals" data-toggle="tab">Terminals</a></li> |
|
30 | 30 | {% endif %} |
|
31 | 31 | <li><a href="#clusters" data-toggle="tab">Clusters</a></li> |
|
32 | 32 | </ul> |
|
33 | 33 | |
|
34 | 34 | <div class="tab-content"> |
|
35 | 35 | <div id="notebooks" class="tab-pane active"> |
|
36 | 36 | <div id="notebook_toolbar" class="row"> |
|
37 | 37 | <div class="col-sm-8 no-padding"> |
|
38 | 38 | <form id='alternate_upload' class='alternate_upload' > |
|
39 | 39 | <span id="notebook_list_info" style="position:absolute" > |
|
40 | 40 | To import a notebook, drag the file onto the listing below or <strong>click here</strong>. |
|
41 | 41 | </span> |
|
42 | 42 | <input type="file" name="datafile" class="fileinput" multiple='multiple'> |
|
43 | 43 | </form> |
|
44 | 44 | </div> |
|
45 | 45 | <div class="col-sm-4 no-padding tree-buttons"> |
|
46 | 46 | <span id="notebook_buttons" class="pull-right"> |
|
47 | 47 | <div id="new-notebook-buttons" class="btn-group"> |
|
48 | 48 | <button id="new_notebook" class="btn btn-default btn-xs"> |
|
49 | 49 | New Notebook |
|
50 | 50 | </button> |
|
51 | 51 | <button class="dropdown-toggle btn btn-default btn-xs" data-toggle="dropdown"> |
|
52 | <span id="current-kernel"></span> | |
|
52 | 53 | <span class="caret"></span> |
|
53 | 54 | </button> |
|
54 | 55 | <ul id="new-notebook-menu" class="dropdown-menu"></ul> |
|
55 | 56 | </div> |
|
56 | 57 | |
|
57 | 58 | |
|
58 | 59 | <button id="refresh_notebook_list" title="Refresh notebook list" class="btn btn-default btn-xs"><i class="fa fa-refresh"></i></button> |
|
59 | 60 | </span> |
|
60 | 61 | </div> |
|
61 | 62 | </div> |
|
62 | 63 | |
|
63 | 64 | <div id="notebook_list"> |
|
64 | 65 | <div id="notebook_list_header" class="row list_header"> |
|
65 | 66 | <div id="project_name"> |
|
66 | 67 | <ul class="breadcrumb"> |
|
67 | 68 | <li><a href="{{breadcrumbs[0][0]}}"><i class="fa fa-home"></i></a></li> |
|
68 | 69 | {% for crumb in breadcrumbs[1:] %} |
|
69 | 70 | <li><a href="{{crumb[0]}}">{{crumb[1]}}</a></li> |
|
70 | 71 | {% endfor %} |
|
71 | 72 | </ul> |
|
72 | 73 | </div> |
|
73 | 74 | </div> |
|
74 | 75 | </div> |
|
75 | 76 | </div> |
|
76 | 77 | |
|
77 | 78 | <div id="running" class="tab-pane"> |
|
78 | 79 | |
|
79 | 80 | <div id="running_toolbar" class="row"> |
|
80 | 81 | <div class="col-sm-8 no-padding"> |
|
81 | 82 | <span id="running_list_info">Currently running IPython notebooks</span> |
|
82 | 83 | </div> |
|
83 | 84 | <div class="col-sm-4 no-padding tree-buttons"> |
|
84 | 85 | <span id="running_buttons" class="pull-right"> |
|
85 | 86 | <button id="refresh_running_list" title="Refresh running list" class="btn btn-default btn-xs"><i class="fa fa-refresh"></i></button> |
|
86 | 87 | </span> |
|
87 | 88 | </div> |
|
88 | 89 | </div> |
|
89 | 90 | |
|
90 | 91 | <div id="running_list"> |
|
91 | 92 | <div id="running_list_header" class="row list_header"> |
|
92 | 93 | <div> There are no notebooks running. </div> |
|
93 | 94 | </div> |
|
94 | 95 | </div> |
|
95 | 96 | </div> |
|
96 | 97 | |
|
97 | 98 | {% if terminals_available %} |
|
98 | 99 | <div id="terminals" class="tab-pane"> |
|
99 | 100 | |
|
100 | 101 | <div id="terminal_toolbar" class="row"> |
|
101 | 102 | <div class="col-xs-8 no-padding"> |
|
102 | 103 | <span id="terminal_list_info">Currently running terminals</span> |
|
103 | 104 | </div> |
|
104 | 105 | <div class="col-xs-4 no-padding tree-buttons"> |
|
105 | 106 | <span id="terminal_buttons" class="pull-right"> |
|
106 | 107 | <button id="new_terminal" title="New terminal" class="btn btn-default btn-xs">New Terminal</button> |
|
107 | 108 | <button id="refresh_terminal_list" title="Refresh terminal list" class="btn btn-default btn-xs"><i class="fa fa-refresh"></i></button> |
|
108 | 109 | </span> |
|
109 | 110 | </div> |
|
110 | 111 | </div> |
|
111 | 112 | |
|
112 | 113 | <div id="terminal_list"> |
|
113 | 114 | <div id="terminal_list_header" class="row list_header"> |
|
114 | 115 | <div> There are no terminals running. </div> |
|
115 | 116 | </div> |
|
116 | 117 | </div> |
|
117 | 118 | </div> |
|
118 | 119 | {% endif %} |
|
119 | 120 | |
|
120 | 121 | <div id="clusters" class="tab-pane"> |
|
121 | 122 | |
|
122 | 123 | <div id="cluster_toolbar" class="row"> |
|
123 | 124 | <div class="col-xs-8 no-padding"> |
|
124 | 125 | <span id="cluster_list_info">IPython parallel computing clusters</span> |
|
125 | 126 | </div> |
|
126 | 127 | <div class="col-xs-4 no-padding tree-buttons"> |
|
127 | 128 | <span id="cluster_buttons" class="pull-right"> |
|
128 | 129 | <button id="refresh_cluster_list" title="Refresh cluster list" class="btn btn-default btn-xs"><i class="fa fa-refresh"></i></button> |
|
129 | 130 | </span> |
|
130 | 131 | </div> |
|
131 | 132 | </div> |
|
132 | 133 | |
|
133 | 134 | <div id="cluster_list"> |
|
134 | 135 | <div id="cluster_list_header" class="row list_header"> |
|
135 | 136 | <div class="profile_col col-xs-4">profile</div> |
|
136 | 137 | <div class="status_col col-xs-3">status</div> |
|
137 | 138 | <div class="engines_col col-xs-3" title="Enter the number of engines to start or empty for default"># of engines</div> |
|
138 | 139 | <div class="action_col col-xs-2">action</div> |
|
139 | 140 | </div> |
|
140 | 141 | </div> |
|
141 | 142 | </div> |
|
142 | 143 | </div> |
|
143 | 144 | |
|
144 | 145 | </div> |
|
145 | 146 | |
|
146 | 147 | {% endblock %} |
|
147 | 148 | |
|
148 | 149 | {% block script %} |
|
149 | 150 | {{super()}} |
|
150 | 151 | |
|
151 | 152 | <script src="{{ static_url("tree/js/main.js") }}" type="text/javascript" charset="utf-8"></script> |
|
152 | 153 | {% endblock %} |
General Comments 0
You need to be logged in to leave comments.
Login now