-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
71 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,3 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
/log/*.log | ||
/test/dummy/db/*.sqlite3 | ||
/test/dummy/db/*.sqlite3-* | ||
/test/dummy/log/*.log | ||
/test/dummy/storage/ | ||
/test/dummy/tmp/ | ||
/.bundle | ||
|
||
/Gemfile.lock | ||
.rspec_status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"arrowParens": "always", | ||
"bracketSameLine": true, | ||
"bracketSpacing": true, | ||
"endOfLine": "lf", | ||
"printWidth": 80, | ||
"quoteProps": "consistent", | ||
"semi": false, | ||
"singleQuote": false, | ||
"tabWidth": 2, | ||
"trailingComma": "all", | ||
"useTabs": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { createConsumer } from "https://unpkg.com/@rails/actioncable@7.1.3-4/app/assets/javascripts/actioncable.esm.js"; | ||
import { createConsumer } from "https://unpkg.com/@rails/actioncable@7.1.3-4/app/assets/javascripts/actioncable.esm.js" | ||
|
||
export default createConsumer(); | ||
export default createConsumer() |
4 changes: 2 additions & 2 deletions
4
app/assets/javascripts/hotsheet/channels/inline_edit_channel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import consumer from "channels/consumer"; | ||
import consumer from "channels/consumer" | ||
|
||
consumer.subscriptions.create({ channel: "InlineEditChannel" }); | ||
consumer.subscriptions.create({ channel: "InlineEditChannel" }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { Application } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js"; | ||
import { Application } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js" | ||
import EditableAttributeController from "./controllers/editable_attribute_controller" | ||
|
||
import EditableAttributeController from "./controllers/editable_attribute_controller.js"; | ||
|
||
window.Stimulus = Application.start(); | ||
window.Stimulus = Application.start() | ||
|
||
Stimulus.register("editable-attribute", EditableAttributeController) |
95 changes: 45 additions & 50 deletions
95
app/assets/javascripts/hotsheet/controllers/editable_attribute_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,51 @@ | ||
import { | ||
Controller, | ||
} from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js"; | ||
import { Controller } from "https://unpkg.com/@hotwired/stimulus/dist/stimulus.js" | ||
|
||
export default class extends Controller { | ||
static values = { | ||
broadcastUrl: String, | ||
resourceName: String, | ||
resourceId: Number | ||
}; | ||
|
||
static targets = [ | ||
'readonlyAttribute', | ||
'attributeForm', | ||
'attributeFormInput' | ||
]; | ||
|
||
displayInputField() { | ||
this.broadcastEditIntent(); | ||
this.readonlyAttributeTarget.style.display = 'none'; | ||
this.attributeFormTarget.style.display = 'block'; | ||
this.attributeFormInputTarget.focus(); | ||
static values = { | ||
broadcastUrl: String, | ||
resourceName: String, | ||
resourceId: Number, | ||
} | ||
|
||
static targets = ["readonlyAttribute", "attributeForm", "attributeFormInput"] | ||
|
||
displayInputField() { | ||
// this.broadcastEditIntent() | ||
this.readonlyAttributeTarget.style.display = "none" | ||
this.attributeFormTarget.style.display = "block" | ||
this.attributeFormInputTarget.focus() | ||
} | ||
|
||
broadcastEditIntent() { | ||
const headers = { | ||
"Content-Type": "application/json", | ||
"X-CSRF-Token": document.querySelector("meta[name=csrf-token]").content, | ||
} | ||
|
||
broadcastEditIntent() { | ||
const headers = new Headers(); | ||
headers.append("Content-Type", "application/json"); | ||
headers.append("X-CSRF-Token", document.querySelector("meta[name=csrf-token]").content); | ||
|
||
const data = JSON.stringify({ | ||
broadcast: { | ||
resource_name: this.resourceNameValue, | ||
resource_id: this.resourceIdValue | ||
} | ||
}); | ||
|
||
fetch(this.broadcastUrlValue, { method: "POST", headers: headers, body: data }).then(); | ||
const body = JSON.stringify({ | ||
broadcast: { | ||
resource_name: this.resourceNameValue, | ||
resource_id: this.resourceIdValue, | ||
}, | ||
}) | ||
|
||
fetch(this.broadcastUrlValue, { method: "POST", headers, body }) | ||
} | ||
|
||
submitForm(event) { | ||
// Prevent standard submission triggered by Enter press | ||
event.preventDefault() | ||
|
||
const previousValue = this.readonlyAttributeTarget.innerText.trim() | ||
const newValue = this.attributeFormInputTarget.value | ||
|
||
if (previousValue && previousValue === newValue) { | ||
this.readonlyAttributeTarget.style.display = "block" | ||
this.attributeFormTarget.style.display = "none" | ||
return | ||
} | ||
|
||
submitForm(event) { | ||
// Prevent standard submission triggered by Enter press | ||
event.preventDefault(); | ||
|
||
const previousValue = this.readonlyAttributeTarget.innerText.trim(); | ||
const newValue = this.attributeFormInputTarget.value; | ||
if (previousValue && previousValue === newValue) { | ||
this.readonlyAttributeTarget.style.display = 'block'; | ||
this.attributeFormTarget.style.display = 'none'; | ||
return; | ||
} | ||
|
||
// It's important to use requestSubmit() instead of simply submit() as the latter will circumvent the | ||
// Turbo mechanism, causing the PATCH request to be submitted as HTML instead of TURBO_STREAM | ||
this.attributeFormInputTarget.form.requestSubmit(); | ||
} | ||
// It's important to use requestSubmit() instead of simply submit() as the latter will circumvent the | ||
// Turbo mechanism, causing the PATCH request to be submitted as HTML instead of TURBO_STREAM | ||
this.attributeFormInputTarget.form.requestSubmit() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.