|
Lines 2-17
import { defineStore } from "pinia";
Link Here
|
| 2 |
import { $__ } from "../i18n"; |
2 |
import { $__ } from "../i18n"; |
| 3 |
import { APIClient } from "../fetch/api-client.js"; |
3 |
import { APIClient } from "../fetch/api-client.js"; |
| 4 |
import { isEqual } from "lodash"; |
4 |
import { isEqual } from "lodash"; |
|
|
5 |
import { permissionsActions } from "../composables/permissions"; |
| 6 |
import { reactive, toRefs } from "vue"; |
| 5 |
|
7 |
|
| 6 |
export const useCircRulesStore = defineStore("circRules", { |
8 |
// NOTES ON RULE SETS TYPES |
| 7 |
// NOTES ON RULE SETS TYPES |
9 |
// exhaustive: includes 'pure fallback' rules sets for contexts that no rules match. |
| 8 |
// exhaustive: includes 'pure fallback' rules sets for contexts that no rules match. |
10 |
// Format: [{overdue_X_<rule_name>: {value: mixed: isFallback: bool}}] |
| 9 |
// Format: [{overdue_X_<rule_name>: {value: mixed: isFallback: bool}}] |
11 |
// effective: includes sets only for contexts for which one or more rule exists in the db. These sets will include fallbacks. |
| 10 |
// effective: includes sets only for contexts for which one or more rule exists in the db. These sets will include fallbacks. |
12 |
// Format: [{overdue_X_<rule_name>: <value>}} |
| 11 |
// Format: [{overdue_X_<rule_name>: <value>}} |
13 |
// raw: includes only the exact sets as they are found in the db |
| 12 |
// raw: includes only the exact sets as they are found in the db |
14 |
// Format: [{overdue_X_<rule_name>: <value>}}] |
| 13 |
// Format: [{overdue_X_<rule_name>: <value>}}] |
15 |
|
| 14 |
state: () => ({ |
16 |
export const useCircRulesStore = defineStore("circRules", () => { |
|
|
17 |
const store = reactive({ |
| 15 |
// context |
18 |
// context |
| 16 |
currentLibraryId: "*", |
19 |
currentLibraryId: "*", |
| 17 |
currentPatronCategoryId: null, |
20 |
currentPatronCategoryId: null, |
|
Lines 21-26
export const useCircRulesStore = defineStore("circRules", {
Link Here
|
| 21 |
itemTypes: [], |
24 |
itemTypes: [], |
| 22 |
libraries: [], |
25 |
libraries: [], |
| 23 |
patronCategories: [], |
26 |
patronCategories: [], |
|
|
27 |
userPermissions: null, |
| 24 |
letters: [], |
28 |
letters: [], |
| 25 |
ruleSuffixes: ["delay", "notice", "mtt", "restrict", "has_rules"], |
29 |
ruleSuffixes: ["delay", "notice", "mtt", "restrict", "has_rules"], |
| 26 |
transportTypes: [ |
30 |
transportTypes: [ |
|
Lines 36-49
export const useCircRulesStore = defineStore("circRules", {
Link Here
|
| 36 |
allExhaustiveEffectiveRuleSets: [], // main data set for display all applied rules for current library |
40 |
allExhaustiveEffectiveRuleSets: [], // main data set for display all applied rules for current library |
| 37 |
currentAndDefaultRawRuleSets: [], // data set to identify effective rules from (combines allDefaultLibraryRawRuleSets and allCurrentLibraryRawRuleSets) |
41 |
currentAndDefaultRawRuleSets: [], // data set to identify effective rules from (combines allDefaultLibraryRawRuleSets and allCurrentLibraryRawRuleSets) |
| 38 |
storeInitialized: false, |
42 |
storeInitialized: false, |
| 39 |
}), |
43 |
}); |
| 40 |
actions: { |
44 |
|
|
|
45 |
const actions = { |
| 41 |
// controllers |
46 |
// controllers |
| 42 |
async init() { |
47 |
async init() { |
| 43 |
await this.getItemTypes(); |
48 |
await this.getItemTypes(); |
| 44 |
await this.getLibraries(); |
49 |
await this.getLibraries(); |
| 45 |
await this.getPatronCategories(); |
50 |
await this.getPatronCategories(); |
| 46 |
}, |
51 |
}, |
|
|
52 |
async loadUserPermissions() { |
| 53 |
if (this.userPermissions !== null) { |
| 54 |
return; |
| 55 |
} |
| 56 |
await this.getConfigurationOptions(); |
| 57 |
}, |
| 47 |
// utilities |
58 |
// utilities |
| 48 |
formatTriggerSpecificRuleSetForDisplay( |
59 |
formatTriggerSpecificRuleSetForDisplay( |
| 49 |
context, |
60 |
context, |
|
Lines 403-408
export const useCircRulesStore = defineStore("circRules", {
Link Here
|
| 403 |
throw e; |
414 |
throw e; |
| 404 |
} |
415 |
} |
| 405 |
}, |
416 |
}, |
|
|
417 |
async getConfigurationOptions() { |
| 418 |
const client = APIClient.circRule; |
| 419 |
const { permissions } = await client.config.getAll(); |
| 420 |
this.userPermissions = permissions; |
| 421 |
}, |
| 406 |
async getItemTypes() { |
422 |
async getItemTypes() { |
| 407 |
const client = APIClient.item; |
423 |
const client = APIClient.item; |
| 408 |
let itemTypes = []; |
424 |
let itemTypes = []; |
|
Lines 485-489
export const useCircRulesStore = defineStore("circRules", {
Link Here
|
| 485 |
//TODO: handle e |
501 |
//TODO: handle e |
| 486 |
} |
502 |
} |
| 487 |
}, |
503 |
}, |
| 488 |
}, |
504 |
...permissionsActions(store), |
|
|
505 |
}; |
| 506 |
|
| 507 |
return { |
| 508 |
...toRefs(store), |
| 509 |
...actions, |
| 510 |
}; |
| 489 |
}); |
511 |
}); |
| 490 |
- |
|
|