Fix: various papercuts (#409)
* Do not report converted grouped meshes * remember last selected account on db
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../action'
|
||||
require_relative '../../preferences/preferences'
|
||||
|
||||
module SpeckleConnector3
|
||||
module Actions
|
||||
class GetUserSelectedAccountId < Action
|
||||
# @param state [States::State] the current state of the {App::SpeckleConnectorApp}
|
||||
# @return [States::State] the new updated state object
|
||||
def self.update_state(state, resolve_id)
|
||||
user_selected_account_id = Preferences.get_user_selected_account_id
|
||||
accountsConfig = {
|
||||
userSelectedAccountId: user_selected_account_id
|
||||
}
|
||||
js_script = "configBinding.receiveResponse('#{resolve_id}', #{accountsConfig.to_json})"
|
||||
state.with_add_queue_js_command('getUserSelectedAccountId', js_script)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../action'
|
||||
require_relative '../../preferences/preferences'
|
||||
|
||||
module SpeckleConnector3
|
||||
module Actions
|
||||
class SetUserSelectedAccountId < Action
|
||||
# @param state [States::State] the current state of the {App::SpeckleConnectorApp}
|
||||
# @return [States::State] the new updated state object
|
||||
def self.update_state(state, resolve_id, account_id)
|
||||
Preferences.set_user_selected_account_id(account_id)
|
||||
js_script = "configBinding.receiveResponse('#{resolve_id}')"
|
||||
state.with_add_queue_js_command('setUserSelectedAccountId', js_script)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -140,14 +140,13 @@ module SpeckleConnector3
|
||||
if entity.is_a?(SpeckleObjects::Geometry::GroupedMesh)
|
||||
mesh = SpeckleObjects::Geometry::Mesh.from_faces(speckle_state: speckle_state, faces: entity.faces,
|
||||
units: @units, model_preferences: preferences[:model])
|
||||
add_to_report(entity, mesh)
|
||||
return speckle_state, mesh
|
||||
end
|
||||
|
||||
if entity.is_a?(Sketchup::Edge)
|
||||
line = SpeckleObjects::Geometry::Line.from_edge(speckle_state: speckle_state, edge: entity,
|
||||
units: @units, model_preferences: preferences[:model]).to_h
|
||||
add_to_report(entity, line)
|
||||
add_to_report(entity, line) unless entity.parent.is_a?(Sketchup::ComponentDefinition)
|
||||
return speckle_state, line
|
||||
end
|
||||
|
||||
|
||||
@@ -34,6 +34,41 @@ module SpeckleConnector3
|
||||
)
|
||||
end
|
||||
|
||||
# this is needed to get last selected account
|
||||
def self.get_user_selected_account_id
|
||||
db = Sqlite3::Database.new(SPECKLE_CONFIG_DB_PATH)
|
||||
row_data = db.exec("SELECT content FROM 'objects' WHERE hash = 'accounts'")
|
||||
is_config_accounts_exist = !row_data.empty?
|
||||
return nil unless is_config_accounts_exist
|
||||
|
||||
# Select data
|
||||
row_data = db.exec("SELECT content FROM 'objects' WHERE hash = 'accounts'").first.first
|
||||
# Parse string to hash
|
||||
data_hash = JSON.parse(row_data).to_h
|
||||
# Get current theme value
|
||||
data_hash['userSelectedAccountId']
|
||||
end
|
||||
|
||||
def self.format_user_selected_accounts_insert(account_id)
|
||||
"('accounts', '{\"userSelectedAccountId\": \"#{account_id}\"}');"
|
||||
end
|
||||
|
||||
def self.format_user_selected_accounts_update(account_id)
|
||||
"{\"userSelectedAccountId\": \"#{account_id}\"}"
|
||||
end
|
||||
|
||||
def self.set_user_selected_account_id(account_id)
|
||||
db = Sqlite3::Database.new(SPECKLE_CONFIG_DB_PATH)
|
||||
row_data = db.exec("SELECT content FROM 'objects' WHERE hash = 'accounts'")
|
||||
is_config_accounts_exist = !row_data.empty?
|
||||
|
||||
if !is_config_accounts_exist
|
||||
db.exec("INSERT INTO 'objects' VALUES #{format_user_selected_accounts_insert(account_id)}")
|
||||
else
|
||||
db.exec("UPDATE 'objects' SET content = '#{format_user_selected_accounts_update(account_id)}' WHERE hash = 'accounts'")
|
||||
end
|
||||
end
|
||||
|
||||
# Creates the 'objects' table in the database if it doesn't already exist.
|
||||
# @param db [Sqlite3::Database] the SQLite3 database instance.
|
||||
def self.create_objects_table(db)
|
||||
|
||||
@@ -4,6 +4,8 @@ require_relative 'binding'
|
||||
require_relative '../../actions/config_actions/get_is_dev_mode'
|
||||
require_relative '../../actions/config_actions/get_config'
|
||||
require_relative '../../actions/config_actions/update_config'
|
||||
require_relative '../../actions/config_actions/get_user_selected_account_id'
|
||||
require_relative '../../actions/config_actions/set_user_selected_account_id'
|
||||
|
||||
module SpeckleConnector3
|
||||
module Ui
|
||||
@@ -15,7 +17,9 @@ module SpeckleConnector3
|
||||
@commands ||= {
|
||||
getIsDevMode: Commands::ActionCommand.new(@app, self, Actions::GetIsDevMode),
|
||||
getConfig: Commands::ActionCommand.new(@app, self, Actions::GetConfig),
|
||||
updateConfig: Commands::ActionCommand.new(@app, self, Actions::UpdateConfig)
|
||||
updateConfig: Commands::ActionCommand.new(@app, self, Actions::UpdateConfig),
|
||||
getUserSelectedAccountId: Commands::ActionCommand.new(@app, self, Actions::GetUserSelectedAccountId),
|
||||
setUserSelectedAccountId: Commands::ActionCommand.new(@app, self, Actions::SetUserSelectedAccountId)
|
||||
}.freeze
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user