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