Skip to content

Commit ba4eb77

Browse files
added delete component feature
1 parent 3ed7dc9 commit ba4eb77

File tree

7 files changed

+264
-46
lines changed

7 files changed

+264
-46
lines changed

src/components/panels/edit/EditPanel.vue

+25-23
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
<template v-if="(preferenceStore.returnValue('--b-edit-main-splitpane-edit-adhoc-mode') === true && activeProfile.rt[profileName].pt[profileCompoent].canBeHidden === false) || preferenceStore.returnValue('--b-edit-main-splitpane-edit-adhoc-mode') === false">
2828

29-
3029
<div class="component-label" >{{activeProfile.rt[profileName].pt[profileCompoent].propertyLabel}}</div>
3130
<Main
3231
:guid="activeProfile.rt[profileName].pt[profileCompoent]['@guid']"
@@ -50,35 +49,38 @@
5049

5150
<template v-if="((preferenceStore.returnValue('--b-edit-main-splitpane-edit-switch-between-resource-button') === false) || (preferenceStore.returnValue('--b-edit-main-splitpane-edit-switch-between-resource-button') === true && profileName == activeResourceName ))">
5251

53-
<div :class="{ 'inline-mode' : (preferenceStore.returnValue('--b-edit-main-splitpane-edit-inline-mode')), 'edit-panel-scroll-x-child': preferenceStore.returnValue('--b-edit-main-splitpane-edit-scroll-x')}">
52+
<template v-if="!activeProfile.rt[profileName].pt[profileCompoent].deleted">
53+
54+
<div :class="{ 'inline-mode' : (preferenceStore.returnValue('--b-edit-main-splitpane-edit-inline-mode')), 'edit-panel-scroll-x-child': preferenceStore.returnValue('--b-edit-main-splitpane-edit-scroll-x')}">
5455

5556

5657

57-
<template v-if="preferenceStore.returnValue('--b-edit-main-splitpane-edit-shortcode-display-mode') == false && preferenceStore.returnValue('--b-edit-main-splitpane-edit-inline-mode') == false ">
58-
<div class="component-label" >{{activeProfile.rt[profileName].pt[profileCompoent].propertyLabel}}</div>
59-
</template>
58+
<template v-if="preferenceStore.returnValue('--b-edit-main-splitpane-edit-shortcode-display-mode') == false && preferenceStore.returnValue('--b-edit-main-splitpane-edit-inline-mode') == false ">
59+
<div class="component-label" >{{activeProfile.rt[profileName].pt[profileCompoent].propertyLabel}}</div>
60+
</template>
61+
62+
<template v-if="preferenceStore.returnValue('--b-edit-main-splitpane-edit-inline-mode')">
63+
<div v-if="profileName.split(':').slice(-1)[0] == 'Work'" class="inline-mode-resource-color-work">&nbsp;</div>
64+
<div v-if="profileName.indexOf(':Instance') > -1" class="inline-mode-resource-color-instance">&nbsp;</div>
65+
<button @mouseenter="inlineRowButtonMouseEnter" :class="{'inline-mode-mian-button': true, 'inline-mode-mian-button-has-ref' : profileStore.ptHasRefComponent(activeProfile.rt[profileName].pt[profileCompoent]) }"></button>
66+
67+
68+
</template>
6069

61-
<template v-if="preferenceStore.returnValue('--b-edit-main-splitpane-edit-inline-mode')">
62-
<div v-if="profileName.split(':').slice(-1)[0] == 'Work'" class="inline-mode-resource-color-work">&nbsp;</div>
63-
<div v-if="profileName.indexOf(':Instance') > -1" class="inline-mode-resource-color-instance">&nbsp;</div>
64-
<button @mouseenter="inlineRowButtonMouseEnter" :class="{'inline-mode-mian-button': true, 'inline-mode-mian-button-has-ref' : profileStore.ptHasRefComponent(activeProfile.rt[profileName].pt[profileCompoent]) }"></button>
65-
6670

71+
<Main
72+
:guid="activeProfile.rt[profileName].pt[profileCompoent]['@guid']"
73+
:level="0"
74+
:id="activeProfile.rt[profileName].pt[profileCompoent].id"
75+
:parentId="activeProfile.rt[profileName].pt[profileCompoent].parentId"/>
76+
77+
<template v-if="preferenceStore.returnValue('--b-edit-main-splitpane-edit-inline-mode')">
78+
<InlineModeAddField :guid="activeProfile.rt[profileName].pt[profileCompoent]['@guid']" />
79+
</template>
80+
81+
</div>
6782
</template>
68-
69-
<Main
70-
:guid="activeProfile.rt[profileName].pt[profileCompoent]['@guid']"
71-
:level="0"
72-
:id="activeProfile.rt[profileName].pt[profileCompoent].id"
73-
:parentId="activeProfile.rt[profileName].pt[profileCompoent].parentId"/>
74-
75-
<template v-if="preferenceStore.returnValue('--b-edit-main-splitpane-edit-inline-mode')">
76-
<InlineModeAddField :guid="activeProfile.rt[profileName].pt[profileCompoent]['@guid']" />
77-
</template>
78-
79-
</div>
8083
</template>
81-
8284
</template>
8385

8486
</template>

src/components/panels/edit/fields/helpers/ActionButton.vue

+10-5
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@
6060
<button style="width:100%" class="" @click="showDebug()">
6161
Debug
6262
</button>
63+
6364
<button style="width:100%" class="" @click="duplicateComponent()">
6465
Add Component
6566
</button>
66-
67+
<button style="width:100%" class="" @click="deleteComponent()">
68+
Delete Component
69+
</button>
6770

6871

6972

@@ -148,12 +151,14 @@
148151
},
149152
150153
duplicateComponent: function(){
151-
152154
this.profileStore.duplicateComponent(this.profileStore.returnStructureByComponentGuid(this.guid)['@guid'])
153-
154-
155-
156155
},
156+
deleteComponent: function(){
157+
this.profileStore.deleteComponent(this.profileStore.returnStructureByComponentGuid(this.guid)['@guid'])
158+
},
159+
160+
161+
157162
addComponent: function(){
158163
159164
},

src/components/panels/sidebar_preview_opac/Opac.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189

190190
<ul class="sidebar-opac-ul" role="list">
191191
<template v-for="(profileCompoent,idx) in activeProfile.rt[profileName].ptOrder" :key="profileCompoent">
192-
<li v-if="activeProfile.rt[profileName].pt[profileCompoent].hasData" @click.stop="activeComponent = activeProfile.rt[profileName].pt[profileCompoent]" class="sidebar-opac-li sidebar-opac-li-empty" >
192+
<li v-if="activeProfile.rt[profileName].pt[profileCompoent].hasData && !activeProfile.rt[profileName].pt[profileCompoent].deleted" @click.stop="activeComponent = activeProfile.rt[profileName].pt[profileCompoent]" class="sidebar-opac-li sidebar-opac-li-empty" >
193193
<a style="font-size:0.95em" href="#" @click.stop="activeComponent = activeProfile.rt[profileName].pt[profileCompoent]" class="sidebar-property-ul-alink">
194194
{{activeProfile.rt[profileName].pt[profileCompoent].propertyLabel}}
195195
</a>

src/components/panels/sidebar_property/Properties.vue

+17-17
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,23 @@
117117
@end="drag=false"
118118
item-key="id">
119119
<template #item="{element}">
120-
121-
<li @click.stop="activeComponent = activeProfile.rt[profileName].pt[element]" class="sidebar-property-li sidebar-property-li-empty">
122-
123-
<a href="#" @click.stop="activeComponent = activeProfile.rt[profileName].pt[element]" class="sidebar-property-ul-alink">
124-
<template v-if="preferenceStore.returnValue('--b-edit-main-splitpane-properties-number-labels')">{{activeProfile.rt[profileName].ptOrder.indexOf(element)}}</template>
125-
{{activeProfile.rt[profileName].pt[element].propertyLabel}}
126-
</a>
127-
<template v-if="preferenceStore.returnValue('--b-edit-main-splitpane-properties-show-types')">
128-
<template v-if="activeProfile.rt[profileName].pt[element].valueConstraint.valueTemplateRefs.length>1">
129-
<ul class="sidebar-property-ul sidebar-property-ul-sub-ul">
130-
<li class="sidebar-property-li sidebar-property-li-sub-li" :key="t" v-for="t in returnTemplateTypes(activeProfile.rt[profileName].pt[element].valueConstraint.valueTemplateRefs)">
131-
<a tabindex="-1" href="#" class="sidebar-property-ul-alink sidebar-property-ul-alink-sublink" >{{t}}</a>
132-
</li>
133-
</ul>
134-
</template>
135-
</template>
136-
</li>
120+
<template v-if="!activeProfile.rt[profileName].pt[element].deleted">
121+
<li @click.stop="activeComponent = activeProfile.rt[profileName].pt[element]" class="sidebar-property-li sidebar-property-li-empty">
122+
<a href="#" @click.stop="activeComponent = activeProfile.rt[profileName].pt[element]" class="sidebar-property-ul-alink">
123+
<template v-if="preferenceStore.returnValue('--b-edit-main-splitpane-properties-number-labels')">{{activeProfile.rt[profileName].ptOrder.indexOf(element)}}</template>
124+
{{activeProfile.rt[profileName].pt[element].propertyLabel}}
125+
</a>
126+
<template v-if="preferenceStore.returnValue('--b-edit-main-splitpane-properties-show-types')">
127+
<template v-if="activeProfile.rt[profileName].pt[element].valueConstraint.valueTemplateRefs.length>1">
128+
<ul class="sidebar-property-ul sidebar-property-ul-sub-ul">
129+
<li class="sidebar-property-li sidebar-property-li-sub-li" :key="t" v-for="t in returnTemplateTypes(activeProfile.rt[profileName].pt[element].valueConstraint.valueTemplateRefs)">
130+
<a tabindex="-1" href="#" class="sidebar-property-ul-alink sidebar-property-ul-alink-sublink" >{{t}}</a>
131+
</li>
132+
</ul>
133+
</template>
134+
</template>
135+
</li>
136+
</template>
137137
</template>
138138
</draggable>
139139

src/lib/utils_export.js

+3
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,9 @@ const utilsExport = {
416416

417417
// extract the pt, this is the individual component like a <mainTitle>
418418
let ptObj = profile.rt[rt].pt[pt]
419+
if (ptObj.deleted){
420+
continue
421+
}
419422

420423
xmlLog.push(`Working on: ${pt}`)
421424
// console.log('ptObj.userValue',ptObj.userValue)

src/lib/utils_parse.js

+1
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,7 @@ const utilsParse = {
11581158
let newKey = `${k}_${counter}`
11591159
let currentpos = profile.rt[pkey].ptOrder.indexOf(k)
11601160
profile.rt[pkey].ptOrder.splice(currentpos+1, 0, newKey);
1161+
populateData.id = newKey
11611162
pt[newKey] = populateData
11621163

11631164

src/stores/profile.js

+207
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,213 @@ export const useProfileStore = defineStore('profile', {
25372537

25382538
},
25392539

2540+
/**
2541+
* Delete existing component
2542+
*
2543+
* @param {string} componentGuid - the guid of the component (the parent of all fields)
2544+
* @return {void}
2545+
*/
2546+
deleteComponent: async function(componentGuid){
2547+
2548+
console.log(componentGuid)
2549+
2550+
// locate the correct pt to work on in the activeProfile
2551+
let pt = utilsProfile.returnPt(this.activeProfile,componentGuid)
2552+
2553+
if (pt !== false){
2554+
console.log(this.activeProfile)
2555+
2556+
// first see how many these properties exist in the resource
2557+
let propertyCount = 0
2558+
for (let k in this.activeProfile.rt[pt.parentId].pt){
2559+
if (this.activeProfile.rt[pt.parentId].pt[k].propertyURI == pt.propertyURI && !this.activeProfile.rt[pt.parentId].pt[k].deleted){
2560+
2561+
propertyCount++
2562+
}
2563+
}
2564+
2565+
// if the propertyCount is 1 then we are about to delete the only property
2566+
// so instead just blank out the user value so it still exists if they need to add a value
2567+
2568+
if (propertyCount>1){
2569+
2570+
console.log("deleting")
2571+
console.log(this.activeProfile.rt[pt.parentId].pt[pt.id])
2572+
// delete this.activeProfile.rt[pt.parentId].pt[pt.id]
2573+
2574+
this.activeProfile.rt[pt.parentId].pt[pt.id].deleted = true
2575+
2576+
}else{
2577+
2578+
for (let key in this.activeProfile.rt[pt.parentId].pt[pt.id].userValue){
2579+
if (!key.startsWith('@')){
2580+
delete this.activeProfile.rt[pt.parentId].pt[pt.id].userValue[key]
2581+
}
2582+
}
2583+
2584+
2585+
}
2586+
2587+
// if the
2588+
2589+
// let profile
2590+
// let propertyPosition
2591+
// for (let r of this.activeProfile.rtOrder){
2592+
// propertyPosition = this.activeProfile.rt[r].ptOrder.indexOf(pt.id)
2593+
// if (propertyPosition != -1){
2594+
// profile = r
2595+
// break
2596+
// }
2597+
// }
2598+
2599+
// let key = pt.propertyURI.replace('http://','').replace('https://','').replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"_") + '__' + ((pt.propertyLabel) ? pt.propertyLabel.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"").replace(/\s+/g,'_').toLowerCase() : "plabel")
2600+
// let newPropertyId = key + '_'+ (+ new Date())
2601+
2602+
2603+
// let newPt = JSON.parse(JSON.stringify(pt))
2604+
// newPt.id = newPropertyId
2605+
// newPt['@guid'] = short.generate()
2606+
2607+
2608+
// console.log("Lookign at this PT", pt)
2609+
// console.log(this.activeProfile)
2610+
// console.log(propertyPosition)
2611+
// console.log(key,newPropertyId)
2612+
// if (createEmpty){
2613+
2614+
2615+
// // store.state.activeUndoLog.push(`Added another property ${exportXML.namespaceUri(activeProfile.rt[profile].pt[id].propertyURI)}`)
2616+
2617+
// // console.log(activeProfile.rt[profile].pt[newPropertyId])
2618+
// // console.log(profile,newPropertyId)
2619+
// newPt.userValue = {
2620+
// '@guid': short.generate(),
2621+
// '@root' : newPt.propertyURIhihi
2622+
2623+
// }
2624+
2625+
// // we also want to add any default values in if it is just a empty new property and not duping
2626+
2627+
// let idPropertyId = newPt.propertyURI
2628+
2629+
// let baseURI = newPt.propertyURI
2630+
2631+
2632+
// // let defaults = null
2633+
// let defaultsProperty
2634+
2635+
2636+
// let useProfile = profile
2637+
// // if the profile is a multiple, like lc:RT:bf2:Monograph:Item-0 split off the -0 for it to find it in the RT lookup
2638+
// if (!this.rtLookup[useProfile]){
2639+
// if (useProfile.includes('-')){
2640+
// useProfile = useProfile.split('-')[0]
2641+
// }
2642+
// }
2643+
// // first check the top level
2644+
// if (this.rtLookup[useProfile]){
2645+
// defaultsProperty = this.rtLookup[useProfile].propertyTemplates.filter((x)=>{ return (x.propertyURI === idPropertyId) ? true : false})
2646+
// if (defaultsProperty.length>0){
2647+
// defaultsProperty=defaultsProperty[0]
2648+
2649+
// }
2650+
// }
2651+
2652+
2653+
2654+
// if (defaultsProperty && defaultsProperty.valueConstraint.defaults.length>0){
2655+
// // make sure the base URI exists in the uservalue
2656+
// if (!newPt.userValue[baseURI]){
2657+
// newPt.userValue[baseURI] = [{}]
2658+
// }
2659+
// let userValue = newPt.userValue[baseURI][0]
2660+
2661+
// // there are defauts at this level
2662+
// // its not a nested component just add it in the first level
2663+
// if (defaultsProperty.valueConstraint.defaults[0].defaultLiteral){
2664+
// // console.log(newPt)
2665+
// userValue['http://www.w3.org/2000/01/rdf-schema#label'] = [{
2666+
// '@guid': short.generate(),
2667+
// 'http://www.w3.org/2000/01/rdf-schema#label':defaultsProperty.valueConstraint.defaults[0].defaultLiteral
2668+
// }]
2669+
// }
2670+
// if (defaultsProperty.valueConstraint.defaults[0].defaultURI){
2671+
// userValue['@id'] = defaultsProperty.valueConstraint.defaults[0].defaultURI
2672+
// }
2673+
2674+
2675+
// }else if (defaultsProperty && defaultsProperty.valueConstraint.valueTemplateRefs.length>0){
2676+
2677+
// if (!newPt.userValue[baseURI]){
2678+
// newPt.userValue[baseURI] = [{}]
2679+
// }
2680+
// let userValue = newPt.userValue[baseURI][0]
2681+
2682+
2683+
// // it doesn't exist at the top level, see if it has at least one reference template, if so use the first one and look up if that one has defualt values
2684+
// // the first one since it is the default for the referencetemplace componment
2685+
// let useRef = defaultsProperty.valueConstraint.valueTemplateRefs[0]
2686+
2687+
// // look through all of them and add in any default
2688+
// for (let refPt of this.rtLookup[useRef].propertyTemplates){
2689+
// if (refPt.valueConstraint.defaults.length>0){
2690+
// let defaults = refPt.valueConstraint.defaults[0]
2691+
// if (defaults.defaultLiteral){
2692+
// userValue[refPt.propertyURI]= [{
2693+
// '@guid': short.generate(),
2694+
// 'http://www.w3.org/2000/01/rdf-schema#label': [
2695+
// {
2696+
// 'http://www.w3.org/2000/01/rdf-schema#label':defaults.defaultLiteral,
2697+
// '@guid': short.generate(),
2698+
// }
2699+
// ]
2700+
// }]
2701+
// }
2702+
// if (defaults.defaultURI){
2703+
// if (userValue[refPt.propertyURI][0]){
2704+
// userValue[refPt.propertyURI][0]['@id'] = defaults.defaultURI
2705+
// if (refPt.valueConstraint.valueDataType && refPt.valueConstraint.valueDataType.dataTypeURI){
2706+
// userValue[refPt.propertyURI][0]['@type'] = refPt.valueConstraint.valueDataType.dataTypeURI
2707+
// }
2708+
// }
2709+
// }
2710+
// }
2711+
// }
2712+
// }
2713+
2714+
2715+
// // make sure we didnt make an empty propery array [{}]
2716+
// if (newPt.userValue[baseURI]){
2717+
// if (newPt.userValue[baseURI][0]){
2718+
// if (Object.keys(newPt.userValue[baseURI][0]).length === 0){
2719+
// delete newPt.userValue[baseURI]
2720+
// }
2721+
// }
2722+
// }
2723+
2724+
2725+
2726+
2727+
// }else{
2728+
2729+
2730+
2731+
// }
2732+
2733+
// console.log(JSON.stringify(newPt,null,2))
2734+
// this.activeProfile.rt[profile].pt[newPropertyId] = JSON.parse(JSON.stringify(newPt))
2735+
// this.activeProfile.rt[profile].ptOrder.splice(propertyPosition+1, 0, newPropertyId);
2736+
// console.log(this.activeProfile.rt[profile].ptOrder)
2737+
// // they changed something
2738+
// this.activeProfileSaved = false
2739+
2740+
}else{
2741+
console.error('deleteComponent: Cannot locate the component by guid', componentGuid, this.activeProfile)
2742+
console.log(JSON.stringify(this.activeProfile))
2743+
}
2744+
2745+
2746+
},
25402747

25412748

25422749

0 commit comments

Comments
 (0)