@@ -2537,6 +2537,213 @@ export const useProfileStore = defineStore('profile', {
2537
2537
2538
2538
} ,
2539
2539
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
+ } ,
2540
2747
2541
2748
2542
2749
0 commit comments