]>
Commit | Line | Data |
---|---|---|
5fe42a7f DC |
1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
2 | From: Dominik Csapak <d.csapak@proxmox.com> | |
3 | Date: Wed, 9 Feb 2022 14:50:35 +0100 | |
4 | Subject: [PATCH] show start button on not running vm/ct | |
5 | ||
6 | by querying the 'status' api first and showing a simple startbutton | |
7 | if the status is not 'running' | |
8 | ||
9 | adds a play icon from fontawesome, since novnc had none itself | |
10 | ||
11 | css style is mostly copied from novnc "connect dialog", only the | |
12 | colors were adapted | |
13 | ||
14 | Signed-off-by: Dominik Csapak <d.csapak@proxmox.com> | |
15 | --- | |
36b6bb61 | 16 | app/pve.js | 45 +++++++++++++++++++++++++++++++---- |
ae533130 DC |
17 | app/styles/pve.css | 58 ++++++++++++++++++++++++++++++++++++++++++++++ |
18 | vnc.html | 9 +++++++ | |
36b6bb61 | 19 | 3 files changed, 107 insertions(+), 5 deletions(-) |
5fe42a7f DC |
20 | |
21 | diff --git a/app/pve.js b/app/pve.js | |
36b6bb61 | 22 | index 583a406..287615f 100644 |
5fe42a7f DC |
23 | --- a/app/pve.js |
24 | +++ b/app/pve.js | |
36b6bb61 DC |
25 | @@ -117,7 +117,7 @@ PVEUI.prototype = { |
26 | ||
27 | if (errmsg !== undefined) { | |
28 | if (reqOpts.failure) { | |
29 | - reqOpts.failure.call(scope, errmsg); | |
30 | + reqOpts.failure.call(scope, errmsg, xhr.status); | |
31 | } | |
32 | } else { | |
33 | if (reqOpts.success) { | |
b23fa193 DC |
34 | @@ -231,7 +231,7 @@ PVEUI.prototype = { |
35 | ||
36 | }, | |
37 | ||
38 | - pve_vm_command: function(cmd, params, reload) { | |
39 | + pve_vm_command: function(cmd, params, reload, mustConfirm = true) { | |
40 | var me = this; | |
41 | var baseUrl; | |
42 | var confirmMsg = ""; | |
43 | @@ -255,7 +255,7 @@ PVEUI.prototype = { | |
44 | ||
45 | confirmMsg = confirmMsg.replace('{0}', me.vmid); | |
46 | ||
47 | - if (confirmMsg !== "" && confirm(confirmMsg) !== true) { | |
48 | + if (confirmMsg !== "" && mustConfirm && confirm(confirmMsg) !== true) { | |
49 | return; | |
50 | } | |
51 | ||
aec97326 | 52 | @@ -320,6 +320,11 @@ PVEUI.prototype = { |
5fe42a7f DC |
53 | .classList.add('pve_hidden'); |
54 | } | |
55 | ||
56 | + document.getElementById("pve_start_button") | |
57 | + .addEventListener('click', function() { | |
b23fa193 | 58 | + me.pve_vm_command('start', {}, undefined, false); |
5fe42a7f DC |
59 | + }); |
60 | + | |
61 | // add command logic | |
62 | var commandArray = [ | |
63 | { cmd: 'start', kvm: 1, lxc: 1}, | |
aec97326 | 64 | @@ -368,8 +373,8 @@ PVEUI.prototype = { |
5fe42a7f DC |
65 | return { width: ow, height: oh }; |
66 | }, | |
67 | ||
68 | - pveStart: function(callback) { | |
69 | - var me = this; | |
70 | + initConnection: function(callback) { | |
71 | + let me = this; | |
72 | me.API2Request({ | |
73 | url: me.url, | |
74 | method: 'POST', | |
36b6bb61 | 75 | @@ -391,6 +396,36 @@ PVEUI.prototype = { |
5fe42a7f DC |
76 | }); |
77 | }, | |
78 | ||
79 | + pveStart: function(callback) { | |
80 | + var me = this; | |
81 | + if (me.consoletype === 'kvm' || me.consoletype === 'lxc') { | |
82 | + // check status for vms first | |
83 | + me.API2Request({ | |
84 | + url: `${me.baseUrl}/status/current`, | |
85 | + method: 'GET', | |
86 | + success: function(result) { | |
87 | + let status = result.data.status; | |
88 | + if (status === 'running') { | |
89 | + me.initConnection(callback); | |
90 | + } else { | |
91 | + document.getElementById('pve_start_dlg') | |
92 | + .classList.add("noVNC_open"); | |
93 | + } | |
94 | + }, | |
36b6bb61 DC |
95 | + failure: function(msg, code) { |
96 | + if (code === 403) { | |
97 | + // connect anyway for users with VM.Console but without VM.Audit | |
98 | + me.initConnection(callback); | |
99 | + } else { | |
100 | + me.UI.showStatus(msg, 'error'); | |
101 | + } | |
5fe42a7f DC |
102 | + } |
103 | + }); | |
104 | + } else { | |
105 | + me.initConnection(callback); | |
106 | + } | |
107 | + }, | |
108 | + | |
109 | updateFBSize: function(rfb, width, height) { | |
110 | var me = this; | |
111 | try { | |
112 | diff --git a/app/styles/pve.css b/app/styles/pve.css | |
ae533130 | 113 | index 18126b0..e0ca61f 100644 |
5fe42a7f DC |
114 | --- a/app/styles/pve.css |
115 | +++ b/app/styles/pve.css | |
116 | @@ -44,3 +44,61 @@ | |
117 | .noVNC_button.pve_hidden { | |
118 | display: none; | |
119 | } | |
120 | + | |
121 | +/* start button */ | |
122 | +#pve_start_dlg { | |
18fa9537 | 123 | + transition: 0.2s ease-in-out; |
5fe42a7f DC |
124 | + transform: scale(0, 0); |
125 | + visibility: hidden; | |
126 | + opacity: 0; | |
127 | +} | |
128 | + | |
129 | +#pve_start_dlg.noVNC_open { | |
130 | + transform: scale(1, 1); | |
131 | + visibility: visible; | |
132 | + opacity: 1; | |
133 | +} | |
134 | + | |
135 | +#pve_start_info { | |
136 | + color: white; | |
137 | + text-align: center; | |
138 | + font-size: 20px; | |
139 | + padding: 6px; | |
140 | +} | |
141 | + | |
142 | +#pve_start_button { | |
143 | + cursor: pointer; | |
144 | + padding: 6px; | |
145 | + color: white; | |
146 | + background:#4c4c4c;; | |
147 | + border-radius: 8px; | |
148 | + text-align: center; | |
149 | + font-size: 20px; | |
150 | + box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.5); | |
151 | +} | |
152 | + | |
153 | +#pve_start_button div { | |
154 | + margin: 2px; | |
155 | + padding: 5px 30px; | |
156 | + border: 1px solid #2f2f2f; | |
157 | + border-bottom-width: 2px; | |
158 | + border-radius: 5px; | |
159 | + background:#4c4c4c;; | |
160 | + | |
161 | + /* This avoids it jumping around when :active */ | |
162 | + vertical-align: middle; | |
163 | +} | |
164 | + | |
165 | +#pve_start_button div:active { | |
166 | + border-bottom-width: 1px; | |
167 | + margin-top: 3px; | |
168 | +} | |
169 | + | |
170 | +:root:not(.noVNC_touch) #pve_start_button div:hover { | |
171 | + background: rgba(255, 255, 255, 0.2); | |
172 | +} | |
173 | + | |
174 | +#pve_start_button img { | |
175 | + vertical-align: bottom; | |
176 | + padding: 0 5px 2px 0; | |
177 | +} | |
178 | diff --git a/vnc.html b/vnc.html | |
ae533130 | 179 | index 3e63087..f0488b1 100644 |
5fe42a7f DC |
180 | --- a/vnc.html |
181 | +++ b/vnc.html | |
ae533130 | 182 | @@ -281,6 +281,15 @@ |
5fe42a7f DC |
183 | </div> |
184 | </div> | |
185 | ||
186 | + <div class="noVNC_center"> | |
187 | + <div id="pve_start_dlg"> | |
188 | + <div id="pve_start_info">Guest not running</div> | |
189 | + <div id="pve_start_button"><div> | |
190 | + <img alt="" src="/novnc/app/images/power.svg"> Start Now | |
191 | + </div></div> | |
192 | + </div> | |
193 | + </div> | |
194 | + | |
195 | <!-- Password Dialog --> | |
196 | <div class="noVNC_center noVNC_connect_layer"> | |
197 | <div id="noVNC_credentials_dlg" class="noVNC_panel"><form> |