-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from CropWatchDevelopment/change-device-names
Change device names
- Loading branch information
Showing
10 changed files
with
266 additions
and
49 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE POLICY "update_if_user_owns_table" | ||
ON cw_locations | ||
FOR UPDATE | ||
USING ( | ||
EXISTS ( | ||
SELECT 1 | ||
FROM cw_location_owners | ||
WHERE cw_location_owners.user_id = auth.uid() | ||
AND cw_location_owners.location_id = cw_locations.location_id | ||
AND cw_location_owners.is_active = true -- Assuming you have a similar condition | ||
) | ||
); |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<script lang="ts"> | ||
import { enhance } from '$app/forms'; | ||
import { mdiClose, mdiFloppy, mdiPencil } from '@mdi/js'; | ||
import { toast } from '@zerodevx/svelte-toast'; | ||
import { Button, Dialog, TextField } from 'svelte-ux'; | ||
import { _ } from 'svelte-i18n'; | ||
export let currentSensorName: string = ''; | ||
export let dev_eui: string = -1; | ||
let currentSensorNameStatic = currentSensorName; | ||
let open = false; | ||
const handleSubmit = () => { | ||
fetch(`/api/v1/devices/${dev_eui}`, { | ||
method: 'PUT', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify({ name: currentSensorName }) | ||
}) | ||
.then((res) => { | ||
if (res.ok) { | ||
toast.push(`Sensor name updated successfully`, { | ||
theme: { | ||
'--toastBackground': 'green', | ||
'--toastColor': 'black' | ||
} | ||
}); | ||
currentSensorNameStatic = currentSensorName; | ||
} else { | ||
toast.push(`Sensor name updated FAILED`, { | ||
theme: { | ||
'--toastBackground': 'red', | ||
'--toastColor': 'black' | ||
} | ||
}); | ||
currentSensorName = currentSensorNameStatic; | ||
open = false; | ||
} | ||
return res.json(); | ||
}) | ||
.then((data) => { | ||
console.log(data); | ||
currentSensorName = data.name; | ||
open = false; | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
currentSensorName = currentSensorNameStatic; | ||
open = false; | ||
}); | ||
}; | ||
const closing = () => { | ||
currentSensorName = currentSensorNameStatic; | ||
open = false; | ||
}; | ||
</script> | ||
|
||
<Button on:click={() => (open = true)} icon={mdiPencil} size="sm" /> | ||
|
||
<form action={`/api/v1/sensors/${dev_eui}`} method="PUT"> | ||
<Dialog bind:open on:close={() => closing()}> | ||
<div slot="title">{$_('rename_dialog.rename')} {currentSensorNameStatic} {$_('rename_dialog.to_what')}</div> | ||
<div class="m-4"> | ||
<TextField name="newName" label={$_('rename_dialog.new_name')} bind:value={currentSensorName} /> | ||
</div> | ||
<div class="flex flex-row mt-1 p-2"> | ||
<Button variant="fill" icon={mdiClose} on:click={() => (open = false)} color="danger">{$_('close')}</Button> | ||
<span class="flex-grow" /> | ||
<Button | ||
variant="fill" | ||
type="button" | ||
icon={mdiFloppy} | ||
on:click={() => handleSubmit()} | ||
color="success">{$_('save')}</Button | ||
> | ||
</div> | ||
</Dialog> | ||
</form> |
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
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
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
Oops, something went wrong.