Adding a OpenProject module for IFC models

Add to last commit
This commit is contained in:
Wieland Lindenthal
2019-10-31 16:32:04 +01:00
parent 5a9ed0fd2c
commit fb600d389c
21 changed files with 614 additions and 1 deletions
+8
View File
@@ -151,6 +151,13 @@ PATH
specs:
grids (1.0.0)
PATH
remote: modules/ifc_models
specs:
openproject-ifc_models (1.0.0)
activerecord-import
rubyzip (~> 1.2)
PATH
remote: modules/ldap_groups
specs:
@@ -1028,6 +1035,7 @@ DEPENDENCIES
openproject-documents!
openproject-github_integration!
openproject-global_roles!
openproject-ifc_models!
openproject-ldap_groups!
openproject-meeting!
openproject-openid_connect!
+1
View File
@@ -47,4 +47,5 @@ group :opf_plugins do
gem 'openproject-bim_seeder', path: 'modules/bim_seeder', require: !!(ENV['OPENPROJECT_EDITION'] == 'bim')
gem 'openproject-bcf', path: 'modules/bcf', require: !!(ENV['OPENPROJECT_EDITION'] == 'bim')
gem 'openproject-ifc_models', path: 'modules/ifc_models', require: !!(ENV['OPENPROJECT_EDITION'] == 'bim')
end
+1
View File
@@ -43,4 +43,5 @@
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'OAuth'
inflect.acronym 'OpenID'
inflect.acronym 'IFC'
end
+2
View File
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gemspec
@@ -0,0 +1,4 @@
module ::IFCModels
class BaseController < ApplicationController
end
end
@@ -0,0 +1,106 @@
#-- encoding: UTF-8
#-- 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 IFCModelsController < BaseController
include PaginationHelper
before_action :find_project_by_project_id, only: [:index, :new, :create, :show, :edit, :update, :destroy]
before_action :find_ifc_model_object, except: [:index, :new, :create]
before_action :authorize
menu_item :ifc_models
def index
@ifc_models = @project.ifc_models.order('created_at DESC').page(page_param).per_page(per_page_param)
render 'ifc_models/index'
end
def new
@ifc_model = @project.ifc_models.build(ifc_model_params)
render 'ifc_models/new'
end
def edit
render 'ifc_models/edit'
end
def show
render 'ifc_models/show'
end
def create
@ifc_model = @project.ifc_models.build(uploader: User.current)
if add_attachment && @ifc_model.save
redirect_to action: :show, id: @ifc_model.id
else
render 'ifc_models/new'
end
end
def update
if @ifc_model.update(ifc_model_params)
redirect_to action: :show, id: @ifc_model.id
else
render 'ifc_models/new'
end
end
def destroy
@ifc_model.destroy
redirect_to action: :index
end
private
def add_attachment
if (file = ifc_model_params['ifc_attachment']) && file && file.size.positive?
@ifc_model.attachments.build(file: file,
container: @ifc_model,
description: 'IFC attachment',
author: User.current)
@ifc_model.title = file.original_filename
else
flash[:error] = t('ifc_models.could_not_save_file')
false
end
end
def ifc_model_params
params.fetch(:ifc_models_ifc_model, {}).permit('title', 'ifc_attachment')
end
def find_ifc_model_object
@ifc_model = IFCModels::IFCModel.find_by(id: params[:id])
end
end
end
@@ -0,0 +1,25 @@
module IFCModels
class IFCModel < ActiveRecord::Base
acts_as_attachable delete_permission: :manage_ifc_models
has_one :project
belongs_to :uploader, class_name: 'User', foreign_key: 'uploader_id'
def ifc_attachment
attachments.first
end
def xkt_attachment
attachments.second
end
def delete_ifc_attachment
delete_xkt_attachment
ifc_attachment&.destroy
end
def delete_xkt_attachment
xkt_attachment&.destroy
end
end
end
@@ -0,0 +1,38 @@
<%#-- 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.
++#%>
<%= error_messages_for 'ifc_model' %>
<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>
@@ -0,0 +1,38 @@
<%#-- 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.
++#%>
<%= toolbar title: IFCModels::IFCModel.model_name.human %>
<%= labelled_tabular_form_for @ifc_model, url: ifc_models_project_ifc_model_path(@project, @ifc_model), method: 'PATCH' do |f| -%>
<%= render partial: "ifc_models/form", locals: { f: f } %>
<%= styled_button_tag t(:button_save), class: "-highlight -with-icon icon-checkmark" %>
<% end %>
@@ -0,0 +1,107 @@
<%#-- 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.
++#%>
<% html_title(t('ifc_models.label_ifc_models')) -%>
<%= toolbar title: t('ifc_models.label_ifc_models') do %>
<% 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 %>
<%= op_icon('button--icon icon-add') %>
<span class="button--text"><%= IFCModels::IFCModel.model_name.human %></span>
<% end %>
</li>
<% end %>
<% end %>
<% if @ifc_models.any? %>
<table class="generic-table" id="project-table">
<thead>
<tr>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<%= IFCModels::IFCModel.human_attribute_name(:title) %>
</div>
</div>
</th>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<%= t('ifc_models.uploaded_at')%>
</div>
</div>
</th>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<%= t('ifc_models.uploader')%>
</div>
</div>
</th>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
<%= t('ifc_models.processing_state.label')%>
</div>
</div>
</th>
<th>
<div class="generic-table--sort-header-outer">
<div class="generic-table--sort-header">
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<% @ifc_models.each do |ifc_model| %>
<tr class="basics">
<td><%= link_to(ifc_model.title, ifc_models_project_ifc_model_path(@project, ifc_model)) %></td>
<td><%= format_date(ifc_model.created_at) %></td>
<td><%= link_to_user(ifc_model.uploader.name) %></td>
<td><%= ifc_model.xkt_attachment.present? ? t('ifc_models.processing_state.completed') : t('ifc_models.processing_state.in_progress') %></td>
<td class="buttons">
<% if authorize_for('ifc_models/ifc_models', :edit) %>
<%= link_to('', edit_ifc_models_project_ifc_model_path(@project, ifc_model), class: 'icon icon-edit', accesskey: accesskey(:edit)) %>
<% end %>
<% if authorize_for('ifc_models/ifc_models', :destroy) %>
<%= link_to('', ifc_models_project_ifc_model_path(@project, ifc_model), class: 'icon icon-delete', data: { confirm: l(:text_are_you_sure) }, method: :delete) %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= pagination_links_full @ifc_models %>
<% else %>
<%= no_results_box({}) %>
<% end %>
@@ -0,0 +1,37 @@
<%#-- 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.
++#%>
<%= toolbar title: t('ifc_models.label_new_ifc_model') %>
<%= labelled_tabular_form_for @ifc_model, url: ifc_models_project_ifc_models_path(@project), html: { multipart: true } do |f| -%>
<%= render :partial => 'ifc_models/form', locals: { f: f } %>
<%= styled_button_tag l(:button_create), class: "-highlight -with-icon icon-checkmark" %>
<% end %>
@@ -0,0 +1,50 @@
<%#-- 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 h(@ifc_model.title) -%>
<%= toolbar title: @ifc_model.title do %>
<% 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) %>
<% 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) %>
<% end %>
</li>
<% end %>
<% end %>
+13
View File
@@ -0,0 +1,13 @@
# English strings go here for Rails i18n
en:
ifc_models:
label_ifc_models: 'IFC models'
label_new_ifc_model: 'New IFC model'
could_not_save_file': 'Could not save the file.'
processing_state:
label: 'Processing?'
in_progress: 'In progress'
completed: 'Completed'
project_module_ifc_models: "IFC models"
permission_view_ifc_models: "View IFC models"
permission_manage_ifc_models: "Import and manage IFC models"
+43
View File
@@ -0,0 +1,43 @@
#-- copyright
# OpenProject Backlogs Plugin
#
# Copyright (C)2013-2014 the OpenProject Foundation (OPF)
# Copyright (C)2011 Stephan Eckardt, Tim Felgentreff, Marnen Laibow-Koser, Sandro Munda
# Copyright (C)2010-2011 friflaj
# Copyright (C)2010 Maxime Guilbot, Andrew Vit, Joakim Kolsjö, ibussieres, Daniel Passos, Jason Vasquez, jpic, Emiliano Heyns
# Copyright (C)2009-2010 Mark Maglana
# Copyright (C)2009 Joe Heck, Nate Lowrie
#
# 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 Backlogs is a derivative work based on ChiliProject Backlogs.
# The copyright follows:
# Copyright (C) 2010-2011 - Emiliano Heyns, Mark Maglana, friflaj
# Copyright (C) 2011 - Jens Ulferts, Gregor Schmidt - Finn GmbH - Berlin, Germany
#
# 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.
#++
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'
end
end
end
@@ -0,0 +1,11 @@
class AddIFCModelsPlugin < ActiveRecord::Migration[5.1]
def change
create_table :ifc_models do |t|
t.string :title
t.timestamps
t.references :project, foreign_key: { on_delete: :cascade }, index: true
t.references :uploader, index: true
end
end
end
@@ -0,0 +1,6 @@
module OpenProject
module IFCModels
require "open_project/ifc_models/engine"
require "open_project/ifc_models"
end
end
@@ -0,0 +1,67 @@
#-- encoding: UTF-8
#-- 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.
#++
require 'open_project/plugins'
module OpenProject::IFCModels
class Engine < ::Rails::Engine
engine_name :openproject_ifc_models
include OpenProject::Plugins::ActsAsOpEngine
register 'openproject-ifc_models',
author_url: 'https://openproject.com',
settings: {
default: {
}
} do
project_module :ifc_models do
permission :view_ifc_models,
{ 'ifc_models/ifc_models': %i[index show] }
permission :manage_ifc_models,
{ 'ifc_models/ifc_models': %i[index show destroy edit update create new] },
dependencies: %i[view_ifc_models]
end
end
initializer 'ifc_models.menu' do
::Redmine::MenuManager.map(:project_menu) do |menu|
menu.push(:ifc_models,
{ controller: '/ifc_models/ifc_models', action: 'index' },
caption: :'ifc_models.label_ifc_models',
param: :project_id,
icon: 'icon2 icon-ifc')
end
end
patches %i[Project]
end
end
@@ -0,0 +1,37 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2019 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.
#++
require_dependency 'work_package'
module OpenProject::IFCModels::Patches::ProjectPatch
def self.included(base)
base.class_eval do
has_many :ifc_models, class_name: 'IFCModels::IFCModel', foreign_key: 'project_id'
end
end
end
@@ -0,0 +1 @@
require 'open_project/ifc_models'
@@ -0,0 +1,18 @@
# encoding: UTF-8
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "openproject-ifc_models"
s.version = "1.0.0"
s.authors = "OpenProject GmbH"
s.email = "info@openproject.com"
s.homepage = "https://community.openproject.org/"
s.summary = "Save and view IFC models in OpenProject."
s.description = "This OpenProject plugin allows to store and view IFC models."
s.files = Dir["{app,config,db,lib}/**/*", "CHANGELOG.md", "README.rdoc"]
s.test_files = Dir["spec/**/*"]
s.add_dependency 'activerecord-import'
s.add_dependency 'rubyzip', '~> 1.2'
end
+1 -1
View File
@@ -20,7 +20,7 @@ Since it seldomly changes, it is only rebuilt manually and on demand.
To rebuild the font (e.g., after changing icons in the source `app/assets/fonts/openproject_icon/src` directory), use the node script `generate.js`.
```
$ cd app/assets/fonts/openproject_icon
$ cd vendor/openproject-icon-font/
$ node generate.js
```