##// END OF EJS Templates
min and default for engine number
Matthias BUSSONNIER -
Show More
@@ -1,180 +1,183 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // NotebookList
9 // NotebookList
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13
13
14 var ClusterList = function (selector) {
14 var ClusterList = function (selector) {
15 this.selector = selector;
15 this.selector = selector;
16 if (this.selector !== undefined) {
16 if (this.selector !== undefined) {
17 this.element = $(selector);
17 this.element = $(selector);
18 this.style();
18 this.style();
19 this.bind_events();
19 this.bind_events();
20 }
20 }
21 };
21 };
22
22
23 ClusterList.prototype.style = function () {
23 ClusterList.prototype.style = function () {
24 $('#cluster_toolbar').addClass('list_toolbar');
24 $('#cluster_toolbar').addClass('list_toolbar');
25 $('#cluster_list_info').addClass('toolbar_info');
25 $('#cluster_list_info').addClass('toolbar_info');
26 $('#cluster_buttons').addClass('toolbar_buttons');
26 $('#cluster_buttons').addClass('toolbar_buttons');
27 $('div#cluster_header').addClass('list_header ui-widget ui-widget-header ui-helper-clearfix');
27 $('div#cluster_header').addClass('list_header ui-widget ui-widget-header ui-helper-clearfix');
28 $('div#cluster_header').children().eq(0).addClass('profile_col');
28 $('div#cluster_header').children().eq(0).addClass('profile_col');
29 $('div#cluster_header').children().eq(1).addClass('action_col');
29 $('div#cluster_header').children().eq(1).addClass('action_col');
30 $('div#cluster_header').children().eq(2).addClass('engines_col');
30 $('div#cluster_header').children().eq(2).addClass('engines_col');
31 $('div#cluster_header').children().eq(3).addClass('status_col');
31 $('div#cluster_header').children().eq(3).addClass('status_col');
32 $('#refresh_cluster_list').button({
32 $('#refresh_cluster_list').button({
33 icons : {primary: 'ui-icon-arrowrefresh-1-s'},
33 icons : {primary: 'ui-icon-arrowrefresh-1-s'},
34 text : false
34 text : false
35 });
35 });
36 };
36 };
37
37
38
38
39 ClusterList.prototype.bind_events = function () {
39 ClusterList.prototype.bind_events = function () {
40 var that = this;
40 var that = this;
41 $('#refresh_cluster_list').click(function () {
41 $('#refresh_cluster_list').click(function () {
42 that.load_list();
42 that.load_list();
43 });
43 });
44 };
44 };
45
45
46
46
47 ClusterList.prototype.load_list = function () {
47 ClusterList.prototype.load_list = function () {
48 var settings = {
48 var settings = {
49 processData : false,
49 processData : false,
50 cache : false,
50 cache : false,
51 type : "GET",
51 type : "GET",
52 dataType : "json",
52 dataType : "json",
53 success : $.proxy(this.load_list_success, this)
53 success : $.proxy(this.load_list_success, this)
54 };
54 };
55 var url = $('body').data('baseProjectUrl') + 'clusters';
55 var url = $('body').data('baseProjectUrl') + 'clusters';
56 $.ajax(url, settings);
56 $.ajax(url, settings);
57 };
57 };
58
58
59
59
60 ClusterList.prototype.clear_list = function () {
60 ClusterList.prototype.clear_list = function () {
61 this.element.children('.list_item').remove();
61 this.element.children('.list_item').remove();
62 }
62 }
63
63
64 ClusterList.prototype.load_list_success = function (data, status, xhr) {
64 ClusterList.prototype.load_list_success = function (data, status, xhr) {
65 this.clear_list();
65 this.clear_list();
66 var len = data.length;
66 var len = data.length;
67 for (var i=0; i<len; i++) {
67 for (var i=0; i<len; i++) {
68 var item_div = $('<div/>');
68 var item_div = $('<div/>');
69 var item = new ClusterItem(item_div);
69 var item = new ClusterItem(item_div);
70 item.update_state(data[i]);
70 item.update_state(data[i]);
71 item_div.data('item', item);
71 item_div.data('item', item);
72 this.element.append(item_div);
72 this.element.append(item_div);
73 };
73 };
74 };
74 };
75
75
76
76
77 var ClusterItem = function (element) {
77 var ClusterItem = function (element) {
78 this.element = $(element);
78 this.element = $(element);
79 this.data = null;
79 this.data = null;
80 this.style();
80 this.style();
81 };
81 };
82
82
83
83
84 ClusterItem.prototype.style = function () {
84 ClusterItem.prototype.style = function () {
85 this.element.addClass('list_item ui-widget ui-widget-content ui-helper-clearfix');
85 this.element.addClass('list_item ui-widget ui-widget-content ui-helper-clearfix');
86 this.element.css('border-top-style','none');
86 this.element.css('border-top-style','none');
87 }
87 }
88
88
89 ClusterItem.prototype.update_state = function (data) {
89 ClusterItem.prototype.update_state = function (data) {
90 this.data = data;
90 this.data = data;
91 if (data.status === 'running') {
91 if (data.status === 'running') {
92 this.state_running();
92 this.state_running();
93 } else if (data.status === 'stopped') {
93 } else if (data.status === 'stopped') {
94 this.state_stopped();
94 this.state_stopped();
95 };
95 };
96
96
97 }
97 }
98
98
99
99
100 ClusterItem.prototype.state_stopped = function () {
100 ClusterItem.prototype.state_stopped = function () {
101 var that = this;
101 var that = this;
102 this.element.empty();
102 this.element.empty();
103 var profile_col = $('<span/>').addClass('profile_col').text(this.data.profile);
103 var profile_col = $('<span/>').addClass('profile_col').text(this.data.profile);
104 var status_col = $('<span/>').addClass('status_col').html('stopped');
104 var status_col = $('<span/>').addClass('status_col').html('stopped');
105 var engines_col = $('<span/>').addClass('engines_col');
105 var engines_col = $('<span/>').addClass('engines_col');
106 var input = $('<input/>').attr('type','number').
106 var input = $('<input/>').attr('type','number')
107 attr('size',3).addClass('engine_num_input');
107 .attr('min',1)
108 .attr('value',2)
109 .attr('size',3)
110 .addClass('engine_num_input');
108 engines_col.append(input);
111 engines_col.append(input);
109 var action_col = $('<span/>').addClass('action_col');
112 var action_col = $('<span/>').addClass('action_col');
110 var start_button = $('<button>Start</button>').button();
113 var start_button = $('<button>Start</button>').button();
111 action_col.append(start_button);
114 action_col.append(start_button);
112 this.element.append(profile_col).
115 this.element.append(profile_col).
113 append(action_col).
116 append(action_col).
114 append(engines_col).
117 append(engines_col).
115 append(status_col);
118 append(status_col);
116 start_button.click(function (e) {
119 start_button.click(function (e) {
117 var n = that.element.find('.engine_num_input').val();
120 var n = that.element.find('.engine_num_input').val();
118 if (!/^\d+$/.test(n) && n.length>0) {
121 if (!/^\d+$/.test(n) && n.length>0) {
119 status_col.html('invalid engine #');
122 status_col.html('invalid engine #');
120 } else {
123 } else {
121 var settings = {
124 var settings = {
122 cache : false,
125 cache : false,
123 data : {n:n},
126 data : {n:n},
124 type : "POST",
127 type : "POST",
125 dataType : "json",
128 dataType : "json",
126 success : function (data, status, xhr) {
129 success : function (data, status, xhr) {
127 that.update_state(data);
130 that.update_state(data);
128 },
131 },
129 error : function (data, status, xhr) {
132 error : function (data, status, xhr) {
130 status_col.html("error starting cluster")
133 status_col.html("error starting cluster")
131 }
134 }
132 };
135 };
133 status_col.html('starting');
136 status_col.html('starting');
134 var url = $('body').data('baseProjectUrl') + 'clusters/' + that.data.profile + '/start';
137 var url = $('body').data('baseProjectUrl') + 'clusters/' + that.data.profile + '/start';
135 $.ajax(url, settings);
138 $.ajax(url, settings);
136 };
139 };
137 });
140 });
138 };
141 };
139
142
140
143
141 ClusterItem.prototype.state_running = function () {
144 ClusterItem.prototype.state_running = function () {
142 this.element.empty();
145 this.element.empty();
143 var that = this;
146 var that = this;
144 var profile_col = $('<span/>').addClass('profile_col').text(this.data.profile);
147 var profile_col = $('<span/>').addClass('profile_col').text(this.data.profile);
145 var status_col = $('<span/>').addClass('status_col').html('running');
148 var status_col = $('<span/>').addClass('status_col').html('running');
146 var engines_col = $('<span/>').addClass('engines_col').html(this.data.n);
149 var engines_col = $('<span/>').addClass('engines_col').html(this.data.n);
147 var action_col = $('<span/>').addClass('action_col');
150 var action_col = $('<span/>').addClass('action_col');
148 var stop_button = $('<button>Stop</button>').button();
151 var stop_button = $('<button>Stop</button>').button();
149 action_col.append(stop_button);
152 action_col.append(stop_button);
150 this.element.append(profile_col).
153 this.element.append(profile_col).
151 append(action_col).
154 append(action_col).
152 append(engines_col).
155 append(engines_col).
153 append(status_col);
156 append(status_col);
154 stop_button.click(function (e) {
157 stop_button.click(function (e) {
155 var settings = {
158 var settings = {
156 cache : false,
159 cache : false,
157 type : "POST",
160 type : "POST",
158 dataType : "json",
161 dataType : "json",
159 success : function (data, status, xhr) {
162 success : function (data, status, xhr) {
160 that.update_state(data);
163 that.update_state(data);
161 },
164 },
162 error : function (data, status, xhr) {
165 error : function (data, status, xhr) {
163 console.log('error',data);
166 console.log('error',data);
164 status_col.html("error stopping cluster")
167 status_col.html("error stopping cluster")
165 }
168 }
166 };
169 };
167 status_col.html('stopping')
170 status_col.html('stopping')
168 var url = $('body').data('baseProjectUrl') + 'clusters/' + that.data.profile + '/stop';
171 var url = $('body').data('baseProjectUrl') + 'clusters/' + that.data.profile + '/stop';
169 $.ajax(url, settings);
172 $.ajax(url, settings);
170 });
173 });
171 };
174 };
172
175
173
176
174 IPython.ClusterList = ClusterList;
177 IPython.ClusterList = ClusterList;
175 IPython.ClusterItem = ClusterItem;
178 IPython.ClusterItem = ClusterItem;
176
179
177 return IPython;
180 return IPython;
178
181
179 }(IPython));
182 }(IPython));
180
183
General Comments 0
You need to be logged in to leave comments. Login now