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