{"version":3,"file":"c8y-ngx-components-operations-status-filter.mjs","sources":["../../operations/status-filter/status-filter.component.ts","../../operations/status-filter/status-filter.component.html","../../operations/status-filter/status-filter.module.ts","../../operations/status-filter/c8y-ngx-components-operations-status-filter.ts"],"sourcesContent":["import { coerceBooleanProperty } from '@angular/cdk/coercion';\nimport { Component, EventEmitter, forwardRef, HostBinding, Input, Output } from '@angular/core';\nimport {\n  ProductExperienceEvent,\n  ProductExperienceEventSource,\n  PRODUCT_EXPERIENCE_EVENT_SOURCE,\n  IconDirective,\n  ProductExperienceDirective,\n  C8yTranslatePipe\n} from '@c8y/ngx-components';\nimport { ACTIONS_OPERATIONS } from '@c8y/ngx-components/operations/product-experience';\nimport {\n  OperationStatusOptionsMapShared,\n  OperationStatusOption\n} from '@c8y/ngx-components/operations/shared';\nimport {\n  BsDropdownDirective,\n  BsDropdownToggleDirective,\n  BsDropdownMenuDirective\n} from 'ngx-bootstrap/dropdown';\nimport { NgFor, NgIf, NgClass } from '@angular/common';\n\n@Component({\n  selector: 'c8y-status-filter',\n  templateUrl: './status-filter.component.html',\n  providers: [\n    {\n      provide: PRODUCT_EXPERIENCE_EVENT_SOURCE,\n      useExisting: forwardRef(() => StatusFilterComponent)\n    }\n  ],\n  imports: [\n    BsDropdownDirective,\n    BsDropdownToggleDirective,\n    NgFor,\n    NgIf,\n    IconDirective,\n    NgClass,\n    BsDropdownMenuDirective,\n    ProductExperienceDirective,\n    C8yTranslatePipe\n  ]\n})\nexport class StatusFilterComponent implements ProductExperienceEventSource {\n  ACTIONS = ACTIONS_OPERATIONS;\n  productExperienceEvent: ProductExperienceEvent;\n  statusOptions: Array<{ selected: boolean; option: OperationStatusOption }> = [];\n\n  /** List of filter options to be displayed */\n  @Input() set options(options: OperationStatusOptionsMapShared) {\n    this.statusOptions = (Object.values(options) || []).map(option => ({\n      selected: false,\n      option\n    }));\n  }\n\n  /**\n   * Allows multiple options to be active simultaneosly.\n   */\n  @Input('multiple') set _multiple(multiple: boolean) {\n    this.multiple = coerceBooleanProperty(multiple);\n  }\n\n  /** Display the filter as a small button group */\n  @Input('small') set _small(small: boolean) {\n    this.small = coerceBooleanProperty(small);\n  }\n\n  @HostBinding('class.btn-group-sm') get displaySmall() {\n    return this.small;\n  }\n\n  @Output() onFilterChanged: EventEmitter<OperationStatusOption[]> = new EventEmitter();\n\n  isAllButtonSelected = true;\n\n  private multiple: boolean;\n  private small: boolean;\n\n  changeFilter(option: { selected: boolean; option: OperationStatusOption }) {\n    this.isAllButtonSelected = false;\n    let emitNeeded = false;\n\n    if (this.multiple) {\n      option.selected = !option.selected;\n      emitNeeded = true;\n    } else if (!option.selected) {\n      option.selected = true;\n      this.statusOptions.filter(op => op !== option).forEach(op => (op.selected = false));\n      emitNeeded = true;\n    }\n\n    if (emitNeeded) {\n      this.emitSelectedOptions();\n    }\n  }\n\n  removeFilter() {\n    this.isAllButtonSelected = true;\n    this.statusOptions.forEach(op => (op.selected = false));\n\n    this.emitSelectedOptions();\n  }\n\n  /**\n   * Allows the filter to be initalliy displayed with some preset filters.\n   *\n   * @param filters An `StatusOption` array defining filter options to be preset.\n   * @param emit  (optional) If `true` component will emit `onFilterChanged` event.\n   */\n  preset(filters: OperationStatusOption[], emit = true) {\n    let firstSelected = false;\n\n    this.statusOptions.forEach(option => (option.selected = false));\n\n    this.statusOptions\n      .filter(option => (filters || []).map(o => o.label).includes(option.option.label))\n      .filter(() => {\n        // only first option passed will be set in single selection mode\n        const include: boolean = this.multiple || !firstSelected;\n        if (include) {\n          firstSelected = true;\n        }\n\n        return include;\n      })\n      .forEach(option => (option.selected = true));\n\n    this.isAllButtonSelected = !(filters && filters.length);\n\n    if (emit) {\n      this.emitSelectedOptions();\n    }\n  }\n\n  reset() {\n    this.removeFilter();\n  }\n\n  activeFilters(): OperationStatusOption[] {\n    return this.statusOptions.filter(option => option.selected).map(option => option.option);\n  }\n\n  isFilterApplied(): boolean {\n    return this.statusOptions.some(option => option.selected);\n  }\n\n  private emitSelectedOptions() {\n    this.onFilterChanged.emit(\n      this.statusOptions.filter(option => option.selected).map(option => option.option)\n    );\n  }\n}\n","<div dropdown placement=\"bottom left\" class=\"dropdown c8y-child-assets-selector\">\n  <button\n    class=\"btn dropdown-toggle d-flex a-i-center c8y-dropdown\"\n    type=\"button\"\n    title=\"{{ 'Status filter' | translate }}\"\n    dropdownToggle\n  >\n    <span *ngFor=\"let option of statusOptions\" class=\"d-contents\">\n      <span class=\"text-truncate\" *ngIf=\"option.selected\">\n        <i [c8yIcon]=\"option.option.icon\" [ngClass]=\"option.option.styleClass\"></i>\n        <span class=\"m-l-4\">{{ option.option.label | translate }}</span>\n      </span>\n    </span>\n    <span class=\"text-truncate\" *ngIf=\"isAllButtonSelected\">\n      <i c8yIcon=\"c8y-energy\" class=\"m-r-4 text-info\"></i>\n      {{ 'All statuses' | translate }}\n    </span>\n  </button>\n  <ul\n    id=\"dropdown-status-filter\"\n    *dropdownMenu\n    class=\"dropdown-menu\"\n    role=\"menu\"\n    aria-labelledby=\"status-filter\"\n  >\n    <li *ngFor=\"let option of statusOptions\" [ngClass]=\"{ active: option.selected }\">\n      <button\n        type=\"button\"\n        [title]=\"option.option.label | translate\"\n        (click)=\"changeFilter(option)\"\n        c8yProductExperience\n        inherit\n        [actionData]=\"{\n          action: ACTIONS.FILTER,\n          filterBy: 'status',\n          filterValue: option.option.label\n        }\"\n      >\n        <i [c8yIcon]=\"option.option.icon\" [ngClass]=\"option.option.styleClass\"></i>\n        <span class=\"m-l-4\">{{ option.option.label | translate }}</span>\n      </button>\n    </li>\n    <li [ngClass]=\"{ active: isAllButtonSelected }\">\n      <button\n        type=\"button\"\n        title=\"{{ 'All statuses' | translate }}\"\n        (click)=\"removeFilter()\"\n        c8yProductExperience\n        inherit\n        [actionData]=\"{\n          action: ACTIONS.FILTER,\n          filterBy: 'status'\n        }\"\n      >\n        <i c8yIcon=\"c8y-energy\" class=\"m-r-4 text-info\"></i>\n        {{ 'All statuses' | translate }}\n      </button>\n    </li>\n  </ul>\n</div>\n","import { NgModule } from '@angular/core';\nimport { StatusFilterComponent } from './status-filter.component';\n\n/**\n * This module provides a component for selecting status filter.\n */\n@NgModule({\n  imports: [StatusFilterComponent],\n  exports: [StatusFilterComponent]\n})\nexport class StatusFilterModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;MA2Ca,qBAAqB,CAAA;AArBlC,IAAA,WAAA,GAAA;QAsBE,IAAA,CAAA,OAAO,GAAG,kBAAkB;QAE5B,IAAA,CAAA,aAAa,GAAgE,EAAE;AA0BrE,QAAA,IAAA,CAAA,eAAe,GAA0C,IAAI,YAAY,EAAE;QAErF,IAAA,CAAA,mBAAmB,GAAG,IAAI;AA8E3B,IAAA;;IAvGC,IAAa,OAAO,CAAC,OAAwC,EAAA;QAC3D,IAAI,CAAC,aAAa,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,MAAM,KAAK;AACjE,YAAA,QAAQ,EAAE,KAAK;YACf;AACD,SAAA,CAAC,CAAC;IACL;AAEA;;AAEG;IACH,IAAuB,SAAS,CAAC,QAAiB,EAAA;AAChD,QAAA,IAAI,CAAC,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAC;IACjD;;IAGA,IAAoB,MAAM,CAAC,KAAc,EAAA;AACvC,QAAA,IAAI,CAAC,KAAK,GAAG,qBAAqB,CAAC,KAAK,CAAC;IAC3C;AAEA,IAAA,IAAuC,YAAY,GAAA;QACjD,OAAO,IAAI,CAAC,KAAK;IACnB;AASA,IAAA,YAAY,CAAC,MAA4D,EAAA;AACvE,QAAA,IAAI,CAAC,mBAAmB,GAAG,KAAK;QAChC,IAAI,UAAU,GAAG,KAAK;AAEtB,QAAA,IAAI,IAAI,CAAC,QAAQ,EAAE;AACjB,YAAA,MAAM,CAAC,QAAQ,GAAG,CAAC,MAAM,CAAC,QAAQ;YAClC,UAAU,GAAG,IAAI;QACnB;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