| 
1 | 1 | <template>  | 
2 | 2 |   <div class="SliderInput ml-3 mr-3 pl-3 pr-3">  | 
3 | 3 |     <vue-slider v-model="input" :lazy="true" :data="interval"  | 
4 |  | -                :marks="true" :process="false"></vue-slider>  | 
 | 4 | +                :marks="getMarks" :process="false"></vue-slider>  | 
5 | 5 |     <b-row class="mt-3 pt-3 pl-0 pr-0">  | 
6 | 6 |       <div class="col text-left pr-0 pl-0">  | 
7 | 7 |         <span v-if="getMinImageLabel">  | 
8 | 8 |           <img class="imgLabel" :src="getMinImageLabel" />  | 
9 | 9 |         </span>  | 
10 | 10 |         <p>{{ getMinLabel }}</p>  | 
11 | 11 |       </div>  | 
 | 12 | +      <div class="col text-center pr-0 pl-0" v-if="getMidLabel">  | 
 | 13 | +        <span v-if="getMidImageLabel">  | 
 | 14 | +          <img class="imgLabel" :src="getMidImageLabel" />  | 
 | 15 | +        </span>  | 
 | 16 | +        <p>{{ getMidLabel }}</p>  | 
 | 17 | +      </div>  | 
12 | 18 |       <div class="col text-right pr-0 pl-0">  | 
13 | 19 |         <span v-if="getMaxImageLabel">  | 
14 | 20 |           <img class="imgLabel" :src="getMaxImageLabel" />  | 
@@ -47,43 +53,93 @@ export default {  | 
47 | 53 |     },  | 
48 | 54 |   },  | 
49 | 55 |   computed: {  | 
 | 56 | +    choices() {  | 
 | 57 | +      return this.constraints['http://schema.repronim.org/choices'] || [];  | 
 | 58 | +    },  | 
 | 59 | +      | 
50 | 60 |     interval() {  | 
51 |  | -      return _.map(this.constraints['http://schema.repronim.org/choices'], (v) => {  | 
52 |  | -        // console.log(52, v['http://schema.repronim.org/value'][0]['@value']);  | 
53 |  | -        return v['http://schema.repronim.org/value'][0]['@value'];  | 
54 |  | -      });  | 
55 |  | -      // const diff = choices[1]-choices[0];  | 
56 |  | -      // console.log(55, choices, diff, choices.unshift(choices[0] - diff));  | 
57 |  | -      // return choices;  | 
 | 61 | +      const minValue = this.constraints['http://schema.org/minValue'];  | 
 | 62 | +      const maxValue = this.constraints['http://schema.org/maxValue'];  | 
 | 63 | +        | 
 | 64 | +      if (minValue && maxValue) {  | 
 | 65 | +        const min = minValue[0]['@value'];  | 
 | 66 | +        const max = maxValue[0]['@value'];  | 
 | 67 | +        return Array.from({length: max - min + 1}, (_, i) => min + i);  | 
 | 68 | +      }  | 
 | 69 | +        | 
 | 70 | +      return this.choices.map(v => v['http://schema.repronim.org/value'][0]['@value']);  | 
58 | 71 |     },  | 
 | 72 | +      | 
59 | 73 |     getMinLabel() {  | 
60 |  | -      if (this.constraints['http://schema.repronim.org/choices']) {  | 
61 |  | -        const activeMinLabel = _.filter(this.constraints['http://schema.repronim.org/choices'][0]['http://schema.org/name'], labels => labels['@language'] === this.selected_language);  | 
62 |  | -        return activeMinLabel[0]['@value'];  | 
63 |  | -      } return 'no min label';  | 
 | 74 | +      if (this.choices.length) {  | 
 | 75 | +        const activeLabel = _.find(this.choices[0]['http://schema.org/name'],   | 
 | 76 | +          label => label['@language'] === this.selected_language);  | 
 | 77 | +        return activeLabel ? activeLabel['@value'] : '';  | 
 | 78 | +      }  | 
 | 79 | +      return '';  | 
64 | 80 |     },  | 
 | 81 | +      | 
65 | 82 |     getMaxLabel() {  | 
66 |  | -      if (this.constraints['http://schema.repronim.org/choices']) {  | 
67 |  | -        const choicesLength = (this.constraints['http://schema.repronim.org/choices']).length;  | 
68 |  | -        const activeMaxLabel = _.filter(this.constraints['http://schema.repronim.org/choices'][choicesLength-1]['http://schema.org/name'], labels => labels['@language'] === this.selected_language);  | 
69 |  | -        return activeMaxLabel[0]['@value'];  | 
70 |  | -      } return 'no max label';  | 
 | 83 | +      if (this.choices.length) {  | 
 | 84 | +        const activeLabel = _.find(this.choices[this.choices.length - 1]['http://schema.org/name'],   | 
 | 85 | +          label => label['@language'] === this.selected_language);  | 
 | 86 | +        return activeLabel ? activeLabel['@value'] : '';  | 
 | 87 | +      }  | 
 | 88 | +      return '';  | 
71 | 89 |     },  | 
 | 90 | +      | 
72 | 91 |     getMinImageLabel() {  | 
73 |  | -      const vcList = this.constraints['http://schema.repronim.org/choices'];  | 
 | 92 | +      const vcList = this.choices;  | 
74 | 93 |       if (vcList[0]['http://schema.org/image']) {  | 
75 | 94 |         return vcList[0]['http://schema.org/image'][0]['@value'];  | 
76 | 95 |       }  | 
77 | 96 |       return false;  | 
78 | 97 |     },  | 
 | 98 | +      | 
79 | 99 |     getMaxImageLabel() {  | 
80 |  | -      const vcList = this.constraints['http://schema.repronim.org/choices'];  | 
 | 100 | +      const vcList = this.choices;  | 
81 | 101 |       const N = vcList.length;  | 
82 | 102 |       if (vcList[N - 1]['http://schema.org/image']) {  | 
83 | 103 |         return vcList[N - 1]['http://schema.org/image'][0]['@value'];  | 
84 | 104 |       }  | 
85 | 105 |       return false;  | 
86 | 106 |     },  | 
 | 107 | +      | 
 | 108 | +    getMarks() {  | 
 | 109 | +      if (this.constraints['http://schema.org/minValue'] &&   | 
 | 110 | +          this.constraints['http://schema.org/maxValue']) {  | 
 | 111 | +        const min = this.constraints['http://schema.org/minValue'][0]['@value'];  | 
 | 112 | +        const max = this.constraints['http://schema.org/maxValue'][0]['@value'];  | 
 | 113 | +        const choices = this.choices;  | 
 | 114 | +          | 
 | 115 | +        if (choices) {  | 
 | 116 | +          const numChoices = choices.length;  | 
 | 117 | +          const step = (max - min) / (numChoices - 1);  | 
 | 118 | +          return Array.from({length: numChoices}, (_, i) => min + i * step);  | 
 | 119 | +        }  | 
 | 120 | +      }  | 
 | 121 | +      return true; // fallback to default behavior  | 
 | 122 | +    },  | 
 | 123 | +      | 
 | 124 | +    getMidLabel() {  | 
 | 125 | +      if (this.choices.length % 2 === 1) { // Check if odd number of choices  | 
 | 126 | +        const midIndex = Math.floor(this.choices.length / 2);  | 
 | 127 | +        const activeMidLabel = _.find(this.choices[midIndex]['http://schema.org/name'],   | 
 | 128 | +          label => label['@language'] === this.selected_language);  | 
 | 129 | +        return activeMidLabel ? activeMidLabel['@value'] : '';  | 
 | 130 | +      }  | 
 | 131 | +      return '';  | 
 | 132 | +    },  | 
 | 133 | +      | 
 | 134 | +    getMidImageLabel() {  | 
 | 135 | +      if (this.choices.length % 2 === 1) {  | 
 | 136 | +        const midIndex = Math.floor(this.choices.length / 2);  | 
 | 137 | +        if (this.choices[midIndex]['http://schema.org/image']) {  | 
 | 138 | +          return this.choices[midIndex]['http://schema.org/image'][0]['@value'];  | 
 | 139 | +        }  | 
 | 140 | +      }  | 
 | 141 | +      return false;  | 
 | 142 | +    },  | 
87 | 143 |   },  | 
88 | 144 |   data() {  | 
89 | 145 |     return {  | 
 | 
0 commit comments