3838 <Modal v-if =" modal" @close =" closeModal" >
3939 <div class =" modal__content" >
4040 <h3 >{{ t('dashboard', 'Edit widgets') }}</h3 >
41+ <ol class =" panels" >
42+ <li v-for =" status in sortedAllStatuses" :key =" status" >
43+ <input :id =" 'status-checkbox-' + status"
44+ type =" checkbox"
45+ class =" checkbox"
46+ :checked =" isStatusActive(status)"
47+ @input =" updateStatusCheckbox(status, $event.target.checked)" >
48+ <label :for =" 'status-checkbox-' + status" :class =" statusInfo[status].icon" >
49+ {{ statusInfo[status].text }}
50+ </label >
51+ </li >
52+ </ol >
4153 <Draggable v-model =" layout"
4254 class =" panels"
4355 tag =" ol"
@@ -90,6 +102,16 @@ const firstRun = loadState('dashboard', 'firstRun')
90102const background = loadState (' dashboard' , ' background' )
91103const version = loadState (' dashboard' , ' version' )
92104const shippedBackgroundList = loadState (' dashboard' , ' shippedBackgrounds' )
105+ const statusInfo = {
106+ weather: {
107+ text: t (' dashboard' , ' Weather' ),
108+ icon: ' icon-weather-status' ,
109+ },
110+ status: {
111+ text: t (' dashboard' , ' Status' ),
112+ icon: ' icon-user-status-online' ,
113+ },
114+ }
93115
94116export default {
95117 name: ' App' ,
@@ -108,6 +130,9 @@ export default {
108130 registeredStatus: [],
109131 callbacks: {},
110132 callbacksStatus: {},
133+ allCallbacksStatus: {},
134+ statusInfo,
135+ enabledStatuses: loadState (' dashboard' , ' statuses' ),
111136 panels,
112137 firstRun,
113138 displayName: getCurrentUser ()? .displayName ,
@@ -162,6 +187,12 @@ export default {
162187 isActive () {
163188 return (panel ) => this .layout .indexOf (panel .id ) > - 1
164189 },
190+ isStatusActive () {
191+ return (status ) => ! (status in this .enabledStatuses ) || this .enabledStatuses [status]
192+ },
193+ sortedAllStatuses () {
194+ return Object .keys (this .allCallbacksStatus ).slice ().sort ((a , b ) => a > b)
195+ },
165196 sortedPanels () {
166197 return Object .values (this .panels ).sort ((a , b ) => {
167198 const indexA = this .layout .indexOf (a .id )
@@ -224,10 +255,15 @@ export default {
224255 Vue .set (this .callbacks , app, callback)
225256 },
226257 registerStatus (app , callback ) {
227- this .registeredStatus .push (app)
228- this .$nextTick (() => {
229- Vue .set (this .callbacksStatus , app, callback)
230- })
258+ // always save callbacks in case user enables the status later
259+ Vue .set (this .allCallbacksStatus , app, callback)
260+ // register only if status is enabled or missing from config
261+ if (this .isStatusActive (app)) {
262+ this .registeredStatus .push (app)
263+ this .$nextTick (() => {
264+ Vue .set (this .callbacksStatus , app, callback)
265+ })
266+ }
231267 },
232268 rerenderPanels () {
233269 for (const app in this .callbacks ) {
@@ -253,6 +289,11 @@ export default {
253289 layout: this .layout .join (' ,' ),
254290 })
255291 },
292+ saveStatuses () {
293+ axios .post (generateUrl (' /apps/dashboard/statuses' ), {
294+ statuses: JSON .stringify (this .enabledStatuses ),
295+ })
296+ },
256297 showModal () {
257298 this .modal = true
258299 this .firstRun = false
@@ -296,6 +337,30 @@ export default {
296337 document .body .classList .remove (' dashboard--dark' )
297338 }
298339 },
340+ updateStatusCheckbox (app , checked ) {
341+ if (checked) {
342+ this .enableStatus (app)
343+ } else {
344+ this .disableStatus (app)
345+ }
346+ },
347+ enableStatus (app ) {
348+ this .enabledStatuses [app] = true
349+ this .registerStatus (app, this .allCallbacksStatus [app])
350+ this .saveStatuses ()
351+ },
352+ disableStatus (app ) {
353+ this .enabledStatuses [app] = false
354+ const i = this .registeredStatus .findIndex ((s ) => s === app)
355+ if (i !== - 1 ) {
356+ this .registeredStatus .splice (i, 1 )
357+ Vue .set (this .statuses , app, { mounted: false })
358+ this .$nextTick (() => {
359+ Vue .delete (this .callbacksStatus , app)
360+ })
361+ }
362+ this .saveStatuses ()
363+ },
299364 },
300365}
301366 </script >
0 commit comments