1
|
define([
|
2
|
"dojo/_base/lang",
|
3
|
"dojo/_base/declare",
|
4
|
"dojo/_base/connect",
|
5
|
"dojo/dom-construct",
|
6
|
"dojo/string",
|
7
|
"dijit/form/Select",
|
8
|
"steam2/ActionGrid",
|
9
|
"steam2/ServersGridFormatters",
|
10
|
"steam2/stores",
|
11
|
"steam2/statusColorMap",
|
12
|
"steam2/models/Server",
|
13
|
"steam2/user"
|
14
|
], function(lang, declare, connect, domConstruct, string, Select, ActionGrid, formatters, stores, statusColorMap, Server, user){
|
15
|
|
16
|
return declare("steam2.ServersGrid", ActionGrid, {
|
17
|
|
18
|
store: stores.servers,
|
19
|
model: Server,
|
20
|
|
21
|
// FIXME: removed when stores are converted to JsonRestStore
|
22
|
postURL: '/stabile/servers',
|
23
|
|
24
|
summaryTemplate: "Total VCPUs: ${vcpus} (Quota: ${vcpuQuota}) Total memory: ${memory} GB (Quota: ${memoryQuota} GB)",
|
25
|
|
26
|
searchPlaceholder: user.is_admin ?
|
27
|
'Find by name, status or node' :
|
28
|
'Find by name or status',
|
29
|
|
30
|
constructor: function(args){
|
31
|
connect.connect(Server, 'onViewerStart', this, function(server){
|
32
|
this.updateRow(this.getItemIndex(server));
|
33
|
});
|
34
|
connect.connect(Server, 'onViewerStop', this, function(server){
|
35
|
this.updateRow(this.getItemIndex(server));
|
36
|
});
|
37
|
// on every fetch update the summary.
|
38
|
connect.connect(this, '_onFetchComplete', this, function(){
|
39
|
this.updateSummary();
|
40
|
});
|
41
|
connect.connect(this.store, 'onSet', this, function(){
|
42
|
this.updateSummary();
|
43
|
});
|
44
|
|
45
|
this.inherited(arguments);
|
46
|
},
|
47
|
|
48
|
postrender: function(){
|
49
|
this.inherited(arguments);
|
50
|
|
51
|
var statusFilter = new Select({
|
52
|
options: [
|
53
|
{ label: 'All', value: 'all', selected: true },
|
54
|
{ label: 'Running', value: 'running' },
|
55
|
{ label: 'Inactive', value: 'inactive' },
|
56
|
{ label: 'Shutoff', value: 'shutoff' }
|
57
|
]
|
58
|
}, this.searchFilterNode);
|
59
|
|
60
|
connect.connect(statusFilter, "onChange", this, function(status){
|
61
|
if(status === "all"){
|
62
|
delete this.queries['statusFilter'];
|
63
|
}
|
64
|
else{
|
65
|
this.queries.statusFilter = {prop:"status", value:status, type:"and"};
|
66
|
}
|
67
|
if(this._selectAllCheckBox.checked){
|
68
|
this._onFetchCompleteSelectAll();
|
69
|
}
|
70
|
this.filter(this._toJsonQuery(), /*rerender*/true);
|
71
|
});
|
72
|
this.updateSummary();
|
73
|
},
|
74
|
|
75
|
getBulkActions: function(){
|
76
|
var actions = this.inherited(arguments);
|
77
|
// always enable destroy
|
78
|
if(!actions){
|
79
|
actions = {};
|
80
|
}
|
81
|
actions.destroy = 'destroy';
|
82
|
actions.start = 'start';
|
83
|
return actions;
|
84
|
},
|
85
|
|
86
|
updateSummary: function(){
|
87
|
|
88
|
function toGb(mb){
|
89
|
return (Math.round(10*mb / 1024) / 10);
|
90
|
}
|
91
|
|
92
|
var templateArgs = {
|
93
|
vcpus : 0,
|
94
|
memory : 0,
|
95
|
vcpuQuota : user.vcpuquota,
|
96
|
memoryQuota : user.memoryquota
|
97
|
};
|
98
|
|
99
|
for(var i = 0; i < this.rowCount; i++){
|
100
|
var server = this.getItem(i);
|
101
|
if (server) {
|
102
|
if (server.isPowered()){
|
103
|
templateArgs.vcpus += (parseInt(server.vcpu));
|
104
|
templateArgs.memory += parseInt(server.memory);
|
105
|
}
|
106
|
}
|
107
|
}
|
108
|
|
109
|
// convert to GB
|
110
|
templateArgs.memory = toGb(templateArgs.memory);
|
111
|
templateArgs.memoryQuota = toGb(templateArgs.memoryQuota);
|
112
|
|
113
|
this.summaryNode.innerHTML = string.substitute(this.summaryTemplate, templateArgs);
|
114
|
},
|
115
|
|
116
|
structure: [
|
117
|
{
|
118
|
width:'20px',
|
119
|
name: '<input type="checkbox" class="gridSelectAllCheckbox"></input>',
|
120
|
formatter: function(val, rowIdx){
|
121
|
if(this.grid.selection.isSelected(rowIdx)){
|
122
|
return '<input type="checkbox" checked="checked"></input>';
|
123
|
}
|
124
|
return '<input type="checkbox"></input>';
|
125
|
},
|
126
|
hidden: user.is_readonly
|
127
|
},
|
128
|
{
|
129
|
width: '30px',
|
130
|
name: '<a href="https://www.origo.io/info/support/help/origo-stabile/servers/console" rel="help" target="_blank" class="irigo-tooltip">help</a>',
|
131
|
formatter: formatters.viewer
|
132
|
},
|
133
|
{
|
134
|
field: 'name',
|
135
|
width: '100%',
|
136
|
formatter: formatters.name
|
137
|
},
|
138
|
{
|
139
|
field: 'status',
|
140
|
name: 'Status <a href="https://www.origo.io/info/support/help/origo-stabile/servers/status" rel="help" target="_blank" class="irigo-tooltip">help</a>',
|
141
|
width: '100px',
|
142
|
formatter: formatters.status
|
143
|
},
|
144
|
{
|
145
|
field: 'vcpu',
|
146
|
width: '40px',
|
147
|
name: 'VCPUs',
|
148
|
cellStyles: 'text-align:right;'
|
149
|
},
|
150
|
{
|
151
|
field: 'memory',
|
152
|
width: '70px'
|
153
|
},
|
154
|
{
|
155
|
field: 'image',
|
156
|
name: 'Image',
|
157
|
width: '130px',
|
158
|
formatter: formatters.image
|
159
|
},
|
160
|
{
|
161
|
field: 'network',
|
162
|
name:'Network',
|
163
|
width:'100px',
|
164
|
formatter: formatters.network
|
165
|
},
|
166
|
{
|
167
|
field: 'action',
|
168
|
name: 'Action <a href="https://www.origo.io/info/support/help/origo-stabile/servers/actions" rel="help" target="_blank" class="irigo-tooltip">help</a>',
|
169
|
width: '120px',
|
170
|
formatter: formatters.action,
|
171
|
hidden: user.is_readonly
|
172
|
}
|
173
|
],
|
174
|
|
175
|
canSort: function(index){
|
176
|
if(index === 1 || index === 2 || index === 6){
|
177
|
return false;
|
178
|
}
|
179
|
return true;
|
180
|
},
|
181
|
|
182
|
setQuery: function(query){
|
183
|
this.inherited(arguments);
|
184
|
if(user.is_admin){
|
185
|
if(!query){
|
186
|
delete this.queries['macname'];
|
187
|
}
|
188
|
else{
|
189
|
this.queries['macname'] = {prop:'macname', value:query, type:'or'};
|
190
|
}
|
191
|
}
|
192
|
|
193
|
}
|
194
|
|
195
|
// onCellMouseOver: function(e){
|
196
|
// if(e.cellIndex === 0){
|
197
|
// var msg = 'Info ...';
|
198
|
// dijit.showTooltip(msg, e.cellNode);
|
199
|
// }
|
200
|
// }
|
201
|
});
|
202
|
|
203
|
});
|