Skip to content

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

Directly show default IFC models on click on module in main menu

Wieland Lindenthal510ff08a4074
diff --git a/frontend/src/app/modules/ifc_models/ifc-viewer.component.ts b/frontend/src/app/modules/ifc_models/ifc-viewer.component.ts
index 2f8b0dc8076..e09fe2bc9aa 100644
--- a/frontend/src/app/modules/ifc_models/ifc-viewer.component.ts
+++ b/frontend/src/app/modules/ifc_models/ifc-viewer.component.ts
@@ -33,7 +33,6 @@ import {DynamicBootstrapper} from "app/globals/dynamic-bootstrapper";
selector: 'ifc-viewer',
template: `
<canvas [id]="'xeokit-model-canvas-' + ifcModelId" class="xeokit-model-canvas"></canvas>
- <div [id]="'xeokit-tree-panel-' + ifcModelId" class="treePanel" class="xeokit-tree-panel"></div>
`,
styleUrls: [
'../../../../node_modules/inspire-tree-dom/dist/inspire-tree-light.css'
diff --git a/frontend/src/app/modules/ifc_models/xeokit-viewer.js b/frontend/src/app/modules/ifc_models/xeokit-viewer.js
index 545cdfb99a5..8c5b12d9250 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-${ifcModelId}`)
+ target: document.getElementById('xeokit-tree-panel')
});
// Initialize the tree view once loaded
treeView.on('model.loaded', function () {
diff --git a/modules/ifc_models/app/controllers/ifc_models/ifc_models_controller.rb b/modules/ifc_models/app/controllers/ifc_models/ifc_models_controller.rb
index 405c6a4e153..899939f62a2 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
@@ -32,8 +32,10 @@ module ::IFCModels
class IFCModelsController < BaseController
include IFCModelsHelper
- before_action :find_project_by_project_id, only: %i[index new create show edit update destroy]
- before_action :find_ifc_model_object, except: %i[index new create]
+ before_action :find_project_by_project_id, only: %i[index new create show show_defaults edit update destroy]
+ before_action :find_ifc_model_object, except: %i[index new create show_defaults]
+ before_action :find_all_ifc_models, only: %i[show show_defaults]
+ before_action :provision_gon, only: %i[show_defaults]
before_action :authorize
@@ -54,6 +56,14 @@ module ::IFCModels
def show; end
+ def show_defaults
+ if @ifc_models.empty?
+ redirect_to "index"
+ end
+
+ @default_ifc_models = @project.ifc_models.defaults
+ end
+
def create
combined_params = permitted_model_params
.to_h
@@ -101,6 +111,24 @@ module ::IFCModels
private
+ def find_all_ifc_models
+ @ifc_models = @project
+ .ifc_models
+ .order('created_at ASC')
+ end
+
+ def provision_gon
+ gon.ifc_models = {
+ models: @ifc_models.map do |ifc_model|
+ {
+ id: ifc_model.id,
+ name: ifc_model.title,
+ load: ifc_model.is_default
+ }
+ end
+ }
+ end
+
def permitted_model_params
params
.fetch(:ifc_models_ifc_model, {})
diff --git a/modules/ifc_models/app/models/ifc_models/ifc_model.rb b/modules/ifc_models/app/models/ifc_models/ifc_model.rb
index 3e869da2fbe..8131d00d70a 100644
--- a/modules/ifc_models/app/models/ifc_models/ifc_model.rb
+++ b/modules/ifc_models/app/models/ifc_models/ifc_model.rb
@@ -5,6 +5,8 @@ module IFCModels
belongs_to :project
belongs_to :uploader, class_name: 'User', foreign_key: 'uploader_id'
+ scope :defaults, -> { where(is_default: true) }
+
%i(ifc xkt metadata).each do |name|
define_method "#{name}_attachment" do
get_attached_type(name)
@@ -23,7 +25,7 @@ module IFCModels
end
def converted?
- xkt_attachment && metadata_attachment
+ xkt_attachment.present? && metadata_attachment.present?
end
private
diff --git a/modules/ifc_models/app/views/ifc_models/ifc_models/_panels.html.erb b/modules/ifc_models/app/views/ifc_models/ifc_models/_panels.html.erb
new file mode 100644
index 00000000000..89ac8c7ab22
--- /dev/null
+++ b/modules/ifc_models/app/views/ifc_models/ifc_models/_panels.html.erb
@@ -0,0 +1 @@
+<div id="xeokit-tree-panel" class="treePanel xeokit-tree-panel"></div>
\ No newline at end of file
diff --git a/modules/ifc_models/app/views/ifc_models/ifc_models/index.html.erb b/modules/ifc_models/app/views/ifc_models/ifc_models/index.html.erb
index b8fd0273a3e..16e76c82cea 100644
--- a/modules/ifc_models/app/views/ifc_models/ifc_models/index.html.erb
+++ b/modules/ifc_models/app/views/ifc_models/ifc_models/index.html.erb
@@ -29,12 +29,23 @@ See docs/COPYRIGHT.rdoc for more details.
<% html_title(t('ifc_models.label_ifc_models')) -%>
<%= toolbar title: t('ifc_models.label_ifc_models') do %>
+ <% if @ifc_models.any? %>
+ <li class="toolbar-item">
+ <%= link_to show_defaults_ifc_models_project_ifc_models_path,
+ { class: 'button -alt-highlight',
+ aria: { label: t(:label_new_ifc_model) },
+ title: t(:label_new_ifc_model) } do %>
+ <%= op_icon('button--icon icon-eye') %>
+ <span class="button--text"><%= t('ifc_models.label_show_defaults') %></span>
+ <% end %>
+ </li>
+ <% end %>
<% if User.current.allowed_to?(:manage_ifc_models, @project) %>
<li class="toolbar-item">
<%= link_to new_ifc_models_project_ifc_model_path,
- { class: 'button -alt-highlight',
- aria: { label: t(:label_project_new) },
- title: t(:label_project_new) } do %>
+ { class: 'button -highlight',
+ aria: { label: t(:label_new_ifc_model) },
+ title: t(:label_new_ifc_model) } do %>
<%= op_icon('button--icon icon-add') %>
<span class="button--text"><%= ::IFCModels::IFCModel.model_name.human %></span>
<% end %>
diff --git a/modules/ifc_models/app/views/ifc_models/ifc_models/show_defaults.html.erb b/modules/ifc_models/app/views/ifc_models/ifc_models/show_defaults.html.erb
new file mode 100644
index 00000000000..d7b8f5c6154
--- /dev/null
+++ b/modules/ifc_models/app/views/ifc_models/ifc_models/show_defaults.html.erb
@@ -0,0 +1,75 @@
+<%#-- copyright
+OpenProject Documents Plugin
+
+Former OpenProject Core functionality extracted into a plugin.
+
+Copyright (C) 2009-2014 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-2013 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.
+
+++#%>
+
+<% html_title t('ifc_models.label_default_ifc_models') -%>
+
+<% content_for :header_tags do %>
+ <%= stylesheet_link_tag "ifc_models/ifc_models", media: 'all' %>
+<% end %>
+
+
+<%= toolbar title: t('ifc_models.label_default_ifc_models') do %>
+ <li class="toolbar-item">
+ <%= link_to(ifc_models_project_ifc_models_path(@project), class: 'button', accesskey: accesskey(:edit)) do %>
+ <%= op_icon('button--icon icon-edit') %> <%= t('ifc_models.label_manage_models') %>
+ <% end %>
+ </li>
+<% end %>
+
+
+<% content_for :header_tags do %>
+ <%= include_gon(nonce: content_security_policy_script_nonce) %>
+<% end %>
+
+<% if @default_ifc_models.empty? %>
+ <div class="notification-box -error">
+ <div class="notification-box--content">
+ <p><%= t('ifc_models.no_defaults_warning.title') %></p>
+ <ul>
+ <li><%= t('ifc_models.no_defaults_warning.check_1') %></li>
+ <li><%= t('ifc_models.no_defaults_warning.check_2') %></li>
+ </ul>
+ <%= link_to(ifc_models_project_ifc_models_path(@project), class: 'button', accesskey: accesskey(:edit)) do %>
+ <%= op_icon('button--icon icon-edit') %> <%= t('ifc_models.label_edit_defaults') %>
+ <% end %>
+ </div>
+ </div>
+<% end %>
+
+<% if @default_ifc_models.map(&:converted?).uniq == [true] %>
+<div class="ifc-model-viewer-container">
+ <% @ifc_model = @default_ifc_models.first %>
+ <ifc-viewer-entry data-ifc-model-id="<%= @ifc_model.id %>"
+ data-xkt-file-url="<%= attachment_content_url(@ifc_model.xkt_attachment) %>"
+ data-metadata-file-url="<%= attachment_content_url(@ifc_model.metadata_attachment) %>"></ifc-viewer-entry>
+</div>
+<% end %>
diff --git a/modules/ifc_models/config/locales/en.yml b/modules/ifc_models/config/locales/en.yml
index 766f487ac68..06249b70433 100644
--- a/modules/ifc_models/config/locales/en.yml
+++ b/modules/ifc_models/config/locales/en.yml
@@ -3,6 +3,14 @@ en:
ifc_models:
label_ifc_models: 'IFC models'
label_new_ifc_model: 'New IFC model'
+ label_show_defaults: 'Show defaults'
+ label_default_ifc_models: 'Default IFC models'
+ label_edit_defaults: 'Edit defaults'
+ label_manage_models: 'Manage models'
+ no_defaults_warning:
+ title: 'No IFC model was set as default for this project.'
+ check_1: 'Check that you have uploaded at least one IFC model.'
+ check_2: 'Check that at least one IFC model is set to "Default".'
no_results: "No IFC models have been uploaded in this project."
could_not_save_file': 'Could not save the file.'
processing_state:
diff --git a/modules/ifc_models/config/routes.rb b/modules/ifc_models/config/routes.rb
index f4d30a12fc1..11f8fb59539 100644
--- a/modules/ifc_models/config/routes.rb
+++ b/modules/ifc_models/config/routes.rb
@@ -37,7 +37,11 @@ OpenProject::Application.routes.draw do
# get '/projects/:project_id/ifc_models', to: 'ifc_models/ifc_models#index'
scope '', as: 'ifc_models' do
scope 'projects/:project_id', as: 'project' do
- resources :ifc_models, controller: 'ifc_models/ifc_models'
+ resources :ifc_models, controller: 'ifc_models/ifc_models' do
+ collection do
+ get 'show_defaults'
+ end
+ end
end
end
end
diff --git a/modules/ifc_models/lib/open_project/ifc_models/engine.rb b/modules/ifc_models/lib/open_project/ifc_models/engine.rb
index 6dcc69788e7..76a1633faac 100644
--- a/modules/ifc_models/lib/open_project/ifc_models/engine.rb
+++ b/modules/ifc_models/lib/open_project/ifc_models/engine.rb
@@ -45,7 +45,7 @@ module OpenProject::IFCModels
project_module :ifc_models do
permission :view_ifc_models,
- { 'ifc_models/ifc_models': %i[index show] }
+ { 'ifc_models/ifc_models': %i[index show show_defaults] }
permission :manage_ifc_models,
{ 'ifc_models/ifc_models': %i[index show destroy edit update create new] },
dependencies: %i[view_ifc_models]
@@ -57,10 +57,16 @@ module OpenProject::IFCModels
initializer 'ifc_models.menu' do
::Redmine::MenuManager.map(:project_menu) do |menu|
menu.push(:ifc_models,
- { controller: '/ifc_models/ifc_models', action: 'index' },
+ { controller: '/ifc_models/ifc_models', action: 'show_defaults' },
caption: :'ifc_models.label_ifc_models',
param: :project_id,
icon: 'icon2 icon-ifc')
+
+ menu.push :ifc_viewer_panels,
+ { controller: '/ifc_models/ifc_models', action: 'show_defaults' },
+ param: :project_id,
+ parent: :ifc_models,
+ partial: '/ifc_models/ifc_models/panels'
end
end