controllers/dashboard/frame_controller.js

  1. import { Controller } from "@hotwired/stimulus"
  2. import { subscription } from "~/javascripts/store/mixins/subscription"
  3. /**
  4. * @class Dashboard.FrameController
  5. * @classdesc Handles the click events on the data visualisation selectors
  6. * @extends Controller
  7. **/
  8. export default class extends Controller {
  9. static targets = [ "button", "header" ]
  10. static values = {
  11. storeId: String
  12. }
  13. /**
  14. * Subscribe to the store.
  15. *
  16. * @instance
  17. * @memberof Dashboard.FrameController
  18. **/
  19. connect() {
  20. subscription(this)
  21. this.subscribe()
  22. }
  23. /**
  24. * Event action to set the selected frame id in the store and add the appropriate active class
  25. *
  26. * @instance
  27. * @memberof Dashboard.FrameController
  28. **/
  29. frameSelected(event) {
  30. this.editStore("frameSelected", event.params.id)
  31. this.buttonTargets.forEach(buttonTarget => buttonTarget.classList.remove("active"))
  32. event.target.classList.add("active")
  33. this.headerTarget.innerHTML = event.params.header
  34. }
  35. /**
  36. * Unsubscribe from the store
  37. *
  38. * @instance
  39. * @memberof Dashboard.FrameController
  40. **/
  41. disconnect() {
  42. this.unsubscribe()
  43. }
  44. }