@abi-software/map-side-bar 2.5.1 → 2.5.2-isan.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,102 @@
1
+ <script>
2
+ // The functions below are needed because the number of results shown on the page is dependent what is available from each index.
3
+ // We fix this by calcuting how many results we have shown before the requested page and then calculating the offset based on that.
4
+
5
+ // Note that this.RatioOfPMRResults is a number that determines how many PMR results are shown compared to SPARC results. It is grabbed from a constant in
6
+ // SidebarContent.vue.
7
+
8
+ export default {
9
+ methods: {
10
+
11
+ // Calculate Variable Ratio is used as a number to determine how the ratio of PMR results to SPARC results
12
+ // will be shown on the page. 1 means only PMR results, 0 means only SPARC results.
13
+ calculateVariableRatio: function () {
14
+ if (this.page === 1) {
15
+ this.variableRatio = this.RatioOfPMRResults
16
+
17
+ // Check if we have run out of Sparc results
18
+ } else if( this.npp_SPARC * (this.page -1) >= this.sparcNumberOfHits) {
19
+ this.variableRatio = 1
20
+
21
+ // Check if we have run out of PMR results
22
+ } else if(this.npp_PMR * (this.page - 1) >= this.pmrNumberOfHits) {
23
+ this.variableRatio = 0
24
+ } else {
25
+
26
+ // Set the ratio to the same as the previous page if both indeces have results
27
+ this.variableRatio = this.RatioOfPMRResults
28
+ }
29
+ },
30
+
31
+ // calculatePMROffest is used to calculate how many PMR results we have shown before the requested page
32
+ calculatePMROffest: function() {
33
+
34
+ // If variable ratio has not changed, we have not run out of results.
35
+ // we can use the the number per page PMR to calculate the offset
36
+ if (this.variableRatio === this.RatioOfPMRResults) {
37
+ return (this.page-1)*this.npp_PMR
38
+
39
+ // If we have run out of SPARC results, we need to calculate how many PMR results we have shown before the requested page
40
+ } else if (this.variableRatio === 1) {
41
+
42
+ // calculate how many results we showed before the requested page
43
+ // We want our offset to be the number of PMR results shown before the requested page
44
+ // This can be though of as numberOfPMRResultsShownInMixed + numberOfPMRResultsShownInPMROnly = offset
45
+ let pageWhereSPARCResultsRanOut = Math.ceil(this.sparcNumberOfHits / this.npp_SPARC)
46
+ let numberOfPMRResultsShownInMixed = this.npp_PMR * pageWhereSPARCResultsRanOut
47
+ let numberOfPMRResultsShownInPMROnly = (this.page - 1 - pageWhereSPARCResultsRanOut) * this.numberPerPage
48
+ return numberOfPMRResultsShownInMixed + numberOfPMRResultsShownInPMROnly
49
+ }
50
+ },
51
+
52
+ // calculateSPARCOffest is used to calculate how many SPARC results we have shown before the requested page. See above for details
53
+ calculateSPARCOffest: function() {
54
+ if(this.variableRatio === this.RatioOfPMRResults) {
55
+ return (this.page-1)*this.npp_SPARC
56
+ } else if (this.variableRatio === 0) {
57
+
58
+ // calculate how many results we showed before the requested page
59
+ let pageWherePMRResultsRanOut = Math.ceil(this.pmrNumberOfHits / this.npp_PMR)
60
+ let numberOfSPARCResultsShownInMixed = this.npp_SPARC * pageWherePMRResultsRanOut
61
+ let numberOfSPARCResultsShownInSPARCOnly = (this.page - 1 - pageWherePMRResultsRanOut) * this.numberPerPage
62
+ let offset = numberOfSPARCResultsShownInMixed + numberOfSPARCResultsShownInSPARCOnly
63
+ return offset
64
+ }
65
+ },
66
+
67
+ // PMRLimit is used to calculate how many PMR results we can show on the page.
68
+ PMRLimit: function(pmrResultsOnlyFlag=false) {
69
+ // If we only want PMR results, return the number per page
70
+ if (pmrResultsOnlyFlag) {
71
+ return this.numberPerPage
72
+ }
73
+ // If the variable ratio is the same as the ratio of PMR results, return the number per page set for PMR
74
+ if (this.variableRatio === this.RatioOfPMRResults) {
75
+ return this.npp_PMR
76
+
77
+ // if we have run out of sparc results, we want to show pmr results equal to the total number of results per page
78
+ } else if (this.variableRatio === 1) {
79
+ return this.numberPerPage
80
+
81
+ // if we have run out of pmr results, we want to show 0 pmr results
82
+ } else if (this.variableRatio === 0) {
83
+ return 0
84
+ }
85
+ },
86
+ SPARCLimit: function(pmrResultsOnlyFlag=false) {
87
+ if(pmrResultsOnlyFlag) {
88
+ return 0
89
+ }
90
+ if (this.variableRatio === this.RatioOfPMRResults) {
91
+ return this.npp_SPARC
92
+ } else if (this.variableRatio === 0) {
93
+ return this.numberPerPage
94
+ } else if (this.variableRatio === 1) {
95
+ return 0
96
+ }
97
+ },
98
+ }
99
+ };
100
+ </script>
101
+
102
+