Sha256: a5f1c6a445668dced4e4f627637fdd76ea5aa650888e0906b706a3464aa16c00

Contents?: true

Size: 1.12 KB

Versions: 36

Compression:

Stored size: 1.12 KB

Contents

import ServerRefreshController from './server-refresh-controller'
import { FetchRequest } from '@rails/request.js'

export default class extends ServerRefreshController {
  static values = {
    previousCriterionId: Number,
  }

  async criterion() {
    const isValid = await this.validateBlueprint()
    if (isValid) {
      this.state.addCriterion(this.previousCriterionIdValue)
    }
    this.refreshFromServer({includeErrors: !isValid})
  }

  async group() {
    const isValid = await this.validateBlueprint()
    if (isValid) {
      this.state.addGroup()
    }
    this.refreshFromServer({includeErrors: !isValid})
  }

  async validateBlueprint(blueprint) {
    const { state } = this

    const request = new FetchRequest(
      "GET",
      this.state.validateBlueprintUrlValue,
      {
        query: {
          "refine_filters_builder[filter_class]": this.state.filterName,
          "refine_filters_builder[blueprint_json]": JSON.stringify(this.state.blueprint),
          "refine_filters_builder[client_id]": this.state.clientIdValue
        }
      }
    )
    const response = await request.perform()
    return response.ok
  }
}

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
refine-rails-2.10.0 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.14 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.13 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.12 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.11 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.10 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.9 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.8 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.7 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.6 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.5 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.4 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.3 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.2 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.1 app/javascript/controllers/refine/add-controller.js
refine-rails-2.9.0 app/javascript/controllers/refine/add-controller.js