Sha256: 5ac945a64a8311105a4c9602937d23d736b6ac4b9c7b4d171f04ffd34a79d90c

Contents?: true

Size: 1.6 KB

Versions: 30

Compression:

Stored size: 1.6 KB

Contents

import { Controller } from "@hotwired/stimulus"
import { FetchRequest } from '@rails/request.js'

export default class extends Controller {
  static values = {
    submitUrl: String
  }

  connect() {
    const urlParams = new URLSearchParams(window.location.search)
    this.existingParams = urlParams
    this.existingParams.delete('stable_id')
  }

  delete(event) {
    const { criterionId } = event.currentTarget.dataset
    var index = parseInt(criterionId)
    this.stateController.deleteCriterion(index)
    this.reloadPage()
  }

  async reloadPage() {
    const {blueprint} = this.stateController
    const request = new FetchRequest(
      "POST",
      this.submitUrlValue,
      {
        responseKind: "turbo-stream",
        body: JSON.stringify({
          refine_filters_builder: {
            filter_class: this.stateController.filterName,
            blueprint_json: JSON.stringify(blueprint),
            client_id: this.stateController.clientIdValue
          }
        })
      }
    )
    await request.perform()
  }

  redirectToStableId(stableId) {
    const params = new URLSearchParams()
    if (stableId) {
      params.append('stable_id', stableId)
    }
    const allParams = new URLSearchParams({
      ...Object.fromEntries(this.existingParams),
      ...Object.fromEntries(params),
    }).toString()
    const url = `${window.location.pathname}?${allParams}`

    history.pushState({}, document.title, url)
    window.location.reload()
  }

  get stateController() {
    return this.element.refineStateController
  }

  get stabilizeFilterController() {
    return this.element.stabilizeFilterController
  }
}

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
refine-rails-2.12.0 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.11.12 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.11.11 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.11.10 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.11.9 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.11.8 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.11.6 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.11.5 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.11.4 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.11.3 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.11.2 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.11.1 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.11.0 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.10.1 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.10.0 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.9.14 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.9.13 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.9.12 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.9.11 app/javascript/controllers/refine/filter-pills-controller.js
refine-rails-2.9.10 app/javascript/controllers/refine/filter-pills-controller.js