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

(-)a/acqui/vendors.pl (-1 / +2 lines)
Lines 49-55 $template->param( Link Here
49
    currencies       => Koha::Acquisition::Currencies->search->unblessed,
49
    currencies       => Koha::Acquisition::Currencies->search->unblessed,
50
    gst_values       => \@gst_values,
50
    gst_values       => \@gst_values,
51
    edifact          => C4::Context->preference('EDIFACT'),
51
    edifact          => C4::Context->preference('EDIFACT'),
52
    erm_module       => C4::Context->preference('ERMModule')
52
    erm_module       => C4::Context->preference('ERMModule'),
53
    logged_in_branch => { branchcode => C4::Context::mybranch },
53
);
54
);
54
55
55
output_html_with_http_headers $query, $cookie, $template->output;
56
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/admin/library_groups.pl (+4 lines)
Lines 52-57 if ( $op eq 'cud-add' ) { Link Here
52
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
52
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
53
    my $ft_local_hold_group    = $cgi->param('ft_local_hold_group')    || 0;
53
    my $ft_local_hold_group    = $cgi->param('ft_local_hold_group')    || 0;
54
    my $ft_local_float_group   = $cgi->param('ft_local_float_group')   || 0;
54
    my $ft_local_float_group   = $cgi->param('ft_local_float_group')   || 0;
55
    my $ft_acquisitions        = $cgi->param('ft_acquisitions')        || 0;
55
56
56
    if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) {
57
    if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) {
57
        $template->param( error_duplicate_title => $title );
58
        $template->param( error_duplicate_title => $title );
Lines 69-74 if ( $op eq 'cud-add' ) { Link Here
69
                    ft_local_hold_group    => $ft_local_hold_group,
70
                    ft_local_hold_group    => $ft_local_hold_group,
70
                    ft_limit_item_editing  => $ft_limit_item_editing,
71
                    ft_limit_item_editing  => $ft_limit_item_editing,
71
                    ft_local_float_group   => $ft_local_float_group,
72
                    ft_local_float_group   => $ft_local_float_group,
73
                    ft_acquisitions        => $ft_acquisitions,
72
                    branchcode             => $branchcode,
74
                    branchcode             => $branchcode,
73
                }
75
                }
74
            )->store();
76
            )->store();
Lines 91-96 elsif ( $op eq 'cud-edit' ) { Link Here
91
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
93
    my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
92
    my $ft_local_hold_group    = $cgi->param('ft_local_hold_group')    || 0;
94
    my $ft_local_hold_group    = $cgi->param('ft_local_hold_group')    || 0;
93
    my $ft_local_float_group   = $cgi->param('ft_local_float_group')   || 0;
95
    my $ft_local_float_group   = $cgi->param('ft_local_float_group')   || 0;
96
    my $ft_acquisitions        = $cgi->param('ft_acquisitions')        || 0;
94
97
95
    if ($id) {
98
    if ($id) {
96
        my $group = Koha::Library::Groups->find($id);
99
        my $group = Koha::Library::Groups->find($id);
Lines 105-110 elsif ( $op eq 'cud-edit' ) { Link Here
105
                ft_search_groups_staff => $ft_search_groups_staff,
108
                ft_search_groups_staff => $ft_search_groups_staff,
106
                ft_local_hold_group    => $ft_local_hold_group,
109
                ft_local_hold_group    => $ft_local_hold_group,
107
                ft_local_float_group   => $ft_local_float_group,
110
                ft_local_float_group   => $ft_local_float_group,
111
                ft_acquisitions        => $ft_acquisitions,
108
            }
112
            }
109
        )->store();
113
        )->store();
110
114
(-)a/api/v1/swagger/definitions/vendor.yaml (+8 lines)
Lines 124-129 properties: Link Here
124
      - string
124
      - string
125
      - "null"
125
      - "null"
126
    description: Language
126
    description: Language
127
  lib_group_visibility:
128
    type:
129
      - string
130
      - "null"
131
    description: Language
132
  lib_group_limits:
133
    type: array
134
    description: Library groups this vendor belongs to
127
  aliases:
135
  aliases:
128
    type: array
136
    type: array
129
    description: List of aliases
137
    description: List of aliases
(-)a/api/v1/swagger/paths/acquisitions_vendors.yaml (+1 lines)
Lines 158-163 Link Here
158
            - contracts
158
            - contracts
159
            - extended_attributes
159
            - extended_attributes
160
            - +strings
160
            - +strings
161
            - lib_group_limits
161
        collectionFormat: csv
162
        collectionFormat: csv
162
    produces:
163
    produces:
163
      - application/json
164
      - application/json
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/vendors.tt (+3 lines)
Lines 34-39 Link Here
34
        const gstValues = [% To.json(gst_values) | $raw %];
34
        const gstValues = [% To.json(gst_values) | $raw %];
35
        const edifact = [% To.json(edifact) | $raw %];
35
        const edifact = [% To.json(edifact) | $raw %];
36
        const ermModule = [% To.json(erm_module) | $raw %];
36
        const ermModule = [% To.json(erm_module) | $raw %];
37
        const loggedInUser = [% To.json(logged_in_user.unblessed) | $raw %];
38
        const loggedInBranch = [% To.json(logged_in_branch) | $raw %];
39
37
    </script>
40
    </script>
38
41
39
42
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt (-3 / +22 lines)
Lines 166-171 Link Here
166
                                        Is local float group
166
                                        Is local float group
167
                                    </label>
167
                                    </label>
168
                                </p>
168
                                </p>
169
                                <p>
170
                                    <label>
171
                                        <input type="checkbox" name="ft_acquisitions" id="add-group-modal-ft_acquisitions" value="1" />
172
                                        Use in the acquisitions module
173
                                    </label>
174
                                </p>
169
                            </div>
175
                            </div>
170
                        </div>
176
                        </div>
171
                    </div>
177
                    </div>
Lines 244-249 Link Here
244
                                        Is local float group
250
                                        Is local float group
245
                                    </label>
251
                                    </label>
246
                                </p>
252
                                </p>
253
                                <p>
254
                                    <label>
255
                                        <input type="checkbox" id="edit-group-modal-ft_acquisitions" name="ft_acquisitions" value="1" />
256
                                        Use in the acquisitions module
257
                                    </label>
258
                                </p>
247
                            </div>
259
                            </div>
248
                        </div>
260
                        </div>
249
                    </div>
261
                    </div>
Lines 330-336 Link Here
330
                var ft_search_groups_staff = $(this).data('groupFt_search_groups_staff');
342
                var ft_search_groups_staff = $(this).data('groupFt_search_groups_staff');
331
                var ft_local_hold_group = $(this).data('groupFt_local_hold_group');
343
                var ft_local_hold_group = $(this).data('groupFt_local_hold_group');
332
                var ft_local_float_group = $(this).data('groupFt_local_float_group');
344
                var ft_local_float_group = $(this).data('groupFt_local_float_group');
333
                edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group, ft_limit_item_editing, ft_local_float_group );
345
                var ft_acquisitions = $(this).data('groupFt_acquisitions');
346
                edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group, ft_limit_item_editing, ft_local_float_group, ft_acquisitions );
334
            });
347
            });
335
348
336
            $('.delete-group').on('click', function(e) {
349
            $('.delete-group').on('click', function(e) {
Lines 368-373 Link Here
368
            $('#add-group-modal-ft_search_groups_staff').prop('checked', false);
381
            $('#add-group-modal-ft_search_groups_staff').prop('checked', false);
369
            $('#add-group-modal-ft_local_hold_group').prop('checked', false);
382
            $('#add-group-modal-ft_local_hold_group').prop('checked', false);
370
            $('#add-group-modal-ft_local_float_group').prop('checked', false);
383
            $('#add-group-modal-ft_local_float_group').prop('checked', false);
384
            $('#add-group-modal-ft_acquisitions').prop('checked', false);
371
            if ( parent_id ) {
385
            if ( parent_id ) {
372
                $('#root-group-features-add').hide();
386
                $('#root-group-features-add').hide();
373
            } else {
387
            } else {
Lines 377-383 Link Here
377
391
378
        }
392
        }
379
393
380
        function edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group, ft_limit_item_editing, ft_local_float_group ) {
394
        function edit_group( id, parent_id, title, description, ft_hide_patron_info, ft_search_groups_opac, ft_search_groups_staff, ft_local_hold_group, ft_limit_item_editing, ft_local_float_group, ft_acquisitions ) {
381
            $('#edit-group-modal-id').val( id );
395
            $('#edit-group-modal-id').val( id );
382
            $('#edit-group-modal-title').val( title );
396
            $('#edit-group-modal-title').val( title );
383
            $('#edit-group-modal-description').val( description );
397
            $('#edit-group-modal-description').val( description );
Lines 388-393 Link Here
388
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', false);
402
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', false);
389
                $('#edit-group-modal-ft_local_hold_group').prop('checked', false);
403
                $('#edit-group-modal-ft_local_hold_group').prop('checked', false);
390
                $('#edit-group-modal-ft_local_float_group').prop('checked', false);
404
                $('#edit-group-modal-ft_local_float_group').prop('checked', false);
405
                $('#edit-group-modal-ft_acquisitions').prop('checked', false);
391
                $('#root-group-features-edit').hide();
406
                $('#root-group-features-edit').hide();
392
            } else {
407
            } else {
393
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', ft_hide_patron_info ? true : false );
408
                $('#edit-group-modal-ft_hide_patron_info').prop('checked', ft_hide_patron_info ? true : false );
Lines 396-401 Link Here
396
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', ft_search_groups_staff ? true : false );
411
                $('#edit-group-modal-ft_search_groups_staff').prop('checked', ft_search_groups_staff ? true : false );
397
                $('#edit-group-modal-ft_local_hold_group').prop('checked', ft_local_hold_group ? true : false );
412
                $('#edit-group-modal-ft_local_hold_group').prop('checked', ft_local_hold_group ? true : false );
398
                $('#edit-group-modal-ft_local_float_group').prop('checked', ft_local_float_group ? true : false );
413
                $('#edit-group-modal-ft_local_float_group').prop('checked', ft_local_float_group ? true : false );
414
                $('#edit-group-modal-ft_acquisitions').prop('checked', ft_acquisitions ? true : false );
399
                $('#root-group-features-edit').show();
415
                $('#root-group-features-edit').show();
400
            }
416
            }
401
417
Lines 457-462 Link Here
457
                [% IF group.ft_local_float_group %]
473
                [% IF group.ft_local_float_group %]
458
                    <li>Is local float group</li>
474
                    <li>Is local float group</li>
459
                [% END %]
475
                [% END %]
476
                [% IF group.ft_acquisitions %]
477
                    <li>Use in the acquisitions module</li>
478
                [% END %]
460
              </ul>
479
              </ul>
461
            [% END %]
480
            [% END %]
462
        </td>
481
        </td>
Lines 474-480 Link Here
474
                       </li>
493
                       </li>
475
494
476
                        <li>
495
                        <li>
477
                            <a class="edit-group dropdown-item" id="edit-group-[% group.id | html %]" href="#" data-group-id="[% group.id | html %]" data-group-parent-id="[% group.parent_id | html %]" data-group-title="[% group.title | html %]" data-group-description="[% group.description | html %]" data-group-ft_hide_patron_info="[% group.ft_hide_patron_info | html %]" data-group-ft_search_groups_opac="[% group.ft_search_groups_opac | html %]" data-group-ft_search_groups_staff="[% group.ft_search_groups_staff | html %]" data-group-ft_local_hold_group="[% group.ft_local_hold_group | html %]" data-group-ft_limit_item_editing="[% group.ft_limit_item_editing | html %]" data-group-ft_local_float_group="[% group.ft_local_float_group | html %]" >
496
                            <a class="edit-group dropdown-item" id="edit-group-[% group.id | html %]" href="#" data-group-id="[% group.id | html %]" data-group-parent-id="[% group.parent_id | html %]" data-group-title="[% group.title | html %]" data-group-description="[% group.description | html %]" data-group-ft_hide_patron_info="[% group.ft_hide_patron_info | html %]" data-group-ft_search_groups_opac="[% group.ft_search_groups_opac | html %]" data-group-ft_search_groups_staff="[% group.ft_search_groups_staff | html %]" data-group-ft_local_hold_group="[% group.ft_local_hold_group | html %]" data-group-ft_limit_item_editing="[% group.ft_limit_item_editing | html %]" data-group-ft_local_float_group="[% group.ft_local_float_group | html %]" data-group-ft_acquisitions="[% group.ft_acquisitions | html %]" >
478
                                <i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit
497
                                <i class="fa-solid fa-pencil" aria-hidden="true"></i> Edit
479
                            </a>
498
                            </a>
480
                       </li>
499
                       </li>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/Main.vue (-3 / +21 lines)
Lines 37-43 import { APIClient } from "../../fetch/api-client" Link Here
37
export default {
37
export default {
38
    setup() {
38
    setup() {
39
        const vendorStore = inject("vendorStore")
39
        const vendorStore = inject("vendorStore")
40
        const { config } = storeToRefs(vendorStore)
40
        const { config, user, currencies, libraryGroups, gstValues } =
41
            storeToRefs(vendorStore)
42
        const { setLibraryGroups } = vendorStore
41
43
42
        const mainStore = inject("mainStore")
44
        const mainStore = inject("mainStore")
43
        const { loading, loaded, setError } = mainStore
45
        const { loading, loaded, setError } = mainStore
Lines 54-59 export default { Link Here
54
            userPermissions,
56
            userPermissions,
55
            AVStore,
57
            AVStore,
56
            config,
58
            config,
59
            user,
60
            currencies,
61
            libraryGroups,
62
            gstValues,
63
            setLibraryGroups,
57
        }
64
        }
58
    },
65
    },
59
    beforeCreate() {
66
    beforeCreate() {
Lines 62-67 export default { Link Here
62
        const fetchConfig = () => {
69
        const fetchConfig = () => {
63
            let promises = []
70
            let promises = []
64
71
72
            const libraryClient = APIClient.libraries
73
            libraryClient.libraryGroups.getAll().then(
74
                libraryGroups => {
75
                    this.setLibraryGroups(libraryGroups)
76
                },
77
                error => {}
78
            )
79
65
            const av_client = APIClient.authorised_values
80
            const av_client = APIClient.authorised_values
66
            const authorised_values = {
81
            const authorised_values = {
67
                av_vendor_types: "VENDOR_TYPE",
82
                av_vendor_types: "VENDOR_TYPE",
Lines 100-107 export default { Link Here
100
            this.userPermissions = userPermissions
115
            this.userPermissions = userPermissions
101
            this.config.settings.edifact = edifact
116
            this.config.settings.edifact = edifact
102
            this.config.settings.ermModule = ermModule
117
            this.config.settings.ermModule = ermModule
103
            this.vendorStore.currencies = currencies
118
            this.currencies = currencies
104
            this.vendorStore.gstValues = gstValues.map(gv => {
119
            // this.libraryGroups = libraryGroups
120
            this.user.loggedInUser = loggedInUser
121
            this.user.loggedInUser.loggedInBranch = loggedInBranch.branchcode
122
            this.gstValues = gstValues.map(gv => {
105
                return {
123
                return {
106
                    label: `${(gv.option * 100).toFixed(2)}%`,
124
                    label: `${(gv.option * 100).toFixed(2)}%`,
107
                    value: gv.option,
125
                    value: gv.option,
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorDetails.vue (+45 lines)
Lines 66-71 Link Here
66
                    {{ get_lib_from_av("av_lang", vendor.language) }}
66
                    {{ get_lib_from_av("av_lang", vendor.language) }}
67
                </span>
67
                </span>
68
            </li>
68
            </li>
69
            <li v-if="vendor.lib_group_limits.length">
70
                <label>{{ $__("Library group visibility") }}:</label>
71
                <table id="lib_group_visibility_table">
72
                    <thead>
73
                        <tr>
74
                            <th>{{ $__("ID") }}</th>
75
                            <th>{{ $__("Title") }}</th>
76
                        </tr>
77
                    </thead>
78
                    <tbody>
79
                        <tr
80
                            v-for="(libGroup, key) in vendor.lib_group_limits"
81
                            v-bind:key="key"
82
                        >
83
                            <td>{{ libGroup.id }}</td>
84
                            <td>{{ libGroup.title }}</td>
85
                        </tr>
86
                    </tbody>
87
                </table>
88
            </li>
89
            <li v-else>
90
                <label>{{ $__("Library group visibility") }}:</label>
91
                <span>{{ $__("All library groups") }}</span>
92
            </li>
69
            <li v-if="vendor.aliases.length">
93
            <li v-if="vendor.aliases.length">
70
                <label>{{ $__("Aliases") }}:</label>
94
                <label>{{ $__("Aliases") }}:</label>
71
                <ul style="margin-left: 8rem">
95
                <ul style="margin-left: 8rem">
Lines 159-164 Link Here
159
                />
183
                />
160
                <input v-else id="language" v-model="vendor.type" />
184
                <input v-else id="language" v-model="vendor.type" />
161
            </li>
185
            </li>
186
            <li>
187
                <label for="lib_group_visibility"
188
                    >{{ $__("Library group visibility") }}:</label
189
                >
190
                <v-select
191
                    v-if="av_lang.length"
192
                    id="lib_group_visibility"
193
                    v-model="vendor.lib_group_visibility"
194
                    label="title"
195
                    :reduce="av => av.id"
196
                    :options="getVisibleGroups"
197
                    multiple
198
                />
199
                <input v-else id="lib_group_visibility" v-model="vendor.type" />
200
            </li>
162
            <li>
201
            <li>
163
                <label for="vendor_aliases">{{ $__("Aliases") }}:</label>
202
                <label for="vendor_aliases">{{ $__("Aliases") }}:</label>
164
                <input id="vendor_aliases" v-model="newAlias" />
203
                <input id="vendor_aliases" v-model="newAlias" />
Lines 189-194 Link Here
189
<script>
228
<script>
190
import { inject } from "vue"
229
import { inject } from "vue"
191
import ToolbarButton from "../ToolbarButton.vue"
230
import ToolbarButton from "../ToolbarButton.vue"
231
import { storeToRefs } from "pinia"
192
232
193
export default {
233
export default {
194
    props: {
234
    props: {
Lines 198-207 export default { Link Here
198
    setup() {
238
    setup() {
199
        const AVStore = inject("AVStore")
239
        const AVStore = inject("AVStore")
200
        const { get_lib_from_av, av_vendor_types, av_lang } = AVStore
240
        const { get_lib_from_av, av_vendor_types, av_lang } = AVStore
241
        const vendorStore = inject("vendorStore")
242
        const { formatLibraryGroupIds } = vendorStore
243
        const { getVisibleGroups } = storeToRefs(vendorStore)
201
        return {
244
        return {
202
            get_lib_from_av,
245
            get_lib_from_av,
203
            av_vendor_types,
246
            av_vendor_types,
204
            av_lang,
247
            av_lang,
248
            getVisibleGroups,
249
            formatLibraryGroupIds,
205
        }
250
        }
206
    },
251
    },
207
    data() {
252
    data() {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorFormAdd.vue (+16 lines)
Lines 39-46 import VendorContacts from "./VendorContacts.vue" Link Here
39
import VendorOrderingInformation from "./VendorOrderingInformation.vue"
39
import VendorOrderingInformation from "./VendorOrderingInformation.vue"
40
import VendorInterfaces from "./VendorInterfaces.vue"
40
import VendorInterfaces from "./VendorInterfaces.vue"
41
import AdditionalFieldsEntry from "../AdditionalFieldsEntry.vue"
41
import AdditionalFieldsEntry from "../AdditionalFieldsEntry.vue"
42
import { inject } from "vue"
42
43
43
export default {
44
export default {
45
    setup() {
46
        const vendorStore = inject("vendorStore")
47
        const { formatLibraryGroupIds } = vendorStore
48
49
        return {
50
            formatLibraryGroupIds,
51
        }
52
    },
44
    data() {
53
    data() {
45
        return {
54
        return {
46
            vendor: {
55
            vendor: {
Lines 69-74 export default { Link Here
69
                external_id: "",
78
                external_id: "",
70
                payment_method: [],
79
                payment_method: [],
71
                language: "",
80
                language: "",
81
                lib_group_visibility: [],
72
                aliases: [],
82
                aliases: [],
73
                contacts: [],
83
                contacts: [],
74
                interfaces: [],
84
                interfaces: [],
Lines 101-106 export default { Link Here
101
                    this.vendor.payment_method = vendor.payment_method
111
                    this.vendor.payment_method = vendor.payment_method
102
                        ? vendor.payment_method.split("|")
112
                        ? vendor.payment_method.split("|")
103
                        : []
113
                        : []
114
                    this.vendor.lib_group_visibility =
115
                        this.formatLibraryGroupIds(vendor.lib_group_visibility)
104
                    this.initialized = true
116
                    this.initialized = true
105
                },
117
                },
106
                error => {}
118
                error => {}
Lines 126-131 export default { Link Here
126
            delete vendor.physical
138
            delete vendor.physical
127
            delete vendor.subscriptions_count
139
            delete vendor.subscriptions_count
128
            delete vendor._strings
140
            delete vendor._strings
141
            delete vendor.lib_group_limits
129
142
130
            vendor.contacts = vendor.contacts.map(
143
            vendor.contacts = vendor.contacts.map(
131
                ({ id, booksellerid, ...requiredProperties }) =>
144
                ({ id, booksellerid, ...requiredProperties }) =>
Lines 142-147 export default { Link Here
142
                vendor.payment_method = null
155
                vendor.payment_method = null
143
            }
156
            }
144
157
158
            const visibility = vendor.lib_group_visibility.join("|")
159
            vendor.lib_group_visibility = visibility
160
145
            const client = APIClient.acquisition
161
            const client = APIClient.acquisition
146
            if (vendorId) {
162
            if (vendorId) {
147
                client.vendors.update(vendor, vendorId).then(
163
                client.vendors.update(vendor, vendorId).then(
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/acquisition-api-client.js (-1 / +1 lines)
Lines 14-20 export class AcquisitionAPIClient extends HttpClient { Link Here
14
                    endpoint: "vendors/" + id,
14
                    endpoint: "vendors/" + id,
15
                    headers: {
15
                    headers: {
16
                        "x-koha-embed":
16
                        "x-koha-embed":
17
                            "aliases,subscriptions+count,interfaces,contacts,contracts,extended_attributes,+strings",
17
                            "aliases,subscriptions+count,interfaces,contacts,contracts,extended_attributes,+strings,lib_group_limits",
18
                    },
18
                    },
19
                }),
19
                }),
20
            getAll: (query, params) =>
20
            getAll: (query, params) =>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/vendors.js (-1 / +140 lines)
Lines 5-14 export const useVendorStore = defineStore("vendors", { Link Here
5
        vendors: [],
5
        vendors: [],
6
        currencies: [],
6
        currencies: [],
7
        gstValues: [],
7
        gstValues: [],
8
        libraryGroups: null,
9
        visibleGroups: null,
10
        user: {
11
            loggedInUser: null,
12
            userflags: null,
13
        },
8
        config: {
14
        config: {
9
            settings: {
15
            settings: {
10
                edifact: false,
16
                edifact: false,
11
            },
17
            },
12
        },
18
        },
13
    }),
19
    }),
20
    actions: {
21
        determineBranch(code) {
22
            if (code) {
23
                return code;
24
            }
25
            const {
26
                loggedInUser: { loggedInBranch, branchcode },
27
            } = this.user;
28
            return loggedInBranch ? loggedInBranch : branchcode;
29
        },
30
        _matchSubGroups(group, filteredGroups, branch, groupsToCheck) {
31
            let matched = false;
32
            if (group.libraries.find(lib => lib.branchcode === branch)) {
33
                if (
34
                    groupsToCheck &&
35
                    groupsToCheck.length &&
36
                    groupsToCheck.includes(group.id)
37
                ) {
38
                    filteredGroups[group.id] = group;
39
                    matched = true;
40
                }
41
                if (!groupsToCheck || groupsToCheck.length === 0) {
42
                    filteredGroups[group.id] = group;
43
                    matched = true;
44
                }
45
            }
46
            if (group.subGroups && group.subGroups.length) {
47
                group.subGroups.forEach(grp => {
48
                    const result = this._matchSubGroups(
49
                        grp,
50
                        filteredGroups,
51
                        branch,
52
                        groupsToCheck
53
                    );
54
                    matched = matched ? matched : result;
55
                });
56
            }
57
            return matched;
58
        },
59
        filterLibGroupsByUsersBranchcode(branchcode, groupsToCheck) {
60
            const branch = this.determineBranch(branchcode);
61
            const filteredGroups = {};
62
            if (!this.libraryGroups) {
63
                return [];
64
            }
65
            this.libraryGroups.forEach(group => {
66
                const matched = this._matchSubGroups(
67
                    group,
68
                    filteredGroups,
69
                    branch,
70
                    groupsToCheck
71
                );
72
                // If a sub group has been matched but the parent level group did not, then we should add the parent level group as well
73
                // This happens when a parent group doesn't have any branchcodes assigned to it, only sub groups
74
                if (
75
                    matched &&
76
                    !Object.keys(filteredGroups).find(id => id === group.id)
77
                ) {
78
                    filteredGroups[group.id] = group;
79
                }
80
            });
81
            return Object.keys(filteredGroups)
82
                .map(key => {
83
                    return filteredGroups[key];
84
                })
85
                .sort((a, b) => a.id - b.id);
86
        },
87
        formatLibraryGroupIds(ids) {
88
            if (!ids) {
89
                return [];
90
            }
91
            const groups = ids.includes("|") ? ids.split("|") : [ids];
92
            const groupIds = groups.map(group => {
93
                return parseInt(group);
94
            });
95
            return groupIds;
96
        },
97
        setLibraryGroups(groups) {
98
            if (!groups?.length) {
99
                return;
100
            }
101
            const topLevelGroups = groups.filter(
102
                group => !group.parent_id && group.ft_acquisitions
103
            );
104
            if (!topLevelGroups?.length) {
105
                return;
106
            }
107
            this.libraryGroups = topLevelGroups.map(group => {
108
                return this._mapLibraryGroup(group, groups);
109
            });
110
        },
111
        _mapLibraryGroup(group, groups) {
112
            const groupInfo = {
113
                id: group.id,
114
                title: group.title,
115
                libraries: [],
116
                subGroups: [],
117
            };
118
            const libsOrSubGroups = groups.filter(
119
                grp => grp.parent_id == group.id
120
            );
121
            libsOrSubGroups.forEach(libOrSubGroup => {
122
                if (libOrSubGroup.branchcode) {
123
                    groupInfo.libraries.push(libOrSubGroup);
124
                } else {
125
                    const subGroupInfo = this._mapLibraryGroup(
126
                        libOrSubGroup,
127
                        groups,
128
                        true
129
                    );
130
                    groupInfo.subGroups.push(subGroupInfo);
131
                }
132
            });
133
            groupInfo.subGroups.forEach(subGroup => {
134
                subGroup.libraries.forEach(lib => {
135
                    if (
136
                        !groupInfo.libraries.find(
137
                            g => g.branchcode === lib.branchcode
138
                        )
139
                    ) {
140
                        groupInfo.libraries.push(lib);
141
                    }
142
                });
143
            });
144
            return groupInfo;
145
        },
146
    },
147
    getters: {
148
        getVisibleGroups() {
149
            return this.visibleGroups?.length
150
                ? this.visibleGroups
151
                : this.filterLibGroupsByUsersBranchcode();
152
        },
153
    },
14
});
154
});
15
- 

Return to bug 38290