OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Resolve merge conflict, add UpdateService and is_default attribute
Wieland Lindenthal656b8f67f700
diff --git a/frontend/src/app/modules/ifc_models/xeokit-viewer.js b/frontend/src/app/modules/ifc_models/xeokit-viewer.jsindex 0c01a7337e8..996c564780d 100644--- a/frontend/src/app/modules/ifc_models/xeokit-viewer.js+++ b/frontend/src/app/modules/ifc_models/xeokit-viewer.js@@ -109,7 +109,7 @@ export class XeokitViewer {data: createData(metaModel)});new InspireTreeDOM(treeView, {- target: document.getElementById("xeokit-tree-panel-12")+ target: document.getElementById(`xeokit-tree-panel-${ifcModelId}`)});// Initialize the tree view once loadedtreeView.on('model.loaded', function () {diff --git a/modules/ifc_models/app/cells/ifc_models/models/row_cell.rb b/modules/ifc_models/app/cells/ifc_models/models/row_cell.rbindex d41ff49f758..ec47e02ff61 100644--- a/modules/ifc_models/app/cells/ifc_models/models/row_cell.rb+++ b/modules/ifc_models/app/cells/ifc_models/models/row_cell.rb@@ -14,6 +14,12 @@ module IFCModelsendend+ def is_default+ if model.is_default?+ op_icon 'icon icon-checkmark'+ end+ end+def updated_atformat_date(model.updated_at)enddiff --git a/modules/ifc_models/app/cells/ifc_models/models/table_cell.rb b/modules/ifc_models/app/cells/ifc_models/models/table_cell.rbindex ea075dcaf82..ba81a12ef7a 100644--- a/modules/ifc_models/app/cells/ifc_models/models/table_cell.rb+++ b/modules/ifc_models/app/cells/ifc_models/models/table_cell.rb@@ -2,7 +2,7 @@ module IFCModelsmodule Modelsclass TableCell < ::TableCellinclude ::IconsHelper- columns :title, :created_at, :updated_at, :uploader, :processing+ columns :title, :is_default, :created_at, :updated_at, :uploader, :processingdef initial_sort[:created_at, :asc]@@ -27,6 +27,7 @@ module IFCModelsdef headers[['title', caption: IFCModel.human_attribute_name(:title)],+ ['is_default', caption: IFCModel.human_attribute_name(:is_default)],['created_at', caption: IFCModel.human_attribute_name(:created_at)],['updated_at', caption: IFCModel.human_attribute_name(:updated_at)],['uploader', caption: IFCModel.human_attribute_name(:uploader)],diff --git a/modules/ifc_models/app/contracts/ifc_models/base_contract.rb b/modules/ifc_models/app/contracts/ifc_models/base_contract.rbindex 1686353cf79..fd2da3ad6e5 100644--- a/modules/ifc_models/app/contracts/ifc_models/base_contract.rb+++ b/modules/ifc_models/app/contracts/ifc_models/base_contract.rb@@ -35,6 +35,7 @@ module IFCModelsattribute :titleattribute :projectattribute :uploader+ attribute :is_defaultdef self.model::IFCModels::IFCModeldiff --git a/modules/ifc_models/app/contracts/ifc_models/update_contract.rb b/modules/ifc_models/app/contracts/ifc_models/update_contract.rbnew file mode 100644index 00000000000..1f5e7bdd16f--- /dev/null+++ b/modules/ifc_models/app/contracts/ifc_models/update_contract.rb@@ -0,0 +1,32 @@+#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2017 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See doc/COPYRIGHT.rdoc for more details.+#++++module IFCModels+ class UpdateContract < BaseContract+ end+enddiff --git a/modules/ifc_models/app/controllers/ifc_models/ifc_models_controller.rb b/modules/ifc_models/app/controllers/ifc_models/ifc_models_controller.rbindex f11733f51b7..405c6a4e153 100644--- a/modules/ifc_models/app/controllers/ifc_models/ifc_models_controller.rb+++ b/modules/ifc_models/app/controllers/ifc_models/ifc_models_controller.rb@@ -66,8 +66,8 @@ module ::IFCModels@ifc_model = call.resultif call.success?- flash[:notice] = t(:notice_successful_create)- redirect_to action: :show, id: @ifc_model.id+ flash[:notice] = t('ifc_models.flash_messages.upload_successful')+ redirect_to action: :indexelse@errors = call.errorsrender action: :new@@ -75,9 +75,21 @@ module ::IFCModelsenddef update- if @ifc_model.update(permitted_params)- redirect_to action: :show, id: @ifc_model.id+ combined_params = permitted_model_params+ .to_h+ .reverse_merge(project: @project)++ call = ::IFCModels::UpdateService+ .new(user: current_user, model: @ifc_model)+ .call(combined_params)++ @ifc_model = call.result++ if call.success?+ flash[:notice] = t(:notice_successful_update)+ redirect_to action: :indexelse+ @errors = call.errorsrender action: :editendend@@ -92,7 +104,7 @@ module ::IFCModelsdef permitted_model_paramsparams.fetch(:ifc_models_ifc_model, {})- .permit('title', 'ifc_attachment')+ .permit('title', 'ifc_attachment', 'is_default')enddef find_ifc_model_objectdiff --git a/modules/ifc_models/app/services/ifc_models/create_service.rb b/modules/ifc_models/app/services/ifc_models/create_service.rbindex 58e84247f95..d0f39743c85 100644--- a/modules/ifc_models/app/services/ifc_models/create_service.rb+++ b/modules/ifc_models/app/services/ifc_models/create_service.rb@@ -35,7 +35,7 @@ module IFCModelsifc_attachment = params.delete('ifc_attachment')super(params).tap do |result|- result.success = replace_attachment(result, ifc_attachment)+ result.success = add_attachment(result, ifc_attachment)endend@@ -52,8 +52,8 @@ module IFCModelsend##- # Replace the IFC attachment file after saving- def replace_attachment(result, file)+ # Add the IFC attachment file after saving+ def add_attachment(result, file)return unless result.success?model = result.resultdiff --git a/modules/ifc_models/app/services/ifc_models/set_attributes_service.rb b/modules/ifc_models/app/services/ifc_models/set_attributes_service.rbindex d74bdd454d3..d82bedfb1b7 100644--- a/modules/ifc_models/app/services/ifc_models/set_attributes_service.rb+++ b/modules/ifc_models/app/services/ifc_models/set_attributes_service.rb@@ -30,8 +30,10 @@module IFCModelsclass SetAttributesService < ::BaseServices::SetAttributes- def set_default_attributes(_params)+ def set_default_attributes(params)model.uploader = user+ model.is_default = params[:is_default]+ model.title = params[:title]endendenddiff --git a/modules/ifc_models/app/services/ifc_models/update_service.rb b/modules/ifc_models/app/services/ifc_models/update_service.rbnew file mode 100644index 00000000000..b553a15976c--- /dev/null+++ b/modules/ifc_models/app/services/ifc_models/update_service.rb@@ -0,0 +1,71 @@+#-- copyright+# OpenProject is a project management system.+# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2017 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See docs/COPYRIGHT.rdoc for more details.+#+++module IFCModels+ class UpdateService < ::BaseServices::Update++ protected++ def before_perform(params)+ ifc_attachment = params.delete('ifc_attachment')++ super(params).tap do |result|+ result.success = replace_attachment(result, ifc_attachment)+ end+ end++ def after_perform(call)+ if @ifc_attachment_replaced && call.success?+ IFCConversionJob.perform_later(call.result)+ end++ call+ end++ ##+ # Replace the IFC attachment file after saving+ def replace_attachment(result, file)+ return unless result.success?++ model = result.result++ # Uploading an IFC file is optional+ if file && file.size.positive?+ model.ifc_attachment = file+ @ifc_attachment_replaced = true+ end++ if model.save+ true+ else+ result.errors.add(:ifc_attachment, t('ifc_models.could_not_save_file'))+ false+ end+ end+ end+enddiff --git a/modules/ifc_models/app/views/ifc_models/ifc_models/_form.html.erb b/modules/ifc_models/app/views/ifc_models/ifc_models/_form.html.erbindex 1e431b60d7e..e3847cd5ef1 100644--- a/modules/ifc_models/app/views/ifc_models/ifc_models/_form.html.erb+++ b/modules/ifc_models/app/views/ifc_models/ifc_models/_form.html.erb@@ -32,7 +32,14 @@ See doc/COPYRIGHT.rdoc for more details.<%= error_messages_for 'ifc_model' %>+<% unless @ifc_model.new_record? %><div class="form--field -required">- <%= f.text_field :title, required: true, container_class: '-wide' unless @ifc_model.new_record? %>- <%= f.file_field :ifc_attachment if @ifc_model.new_record? %>-</div>\ No newline at end of file+ <%= f.text_field :title, required: true, container_class: '-wide' %>+</div>+<% end %>+<div class="form--field">+ <%= f.file_field :ifc_attachment %>+</div>+<div class="form--field">+ <%= f.check_box 'is_default' %>+</div>diff --git a/modules/ifc_models/app/views/ifc_models/ifc_models/show.html.erb b/modules/ifc_models/app/views/ifc_models/ifc_models/show.html.erbindex 3a4c0845a8c..da197a7ee77 100644--- a/modules/ifc_models/app/views/ifc_models/ifc_models/show.html.erb+++ b/modules/ifc_models/app/views/ifc_models/ifc_models/show.html.erb@@ -41,14 +41,14 @@ See doc/COPYRIGHT.rdoc for more details.<% if authorize_for('ifc_models/ifc_models', :edit) %><li class="toolbar-item"><%= link_to(edit_ifc_models_project_ifc_model_path(@project, @ifc_model), class: 'button', accesskey: accesskey(:edit)) do %>- <%= op_icon('button--icon icon-edit') %> <%= l(:button_rename) %>+ <%= op_icon('button--icon icon-edit') %> <%= t(:button_edit) %><% end %></li><% end %><% if authorize_for('ifc_models/ifc_models', :destroy) %><li class="toolbar-item">- <%= link_to(ifc_models_project_ifc_model_path(@project, @ifc_model), class: 'button', data: { confirm: l(:text_are_you_sure) }, method: :delete) do %>- <%= op_icon('button--icon icon-delete') %> <%= l(:button_delete) %>+ <%= link_to(ifc_models_project_ifc_model_path(@project, @ifc_model), class: 'button', data: { confirm: t(:text_are_you_sure) }, method: :delete) do %>+ <%= op_icon('button--icon icon-delete') %> <%= t(:button_delete) %><% end %></li><% end %>diff --git a/modules/ifc_models/config/locales/en.yml b/modules/ifc_models/config/locales/en.ymlindex cfd1fd36871..766f487ac68 100644--- a/modules/ifc_models/config/locales/en.yml+++ b/modules/ifc_models/config/locales/en.yml@@ -9,6 +9,8 @@ en:label: 'Processing?'in_progress: 'In progress'completed: 'Completed'+ flash_messages:+ upload_successful: 'Upload succeeded. It will now get processed and will be ready to use in a couple of minutes.'conversion:missing_commands: "The following IFC converter commands are missing on this system: %{names}"project_module_ifc_models: "IFC models"diff --git a/modules/ifc_models/db/migrate/20191114090353_add_is_default_to_ifc_models.rb b/modules/ifc_models/db/migrate/20191114090353_add_is_default_to_ifc_models.rbnew file mode 100644index 00000000000..e9aefeed8f7--- /dev/null+++ b/modules/ifc_models/db/migrate/20191114090353_add_is_default_to_ifc_models.rb@@ -0,0 +1,7 @@+class AddIsDefaultToIFCModels < ActiveRecord::Migration[5.1]+ def change+ add_column :ifc_models, :is_default, :boolean, default: false, null: false++ add_index :ifc_models, :is_default+ end+end