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 / +536 lines)
Lines 253-258 function get_agreements_additional_fields() { Link Here
253
    ];
253
    ];
254
}
254
}
255
255
256
function get_no_additional_fields_package() {
257
    return {
258
        package_id: 1,
259
        name: "package 1",
260
        notes: "my first package",
261
        content_type: "",
262
        created_on: "2024-09-12T10:26:40+00:00",
263
        external_id: null,
264
        package_agreements: [],
265
        package_type: "",
266
        provider: null,
267
        resources_count: 0,
268
        vendor_id: 1,
269
        vendor: [cy.get_vendors_to_relate()[0]],
270
        extended_attributes: [],
271
        _strings: {
272
            "additional_field_values": []
273
        },
274
    };
275
}
276
function get_package() {
277
    return {
278
        package_id: 1,
279
        name: "package 1",
280
        notes: "my first package",
281
        content_type: "",
282
        created_on: "2024-09-12T10:26:40+00:00",
283
        external_id: null,
284
        package_agreements: [],
285
        package_type: "",
286
        provider: null,
287
        resources_count: 0,
288
        vendor_id: 1,
289
        vendor: [cy.get_vendors_to_relate()[0]],
290
        extended_attributes: [
291
            {
292
                field_id: 1,
293
                id: "1",
294
                record_id: "1",
295
                value: "REF",
296
            },
297
            {
298
                field_id: 1,
299
                id: "2",
300
                record_id: "1",
301
                value: "NFIC",
302
            },
303
            {
304
                field_id: 2,
305
                id: "3",
306
                record_id: "1",
307
                value: "some text",
308
            },
309
            {
310
                field_id: 3,
311
                id: "4",
312
                record_id: "1",
313
                value: "some repeatable text",
314
            },
315
            {
316
                field_id: 4,
317
                id: "5",
318
                record_id: "1",
319
                value: "AF",
320
            },
321
        ],
322
        _strings: {
323
            additional_field_values: [
324
                {
325
                    field_id: 1,
326
                    field_label: "AV Repeatable",
327
                    type: "av",
328
                    value_str: "Reference, Non-fiction",
329
                },
330
                {
331
                    field_id: 2,
332
                    field_label: "Text non-repeatable",
333
                    type: "text",
334
                    value_str: "some text",
335
                },
336
                {
337
                    field_id: 3,
338
                    field_label: "Text repeatable",
339
                    type: "text",
340
                    value_str: "some repeatable text",
341
                },
342
                {
343
                    field_id: 4,
344
                    field_label: "AV Searchable",
345
                    type: "av",
346
                    value_str: "Afghanistan",
347
                },
348
            ],
349
        },
350
    };
351
}
352
353
function get_packages_additional_fields() {
354
    return [
355
        {
356
            authorised_value_category_name: "CCODE",
357
            extended_attribute_type_id: 1,
358
            marcfield: "",
359
            marcfield_mode: "get",
360
            name: "AV Repeatable",
361
            repeatable: true,
362
            searchable: true,
363
            resource_type: "package",
364
        },
365
        {
366
            authorised_value_category_name: null,
367
            extended_attribute_type_id: 2,
368
            marcfield: "",
369
            marcfield_mode: "get",
370
            name: "Text non-repeatable",
371
            repeatable: false,
372
            searchable: false,
373
            resource_type: "package",
374
        },
375
        {
376
            authorised_value_category_name: null,
377
            extended_attribute_type_id: 3,
378
            marcfield: "",
379
            marcfield_mode: "get",
380
            name: "Text repeatable",
381
            repeatable: true,
382
            searchable: false,
383
            resource_type: "package",
384
        },
385
        {
386
            authorised_value_category_name: "COUNTRY",
387
            extended_attribute_type_id: 4,
388
            marcfield: "",
389
            marcfield_mode: "get",
390
            name: "AV Searchable",
391
            repeatable: false,
392
            searchable: true,
393
            resource_type: "package",
394
        },
395
    ];
396
}
397
256
function get_av_cats() {
398
function get_av_cats() {
257
    return [
399
    return [
258
        {
400
        {
Lines 1124-1127 describe("Additional Fields operations", () => { Link Here
1124
            "#agreements_add form #additional_fields label[for='additional_field_3']"
1266
            "#agreements_add form #additional_fields label[for='additional_field_3']"
1125
        ).should("have.length", 2);
1267
        ).should("have.length", 2);
1126
    });
1268
    });
1269
1270
    //
1271
    // for packages
1272
    //
1273
1274
    it("Additional Fields display - Table (eHoldings packages)", () => {
1275
        let eholdings_package = get_package();
1276
        let eholdings_packages = [eholdings_package];
1277
        let eholdings_package_additional_fields = get_packages_additional_fields();
1278
        let av_cats = get_av_cats();
1279
1280
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1281
            body: eholdings_package_additional_fields,
1282
            statusCode: 200,
1283
        });
1284
1285
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
1286
            statusCode: 200,
1287
            body: eholdings_packages,
1288
            headers: {
1289
                "X-Base-Total-Count": "1",
1290
                "X-Total-Count": "1",
1291
            },
1292
        });
1293
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package);
1294
        cy.visit("/cgi-bin/koha/erm/eholdings/local/packages");
1295
        cy.get("#packages_list").contains("Showing 1 to 1 of 1 entries");
1296
1297
        cy.get("#packages_list table tbody tr:first").contains(
1298
            get_description_from_av_value(
1299
                av_cats,
1300
                eholdings_package.extended_attributes[0]
1301
            )
1302
        );
1303
        cy.get("#packages_list table tbody tr:first").contains(
1304
            get_description_from_av_value(
1305
                av_cats,
1306
                eholdings_package.extended_attributes[0]
1307
            ) +
1308
                ", " +
1309
                get_description_from_av_value(
1310
                    av_cats,
1311
                    eholdings_package.extended_attributes[1]
1312
                )
1313
        );
1314
    });
1315
1316
    it("Additional Fields display - Show (eHoldings packages)", () => {
1317
        let empty_eholdings_package = get_no_additional_fields_package();
1318
        let eholdings_package = get_package();
1319
        let eholdings_packages = [eholdings_package];
1320
        let vendors = cy.get_vendors_to_relate();
1321
        let eholdings_package_additional_fields = get_packages_additional_fields();
1322
        let av_cats = get_av_cats();
1323
1324
        // Click the 'Edit' button from the list
1325
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
1326
            statusCode: 200,
1327
            body: eholdings_packages,
1328
            headers: {
1329
                "X-Base-Total-Count": "1",
1330
                "X-Total-Count": "1",
1331
            },
1332
        });
1333
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", empty_eholdings_package).as(
1334
            "get-empty-eholdings-package"
1335
        );
1336
1337
        //Intercept vendors request
1338
        cy.intercept("GET", "/api/v1/acquisitions/vendors*", {
1339
            statusCode: 200,
1340
            body: vendors,
1341
        });
1342
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1343
            body: [],
1344
            statusCode: 200,
1345
        }).as("empty-additional-fields");
1346
1347
        //Empty additional fields, should not display
1348
        cy.visit("/cgi-bin/koha/erm/eholdings/local/packages");
1349
        cy.get("#packages_list table tbody tr:first td:first a").click();
1350
        cy.wait("@get-empty-eholdings-package");
1351
        cy.get("#packages_list #additional_fields").should("not.exist");
1352
1353
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1354
            body: eholdings_package_additional_fields,
1355
            statusCode: 200,
1356
        }).as("existing-additional-fields");
1357
1358
        cy.intercept(
1359
            {
1360
                pathname: "/api/v1/authorised_value_categories",
1361
                query: {
1362
                    q: '{"me.category_name":["CCODE", "COUNTRY"]}',
1363
                },
1364
            },
1365
            {
1366
                body: av_cats,
1367
                statusCode: 200,
1368
            }
1369
        ).as("avcategories");
1370
1371
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package).as(
1372
            "get-eholdings-package"
1373
        );
1374
1375
        // There are additional fields, fieldset should exist
1376
        cy.visit("/cgi-bin/koha/erm/eholdings/local/packages");
1377
        cy.get("#packages_list table tbody tr:first td:first a").click();
1378
        cy.wait("@get-eholdings-package");
1379
        cy.get("#packages_show #additional_fields").should("exist");
1380
1381
        // All fields are presented correctly
1382
        cy.get(
1383
            "#packages_show #additional_fields label[for='additional_field_1']"
1384
        ).contains(eholdings_package_additional_fields[0].name);
1385
        cy.get(
1386
            "#packages_show #additional_fields label[for='additional_field_1']"
1387
        )
1388
            .parent()
1389
            .children("span")
1390
            .contains(
1391
                get_description_from_av_value(
1392
                    av_cats,
1393
                    eholdings_package.extended_attributes[0]
1394
                ) +
1395
                    ", " +
1396
                    get_description_from_av_value(
1397
                        av_cats,
1398
                        eholdings_package.extended_attributes[1]
1399
                    )
1400
            );
1401
1402
        cy.get(
1403
            "#packages_show #additional_fields label[for='additional_field_2']"
1404
        ).contains(eholdings_package_additional_fields[1].name);
1405
        cy.get(
1406
            "#packages_show #additional_fields label[for='additional_field_2']"
1407
        )
1408
            .parent()
1409
            .children("span")
1410
            .contains(eholdings_package.extended_attributes[2].value);
1411
1412
        cy.get(
1413
            "#packages_show #additional_fields label[for='additional_field_3']"
1414
        ).contains(eholdings_package_additional_fields[2].name);
1415
        cy.get(
1416
            "#packages_show #additional_fields label[for='additional_field_3']"
1417
        )
1418
            .parent()
1419
            .children("span")
1420
            .contains(eholdings_package.extended_attributes[3].value);
1421
1422
        cy.get(
1423
            "#packages_show #additional_fields label[for='additional_field_4']"
1424
        ).contains(eholdings_package_additional_fields[3].name);
1425
        cy.get(
1426
            "#packages_show #additional_fields label[for='additional_field_4']"
1427
        )
1428
            .parent()
1429
            .children("span")
1430
            .contains(
1431
                get_description_from_av_value(
1432
                    av_cats,
1433
                    eholdings_package.extended_attributes[4]
1434
                )
1435
            );
1436
    });
1437
1438
    it("Additional Fields entry - Add (eHoldings packages)", () => {
1439
        let vendors = cy.get_vendors_to_relate();
1440
        let eholdings_package_additional_fields = get_packages_additional_fields();
1441
        let av_cats = get_av_cats();
1442
1443
        //Intercept vendors request
1444
        cy.intercept("GET", "/api/v1/acquisitions/vendors*", {
1445
            statusCode: 200,
1446
            body: vendors,
1447
        });
1448
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1449
            body: [],
1450
            statusCode: 200,
1451
        }).as("empty-additional-fields");
1452
1453
        // No additional fields, fieldset should not exist
1454
        cy.visit("/cgi-bin/koha/erm/eholdings/local/packages/add");
1455
        cy.get("#packages_add form #additional_fields").should("not.exist");
1456
1457
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1458
            body: eholdings_package_additional_fields,
1459
            statusCode: 200,
1460
        }).as("existing-additional-fields");
1461
1462
        cy.intercept(
1463
            {
1464
                pathname: "/api/v1/authorised_value_categories",
1465
                query: {
1466
                    q: '{"me.category_name":["CCODE", "COUNTRY"]}',
1467
                },
1468
            },
1469
            {
1470
                body: av_cats,
1471
                statusCode: 200,
1472
            }
1473
        ).as("avcategories");
1474
        // There are additional fields, fieldset should exist
1475
        cy.visit("/cgi-bin/koha/erm/eholdings/local/packages/add");
1476
        cy.get("#packages_add form #additional_fields").should("exist");
1477
1478
        // All additional fields should be listed
1479
        cy.get(
1480
            "#packages_add form #additional_fields label[for='additional_field_1']"
1481
        ).contains(eholdings_package_additional_fields[0].name);
1482
        cy.get(
1483
            "#packages_add form #additional_fields label[for='additional_field_2']"
1484
        ).contains(eholdings_package_additional_fields[1].name);
1485
        cy.get(
1486
            "#packages_add form #additional_fields label[for='additional_field_3']"
1487
        ).contains(eholdings_package_additional_fields[2].name);
1488
        cy.get(
1489
            "#packages_add form #additional_fields label[for='additional_field_4']"
1490
        ).contains(eholdings_package_additional_fields[3].name);
1491
1492
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1493
            "not.exist"
1494
        ); //new package, no pre-selected value
1495
1496
        // Pick one value
1497
        cy.get("#additional_fields #additional_field_1 .vs__search").click();
1498
        cy.get(
1499
            "#additional_fields #additional_field_1 #vs4__option-0"
1500
        ).contains(av_cats[0].authorised_values[0].description);
1501
        cy.get("#additional_fields #additional_field_1 #vs4__option-0").click();
1502
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1503
            av_cats[0].authorised_values[0].description
1504
        );
1505
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1506
            "have.length",
1507
            1
1508
        );
1509
1510
        // Pick a second value for the same repeatable AV field
1511
        cy.get("#additional_fields #additional_field_1 .vs__search").click();
1512
        cy.get(
1513
            "#additional_fields #additional_field_1 #vs4__option-1"
1514
        ).contains(av_cats[0].authorised_values[1].description);
1515
        cy.get("#additional_fields #additional_field_1 #vs4__option-1").click();
1516
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1517
            av_cats[0].authorised_values[1].description
1518
        );
1519
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1520
            "have.length",
1521
            2
1522
        );
1523
1524
        // Attempt to pick the same value again - should not be possible
1525
        cy.get("#additional_fields #additional_field_1 .vs__search").click();
1526
        cy.get(
1527
            "#additional_fields #additional_field_1 #vs4__option-1"
1528
        ).contains(av_cats[0].authorised_values[1].description);
1529
        cy.get("#additional_fields #additional_field_1 #vs4__option-1").click();
1530
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1531
            "have.length",
1532
            2
1533
        );
1534
1535
        // Remove the second selected value
1536
        cy.get(
1537
            "#additional_fields #additional_field_1 .vs__selected button[title='Deselect " +
1538
                av_cats[0].authorised_values[1].description +
1539
                "'"
1540
        ).click();
1541
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1542
            "have.length",
1543
            1
1544
        );
1545
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1546
            av_cats[0].authorised_values[0].description
1547
        );
1548
    });
1549
1550
    it("Additional Fields entry - Edit (eHoldings packages)", () => {
1551
        let eholdings_package = get_package();
1552
        let eholdings_packages = [eholdings_package];
1553
        let vendors = cy.get_vendors_to_relate();
1554
        let eholdings_package_additional_fields = get_packages_additional_fields();
1555
        let av_cats = get_av_cats();
1556
1557
        // Click the 'Edit' button from the list
1558
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages*", {
1559
            statusCode: 200,
1560
            body: eholdings_packages,
1561
            headers: {
1562
                "X-Base-Total-Count": "1",
1563
                "X-Total-Count": "1",
1564
            },
1565
        });
1566
        cy.intercept("GET", "/api/v1/erm/eholdings/local/packages/*", eholdings_package).as(
1567
            "get-eholdings-package"
1568
        );
1569
1570
        //Intercept vendors request
1571
        cy.intercept("GET", "/api/v1/acquisitions/vendors*", {
1572
            statusCode: 200,
1573
            body: vendors,
1574
        });
1575
1576
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1577
            body: eholdings_package_additional_fields,
1578
            statusCode: 200,
1579
        }).as("existing-additional-fields");
1580
1581
        cy.intercept(
1582
            {
1583
                pathname: "/api/v1/authorised_value_categories",
1584
                query: {
1585
                    q: '{"me.category_name":["CCODE", "COUNTRY"]}',
1586
                },
1587
            },
1588
            {
1589
                body: av_cats,
1590
                statusCode: 200,
1591
            }
1592
        ).as("avcategories");
1593
1594
        cy.visit("/cgi-bin/koha/erm/eholdings/local/packages");
1595
        cy.get("#packages_list table tbody tr:first").contains("Edit").click();
1596
        cy.wait("@get-eholdings-package");
1597
        cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
1598
1599
        // All additional fields should be pre-populated
1600
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1601
            get_description_from_av_value(
1602
                av_cats,
1603
                eholdings_package.extended_attributes[0]
1604
            )
1605
        );
1606
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1607
            get_description_from_av_value(
1608
                av_cats,
1609
                eholdings_package.extended_attributes[1]
1610
            )
1611
        );
1612
1613
        cy.get(
1614
            "#packages_add form #additional_fields label[for='additional_field_2']"
1615
        )
1616
            .parent()
1617
            .children("input")
1618
            .should("have.value", eholdings_package.extended_attributes[2].value);
1619
1620
        cy.get(
1621
            "#packages_add form #additional_fields label[for='additional_field_3']"
1622
        )
1623
            .parent()
1624
            .children("input")
1625
            .should("have.value", eholdings_package.extended_attributes[3].value);
1626
1627
        cy.get("#additional_fields #additional_field_4 .vs__selected").contains(
1628
            get_description_from_av_value(
1629
                av_cats,
1630
                eholdings_package.extended_attributes[4]
1631
            )
1632
        );
1633
1634
        // Clear text field works
1635
        cy.get(
1636
            "#packages_add form #additional_fields label[for='additional_field_2']"
1637
        )
1638
            .parent()
1639
            .children(".clear_attribute")
1640
            .click();
1641
        cy.get(
1642
            "#packages_add form #additional_fields label[for='additional_field_2']"
1643
        )
1644
            .parent()
1645
            .children("input")
1646
            .should("have.value", "");
1647
1648
        // "+New" text field works
1649
        cy.get(
1650
            "#packages_add form #additional_fields label[for='additional_field_3']"
1651
        ).should("have.length", 1);
1652
        cy.get(
1653
            "#packages_add form #additional_fields label[for='additional_field_3']"
1654
        )
1655
            .parent()
1656
            .children(".clone_attribute")
1657
            .click();
1658
        cy.get(
1659
            "#packages_add form #additional_fields label[for='additional_field_3']"
1660
        ).should("have.length", 2);
1661
    });
1662
1127
});
1663
});
1128
- 

Return to bug 37577