Merge pull request #8122 from opf/bim/feature/delete-viewpoints

Delete viewpoints from gallery
pull/8131/head
Oliver Günther 5 years ago committed by GitHub
commit 8093bc6af9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      frontend/src/app/modules/bim/bcf/api/bcf-api.service.ts
  2. 4
      frontend/src/app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.paths.ts
  3. 39
      frontend/src/app/modules/bim/bcf/bcf-wp-single-view/bcf-wp-single-view.component.ts
  4. 1
      modules/bim/config/locales/js-en.yml
  5. 73
      modules/bim/spec/features/viewer/delete_viewpoint_spec.rb
  6. 10
      modules/bim/spec/support/pages/ifc_models/bcf_details_page.rb

@ -27,7 +27,7 @@
// ++
import {Injectable, Injector} from "@angular/core";
import {BcfResourceCollectionPath, BcfResourcePath} from "core-app/modules/bim/bcf/api/bcf-path-resources";
import {BcfResourceCollectionPath} from "core-app/modules/bim/bcf/api/bcf-path-resources";
import {BcfProjectPaths} from "core-app/modules/bim/bcf/api/projects/bcf-project.paths";
@ -49,9 +49,9 @@ export class BcfApiService {
*
* @param href
*/
parse(href:string):BcfResourcePath|BcfResourceCollectionPath<any>|undefined {
parse<T>(href:string):T {
if (!href.startsWith(this.bcfApiBase)) {
return;
throw new Error(`Cannot parse ${href} into BCF resource.`);
}
const parts = href

@ -9,4 +9,8 @@ export class BcfViewpointPaths extends BcfResourcePath {
get(params:HTTPClientParamMap = {}, headers:HTTPClientHeaders = {}) {
return this.bcfTopicService.get(this.toPath(), params, headers);
}
delete(headers:HTTPClientHeaders = {}) {
return this.bcfTopicService.request('delete', this.toPath(), {}, headers);
}
}

@ -28,6 +28,8 @@ export class BcfWpSingleViewComponent implements OnInit, OnDestroy {
viewpoint: this.I18n.t('js.bcf.viewpoint'),
add_viewpoint: this.I18n.t('js.bcf.add_viewpoint'),
show_viewpoint: this.I18n.t('js.bcf.show_viewpoint'),
delete_viewpoint: this.I18n.t('js.bcf.delete_viewpoint'),
text_are_you_sure: this.I18n.t('js.text_are_you_sure')
};
actions = [
@ -35,6 +37,11 @@ export class BcfWpSingleViewComponent implements OnInit, OnDestroy {
icon: 'icon-watched',
onClick: this.showViewpoint.bind(this),
titleText: this.text.show_viewpoint
},
{
icon: 'icon-delete',
onClick: this.deleteViewpoint.bind(this),
titleText: this.text.delete_viewpoint
}
];
@ -118,21 +125,28 @@ export class BcfWpSingleViewComponent implements OnInit, OnDestroy {
}
showViewpoint(event:Event, index:number) {
let viewpointHref = this.workPackage.bcfViewpoints[index].href;
let viewpoint = this.bcfApi.parse(viewpointHref)!;
let viewpointUuid = viewpoint.id as string;
this
.bcfApi
.projects.id(this.workPackage.project.idFromLink)
.topics.id(this.topicUUID!)
.viewpoints.id(viewpointUuid)
.viewpointFromIndex(index)
.get()
.subscribe(data => {
this.viewerBridge.showViewpoint(data);
});
}
deleteViewpoint(event:Event, index:number) {
if (!window.confirm(this.text.text_are_you_sure)) {
return;
}
this
.viewpointFromIndex(index)
.delete()
.subscribe(data => {
// Update the work package to reload the viewpoint
this.wpCache.require(this.workPackage.id!, true);
});
}
async saveCurrentAsViewpoint() {
const viewpoint = await this.viewerBridge.getViewpoint();
const uuid = this.topicUUID || await this.createBcfTopic();
@ -160,7 +174,7 @@ export class BcfWpSingleViewComponent implements OnInit, OnDestroy {
const topicHref:string|undefined = this.workPackage.bcfTopic?.href;
if (topicHref) {
return this.bcfApi.parse(topicHref)!.id as string;
return this.bcfApi.parse<BcfViewpointPaths>(topicHref)!.id as string;
}
return null;
@ -177,7 +191,7 @@ export class BcfWpSingleViewComponent implements OnInit, OnDestroy {
private setViewpoints() {
this.viewpoints = this.workPackage.bcfViewpoints.map((vp:HalLink) => {
const viewpointResource = this.bcfApi.parse(vp.href!) as BcfViewpointPaths;
const viewpointResource = this.bcfApi.parse<BcfViewpointPaths>(vp.href!);
return {
snapshotId: viewpointResource.id,
@ -193,4 +207,9 @@ export class BcfWpSingleViewComponent implements OnInit, OnDestroy {
};
});
}
private viewpointFromIndex(index:number):BcfViewpointPaths {
let viewpointHref = this.workPackage.bcfViewpoints[index].href;
return this.bcfApi.parse<BcfViewpointPaths>(viewpointHref);
}
}

@ -8,6 +8,7 @@ en:
viewpoint: 'Viewpoint'
add_viewpoint: 'Add viewpoint'
show_viewpoint: 'Show viewpoint'
delete_viewpoint: 'Delete viewpoint'
ifc_models:
models:
default: 'Default IFC models'

@ -0,0 +1,73 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2020 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-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_relative '../../spec_helper'
describe 'Delete viewpoint in model viewer', type: :feature, js: true do
let(:project) { FactoryBot.create :project, enabled_module_names: [:bim, :work_package_tracking] }
let(:user) { FactoryBot.create :admin }
let!(:work_package) { FactoryBot.create(:work_package, project: project) }
let!(:bcf) { FactoryBot.create :bcf_issue, work_package: work_package }
let!(:viewpoint) { FactoryBot.create :bcf_viewpoint, issue: bcf, viewpoint_name: 'minimal_hidden_except_one' }
let!(:model) do
FactoryBot.create(:ifc_model_minimal_converted,
title: 'minimal',
project: project,
uploader: user)
end
let(:model_tree) { ::Components::XeokitModelTree.new }
let(:bcf_details) { ::Pages::BcfDetailsPage.new(work_package, project) }
before do
login_as(user)
bcf_details.visit!
end
it 'can delete the viewpoint through the gallery' do
bcf_details.ensure_page_loaded
bcf_details.expect_viewpoint_count 1
bcf_details.show_current_viewpoint
# Delete but don't confirm alert
bcf_details.delete_current_viewpoint confirm: false
sleep 1
bcf_details.expect_viewpoint_count 1
# Delete for real now
bcf_details.delete_current_viewpoint confirm: true
sleep 1
bcf_details.expect_viewpoint_count 0
bcf.reload
expect(bcf.viewpoints).to be_empty
end
end

@ -46,6 +46,16 @@ module Pages
page.find('.icon-watched.ngx-gallery-icon-content').click
end
def delete_current_viewpoint(confirm: true)
page.find('.icon-delete.ngx-gallery-icon-content').click
if confirm
page.driver.browser.switch_to.alert.accept
else
page.driver.browser.switch_to.alert.dismiss
end
end
def add_viewpoint
page.find('a.button', text: 'Viewpoint').click
end

Loading…
Cancel
Save