Resolve merge conflict, add UpdateService and is_default attribute

pull/7924/head
Wieland Lindenthal 5 years ago
parent ca0b6e0bb3
commit 656b8f67f7
  1. 2
      frontend/src/app/modules/ifc_models/xeokit-viewer.js
  2. 6
      modules/ifc_models/app/cells/ifc_models/models/row_cell.rb
  3. 3
      modules/ifc_models/app/cells/ifc_models/models/table_cell.rb
  4. 1
      modules/ifc_models/app/contracts/ifc_models/base_contract.rb
  5. 32
      modules/ifc_models/app/contracts/ifc_models/update_contract.rb
  6. 22
      modules/ifc_models/app/controllers/ifc_models/ifc_models_controller.rb
  7. 6
      modules/ifc_models/app/services/ifc_models/create_service.rb
  8. 4
      modules/ifc_models/app/services/ifc_models/set_attributes_service.rb
  9. 71
      modules/ifc_models/app/services/ifc_models/update_service.rb
  10. 13
      modules/ifc_models/app/views/ifc_models/ifc_models/_form.html.erb
  11. 6
      modules/ifc_models/app/views/ifc_models/ifc_models/show.html.erb
  12. 2
      modules/ifc_models/config/locales/en.yml
  13. 7
      modules/ifc_models/db/migrate/20191114090353_add_is_default_to_ifc_models.rb

@ -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 loaded
treeView.on('model.loaded', function () {

@ -14,6 +14,12 @@ module IFCModels
end
end
def is_default
if model.is_default?
op_icon 'icon icon-checkmark'
end
end
def updated_at
format_date(model.updated_at)
end

@ -2,7 +2,7 @@ module IFCModels
module Models
class TableCell < ::TableCell
include ::IconsHelper
columns :title, :created_at, :updated_at, :uploader, :processing
columns :title, :is_default, :created_at, :updated_at, :uploader, :processing
def initial_sort
[:created_at, :asc]
@ -27,6 +27,7 @@ module IFCModels
def 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)],

@ -35,6 +35,7 @@ module IFCModels
attribute :title
attribute :project
attribute :uploader
attribute :is_default
def self.model
::IFCModels::IFCModel

@ -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
end

@ -66,8 +66,8 @@ module ::IFCModels
@ifc_model = call.result
if 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: :index
else
@errors = call.errors
render action: :new
@ -75,9 +75,21 @@ module ::IFCModels
end
def 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: :index
else
@errors = call.errors
render action: :edit
end
end
@ -92,7 +104,7 @@ module ::IFCModels
def permitted_model_params
params
.fetch(:ifc_models_ifc_model, {})
.permit('title', 'ifc_attachment')
.permit('title', 'ifc_attachment', 'is_default')
end
def find_ifc_model_object

@ -35,7 +35,7 @@ module IFCModels
ifc_attachment = params.delete('ifc_attachment')
super(params).tap do |result|
result.success = replace_attachment(result, ifc_attachment)
result.success = add_attachment(result, ifc_attachment)
end
end
@ -52,8 +52,8 @@ module IFCModels
end
##
# 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.result

@ -30,8 +30,10 @@
module IFCModels
class 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]
end
end
end

@ -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
end

@ -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>
<%= 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>

@ -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 %>

@ -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"

@ -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
Loading…
Cancel
Save