{"version":3,"sources":["https://lively-kernel.org/lively4/BP2019RH1/components/bp2019-select-widget.js"],"names":["Morph","assertListenerInterface","AtomicFilterAction","FilterAction","SelectAction","SelectWidget","initialize","name","get","checked","onFilterAppliedListeners","valuesByAttribute","attributeSelect","valueSelect","addEventListener","_setFilterValues","_getSelectedFilterAttribute","combinationLogicSelect","_changeCombinationLogicToSelectedValue","combinationTexts","forEach","text","options","length","Option","filterHistoryContainer","addToHistoryButton","_addFilterToHistory","_createFilterFromCurrentSelection","selectAction","dataProcessor","colorStore","isGlobal","setIncludeStop","setDataProcessor","setColorStore","addListener","listener","push","initializeWithData","data","Object","keys","includes","_setValuesByAttributes","deleteFilterListItem","filterListItem","removeChild","removeFilter","getFilter","setRemovedFilters","setAddedFilters","_applyFilterHistory","loadState","state","innerHTML","getValuesByAttribute","i","getAllFilters","filterElement","lively","create","setFilter","appendChild","valuesByAttributes","_setFilterAttributes","attributes","_clearSelectOptions","string","values","selectedIndex","value","_getSelectedFilterValues","selectedValues","availableOptionsCount","option","selected","select","remove","_getCombinationLogic","selectedCombination","setCombinationLogic","newFilter","filterValues","addFilter","notify","applyAction","currentFilterAttribute","currentFilterValues","_isGlobal"],"mappings":";;;;;;;;;AAAOA,W;;AACEC,6B,qDAAAA,uB;;AACAC,wB,kDAAAA,kB;AAAoBC,kB,kDAAAA,Y;AAAcC,kB,kDAAAA,Y;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE5B,YAAMC,YAAN,SAA2BL,KAA3B,CAAiC;AAC9C,cAAMM,UAAN,GAAmB;AACjB,eAAKC,IAAL,GAAY,QAAZ;AACA,eAAKC,GAAL,CAAS,YAAT,EAAuBC,OAAvB,GAAiC,IAAjC;AACA,eAAKC,wBAAL,GAAgC,EAAhC;AACA,eAAKC,iBAAL,GAAyB,EAAzB;;AAEA,eAAKC,eAAL,GAAuB,KAAKJ,GAAL,CAAS,mBAAT,CAAvB;A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AEDjC,8BAAsB;AACpB,eAAK1C,wBAAL,CAA8BU,OAA9B,CAAsCiB,YAAY;AAChDA,qBAASiD,WAAT,CAAqB,KAAKzD,YAA1B;AACD,WAFD;AAGD;;AAEDD,4CAAoC;AAClC,cAAI2D,yBAAyB,KAAKvE,2BAAL,EAA7B;AACA,cAAIwE,sBAAsB,KAAKhB,wBAAL,EAA1B;;AAEA,iBAAO,IAAItE,kBAAJ,CAAuBqF,sBAAvB,EAA+CC,mBAA/C,EAAoE,KAAK1D,aAAzE,EAAwF,KAAK2D,SAAL,EAAxF,CAAP;AACD;;AAEDA,oBAAY;AACV,iBAAO,KAAKjF,GAAL,CAAS,YAAT,EAAuBC,OAA9B;AACD;;AA3L6C;;yBAA3BJ,Y","file":"bp2019-select-widget.js","sourcesContent":["import Morph from 'src/components/widgets/lively-morph.js'\nimport { assertListenerInterface } from '../src/internal/individuals-as-points/common/interfaces.js'\nimport { AtomicFilterAction, FilterAction, SelectAction } from '../src/internal/individuals-as-points/common/actions.js'\n\nexport default class SelectWidget extends Morph {\n  async initialize() {\n    this.name = \"select\";\n    this.get('#is-global').checked = true\n    this.onFilterAppliedListeners = []\n    this.valuesByAttribute = {}\n    \n    this.attributeSelect = this.get(\"#attribute-select\")\n    this.valueSelect = this.get(\"#value-select\")\n    \n    this.attributeSelect.addEventListener(\"change\", () => {\n      this._setFilterValues(this.valuesByAttribute[this._getSelectedFilterAttribute()])\n    })\n    \n    this.combinationLogicSelect = this.get(\"#combination-logic-select\")\n    this.combinationLogicSelect.addEventListener(\"change\", () => {\n      this._changeCombinationLogicToSelectedValue()\n    })\n    \n    let combinationTexts = [\"logic and\", \"logic or\"]\n    combinationTexts.forEach(text => {\n      this.combinationLogicSelect.options[this.combinationLogicSelect.options.length] = new Option(text)\n    })\n    \n    this.filterHistoryContainer = this.get(\"#select-history-container\")\n    \n    this.addToHistoryButton = this.get(\"#add-select-button\")\n    \n    this.addToHistoryButton.addEventListener(\"click\", async () => await this._addFilterToHistory(this._createFilterFromCurrentSelection()))\n    this.selectAction = new SelectAction(new FilterAction(), this.dataProcessor, this.colorStore, this.isGlobal)\n    this.selectAction.setIncludeStop(true)\n    \n  }\n  \n  /*\n  Expects the folowing format for valuesByAttributes:\n  {\n    <attribute 1>: [<value 1>, <value 2>, ...],\n    <attribute 2>: [<value 1>, <value 2>, ...],\n    ...\n  }\n  */\n  \n  // ------------------------------------------\n  // Public Methods\n  // ------------------------------------------\n  \n  setDataProcessor(dataProcessor) {\n    this.dataProcessor = dataProcessor\n    this.selectAction.dataProcessor = dataProcessor\n  }\n  \n  setColorStore(colorStore) {\n    this.colorStore = colorStore\n    this.selectAction.colorStore = this.colorStore\n  }\n  \n  addListener(listener) {\n    assertListenerInterface(listener)\n    this.onFilterAppliedListeners.push(listener)\n  }\n  \n  initializeWithData(data){\n    if (Object.keys(data).includes(\"consent_withdrawn\")) {\n      delete data[\"consent_withdrawn\"]\n    }\n    this._setValuesByAttributes(data);\n  }\n  \n  deleteFilterListItem(filterListItem) {\n    this.filterHistoryContainer.removeChild(filterListItem)\n    this.selectAction.removeFilter(filterListItem.getFilter())\n    this.selectAction.setRemovedFilters([filterListItem.getFilter()])\n    this.selectAction.setAddedFilters([])\n    this._applyFilterHistory()\n  }\n  \n  async loadState(state) {\n    // remove everything\n    this.filterHistoryContainer.innerHTML = \"\"\n    \n    this._setValuesByAttributes(state.dataProcessor.getValuesByAttribute())\n    \n    // load stuff from state\n    this.selectAction = state.selectAction\n    \n    for (let i=0; i < this.selectAction.getAllFilters().length; i++) {\n      let filterElement = await lively.create(\"bp2019-filter-list-element\")\n      filterElement.setFilter(this.selectAction.getAllFilters()[i])\n      filterElement.addListener(this)\n\n      this.filterHistoryContainer.appendChild(filterElement)\n    }\n  }\n  \n  // ------------------------------------------\n  // Private Methods\n  // ------------------------------------------\n\n  _setValuesByAttributes(valuesByAttributes) {\n    this.valuesByAttribute = valuesByAttributes\n    \n    this._setFilterAttributes(Object.keys(valuesByAttributes))\n    this._setFilterValues(this.valuesByAttribute[this._getSelectedFilterAttribute()])\n  }\n  \n  _setFilterAttributes(attributes) {\n    this._clearSelectOptions(this.attributeSelect)\n    attributes.forEach(string => {\n      this.attributeSelect.options[this.attributeSelect.options.length] = new Option(string)\n    })\n  }\n  \n  _setFilterValues(values) {\n    this._clearSelectOptions(this.valueSelect)\n    values.forEach(string => {\n      this.valueSelect.options[this.valueSelect.options.length] = new Option(string)\n    })\n  }\n  \n  _getSelectedFilterAttribute() {\n    return this.attributeSelect.options[this.attributeSelect.selectedIndex].value;\n  }\n  \n  _getSelectedFilterValues() {\n    let selectedValues = [];\n    let availableOptionsCount = this.valueSelect.options.length;\n    \n    for(let i = 0; i < availableOptionsCount; i++){\n      let option = this.valueSelect.options[i];\n      if(option.selected){\n        selectedValues.push(option.value);\n      }\n    }\n      \n    return selectedValues;\n  }\n  \n  _clearSelectOptions(select) {\n    while(select.options.length > 0) {\n      select.options.remove(0)\n    }\n  }\n  \n  _getCombinationLogic() {\n    return this.combinationLogicSelect.options[this.combinationLogicSelect.selectedIndex].value\n  }\n  \n  _changeCombinationLogicToSelectedValue() {\n    let selectedCombination = this._getCombinationLogic()\n    this.selectAction.setCombinationLogic(selectedCombination)\n    this._applyFilterHistory()\n  }\n  \n  async _addFilterToHistory(newFilter) {\n    if (newFilter.filterValues.length > 0) {\n      this.selectAction.addFilter(newFilter)\n      this.selectAction.setAddedFilters([newFilter])\n      this.selectAction.setRemovedFilters([])\n    \n      let filterElement = await lively.create(\"bp2019-filter-list-element\")\n      filterElement.setFilter(newFilter)\n      filterElement.addListener(this)\n\n      this.filterHistoryContainer.appendChild(filterElement)\n\n      this._applyFilterHistory()\n    } else {\n      lively.notify(\"Please select values\")\n    }\n  }\n  \n  _applyFilterHistory() {\n    this.onFilterAppliedListeners.forEach(listener => {\n      listener.applyAction(this.selectAction)\n    })  \n  }\n  \n  _createFilterFromCurrentSelection() {\n    let currentFilterAttribute = this._getSelectedFilterAttribute();\n    let currentFilterValues = this._getSelectedFilterValues();\n    \n    return new AtomicFilterAction(currentFilterAttribute, currentFilterValues, this.dataProcessor, this._isGlobal());\n  }\n  \n  _isGlobal() {\n    return this.get('#is-global').checked\n  }\n  \n}"]}