@@ -3,59 +3,16 @@ import { inject, ref } from "vue";
33import { useStateStore } from " @/stores/StateStore" ;
44import PvSelect from " @/components/common/pv-select.vue" ;
55import PvInput from " @/components/common/pv-input.vue" ;
6- import axios from " axios" ;
76import { useTheme } from " vuetify" ;
7+ import { axiosPost } from " @/lib/PhotonUtils" ;
88
99const theme = useTheme ();
1010
1111const restartProgram = () => {
12- axios
13- .post (" /utils/restartProgram" )
14- .then (() => {
15- useStateStore ().showSnackbarMessage ({ message: " Successfully sent program restart request" , color: " success" });
16- })
17- .catch ((error ) => {
18- // This endpoint always return 204 regardless of outcome
19- if (error .request ) {
20- useStateStore ().showSnackbarMessage ({
21- message: " Error while trying to process the request! The backend didn't respond." ,
22- color: " error"
23- });
24- } else {
25- useStateStore ().showSnackbarMessage ({
26- message: " An error occurred while trying to process the request." ,
27- color: " error"
28- });
29- }
30- });
12+ axiosPost (" /utils/restartProgram" , " restart PhotonVision" );
3113};
3214const restartDevice = () => {
33- axios
34- .post (" /utils/restartDevice" )
35- .then (() => {
36- useStateStore ().showSnackbarMessage ({
37- message: " Successfully dispatched the restart command. It isn't confirmed if a device restart will occur." ,
38- color: " success"
39- });
40- })
41- .catch ((error ) => {
42- if (error .response ) {
43- useStateStore ().showSnackbarMessage ({
44- message: " The backend is unable to fulfil the request to restart the device." ,
45- color: " error"
46- });
47- } else if (error .request ) {
48- useStateStore ().showSnackbarMessage ({
49- message: " Error while trying to process the request! The backend didn't respond." ,
50- color: " error"
51- });
52- } else {
53- useStateStore ().showSnackbarMessage ({
54- message: " An error occurred while trying to process the request." ,
55- color: " error"
56- });
57- }
58- });
15+ axiosPost (" /utils/restartDevice" , " restart the device" );
5916};
6017
6118const address = inject <string >(" backendHost" );
@@ -77,47 +34,25 @@ const handleOfflineUpdate = () => {
7734 timeout: - 1
7835 });
7936
80- axios
81- .post (" /utils/offlineUpdate" , formData , {
82- headers: { " Content-Type" : " multipart/form-data" },
83- onUploadProgress : ({ progress }) => {
84- const uploadPercentage = (progress || 0 ) * 100.0 ;
85- if (uploadPercentage < 99.5 ) {
86- useStateStore ().showSnackbarMessage ({
87- message: " New Software Upload in Process, " + uploadPercentage .toFixed (2 ) + " % complete" ,
88- color: " secondary" ,
89- timeout: - 1
90- });
91- } else {
92- useStateStore ().showSnackbarMessage ({
93- message: " Installing uploaded software..." ,
94- color: " secondary" ,
95- timeout: - 1
96- });
97- }
98- }
99- })
100- .then ((response ) => {
101- useStateStore ().showSnackbarMessage ({ message: response .data .text || response .data , color: " success" });
102- })
103- .catch ((error ) => {
104- if (error .response ) {
105- useStateStore ().showSnackbarMessage ({
106- color: " error" ,
107- message: error .response .data .text || error .response .data
108- });
109- } else if (error .request ) {
37+ axiosPost (" /utils/offlineUpdate" , " upload new software" , formData , {
38+ headers: { " Content-Type" : " multipart/form-data" },
39+ onUploadProgress : ({ progress }) => {
40+ const uploadPercentage = (progress || 0 ) * 100.0 ;
41+ if (uploadPercentage < 99.5 ) {
11042 useStateStore ().showSnackbarMessage ({
111- color: " error" ,
112- message: " Error while trying to process the request! The backend didn't respond."
43+ message: " New Software Upload in Process, " + uploadPercentage .toFixed (2 ) + " % complete" ,
44+ color: " secondary" ,
45+ timeout: - 1
11346 });
11447 } else {
11548 useStateStore ().showSnackbarMessage ({
116- color: " error" ,
117- message: " An error occurred while trying to process the request."
49+ message: " Installing uploaded software..." ,
50+ color: " secondary" ,
51+ timeout: - 1
11852 });
11953 }
120- });
54+ }
55+ });
12156};
12257
12358const exportLogFile = ref ();
@@ -166,29 +101,9 @@ const handleSettingsImport = () => {
166101 break ;
167102 }
168103
169- axios
170- .post (` /settings${settingsEndpoint } ` , formData , { headers: { " Content-Type" : " multipart/form-data" } })
171- .then ((response ) => {
172- useStateStore ().showSnackbarMessage ({ message: response .data .text || response .data , color: " success" });
173- })
174- .catch ((error ) => {
175- if (error .response ) {
176- useStateStore ().showSnackbarMessage ({
177- color: " error" ,
178- message: error .response .data .text || error .response .data
179- });
180- } else if (error .request ) {
181- useStateStore ().showSnackbarMessage ({
182- color: " error" ,
183- message: " Error while trying to process the request! The backend didn't respond."
184- });
185- } else {
186- useStateStore ().showSnackbarMessage ({
187- color: " error" ,
188- message: " An error occurred while trying to process the request."
189- });
190- }
191- });
104+ axiosPost (` /settings${settingsEndpoint } ` , " import settings" , formData , {
105+ headers: { " Content-Type" : " multipart/form-data" }
106+ });
192107
193108 showImportDialog .value = false ;
194109 importType .value = undefined ;
@@ -199,32 +114,8 @@ const showFactoryReset = ref(false);
199114const expected = " Delete Everything" ;
200115const yesDeleteMySettingsText = ref (" " );
201116const nukePhotonConfigDirectory = () => {
202- axios
203- .post (" /utils/nukeConfigDirectory" )
204- .then (() => {
205- useStateStore ().showSnackbarMessage ({
206- message: " Successfully dispatched the reset command. Waiting for backend to start back up" ,
207- color: " success"
208- });
209- })
210- .catch ((error ) => {
211- if (error .response ) {
212- useStateStore ().showSnackbarMessage ({
213- message: " The backend is unable to fulfill the request to reset the device." ,
214- color: " error"
215- });
216- } else if (error .request ) {
217- useStateStore ().showSnackbarMessage ({
218- message: " Error while trying to process the request! The backend didn't respond." ,
219- color: " error"
220- });
221- } else {
222- useStateStore ().showSnackbarMessage ({
223- message: " An error occurred while trying to process the request." ,
224- color: " error"
225- });
226- }
227- });
117+ axiosPost (" /utils/nukeConfigDirectory" , " delete the config directory" );
118+
228119 showFactoryReset .value = false ;
229120};
230121 </script >
0 commit comments