Skip to content

Add dialog validate #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions openc3-cosmos-cmd-tlm-api/app/controllers/scopes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/models/scope_model'
Expand All @@ -35,15 +35,15 @@ def index
def create(update_model = false)
return unless authorization('superadmin')
super(update_model)
rescue Exception => e
render(:json => { :status => 'error', :message => e.message }, :status => 500) and return
end

def destroy
return unless authorization('superadmin')
begin
result = OpenC3::ProcessManager.instance.spawn(["ruby", "/openc3/bin/openc3cli", "destroyscope", params[:id]], "scope_uninstall", params[:id], Time.now + 2.hours, scope: 'DEFAULT')
render :json => result
rescue Exception => e
render(:json => { :status => 'error', :message => e.message }, :status => 500) and return
end
result = OpenC3::ProcessManager.instance.spawn(["ruby", "/openc3/bin/openc3cli", "destroyscope", params[:id]], "scope_uninstall", params[:id], Time.now + 2.hours, scope: 'DEFAULT')
render :json => result
rescue Exception => e
render(:json => { :status => 'error', :message => e.message }, :status => 500) and return
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.
-->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@
<v-spacer />
</v-system-bar>
<v-card-text class="pa-3">
<v-icon v-if="params.validateText" class="mr-2"> mdi-alert </v-icon>
<span v-if="params.html" v-html="params.text" class="pa-3"></span>
<span v-else>{{ params.text }}</span>
<div v-if="params.validateText" class="validate mt-4">
Enter {{ params.validateText }} to confirm!
<v-text-field
solo
dense
single-line
v-model="validationText"
:label="Confirm"
:rules="[rules.required, rules.match]"
data-test="confirm-dialog-validate"
/>
</div>
</v-card-text>
<v-card-actions>
<v-spacer />
Expand Down Expand Up @@ -44,11 +57,19 @@ export default {
title: 'Title',
text: 'The text that is displayed',
okText: 'Ok',
validateText: 'CONFIRM',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fine default. Should you be asking for the SCOPE name when deleting a scope?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I do. That change is in Enterprise code.

cancelText: 'Cancel',
html: false,
},
resolve: null,
reject: null,
validationText: null,
rules: {
required: (value) => !!value || 'Required.',
match: (value) => {
return value === this.params.validateText || 'Value mismatch.'
},
},
}
},
computed: {
Expand All @@ -67,8 +88,10 @@ export default {
this.reject = reject
},
ok: function () {
this.show = false
this.resolve(true)
if (this.params.validateText === this.validationText) {
this.show = false
this.resolve(true)
}
},
cancel: function () {
this.show = false
Expand All @@ -78,4 +101,8 @@ export default {
}
</script>

<style scoped></style>
<style scoped>
.validate {
color: #ff5252;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.
*/

Expand All @@ -42,46 +42,50 @@ class Dialog {
this.mounted = true
}

open = function ({
title,
text,
okText,
cancelText,
html,
}) {
open = function ({ title, text, okText, validateText, cancelText, html }) {
this.mount()
return new Promise((resolve, reject) => {
this.$root.dialog(
{ title, text, okText, cancelText, html },
resolve, reject
{ title, text, okText, validateText, cancelText, html },
resolve,
reject
)
})
}

confirm = function (text, {
okText = 'Ok',
cancelText = 'Cancel',
}) {
confirm = function (text, { okText = 'Ok', cancelText = 'Cancel' }) {
return this.open({
title: 'Confirm',
text: text,
okText: okText,
validateText: null,
cancelText: cancelText,
html: false,
})
}
alert = function (text, {
okText = 'Ok',
html = false,
}) {
alert = function (text, { okText = 'Ok', html = false }) {
return this.open({
title: 'Alert',
text: text,
okText: okText,
cancelText: null, // Which means no cancel
validateText: null,
cancelText: null,
html: html,
})
}
validate = function (
text,
{ okText = 'Ok', validateText = 'CONFIRM', cancelText = 'Cancel' }
) {
return this.open({
title: 'Confirm',
text: text,
okText: okText,
validateText: validateText,
cancelText: cancelText,
html: false,
})
}
}

export default {
Expand Down
14 changes: 0 additions & 14 deletions openc3-cosmos-script-runner-api/app/models/running_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -894,20 +894,6 @@ def debug(debug_text)
end
end

# TODO: Do we still want a 'Locals' button ... not sure how useful this is
# @locals_button = Qt::PushButton.new('Locals')
# @locals_button.connect(SIGNAL('clicked(bool)')) do
# next unless @script_binding
# @locals_button.setEnabled(false)
# vars = @script_binding.local_variables.map(&:to_s)
# puts "Locals: #{vars.reject {|x| INSTANCE_VARS.include?(x)}.sort.join(', ')}"
# while @output_io.string[-1..-1] == "\n"
# Qt::CoreApplication.processEvents()
# end
# @locals_button.setEnabled(true)
# end
# @debug_frame.addWidget(@locals_button)

def self.set_breakpoint(filename, line_number)
@@breakpoints[filename] ||= {}
@@breakpoints[filename][line_number] = true
Expand Down
4 changes: 3 additions & 1 deletion openc3/lib/openc3/models/microservice_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/top_level'
Expand Down Expand Up @@ -236,6 +236,8 @@ def undeploy
@bucket.delete_object(bucket: ENV['OPENC3_CONFIG_BUCKET'], key: object.key)
end
ConfigTopic.write({ kind: 'deleted', type: 'microservice', name: @name, plugin: @plugin }, scope: @scope)
rescue Exception => error
Logger.error("Error undeploying microservice model #{@name} in scope #{@scope} due to #{error}")
end
end
end
6 changes: 6 additions & 0 deletions openc3/lib/openc3/models/scope_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

require 'openc3/version'
require 'openc3/models/model'
require 'openc3/models/plugin_model'
require 'openc3/models/microservice_model'
require 'openc3/models/settings_model'

Expand Down Expand Up @@ -182,6 +183,11 @@ def undeploy
model.destroy if model
model = MicroserviceModel.get_model(name: "#{@scope}__PACKETLOG__UNKNOWN", scope: @scope)
model.destroy if model
# Delete the topics we created for the scope
Topic.del("#{@scope}__COMMAND__{UNKNOWN}__UNKNOWN")
Topic.del("#{@scope}__TELEMETRY__{UNKNOWN}__UNKNOWN")
Topic.del("#{@scope}__openc3_targets")
Topic.del("#{@scope}__CONFIG")
end

def seed_database
Expand Down
26 changes: 1 addition & 25 deletions openc3/lib/openc3/packets/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/packets/packet_config'
Expand Down Expand Up @@ -297,30 +297,6 @@ def clear_counters
end
end

# Returns an array with a "TARGET_NAME PACKET_NAME" string for every command in the system (PACKET_NAME == command name)
def all_packet_strings(include_hidden = false, splash = nil)
strings = []
tnames = target_names()
total = tnames.length.to_f
tnames.each_with_index do |target_name, index|
if splash
splash.message = "Processing #{target_name} command"
splash.progress = index / total
end

# TODO: This wasn't being used ... should it be
# ignored_items = System.targets[target_name].ignored_items

packets(target_name).each do |command_name, packet|
# We don't audit against hidden or disabled packets/commands
next if !include_hidden and (packet.hidden || packet.disabled)

strings << "#{target_name} #{command_name}"
end
end
strings
end

def all
@config.commands
end
Expand Down
1 change: 0 additions & 1 deletion openc3/lib/openc3/script/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module Script
private

# Format the command like it appears in a script
# TODO: Make this output alternative syntax if any binary data
def _cmd_string(target_name, cmd_name, cmd_params, raw)
output_string = $disconnect ? 'DISCONNECT: ' : ''
if raw
Expand Down
1 change: 0 additions & 1 deletion openc3/lib/openc3/topics/command_topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def self.send_command(command, timeout: COMMAND_ACK_TIMEOUT_S, scope:)
command['cmd_params'] = JSON.generate(command['cmd_params'].as_json(:allow_nan => true))
OpenC3.inject_context(command)
cmd_id = Topic.write_topic("{#{scope}__CMD}TARGET__#{command['target_name']}", command, '*', 100)
# TODO: This timeout is fine for most but can we get the write_timeout from the interface here?
time = Time.now
while (Time.now - time) < timeout
Topic.read_topics([ack_topic]) do |topic, msg_id, msg_hash, redis|
Expand Down
2 changes: 1 addition & 1 deletion openc3/lib/openc3/utilities/store_autoload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def read_topics(topics, offsets = nil, timeout_ms = 1000, count = nil)
# @return [String] the entry id
def write_topic(topic, msg_hash, id = '*', maxlen = nil, approximate = 'true')
id = '*' if id.nil?
# Logger.debug "write_topic topic:#{topic} id:#{id} hash:#{msg_hash}"
Logger.debug "write_topic topic:#{topic} id:#{id} hash:#{msg_hash}"
@redis_pool.with do |redis|
return redis.xadd(topic, msg_hash, id: id, maxlen: maxlen, approximate: approximate)
end
Expand Down
27 changes: 26 additions & 1 deletion openc3/spec/models/scope_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'spec_helper'
Expand Down Expand Up @@ -92,5 +92,30 @@ module OpenC3
expect(Store.exists("DEFAULT__TELEMETRY__{UNKNOWN}__UNKNOWN")).to eql 1
end
end

describe "destroy" do
it "destroys the scope and all microservices" do
s3 = instance_double("Aws::S3::Client")
allow(Aws::S3::Client).to receive(:new).and_return(s3)
options = OpenStruct.new
options.key = "blah"
objs = double("Object", :contents => [options], is_truncated: false)

scope = "TEST"
allow(s3).to receive(:list_objects_v2).and_return(objs)
allow(s3).to receive(:delete_object).with(bucket: 'config', key: "blah")

dir = File.join(SPEC_DIR, "install")
model = ScopeModel.new(name: scope, updated_at: 12345)
model.create
model.deploy(dir, {})

topics = EphemeralStore.scan_each(match: "#{scope}*", type: 'stream', count: 100).to_a.uniq.sort
expect(topics).to eql(%w(TEST__COMMAND__{UNKNOWN}__UNKNOWN TEST__CONFIG TEST__TELEMETRY__{UNKNOWN}__UNKNOWN TEST__openc3_targets))
model.destroy
topics = EphemeralStore.scan_each(match: "#{scope}*", type: 'stream', count: 100).to_a.uniq.sort
expect(topics).to eql([])
end
end
end
end
6 changes: 3 additions & 3 deletions openc3/spec/operators/microservice_operator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'spec_helper'
require 'openc3/operators/microservice_operator'
require 'openc3/utilities/aws_bucket'

# Override at_exit to do nothing for testing
saved_verbose = $VERBOSE; $VERBOSE = nil
Expand Down Expand Up @@ -117,8 +118,7 @@ module OpenC3
expect(stdout.string.scan(/Starting.*ruby.*while.rb/).size).to be > 1
# We should see Soft and Hard stopping
expect(stdout.string.scan(/Soft shutting down.*ruby.*while.rb/).size).to eq 1
# TODO: This is flaky in jenkins
# expect(stdout.string.scan(/Hard shutting down.*ruby.*while.rb/).size).to eq 1
expect(stdout.string.scan(/Hard shutting down.*ruby.*while.rb/).size).to eq 1
end
end

Expand Down
4 changes: 1 addition & 3 deletions openc3/spec/script/suite_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'spec_helper'
Expand Down Expand Up @@ -86,8 +86,6 @@ def test_image2

def test_image3
OpenC3::Group.puts "#{OpenC3::Group.current_suite}::#{OpenC3::Group.current_group}::#{OpenC3::Group.current_script}"
# TODO: Real scripts don't have to qualify StopScript with OpenC3::
# Why do we have to do it here?
raise OpenC3::StopScript if $stop_script

puts "more"
Expand Down