flipside 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10dcbfd4da7a00053fc1e9486c54312a0010096deeec169368e251dd173a6c41
4
- data.tar.gz: 0327eac1507849ce0ae681a37af3ca5b09af9d642331619879cfd2e876f97462
3
+ metadata.gz: 40777dd3225cce9bdb82e6d66301c8612a7284a51011610203cf717e6b68d2bc
4
+ data.tar.gz: 26f0f2f2570389e80c76ebc3cdb347ff328d504b6291a4ba50d3df88d1c61a91
5
5
  SHA512:
6
- metadata.gz: 1380f6f03f37f95a4f567ea840534e371a963fa1380bde5424981651d558761c642f67ba9cbc9bc14fac90ee0dc9393020a3bb13ca809b0e5206cea7c542ffe9
7
- data.tar.gz: f9827baa63d88ec20224c8e5bb356af5ac03271714a0db706359e53b157a28e03108a2be5c729fd83e58a39d443dc548b4e7bdcdebe591fce706b7839bae8d55
6
+ metadata.gz: 88e26979066424e8474657fe29818254e85ac182113513bfb9fae0849fd73c9c54541c7e1cbca2f33a98e41b01b1c8b54c5c9adcb6613000fa99c181086128bd
7
+ data.tar.gz: 899954def9a08cbdd895683e2975e32e59ab2ab1147d423460be32db25eeb764342124dfe7b89aacbf95abcca6613181cfb9470b1c377cfd25c83ddbfbb71757
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.1] - 2024-11-22
4
+
5
+ - Fix missing js files for web UI
6
+
3
7
  ## [0.1.0] - 2024-11-22
4
8
 
5
9
  - Initial release
@@ -0,0 +1,9 @@
1
+ import { Application } from "@hotwired/stimulus"
2
+ import ToggleController from "toggle_controller"
3
+ import SearchController from "search_controller"
4
+ import ModalController from "modal_controller"
5
+
6
+ const application = Application.start()
7
+ application.register("toggle", ToggleController)
8
+ application.register("search", SearchController)
9
+ application.register("modal", ModalController)
@@ -0,0 +1,20 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static targets = ["dialog"];
5
+
6
+ open() {
7
+ if (this.hasDialogTarget) {
8
+ this.dialogTarget.classList.remove("hidden");
9
+ this.dialogTarget.showModal()
10
+ }
11
+ }
12
+
13
+ close() {
14
+ if (this.hasDialogTarget) {
15
+ this.dialogTarget.classList.add("hidden");
16
+ this.dialogTarget.close()
17
+ }
18
+ }
19
+ }
20
+
@@ -0,0 +1,110 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class SearchController extends Controller {
4
+ static targets = ["input", "value", "param", "results", "addButton"]
5
+ static values = {url: String}
6
+
7
+ timer = null
8
+
9
+ async search(event) {
10
+ clearTimeout(this.timer)
11
+ this.timer = setTimeout(this.fetchResults.bind(this), 400)
12
+ }
13
+
14
+ async fetchResults() {
15
+ this.clearResults()
16
+ try {
17
+ const url = this.getUrl()
18
+ if (!url) return
19
+
20
+ const response = await fetch(url)
21
+ if (!response.ok) {
22
+ console.error("Failed to fetch search results")
23
+ return
24
+ }
25
+
26
+ const html = await response.text()
27
+ this.updateResults(html)
28
+ } catch (error) {
29
+ console.error("Error fetching search results:", error)
30
+ }
31
+ }
32
+
33
+ select(event) {
34
+ // If the event target has no value, then we assume we didn't find any results
35
+ if (!event.target.value) {
36
+ this.clearResults()
37
+ if (this.hasAddButtonTarget) this.disableAddButton()
38
+ return
39
+ }
40
+
41
+ if (this.hasInputTarget) {
42
+ this.inputTarget.value = event.target.textContent.trim()
43
+ }
44
+
45
+ if (this.hasValueTarget) {
46
+ this.valueTarget.value = event.target.value
47
+ if (this.hasAddButtonTarget) this.enabledAddButton()
48
+ }
49
+
50
+ this.clearResults()
51
+ }
52
+
53
+ getUrl() {
54
+ if (!this.hasInputTarget) return
55
+
56
+ const query = this.inputTarget.value.trim()
57
+ if (query.length === 0) return
58
+
59
+ const params = new URLSearchParams()
60
+ params.append("q", encodeURIComponent(query))
61
+
62
+ this.paramTargets.forEach(paramTarget => {
63
+ const key = paramTarget.dataset.searchParam
64
+ const value = paramTarget.value
65
+ params.append(key, value)
66
+ })
67
+
68
+ return `${this.urlValue}?${params.toString()}`
69
+ }
70
+
71
+ updateResults(html) {
72
+ if (!this.hasResultsTarget) return
73
+
74
+ this.resultsTarget.innerHTML = html
75
+ this.resultsTarget.classList.add("block")
76
+ }
77
+
78
+ clearResults() {
79
+ if (this.hasResultsTarget) {
80
+ this.resultsTarget.innerHTML = ""
81
+ }
82
+ }
83
+
84
+ clearAll() {
85
+ if (this.hasInputTarget) {
86
+ this.inputTarget.value = ""
87
+ }
88
+
89
+ if (this.hasResultsTarget) {
90
+ this.resultsTarget.innerHTML = ""
91
+ }
92
+
93
+ if (this.hasAddButtonTarget) this.disableAddButton()
94
+ }
95
+
96
+ enabledAddButton() {
97
+ this.addButtonTarget.classList.remove("bg-gray-600")
98
+ this.addButtonTarget.classList.add("bg-gray-300")
99
+ this.addButtonTarget.classList.add("hover:bg-gray-400")
100
+ this.addButtonTarget.disabled = false
101
+ }
102
+
103
+ disableAddButton() {
104
+ this.addButtonTarget.classList.add("bg-gray-600")
105
+ this.addButtonTarget.classList.remove("bg-gray-300")
106
+ this.addButtonTarget.classList.remove("hover:bg-gray-400")
107
+ this.addButtonTarget.disabled = true
108
+ }
109
+ }
110
+
@@ -0,0 +1,29 @@
1
+ import { Controller } from "@hotwired/stimulus";
2
+
3
+ export default class ToggleController extends Controller {
4
+ static targets = ["switch"]
5
+ static values = {
6
+ url: String,
7
+ enabled: Boolean
8
+ }
9
+
10
+ async switch(event) {
11
+ try {
12
+ const data = {enable: !this.enabledValue}
13
+ const response = await fetch(this.urlValue, {
14
+ method: "PUT",
15
+ headers: {"Content-Type": "application/json"},
16
+ body: JSON.stringify(data)
17
+ })
18
+
19
+ if (response.ok) {
20
+ location.reload()
21
+ } else {
22
+ const text = await response.text()
23
+ console.error("Failed to update:", text)
24
+ }
25
+ } catch (error) {
26
+ console.error("Error during the PUT request:", error)
27
+ }
28
+ }
29
+ }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flipside
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipside
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sammy Henningsson
@@ -82,7 +82,7 @@ dependencies:
82
82
  version: '2.1'
83
83
  description: Create simple feature toggles.
84
84
  email:
85
- - sammy.henningsson@apoex.se
85
+ - sammy.henningsson@hey.com
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
@@ -104,6 +104,10 @@ files:
104
104
  - lib/flipside/config/registered_role.rb
105
105
  - lib/flipside/config/roles.rb
106
106
  - lib/flipside/feature_presenter.rb
107
+ - lib/flipside/public/index.js
108
+ - lib/flipside/public/modal_controller.js
109
+ - lib/flipside/public/search_controller.js
110
+ - lib/flipside/public/toggle_controller.js
107
111
  - lib/flipside/search_result.rb
108
112
  - lib/flipside/version.rb
109
113
  - lib/flipside/views/_datetime_modal.erb
@@ -119,10 +123,13 @@ files:
119
123
  - lib/flipside/web.rb
120
124
  - lib/generators/flipside/install/install_generator.rb
121
125
  - lib/generators/flipside/install/templates/20241122_create_flipside_migration.rb
122
- homepage:
126
+ homepage: https://github.com/sammyhenningsson/flipside
123
127
  licenses:
124
128
  - MIT
125
- metadata: {}
129
+ metadata:
130
+ homepage_uri: https://github.com/sammyhenningsson/flipside
131
+ source_code_uri: https://github.com/sammyhenningsson/flipside
132
+ changelog_uri: https://github.com/sammyhenningsson/flipside/blob/main/CHANGELOG.md
126
133
  post_install_message:
127
134
  rdoc_options: []
128
135
  require_paths: