Skip to content

Commit

Permalink
~ No model errors improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bbeaulant committed Apr 9, 2018
1 parent a32691a commit 040f079
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 94 deletions.
Binary file modified dist/ladb_opencutlist-dev.rbz
Binary file not shown.
8 changes: 8 additions & 0 deletions src/ladb_opencutlist/js/plugins/jquery.ladb.dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@
return n;
};

LadbDialog.prototype.notifyErrors = function(errors) {
if (Array.isArray(errors)) {
for (var i = 0; i < errors.length; i++) {
this.notify('<i class="ladb-opencutlist-icon-warning"></i> ' + i18next.t(errors[i]), 'error');
}
}
};

LadbDialog.prototype.setupTooltips = function() {
$('[data-toggle="tooltip"]').tooltip({
container: 'body'
Expand Down
62 changes: 38 additions & 24 deletions src/ladb_opencutlist/js/plugins/jquery.ladb.tab-cutlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,10 @@

rubyCallCommand('cutlist_part_highlight', part, function (response) {

var success = response['success'];

if (success) {
that.opencutlist.minimize();
} else {
if (response['errors']) {
that.opencutlist.notify('<i class="ladb-opencutlist-icon-warning"></i> ' + i18next.t('tab.cutlist.highlight_error', {'name': part.name}), 'error');
} else {
that.opencutlist.minimize();
}

});
Expand Down Expand Up @@ -414,29 +412,37 @@
that.editedPart.cumulable = $selectCumulable.val();
that.editedPart.orientation_locked_on_axis = $inputOrientationLockedOnAxis.is(':checked');

rubyCallCommand('cutlist_part_update', that.editedPart, function() {
rubyCallCommand('cutlist_part_update', that.editedPart, function(response) {

if (response['errors']) {

that.opencutlist.notifyErrors(response['errors']);

} else {

var partId = that.editedPart.id;
var wTop = $('#ladb_part_' + partId).offset().top - $(window).scrollTop();

// Refresh the list
that.generateCutlist(function() {

// Try to scroll to the edited part's row
var $part = $('#ladb_part_' + partId);
if ($part.length > 0) {
$part.effect("highlight", {}, 1500);
$('html, body').animate({ scrollTop: $part.offset().top - wTop }, 0);
}

});

var partId = that.editedPart.id;
var wTop = $('#ladb_part_' + partId).offset().top - $(window).scrollTop();
}

// Reset edited part
that.editedPart = null;

// Hide modal
$modal.modal('hide');

// Refresh the list
that.generateCutlist(function() {

// Try to scroll to the edited part's row
var $part = $('#ladb_part_' + partId);
if ($part.length > 0) {
$part.effect("highlight", {}, 1500);
$('html, body').animate({ scrollTop: $part.offset().top - wTop }, 0);
}

});

});

});
Expand Down Expand Up @@ -492,17 +498,25 @@
// Fetch form values
that.editedGroup.material_name = $selectMaterialName.val();

rubyCallCommand('cutlist_group_update', that.editedGroup, function() {
rubyCallCommand('cutlist_group_update', that.editedGroup, function(response) {

if (response['errors']) {

that.opencutlist.notifyErrors(response['errors']);

} else {

// Refresh the list
that.generateCutlist();

}

// Reset edited group
that.editedGroup = null;

// Hide modal
$modal.modal('hide');

// Refresh the list
that.generateCutlist();

});

});
Expand Down
18 changes: 13 additions & 5 deletions src/ladb_opencutlist/js/plugins/jquery.ladb.tab-materials.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
}));

// Update items state
that.$itemPurgeUnused.closest('li').toggleClass('disabled', materials.length == 0);
that.$itemPurgeUnused.closest('li').toggleClass('disabled', materials == null || materials.length == 0);

// Update page
that.$page.empty();
Expand Down Expand Up @@ -416,17 +416,25 @@
// Flag to ignore next material change event
that.ignoreNextMaterialChangeEvent = true;

rubyCallCommand('materials_update', that.editedMaterial, function() {
rubyCallCommand('materials_update', that.editedMaterial, function(response) {

if (response['errors']) {

that.opencutlist.notifyErrors(response['errors']);

} else {

// Refresh the list
that.loadList();

}

// Reset edited material
that.editedMaterial = null;

// Hide modal
$modal.modal('hide');

// Refresh the list
that.loadList();

});

});
Expand Down
89 changes: 45 additions & 44 deletions src/ladb_opencutlist/ruby/controller/cutlist_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,17 +356,17 @@ def _get_inherited_material(path)
if @instance_infos_cache.length == 0
if model
if entities.length == 0
cutlist_def.add_error("tab.cutlist.error.no_entities")
cutlist_def.add_error('tab.cutlist.error.no_entities')
else
if use_selection
cutlist_def.add_error("tab.cutlist.error.no_component_in_selection")
cutlist_def.add_error('tab.cutlist.error.no_component_in_selection')
else
cutlist_def.add_error("tab.cutlist.error.no_component_in_model")
cutlist_def.add_error('tab.cutlist.error.no_component_in_model')
end
cutlist_def.add_tip("tab.cutlist.tip.no_component")
cutlist_def.add_tip('tab.cutlist.tip.no_component')
end
else
cutlist_def.add_error("tab.cutlist.error.no_model")
cutlist_def.add_error('tab.cutlist.error.no_model')
end
end

Expand Down Expand Up @@ -819,7 +819,7 @@ def numbers_command(settings, reset)
group_id = settings['group_id']

model = Sketchup.active_model
definitions = model.definitions
definitions = model ? model.definitions : []

@cutlist[:groups].each { |group|

Expand Down Expand Up @@ -849,10 +849,12 @@ def part_get_thumbnail_command(part_data)
:thumbnail_file => ''
}

model = Sketchup.active_model
return response unless model

# Extract parameters
definition_id = part_data['definition_id']

model = Sketchup.active_model
definitions = model.definitions
definition = definitions[definition_id]
if definition
Expand All @@ -876,13 +878,8 @@ def part_get_thumbnail_command(part_data)

def part_highlight_command(part_data)

response = {
:success => false
}

model = Sketchup.active_model

return response unless model
return { :errors => [ 'tab.cutlist.error.no_model' ] } unless model

# Extract parameters
name = part_data['name']
Expand All @@ -892,7 +889,6 @@ def part_highlight_command(part_data)
material_name = part_data['material_name']
entity_serialized_paths = part_data['entity_serialized_paths']


# Populate instance defs
entity_infos = []
entity_serialized_paths.each { |entity_serialized_path|
Expand All @@ -914,15 +910,15 @@ def part_highlight_command(part_data)
highlight_tool = HighlightPartTool.new(text_line_1, text_line_2, entity_infos)
model.select_tool(highlight_tool)

response[:success] = true

end

response
end

def part_update_command(part_data)

model = Sketchup.active_model
return { :errors => [ 'tab.cutlist.error.no_model' ] } unless model

# Extract parameters
definition_id = part_data['definition_id']
name = part_data['name']
Expand All @@ -931,52 +927,57 @@ def part_update_command(part_data)
orientation_locked_on_axis = part_data['orientation_locked_on_axis']
entity_ids = part_data['entity_ids']

model = Sketchup.active_model

# Update definition's name
definitions = model.definitions
definition = definitions[definition_id]
if definition and definition.name != name
definition.name = name
end

definition_attributes = DefinitionAttributes.new(definition)
if cumulable != definition_attributes.cumulable or orientation_locked_on_axis != definition_attributes.orientation_locked_on_axis
definition_attributes.cumulable = cumulable
definition_attributes.orientation_locked_on_axis = orientation_locked_on_axis
definition_attributes.write_to_attributes
end
if definition

# Update component instance material
materials = model.materials
if material_name.nil? or material_name.empty? or (material = materials[material_name])
# Update definition's name
if definition.name != name
definition.name = name
end

# Update definition's attributes
definition_attributes = DefinitionAttributes.new(definition)
if cumulable != definition_attributes.cumulable or orientation_locked_on_axis != definition_attributes.orientation_locked_on_axis
definition_attributes.cumulable = cumulable
definition_attributes.orientation_locked_on_axis = orientation_locked_on_axis
definition_attributes.write_to_attributes
end

# Update component instance material
materials = model.materials
if material_name.nil? or material_name.empty? or (material = materials[material_name])

entity_ids.each { |entity_id|
entity = ModelUtils::find_entity_by_id(model, entity_id)
if entity
if material_name.nil? or material_name.empty?
entity.material = nil
elsif entity.material != material
entity.material = material
entity_ids.each { |entity_id|
entity = ModelUtils::find_entity_by_id(model, entity_id)
if entity
if material_name.nil? or material_name.empty?
entity.material = nil
elsif entity.material != material
entity.material = material
end
end
end
}
}

end

end

end

def group_update_command(group_data)

model = Sketchup.active_model
return { :errors => [ 'tab.cutlist.error.no_model' ] } unless model

# Extract parameters
id = group_data['id']
material_name = group_data['material_name']
parts = group_data['parts']

model = Sketchup.active_model
materials = model.materials

# Update component instance material
materials = model.materials
if material_name.nil? or material_name.empty? or (material = materials[material_name])

parts.each { |part_data|
Expand Down
Loading

0 comments on commit 040f079

Please sign in to comment.