command_proposal 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/command_proposal/_helpers.js +62 -1
- data/app/assets/javascripts/command_proposal/console.js +24 -29
- data/app/assets/javascripts/command_proposal/feed.js +27 -30
- data/app/assets/javascripts/command_proposal/terminal.js +1 -1
- data/app/helpers/command_proposal/application_helper.rb +7 -22
- data/app/helpers/command_proposal/permissions_helper.rb +1 -1
- data/app/models/command_proposal/task.rb +3 -3
- data/lib/command_proposal/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cc9baadf971edd54dc7558fbec28c8f515e9fb572975705f886b18a68693b7b
|
4
|
+
data.tar.gz: 2793d9b73e85d8e0d509974cf9b6f7ed36517c4adbfec9a23f52bbc66d4effff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b80eb953b76e09aa2dbbc62c0df2884c15833e8dd1abc4bd66141f0c6b0adc608fcbda97efb80647ec31a1d92ac20d43fda79675560815b74cd93a878a79dc5f
|
7
|
+
data.tar.gz: f26da392c2ed15eaf1f362d0e0bd131ac8c9a05df30390871acc56a9fb8543cb5e69c88816be1fc36cb78478797659222a0edf8e4945b948538f17b97e206579
|
@@ -1,4 +1,4 @@
|
|
1
|
-
function
|
1
|
+
function cmdDocReady(fn) {
|
2
2
|
// see if DOM is already available
|
3
3
|
if (document.readyState === "complete" || document.readyState === "interactive") {
|
4
4
|
// call on next available tick
|
@@ -7,3 +7,64 @@ function docReady(fn) {
|
|
7
7
|
document.addEventListener("DOMContentLoaded", fn)
|
8
8
|
}
|
9
9
|
}
|
10
|
+
|
11
|
+
function HttpClient() {
|
12
|
+
this.request = function(method, url, opts) {
|
13
|
+
var req = new XMLHttpRequest()
|
14
|
+
req.onreadystatechange = function() {
|
15
|
+
if (req.status != 0 && req.readyState == 4 && opts.done) {
|
16
|
+
opts.done(req.responseText, req.status, req)
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
req.open(method, url, true)
|
21
|
+
if (opts.headers) {
|
22
|
+
Object.keys(opts.headers).forEach(function(key) {
|
23
|
+
req.setRequestHeader(key, opts.headers[key])
|
24
|
+
})
|
25
|
+
}
|
26
|
+
req.send(opts.body)
|
27
|
+
}
|
28
|
+
|
29
|
+
this.get = function(url, opts) {
|
30
|
+
this.request("GET", url, opts)
|
31
|
+
}
|
32
|
+
|
33
|
+
this.post = function(url, opts) {
|
34
|
+
this.request("POST", url, opts)
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
function CommandQueue() {
|
39
|
+
this.queue = []
|
40
|
+
this.eventCurrentlyRunning = false
|
41
|
+
this.runningQueue = null
|
42
|
+
|
43
|
+
this.run = function() {
|
44
|
+
if (!this.eventCurrentlyRunning) {
|
45
|
+
if (this.queue.length == 0) {
|
46
|
+
clearInterval(this.runningQueue)
|
47
|
+
this.runningQueue = null
|
48
|
+
return
|
49
|
+
}
|
50
|
+
var nextEvent = this.queue.shift()
|
51
|
+
this.eventCurrentlyRunning = true
|
52
|
+
nextEvent(this)
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
this.add = function(queued_function) {
|
57
|
+
this.queue.push(queued_function)
|
58
|
+
this.process()
|
59
|
+
}
|
60
|
+
|
61
|
+
this.finish = function(ms) {
|
62
|
+
this.eventCurrentlyRunning = false
|
63
|
+
}
|
64
|
+
|
65
|
+
this.process = function() {
|
66
|
+
if (this.runningQueue) { return }
|
67
|
+
var q = this
|
68
|
+
this.runningQueue = setInterval(function() { q.run() }, 1)
|
69
|
+
}
|
70
|
+
}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
// Add tab / shift-tab for changing indents
|
2
|
-
|
2
|
+
cmdDocReady(function() {
|
3
3
|
var cmdconsole = document.querySelector(".cmd-console")
|
4
4
|
|
5
5
|
if (cmdconsole) {
|
6
6
|
var console_input = document.querySelector(".cmd-console .cmd-entry")
|
7
7
|
var lines = document.querySelector(".cmd-console .lines")
|
8
|
-
var queue =
|
8
|
+
var queue = new CommandQueue
|
9
9
|
var history_cmd_idx = undefined
|
10
10
|
var stored_entry = undefined
|
11
11
|
var commands = getPrevCommands()
|
@@ -152,43 +152,38 @@ docReady(function() {
|
|
152
152
|
if (/^[\s\n]*$/.test(line.textContent)) { return }
|
153
153
|
|
154
154
|
commands.push(line.textContent)
|
155
|
-
queue
|
155
|
+
queue.add(function(evt) {
|
156
156
|
$.rails.refreshCSRFTokens()
|
157
157
|
|
158
158
|
var params = { code: line.textContent, task_id: cmdconsole.dataset.task }
|
159
159
|
|
160
|
-
var
|
161
|
-
|
160
|
+
var client = new HttpClient()
|
161
|
+
client.post(cmdconsole.dataset.exeUrl, {
|
162
162
|
headers: {
|
163
163
|
"Content-Type": "application/json",
|
164
164
|
"X-CSRF-Token": $.rails.csrfToken()
|
165
165
|
},
|
166
|
-
body: JSON.stringify(params)
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
166
|
+
body: JSON.stringify(params),
|
167
|
+
done: function(res, status, req) {
|
168
|
+
if (status == 200) {
|
169
|
+
var json = JSON.parse(res)
|
170
|
+
var result = document.createElement("div")
|
171
|
+
result.classList.add("result")
|
172
|
+
|
173
|
+
if (json.error) {
|
174
|
+
result.classList.add("cmd-error")
|
175
|
+
result.textContent = json.error
|
176
|
+
} else {
|
177
|
+
result.textContent = json.result
|
178
|
+
}
|
179
|
+
|
180
|
+
line.appendChild(result)
|
181
|
+
} else {
|
182
|
+
console.log("Error: ", res, req);
|
183
|
+
}
|
184
|
+
evt.finish()
|
176
185
|
}
|
177
186
|
})
|
178
|
-
|
179
|
-
var json = await res
|
180
|
-
|
181
|
-
var result = document.createElement("div")
|
182
|
-
result.classList.add("result")
|
183
|
-
|
184
|
-
if (json.error) {
|
185
|
-
result.classList.add("cmd-error")
|
186
|
-
result.textContent = json.error
|
187
|
-
} else {
|
188
|
-
result.textContent = json.result
|
189
|
-
}
|
190
|
-
|
191
|
-
line.appendChild(result)
|
192
187
|
})
|
193
188
|
}
|
194
189
|
}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
cmdDocReady(function() {
|
2
2
|
var terminals = document.querySelectorAll("[data-feed]")
|
3
|
-
var queue =
|
3
|
+
var queue = new CommandQueue
|
4
4
|
var continue_statuses = ["started", "approved", "cancelling"]
|
5
5
|
|
6
6
|
terminals.forEach(function(terminal) {
|
@@ -10,42 +10,39 @@ docReady(function() {
|
|
10
10
|
})
|
11
11
|
|
12
12
|
function pingFeed(terminal) {
|
13
|
-
queue
|
13
|
+
queue.add(function(evt) {
|
14
14
|
$.rails.refreshCSRFTokens()
|
15
15
|
|
16
|
-
var
|
17
|
-
|
16
|
+
var client = new HttpClient()
|
17
|
+
client.get(terminal.dataset.feed, {
|
18
18
|
headers: {
|
19
19
|
"Content-Type": "text/html",
|
20
20
|
"X-CSRF-Token": $.rails.csrfToken()
|
21
21
|
},
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
var json = await res
|
22
|
+
done: function(res, status, req) {
|
23
|
+
if (status == 200) {
|
24
|
+
var json = JSON.parse(res)
|
25
|
+
if (terminal.nextElementSibling && terminal.nextElementSibling.CodeMirror) {
|
26
|
+
terminal.nextElementSibling.CodeMirror.doc.setValue(json.result || "")
|
27
|
+
} else {
|
28
|
+
terminal.innerHTML = json.result_html
|
29
|
+
}
|
30
|
+
document.querySelector("td[data-iteration-status]").innerText = json.status
|
31
|
+
document.querySelector("td[data-iteration-duration]").innerText = json.duration
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
if (document.querySelector(".cancel-btn")) {
|
46
|
-
document.querySelector(".cancel-btn").remove()
|
33
|
+
if (continue_statuses.includes(json.status)) {
|
34
|
+
setTimeout(function() { pingFeed(terminal) }, 1000)
|
35
|
+
} else {
|
36
|
+
if (document.querySelector(".cancel-btn")) {
|
37
|
+
document.querySelector(".cancel-btn").remove()
|
38
|
+
}
|
39
|
+
}
|
40
|
+
} else {
|
41
|
+
console.log("Error: ", res, req);
|
42
|
+
}
|
43
|
+
evt.finish()
|
47
44
|
}
|
48
|
-
}
|
45
|
+
})
|
49
46
|
})
|
50
47
|
}
|
51
48
|
})
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module CommandProposal
|
2
2
|
module ApplicationHelper
|
3
|
+
include ActionDispatch::Routing::PolymorphicRoutes
|
4
|
+
include Rails.application.routes.url_helpers
|
3
5
|
# In order to keep the regular app's routes working in the base template, we have to manually
|
4
6
|
# render the engine routes. Built a helper for this because it's long and nasty otherwise.
|
5
7
|
def cmd_path(*args)
|
@@ -19,39 +21,22 @@ module CommandProposal
|
|
19
21
|
args << { host: host, port: nil } if host.present?
|
20
22
|
|
21
23
|
begin
|
22
|
-
|
24
|
+
command_proposal_engine.url_for(args.compact)
|
23
25
|
rescue NoMethodError => e
|
24
|
-
raise "Error generating route! Please make sure `default_url_options` are set."
|
26
|
+
raise "Error generating route! Please make sure `config.action_mailer.default_url_options` are set."
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
30
|
def string_path(*args)
|
29
|
-
[
|
31
|
+
[command_proposal_engine.command_proposal_tasks_url + args.shift, args.to_param.presence].compact.join("?")
|
30
32
|
end
|
31
33
|
|
32
34
|
# Runner controller doesn't map to a model, so needs special handling
|
33
35
|
def runner_path(task, iteration=nil)
|
34
36
|
if iteration.present?
|
35
|
-
|
37
|
+
command_proposal_engine.command_proposal_task_runner_url(task, iteration)
|
36
38
|
else
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def router
|
42
|
-
@@router ||= begin
|
43
|
-
routes = ::CommandProposal::Engine.routes
|
44
|
-
routes.default_url_options = rails_default_url_options
|
45
|
-
routes.url_helpers
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def rails_default_url_options
|
50
|
-
Rails.application.config.action_mailer.default_url_options.tap do |default_opts|
|
51
|
-
default_opts ||= {}
|
52
|
-
default_opts[:host] ||= "localhost"
|
53
|
-
default_opts[:port] ||= "3000"
|
54
|
-
default_opts[:protocol] ||= "http"
|
39
|
+
command_proposal_engine.command_proposal_task_runner_index_url(task)
|
55
40
|
end
|
56
41
|
end
|
57
42
|
end
|
@@ -19,10 +19,10 @@ class ::CommandProposal::Task < ApplicationRecord
|
|
19
19
|
enum session_type: {
|
20
20
|
# Task will have multiple iterations that are all essentially the same just with code changes
|
21
21
|
task: 0,
|
22
|
-
# Console iterations are actually line by line, so order matters
|
23
|
-
console: 1,
|
24
22
|
# Function iterations are much like tasks
|
25
|
-
function:
|
23
|
+
function: 1,
|
24
|
+
# Console iterations are actually line by line, so order matters
|
25
|
+
console: 2,
|
26
26
|
# Modules are included in tasks and not run independently
|
27
27
|
module: 3,
|
28
28
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: command_proposal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rocco Nicholls
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|