View | Details | Raw Unified | Return to bug 10190
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Admin/CirculationTriggers/TriggersTable.vue (-138 / +150 lines)
Lines 1-5 Link Here
1
<template>
1
<template>
2
    <div class="page-section">
2
    <div class="page-section">
3
        <div class="page-section bg-info">{{ $__("Bolid italic values denote fallback values where an override has not been set for the context.") }}</div>
3
        <table>
4
        <table>
4
            <thead>
5
            <thead>
5
                <th v-if="!modal">
6
                <th v-if="!modal">
Lines 39-53 Link Here
39
                        triggerNumber
40
                        triggerNumber
40
                    )"
41
                    )"
41
                    v-bind:key="'rule' + i"
42
                    v-bind:key="'rule' + i"
43
                    :class="{
44
                        selected_rule:
45
                            modal && i + 1 === parseInt(ruleBeingEdited),
46
                    }"
42
                >
47
                >
43
                    <td
48
                    <td v-if="!modal">
44
                        v-if="!modal"
45
                        :class="
46
                            modal && i + 1 === parseInt(ruleBeingEdited)
47
                                ? 'selected_rule'
48
                                : ''
49
                        "
50
                    >
51
                        {{
49
                        {{
52
                            handleContext(
50
                            handleContext(
53
                                rule.context.patron_category_id,
51
                                rule.context.patron_category_id,
Lines 56-69 Link Here
56
                            )
54
                            )
57
                        }}
55
                        }}
58
                    </td>
56
                    </td>
59
                    <td
57
                    <td v-if="!modal">
60
                        v-if="!modal"
61
                        :class="
62
                            modal && i + 1 === parseInt(ruleBeingEdited)
63
                                ? 'selected_rule'
64
                                : ''
65
                        "
66
                    >
67
                        {{
58
                        {{
68
                            handleContext(
59
                            handleContext(
69
                                rule.context.item_type_id,
60
                                rule.context.item_type_id,
Lines 73-199 Link Here
73
                            )
64
                            )
74
                        }}
65
                        }}
75
                    </td>
66
                    </td>
76
                    <td
67
                    <td v-if="modal">{{ i + 1 }}</td>
77
                        v-if="modal"
68
78
                        :class="
69
                    <!-- Delay -->
79
                            modal && i + 1 === parseInt(ruleBeingEdited)
70
                    <td>
80
                                ? 'selected_rule'
71
                        <span
81
                                : ''
72
                            :class="{
82
                        "
73
                                fallback: findEffectiveRule(rule, `overdue_${modal ? i + 1 : triggerNumber}_delay`).isFallback,
83
                    >
74
                            }"
84
                        {{ i + 1 }}
75
                        >
85
                    </td>
76
                            {{
86
                    <td
77
                                findEffectiveRule(rule, `overdue_${modal ? i + 1 : triggerNumber}_delay`).value +
87
                        :class="
78
                                " " +
88
                            modal && i + 1 === parseInt(ruleBeingEdited)
79
                                $__("days")
89
                                ? 'selected_rule'
80
                            }}
90
                                : ''
81
                        </span>
91
                        "
92
                    >
93
                        {{
94
                            rule[
95
                                "overdue_" +
96
                                    (modal ? i + 1 : triggerNumber) +
97
                                    "_delay"
98
                            ]
99
                                ? rule[
100
                                      "overdue_" +
101
                                          (modal ? i + 1 : triggerNumber) +
102
                                          "_delay"
103
                                  ] +
104
                                  " " +
105
                                  $__("days")
106
                                : 0 + " " + $__("days")
107
                        }}
108
                    </td>
82
                    </td>
109
                    <td
83
110
                        :class="
84
                    <!-- Notice -->
111
                            modal && i + 1 === parseInt(ruleBeingEdited)
85
                    <td>
112
                                ? 'selected_rule'
86
                        <span
113
                                : ''
87
                            :class="{
114
                        "
88
                                fallback: findEffectiveRule(rule, `overdue_${modal ? i + 1 : triggerNumber}_notice`).isFallback,
115
                    >
89
                            }"
116
                        {{
90
                        >
117
                            handleNotice(
91
                            {{ handleNotice(findEffectiveRule(rule, `overdue_${modal ? i + 1 : triggerNumber}_notice`).value) }}
118
                                rule[
92
                        </span>
119
                                    "overdue_" +
120
                                        (modal ? i + 1 : triggerNumber) +
121
                                        "_notice"
122
                                ]
123
                            )
124
                        }}
125
                    </td>
93
                    </td>
126
                    <td
94
127
                        :class="
95
                    <!-- Email -->
128
                            modal && i + 1 === parseInt(ruleBeingEdited)
96
                    <td>
129
                                ? 'selected_rule'
97
                        <span
130
                                : ''
98
                            :class="{
131
                        "
99
                                fallback: findEffectiveRule(rule, `overdue_${modal ? i + 1 : triggerNumber}_mtt`).isFallback,
132
                    >
100
                            }"
133
                        {{
101
                        >
134
                            handleTransport(
102
                            {{
135
                                rule[
103
                                handleTransport(
136
                                    "overdue_" +
104
                                    findEffectiveRule(rule, `overdue_${modal ? i + 1 : triggerNumber}_mtt`).value,
137
                                        (modal ? i + 1 : triggerNumber) +
105
                                    "email"
138
                                        "_mtt"
106
                                )
139
                                ],
107
                            }}
140
                                "email"
108
                        </span>
141
                            )
142
                        }}
143
                    </td>
109
                    </td>
144
                    <td
110
145
                        :class="
111
                    <!-- Print -->
146
                            modal && i + 1 === parseInt(ruleBeingEdited)
112
                    <td>
147
                                ? 'selected_rule'
113
                        <span
148
                                : ''
114
                            :class="{
149
                        "
115
                                fallback: findEffectiveRule(rule, `overdue_${modal ? i + 1 : triggerNumber}_mtt`).isFallback,
150
                    >
116
                            }"
151
                        {{
117
                        >
152
                            handleTransport(
118
                            {{
153
                                rule[
119
                                handleTransport(
154
                                    "overdue_" +
120
                                    findEffectiveRule(rule, `overdue_${modal ? i + 1 : triggerNumber}_mtt`).value,
155
                                        (modal ? i + 1 : triggerNumber) +
121
                                    "print"
156
                                        "_mtt"
122
                                )
157
                                ],
123
                            }}
158
                                "print"
124
                        </span>
159
                            )
160
                        }}
161
                    </td>
125
                    </td>
162
                    <td
126
163
                        :class="
127
                    <!-- SMS -->
164
                            modal && i + 1 === parseInt(ruleBeingEdited)
128
                    <td>
165
                                ? 'selected_rule'
129
                        <span
166
                                : ''
130
                            :class="{
167
                        "
131
                                fallback: findEffectiveRule(rule, `overdue_${modal ? i + 1 : triggerNumber}_mtt`).isFallback,
168
                    >
132
                            }"
169
                        {{
133
                        >
170
                            handleTransport(
134
                            {{
171
                                rule[
135
                                handleTransport(
172
                                    "overdue_" +
136
                                    findEffectiveRule(rule, `overdue_${modal ? i + 1 : triggerNumber}_mtt`).value,
173
                                        (modal ? i + 1 : triggerNumber) +
137
                                    "sms"
174
                                        "_mtt"
138
                                )
175
                                ],
139
                            }}
176
                                "sms"
140
                        </span>
177
                            )
178
                        }}
179
                    </td>
141
                    </td>
180
                    <td
142
181
                        :class="
143
                    <!-- Restricts Checkouts -->
182
                            modal && i + 1 === parseInt(ruleBeingEdited)
144
                    <td>
183
                                ? 'selected_rule'
145
                        <span
184
                                : ''
146
                            :class="{
185
                        "
147
                                fallback: findEffectiveRule(rule, `overdue_${modal ? i + 1 : triggerNumber}_restrict`).isFallback,
186
                    >
148
                            }"
187
                        {{
149
                        >
188
                            handleRestrictions(
150
                            {{
189
                                rule[
151
                                handleRestrictions(
190
                                    "overdue_" +
152
                                    findEffectiveRule(rule, `overdue_${modal ? i + 1 : triggerNumber}_restrict`).value
191
                                        (modal ? i + 1 : triggerNumber) +
153
                                )
192
                                        "_restrict"
154
                            }}
193
                                ]
155
                        </span>
194
                            )
195
                        }}
196
                    </td>
156
                    </td>
157
197
                    <td v-if="!modal" class="actions">
158
                    <td v-if="!modal" class="actions">
198
                        <router-link
159
                        <router-link
199
                            :to="{
160
                            :to="{
Lines 238-244 export default { Link Here
238
                ? value.includes(type)
199
                ? value.includes(type)
239
                    ? this.$__("Yes")
200
                    ? this.$__("Yes")
240
                    : this.$__("No")
201
                    : this.$__("No")
241
                : this.$__("Default")
202
                : ''
242
        },
203
        },
243
        handleRestrictions(value) {
204
        handleRestrictions(value) {
244
            return value === "1" ? this.$__("Yes") : this.$__("No")
205
            return value === "1" ? this.$__("Yes") : this.$__("No")
Lines 258-276 export default { Link Here
258
            const letter = this.letters.find(letter => letter.code === notice)
219
            const letter = this.letters.find(letter => letter.code === notice)
259
            return letter
220
            return letter
260
                ? letter.name
221
                ? letter.name
261
                    ? letter.name
222
                : notice
262
                    : notice
223
        },
263
                : this.$__("Default")
224
        findEffectiveRule(ruleSet, key) {
225
            // Check if the current rule's value for the key is null
226
            if (ruleSet[key] === null) {
227
                // Filter rules to only those with non-null values for the specified key
228
                const relevantRules = this.circRules.filter(
229
                    rule => rule[key] !== null
230
                )
231
232
                // Function to calculate specificity score
233
                const getSpecificityScore = ruleContext => {
234
                    let score = 0
235
                    if (
236
                        ruleContext.library_id !== "*" &&
237
                        ruleContext.library_id === ruleSet.library_id
238
                    )
239
                        score += 4
240
                    if (
241
                        ruleContext.patron_category_id !== "*" &&
242
                        ruleContext.patron_category_id ===
243
                            ruleSet.patron_category_id
244
                    )
245
                        score += 2
246
                    if (
247
                        ruleContext.item_type_id !== "*" &&
248
                        ruleContext.item_type_id === ruleSet.item_type_id
249
                    )
250
                        score += 1
251
                    return score
252
                }
253
254
                // Sort the rules based on specificity score, descending
255
                const sortedRules = relevantRules.sort((a, b) => {
256
                    return (
257
                        getSpecificityScore(b.context) -
258
                        getSpecificityScore(a.context)
259
                    )
260
                })
261
262
                // If no rule found, return null
263
                if (sortedRules.length === 0) {
264
                    return { value: null, isFallback: true }
265
                }
266
267
                // Get the value from the most specific rule
268
                const bestRule = sortedRules[0]
269
                return { value: bestRule[key], isFallback: true }
270
            } else {
271
                // If the current rule's value is not null, use it directly
272
                return { value: ruleSet[key], isFallback: false }
273
            }
264
        },
274
        },
265
    },
275
    },
266
}
276
}
267
</script>
277
</script>
268
278
269
<style scoped>
279
<style scoped>
270
.selected_rule {
280
.selected_rule > td {
271
    background-color: yellow !important;
281
    background-color: yellow !important;
272
}
282
}
273
283
.fallback {
284
    font-style: italic;
285
    font-weight: bold;
286
}
274
.actions a {
287
.actions a {
275
    margin-right: 5px;
288
    margin-right: 5px;
276
}
289
}
277
- 

Return to bug 10190