BrightSide Workbench Full Report + Source Code
ElephantUserMenu.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.user.menu;
20 
21 import org.turro.elephant.context.Application;
22 import org.turro.elephant.context.ElephantContext;
23 import org.turro.elephant.user.menu.CaptionMenu;
24 import org.turro.elephant.user.menu.DefaultUserMenu;
25 import org.turro.elephant.user.menu.IUserMenu;
26 import org.turro.elephant.user.menu.UserMenu;
27 import org.turro.elephant.user.menu.UserMenus;
28 import org.turro.i18n.I_;
29 
34 @UserMenu
35 public class ElephantUserMenu extends DefaultUserMenu {
36 
37  public ElephantUserMenu() {
38  super("Elephant", null);
39  }
40 
41  @Override
42  public void initMenu() {
44  session.addChild(new DefaultUserMenu("Devices", null, "/user/sso") {
45  @Override
46  public boolean isInRole() {
47  return ElephantContext.getUseSSO();
48  }
49  @Override
50  public Object getDetail() {
51  return null;
52  }
53  });
54  IUserMenu mlangs = session.addChild(new CaptionMenu("Language", null));
55  String[] langs = ElephantContext.getSiteLocales().split(" *, *");
56  mlangs.addChild(new DefaultUserMenu("Browser's default", null, menu -> {
57  Application.deleteCookie("lang", "/");
58  Application.getApplication().sendRedirect("/user");
59  return true;
60  }) {
61  @Override
62  public boolean isInRole() {
63  return true;
64  }
65  @Override
66  public Object getDetail() {
67  return null;
68  }
69  });
70  for(String l : langs) {
71  mlangs.addChild(new DefaultUserMenu(I_.keyValue(l), null, menu -> {
72  Application.setCookie("lang", l, "/", 365*24*60*60);
73  Application.getApplication().sendRedirect("/user");
74  return true;
75  }) {
76  @Override
77  public boolean isInRole() {
78  return true;
79  }
80  @Override
81  public Object getDetail() {
82  return null;
83  }
84  });
85  }
86  session.addChild(new DefaultUserMenu("Cookies", null, "/user/cookies") {
87  @Override
88  public boolean isInRole() {
89  return true;
90  }
91  @Override
92  public Object getDetail() {
93  return null;
94  }
95  });
96  session.addChild(new DefaultUserMenu("Time tracker", null, "/user/timetracker") {
97  @Override
98  public boolean isInRole() {
100  }
101  @Override
102  public Object getDetail() {
103  return null;
104  }
105  });
106  IUserMenu settings = UserMenus.getSettingsMenu();
107  settings.addChild(new DefaultUserMenu("Universe", null, "/user/entity") {
108  @Override
109  public boolean isInRole() {
110  return Application.getApplication().isInRole("@admin:is");
111  }
112  @Override
113  public Object getDetail() {
114  return null;
115  }
116  });
117  IUserMenu mfunnel = settings.addChild(new CaptionMenu("Funneling", null) {
118  @Override
119  public boolean isInRole() {
120  return Application.getApplication().isInRole("@admin:is");
121  }
122  @Override
123  public Object getDetail() {
124  return null;
125  }
126  });
127  mfunnel.addChild(new DefaultUserMenu("Funneling items", null, "/user/web/funnel/items") {
128  @Override
129  public boolean isInRole() {
130  return Application.getApplication().isInRole("@admin:is");
131  }
132  @Override
133  public Object getDetail() {
134  return null;
135  }
136  });
137  mfunnel.addChild(new DefaultUserMenu("Funneling goals", null, "/user/web/funnel/goals") {
138  @Override
139  public boolean isInRole() {
140  return Application.getApplication().isInRole("@admin:is");
141  }
142  @Override
143  public Object getDetail() {
144  return null;
145  }
146  });
147  mfunnel.addChild(new DefaultUserMenu("Funneling test", null, "/user/web/funnel/test") {
148  @Override
149  public boolean isInRole() {
150  return Application.getApplication().isInRole("@admin:is");
151  }
152  @Override
153  public Object getDetail() {
154  return null;
155  }
156  });
157  settings.addChild(new DefaultUserMenu("Importer", null, "/user/importer") {
158  @Override
159  public boolean isInRole() {
160  return true;
161  }
162  @Override
163  public Object getDetail() {
164  return null;
165  }
166  });
167  }
168 
169  @Override
170  public boolean isInRole() {
171  return true;
172  }
173 
174  @Override
175  public Object getDetail() {
176  return null;
177  }
178 
179 }
static void deleteCookie(String name, String path)
static String keyValue(String key)
Definition: I_.java:79
IUserMenu addChild(IUserMenu menu)