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

(-)a/Koha/AdditionalField.pm (+1 lines)
Lines 61-66 sub to_api { Link Here
61
        'aqinvoices'          => 'invoice',
61
        'aqinvoices'          => 'invoice',
62
        'erm_licenses'        => 'license',
62
        'erm_licenses'        => 'license',
63
        'erm_agreements'      => 'agreement',
63
        'erm_agreements'      => 'agreement',
64
        'erm_packages'        => 'package',
64
        'aqorders'            => 'order',
65
        'aqorders'            => 'order',
65
    };
66
    };
66
67
(-)a/Koha/ERM/EHoldings/Package.pm (-1 / +1 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use Koha::Database;
20
use Koha::Database;
21
21
22
use base qw(Koha::Object);
22
use base qw(Koha::Object::Mixin::AdditionalFields Koha::Object);
23
23
24
use Koha::Acquisition::Booksellers;
24
use Koha::Acquisition::Booksellers;
25
use Koha::ERM::EHoldings::Package::Agreements;
25
use Koha::ERM::EHoldings::Package::Agreements;
(-)a/Koha/ERM/EHoldings/Packages.pm (-1 / +1 lines)
Lines 22-28 use Koha::Database; Link Here
22
22
23
use Koha::ERM::EHoldings::Package;
23
use Koha::ERM::EHoldings::Package;
24
24
25
use base qw(Koha::Objects);
25
use base qw(Koha::Objects::Mixin::AdditionalFields Koha::Objects);
26
26
27
=head1 NAME
27
=head1 NAME
28
28
(-)a/Koha/REST/V1/ERM/EHoldings/Packages/Local.pm (+8 lines)
Lines 88-98 sub add { Link Here
88
                my $body = $c->req->json;
88
                my $body = $c->req->json;
89
89
90
                my $package_agreements = delete $body->{package_agreements} // [];
90
                my $package_agreements = delete $body->{package_agreements} // [];
91
                my $extended_attributes = delete $body->{extended_attributes} // [];
91
                delete $body->{external_id} unless $body->{external_id};
92
                delete $body->{external_id} unless $body->{external_id};
92
93
93
                my $package = Koha::ERM::EHoldings::Package->new_from_api($body)->store;
94
                my $package = Koha::ERM::EHoldings::Package->new_from_api($body)->store;
94
                $package->package_agreements($package_agreements);
95
                $package->package_agreements($package_agreements);
95
96
97
                my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
98
                $package->extended_attributes( \@extended_attributes );
99
96
                $c->res->headers->location($c->req->url->to_string . '/' . $package->package_id);
100
                $c->res->headers->location($c->req->url->to_string . '/' . $package->package_id);
97
                return $c->render(
101
                return $c->render(
98
                    status  => 201,
102
                    status  => 201,
Lines 160-165 sub update { Link Here
160
                my $body = $c->req->json;
164
                my $body = $c->req->json;
161
165
162
                my $package_agreements = delete $body->{package_agreements} // [];
166
                my $package_agreements = delete $body->{package_agreements} // [];
167
                my $extended_attributes = delete $body->{extended_attributes} // [];
163
                delete $body->{external_id} unless $body->{external_id};
168
                delete $body->{external_id} unless $body->{external_id};
164
169
165
                $package->set_from_api($body)->store;
170
                $package->set_from_api($body)->store;
Lines 168-173 sub update { Link Here
168
                # ie. It's coming from EBSCO and we don't have local data linked to it
173
                # ie. It's coming from EBSCO and we don't have local data linked to it
169
                $package->package_agreements($package_agreements);
174
                $package->package_agreements($package_agreements);
170
175
176
                my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
177
                $package->extended_attributes( \@extended_attributes );
178
171
                $c->res->headers->location($c->req->url->to_string . '/' . $package->package_id);
179
                $c->res->headers->location($c->req->url->to_string . '/' . $package->package_id);
172
                return $c->render(
180
                return $c->render(
173
                    status  => 200,
181
                    status  => 200,
(-)a/Koha/REST/V1/ExtendedAttributeTypes.pm (+1 lines)
Lines 52-57 sub list { Link Here
52
        invoice   => 'aqinvoices',
52
        invoice   => 'aqinvoices',
53
        license   => 'erm_licenses',
53
        license   => 'erm_licenses',
54
        agreement => 'erm_agreements',
54
        agreement => 'erm_agreements',
55
        package   => 'erm_packages',
55
        order     => 'aqorders',
56
        order     => 'aqorders',
56
    };
57
    };
57
58
(-)a/Koha/Schema/Result/ErmEholdingsPackage.pm (+32 lines)
Lines 201-206 __PACKAGE__->many_to_many("agreements", "erm_eholdings_packages_agreements", "ag Link Here
201
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-11-11 11:52:09
201
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-11-11 11:52:09
202
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3YA6xOwdLHDLoZnQJNk8eQ
202
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3YA6xOwdLHDLoZnQJNk8eQ
203
203
204
__PACKAGE__->has_many(
205
    "additional_field_values",
206
    "Koha::Schema::Result::AdditionalFieldValue",
207
    sub {
208
        my ($args) = @_;
209
210
        return {
211
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.package_id" },
212
213
            "$args->{foreign_alias}.field_id" =>
214
                { -in => \'(SELECT id FROM additional_fields WHERE tablename="erm_packages")' },
215
        };
216
    },
217
    { cascade_copy => 0, cascade_delete => 0 },
218
);
219
220
__PACKAGE__->has_many(
221
    "extended_attributes",
222
    "Koha::Schema::Result::AdditionalFieldValue",
223
    sub {
224
        my ($args) = @_;
225
226
        return {
227
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.package_id" },
228
229
            "$args->{foreign_alias}.field_id" =>
230
                { -in => \'(SELECT id FROM additional_fields WHERE tablename="erm_packages")' },
231
        };
232
    },
233
    { cascade_copy => 0, cascade_delete => 0 },
234
);
235
204
sub koha_object_class {
236
sub koha_object_class {
205
    'Koha::ERM::EHoldings::Package';
237
    'Koha::ERM::EHoldings::Package';
206
}
238
}
(-)a/api/v1/swagger/definitions/erm_eholdings_package.yaml (+10 lines)
Lines 70-75 properties: Link Here
70
    type:
70
    type:
71
      - integer
71
      - integer
72
      - "null"
72
      - "null"
73
  extended_attributes:
74
    description: Related additional field values
75
    type:
76
      - array
77
    items:
78
      $ref: extended_attribute_value.yaml
79
  _strings:
80
    type:
81
      - object
82
      - "null"
73
83
74
additionalProperties: false
84
additionalProperties: false
75
required:
85
required:
(-)a/api/v1/swagger/paths/erm_eholdings_packages.yaml (+6 lines)
Lines 72-77 Link Here
72
            - vendor.name
72
            - vendor.name
73
            - resources+count
73
            - resources+count
74
            - resources
74
            - resources
75
            - extended_attributes
76
            - +strings
75
        collectionFormat: csv
77
        collectionFormat: csv
76
    responses:
78
    responses:
77
      200:
79
      200:
Lines 193-198 Link Here
193
            - package_agreements.agreement
195
            - package_agreements.agreement
194
            - resources+count
196
            - resources+count
195
            - vendor
197
            - vendor
198
            - extended_attributes
199
            - +strings
196
        collectionFormat: csv
200
        collectionFormat: csv
197
    responses:
201
    responses:
198
      200:
202
      200:
Lines 262-267 Link Here
262
          enum:
266
          enum:
263
            - agreements
267
            - agreements
264
            - resources
268
            - resources
269
            - extended_attributes
270
            - +strings
265
        collectionFormat: csv
271
        collectionFormat: csv
266
    responses:
272
    responses:
267
      200:
273
      200:
(-)a/api/v1/swagger/paths/extended_attribute_types.yaml (+1 lines)
Lines 20-25 Link Here
20
          - invoice
20
          - invoice
21
          - license
21
          - license
22
          - agreement
22
          - agreement
23
          - package
23
          - order
24
          - order
24
          - subscription
25
          - subscription
25
      - $ref: "../swagger.yaml#/parameters/match"
26
      - $ref: "../swagger.yaml#/parameters/match"
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt (-1 / +2 lines)
Lines 23-29 Link Here
23
</head>
23
</head>
24
24
25
[% marcfield_tables = ['subscription', 'aqorders'] %]
25
[% marcfield_tables = ['subscription', 'aqorders'] %]
26
[% searchable_tables = ['subscription', 'aqbasket', 'aqinvoices', 'erm_licenses', 'erm_agreements'] %]
26
[% searchable_tables = ['subscription', 'aqbasket', 'aqinvoices', 'erm_licenses', 'erm_agreements', 'erm_packages'] %]
27
[% show_marcfield = marcfield_tables.grep('^' _ tablename _ '$').size ? 1 : 0 %]
27
[% show_marcfield = marcfield_tables.grep('^' _ tablename _ '$').size ? 1 : 0 %]
28
[% show_searchable = searchable_tables.grep('^' _ tablename _ '$').size ? 1 : 0 %]
28
[% show_searchable = searchable_tables.grep('^' _ tablename _ '$').size ? 1 : 0 %]
29
29
Lines 138-143 Link Here
138
                [% IF CAN_user_erm %]
138
                [% IF CAN_user_erm %]
139
                    [% WRAPPER table_option value="erm_licenses" %]ERM Licenses[% END %]
139
                    [% WRAPPER table_option value="erm_licenses" %]ERM Licenses[% END %]
140
                    [% WRAPPER table_option value="erm_agreements" %]ERM Agreements[% END %]
140
                    [% WRAPPER table_option value="erm_agreements" %]ERM Agreements[% END %]
141
                    [% WRAPPER table_option value="erm_packages" %]ERM Packages[% END %]
141
                [% END %]
142
                [% END %]
142
            </ul>
143
            </ul>
143
            [% ELSE %]
144
            [% ELSE %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue (+12 lines)
Lines 63-68 Link Here
63
                        </li>
63
                        </li>
64
                    </ol>
64
                    </ol>
65
                </fieldset>
65
                </fieldset>
66
                <AdditionalFieldsEntry
67
                    resource_type="package"
68
                    :additional_field_values="erm_package.extended_attributes"
69
                    @additional-fields-changed="additionalFieldsChanged"
70
                />
66
                <EHoldingsPackageAgreements
71
                <EHoldingsPackageAgreements
67
                    :package_agreements="erm_package.package_agreements"
72
                    :package_agreements="erm_package.package_agreements"
68
                />
73
                />
Lines 87-92 Link Here
87
<script>
92
<script>
88
import { inject } from "vue"
93
import { inject } from "vue"
89
import EHoldingsPackageAgreements from "./EHoldingsLocalPackageAgreements.vue"
94
import EHoldingsPackageAgreements from "./EHoldingsLocalPackageAgreements.vue"
95
import AdditionalFieldsEntry from "../AdditionalFieldsEntry.vue"
90
import FormSelectVendors from "../FormSelectVendors.vue"
96
import FormSelectVendors from "../FormSelectVendors.vue"
91
import { setMessage, setError, setWarning } from "../../messages"
97
import { setMessage, setError, setWarning } from "../../messages"
92
import { APIClient } from "../../fetch/api-client.js"
98
import { APIClient } from "../../fetch/api-client.js"
Lines 116-121 export default { Link Here
116
                created_on: null,
122
                created_on: null,
117
                resources: null,
123
                resources: null,
118
                package_agreements: [],
124
                package_agreements: [],
125
                extended_attributes: [],
119
            },
126
            },
120
            initialized: false,
127
            initialized: false,
121
        }
128
        }
Lines 172-177 export default { Link Here
172
            delete erm_package.vendor
179
            delete erm_package.vendor
173
            delete erm_package.resources_count
180
            delete erm_package.resources_count
174
            delete erm_package.is_selected
181
            delete erm_package.is_selected
182
            delete erm_package._strings
175
183
176
            erm_package.package_agreements = erm_package.package_agreements.map(
184
            erm_package.package_agreements = erm_package.package_agreements.map(
177
                ({ package_id, agreement, ...keepAttrs }) => keepAttrs
185
                ({ package_id, agreement, ...keepAttrs }) => keepAttrs
Lines 200-209 export default { Link Here
200
                )
208
                )
201
            }
209
            }
202
        },
210
        },
211
        additionalFieldsChanged(additionalFieldValues) {
212
            this.erm_package.extended_attributes = additionalFieldValues
213
        },
203
    },
214
    },
204
    components: {
215
    components: {
205
        EHoldingsPackageAgreements,
216
        EHoldingsPackageAgreements,
206
        FormSelectVendors,
217
        FormSelectVendors,
218
        AdditionalFieldsEntry,
207
    },
219
    },
208
    name: "EHoldingsEBSCOPackagesFormAdd",
220
    name: "EHoldingsEBSCOPackagesFormAdd",
209
}
221
}
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue (-2 / +49 lines)
Lines 17-22 Link Here
17
                <KohaTable
17
                <KohaTable
18
                    ref="table"
18
                    ref="table"
19
                    v-bind="tableOptions"
19
                    v-bind="tableOptions"
20
                    :searchable_additional_fields="searchable_additional_fields"
21
                    :searchable_av_options="searchable_av_options"
20
                    @show="doShow"
22
                    @show="doShow"
21
                    @edit="doEdit"
23
                    @edit="doEdit"
22
                    @delete="doDelete"
24
                    @delete="doDelete"
Lines 74-84 export default { Link Here
74
        return {
76
        return {
75
            package_count: 0,
77
            package_count: 0,
76
            initialized: false,
78
            initialized: false,
79
            searchable_additional_fields: [],
80
            searchable_av_options: [],
77
            tableOptions: {
81
            tableOptions: {
78
                columns: this.getTableColumns(),
82
                columns: this.getTableColumns(),
79
                url: "/api/v1/erm/eholdings/local/packages",
83
                url: "/api/v1/erm/eholdings/local/packages",
80
                options: {
84
                options: {
81
                    embed: "resources+count,vendor.name",
85
                    embed: "resources+count,vendor.name,extended_attributes,+strings",
82
                    searchCols: [
86
                    searchCols: [
83
                        { search: filters.package_name },
87
                        { search: filters.package_name },
84
                        null,
88
                        null,
Lines 109-115 export default { Link Here
109
    },
113
    },
110
    beforeRouteEnter(to, from, next) {
114
    beforeRouteEnter(to, from, next) {
111
        next(vm => {
115
        next(vm => {
112
            vm.getPackageCount().then(() => (vm.initialized = true))
116
            vm.getPackageCount().then(() =>
117
                vm
118
                    .getSearchableAdditionalFields()
119
                    .then(() =>
120
                        vm
121
                            .getSearchableAVOptions()
122
                            .then(() => (vm.initialized = true))
123
                    )
124
            )
113
        })
125
        })
114
    },
126
    },
115
    methods: {
127
    methods: {
Lines 121-126 export default { Link Here
121
                },
133
                },
122
                error => {}
134
                error => {}
123
            )
135
            )
136
        },
137
	    async getSearchableAdditionalFields() {
138
            const client = APIClient.additional_fields
139
            await client.additional_fields.getAll("package").then(
140
                searchable_additional_fields => {
141
                    this.searchable_additional_fields =
142
                        searchable_additional_fields.filter(
143
                            field => field.searchable
144
                        )
145
                },
146
                error => {}
147
            )
148
        },
149
        async getSearchableAVOptions() {
150
            const client_av = APIClient.authorised_values
151
            let av_cat_array = this.searchable_additional_fields
152
                .filter(field => field.authorised_value_category_name)
153
                .map(field => field.authorised_value_category_name)
154
155
            await client_av.values
156
                .getCategoriesWithValues([
157
                    ...new Set(av_cat_array.map(av_cat => '"' + av_cat + '"')),
158
                ]) // unique
159
                .then(av_categories => {
160
                    av_cat_array.forEach(av_cat => {
161
                        let av_match = av_categories.find(
162
                            element => element.category_name == av_cat
163
                        )
164
                        this.searchable_av_options[av_cat] =
165
                            av_match.authorised_values.map(av => ({
166
                                value: av.value,
167
                                label: av.description,
168
                            }))
169
                    })
170
                })
124
        },
171
        },
125
        doShow: function ({ package_id }, dt, event) {
172
        doShow: function ({ package_id }, dt, event) {
126
            event.preventDefault()
173
            event.preventDefault()
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesShow.vue (+10 lines)
Lines 102-107 Link Here
102
                    />
102
                    />
103
                </div>
103
                </div>
104
            </fieldset>
104
            </fieldset>
105
            <AdditionalFieldsDisplay
106
                resource_type="package"
107
                :additional_field_values="
108
                    erm_package._strings.additional_field_values
109
                "
110
            />
105
            <fieldset class="action">
111
            <fieldset class="action">
106
                <router-link
112
                <router-link
107
                    :to="{ name: 'EHoldingsLocalPackagesList' }"
113
                    :to="{ name: 'EHoldingsLocalPackagesList' }"
Lines 120-125 import EHoldingsPackageTitlesList from "./EHoldingsLocalPackageTitlesList.vue" Link Here
120
import { APIClient } from "../../fetch/api-client.js"
126
import { APIClient } from "../../fetch/api-client.js"
121
import Toolbar from "../Toolbar.vue"
127
import Toolbar from "../Toolbar.vue"
122
import ToolbarButton from "../ToolbarButton.vue"
128
import ToolbarButton from "../ToolbarButton.vue"
129
import AdditionalFieldsDisplay from "../AdditionalFieldsDisplay.vue"
123
130
124
export default {
131
export default {
125
    setup() {
132
    setup() {
Lines 149-154 export default { Link Here
149
                created_on: null,
156
                created_on: null,
150
                resources: null,
157
                resources: null,
151
                package_agreements: [],
158
                package_agreements: [],
159
                extended_attributes: [],
160
                _strings: [],
152
            },
161
            },
153
            initialized: false,
162
            initialized: false,
154
        }
163
        }
Lines 206-211 export default { Link Here
206
        EHoldingsPackageTitlesList,
215
        EHoldingsPackageTitlesList,
207
        Toolbar,
216
        Toolbar,
208
        ToolbarButton,
217
        ToolbarButton,
218
        AdditionalFieldsDisplay,
209
    },
219
    },
210
    name: "EHoldingsLocalPackagesShow",
220
    name: "EHoldingsLocalPackagesShow",
211
}
221
}
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js (-1 / +1 lines)
Lines 112-118 export class ERMAPIClient extends HttpClient { Link Here
112
                    endpoint: "eholdings/local/packages/" + id,
112
                    endpoint: "eholdings/local/packages/" + id,
113
                    headers: {
113
                    headers: {
114
                        "x-koha-embed":
114
                        "x-koha-embed":
115
                            "package_agreements,package_agreements.agreement,resources+count,vendor",
115
                            "package_agreements,package_agreements.agreement,resources+count,vendor,extended_attributes,+strings",
116
                    },
116
                    },
117
                }),
117
                }),
118
            getAll: (query, params) =>
118
            getAll: (query, params) =>
(-)a/t/cypress/integration/AdditionalFields_spec.ts (-1 / +535 lines)
Lines 338-343 function get_agreements_additional_fields() { Link Here
338
    ];
338
    ];
339
}
339
}
340
340
341
function get_no_additional_fields_package() {
342
    return {
343
        package_id: 1,
344
        name: "package 1",
345
        notes: "my first package",
346
        content_type: "",
347
        created_on: "2024-09-12T10:26:40+00:00",
348
        external_id: null,
349
        package_agreements: [],
350
        package_type: "",
351
        provider: null,
352
        resources_count: 0,
353
        vendor_id: 1,
354
        vendor: [cy.get_vendors_to_relate()[0]],
355
        extended_attributes: [],
356
        _strings: {
357
            "additional_field_values": []
358
        },
359
    };
360
}
361
function get_package() {
362
    return {
363
        package_id: 1,
364
        name: "package 1",
365
        notes: "my first package",
366
        content_type: "",
367
        created_on: "2024-09-12T10:26:40+00:00",
368
        external_id: null,
369
        package_agreements: [],
370
        package_type: "",
371
        provider: null,
372
        resources_count: 0,
373
        vendor_id: 1,
374
        vendor: [cy.get_vendors_to_relate()[0]],
375
        extended_attributes: [
376
            {
377
                field_id: 1,
378
                id: "1",
379
                record_id: "1",
380
                value: "REF",
381
            },
382
            {
383
                field_id: 1,
384
                id: "2",
385
                record_id: "1",
386
                value: "NFIC",
387
            },
388
            {
389
                field_id: 2,
390
                id: "3",
391
                record_id: "1",
392
                value: "some text",
393
            },
394
            {
395
                field_id: 3,
396
                id: "4",
397
                record_id: "1",
398
                value: "some repeatable text",
399
            },
400
            {
401
                field_id: 4,
402
                id: "5",
403
                record_id: "1",
404
                value: "AF",
405
            },
406
        ],
407
        _strings: {
408
            additional_field_values: [
409
                {
410
                    field_id: 1,
411
                    field_label: "AV Repeatable",
412
                    type: "av",
413
                    value_str: "Reference, Non-fiction",
414
                },
415
                {
416
                    field_id: 2,
417
                    field_label: "Text non-repeatable",
418
                    type: "text",
419
                    value_str: "some text",
420
                },
421
                {
422
                    field_id: 3,
423
                    field_label: "Text repeatable",
424
                    type: "text",
425
                    value_str: "some repeatable text",
426
                },
427
                {
428
                    field_id: 4,
429
                    field_label: "AV Searchable",
430
                    type: "av",
431
                    value_str: "Afghanistan",
432
                },
433
            ],
434
        },
435
    };
436
}
437
438
function get_packages_additional_fields() {
439
    return [
440
        {
441
            authorised_value_category_name: "CCODE",
442
            extended_attribute_type_id: 1,
443
            marcfield: "",
444
            marcfield_mode: "get",
445
            name: "AV Repeatable",
446
            repeatable: true,
447
            searchable: true,
448
            resource_type: "package",
449
        },
450
        {
451
            authorised_value_category_name: null,
452
            extended_attribute_type_id: 2,
453
            marcfield: "",
454
            marcfield_mode: "get",
455
            name: "Text non-repeatable",
456
            repeatable: false,
457
            searchable: false,
458
            resource_type: "package",
459
        },
460
        {
461
            authorised_value_category_name: null,
462
            extended_attribute_type_id: 3,
463
            marcfield: "",
464
            marcfield_mode: "get",
465
            name: "Text repeatable",
466
            repeatable: true,
467
            searchable: false,
468
            resource_type: "package",
469
        },
470
        {
471
            authorised_value_category_name: "COUNTRY",
472
            extended_attribute_type_id: 4,
473
            marcfield: "",
474
            marcfield_mode: "get",
475
            name: "AV Searchable",
476
            repeatable: false,
477
            searchable: true,
478
            resource_type: "package",
479
        },
480
    ];
481
}
482
341
function get_av_cats() {
483
function get_av_cats() {
342
    return [
484
    return [
343
        {
485
        {
Lines 1208-1211 describe("Additional Fields operations", () => { Link Here
1208
        ).should("have.length", 2);
1350
        ).should("have.length", 2);
1209
    });
1351
    });
1210
1352
1353
    //
1354
    // for packages
1355
    //
1356
1357
    it("Additional Fields display - Table (eHoldings packages)", () => {
1358
        let eholdings_package = get_package();
1359
        let eholdings_packages = [eholdings_package];
1360
        let eholdings_package_additional_fields = get_packages_additional_fields();
1361
        let av_cats = get_av_cats();
1362
1363
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1364
            body: eholdings_package_additional_fields,
1365
            statusCode: 200,
1366
        });
1367
1368
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
1369
            statusCode: 200,
1370
            body: eholdings_packages,
1371
            headers: {
1372
                "X-Base-Total-Count": "1",
1373
                "X-Total-Count": "1",
1374
            },
1375
        });
1376
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package);
1377
        cy.visit("/cgi-bin/koha/erm/eholdings/local/packages");
1378
        cy.get("#packages_list").contains("Showing 1 to 1 of 1 entries");
1379
1380
        cy.get("#packages_list table tbody tr:first").contains(
1381
            get_description_from_av_value(
1382
                av_cats,
1383
                eholdings_package.extended_attributes[0]
1384
            )
1385
        );
1386
        cy.get("#packages_list table tbody tr:first").contains(
1387
            get_description_from_av_value(
1388
                av_cats,
1389
                eholdings_package.extended_attributes[0]
1390
            ) +
1391
                ", " +
1392
                get_description_from_av_value(
1393
                    av_cats,
1394
                    eholdings_package.extended_attributes[1]
1395
                )
1396
        );
1397
    });
1398
1399
    it("Additional Fields display - Show (eHoldings packages)", () => {
1400
        let empty_eholdings_package = get_no_additional_fields_package();
1401
        let eholdings_package = get_package();
1402
        let eholdings_packages = [eholdings_package];
1403
        let vendors = cy.get_vendors_to_relate();
1404
        let eholdings_package_additional_fields = get_packages_additional_fields();
1405
        let av_cats = get_av_cats();
1406
1407
        // Click the 'Edit' button from the list
1408
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
1409
            statusCode: 200,
1410
            body: eholdings_packages,
1411
            headers: {
1412
                "X-Base-Total-Count": "1",
1413
                "X-Total-Count": "1",
1414
            },
1415
        });
1416
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", empty_eholdings_package).as(
1417
            "get-empty-eholdings-package"
1418
        );
1419
1420
        //Intercept vendors request
1421
        cy.intercept("GET", "/api/v1/acquisitions/vendors*", {
1422
            statusCode: 200,
1423
            body: vendors,
1424
        });
1425
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1426
            body: [],
1427
            statusCode: 200,
1428
        }).as("empty-additional-fields");
1429
1430
        //Empty additional fields, should not display
1431
        cy.visit("/cgi-bin/koha/erm/eholdings/local/packages");
1432
        cy.get("#packages_list table tbody tr:first td:first a").click();
1433
        cy.wait("@get-empty-eholdings-package");
1434
        cy.get("#packages_list #additional_fields").should("not.exist");
1435
1436
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1437
            body: eholdings_package_additional_fields,
1438
            statusCode: 200,
1439
        }).as("existing-additional-fields");
1440
1441
        cy.intercept(
1442
            {
1443
                pathname: "/api/v1/authorised_value_categories",
1444
                query: {
1445
                    q: '{"me.category_name":["CCODE", "COUNTRY"]}',
1446
                },
1447
            },
1448
            {
1449
                body: av_cats,
1450
                statusCode: 200,
1451
            }
1452
        ).as("avcategories");
1453
1454
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package).as(
1455
            "get-eholdings-package"
1456
        );
1457
1458
        // There are additional fields, fieldset should exist
1459
        cy.visit("/cgi-bin/koha/erm/eholdings/local/packages");
1460
        cy.get("#packages_list table tbody tr:first td:first a").click();
1461
        cy.wait("@get-eholdings-package");
1462
        cy.get("#packages_show #additional_fields").should("exist");
1463
1464
        // All fields are presented correctly
1465
        cy.get(
1466
            "#packages_show #additional_fields label[for='additional_field_1']"
1467
        ).contains(eholdings_package_additional_fields[0].name);
1468
        cy.get(
1469
            "#packages_show #additional_fields label[for='additional_field_1']"
1470
        )
1471
            .parent()
1472
            .children("span")
1473
            .contains(
1474
                get_description_from_av_value(
1475
                    av_cats,
1476
                    eholdings_package.extended_attributes[0]
1477
                ) +
1478
                    ", " +
1479
                    get_description_from_av_value(
1480
                        av_cats,
1481
                        eholdings_package.extended_attributes[1]
1482
                    )
1483
            );
1484
1485
        cy.get(
1486
            "#packages_show #additional_fields label[for='additional_field_2']"
1487
        ).contains(eholdings_package_additional_fields[1].name);
1488
        cy.get(
1489
            "#packages_show #additional_fields label[for='additional_field_2']"
1490
        )
1491
            .parent()
1492
            .children("span")
1493
            .contains(eholdings_package.extended_attributes[2].value);
1494
1495
        cy.get(
1496
            "#packages_show #additional_fields label[for='additional_field_3']"
1497
        ).contains(eholdings_package_additional_fields[2].name);
1498
        cy.get(
1499
            "#packages_show #additional_fields label[for='additional_field_3']"
1500
        )
1501
            .parent()
1502
            .children("span")
1503
            .contains(eholdings_package.extended_attributes[3].value);
1504
1505
        cy.get(
1506
            "#packages_show #additional_fields label[for='additional_field_4']"
1507
        ).contains(eholdings_package_additional_fields[3].name);
1508
        cy.get(
1509
            "#packages_show #additional_fields label[for='additional_field_4']"
1510
        )
1511
            .parent()
1512
            .children("span")
1513
            .contains(
1514
                get_description_from_av_value(
1515
                    av_cats,
1516
                    eholdings_package.extended_attributes[4]
1517
                )
1518
            );
1519
    });
1520
1521
    it("Additional Fields entry - Add (eHoldings packages)", () => {
1522
        let vendors = cy.get_vendors_to_relate();
1523
        let eholdings_package_additional_fields = get_packages_additional_fields();
1524
        let av_cats = get_av_cats();
1525
1526
        //Intercept vendors request
1527
        cy.intercept("GET", "/api/v1/acquisitions/vendors*", {
1528
            statusCode: 200,
1529
            body: vendors,
1530
        });
1531
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1532
            body: [],
1533
            statusCode: 200,
1534
        }).as("empty-additional-fields");
1535
1536
        // No additional fields, fieldset should not exist
1537
        cy.visit("/cgi-bin/koha/erm/eholdings/local/packages/add");
1538
        cy.get("#packages_add form #additional_fields").should("not.exist");
1539
1540
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1541
            body: eholdings_package_additional_fields,
1542
            statusCode: 200,
1543
        }).as("existing-additional-fields");
1544
1545
        cy.intercept(
1546
            {
1547
                pathname: "/api/v1/authorised_value_categories",
1548
                query: {
1549
                    q: '{"me.category_name":["CCODE", "COUNTRY"]}',
1550
                },
1551
            },
1552
            {
1553
                body: av_cats,
1554
                statusCode: 200,
1555
            }
1556
        ).as("avcategories");
1557
        // There are additional fields, fieldset should exist
1558
        cy.visit("/cgi-bin/koha/erm/eholdings/local/packages/add");
1559
        cy.get("#packages_add form #additional_fields").should("exist");
1560
1561
        // All additional fields should be listed
1562
        cy.get(
1563
            "#packages_add form #additional_fields label[for='additional_field_1']"
1564
        ).contains(eholdings_package_additional_fields[0].name);
1565
        cy.get(
1566
            "#packages_add form #additional_fields label[for='additional_field_2']"
1567
        ).contains(eholdings_package_additional_fields[1].name);
1568
        cy.get(
1569
            "#packages_add form #additional_fields label[for='additional_field_3']"
1570
        ).contains(eholdings_package_additional_fields[2].name);
1571
        cy.get(
1572
            "#packages_add form #additional_fields label[for='additional_field_4']"
1573
        ).contains(eholdings_package_additional_fields[3].name);
1574
1575
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1576
            "not.exist"
1577
        ); //new package, no pre-selected value
1578
1579
        // Pick one value
1580
        cy.get("#additional_fields #additional_field_1 .vs__search").click();
1581
        cy.get(
1582
            "#additional_fields #additional_field_1 #vs4__option-0"
1583
        ).contains(av_cats[0].authorised_values[0].description);
1584
        cy.get("#additional_fields #additional_field_1 #vs4__option-0").click();
1585
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1586
            av_cats[0].authorised_values[0].description
1587
        );
1588
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1589
            "have.length",
1590
            1
1591
        );
1592
1593
        // Pick a second value for the same repeatable AV field
1594
        cy.get("#additional_fields #additional_field_1 .vs__search").click();
1595
        cy.get(
1596
            "#additional_fields #additional_field_1 #vs4__option-1"
1597
        ).contains(av_cats[0].authorised_values[1].description);
1598
        cy.get("#additional_fields #additional_field_1 #vs4__option-1").click();
1599
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1600
            av_cats[0].authorised_values[1].description
1601
        );
1602
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1603
            "have.length",
1604
            2
1605
        );
1606
1607
        // Attempt to pick the same value again - should not be possible
1608
        cy.get("#additional_fields #additional_field_1 .vs__search").click();
1609
        cy.get(
1610
            "#additional_fields #additional_field_1 #vs4__option-1"
1611
        ).contains(av_cats[0].authorised_values[1].description);
1612
        cy.get("#additional_fields #additional_field_1 #vs4__option-1").click();
1613
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1614
            "have.length",
1615
            2
1616
        );
1617
1618
        // Remove the second selected value
1619
        cy.get(
1620
            "#additional_fields #additional_field_1 .vs__selected button[title='Deselect " +
1621
                av_cats[0].authorised_values[1].description +
1622
                "'"
1623
        ).click();
1624
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1625
            "have.length",
1626
            1
1627
        );
1628
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1629
            av_cats[0].authorised_values[0].description
1630
        );
1631
    });
1632
1633
    it("Additional Fields entry - Edit (eHoldings packages)", () => {
1634
        let eholdings_package = get_package();
1635
        let eholdings_packages = [eholdings_package];
1636
        let vendors = cy.get_vendors_to_relate();
1637
        let eholdings_package_additional_fields = get_packages_additional_fields();
1638
        let av_cats = get_av_cats();
1639
1640
        // Click the 'Edit' button from the list
1641
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
1642
            statusCode: 200,
1643
            body: eholdings_packages,
1644
            headers: {
1645
                "X-Base-Total-Count": "1",
1646
                "X-Total-Count": "1",
1647
            },
1648
        });
1649
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package).as(
1650
            "get-eholdings-package"
1651
        );
1652
1653
        //Intercept vendors request
1654
        cy.intercept("GET", "/api/v1/acquisitions/vendors*", {
1655
            statusCode: 200,
1656
            body: vendors,
1657
        });
1658
1659
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1660
            body: eholdings_package_additional_fields,
1661
            statusCode: 200,
1662
        }).as("existing-additional-fields");
1663
1664
        cy.intercept(
1665
            {
1666
                pathname: "/api/v1/authorised_value_categories",
1667
                query: {
1668
                    q: '{"me.category_name":["CCODE", "COUNTRY"]}',
1669
                },
1670
            },
1671
            {
1672
                body: av_cats,
1673
                statusCode: 200,
1674
            }
1675
        ).as("avcategories");
1676
1677
        cy.visit("/cgi-bin/koha/erm/eholdings/local/packages");
1678
        cy.get("#packages_list table tbody tr:first").contains("Edit").click();
1679
        cy.wait("@get-eholdings-package");
1680
        cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
1681
1682
        // All additional fields should be pre-populated
1683
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1684
            get_description_from_av_value(
1685
                av_cats,
1686
                eholdings_package.extended_attributes[0]
1687
            )
1688
        );
1689
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1690
            get_description_from_av_value(
1691
                av_cats,
1692
                eholdings_package.extended_attributes[1]
1693
            )
1694
        );
1695
1696
        cy.get(
1697
            "#packages_add form #additional_fields label[for='additional_field_2']"
1698
        )
1699
            .parent()
1700
            .children("input")
1701
            .should("have.value", eholdings_package.extended_attributes[2].value);
1702
1703
        cy.get(
1704
            "#packages_add form #additional_fields label[for='additional_field_3']"
1705
        )
1706
            .parent()
1707
            .children("input")
1708
            .should("have.value", eholdings_package.extended_attributes[3].value);
1709
1710
        cy.get("#additional_fields #additional_field_4 .vs__selected").contains(
1711
            get_description_from_av_value(
1712
                av_cats,
1713
                eholdings_package.extended_attributes[4]
1714
            )
1715
        );
1716
1717
        // Clear text field works
1718
        cy.get(
1719
            "#packages_add form #additional_fields label[for='additional_field_2']"
1720
        )
1721
            .parent()
1722
            .children(".clear_attribute")
1723
            .click();
1724
        cy.get(
1725
            "#packages_add form #additional_fields label[for='additional_field_2']"
1726
        )
1727
            .parent()
1728
            .children("input")
1729
            .should("have.value", "");
1730
1731
        // "+New" text field works
1732
        cy.get(
1733
            "#packages_add form #additional_fields label[for='additional_field_3']"
1734
        ).should("have.length", 1);
1735
        cy.get(
1736
            "#packages_add form #additional_fields label[for='additional_field_3']"
1737
        )
1738
            .parent()
1739
            .children(".clone_attribute")
1740
            .click();
1741
        cy.get(
1742
            "#packages_add form #additional_fields label[for='additional_field_3']"
1743
        ).should("have.length", 2);
1744
    });
1745
1211
});
1746
});
1212
- 

Return to bug 37577