<commit_before>var _ = require('underscore')
function maintenanceInputs (label, type) {
  return {
    // this is an input type used to search for a main resource, e.g. Work. The rendered input field
    // will not be tied to a particular subject and predicate
    searchMainResource: {
      label: label,
      indexType: type
    },
    // this is used to control how the search result in the support panel behaves
    widgetOptions: {
      maintenance: true,
      // make it possible to create a work resource if necessary,
      enableCreateNewResource: {
        formRefs: [ {
          formId: 'create-' + type + '-form',
          targetType: type
        } ]
      },
      enableEditResource: {
        formRefs: [ {
          formId: 'create-' + type + '-form',
          targetType: type
        } ]
      },
      enableInPlaceEditing: true
    }
  }
}

module.exports = (app) => {
  app.get('/config', function (request, response) {
    response.setHeader('Cache-Control', 'public, max-age=3600')
    response.setHeader('Expires', new Date(Date.now() + 3600000).toUTCString())
    var config =
    {
      kohaOpacUri: (process.env.KOHA_OPAC_PORT || 'http://192.168.50.12:8080').replace(/^tcp:\//, 'http:/'),
      kohaIntraUri: (process.env.KOHA_INTRA_PORT || 'http://192.168.50.12:8081').replace(/^tcp:\//, 'http:/'),
      ontologyUri: '/services/ontology',
      resourceApiUri: '/services/',
      inputForms: [
        {
          id: 'create-person-form',
          rdfType: 'Person',
          labelForCreateButton: 'Opprett ny person',
          inputs: [
            {
              rdfProperty: 'name',
              displayValueSource: true,
              // after resource is created, the value entered
              // in input marked with this is used to populate displayValue of the parent input
              preFillFromSearchField: true,
              type: 'input-string'
            },
            {
              rdfProperty: 'birthYear',
              prefillFromSuggestion: true
            },
            {
              rdfProperty: 'deathYear'
            },
            {
              rdfProperty: 'nationality',
              multiple: true
            },
            {
              rdfProperty: 'gender'
            },
            {
              rdfProperty: 'specification',
              type: 'input-string-large'
            },
            {
              rdfProperty: 'alternativeName',
              type: 'input-string'
            },
            {
              rdfProperty: 'ordinal',
              type: 'input-string'
            }
          ]
        },
        {
          id: 'create-subject-form',
          labelForCreateButton: 'Opprett nytt generelt emne',
          rdfType: 'Subject',
          inputs: [
            {
              rdfProperty: 'prefLabel',
              displayValueSource: true,
              type: 'input-string',
              // after resource is created, the value entered
              // in input marked with this is used to populate displayValue of the parent input
              preFillFromSearchField: true
            },
            {
              rdfProperty: 'specification',
              type: 'input-string-large'
            }
          ]
        },
        {
          id: 'create-genre-form',
          labelForCreateButton: 'Opprett ny sjanger',
          rdfType: 'Genre',
          inputs: [
            {
              rdfProperty: 'prefLabel',
              displayValueSource: true,
              type: 'input-string',
              // after resource is created, the value entered
              // in input marked with this is used to populate displayValue of the parent input
              preFillFromSearchField: true
            },
            {
              rdfProperty: 'specification',
              type: 'input-string-large'
            }
          ]
        },
        {
          id: 'create-corporation-form',
          labelForCreateButton: 'Opprett ny organisasjon',
          rdfType: 'Corporation',
          inputs: [
            {
              rdfProperty: 'name',
              displayValueSource: true,
              type: 'input-string',
              // after resource is created, the value entered
              // in input marked with this is used to populate displayValue of the parent input
              preFillFromSearchField: true
            },
            {
              rdfProperty: 'subdivision',
              type: 'input-string'
            },
            {
              label: 'Sted',
              rdfProperty: 'place',
              type: 'searchable-authority-dropdown',
              indexTypes: 'place',
              indexDocumentFields: [ 'prefLabel' ]
            },
            {
              label: 'Forklarende tilføyelse',
              rdfProperty: 'specification',
              type: 'input-string'
            }
          ]
        },
        {
          id: 'create-main-work-form',
          prefillFromAcceptedSource: true,
          labelForCreateButton: 'Opprett nytt verk',
          rdfType: 'Work',
          inputs: [
            {
              label: 'Hovedtittel',
              rdfProperty: 'mainTitle',
              type: 'input-string',
              // input type must be defined explicitly, otherwise it will inherit from the search field above
              preFillFromSearchField: true // value of this field should be copied from the search field above
            },
            {
              label: 'Undertittel',
              type: 'input-string',
              rdfProperty: 'subtitle'
            },
            {
              label: 'Deltittel',
              type: 'input-string',
              rdfProperty: 'partTitle'
            },
            {
              label: 'Delnummer',
              type: 'input-string',
              rdfProperty: 'partNumber'
            },
            {
              rdfProperty: 'hasWorkType',
              type: 'hidden-url-query-value',
              widgetOptions: {
                queryParameter: 'hasWorkType',
                prefix: 'http://data.deichman.no/workType#'
              }
            }
          ]
        },
        {
          id: 'create-work-form',
          labelForCreateButton: 'Opprett nytt verk',
          rdfType: 'Work',
          inputs: [
            {
              label: 'Hovedtittel',
              rdfProperty: 'mainTitle',
              type: 'input-string',
              // input type must be defined explicitly, otherwise it will inherit from the search field above
              preFillFromSearchField: true // value of this field should be copied from the search field above
            },
            {
              label: 'Undertittel',
              type: 'input-string', // input type must be defined explicitly, otherwise it will inherit from the search field above
              rdfProperty: 'subtitle'
            },
            {
              label: 'Deltittel',
              type: 'input-string',
              rdfProperty: 'partTitle'
            },
            {
              label: 'Delnummer',
              type: 'input-string',
              rdfProperty: 'partNumber'
            },
            {
              rdfProperty: 'hasWorkType'
            }
          ]
        },
        {
          id: 'create-place-form',
          labelForCreateButton: 'Opprett nytt sted',
          rdfType: 'Place',
          inputs: [
            {
              label: 'Navn',
              rdfProperty: 'prefLabel',
              displayValueSource: true,
              type: 'input-string', // input type must be defined explicitly, otherwise it will inherit from the search field above
              preFillFromSearchField: true // value of this field should be copied from the search field above
            },
            {
              label: 'Forklarende tilføyelse',
              rdfProperty: 'specification',
              type: 'input-string'
              // input type must be defined explicitly, otherwise it will inherit from the search field above
            }
          ]
        },
        {
          id: 'create-event-form',
          labelForCreateButton: 'Opprett ny hendelse',
          rdfType: 'Event',
          inputs: [
            {
              label: 'Navn',
              rdfProperty: 'prefLabel',
              displayValueSource: true,
              type: 'input-string',
              preFillFromSearchField: true // value of this field should be copied from the search field above
            },
            {
              label: 'Sted',
              rdfProperty: 'place',
              type: 'searchable-authority-dropdown',
              indexTypes: 'place',
              indexDocumentFields: [ 'prefLabel' ]
            },
            {
              label: 'Nummer',
              rdfProperty: 'ordinal',
              type: 'input-string'
            },
            {
              label: 'Dato',
              rdfProperty: 'date',
              type: 'input-string'
            },
            {
              label: 'Forklarende tilføyelse',
              rdfProperty: 'specification',
              type: 'input-string'
            }
          ]
        },
        {
          id: 'create-serial-form',
          labelForCreateButton: 'Opprett ny serie',
          rdfType: 'Serial',
          inputs: [
            {
              label: 'Hovedtittel',
              rdfProperty: 'mainTitle',
              type: 'input-string',
              displayValueSource: true,
              preFillFromSearchField: true
            },
            {
              label: 'Undertittel',
              rdfProperty: 'subtitle',
              type: 'input-string'
            },
            {
              label: 'Utgiver',
              rdfProperty: 'publishedBy',
              type: 'searchable-authority-dropdown',
              indexTypes: 'corporation',
              nameProperties: [ 'name', 'subdivision', '(specification)' ],
              indexDocumentFields: [ 'name', 'subdivision', 'specification' ]
            }
          ]
        },
        {
          id: 'create-instrument-form',
          labelForCreateButton: 'Opprett nytt musikkinstrument',
          rdfType: 'Instrument',
          inputs: [
            {
              label: 'Navn',
              rdfProperty: 'prefLabel',
              type: 'input-string',
              preFillFromSearchField: true
            },
            {
              label: 'Forklarende tilføyelse',
              rdfProperty: 'specification',
              type: 'input-string'
            }
          ]
        },
        {
          id: 'create-compositiontype-form',
          labelForCreateButton: 'Opprett ny komposisjonstype',
          rdfType: 'CompositionType',
          inputs: [
            {
              label: 'Navn',
              rdfProperty: 'prefLabel',
              type: 'input-string',
              preFillFromSearchField: true
            },
            {
              label: 'Forklarende tilføyelse',
              rdfProperty: 'specification',
              type: 'input-string'
            }
          ]
        }
      ],
      tabs: [
        {
          id: 'confirm-person',
          rdfType: 'Work',
          label: 'Hovedinnførsel',
          inputs: [
            {
              id: 'isbnInput',
              includeOnlyWhen: {
                hasMediaType: [ 'Book', 'Audiobook', 'SheetMusic', 'ComicBook', 'LanguageCourse', 'E-book' ]
              },
              // this is an input type used to search for a main resource, e.g. Work. The rendered input field
              // will not be tied to a particular subject and predicate
              searchForValueSuggestions: {
                label: 'ISBN',
                pattern: '^[ 0-9\-]+[xX]?\s*$',
                patternMismatchMessage: 'Dette ser ikke ut som et gyldig ISBN-nummer',
                parameterName: 'isbn',
                automationId: 'searchValueSuggestions',
                showOnlyWhenMissingTargetUri: 'Work', // only show this search field if a work has not been loaded or created
                sources: [ 'bibbi' ],
                preferredSource: {
                  id: 'bibbi',
                  name: 'Biblioteksentralen'
                }
              }
            }
            ,
            {
              includeOnlyWhen: {
                hasMediaType: [ 'Film', 'MusicRecording', 'Game' ]
              },
              // this is an input type used to search for a main resource, e.g. Work. The rendered input field
              // will not be tied to a particular subject and predicate
              searchForValueSuggestions: {
                label: 'EAN',
                pattern: '^ *([0-9]{13})?\s*$',
                patternMismatchMessage: 'Dette ser ikke ut som et gyldig EAN-nummer',
                parameterName: 'ean',
                automationId: 'searchEanValueSuggestions',
                showOnlyWhenMissingTargetUri: 'Work', // only show this search field if a work has not been loaded or created
                sources: [ 'bibbi' ],
                preferredSource: {
                  id: 'bibbi',
                  name: 'Biblioteksentralen'
                }
              }
            }
            ,
            {
              label: "Verket har ikke hovedansvarlig",
              id: 'missingMainEntry',
              rdfProperty: 'missingMainEntry',
            },
            {
              label: 'Hovedansvarlig',
              id: 'mainEntryInput',
              reportFormat: {
                list: true
              },
              showOnlyWhen: {
                inputId: 'missingMainEntry',
                valueAsStringMatches: '^false$'
              },
              subInputs: { // input is a group of sub inputs, which are connected to resource as other ends of a blank node
                rdfProperty: 'contributor', // the rdf property of the resource
                range: 'Contribution', // this is the shorthand name of the type of the blank node
                inputs: [ // these are the actual sub inputs
                  {
                    label: 'Aktør',
                    rdfProperty: 'agent',
                    indexTypes: [ 'person', 'corporation' ],
                    type: 'searchable-with-result-in-side-panel',
                    required: true,
                    nameProperties: [ 'name', 'ordinal', 'subdivision', '(specification)', '(birthYear-', 'deathYear)', 'nationality.fragment.' ],
                    previewProperties: [ '(birthYear-', 'deathYear)', 'nationality.fragment.' ],
                    dependentResourceTypes: [ 'Work', 'Publication' ], // when the creator is changed, unload current work and publication
                    id: 'mainEntryPersonInput',
                    widgetOptions: {
                      showSelectItem: true, // show and enable select work radio button
                      enableCreateNewResource: {
                        formRefs: [
                          {
                            formId: 'create-person-form',
                            targetType: 'person'
                          },
                          {
                            formId: 'create-corporation-form',
                            targetType: 'corporation'
                          }
                        ],
                        useAfterCreation: false
                      }
                    },
                    headlinePart: {
                      order: 10
                    }
                  },
                  {
                    label: 'Rolle',
                    rdfProperty: 'role',
                    required: true
                  }
                ]
              },
              isMainEntry: true,
              // blank nodes connected to this input is expected to have type deichman:MainEntry in addition to its own type (range)
              subjects: [ 'Work' ], // blank node can be attached to the the loaded resource of one of these types
              cssClassPrefix: 'additional-entries' // prefix of class names to identify a span surrounding this input or group of sub inputs.
              // actual names are <prefix>-non-editable and <prefix>-editable to enable alternative presentation when not editable
            },
            {
              label: "Skal ikke vises som verk",
              rdfProperty: 'improperWork',
            },
            {
              // this is an input type used to search for a main resource, e.g. Work. The rendered input field
              // will not be tied to a particular subject and predicate
              id: 'searchMainResourceInput',
              isTitleSource: {
                priority: 3,
                qualifier: ' - verk'
              },
              searchMainResource: {
                label: 'Søk etter eksisterende verk',
                indexType: 'work',
                automationId: 'searchWorkAsMainResource',
                showOnlyWhenMissingTargetUri: 'Work' // only show this search field if a work has not been loaded or created
              },
              suggestValueFrom: {
                domain: 'Work',
                predicate: '#mainTitle'
              },
              // this is used to control how the search result in the support panel behaves
              widgetOptions: {
                // make it possible to create a work resource if necessary,
                enableCreateNewResource: {
                  formRefs: [ {
                    formId: 'create-main-work-form',
                    targetType: 'work'
                  } ],
                  useAfterCreation: true
                },
                filter: {
                  inputRef: 'mainEntryPersonInput',
                  name: 'personAsMainEntryFilter'
                }
              }
            }
          ],
          nextStep: {
            showOnlyWhenInputHasValue: 'mediaTypeInput',
            buttonLabel: 'Neste steg: Beskrivelse',
            disabledUnless: {
              presentTargetUri: 'Work',
              inputIsNonEditableWhenNotOverridden: {
                nonEditableInput: 'mainEntryPersonInput',
                overridingInput: 'missingMainEntry'
              },
              disabledTooltip: 'For å komme videre, må du registrere hovedinnførsel og idenfisere eller opprette verk.'
            },
            createNewResource: {
              type: 'Publication',
              prefillValuesFromResource: {
                'Work': [ 'mainTitle', 'subtitle', 'partTitle', 'partNumber' ]
              }
            }
          }
        },
        {
          id: 'describe-publication',
          rdfType: 'Publication',
          label: 'Beskriv utgivelse',
          reportLabel: 'Utgivelse',
          showOnlyWhenInputHasValue: 'mediaTypeInput',
          inputs: [
            {
              rdfProperty: 'mainTitle',
              id: 'publicationMainTitle',
              isTitleSource: {
                priority: 1,
                qualifier: ' - utgivelse'
              },
              headlinePart: {
                order: 20,
                styleClass: 'title'
              }
            },
            {
              rdfProperty: 'subtitle',
              headlinePart: {
                order: 30,
                styleClass: 'title'
              }
            },
            {
              rdfProperty: 'partTitle',
              headlinePart: {
                order: 40,
                styleClass: 'title'
              }
            },
            { rdfProperty: 'partNumber' },
            { rdfProperty: 'edition' },
            {
              rdfProperty: 'publicationYear',
              headlinePart: {
                order: 60,
                prefix: '(',
                postfix: ')'
              }
            },
            {
              includeOnlyWhen: { hasMediaType: [ 'Other', 'Book', 'ComicBook', 'LanguageCourse', 'SheetMusic' ] },
              rdfProperty: 'numberOfPages'
            },
            { includeOnlyWhen: { hasMediaType: [ 'Other', 'Book', 'SheetMusic' ] }, rdfProperty: 'illustrativeMatter', multiple: true },
            {
              includeOnlyWhen: { hasMediaType: [ 'Other', 'Book', 'Audiobook', 'SheetMusic', 'ComicBook', 'LanguageCourse', 'E-book' ] },
              rdfProperty: 'isbn',
              multiple: true,
              addAnotherLabel: 'Legg til nytt ISBN'
            },
            {
              includeOnlyWhen: { hasMediaType: [ 'Other', 'Film', 'MusicRecording', 'Game' ] },
              rdfProperty: 'hasEan'
            },
            {
              includeOnlyWhen: {
                hasMediaType: [ 'Other', 'Book', 'SheetMusic', 'LanguageCourse', 'ComicBook', ]
              },
              rdfProperty: 'binding'
            }
            ,
            {
              rdfProperty: 'language',
              multiple: true
            },
            {
              includeOnlyWhen: {
                hasMediaType: [ 'Film', 'Game' ]
              },
              rdfProperty: 'hasSubtitles',
              multiple: 'true'
            },
            {
              rdfProperty: 'hasMediaType',
              id: 'mediaTypeInput',
              widgetOptions: {
                queryParameter: 'hasMediaType',
                prefix: 'http://data.deichman.no/mediaType#'
              }
            },
            { rdfProperty: 'format', multiple: true },
            {
              includeOnlyWhen: {
                hasMediaType: [ 'Other', 'Film', 'MusicRecording', 'Audiobook', 'LanguageCourse' ]
              },
              rdfProperty: 'duration',
              type: 'input-duration'
            }
            ,
            {
              includeOnlyWhen: {
                hasMediaType: [ 'Other', 'Film', 'Game' ]
              },
              rdfProperty: 'ageLimit',
              widgetOptions: {
                short: true
              }
            },
            {
              includeOnlyWhen: { hasMediaType: [ 'Other', 'Book', 'E-bok', 'ComicBook', 'SheetMusic' ] },
              rdfProperty: 'writingSystem',
              multiple: true
            },
            { rdfProperty: 'hasFormatAdaptation', multiple: true },
            {
              id: 'publishedByInput',
              rdfProperty: 'publishedBy',
              authority: true, // this indicates it is an authorized entity
              nameProperties: [ 'name' ], // these are property names used to label already connected entities
              indexTypes: [ 'corporation', 'person' ], // this is the name of the elasticsearch index type from which authorities are searched within
              preselectFirstIndexType: true,
              indexDocumentFields: [ 'name' ], // these are indexed document JSON properties from which the labels f
              // or authority select list are concatenated
              type: 'searchable-with-result-in-side-panel',
              widgetOptions: {
                selectIndexTypeLegend: 'Velg type aktør',
                enableCreateNewResource: {
                  formRefs: [
                    {
                      formId: 'create-corporation-form',
                      targetType: 'corporation'
                    },
                    {
                      formId: 'create-person-form',
                      targetType: 'person'
                    }
                  ]
                }
              },
              headlinePart: {
                order: 50,
              }
            },
            {
              id: 'hasPlaceOfPublicationInput',
              rdfProperty: 'hasPlaceOfPublication',
              authority: true, // this indicates it is an authorized entity
              nameProperties: [ 'prefLabel', 'specification' ], // these are property names used to label already connected entities
              indexTypes: 'place', // this is the name of the elasticsearch index type from which authorities are searched within
              // the labels for authority select list are concatenated
              type: 'searchable-with-result-in-side-panel',
              widgetOptions: {
                enableCreateNewResource: {
                  formRefs: [ {
                    formId: 'create-place-form',
                    targetType: 'place'
                  } ]
                }
              }
            },
            {
              label: 'Serie',
              multiple: true,
              addAnotherLabel: 'Legg til ny serie',
              subjects: [ 'Publication' ],
              reportFormat: {
                list: true
              },
              subInputs: {
                rdfProperty: 'inSerial',
                range: 'SerialIssue',
                inputs: [
                  {
                    label: 'Serie',
                    required: true,
                    rdfProperty: 'serial',
                    id: 'serialInput',
                    indexTypes: 'serial',
                    nameProperties: [ 'mainTitle', 'subtitle' ],
                    type: 'searchable-with-result-in-side-panel',
                    widgetOptions: {
                      showSelectItem: false, // show and enable select work radio button
                      enableCreateNewResource: {
                        formRefs: [ {
                          formId: 'create-serial-form',
                          targetType: 'serial'
                        } ],
                        useAfterCreation: false
                      }
                    }
                  },
                  {
                    label: 'Nummer i serien',
                    rdfProperty: 'issue'
                  }
                ]
              }
            },
            { rdfProperty: 'locationFormat' },
            { rdfProperty: 'locationClassNumber' },
            { rdfProperty: 'locationSignature' },
            {
              rdfProperty: 'hasDescription',
              type: 'input-string-large'
            },
            {
              rdfProperty: 'publicationOf',
              id: 'publicationOfInput',
              type: 'searchable-with-result-in-side-panel',
              indexTypes: 'work',
              authority: true,
              nameProperties: [ 'mainTitle', 'subtitle' ],
              label: '',
              initiallyHidden: true,
              dependentResourceTypes: [ 'Work' ], // unload work if this is cleared
              widgetOptions: {
                // make it possible to create a work resource if necessary,
                enableCreateNewResource: {
                  formRefs: [ {
                    formId: 'create-work-form',
                    targetType: 'work'
                  } ]
                }
              }
            }
          ],
          nextStep: {
            buttonLabel: 'Neste steg: Beskriv verk',
            showOnlyWhenInputHasValue: 'mediaTypeInput'
          },
          deleteResource: {
            buttonLabel: 'Slett utgivelsen',
            rdfType: 'Publication',
            dialogKeypath: 'deletePublicationDialog',
            dialogId: 'delete-publication-dialog',
            dialogTemplateValues: {
              work: 'workMainTitle',
              title: 'publicationMainTitle',
              creator: 'mainEntryPersonInput'
            },
            afterSuccess: {
              restart: true
            }
          },
          enableSpecialInput: {
            inputId: 'publicationOfInput',
            buttonLabel: 'Endre verk for utgivelse',
            confirmLabel: 'Er du sikker på at du vil endre verksknytningen for denne utgivelsen?',
          }
        },
        {
          id: 'describe-work',
          rdfType: 'Work',
          label: 'Beskriv verk',
          reportLabel: 'Verk',
          inputs: [
            {
              id: 'workMainTitle',
              rdfProperty: 'mainTitle',
              isTitleSource: {
                priority: 2,
                qualifier: ' - verk'
              },
              multiple: true
            },
            { rdfProperty: 'subtitle' },
            { rdfProperty: 'partTitle' },
            { rdfProperty: 'partNumber' },
            { rdfProperty: 'publicationYear' },
            { rdfProperty: 'language', multiple: true },
            {
              rdfProperty: 'hasWorkType',
              id: 'workTypeInput',
              widgetOptions: {
                queryParameter: 'hasWorkType',
                prefix: 'http://data.deichman.no/workType#'
              }
            },
            {
              includeOnlyWhen: { hasWorkType: [ 'Literature', 'Film' ] },
              rdfProperty: 'literaryForm',
              multiple: true,
              headlinePart: {
                order: 45
              }
            },
            {
              includeOnlyWhen: { hasWorkType: [ 'Other', 'Literature', 'Film' ] },
              rdfProperty: 'fictionNonfiction',
            },
            { rdfProperty: 'audience', multiple: true },
            {
              includeOnlyWhen: { hasWorkType: [ 'Other', 'Literature', 'Film' ] },
              rdfProperty: 'biography',
              multiple: true
            },
            { rdfProperty: 'hasContentAdaptation', multiple: true },
            {
              label: 'Relasjon til annet verk',
              multiple: true,
              addAnotherLabel: 'Legg til en relasjon til',
              reportFormat: {
                list: true
              },
              subInputs: {
                rdfProperty: 'isRelatedTo',
                range: 'WorkRelation',
                inputs: [
                  {
                    label: 'Verk',
                    rdfProperty: 'work',
                    id: 'relatedToWorkInput',
                    required: true,
                    indexTypes: [ 'work' ],
                    type: 'searchable-with-result-in-side-panel',
                    nameProperties: [ 'mainTitle' ],
                    widgetOptions: {
                      enableCreateNewResource: {
                        formRefs: [
                          {
                            formId: 'create-work-form',
                            targetType: 'work'
                          }
                        ],
                        useAfterCreation: false
                      }
                    }
                  },
                  {
                    label: 'Type relasjon',<commit_msg>catalinker: add subtitle. part number and part title to displayed properties of related work<commit_after>var _ = require('underscore')
function maintenanceInputs (label, type) {
  return {
    // this is an input type used to search for a main resource, e.g. Work. The rendered input field
    // will not be tied to a particular subject and predicate
    searchMainResource: {
      label: label,
      indexType: type
    },
    // this is used to control how the search result in the support panel behaves
    widgetOptions: {
      maintenance: true,
      // make it possible to create a work resource if necessary,
      enableCreateNewResource: {
        formRefs: [ {
          formId: 'create-' + type + '-form',
          targetType: type
        } ]
      },
      enableEditResource: {
        formRefs: [ {
          formId: 'create-' + type + '-form',
          targetType: type
        } ]
      },
      enableInPlaceEditing: true
    }
  }
}

module.exports = (app) => {
  app.get('/config', function (request, response) {
    response.setHeader('Cache-Control', 'public, max-age=3600')
    response.setHeader('Expires', new Date(Date.now() + 3600000).toUTCString())
    var config =
    {
      kohaOpacUri: (process.env.KOHA_OPAC_PORT || 'http://192.168.50.12:8080').replace(/^tcp:\//, 'http:/'),
      kohaIntraUri: (process.env.KOHA_INTRA_PORT || 'http://192.168.50.12:8081').replace(/^tcp:\//, 'http:/'),
      ontologyUri: '/services/ontology',
      resourceApiUri: '/services/',
      inputForms: [
        {
          id: 'create-person-form',
          rdfType: 'Person',
          labelForCreateButton: 'Opprett ny person',
          inputs: [
            {
              rdfProperty: 'name',
              displayValueSource: true,
              // after resource is created, the value entered
              // in input marked with this is used to populate displayValue of the parent input
              preFillFromSearchField: true,
              type: 'input-string'
            },
            {
              rdfProperty: 'birthYear',
              prefillFromSuggestion: true
            },
            {
              rdfProperty: 'deathYear'
            },
            {
              rdfProperty: 'nationality',
              multiple: true
            },
            {
              rdfProperty: 'gender'
            },
            {
              rdfProperty: 'specification',
              type: 'input-string-large'
            },
            {
              rdfProperty: 'alternativeName',
              type: 'input-string'
            },
            {
              rdfProperty: 'ordinal',
              type: 'input-string'
            }
          ]
        },
        {
          id: 'create-subject-form',
          labelForCreateButton: 'Opprett nytt generelt emne',
          rdfType: 'Subject',
          inputs: [
            {
              rdfProperty: 'prefLabel',
              displayValueSource: true,
              type: 'input-string',
              // after resource is created, the value entered
              // in input marked with this is used to populate displayValue of the parent input
              preFillFromSearchField: true
            },
            {
              rdfProperty: 'specification',
              type: 'input-string-large'
            }
          ]
        },
        {
          id: 'create-genre-form',
          labelForCreateButton: 'Opprett ny sjanger',
          rdfType: 'Genre',
          inputs: [
            {
              rdfProperty: 'prefLabel',
              displayValueSource: true,
              type: 'input-string',
              // after resource is created, the value entered
              // in input marked with this is used to populate displayValue of the parent input
              preFillFromSearchField: true
            },
            {
              rdfProperty: 'specification',
              type: 'input-string-large'
            }
          ]
        },
        {
          id: 'create-corporation-form',
          labelForCreateButton: 'Opprett ny organisasjon',
          rdfType: 'Corporation',
          inputs: [
            {
              rdfProperty: 'name',
              displayValueSource: true,
              type: 'input-string',
              // after resource is created, the value entered
              // in input marked with this is used to populate displayValue of the parent input
              preFillFromSearchField: true
            },
            {
              rdfProperty: 'subdivision',
              type: 'input-string'
            },
            {
              label: 'Sted',
              rdfProperty: 'place',
              type: 'searchable-authority-dropdown',
              indexTypes: 'place',
              indexDocumentFields: [ 'prefLabel' ]
            },
            {
              label: 'Forklarende tilføyelse',
              rdfProperty: 'specification',
              type: 'input-string'
            }
          ]
        },
        {
          id: 'create-main-work-form',
          prefillFromAcceptedSource: true,
          labelForCreateButton: 'Opprett nytt verk',
          rdfType: 'Work',
          inputs: [
            {
              label: 'Hovedtittel',
              rdfProperty: 'mainTitle',
              type: 'input-string',
              // input type must be defined explicitly, otherwise it will inherit from the search field above
              preFillFromSearchField: true // value of this field should be copied from the search field above
            },
            {
              label: 'Undertittel',
              type: 'input-string',
              rdfProperty: 'subtitle'
            },
            {
              label: 'Deltittel',
              type: 'input-string',
              rdfProperty: 'partTitle'
            },
            {
              label: 'Delnummer',
              type: 'input-string',
              rdfProperty: 'partNumber'
            },
            {
              rdfProperty: 'hasWorkType',
              type: 'hidden-url-query-value',
              widgetOptions: {
                queryParameter: 'hasWorkType',
                prefix: 'http://data.deichman.no/workType#'
              }
            }
          ]
        },
        {
          id: 'create-work-form',
          labelForCreateButton: 'Opprett nytt verk',
          rdfType: 'Work',
          inputs: [
            {
              label: 'Hovedtittel',
              rdfProperty: 'mainTitle',
              type: 'input-string',
              // input type must be defined explicitly, otherwise it will inherit from the search field above
              preFillFromSearchField: true // value of this field should be copied from the search field above
            },
            {
              label: 'Undertittel',
              type: 'input-string', // input type must be defined explicitly, otherwise it will inherit from the search field above
              rdfProperty: 'subtitle'
            },
            {
              label: 'Deltittel',
              type: 'input-string',
              rdfProperty: 'partTitle'
            },
            {
              label: 'Delnummer',
              type: 'input-string',
              rdfProperty: 'partNumber'
            },
            {
              rdfProperty: 'hasWorkType'
            }
          ]
        },
        {
          id: 'create-place-form',
          labelForCreateButton: 'Opprett nytt sted',
          rdfType: 'Place',
          inputs: [
            {
              label: 'Navn',
              rdfProperty: 'prefLabel',
              displayValueSource: true,
              type: 'input-string', // input type must be defined explicitly, otherwise it will inherit from the search field above
              preFillFromSearchField: true // value of this field should be copied from the search field above
            },
            {
              label: 'Forklarende tilføyelse',
              rdfProperty: 'specification',
              type: 'input-string'
              // input type must be defined explicitly, otherwise it will inherit from the search field above
            }
          ]
        },
        {
          id: 'create-event-form',
          labelForCreateButton: 'Opprett ny hendelse',
          rdfType: 'Event',
          inputs: [
            {
              label: 'Navn',
              rdfProperty: 'prefLabel',
              displayValueSource: true,
              type: 'input-string',
              preFillFromSearchField: true // value of this field should be copied from the search field above
            },
            {
              label: 'Sted',
              rdfProperty: 'place',
              type: 'searchable-authority-dropdown',
              indexTypes: 'place',
              indexDocumentFields: [ 'prefLabel' ]
            },
            {
              label: 'Nummer',
              rdfProperty: 'ordinal',
              type: 'input-string'
            },
            {
              label: 'Dato',
              rdfProperty: 'date',
              type: 'input-string'
            },
            {
              label: 'Forklarende tilføyelse',
              rdfProperty: 'specification',
              type: 'input-string'
            }
          ]
        },
        {
          id: 'create-serial-form',
          labelForCreateButton: 'Opprett ny serie',
          rdfType: 'Serial',
          inputs: [
            {
              label: 'Hovedtittel',
              rdfProperty: 'mainTitle',
              type: 'input-string',
              displayValueSource: true,
              preFillFromSearchField: true
            },
            {
              label: 'Undertittel',
              rdfProperty: 'subtitle',
              type: 'input-string'
            },
            {
              label: 'Utgiver',
              rdfProperty: 'publishedBy',
              type: 'searchable-authority-dropdown',
              indexTypes: 'corporation',
              nameProperties: [ 'name', 'subdivision', '(specification)' ],
              indexDocumentFields: [ 'name', 'subdivision', 'specification' ]
            }
          ]
        },
        {
          id: 'create-instrument-form',
          labelForCreateButton: 'Opprett nytt musikkinstrument',
          rdfType: 'Instrument',
          inputs: [
            {
              label: 'Navn',
              rdfProperty: 'prefLabel',
              type: 'input-string',
              preFillFromSearchField: true
            },
            {
              label: 'Forklarende tilføyelse',
              rdfProperty: 'specification',
              type: 'input-string'
            }
          ]
        },
        {
          id: 'create-compositiontype-form',
          labelForCreateButton: 'Opprett ny komposisjonstype',
          rdfType: 'CompositionType',
          inputs: [
            {
              label: 'Navn',
              rdfProperty: 'prefLabel',
              type: 'input-string',
              preFillFromSearchField: true
            },
            {
              label: 'Forklarende tilføyelse',
              rdfProperty: 'specification',
              type: 'input-string'
            }
          ]
        }
      ],
      tabs: [
        {
          id: 'confirm-person',
          rdfType: 'Work',
          label: 'Hovedinnførsel',
          inputs: [
            {
              id: 'isbnInput',
              includeOnlyWhen: {
                hasMediaType: [ 'Book', 'Audiobook', 'SheetMusic', 'ComicBook', 'LanguageCourse', 'E-book' ]
              },
              // this is an input type used to search for a main resource, e.g. Work. The rendered input field
              // will not be tied to a particular subject and predicate
              searchForValueSuggestions: {
                label: 'ISBN',
                pattern: '^[ 0-9\-]+[xX]?\s*$',
                patternMismatchMessage: 'Dette ser ikke ut som et gyldig ISBN-nummer',
                parameterName: 'isbn',
                automationId: 'searchValueSuggestions',
                showOnlyWhenMissingTargetUri: 'Work', // only show this search field if a work has not been loaded or created
                sources: [ 'bibbi' ],
                preferredSource: {
                  id: 'bibbi',
                  name: 'Biblioteksentralen'
                }
              }
            }
            ,
            {
              includeOnlyWhen: {
                hasMediaType: [ 'Film', 'MusicRecording', 'Game' ]
              },
              // this is an input type used to search for a main resource, e.g. Work. The rendered input field
              // will not be tied to a particular subject and predicate
              searchForValueSuggestions: {
                label: 'EAN',
                pattern: '^ *([0-9]{13})?\s*$',
                patternMismatchMessage: 'Dette ser ikke ut som et gyldig EAN-nummer',
                parameterName: 'ean',
                automationId: 'searchEanValueSuggestions',
                showOnlyWhenMissingTargetUri: 'Work', // only show this search field if a work has not been loaded or created
                sources: [ 'bibbi' ],
                preferredSource: {
                  id: 'bibbi',
                  name: 'Biblioteksentralen'
                }
              }
            }
            ,
            {
              label: "Verket har ikke hovedansvarlig",
              id: 'missingMainEntry',
              rdfProperty: 'missingMainEntry',
            },
            {
              label: 'Hovedansvarlig',
              id: 'mainEntryInput',
              reportFormat: {
                list: true
              },
              showOnlyWhen: {
                inputId: 'missingMainEntry',
                valueAsStringMatches: '^false$'
              },
              subInputs: { // input is a group of sub inputs, which are connected to resource as other ends of a blank node
                rdfProperty: 'contributor', // the rdf property of the resource
                range: 'Contribution', // this is the shorthand name of the type of the blank node
                inputs: [ // these are the actual sub inputs
                  {
                    label: 'Aktør',
                    rdfProperty: 'agent',
                    indexTypes: [ 'person', 'corporation' ],
                    type: 'searchable-with-result-in-side-panel',
                    required: true,
                    nameProperties: [ 'name', 'ordinal', 'subdivision', '(specification)', '(birthYear-', 'deathYear)', 'nationality.fragment.' ],
                    previewProperties: [ '(birthYear-', 'deathYear)', 'nationality.fragment.' ],
                    dependentResourceTypes: [ 'Work', 'Publication' ], // when the creator is changed, unload current work and publication
                    id: 'mainEntryPersonInput',
                    widgetOptions: {
                      showSelectItem: true, // show and enable select work radio button
                      enableCreateNewResource: {
                        formRefs: [
                          {
                            formId: 'create-person-form',
                            targetType: 'person'
                          },
                          {
                            formId: 'create-corporation-form',
                            targetType: 'corporation'
                          }
                        ],
                        useAfterCreation: false
                      }
                    },
                    headlinePart: {
                      order: 10
                    }
                  },
                  {
                    label: 'Rolle',
                    rdfProperty: 'role',
                    required: true
                  }
                ]
              },
              isMainEntry: true,
              // blank nodes connected to this input is expected to have type deichman:MainEntry in addition to its own type (range)
              subjects: [ 'Work' ], // blank node can be attached to the the loaded resource of one of these types
              cssClassPrefix: 'additional-entries' // prefix of class names to identify a span surrounding this input or group of sub inputs.
              // actual names are <prefix>-non-editable and <prefix>-editable to enable alternative presentation when not editable
            },
            {
              label: "Skal ikke vises som verk",
              rdfProperty: 'improperWork',
            },
            {
              // this is an input type used to search for a main resource, e.g. Work. The rendered input field
              // will not be tied to a particular subject and predicate
              id: 'searchMainResourceInput',
              isTitleSource: {
                priority: 3,
                qualifier: ' - verk'
              },
              searchMainResource: {
                label: 'Søk etter eksisterende verk',
                indexType: 'work',
                automationId: 'searchWorkAsMainResource',
                showOnlyWhenMissingTargetUri: 'Work' // only show this search field if a work has not been loaded or created
              },
              suggestValueFrom: {
                domain: 'Work',
                predicate: '#mainTitle'
              },
              // this is used to control how the search result in the support panel behaves
              widgetOptions: {
                // make it possible to create a work resource if necessary,
                enableCreateNewResource: {
                  formRefs: [ {
                    formId: 'create-main-work-form',
                    targetType: 'work'
                  } ],
                  useAfterCreation: true
                },
                filter: {
                  inputRef: 'mainEntryPersonInput',
                  name: 'personAsMainEntryFilter'
                }
              }
            }
          ],
          nextStep: {
            showOnlyWhenInputHasValue: 'mediaTypeInput',
            buttonLabel: 'Neste steg: Beskrivelse',
            disabledUnless: {
              presentTargetUri: 'Work',
              inputIsNonEditableWhenNotOverridden: {
                nonEditableInput: 'mainEntryPersonInput',
                overridingInput: 'missingMainEntry'
              },
              disabledTooltip: 'For å komme videre, må du registrere hovedinnførsel og idenfisere eller opprette verk.'
            },
            createNewResource: {
              type: 'Publication',
              prefillValuesFromResource: {
                'Work': [ 'mainTitle', 'subtitle', 'partTitle', 'partNumber' ]
              }
            }
          }
        },
        {
          id: 'describe-publication',
          rdfType: 'Publication',
          label: 'Beskriv utgivelse',
          reportLabel: 'Utgivelse',
          showOnlyWhenInputHasValue: 'mediaTypeInput',
          inputs: [
            {
              rdfProperty: 'mainTitle',
              id: 'publicationMainTitle',
              isTitleSource: {
                priority: 1,
                qualifier: ' - utgivelse'
              },
              headlinePart: {
                order: 20,
                styleClass: 'title'
              }
            },
            {
              rdfProperty: 'subtitle',
              headlinePart: {
                order: 30,
                styleClass: 'title'
              }
            },
            {
              rdfProperty: 'partTitle',
              headlinePart: {
                order: 40,
                styleClass: 'title'
              }
            },
            { rdfProperty: 'partNumber' },
            { rdfProperty: 'edition' },
            {
              rdfProperty: 'publicationYear',
              headlinePart: {
                order: 60,
                prefix: '(',
                postfix: ')'
              }
            },
            {
              includeOnlyWhen: { hasMediaType: [ 'Other', 'Book', 'ComicBook', 'LanguageCourse', 'SheetMusic' ] },
              rdfProperty: 'numberOfPages'
            },
            { includeOnlyWhen: { hasMediaType: [ 'Other', 'Book', 'SheetMusic' ] }, rdfProperty: 'illustrativeMatter', multiple: true },
            {
              includeOnlyWhen: { hasMediaType: [ 'Other', 'Book', 'Audiobook', 'SheetMusic', 'ComicBook', 'LanguageCourse', 'E-book' ] },
              rdfProperty: 'isbn',
              multiple: true,
              addAnotherLabel: 'Legg til nytt ISBN'
            },
            {
              includeOnlyWhen: { hasMediaType: [ 'Other', 'Film', 'MusicRecording', 'Game' ] },
              rdfProperty: 'hasEan'
            },
            {
              includeOnlyWhen: {
                hasMediaType: [ 'Other', 'Book', 'SheetMusic', 'LanguageCourse', 'ComicBook', ]
              },
              rdfProperty: 'binding'
            }
            ,
            {
              rdfProperty: 'language',
              multiple: true
            },
            {
              includeOnlyWhen: {
                hasMediaType: [ 'Film', 'Game' ]
              },
              rdfProperty: 'hasSubtitles',
              multiple: 'true'
            },
            {
              rdfProperty: 'hasMediaType',
              id: 'mediaTypeInput',
              widgetOptions: {
                queryParameter: 'hasMediaType',
                prefix: 'http://data.deichman.no/mediaType#'
              }
            },
            { rdfProperty: 'format', multiple: true },
            {
              includeOnlyWhen: {
                hasMediaType: [ 'Other', 'Film', 'MusicRecording', 'Audiobook', 'LanguageCourse' ]
              },
              rdfProperty: 'duration',
              type: 'input-duration'
            }
            ,
            {
              includeOnlyWhen: {
                hasMediaType: [ 'Other', 'Film', 'Game' ]
              },
              rdfProperty: 'ageLimit',
              widgetOptions: {
                short: true
              }
            },
            {
              includeOnlyWhen: { hasMediaType: [ 'Other', 'Book', 'E-bok', 'ComicBook', 'SheetMusic' ] },
              rdfProperty: 'writingSystem',
              multiple: true
            },
            { rdfProperty: 'hasFormatAdaptation', multiple: true },
            {
              id: 'publishedByInput',
              rdfProperty: 'publishedBy',
              authority: true, // this indicates it is an authorized entity
              nameProperties: [ 'name' ], // these are property names used to label already connected entities
              indexTypes: [ 'corporation', 'person' ], // this is the name of the elasticsearch index type from which authorities are searched within
              preselectFirstIndexType: true,
              indexDocumentFields: [ 'name' ], // these are indexed document JSON properties from which the labels f
              // or authority select list are concatenated
              type: 'searchable-with-result-in-side-panel',
              widgetOptions: {
                selectIndexTypeLegend: 'Velg type aktør',
                enableCreateNewResource: {
                  formRefs: [
                    {
                      formId: 'create-corporation-form',
                      targetType: 'corporation'
                    },
                    {
                      formId: 'create-person-form',
                      targetType: 'person'
                    }
                  ]
                }
              },
              headlinePart: {
                order: 50,
              }
            },
            {
              id: 'hasPlaceOfPublicationInput',
              rdfProperty: 'hasPlaceOfPublication',
              authority: true, // this indicates it is an authorized entity
              nameProperties: [ 'prefLabel', 'specification' ], // these are property names used to label already connected entities
              indexTypes: 'place', // this is the name of the elasticsearch index type from which authorities are searched within
              // the labels for authority select list are concatenated
              type: 'searchable-with-result-in-side-panel',
              widgetOptions: {
                enableCreateNewResource: {
                  formRefs: [ {
                    formId: 'create-place-form',
                    targetType: 'place'
                  } ]
                }
              }
            },
            {
              label: 'Serie',
              multiple: true,
              addAnotherLabel: 'Legg til ny serie',
              subjects: [ 'Publication' ],
              reportFormat: {
                list: true
              },
              subInputs: {
                rdfProperty: 'inSerial',
                range: 'SerialIssue',
                inputs: [
                  {
                    label: 'Serie',
                    required: true,
                    rdfProperty: 'serial',
                    id: 'serialInput',
                    indexTypes: 'serial',
                    nameProperties: [ 'mainTitle', 'subtitle' ],
                    type: 'searchable-with-result-in-side-panel',
                    widgetOptions: {
                      showSelectItem: false, // show and enable select work radio button
                      enableCreateNewResource: {
                        formRefs: [ {
                          formId: 'create-serial-form',
                          targetType: 'serial'
                        } ],
                        useAfterCreation: false
                      }
                    }
                  },
                  {
                    label: 'Nummer i serien',
                    rdfProperty: 'issue'
                  }
                ]
              }
            },
            { rdfProperty: 'locationFormat' },
            { rdfProperty: 'locationClassNumber' },
            { rdfProperty: 'locationSignature' },
            {
              rdfProperty: 'hasDescription',
              type: 'input-string-large'
            },
            {
              rdfProperty: 'publicationOf',
              id: 'publicationOfInput',
              type: 'searchable-with-result-in-side-panel',
              indexTypes: 'work',
              authority: true,
              nameProperties: [ 'mainTitle', 'subtitle' ],
              label: '',
              initiallyHidden: true,
              dependentResourceTypes: [ 'Work' ], // unload work if this is cleared
              widgetOptions: {
                // make it possible to create a work resource if necessary,
                enableCreateNewResource: {
                  formRefs: [ {
                    formId: 'create-work-form',
                    targetType: 'work'
                  } ]
                }
              }
            }
          ],
          nextStep: {
            buttonLabel: 'Neste steg: Beskriv verk',
            showOnlyWhenInputHasValue: 'mediaTypeInput'
          },
          deleteResource: {
            buttonLabel: 'Slett utgivelsen',
            rdfType: 'Publication',
            dialogKeypath: 'deletePublicationDialog',
            dialogId: 'delete-publication-dialog',
            dialogTemplateValues: {
              work: 'workMainTitle',
              title: 'publicationMainTitle',
              creator: 'mainEntryPersonInput'
            },
            afterSuccess: {
              restart: true
            }
          },
          enableSpecialInput: {
            inputId: 'publicationOfInput',
            buttonLabel: 'Endre verk for utgivelse',
            confirmLabel: 'Er du sikker på at du vil endre verksknytningen for denne utgivelsen?',
          }
        },
        {
          id: 'describe-work',
          rdfType: 'Work',
          label: 'Beskriv verk',
          reportLabel: 'Verk',
          inputs: [
            {
              id: 'workMainTitle',
              rdfProperty: 'mainTitle',
              isTitleSource: {
                priority: 2,
                qualifier: ' - verk'
              },
              multiple: true
            },
            { rdfProperty: 'subtitle' },
            { rdfProperty: 'partTitle' },
            { rdfProperty: 'partNumber' },
            { rdfProperty: 'publicationYear' },
            { rdfProperty: 'language', multiple: true },
            {
              rdfProperty: 'hasWorkType',
              id: 'workTypeInput',
              widgetOptions: {
                queryParameter: 'hasWorkType',
                prefix: 'http://data.deichman.no/workType#'
              }
            },
            {
              includeOnlyWhen: { hasWorkType: [ 'Literature', 'Film' ] },
              rdfProperty: 'literaryForm',
              multiple: true,
              headlinePart: {
                order: 45
              }
            },
            {
              includeOnlyWhen: { hasWorkType: [ 'Other', 'Literature', 'Film' ] },
              rdfProperty: 'fictionNonfiction',
            },
            { rdfProperty: 'audience', multiple: true },
            {
              includeOnlyWhen: { hasWorkType: [ 'Other', 'Literature', 'Film' ] },
              rdfProperty: 'biography',
              multiple: true
            },
            { rdfProperty: 'hasContentAdaptation', multiple: true },
            {
              label: 'Relasjon til annet verk',
              multiple: true,
              addAnotherLabel: 'Legg til en relasjon til',
              reportFormat: {
                list: true
              },
              subInputs: {
                rdfProperty: 'isRelatedTo',
                range: 'WorkRelation',
                inputs: [
                  {
                    label: 'Verk',
                    rdfProperty: 'work',
                    id: 'relatedToWorkInput',
                    required: true,
                    indexTypes: [ 'work' ],
                    type: 'searchable-with-result-in-side-panel',
                    nameProperties: [ 'mainTitle', 'subtitle', 'partNumber', 'partTitle' ],
                    widgetOptions: {
                      enableCreateNewResource: {
                        formRefs: [
                          {
                            formId: 'create-work-form',
                            targetType: 'work'
                          }
                        ],
                        useAfterCreation: false
                      }
                    }
                  },
                  {
                    label: 'Type relasjon',
{'fraction_non_alphanumeric': 0.09363853529238522, 'fraction_numerical': 0.0020288622009882523, 'mean_word_length': 1.1674941485211716, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1203449', 'n_tokens_mistral': 15080, 'n_tokens_neox': 14487, 'n_words': 3615}