@@ -5,6 +5,9 @@ import { registry } from "@web/core/registry";
5
5
import { Layout } from "@web/search/layout" ;
6
6
import { useService } from "@web/core/utils/hooks" ;
7
7
import { DashboardItem } from "./dashboard_item" ;
8
+ import { Dialog } from "@web/core/dialog/dialog" ;
9
+ import { CheckBox } from "@web/core/checkbox/checkbox" ;
10
+ import { browser } from "@web/core/browser/browser" ;
8
11
9
12
class AwesomeDashboard extends Component {
10
13
static template = "awesome_dashboard.AwesomeDashboard" ;
@@ -14,11 +17,26 @@ class AwesomeDashboard extends Component {
14
17
this . action = useService ( "action" ) ;
15
18
this . statistics = useState ( useService ( "awesome_dashboard.statistics" ) ) ;
16
19
this . items = registry . category ( "item" ) . getAll ( ) ;
20
+ this . dialog = useService ( "dialog" ) ;
17
21
this . display = {
18
22
controlPanel : { } ,
19
23
} ;
24
+ this . state = useState ( {
25
+ disabledItems : browser . localStorage . getItem ( "disabledDashboardItems" ) ?. split ( "," ) || [ ] ,
26
+ } ) ;
27
+ }
28
+
29
+ openConfiguration ( newDisabledItems ) {
30
+ this . dialog . add ( ConfigurationDialog , {
31
+ items : this . items ,
32
+ disabledItems : this . state . disabledItems ,
33
+ onUpdateConfiguration : this . updateConfiguration . bind ( this ) ,
34
+ } )
20
35
}
21
36
37
+ updateConfiguration ( newDisabledItems ) {
38
+ this . state . disabledItems = newDisabledItems ;
39
+ }
22
40
openCustomerView ( ) {
23
41
this . action . doAction ( "base.action_partner_form" ) ;
24
42
}
@@ -36,4 +54,33 @@ class AwesomeDashboard extends Component {
36
54
}
37
55
}
38
56
57
+ class ConfigurationDialog extends Component {
58
+ static template = "awesome_dashboard.ConfigurationDialog" ;
59
+ static components = { Dialog, CheckBox } ;
60
+ static props = [ "close" , "items" , "disabledItems" , "onUpdateConfiguration" ] ;
61
+
62
+ setup ( ) {
63
+ this . items = useState ( this . props . items . map ( ( item ) => {
64
+ return {
65
+ ...item ,
66
+ enabled : ! this . props . disabledItems . includes ( item . id ) ,
67
+ } ;
68
+ } ) ) ;
69
+ }
70
+
71
+ done ( ) {
72
+ this . props . close ( ) ;
73
+ }
74
+
75
+ onChange ( checked , changedItem ) {
76
+ changedItem . enabled = checked ;
77
+ const newDisabledItems = Object . values ( this . items ) . filter (
78
+ ( item ) => ! item . enabled ) . map ( ( item ) => item . id ) ;
79
+
80
+ browser . localStorage . setItem ( "disabledDashboardItems" , newDisabledItems ) ;
81
+
82
+ this . props . onUpdateConfiguration ( newDisabledItems ) ;
83
+ }
84
+ }
85
+
39
86
registry . category ( "lazy_components" ) . add ( "AwesomeDashboard" , AwesomeDashboard ) ;
0 commit comments