@bimdata/bimobject-viewer-plugin
Advanced tools
Comparing version 0.0.3 to 0.0.4
const BimObjectComponent = { | ||
name: 'BimObjectComponent', | ||
template: ` | ||
<div class="bim-object"> | ||
<div class="bim-object__search"> | ||
<input type="text" v-model="searchText" :placeholder="$t('bimObjectPlugin.search')" @keyup.enter="getProducts"> | ||
<button @click=getProducts>{{ $t('bimObjectPlugin.research') }}</button> | ||
</div> | ||
<div class="bim-object"> | ||
<div class="bim-object__search"> | ||
<input type="text" v-model="searchText" :placeholder="$t('bimObjectPlugin.search')" @keyup.enter="getProducts"> | ||
<button @click=getProducts>{{ $t('bimObjectPlugin.research') }}</button> | ||
</div> | ||
<div v-if="selected === null"> | ||
<div v-if="results.length > 0"> | ||
<ul class="products-wrapper"> | ||
<li class="product-card" v-for="item in results" @click="getProperties(item)"> | ||
<h4>{{ item.name }}</h4> | ||
<img :src="item.imageUrl"> | ||
</li> | ||
</ul> | ||
</div> | ||
<div class="bim-object__empty" v-else> | ||
<p>{{ $t('bimObjectPlugin.noObject') }}</p> | ||
<p>{{ $t('bimObjectPlugin.noObjectResearch') }}</p> | ||
</div> | ||
</div> | ||
<div v-if="selected === null"> | ||
<div v-if="results.length > 0"> | ||
<ul class="products-wrapper"> | ||
<li class="product-card" v-for="item in results" @click="getProperties(item)" :key="item.id"> | ||
<h4>{{ item.name }}</h4> | ||
<img :src="item.imageUrl"> | ||
</li> | ||
</ul> | ||
</div> | ||
<div class="bim-object__empty" v-else> | ||
<p>{{ $t('bimObjectPlugin.noObject') }}</p> | ||
<p>{{ $t('bimObjectPlugin.noObjectResearch') }}</p> | ||
</div> | ||
</div> | ||
<div v-else class="product"> | ||
<button @click="selected=null" class="btn-shadow">{{ $t('bimObjectPlugin.goBack') }}</button> | ||
<div class="product-card"> | ||
<h4>{{ selected.name }}</h4> | ||
<img :src="selected.imageUrl"> | ||
<img :src="selected.brand.imageUrl"> | ||
<button @click="setPropertiesToSelectecObjects">{{ $t('bimObjectPlugin.applySelected') }}</button> | ||
</div> | ||
</div> | ||
</div> | ||
`, | ||
<div v-else class="product"> | ||
<button @click="selected=null" class="btn-shadow">{{ $t('bimObjectPlugin.goBack') }}</button> | ||
<div class="product-card"> | ||
<div class="product-card-header"> | ||
<h4>{{ selected.name }}</h4> | ||
<img :src="selected.imageUrl"> | ||
<img :src="selected.brand.imageUrl"> | ||
<button @click="saveInBimdata">{{ $t('bimObjectPlugin.applySelected') }}</button> | ||
</div> | ||
<h3>Properties</h3> | ||
<ul class="product-card-list"> | ||
<li v-for="pset in propertySets" :key="pset.id"> | ||
<h6>{{ pset.name }}</h6> | ||
<ul class="product-card-list product-card-property-list"> | ||
<li v-for="prop in pset.properties" :key="prop.id"> | ||
{{ prop.definition.name }} - {{ prop.value }} | ||
</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
<h3>Classifications</h3> | ||
<ul class="product-card-list "> | ||
<li class="product-card-property-list product-card-list-flex" v-for="classif in classifications" :key="classif.name"> | ||
<span>{{ classif.name }}</span> | ||
<span>{{ classif.notation }} - {{ classif.title }}</span> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
`, | ||
data: function () { | ||
@@ -42,3 +62,4 @@ return { | ||
selected: null, | ||
properties: [], | ||
propertySets: [], | ||
classifications: [], | ||
searchText: "", | ||
@@ -81,9 +102,23 @@ } | ||
async getProperties(selected) { | ||
this.selected = selected; | ||
const productId = selected.id; | ||
const res = await fetch(`${this.bimobject_url}/details/?productId=${productId}`, { headers: this.headers }); | ||
const json = await res.json(); | ||
this.properties = json.data; | ||
this.selected = selected; | ||
this.propertySets = this.formatProperties(json.data); | ||
this.classifications = this.formatClassifications(json.classifications); | ||
console.log(JSON.parse(JSON.stringify(this.classifications))) | ||
}, | ||
async setPropertiesToSelectecObjects() { | ||
async saveInBimdata() { | ||
const selectedObjectIds = this.$utils.getSelectedObjectIds(); | ||
await Promise.all([ | ||
this.setPropertiesToSelectecObjects(selectedObjectIds), | ||
this.setClassificationsToSelectecObjects(selectedObjectIds) | ||
]); | ||
this.$hub.emit('updated-objects-properties', selectedObjectIds); | ||
this.$hub.emit('alert', { | ||
type: 'success', | ||
message: this.$t('bimObjectPlugin.successMessage') | ||
}); | ||
}, | ||
async setPropertiesToSelectecObjects(selectedObjectIds) { | ||
const loadedIfc = this.$utils.getSelectedIfcs()[0] | ||
@@ -95,6 +130,5 @@ const apiClient = new this.$bimdataApiClient.IfcApi(); | ||
this.$utils.getProjectId(), | ||
this.formatProperties(this.properties) | ||
this.propertySets | ||
); | ||
const psetIds = propertySets.map(pset => pset.id); | ||
const selectedObjectIds = this.$utils.getSelectedObjectIds(); | ||
const elementsPsetsRelations = selectedObjectIds.reduce((acc, elementUuid) => { | ||
@@ -110,8 +144,24 @@ psetIds.forEach(id => acc.push({ element_uuid: elementUuid, property_set_id: id })); | ||
); | ||
this.$hub.emit('updated-objects-properties', selectedObjectIds); | ||
this.$hub.emit('alert', { | ||
type: 'success', | ||
message: this.$t('bimObjectPlugin.successMessage') | ||
}); | ||
}, | ||
async setClassificationsToSelectecObjects(selectedObjectIds) { | ||
const loadedIfc = this.$utils.getSelectedIfcs()[0] | ||
const collaborationApi = new this.$bimdataApiClient.CollaborationApi(); | ||
const ifcApi = new this.$bimdataApiClient.IfcApi(); | ||
const classifications = await collaborationApi.createClassification( | ||
this.$utils.getCloudId(), | ||
this.$utils.getProjectId(), | ||
this.classifications | ||
); | ||
const classifIds = classifications.map(classif => classif.id); | ||
const elementsClassifRelations = selectedObjectIds.reduce((acc, elementUuid) => { | ||
classifIds.forEach(id => acc.push({ element_uuid: elementUuid, classification_id: id })); | ||
return acc; | ||
}, []); | ||
await ifcApi.createClassificationElementRelations( | ||
this.$utils.getCloudId(), | ||
loadedIfc.id, | ||
this.$utils.getProjectId(), | ||
elementsClassifRelations | ||
); | ||
}, | ||
getBimDataPropertyType(bimObjectType) { | ||
@@ -144,2 +194,13 @@ const mapping = { | ||
}); | ||
}, | ||
formatClassifications(bimObjectClassifs) { | ||
return Object.keys(bimObjectClassifs) | ||
.filter(name => name !== "bimObjectCategory") | ||
.map(name => { | ||
return { | ||
name, | ||
notation: bimObjectClassifs[name].code, | ||
title: bimObjectClassifs[name].name | ||
} | ||
}); | ||
} | ||
@@ -146,0 +207,0 @@ } |
{ | ||
"name": "@bimdata/bimobject-viewer-plugin", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "bimobject.plugin.js", |
9337
250