UI confirm of datapoint renaming
This commit is contained in:
parent
8ef6a2bbfa
commit
96f7b50e4e
22
sql/00027.sql
Normal file
22
sql/00027.sql
Normal file
@ -0,0 +1,22 @@
|
||||
/* Updating a datapoint name also updates the jsonb array entry */
|
||||
CREATE OR REPLACE FUNCTION update_triggers_datapoint_name()
|
||||
RETURNS TRIGGER
|
||||
LANGUAGE PLPGSQL
|
||||
AS
|
||||
$$
|
||||
BEGIN
|
||||
UPDATE "trigger"
|
||||
SET
|
||||
datapoints = (datapoints - OLD.name) || jsonb_build_array(NEW.name)
|
||||
WHERE
|
||||
datapoints ? OLD.name;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
|
||||
CREATE TRIGGER datapoint_renamed
|
||||
AFTER UPDATE
|
||||
ON public.datapoint
|
||||
FOR EACH ROW
|
||||
EXECUTE PROCEDURE update_triggers_datapoint_name();
|
@ -1,5 +1,6 @@
|
||||
export class UI {
|
||||
constructor() {
|
||||
constructor(datapointData) {
|
||||
this.datapoint = datapointData
|
||||
document.addEventListener('keydown', evt=>this.keyHandler(evt))
|
||||
document.querySelector('input[name="group"]').focus()
|
||||
}
|
||||
@ -16,4 +17,10 @@ export class UI {
|
||||
break
|
||||
}
|
||||
}
|
||||
check_rename() {
|
||||
let newName = document.querySelector(`input[name="name"]`).value
|
||||
if (newName != this.datapoint.Name)
|
||||
return confirm(`Trigger expressions needs to be manually updated when renaming a datapoint.\nDo you want to rename the datapoint?`)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,12 @@
|
||||
|
||||
<script type="module" defer>
|
||||
import {UI} from "/js/{{ .VERSION }}/datapoint_edit.mjs"
|
||||
window._ui = new UI()
|
||||
window._ui = new UI({{ .Data.Datapoint }})
|
||||
</script>
|
||||
|
||||
{{ block "page_label" . }}{{end}}
|
||||
|
||||
<form id="form-trigger" action="/datapoint/update/{{ .Data.Datapoint.ID }}" method="post">
|
||||
<form id="form-trigger" action="/datapoint/update/{{ .Data.Datapoint.ID }}" method="post" onsubmit="return _ui.check_rename()">
|
||||
<div id="widgets" class="widgets">
|
||||
<div class="label">Group</div>
|
||||
<div><input type="text" name="group" value="{{ .Data.Datapoint.Group }}"></div>
|
||||
@ -56,6 +56,7 @@
|
||||
{{ end }}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{{ end }}
|
||||
|
Loading…
Reference in New Issue
Block a user