File tree Expand file tree Collapse file tree 2 files changed +26
-7
lines changed
src/lib/devices/DeviceCard/DeviceRoutes Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Original file line number Diff line number Diff line change 11<script >
22 import { getDevices } from ' $lib/common/apiFunctions.svelte' ;
3- import { Device } from ' $lib/common/classes' ;
3+ import { Device } from ' $lib/common/classes' ;
44 import { alertStore } from ' $lib/common/stores' ;
55 import { approveDeviceRoute } from ' ./DeviceRouteAPI.svelte' ;
66
7- export let route = " "
8- export let device = new Device ();
7+ export let route = ' ' ;
8+ export let device = new Device ();
99
1010 let routeDisabled = false ;
1111 function approveRouteAction () {
12- approveDeviceRoute (device .id , [route])
12+ approveDeviceRoute (device .id , [... device . approvedRoutes , route])
1313 .then (() => {
1414 // refresh users after editing
1515 getDevices ();
1919 });
2020 }
2121
22+ function removeRouteAction () {
23+ approveDeviceRoute (device .id , device .approvedRoutes .filter ((r ) => r !== route))
24+ .then (() => {
25+ // refresh users after editing
26+ getDevices ();
27+ })
28+ .catch ((error ) => {
29+ $alertStore = error;
30+ });
31+ }
2232 </script >
2333
2434{route }
2535{#if device .approvedRoutes .includes (route )}
26- <button type =" button" class =" btn btn-xs tooltip capitalize bg-success text-success-content mx-1" >active</button >
36+ <button
37+ on:click ={() => {
38+ routeDisabled = true ;
39+ removeRouteAction ();
40+ routeDisabled = false ;
41+ }}
42+ type =" button"
43+ class =" btn btn-xs tooltip capitalize bg-success text-success-content mx-1" >active</button
44+ >
2745{:else }
2846 <button
2947 on:click ={() => {
3250 routeDisabled = false ;
3351 }}
3452 type =" button"
35- class ="btn btn-xs tooltip capitalize bg-secondary text-secondary-content mx-1" class:disabled ={routeDisabled }
53+ class =" btn btn-xs tooltip capitalize bg-secondary text-secondary-content mx-1"
54+ class:disabled ={routeDisabled }
3655 data-tip =" click to enable route" >pending</button
3756 >
3857{/if }
Original file line number Diff line number Diff line change 11<script context =" module" lang =" ts" >
22
3- export async function approveDeviceRoute(deviceID : string , routes : [ string ]): Promise <any > {
3+ export async function approveDeviceRoute(deviceID : string , routes : string [ ]): Promise <any > {
44 // variables in local storage
55 let headscaleURL = localStorage .getItem (' headscaleURL' ) || ' ' ;
66 let headscaleAPIKey = localStorage .getItem (' headscaleAPIKey' ) || ' ' ;
You can’t perform that action at this time.
0 commit comments