@@ -3,14 +3,15 @@ import {
33 computed , defineComponent , PropType , Ref , ref , watch ,
44} from ' vue' ;
55import {
6- Attribute , AttributeShortcut , NumericAttributeEditorOptions , StringAttributeEditorOptions ,
6+ Attribute , AttributeShortcut , MetadataLinkOptions , NumericAttributeEditorOptions , StringAttributeEditorOptions ,
77} from ' vue-media-annotator/use/AttributeTypes' ;
88import { usePrompt } from ' dive-common/vue-utilities/prompt-service' ;
99import { useTrackStyleManager } from ' vue-media-annotator/provides' ;
1010import AttributeShortcuts from ' ./AttributeShortcuts.vue' ;
1111import AttributeRendering from ' ./AttributeRendering.vue' ;
1212import AttributeValueColors from ' ./AttributeValueColors.vue' ;
1313import AttributeNumberValueColors from ' ./AttributeNumberColors.vue' ;
14+ import AttributeMetadataLink from ' ./AttributeMetadataLink.vue' ;
1415
1516export default defineComponent ({
1617 name: ' AttributeSettings' ,
@@ -19,12 +20,18 @@ export default defineComponent({
1920 AttributeRendering ,
2021 AttributeValueColors ,
2122 AttributeNumberValueColors ,
23+ AttributeMetadataLink ,
2224 },
2325 props: {
2426 selectedAttribute: {
2527 type: Object as PropType <Attribute >,
2628 required: true ,
2729 },
30+ /** Full attribute list (for metadata-link key picker). */
31+ allAttributes: {
32+ type: Array as PropType <Attribute []>,
33+ default : () => [],
34+ },
2835 error: {
2936 type: String ,
3037 default: ' ' ,
@@ -53,6 +60,36 @@ export default defineComponent({
5360 const editor: Ref <
5461 undefined | StringAttributeEditorOptions | NumericAttributeEditorOptions
5562 > = ref (props .selectedAttribute .editor );
63+ const normalizeMetadataNumberConditions = (
64+ nc : MetadataLinkOptions [' numberConditions' ],
65+ ): MetadataLinkOptions [' numberConditions' ] => {
66+ if (! nc ) return undefined ;
67+ return { mode: nc .mode , threshold: nc .threshold };
68+ };
69+
70+ const metadataLinkFromAttribute = (attr : Attribute ): MetadataLinkOptions => {
71+ const m = attr .metadataLink ;
72+ return {
73+ key: m ?.key || ' ' ,
74+ updateValue: m ?.updateValue || false ,
75+ useConditionals: m ?.useConditionals ,
76+ numberConditions: normalizeMetadataNumberConditions (m ?.numberConditions ),
77+ stringConditions: m ?.stringConditions ? { ... m .stringConditions } : undefined ,
78+ useDynamicKeyFromAttribute: m ?.useDynamicKeyFromAttribute ,
79+ dynamicKeyAttributeKey: m ?.dynamicKeyAttributeKey ,
80+ };
81+ };
82+
83+ const metadataLink: Ref <MetadataLinkOptions > = ref (
84+ metadataLinkFromAttribute (props .selectedAttribute ),
85+ );
86+
87+ watch (
88+ () => props .selectedAttribute .key ,
89+ () => {
90+ metadataLink .value = metadataLinkFromAttribute (props .selectedAttribute );
91+ },
92+ );
5693 let values: string [] = props .selectedAttribute .values ? props .selectedAttribute .values : [];
5794 let addNew = ! props .selectedAttribute .key .length ;
5895 const shortcuts: Ref <AttributeShortcut []> = ref (props .selectedAttribute .shortcuts || []);
@@ -81,6 +118,9 @@ export default defineComponent({
81118 belongs .value = ' track' ;
82119 datatype .value = ' number' ;
83120 values = [];
121+ metadataLink .value = {
122+ key: ' ' , updateValue: false , useDynamicKeyFromAttribute: false , dynamicKeyAttributeKey: undefined ,
123+ };
84124 }
85125 function add() {
86126 setDefaultValue ();
@@ -124,6 +164,26 @@ export default defineComponent({
124164 if (colorKeySettings .value ) {
125165 data .colorKeySettings = colorKeySettings .value ;
126166 }
167+ const useDyn = !! metadataLink .value .useDynamicKeyFromAttribute
168+ && !! metadataLink .value .dynamicKeyAttributeKey ?.trim ();
169+ const metadataLinkValue: MetadataLinkOptions = {
170+ key: useDyn ? ' ' : metadataLink .value .key .trim (),
171+ updateValue: metadataLink .value .updateValue ,
172+ useConditionals: metadataLink .value .useConditionals ,
173+ numberConditions: normalizeMetadataNumberConditions (
174+ metadataLink .value .numberConditions ,
175+ ),
176+ stringConditions: metadataLink .value .stringConditions
177+ ? { ... metadataLink .value .stringConditions }
178+ : undefined ,
179+ };
180+ if (useDyn ) {
181+ metadataLinkValue .useDynamicKeyFromAttribute = true ;
182+ metadataLinkValue .dynamicKeyAttributeKey = metadataLink .value .dynamicKeyAttributeKey ! .trim ();
183+ }
184+ if (metadataLinkValue .key .length || metadataLinkValue .updateValue || useDyn ) {
185+ data .metadataLink = metadataLinkValue ;
186+ }
127187 if (addNew ) {
128188 emit (' save' , { data , close });
129189 addNew = false ;
@@ -268,6 +328,7 @@ export default defineComponent({
268328 numericChange ,
269329 launchColorEditor ,
270330 saveAttributeValueColors ,
331+ metadataLink ,
271332 };
272333 },
273334});
@@ -283,6 +344,7 @@ export default defineComponent({
283344 <v-tab > Main </v-tab >
284345 <v-tab > Shortcuts </v-tab >
285346 <v-tab > Rendering </v-tab >
347+ <v-tab > MetadataLink </v-tab >
286348 <v-tab v-if =" datatype === 'text' || datatype === 'number'" >
287349 Value Colors
288350 </v-tab >
@@ -486,6 +548,15 @@ export default defineComponent({
486548 :attribute =" selectedAttribute"
487549 />
488550 </v-tab-item >
551+ <v-tab-item >
552+ <attribute-metadata-link
553+ v-model =" metadataLink"
554+ :belongs =" belongs"
555+ :datatype =" datatype"
556+ :all-attributes =" allAttributes"
557+ :current-attribute-key =" selectedAttribute.key"
558+ />
559+ </v-tab-item >
489560 <v-tab-item v-if =" datatype === 'text'" >
490561 <attribute-value-colors
491562 :attribute =" selectedAttribute"
0 commit comments