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
Remove gon from IFC
Oliver Güntherdf068a27e7e5
diff --git a/frontend/src/app/core/gon/gon.service.ts b/frontend/src/app/core/gon/gon.service.tsdeleted file mode 100644index 7a6a24a1461..00000000000--- a/frontend/src/app/core/gon/gon.service.ts+++ /dev/null@@ -1,55 +0,0 @@-//-- copyright-// OpenProject is an open source project management software.-// Copyright (C) the OpenProject GmbH-//-// 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 COPYRIGHT and LICENSE files for more details.-//++--import { Injectable } from '@angular/core';-import { IFCGonDefinition } from '../../features/bim/ifc_models/pages/viewer/ifc-models-data.service';--declare global {- interface Window {- gon:GonType;- }-}--export interface GonType {- [key:string]:unknown;- ifc_models:IFCGonDefinition;-}--@Injectable({ providedIn: 'root' })-export class GonService {- get(...path:string[]):unknown|null {- return _.get(window.gon, path, null);- }-- /**- * Get the gon object- */- get gon():GonType {- return window.gon;- }-}diff --git a/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.service.ts b/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.service.tsindex fba6e8d9b3d..5db248b9253 100644--- a/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.service.ts+++ b/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.service.ts@@ -37,7 +37,10 @@ import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decoraimport { ViewpointsService } from 'core-app/features/bim/bcf/helper/viewpoints.service';import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';import { HttpClient } from '@angular/common/http';-import { IfcProjectDefinition } from 'core-app/features/bim/ifc_models/pages/viewer/ifc-models-data.service';+import {+ IfcModelsDataService,+ IfcProjectDefinition,+} from 'core-app/features/bim/ifc_models/pages/viewer/ifc-models-data.service';import { BIMViewer } from '@xeokit/xeokit-bim-viewer/dist/xeokit-bim-viewer.es';import { BcfViewpointData, CreateBcfViewpointData } from 'core-app/features/bim/bcf/api/bcf-api.model';import { HalResource } from 'core-app/features/hal/resources/hal-resource';@@ -113,6 +116,8 @@ export class IFCViewerService extends ViewerBridgeService {@InjectField() viewpointsService:ViewpointsService;+ @InjectField() ifcModelsDataService:IfcModelsDataService;+@InjectField() currentProjectService:CurrentProjectService;@InjectField() httpClient:HttpClient;@@ -122,7 +127,7 @@ export class IFCViewerService extends ViewerBridgeService {}public newViewer(elements:XeokitElements, projects:IfcProjectDefinition[]):void {- const server = new XeokitServer(this.pathHelper);+ const server = new XeokitServer(this.pathHelper, this.ifcModelsDataService);// eslint-disable-next-line @typescript-eslint/no-unsafe-callconst viewerUI = new BIMViewer(server, elements) as XeokitBimViewer;diff --git a/frontend/src/app/features/bim/ifc_models/pages/viewer/ifc-models-data.service.ts b/frontend/src/app/features/bim/ifc_models/pages/viewer/ifc-models-data.service.tsindex 8c7efda1df5..5330c823ac9 100644--- a/frontend/src/app/features/bim/ifc_models/pages/viewer/ifc-models-data.service.ts+++ b/frontend/src/app/features/bim/ifc_models/pages/viewer/ifc-models-data.service.ts@@ -1,7 +1,7 @@-import { Injectable } from '@angular/core';+import { inject, Injectable } from '@angular/core';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';-import { GonService } from 'core-app/core/gon/gon.service';import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';+import { getMetaElement } from 'core-app/core/setup/globals/global-helpers';export interface IFCPermissionMap {manage_ifc_models:boolean;@@ -19,7 +19,7 @@ export interface IfcModelDefinition {default:boolean;}-export interface IFCGonDefinition {+export interface IFCModelData {models:IfcModelDefinition[];shown_models:number[];projects:IfcProjectDefinition[];@@ -29,22 +29,41 @@ export interface IFCGonDefinition {@Injectable()export class IfcModelsDataService {- constructor(- readonly paths:PathHelperService,- readonly currentProjectService:CurrentProjectService,- readonly gon:GonService,- ) { }+ private data:IFCModelData = {+ models: [],+ shown_models: [],+ projects: [],+ xkt_attachment_ids: {},+ permissions: {+ manage_ifc_models: false,+ manage_bcf: false,+ },+ };++ readonly paths = inject(PathHelperService);+ readonly currentProjectService = inject(CurrentProjectService);++ constructor() {+ const models = getMetaElement('openproject_ifc_models')?.dataset.models;+ if (models) {+ this.data = JSON.parse(models) as IFCModelData;+ }+ }public get models():IfcModelDefinition[] {- return this.gonIFC.models;+ return this.data.models;}public get projects():IfcProjectDefinition[] {- return this.gonIFC.projects;+ return this.data.projects;+ }++ public get xktAttachmentIds():{ [id:number]:number } {+ return this.data.xkt_attachment_ids;}public get shownModels():number[] {- return this.gonIFC.shown_models;+ return this.data.shown_models;}public isSingleModel() {@@ -62,10 +81,6 @@ export class IfcModelsDataService {}public allowed(permission:keyof IFCPermissionMap):boolean {- return !!this.gonIFC.permissions[permission];- }-- private get gonIFC():IFCGonDefinition {- return (this.gon.get('ifc_models') as IFCGonDefinition);+ return !!this.data.permissions[permission];}}diff --git a/frontend/src/app/features/bim/ifc_models/xeokit/xeokit-server.ts b/frontend/src/app/features/bim/ifc_models/xeokit/xeokit-server.tsindex 73c7e4cd8bd..bc218fdebf5 100644--- a/frontend/src/app/features/bim/ifc_models/xeokit/xeokit-server.ts+++ b/frontend/src/app/features/bim/ifc_models/xeokit/xeokit-server.ts@@ -1,30 +1,31 @@-// @ts-ignore+// @ts-expect-error xeokit-sdk has no module+// eslint-disable-next-line import/no-extraneous-dependenciesimport { utils } from '@xeokit/xeokit-sdk/dist/xeokit-sdk.es';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';-import { IFCGonDefinition } from '../pages/viewer/ifc-models-data.service';+import { IfcModelsDataService } from '../pages/viewer/ifc-models-data.service';+import { debugLog } from 'core-app/shared/helpers/debug_output';/*** Default server client which loads content via HTTP from the file system.*/export class XeokitServer {- private ifcModels:IFCGonDefinition;-/**** @param config- * @param.config.pathHelper instance of PathHelperService.+ * @param pathHelper instance of PathHelperService.+ * @param ifcModelsDataService instance of IfcModelsDataService.*/- constructor(private pathHelper:PathHelperService) {- this.ifcModels = window.gon.ifc_models;+ constructor(+ private pathHelper:PathHelperService,+ private ifcModelsDataService:IfcModelsDataService,+ ) {}/*** Gets the manifest of all projects.- * @param done- * @param error*/- getProjects(done:Function, _error:Function) {- done({ projects: this.ifcModels.projects });+ getProjects(done:(result:unknown) => void, _error:() => void) {+ done({ projects: this.ifcModelsDataService.projects });}/**@@ -34,7 +35,7 @@ export class XeokitServer {* @param _error*/getProject(projectId:string, done:(json:unknown) => void, _error:() => void) {- const projectDefinition = this.ifcModels.projects.find((p) => p.id === projectId);+ const projectDefinition = this.ifcModelsDataService.projects.find((p) => p.id === projectId);if (projectDefinition === undefined) {throw new Error(`unknown project id '${projectId}'`);}@@ -42,9 +43,9 @@ export class XeokitServer {const manifestData = {id: projectDefinition.id,name: projectDefinition.name,- models: this.ifcModels.models,+ models: this.ifcModelsDataService.models,viewerContent: {- modelsLoaded: this.ifcModels.shown_models,+ modelsLoaded: this.ifcModelsDataService.shownModels,},viewerConfigs: {},};@@ -59,9 +60,10 @@ export class XeokitServer {* @param done* @param error*/- getGeometry(projectId:string, modelId:number, done:Function, error:Function) {- const attachmentId = this.ifcModels.xkt_attachment_ids[modelId];- console.log(`Loading model geometry for: ${attachmentId}`);+ getGeometry(projectId:string, modelId:number, done:() => void, error:() => void) {+ const attachmentId = this.ifcModelsDataService.xktAttachmentIds[modelId];+ debugLog(`Loading model geometry for: ${attachmentId}`);+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-accessutils.loadArraybuffer(this.pathHelper.attachmentContentPath(attachmentId), done, error);}}diff --git a/modules/bim/app/helpers/ifc_models_helper.rb b/modules/bim/app/helpers/ifc_models_helper.rbindex b9f801caae7..1d50932d073 100644--- a/modules/bim/app/helpers/ifc_models_helper.rb+++ b/modules/bim/app/helpers/ifc_models_helper.rb@@ -1,8 +1,8 @@module IfcModelsHelper- def provision_gon_for_ifc_model(all_models, shown_models)+ def ifc_model_data_object(all_models, shown_models)all_converted_models = converted_ifc_models(all_models)- gon.ifc_models = {+ {models: gon_ifc_model_models(all_converted_models),shown_models: gon_ifc_shown_models(all_converted_models, shown_models),projects: [{ id: @project.identifier, name: @project.name }],diff --git a/modules/bim/app/views/bim/ifc_models/ifc_viewer/show.html.erb b/modules/bim/app/views/bim/ifc_models/ifc_viewer/show.html.erbindex 032c4e6f161..aac23ce71b1 100644--- a/modules/bim/app/views/bim/ifc_models/ifc_viewer/show.html.erb+++ b/modules/bim/app/views/bim/ifc_models/ifc_viewer/show.html.erb@@ -27,10 +27,15 @@ See COPYRIGHT and LICENSE files for more details.++#%>+<% content_for :header_tags do %>- <% provision_gon_for_ifc_model(@ifc_models, @shown_model_ids) %>+ <%= tag :meta,+ name: "openproject_ifc_models",+ data: {+ models: ifc_model_data_object(@ifc_models, @shown_model_ids).to_json+ }+ %><% end %>-<% unconverted = @shown_ifc_models.reject(&:converted?) %><% if unconverted.any? %>