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

- move xeokit explorer to main menu
- generate Gon containing the project's models
pull/7924/head
Wieland Lindenthal 5 years ago
parent 0e74fcc4a5
commit 510ff08a40
  1. 1
      frontend/src/app/modules/ifc_models/ifc-viewer.component.ts
  2. 2
      frontend/src/app/modules/ifc_models/xeokit-viewer.js
  3. 32
      modules/ifc_models/app/controllers/ifc_models/ifc_models_controller.rb
  4. 4
      modules/ifc_models/app/models/ifc_models/ifc_model.rb
  5. 1
      modules/ifc_models/app/views/ifc_models/ifc_models/_panels.html.erb
  6. 17
      modules/ifc_models/app/views/ifc_models/ifc_models/index.html.erb
  7. 75
      modules/ifc_models/app/views/ifc_models/ifc_models/show_defaults.html.erb
  8. 8
      modules/ifc_models/config/locales/en.yml
  9. 6
      modules/ifc_models/config/routes.rb
  10. 10
      modules/ifc_models/lib/open_project/ifc_models/engine.rb

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

@ -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 () {

@ -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, {})

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

@ -0,0 +1 @@
<div id="xeokit-tree-panel" class="treePanel xeokit-tree-panel"></div>

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

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

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

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

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

Loading…
Cancel
Save