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

(-)a/Koha/AdditionalField.pm (+1 lines)
Lines 60-65 sub to_api { Link Here
60
        'aqbasket'            => 'basket',
60
        'aqbasket'            => 'basket',
61
        'aqinvoices'          => 'invoice',
61
        'aqinvoices'          => 'invoice',
62
        'erm_licenses'        => 'license',
62
        'erm_licenses'        => 'license',
63
        'erm_agreements'      => 'agreement',
63
        'aqorders'            => 'order',
64
        'aqorders'            => 'order',
64
    };
65
    };
65
66
(-)a/Koha/ERM/Agreement.pm (-1 / +1 lines)
Lines 25-31 use Koha::DateUtils qw( dt_from_string ); Link Here
25
use Koha::Exceptions;
25
use Koha::Exceptions;
26
use Koha::Acquisition::Bookseller;
26
use Koha::Acquisition::Bookseller;
27
27
28
use base qw(Koha::Object);
28
use base qw(Koha::Object::Mixin::AdditionalFields Koha::Object);
29
29
30
use Koha::ERM::Agreement::Periods;
30
use Koha::ERM::Agreement::Periods;
31
use Koha::ERM::Agreement::Licenses;
31
use Koha::ERM::Agreement::Licenses;
(-)a/Koha/ERM/Agreements.pm (-1 / +1 lines)
Lines 24-30 use Koha::DateUtils qw( dt_from_string ); Link Here
24
use Koha::ERM::Agreement;
24
use Koha::ERM::Agreement;
25
use Koha::ERM::Agreement::Periods;
25
use Koha::ERM::Agreement::Periods;
26
26
27
use base qw(Koha::Objects);
27
use base qw(Koha::Objects::Mixin::AdditionalFields Koha::Objects);
28
28
29
=head1 NAME
29
=head1 NAME
30
30
(-)a/Koha/REST/V1/ERM/Agreements.pm (+8 lines)
Lines 97-102 sub add { Link Here
97
                my $agreement_licenses = delete $body->{agreement_licenses} // [];
97
                my $agreement_licenses = delete $body->{agreement_licenses} // [];
98
                my $agreement_relationships = delete $body->{agreement_relationships} // [];
98
                my $agreement_relationships = delete $body->{agreement_relationships} // [];
99
                my $documents = delete $body->{documents} // [];
99
                my $documents = delete $body->{documents} // [];
100
                my $extended_attributes = delete $body->{extended_attributes} // [];
100
101
101
                my $agreement = Koha::ERM::Agreement->new_from_api($body)->store;
102
                my $agreement = Koha::ERM::Agreement->new_from_api($body)->store;
102
                $agreement->periods($periods);
103
                $agreement->periods($periods);
Lines 105-110 sub add { Link Here
105
                $agreement->agreement_relationships($agreement_relationships);
106
                $agreement->agreement_relationships($agreement_relationships);
106
                $agreement->documents($documents);
107
                $agreement->documents($documents);
107
108
109
                my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
110
                $agreement->extended_attributes( \@extended_attributes );
111
108
                $c->res->headers->location($c->req->url->to_string . '/' . $agreement->agreement_id);
112
                $c->res->headers->location($c->req->url->to_string . '/' . $agreement->agreement_id);
109
                return $c->render(
113
                return $c->render(
110
                    status  => 201,
114
                    status  => 201,
Lines 181-186 sub update { Link Here
181
                my $agreement_licenses = delete $body->{agreement_licenses} // [];
185
                my $agreement_licenses = delete $body->{agreement_licenses} // [];
182
                my $agreement_relationships = delete $body->{agreement_relationships} // [];
186
                my $agreement_relationships = delete $body->{agreement_relationships} // [];
183
                my $documents = delete $body->{documents} // [];
187
                my $documents = delete $body->{documents} // [];
188
                my $extended_attributes = delete $body->{extended_attributes} // [];
184
189
185
                $agreement->set_from_api($body)->store;
190
                $agreement->set_from_api($body)->store;
186
                $agreement->periods($periods);
191
                $agreement->periods($periods);
Lines 189-194 sub update { Link Here
189
                $agreement->agreement_relationships($agreement_relationships);
194
                $agreement->agreement_relationships($agreement_relationships);
190
                $agreement->documents($documents);
195
                $agreement->documents($documents);
191
196
197
                my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
198
                $agreement->extended_attributes( \@extended_attributes );
199
192
                $c->res->headers->location($c->req->url->to_string . '/' . $agreement->agreement_id);
200
                $c->res->headers->location($c->req->url->to_string . '/' . $agreement->agreement_id);
193
                return $c->render(
201
                return $c->render(
194
                    status  => 200,
202
                    status  => 200,
(-)a/Koha/REST/V1/ExtendedAttributeTypes.pm (-6 / +7 lines)
Lines 46-57 sub list { Link Here
46
46
47
    # FIXME: Maybe not the best place for this mapping
47
    # FIXME: Maybe not the best place for this mapping
48
    my $resource_to_table = {
48
    my $resource_to_table = {
49
        basket  => 'aqbasket',
49
        basket    => 'aqbasket',
50
        credit  => 'accountlines:credit',
50
        credit    => 'accountlines:credit',
51
        debit   => 'accountlines:debit',
51
        debit     => 'accountlines:debit',
52
        invoice => 'aqinvoices',
52
        invoice   => 'aqinvoices',
53
        license => 'erm_licenses',
53
        license   => 'erm_licenses',
54
        order   => 'aqorders',
54
        agreement => 'erm_agreements',
55
        order     => 'aqorders',
55
    };
56
    };
56
57
57
    return try {
58
    return try {
(-)a/Koha/Schema/Result/ErmAgreement.pm (+32 lines)
Lines 281-286 __PACKAGE__->add_columns( Link Here
281
    '+is_perpetual' => { is_boolean => 1 }
281
    '+is_perpetual' => { is_boolean => 1 }
282
);
282
);
283
283
284
__PACKAGE__->has_many(
285
    "additional_field_values",
286
    "Koha::Schema::Result::AdditionalFieldValue",
287
    sub {
288
        my ($args) = @_;
289
290
        return {
291
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.agreement_id" },
292
293
            "$args->{foreign_alias}.field_id" =>
294
                { -in => \'(SELECT id FROM additional_fields WHERE tablename="erm_agreements")' },
295
        };
296
    },
297
    { cascade_copy => 0, cascade_delete => 0 },
298
);
299
300
__PACKAGE__->has_many(
301
    "extended_attributes",
302
    "Koha::Schema::Result::AdditionalFieldValue",
303
    sub {
304
        my ($args) = @_;
305
306
        return {
307
            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.agreement_id" },
308
309
            "$args->{foreign_alias}.field_id" =>
310
                { -in => \'(SELECT id FROM additional_fields WHERE tablename="erm_agreement")' },
311
        };
312
    },
313
    { cascade_copy => 0, cascade_delete => 0 },
314
);
315
284
sub koha_object_class {
316
sub koha_object_class {
285
    'Koha::ERM::Agreement';
317
    'Koha::ERM::Agreement';
286
}
318
}
(-)a/api/v1/swagger/definitions/erm_agreement.yaml (+10 lines)
Lines 69-74 properties: Link Here
69
    type:
69
    type:
70
      - object
70
      - object
71
      - "null"
71
      - "null"
72
  extended_attributes:
73
    description: Related additional field values
74
    type:
75
      - array
76
    items:
77
      $ref: extended_attribute_value.yaml
78
  _strings:
79
    type:
80
      - object
81
      - "null"
72
82
73
additionalProperties: false
83
additionalProperties: false
74
required:
84
required:
(-)a/api/v1/swagger/paths/erm_agreements.yaml (+6 lines)
Lines 69-74 Link Here
69
          enum:
69
          enum:
70
            - user_roles
70
            - user_roles
71
            - vendor
71
            - vendor
72
            - extended_attributes
73
            - +strings
72
        collectionFormat: csv
74
        collectionFormat: csv
73
      - $ref: "../swagger.yaml#/parameters/match"
75
      - $ref: "../swagger.yaml#/parameters/match"
74
      - $ref: "../swagger.yaml#/parameters/order_by"
76
      - $ref: "../swagger.yaml#/parameters/order_by"
Lines 198-203 Link Here
198
            - agreement_packages.package
200
            - agreement_packages.package
199
            - documents
201
            - documents
200
            - vendor
202
            - vendor
203
            - extended_attributes
204
            - +strings
201
        collectionFormat: csv
205
        collectionFormat: csv
202
    responses:
206
    responses:
203
      200:
207
      200:
Lines 265-270 Link Here
265
            - agreement_licenses
269
            - agreement_licenses
266
            - agreement_relationships
270
            - agreement_relationships
267
            - documents
271
            - documents
272
            - extended_attributes
273
            - +strings
268
        collectionFormat: csv
274
        collectionFormat: csv
269
    responses:
275
    responses:
270
      200:
276
      200:
(-)a/api/v1/swagger/paths/extended_attribute_types.yaml (+1 lines)
Lines 19-24 Link Here
19
          - debit
19
          - debit
20
          - invoice
20
          - invoice
21
          - license
21
          - license
22
          - agreement
22
          - order
23
          - order
23
          - subscription
24
          - subscription
24
      - $ref: "../swagger.yaml#/parameters/match"
25
      - $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'] %]
26
[% searchable_tables = ['subscription', 'aqbasket', 'aqinvoices', 'erm_licenses', 'erm_agreements'] %]
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 137-142 Link Here
137
                [% END %]
137
                [% END %]
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
                [% END %]
141
                [% END %]
141
            </ul>
142
            </ul>
142
            [% ELSE %]
143
            [% ELSE %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue (+12 lines)
Lines 132-137 Link Here
132
                        </li>
132
                        </li>
133
                    </ol>
133
                    </ol>
134
                </fieldset>
134
                </fieldset>
135
                <AdditionalFieldsEntry
136
                    resource_type="agreement"
137
                    :additional_field_values="agreement.extended_attributes"
138
                    @additional-fields-changed="additionalFieldsChanged"
139
                />
135
                <AgreementPeriods :periods="agreement.periods" />
140
                <AgreementPeriods :periods="agreement.periods" />
136
                <UserRoles
141
                <UserRoles
137
                    :user_type="$__('Agreement user %s')"
142
                    :user_type="$__('Agreement user %s')"
Lines 174-179 import UserRoles from "./UserRoles.vue" Link Here
174
import AgreementLicenses from "./AgreementLicenses.vue"
179
import AgreementLicenses from "./AgreementLicenses.vue"
175
import AgreementRelationships from "./AgreementRelationships.vue"
180
import AgreementRelationships from "./AgreementRelationships.vue"
176
import Documents from "./Documents.vue"
181
import Documents from "./Documents.vue"
182
import AdditionalFieldsEntry from "../AdditionalFieldsEntry.vue"
177
import ButtonSubmit from "../ButtonSubmit.vue"
183
import ButtonSubmit from "../ButtonSubmit.vue"
178
import FormSelectVendors from "../FormSelectVendors.vue"
184
import FormSelectVendors from "../FormSelectVendors.vue"
179
import { setMessage, setError, setWarning } from "../../messages"
185
import { setMessage, setError, setWarning } from "../../messages"
Lines 221-226 export default { Link Here
221
                agreement_licenses: [],
227
                agreement_licenses: [],
222
                agreement_relationships: [],
228
                agreement_relationships: [],
223
                documents: [],
229
                documents: [],
230
                extended_attributes: [],
224
            },
231
            },
225
            initialized: false,
232
            initialized: false,
226
        }
233
        }
Lines 329-334 export default { Link Here
329
336
330
            delete agreement.agreement_id
337
            delete agreement.agreement_id
331
            delete agreement.vendor
338
            delete agreement.vendor
339
            delete agreement._strings
332
            agreement.is_perpetual = agreement.is_perpetual ? true : false
340
            agreement.is_perpetual = agreement.is_perpetual ? true : false
333
341
334
            if (agreement.vendor_id == "") {
342
            if (agreement.vendor_id == "") {
Lines 388-393 export default { Link Here
388
                this.agreement.closure_reason = ""
396
                this.agreement.closure_reason = ""
389
            }
397
            }
390
        },
398
        },
399
        additionalFieldsChanged(additionalFieldValues) {
400
            this.agreement.extended_attributes = additionalFieldValues
401
        },
391
    },
402
    },
392
    components: {
403
    components: {
393
        AgreementPeriods,
404
        AgreementPeriods,
Lines 397-402 export default { Link Here
397
        Documents,
408
        Documents,
398
        ButtonSubmit,
409
        ButtonSubmit,
399
        FormSelectVendors,
410
        FormSelectVendors,
411
        AdditionalFieldsEntry,
400
    },
412
    },
401
    name: "AgreementsFormAdd",
413
    name: "AgreementsFormAdd",
402
}
414
}
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue (-2 / +49 lines)
Lines 43-48 Link Here
43
            <KohaTable
43
            <KohaTable
44
                ref="table"
44
                ref="table"
45
                v-bind="tableOptions"
45
                v-bind="tableOptions"
46
                :searchable_additional_fields="searchable_additional_fields"
47
                :searchable_av_options="searchable_av_options"
46
                @show="doShow"
48
                @show="doShow"
47
                @edit="doEdit"
49
                @edit="doEdit"
48
                @delete="doDelete"
50
                @delete="doDelete"
Lines 109-117 export default { Link Here
109
            fp_config: flatpickr_defaults,
111
            fp_config: flatpickr_defaults,
110
            agreement_count: 0,
112
            agreement_count: 0,
111
            initialized: false,
113
            initialized: false,
114
            searchable_additional_fields: [],
115
            searchable_av_options: [],
112
            tableOptions: {
116
            tableOptions: {
113
                columns: this.getTableColumns(),
117
                columns: this.getTableColumns(),
114
                options: { embed: "user_roles,vendor" },
118
                options: { embed: "user_roles,vendor,extended_attributes,+strings" },
115
                url: () => this.table_url(),
119
                url: () => this.table_url(),
116
                table_settings: this.agreement_table_settings,
120
                table_settings: this.agreement_table_settings,
117
                add_filters: true,
121
                add_filters: true,
Lines 161-167 export default { Link Here
161
    },
165
    },
162
    beforeRouteEnter(to, from, next) {
166
    beforeRouteEnter(to, from, next) {
163
        next(vm => {
167
        next(vm => {
164
            vm.getAgreementCount().then(() => (vm.initialized = true))
168
            vm.getAgreementCount().then(() =>
169
                vm
170
                    .getSearchableAdditionalFields()
171
                    .then(() =>
172
                        vm
173
                            .getSearchableAVOptions()
174
                            .then(() => (vm.initialized = true))
175
                    )
176
            )
165
        })
177
        })
166
    },
178
    },
167
    methods: {
179
    methods: {
Lines 173-178 export default { Link Here
173
                },
185
                },
174
                error => {}
186
                error => {}
175
            )
187
            )
188
        },
189
	    async getSearchableAdditionalFields() {
190
            const client = APIClient.additional_fields
191
            await client.additional_fields.getAll("agreement").then(
192
                searchable_additional_fields => {
193
                    this.searchable_additional_fields =
194
                        searchable_additional_fields.filter(
195
                            field => field.searchable
196
                        )
197
                },
198
                error => {}
199
            )
200
        },
201
        async getSearchableAVOptions() {
202
            const client_av = APIClient.authorised_values
203
            let av_cat_array = this.searchable_additional_fields
204
                .filter(field => field.authorised_value_category_name)
205
                .map(field => field.authorised_value_category_name)
206
207
            await client_av.values
208
                .getCategoriesWithValues([
209
                    ...new Set(av_cat_array.map(av_cat => '"' + av_cat + '"')),
210
                ]) // unique
211
                .then(av_categories => {
212
                    av_cat_array.forEach(av_cat => {
213
                        let av_match = av_categories.find(
214
                            element => element.category_name == av_cat
215
                        )
216
                        this.searchable_av_options[av_cat] =
217
                            av_match.authorised_values.map(av => ({
218
                                value: av.value,
219
                                label: av.description,
220
                            }))
221
                    })
222
                })
176
        },
223
        },
177
        doShow: function ({ agreement_id }, dt, event) {
224
        doShow: function ({ agreement_id }, dt, event) {
178
            event.preventDefault()
225
            event.preventDefault()
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue (-1 / +10 lines)
Lines 322-327 Link Here
322
                    </li>
322
                    </li>
323
                </ol>
323
                </ol>
324
            </fieldset>
324
            </fieldset>
325
            <AdditionalFieldsDisplay
326
                resource_type="agreement"
327
                :additional_field_values="
328
                    agreement._strings.additional_field_values
329
                "
330
            />
325
            <fieldset class="action">
331
            <fieldset class="action">
326
                <router-link
332
                <router-link
327
                    :to="{ name: 'AgreementsList' }"
333
                    :to="{ name: 'AgreementsList' }"
Lines 339-344 import { inject } from "vue" Link Here
339
import { APIClient } from "../../fetch/api-client.js"
345
import { APIClient } from "../../fetch/api-client.js"
340
import Toolbar from "../Toolbar.vue"
346
import Toolbar from "../Toolbar.vue"
341
import ToolbarButton from "../ToolbarButton.vue"
347
import ToolbarButton from "../ToolbarButton.vue"
348
import AdditionalFieldsDisplay from "../AdditionalFieldsDisplay.vue"
342
349
343
export default {
350
export default {
344
    setup() {
351
    setup() {
Lines 373-378 export default { Link Here
373
                license_info: "",
380
                license_info: "",
374
                periods: [],
381
                periods: [],
375
                user_roles: [],
382
                user_roles: [],
383
                extended_attributes: [],
384
                _strings: [],
376
                agreement_packages: [],
385
                agreement_packages: [],
377
            },
386
            },
378
            initialized: false,
387
            initialized: false,
Lines 425-431 export default { Link Here
425
            )
434
            )
426
        },
435
        },
427
    },
436
    },
428
    components: { Toolbar, ToolbarButton },
437
    components: { Toolbar, ToolbarButton, AdditionalFieldsDisplay },
429
    name: "AgreementsShow",
438
    name: "AgreementsShow",
430
}
439
}
431
</script>
440
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js (-1 / +1 lines)
Lines 23-29 export class ERMAPIClient extends HttpClient { Link Here
23
                    endpoint: "agreements/" + id,
23
                    endpoint: "agreements/" + id,
24
                    headers: {
24
                    headers: {
25
                        "x-koha-embed":
25
                        "x-koha-embed":
26
                            "periods,user_roles,user_roles.patron,agreement_licenses,agreement_licenses.license,agreement_relationships,agreement_relationships.related_agreement,documents,agreement_packages,agreement_packages.package,vendor",
26
                            "periods,user_roles,user_roles.patron,agreement_licenses,agreement_licenses.license,agreement_relationships,agreement_relationships.related_agreement,documents,agreement_packages,agreement_packages.package,vendor,extended_attributes,+strings",
27
                    },
27
                    },
28
                }),
28
                }),
29
            getAll: (query, params) =>
29
            getAll: (query, params) =>
(-)a/t/cypress/integration/AdditionalFields_spec.ts (-1 / +568 lines)
Lines 168-173 function get_licenses_additional_fields() { Link Here
168
    ];
168
    ];
169
}
169
}
170
170
171
function get_no_additional_fields_agreement() {
172
    return {
173
        agreement_id: 1,
174
        name: "agreement 1",
175
        description: "my first agreement",
176
        agreement_licenses: [],
177
        agreement_packages: [],
178
        agreement_relationships: [],
179
        closure_reason: "",
180
        is_perpetual: false,
181
        license_info: "",
182
        periods: [],
183
        renewal_priority: "",
184
        status: "active",
185
        user_roles: [],
186
        vendor_id: 1,
187
        vendor: [cy.get_vendors_to_relate()[0]],
188
        documents: [
189
            {
190
                agreement_id: 1,
191
                file_description: "file description",
192
                file_name: "file.json",
193
                notes: "file notes",
194
                physical_location: "file physical location",
195
                uri: "file uri",
196
                uploaded_on: "2022-10-27T11:57:02+00:00",
197
            },
198
        ],
199
        extended_attributes: [],
200
        _strings: {
201
            "additional_field_values": []
202
        },
203
    };
204
}
205
function get_agreement() {
206
    return {
207
        agreement_id: 1,
208
        name: "agreement 1",
209
        description: "my first agreement",
210
        agreement_licenses: [],
211
        agreement_packages: [],
212
        agreement_relationships: [],
213
        closure_reason: "",
214
        is_perpetual: false,
215
        license_info: "",
216
        periods: [],
217
        renewal_priority: "",
218
        status: "active",
219
        user_roles: [],
220
        vendor_id: 1,
221
        vendor: [cy.get_vendors_to_relate()[0]],
222
        documents: [
223
            {
224
                agreement_id: 1,
225
                file_description: "file description",
226
                file_name: "file.json",
227
                notes: "file notes",
228
                physical_location: "file physical location",
229
                uri: "file uri",
230
                uploaded_on: "2022-10-27T11:57:02+00:00",
231
            },
232
        ],
233
        extended_attributes: [
234
            {
235
                field_id: 1,
236
                id: "1",
237
                record_id: "1",
238
                value: "REF",
239
            },
240
            {
241
                field_id: 1,
242
                id: "2",
243
                record_id: "1",
244
                value: "NFIC",
245
            },
246
            {
247
                field_id: 2,
248
                id: "3",
249
                record_id: "1",
250
                value: "some text",
251
            },
252
            {
253
                field_id: 3,
254
                id: "4",
255
                record_id: "1",
256
                value: "some repeatable text",
257
            },
258
            {
259
                field_id: 4,
260
                id: "5",
261
                record_id: "1",
262
                value: "AF",
263
            },
264
        ],
265
        _strings: {
266
            additional_field_values: [
267
                {
268
                    field_id: 1,
269
                    field_label: "AV Repeatable",
270
                    type: "av",
271
                    value_str: "Reference, Non-fiction",
272
                },
273
                {
274
                    field_id: 2,
275
                    field_label: "Text non-repeatable",
276
                    type: "text",
277
                    value_str: "some text",
278
                },
279
                {
280
                    field_id: 3,
281
                    field_label: "Text repeatable",
282
                    type: "text",
283
                    value_str: "some repeatable text",
284
                },
285
                {
286
                    field_id: 4,
287
                    field_label: "AV Searchable",
288
                    type: "av",
289
                    value_str: "Afghanistan",
290
                },
291
            ],
292
        },
293
    };
294
}
295
296
function get_agreements_additional_fields() {
297
    return [
298
        {
299
            authorised_value_category_name: "CCODE",
300
            extended_attribute_type_id: 1,
301
            marcfield: "",
302
            marcfield_mode: "get",
303
            name: "AV Repeatable",
304
            repeatable: true,
305
            searchable: true,
306
            resource_type: "agreement",
307
        },
308
        {
309
            authorised_value_category_name: null,
310
            extended_attribute_type_id: 2,
311
            marcfield: "",
312
            marcfield_mode: "get",
313
            name: "Text non-repeatable",
314
            repeatable: false,
315
            searchable: false,
316
            resource_type: "agreement",
317
        },
318
        {
319
            authorised_value_category_name: null,
320
            extended_attribute_type_id: 3,
321
            marcfield: "",
322
            marcfield_mode: "get",
323
            name: "Text repeatable",
324
            repeatable: true,
325
            searchable: false,
326
            resource_type: "agreement",
327
        },
328
        {
329
            authorised_value_category_name: "COUNTRY",
330
            extended_attribute_type_id: 4,
331
            marcfield: "",
332
            marcfield_mode: "get",
333
            name: "AV Searchable",
334
            repeatable: false,
335
            searchable: true,
336
            resource_type: "agreement",
337
        },
338
    ];
339
}
340
171
function get_av_cats() {
341
function get_av_cats() {
172
    return [
342
    return [
173
        {
343
        {
Lines 252-257 describe("Additional Fields operations", () => { Link Here
252
        );
422
        );
253
    });
423
    });
254
424
425
    //
426
    // for licenses
427
    //
428
255
    it("Additional Fields display - Table (licenses)", () => {
429
    it("Additional Fields display - Table (licenses)", () => {
256
        let license = get_license();
430
        let license = get_license();
257
        let licenses = [license];
431
        let licenses = [license];
Lines 640-643 describe("Additional Fields operations", () => { Link Here
640
            "#licenses_add form #additional_fields label[for='additional_field_3']"
814
            "#licenses_add form #additional_fields label[for='additional_field_3']"
641
        ).should("have.length", 2);
815
        ).should("have.length", 2);
642
    });
816
    });
817
818
    //
819
    // for agreements
820
    //
821
822
    it("Additional Fields display - Table (agreements)", () => {
823
        let agreement = get_agreement();
824
        let agreements = [agreement];
825
        let agreement_additional_fields = get_agreements_additional_fields();
826
        let av_cats = get_av_cats();
827
828
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
829
            body: agreement_additional_fields,
830
            statusCode: 200,
831
        });
832
833
        cy.intercept("GET", "/api/v1/erm/agreements*", {
834
            statusCode: 200,
835
            body: agreements,
836
            headers: {
837
                "X-Base-Total-Count": "1",
838
                "X-Total-Count": "1",
839
            },
840
        });
841
        cy.intercept("GET", "/api/v1/erm/agreements/*", agreement);
842
        cy.visit("/cgi-bin/koha/erm/agreements");
843
        cy.get("#agreements_list").contains("Showing 1 to 1 of 1 entries");
844
845
        cy.get("#agreements_list table tbody tr:first").contains(
846
            get_description_from_av_value(
847
                av_cats,
848
                agreement.extended_attributes[4]
849
            )
850
        );
851
        cy.get("#agreements_list table tbody tr:first").contains(
852
            get_description_from_av_value(
853
                av_cats,
854
                agreement.extended_attributes[0]
855
            ) +
856
                ", " +
857
                get_description_from_av_value(
858
                    av_cats,
859
                    agreement.extended_attributes[1]
860
                )
861
        );
862
    });
863
864
    it("Additional Fields display - Show (agreements)", () => {
865
        let empty_agreement = get_no_additional_fields_agreement();
866
        let agreement = get_agreement();
867
        let agreements = [agreement];
868
        let vendors = cy.get_vendors_to_relate();
869
        let agreement_additional_fields = get_agreements_additional_fields();
870
        let av_cats = get_av_cats();
871
872
        // Click the 'Edit' button from the list
873
        cy.intercept("GET", "/api/v1/erm/agreements*", {
874
            statusCode: 200,
875
            body: agreements,
876
            headers: {
877
                "X-Base-Total-Count": "1",
878
                "X-Total-Count": "1",
879
            },
880
        });
881
        cy.intercept("GET", "/api/v1/erm/agreements/*", empty_agreement).as(
882
            "get-empty-agreement"
883
        );
884
885
        //Intercept vendors request
886
        cy.intercept("GET", "/api/v1/acquisitions/vendors*", {
887
            statusCode: 200,
888
            body: vendors,
889
        });
890
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
891
            body: [],
892
            statusCode: 200,
893
        }).as("empty-additional-fields");
894
895
        //Empty additional fields, should not display
896
        cy.visit("/cgi-bin/koha/erm/agreements");
897
        cy.get("#agreements_list table tbody tr:first td:first a").click();
898
        cy.wait("@get-empty-agreement");
899
        cy.get("#agreements_show #additional_fields").should("not.exist");
900
901
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
902
            body: agreement_additional_fields,
903
            statusCode: 200,
904
        }).as("existing-additional-fields");
905
906
        cy.intercept(
907
            {
908
                pathname: "/api/v1/authorised_value_categories",
909
                query: {
910
                    q: '{"me.category_name":["CCODE", "COUNTRY"]}',
911
                },
912
            },
913
            {
914
                body: av_cats,
915
                statusCode: 200,
916
            }
917
        ).as("avcategories");
918
919
        cy.intercept("GET", "/api/v1/erm/agreements/*", agreement).as(
920
            "get-agreement"
921
        );
922
923
        // There are additional fields, fieldset should exist
924
        cy.visit("/cgi-bin/koha/erm/agreements");
925
        cy.get("#agreements_list table tbody tr:first td:first a").click();
926
        cy.wait("@get-agreement");
927
        cy.get("#agreements_show #additional_fields").should("exist");
928
929
        // All fields are presented correctly
930
        cy.get(
931
            "#agreements_show #additional_fields label[for='additional_field_1']"
932
        ).contains(agreement_additional_fields[0].name);
933
        cy.get(
934
            "#agreements_show #additional_fields label[for='additional_field_1']"
935
        )
936
            .parent()
937
            .children("span")
938
            .contains(
939
                get_description_from_av_value(
940
                    av_cats,
941
                    agreement.extended_attributes[0]
942
                ) +
943
                    ", " +
944
                    get_description_from_av_value(
945
                        av_cats,
946
                        agreement.extended_attributes[1]
947
                    )
948
            );
949
950
        cy.get(
951
            "#agreements_show #additional_fields label[for='additional_field_2']"
952
        ).contains(agreement_additional_fields[1].name);
953
        cy.get(
954
            "#agreements_show #additional_fields label[for='additional_field_2']"
955
        )
956
            .parent()
957
            .children("span")
958
            .contains(agreement.extended_attributes[2].value);
959
960
        cy.get(
961
            "#agreements_show #additional_fields label[for='additional_field_3']"
962
        ).contains(agreement_additional_fields[2].name);
963
        cy.get(
964
            "#agreements_show #additional_fields label[for='additional_field_3']"
965
        )
966
            .parent()
967
            .children("span")
968
            .contains(agreement.extended_attributes[3].value);
969
970
        cy.get(
971
            "#agreements_show #additional_fields label[for='additional_field_4']"
972
        ).contains(agreement_additional_fields[3].name);
973
        cy.get(
974
            "#agreements_show #additional_fields label[for='additional_field_4']"
975
        )
976
            .parent()
977
            .children("span")
978
            .contains(
979
                get_description_from_av_value(
980
                    av_cats,
981
                    agreement.extended_attributes[4]
982
                )
983
            );
984
    });
985
986
    it("Additional Fields entry - Add (agreements)", () => {
987
        let vendors = cy.get_vendors_to_relate();
988
        let agreement_additional_fields = get_licenses_additional_fields();
989
        let av_cats = get_av_cats();
990
991
        //Intercept vendors request
992
        cy.intercept("GET", "/api/v1/acquisitions/vendors*", {
993
            statusCode: 200,
994
            body: vendors,
995
        });
996
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
997
            body: [],
998
            statusCode: 200,
999
        }).as("empty-additional-fields");
1000
1001
        // No additional fields, fieldset should not exist
1002
        cy.visit("/cgi-bin/koha/erm/agreements/add");
1003
        cy.get("#agreements_add form #additional_fields").should("not.exist");
1004
1005
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1006
            body: agreement_additional_fields,
1007
            statusCode: 200,
1008
        }).as("existing-additional-fields");
1009
1010
        cy.intercept(
1011
            {
1012
                pathname: "/api/v1/authorised_value_categories",
1013
                query: {
1014
                    q: '{"me.category_name":["CCODE", "COUNTRY"]}',
1015
                },
1016
            },
1017
            {
1018
                body: av_cats,
1019
                statusCode: 200,
1020
            }
1021
        ).as("avcategories");
1022
        // There are additional fields, fieldset should exist
1023
        cy.visit("/cgi-bin/koha/erm/agreements/add");
1024
        cy.get("#agreements_add form #additional_fields").should("exist");
1025
1026
        // All additional fields should be listed
1027
        cy.get(
1028
            "#agreements_add form #additional_fields label[for='additional_field_1']"
1029
        ).contains(agreement_additional_fields[0].name);
1030
        cy.get(
1031
            "#agreements_add form #additional_fields label[for='additional_field_2']"
1032
        ).contains(agreement_additional_fields[1].name);
1033
        cy.get(
1034
            "#agreements_add form #additional_fields label[for='additional_field_3']"
1035
        ).contains(agreement_additional_fields[2].name);
1036
        cy.get(
1037
            "#agreements_add form #additional_fields label[for='additional_field_4']"
1038
        ).contains(agreement_additional_fields[3].name);
1039
1040
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1041
            "not.exist"
1042
        ); //new agreement, no pre-selected value
1043
1044
        // Pick one value
1045
        cy.get("#additional_fields #additional_field_1 .vs__search").click();
1046
        cy.get(
1047
            "#additional_fields #additional_field_1 #vs5__option-0"
1048
        ).contains(av_cats[0].authorised_values[0].description);
1049
        cy.get("#additional_fields #additional_field_1 #vs5__option-0").click();
1050
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1051
            av_cats[0].authorised_values[0].description
1052
        );
1053
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1054
            "have.length",
1055
            1
1056
        );
1057
1058
        // Pick a second value for the same repeatable AV field
1059
        cy.get("#additional_fields #additional_field_1 .vs__search").click();
1060
        cy.get(
1061
            "#additional_fields #additional_field_1 #vs5__option-1"
1062
        ).contains(av_cats[0].authorised_values[1].description);
1063
        cy.get("#additional_fields #additional_field_1 #vs5__option-1").click();
1064
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1065
            av_cats[0].authorised_values[1].description
1066
        );
1067
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1068
            "have.length",
1069
            2
1070
        );
1071
1072
        // Attempt to pick the same value again - should not be possible
1073
        cy.get("#additional_fields #additional_field_1 .vs__search").click();
1074
        cy.get(
1075
            "#additional_fields #additional_field_1 #vs5__option-1"
1076
        ).contains(av_cats[0].authorised_values[1].description);
1077
        cy.get("#additional_fields #additional_field_1 #vs5__option-1").click();
1078
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1079
            "have.length",
1080
            2
1081
        );
1082
1083
        // Remove the second selected value
1084
        cy.get(
1085
            "#additional_fields #additional_field_1 .vs__selected button[title='Deselect " +
1086
                av_cats[0].authorised_values[1].description +
1087
                "'"
1088
        ).click();
1089
        cy.get("#additional_fields #additional_field_1 .vs__selected").should(
1090
            "have.length",
1091
            1
1092
        );
1093
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1094
            av_cats[0].authorised_values[0].description
1095
        );
1096
    });
1097
1098
    it("Additional Fields entry - Edit (agreements)", () => {
1099
        let agreement = get_agreement();
1100
        let agreements = [agreement];
1101
        let vendors = cy.get_vendors_to_relate();
1102
        let agreement_additional_fields = get_agreements_additional_fields();
1103
        let av_cats = get_av_cats();
1104
1105
        // Click the 'Edit' button from the list
1106
        cy.intercept("GET", "/api/v1/erm/agreements*", {
1107
            statusCode: 200,
1108
            body: agreements,
1109
            headers: {
1110
                "X-Base-Total-Count": "1",
1111
                "X-Total-Count": "1",
1112
            },
1113
        });
1114
        cy.intercept("GET", "/api/v1/erm/agreements/*", agreement).as(
1115
            "get-agreement"
1116
        );
1117
1118
        //Intercept vendors request
1119
        cy.intercept("GET", "/api/v1/acquisitions/vendors*", {
1120
            statusCode: 200,
1121
            body: vendors,
1122
        });
1123
1124
        cy.intercept("GET", "/api/v1/extended_attribute_types*", {
1125
            body: agreement_additional_fields,
1126
            statusCode: 200,
1127
        }).as("existing-additional-fields");
1128
1129
        cy.intercept(
1130
            {
1131
                pathname: "/api/v1/authorised_value_categories",
1132
                query: {
1133
                    q: '{"me.category_name":["CCODE", "COUNTRY"]}',
1134
                },
1135
            },
1136
            {
1137
                body: av_cats,
1138
                statusCode: 200,
1139
            }
1140
        ).as("avcategories");
1141
1142
        cy.visit("/cgi-bin/koha/erm/agreements");
1143
        cy.get("#agreements_list table tbody tr:first").contains("Edit").click();
1144
        cy.wait("@get-agreement");
1145
        cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet!
1146
1147
        // All additional fields should be pre-populated
1148
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1149
            get_description_from_av_value(
1150
                av_cats,
1151
                agreement.extended_attributes[0]
1152
            )
1153
        );
1154
        cy.get("#additional_fields #additional_field_1 .vs__selected").contains(
1155
            get_description_from_av_value(
1156
                av_cats,
1157
                agreement.extended_attributes[1]
1158
            )
1159
        );
1160
1161
        cy.get(
1162
            "#agreements_add form #additional_fields label[for='additional_field_2']"
1163
        )
1164
            .parent()
1165
            .children("input")
1166
            .should("have.value", agreement.extended_attributes[2].value);
1167
1168
        cy.get(
1169
            "#agreements_add form #additional_fields label[for='additional_field_3']"
1170
        )
1171
            .parent()
1172
            .children("input")
1173
            .should("have.value", agreement.extended_attributes[3].value);
1174
1175
        cy.get("#additional_fields #additional_field_4 .vs__selected").contains(
1176
            get_description_from_av_value(
1177
                av_cats,
1178
                agreement.extended_attributes[4]
1179
            )
1180
        );
1181
1182
        // Clear text field works
1183
        cy.get(
1184
            "#agreements_add form #additional_fields label[for='additional_field_2']"
1185
        )
1186
            .parent()
1187
            .children(".clear_attribute")
1188
            .click();
1189
        cy.get(
1190
            "#agreements_add form #additional_fields label[for='additional_field_2']"
1191
        )
1192
            .parent()
1193
            .children("input")
1194
            .should("have.value", "");
1195
1196
        // "+New" text field works
1197
        cy.get(
1198
            "#agreements_add form #additional_fields label[for='additional_field_3']"
1199
        ).should("have.length", 1);
1200
        cy.get(
1201
            "#agreements_add form #additional_fields label[for='additional_field_3']"
1202
        )
1203
            .parent()
1204
            .children(".clone_attribute")
1205
            .click();
1206
        cy.get(
1207
            "#agreements_add form #additional_fields label[for='additional_field_3']"
1208
        ).should("have.length", 2);
1209
    });
1210
643
});
1211
});
644
- 

Return to bug 37576