/
App.php
239 lines (218 loc) · 7.86 KB
/
App.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<?php
namespace demo;
use \koolreport\dashboard\menu\Group;
use \koolreport\dashboard\pages\Login;
use \koolreport\dashboard\User;
use \koolreport\dashboard\Client;
use \koolreport\dashboard\ExportHandler;
use \koolreport\dashboard\export\LocalExport;
use \koolreport\dashboard\export\ChromeHeadlessio;
use koolreport\dashboard\export\CSVEngine;
use koolreport\dashboard\export\XLSXEngine;
use koolreport\dashboard\menu\MegaMenu;
use \koolreport\dashboard\menu\MenuItem;
use koolreport\amazing\dashboard\Amazing;
use koolreport\appstack\dashboard\AppStack;
use koolreport\dashboard\Cookie;
use koolreport\dashboard\languages\DE;
use koolreport\dashboard\languages\EN;
use koolreport\dashboard\languages\FR;
use koolreport\dashboard\languages\TH;
class App extends \koolreport\dashboard\Application
{
protected function onCreated()
{
$this->debugMode(true)
->footerLeft("
<a class='btn btn-primary btn-sm' target='_blank' href='https://github.com/koolreport/dashboard-demo'>
<i class='fab fa-github'></i> SourceCode
</a>
<a target='_blank' href='https://www.koolreport.com/docs/dashboard/overview/' style='margin-left:5px;' class='btn btn-warning btn-sm'>
<i class='fa fa-file-alt'></i> Docs
</a>
<a target='_blank' href='https://www.koolreport.com/get-koolreport-pro' style='margin-left:5px;' class='btn btn-danger btn-sm'>
<i class='fa fa-shopping-cart'></i> Purchase
</a>
")
->footerRight("
<div class='d-none d-md-block d-lg-block'>Powered by <a target='_blank' href='https://www.koolreport.com'>KoolReport</a></div>
")
->js("//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/highlight.min.js")
->css("https://cdn.koolreport.com/examples/assets/theme/tomorrow.css")
;
}
/**
* This event is called when application is initiated
* We will look for the theme from cookie to set
* @return void
*/
protected function onInit()
{
$themeName = Cookie::themeName();
$themeName = ($themeName !== null) ? $themeName : "Amazing";
$this->setTheme($themeName);
}
protected function login()
{
return Login::create()
->descriptionText("
<i style='color:#333'>
Please log in with <b class='text-danger'>demo</b>/<b class='text-danger'>demo</b>
</i>
")
->failedText("Wrong! Please use <b>demo</b> for both username and password!")
->authenticate(function ($username, $password) {
//Look for user that have username and password
$users = AutoMaker::table("users")
->where("username", $username)
->where("password", $password)
->run();
$user = $users->get(0); //Try to get first user, get associate array contain user information
if ($user !== null) {
//Found a user, return User object
return User::create()
->id($user["id"])
->name($user["displayname"])
->avatar("images/8.jpg")
->roles([$user["role"]]);
}
//Other: fail to login, return null
return null;
});
}
/**
* Provide list of languages for user to choose
* @return array
*/
protected function languages()
{
return [
EN::create(),
DE::create(),
FR::create(),
TH::create(),
];
}
/**
* Return list of all pages.
* Here will have two pages: PublicPage which user can access freely
* and MemberPage which will required user to login access
* @return array
*/
protected function pages()
{
return [
PublicPage::create(),
MemberPage::create(),
];
}
/**
* Return the top menu. By providing the method on app,
* we will use the same top menu on every pages
* @return array
*/
protected function topMenu()
{
return [
"Mega Menu" => MegaMenu::create()->sub([
"Pages" => Group::create()->sub([
"Public" => MenuItem::create()
->icon("fa fa-globe")
->onClick(Client::navigate("App/PublicPage")),
"Member" => MenuItem::create()
->icon("fa fa-lock")
->onClick(Client::navigate("App/MemberPage")),
]),
"Themes" => Group::create()->sub([
"Amazing" => MenuItem::create()->onClick(Client::app()->action("changeTheme", ["name" => "Amazing"])),
"AppStack" => MenuItem::create()->onClick(Client::app()->action("changeTheme", ["name" => "AppStack"])),
])
]),
"About" => MenuItem::create()
->href("https://www.koolreport.com/packages/dashboard")
->target("_blank"),
"Forums" => MenuItem::create()
->href("https://www.koolreport.com/forum/topics")
->target("_blank"),
];
}
/**
* This action will get the user request of changing theme from client
* it will set the theme as well as save the current theme selection
* to cookie. Last, it will reload page to get theme changed.
* @param mixed $request
* @param mixed $response
* @return void
*/
protected function actionChangeTheme($request, $response)
{
$themeName = $request->params("name");
$this->setTheme($themeName);
Cookie::themeName($themeName);
$response->runScript("location.reload()");
}
/**
* Just a function to set correct theme for App
* from the name of theme
* @param mixed $name
* @return void
*/
protected function setTheme($name)
{
switch ($name) {
case "Amazing":
$this->theme(Amazing::create());
break;
case "AppStack":
$this->theme(AppStack::create());
break;
}
}
/**
* Account menu that will appear when user login
* We will use the same account menu on all pages
* @return array
*/
protected function accountMenu()
{
return [
"Logout" => MenuItem::create()
->icon("fa fa-lock")
->onClick(Client::logout())
];
}
protected function export()
{
return ExportHandler::create()
->storage(dirname(__DIR__) . "/storage")
// ->csvEngine(
// CSVEngine::create()
// )
// ->xlsxEngine(
// XLSXEngine::create()
// )
// ->pdfEngine(
// ChromeHeadlessio::create()
// ->token("716168c297fb0486d4cf24458ac2f860364f277f081630d640e16ac313aba310")
// )
// ->engine(
// CSVEngine::create()->defaultConfig([
// // 'delimiter' => ';'
// ])
// )
// ->engine(
// XLSXEngine::create()
// )
// ->engine(
// ChromeHeadlessio::create()
// ->token("716168c297fb0486d4cf24458ac2f860364f277f081630d640e16ac313aba310")
// )
->engine(
CSVEngine::create('CsvEngine'),
XLSXEngine::create('ExcelEngine'),
LocalExport::create('LocalPdfEngine'),
ChromeHeadlessio::create('CloudPdfEngine')
->token("716168c297fb0486d4cf24458ac2f860364f277f081630d640e16ac313aba310")
);
}
}