Apply same dialog-view relationship to legacy UI
This commit is contained in:
@@ -41,6 +41,7 @@ module SpeckleConnector
|
||||
def send_messages!
|
||||
queue = @state.speckle_state.message_queue
|
||||
queue.each_value do |value|
|
||||
# FIXME: here need to identify message scope
|
||||
ui_controller.user_interfaces.each_value do |dialog|
|
||||
dialog.execute_script(value)
|
||||
end
|
||||
|
||||
@@ -48,7 +48,7 @@ module SpeckleConnector
|
||||
base_binding_view = Ui::BaseBindingView.new(app)
|
||||
|
||||
dui3_dialog = SpeckleConnector::Ui::DUI3Dialog.new(**dialog_specs)
|
||||
dui3_dialog.views[Ui::BASE_BINDING] = base_binding_view
|
||||
dui3_dialog.views[Ui::BASE_BINDING_VIEW] = base_binding_view
|
||||
app.ui_controller.register_ui(SPECKLE_DUI3, dui3_dialog)
|
||||
dui3_dialog.show
|
||||
end
|
||||
|
||||
@@ -11,6 +11,8 @@ module SpeckleConnector
|
||||
# Command to initialize old Speckle UI and register it to ui_controller.
|
||||
# This is the command where we show UI to user.
|
||||
class InitializeSpeckle < Command
|
||||
SPECKLE_LEGACY_UI = 'speckle_legacy_ui'
|
||||
|
||||
def dialog_title
|
||||
"Speckle #{CONNECTOR_VERSION}"
|
||||
end
|
||||
@@ -19,8 +21,8 @@ module SpeckleConnector
|
||||
|
||||
def _run
|
||||
app = self.app
|
||||
if !app.state.instance_of?(States::InitialState) && app.ui_controller.user_interfaces[Ui::SPECKLE_UI_ID]
|
||||
vue_view = app.ui_controller.user_interfaces[Ui::SPECKLE_UI_ID]
|
||||
if !app.state.instance_of?(States::InitialState) && app.ui_controller.user_interfaces[SPECKLE_LEGACY_UI]
|
||||
vue_view = app.ui_controller.user_interfaces[SPECKLE_LEGACY_UI]
|
||||
vue_view.show
|
||||
return
|
||||
end
|
||||
@@ -36,15 +38,17 @@ module SpeckleConnector
|
||||
observers = Observers::Factory.create_observers(observer_handler)
|
||||
app.update_state!(Actions::InitializeSpeckle, observers)
|
||||
dialog_specs = {
|
||||
dialog_id: Ui::SPECKLE_UI_ID,
|
||||
dialog_id: SPECKLE_LEGACY_UI,
|
||||
htm_file: Ui::VUE_UI_HTML,
|
||||
dialog_title: dialog_title,
|
||||
height: 950,
|
||||
width: 300
|
||||
}
|
||||
vue_view = Ui::VueView.new(dialog_specs, app)
|
||||
app.ui_controller.register_ui(Ui::SPECKLE_UI_ID, vue_view)
|
||||
vue_view.show
|
||||
legacy_ui_dialog = SpeckleConnector::Ui::Dialog.new(**dialog_specs)
|
||||
vue_view = Ui::VueView.new(app)
|
||||
legacy_ui_dialog.views[Ui::SPECKLE_LEGACY_VIEW_ID] = vue_view
|
||||
app.ui_controller.register_ui(SPECKLE_LEGACY_UI, legacy_ui_dialog)
|
||||
legacy_ui_dialog.show
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ require_relative '../actions/get_source_app_name'
|
||||
|
||||
module SpeckleConnector
|
||||
module Ui
|
||||
BASE_BINDING = 'baseBinding'
|
||||
BASE_BINDING_VIEW = 'baseBinding'
|
||||
|
||||
# View that provided by vue.js
|
||||
class BaseBindingView < View
|
||||
|
||||
@@ -11,10 +11,12 @@ module SpeckleConnector
|
||||
height: 400, width: 600, min_width: 250, min_height: 50
|
||||
}.freeze
|
||||
|
||||
# @param commands [Hash{Symbol=>Object}] commands that are sent from the HTMLDialog
|
||||
# @return views [Hash{String=>Ui::View}] views that responsible to run upcoming commands
|
||||
attr_reader :views
|
||||
|
||||
# @param specs [Hash] the specifications that will be passed to {UI::HTMLDialog}
|
||||
def initialize(commands:, dialog_id:, htm_file:, **specs)
|
||||
@commands = commands
|
||||
def initialize(dialog_id:, htm_file:, **specs)
|
||||
@views = {}
|
||||
@id = dialog_id
|
||||
@htm_file = htm_file
|
||||
@dialog_specs = DEFAULT_SPECS.merge(
|
||||
@@ -27,6 +29,12 @@ module SpeckleConnector
|
||||
@ready
|
||||
end
|
||||
|
||||
def update_views(state)
|
||||
views.each_value do |view|
|
||||
view.update_view(state)
|
||||
end
|
||||
end
|
||||
|
||||
# Show dialog if it's not visible yet
|
||||
def show
|
||||
bring_to_front if html_dialog.visible?
|
||||
@@ -78,7 +86,7 @@ module SpeckleConnector
|
||||
true
|
||||
end
|
||||
# File.exist?(@htm_file) ? dialog.set_file(@htm_file) : dialog.set_url('http://localhost:8081')
|
||||
dialog.set_url('http://localhost:8083') # uncomment this line if you want to use your local version of ui
|
||||
dialog.set_url('http://localhost:8081') # uncomment this line if you want to use your local version of ui
|
||||
add_exec_callback(dialog)
|
||||
dialog
|
||||
end
|
||||
@@ -107,7 +115,8 @@ module SpeckleConnector
|
||||
puts '### COMMAND CALLED BY DIALOG ###'
|
||||
puts "name: #{cmd.name}"
|
||||
@ready = true if cmd.name == DIALOG_READY
|
||||
@commands[cmd.name].run(cmd.resolve_id, cmd.data)
|
||||
# We have single view for legacy UI
|
||||
@views[SPECKLE_LEGACY_VIEW_ID].commands[cmd.name].run(cmd.resolve_id, cmd.data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,31 +34,19 @@ require_relative '../actions/clear_mapper_source'
|
||||
|
||||
module SpeckleConnector
|
||||
module Ui
|
||||
SPECKLE_UI_ID = 'speckle_ui'
|
||||
SPECKLE_LEGACY_VIEW_ID = 'speckle_legacy_view'
|
||||
VUE_UI_HTML = Pathname.new(File.join(SPECKLE_SRC_PATH, '..', 'vue_ui', 'index.html')).cleanpath.to_s
|
||||
|
||||
# View that provided by vue.js
|
||||
class VueView < View
|
||||
CMD_UPDATE_VIEW = 'speckle.updateView'
|
||||
|
||||
# @param dialog_specs [Hash] the specifications for the {SpeckleConnector::Ui::Dialog}.
|
||||
# @param app [App::SpeckleConnectorApp] the reference to the app object
|
||||
def initialize(dialog_specs, app)
|
||||
def initialize( app)
|
||||
super()
|
||||
@dialog_specs = dialog_specs
|
||||
@app = app
|
||||
end
|
||||
|
||||
# Show the HTML dialog
|
||||
def show
|
||||
dialog.show
|
||||
end
|
||||
|
||||
# @return [SpeckleConnector::Ui::Dialog] wrapper for the {Sketchup::HTMLDialog}
|
||||
def dialog
|
||||
@dialog ||= SpeckleConnector::Ui::Dialog.new(commands: commands, **@dialog_specs)
|
||||
end
|
||||
|
||||
def update_view(_state)
|
||||
# TODO: If you want to send data to dialog additionally, consume this method.
|
||||
# App object triggers this method by ui_controller
|
||||
|
||||
Reference in New Issue
Block a user