UNPKG

@boligmappa/web-component-search

Version:

Web component for interacting with the Boligmappa APIs

127 lines 5.25 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { LitElement, html, css } from "lit"; import { property } from "lit/decorators.js"; import TableType from "../helpers/enums/table-type"; import "./tables/addresses-table"; import "./tables/buildings-table"; import "./tables/overview-table"; import "./tables/streets-table"; import "./tables/properties-table"; import "./tables/projects-table"; import SearchType from "../helpers/enums/search-type"; import "./tables/empty-table"; export class ResultsTable extends LitElement { constructor() { super(); this.tableData = {}; this.streetPageSize = -1; this.searchText = ""; this.isLoadingMoreData = false; } getKeyFromTableType() { switch (this.tableData.tableType) { case TableType.Streets: return "streetListData"; case TableType.Addresses: return "addressListData"; case TableType.Buildings: return "buildingListData"; case TableType.Properties: return "propertyListData"; default: return null; } } checkIfTableIsEmpty() { const tableDataKey = this.getKeyFromTableType(); const data = tableDataKey && this.tableData[tableDataKey]; const dataAsArray = data && Array.isArray(data) ? data : Array(data); if (tableDataKey === "propertyListData") { const buildingData = this.tableData["buildingListData"]; const buildingDataAsArray = buildingData && Array.isArray(buildingData) ? buildingData : Array(buildingData); return dataAsArray.length + buildingDataAsArray.length === 0; } return dataAsArray.length === 0; } renderChosenTable() { const tableIsEmpty = this.checkIfTableIsEmpty(); if (tableIsEmpty) return html `<empty-table></empty-table>`; switch (this.tableData.tableType) { case TableType.Overview: return html ` <overview-table .overviewData=${this.tableData} .streetPageSize=${this.streetPageSize} .languageObject=${this.languageObject} ></overview-table>`; case 2: if (this.tableData.searchType === SearchType.Streets) { return html ` <streets-table .streetsData=${this.tableData.streetListData} .isLoadingMoreData=${this.isLoadingMoreData} ></streets-table>`; } if (this.tableData.searchType === SearchType.Projects) { return html ` <projects-table .projectsData=${this.tableData.projectListData} .languageObject=${this.languageObject} ></projects-table>`; } return html `<p>failed</p>`; case TableType.Addresses: return html ` <addresses-table .addressesData=${this.tableData.addressListData} .searchText=${this.searchText} .isLoadingMoreData=${this.isLoadingMoreData} ></addresses-table>`; case TableType.Buildings: return html ` <buildings-table .buildingsData=${this.tableData.buildingListData} .isLoadingMoreData=${this.isLoadingMoreData} .languageObject=${this.languageObject} ></buildings-table>`; case TableType.Properties: return html ` <properties-table .languageObject=${this.languageObject} .building=${this.tableData.selectedBuilding} .selectedAddress=${this.tableData.selectedAddress} .propertiesData=${this.tableData.propertyListData} .isLoadingMoreData=${this.isLoadingMoreData} ></properties-table>`; default: return html ``; } } render() { return this.renderChosenTable(); } } ResultsTable.styles = css ``; __decorate([ property() ], ResultsTable.prototype, "isLoadingMoreData", void 0); __decorate([ property({ hasChanged(newVal, oldVal) { return JSON.stringify(newVal) !== JSON.stringify(oldVal); }, }) ], ResultsTable.prototype, "tableData", void 0); __decorate([ property() ], ResultsTable.prototype, "streetPageSize", void 0); __decorate([ property() ], ResultsTable.prototype, "searchText", void 0); __decorate([ property() ], ResultsTable.prototype, "languageObject", void 0); customElements.define("results-table", ResultsTable); //# sourceMappingURL=results-table.js.map