Source: media/data/OverviewData.js

import { GridData } from "./GridData.js";
import { GalleryWFSService } from "./input.js";
import { GalleryMappingScheme, DataRequestProcessing } from "./utils.js";
export { OverviewData }

/**
 * Class representing a data overview.
 */
class OverviewData extends GridData {
    /**
     * Create an data overview.
     * @param {Object} configuration - Object from the GalleryConfigLoader.
     * @param {Array} dataKeyList - Key names of data that should be loaded. 
     */
    constructor(configuration, dataKeyList) {
        const serviceConfigDict = configuration.serviceConfigDict;
        const galleryConfigDict = configuration.galleryConfigDict;

        super(galleryConfigDict);
        this.dataKeyList = dataKeyList;
        this.serviceConfigDict = serviceConfigDict;
    }

    /**
     * Data service initialization.
     * @returns Promise
     */
    initDataService() {
        return super.initDataService(this.serviceConfigDict)
            .then(() => {
                this.dataKeyListMapped = GalleryMappingScheme.findPropertyKeyInMapping(this.galleryConfigDict, this.dataKeyList);
            })
    }

    /**
     * Get number of data items.
     * @returns Promise
     */
    getDataQuantity() {
        return this.initDataService().then(() => {
            return this.getItemsQuantity().then((number) => {
                this.dataItemsQuantity = number;
            })
        })
    }

    /**
     * Get the data items.
     * @returns Promise
     */
    getData() {
        return this.initDataService().then(() => {

            const serviceType = this.adapter.dataService instanceof GalleryWFSService ? 'wfs' : null;
            if (serviceType == 'wfs' && this.dataKeyListMapped.includes('coordinates')) {
                this.dataKeyListMapped = this.dataKeyListMapped.map(item => item == 'coordinates' ? 'geometry' : item);
            }
            if (this.dataKeyListMapped.length != 0)
                return this.loadItems(undefined, undefined, { 'PROPERTYNAME': this.dataKeyListMapped.join(',') })
            else {
                // No request, but include override constants.
                this.dataItemsHarmonized = DataRequestProcessing.harmonizeData([{}], this.galleryConfigDict);
                return Promise.resolve()
            }
        })
    }
}