|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
Lib::loadClass('RouteBase');
|
|
|
Lib::loadClass('UI');
|
|
|
+Lib::loadClass('Response');
|
|
|
|
|
|
class Route_Status extends RouteBase {
|
|
|
|
|
|
@@ -111,10 +112,123 @@ class Route_Status extends RouteBase {
|
|
|
: -1
|
|
|
) ;
|
|
|
});
|
|
|
+ if ('0' == User::get('ADM_ADMIN_LEVEL')) {
|
|
|
+ $sesUsers = array_map(function ($row) {
|
|
|
+ $row['#'] = UI::h('div', [ 'style' => "display:inline-block", 'class' => "activateUserDebugBtn" . ( DBG::hasUserDebug($row['idUser'], User::getID()) ? ' active' : '' ) ], [
|
|
|
+ UI::h('label', ['style' => "padding-right:6px; font-weight:normal"], "Debug"),
|
|
|
+ UI::hButtonAjax("Włącz", "activateUserDebug", [
|
|
|
+ 'class' => "btn btn-xs btn-default activateUserDebugBtn-activate",
|
|
|
+ 'href' => $this->getLink('startUserDebugAjax'),
|
|
|
+ 'data' => [ 'idUser' => $row['idUser'], 'do' => 'activate' ]
|
|
|
+ ]),
|
|
|
+ UI::hButtonAjax("Wyłącz", "activateUserDebug", [
|
|
|
+ 'class' => "btn btn-xs btn-default activateUserDebugBtn-deactivate",
|
|
|
+ 'href' => $this->getLink('startUserDebugAjax'),
|
|
|
+ 'data' => [ 'idUser' => $row['idUser'], 'do' => 'deactivate' ]
|
|
|
+ ]),
|
|
|
+ ]);
|
|
|
+ return $row;
|
|
|
+ }, $sesUsers);
|
|
|
+ }
|
|
|
UI::table([
|
|
|
'caption' => UI::h('b', ['style' => "color:#000"], "Ostatnie logowania do aplikacji") . " <small>(update acl cache)</small>", // TODO: Aktualnie zalogowani użytkownicy
|
|
|
'rows' => $sesUsers
|
|
|
]);
|
|
|
+ echo UI::h('style', ['type' => "text/css"], "
|
|
|
+ .activateUserDebugBtn .activateUserDebugBtn-activate { display:inline }
|
|
|
+ .activateUserDebugBtn .activateUserDebugBtn-deactivate { display:none }
|
|
|
+ .activateUserDebugBtn.active .activateUserDebugBtn-activate { display:none }
|
|
|
+ .activateUserDebugBtn.active .activateUserDebugBtn-deactivate { display:inline }
|
|
|
+ ");
|
|
|
+ echo UI::h('script', ['src'=>"static/vendor.js?_v=b636cab1", 'type'=>"text/javascript"]);
|
|
|
+ echo UI::h('script', [], "
|
|
|
+ (function (global) {
|
|
|
+ if (!global.p5VendorJs.React) throw 'Missing p5VendorJs.React'
|
|
|
+ if (!global.p5VendorJs.ReactDOM) throw 'Missing p5VendorJs.ReactDOM'
|
|
|
+ if (!global.p5VendorJs.ToggleButton) throw 'Missing p5VendorJs.ToggleButton'
|
|
|
+ if (!global.fetch) throw 'Missing global.fetch'
|
|
|
+ var React = global.p5VendorJs.React
|
|
|
+ var ReactDOM = global.p5VendorJs.ReactDOM
|
|
|
+ var h = React.createElement
|
|
|
+
|
|
|
+ function convertToReactToggle(n, activateBtn, deactivateBtn, isActive) {
|
|
|
+ var toggleReact = document.createElement('div')
|
|
|
+ toggleReact.style.display = 'inline-block'
|
|
|
+ n.parentNode.insertBefore(toggleReact, n.nextSibling)
|
|
|
+ deactivateBtn.style.display = 'none'
|
|
|
+ activateBtn.style.display = 'none'
|
|
|
+
|
|
|
+ function reactToggleBtnOnToggle(value) {
|
|
|
+ if (value) {
|
|
|
+ deactivateBtn.onclick()
|
|
|
+ } else {
|
|
|
+ activateBtn.onclick()
|
|
|
+ }
|
|
|
+ render_reactToggleBtn(!value)
|
|
|
+ }
|
|
|
+ function render_reactToggleBtn(state) {
|
|
|
+ ReactDOM.render(
|
|
|
+ h(global.p5VendorJs.ToggleButton, {
|
|
|
+ value: state,
|
|
|
+ onToggle: reactToggleBtnOnToggle
|
|
|
+ })
|
|
|
+ , toggleReact
|
|
|
+ )
|
|
|
+ }
|
|
|
+ render_reactToggleBtn(isActive)
|
|
|
+ }
|
|
|
+
|
|
|
+ var toggles = document.querySelectorAll('.activateUserDebugBtn')
|
|
|
+ for (var i = 0; i < toggles.length; i++) {
|
|
|
+ var btns = toggles[i].querySelectorAll('a')
|
|
|
+ if (2 !== btns.length) contiune;
|
|
|
+ var activateBtn = btns[0]
|
|
|
+ var deactivateBtn = btns[1]
|
|
|
+ convertToReactToggle(toggles[i], activateBtn, deactivateBtn, toggles[i].classList.contains('active'))
|
|
|
+ }
|
|
|
+ })(window)
|
|
|
+ ");
|
|
|
+ UI::hButtonAjaxOnResponse("activateUserDebug", /* payload, n */ "
|
|
|
+ p5UI__notifyAjaxCallback(payload)
|
|
|
+ console.log('activateUserDebug :: payload', payload)
|
|
|
+ if ('success' !== payload.type) return false
|
|
|
+ if (payload.body && 'active' in payload.body) {
|
|
|
+ if (payload.body.active) {
|
|
|
+ n.parentNode.classList.add('active')
|
|
|
+ } else {
|
|
|
+ n.parentNode.classList.remove('active')
|
|
|
+ }
|
|
|
+ // if (!n.parentNode.classList.contains('active')) {
|
|
|
+ // n.parentNode.classList.add('active')
|
|
|
+ // } else {
|
|
|
+ // n.parentNode.classList.remove('active')
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ ");
|
|
|
}
|
|
|
+ public function startUserDebugAjaxAction() {
|
|
|
+ Response::sendTryCatchJson(array($this, 'startUserDebugAjax'), $_POST);
|
|
|
+ }
|
|
|
+ public function startUserDebugAjax($args) {
|
|
|
+ if ('0' !== (string)User::get('ADM_ADMIN_LEVEL')) throw new Exception("Access Denied");
|
|
|
+ $idUser = V::get('idUser', 0, $args);
|
|
|
+ if ($idUser <= 0) throw new Exception("Missing idUser");
|
|
|
+ $do = V::get('do', 0, $args);
|
|
|
+ if (!in_array($do, ['activate', 'deactivate'])) throw new Exception("Missing do");
|
|
|
+
|
|
|
+ $hasDebug = DBG::hasUserDebug($idUser, User::getID());
|
|
|
+ switch ($do) {
|
|
|
+ case 'activate': DBG::startUserDebug($idUser, User::getID()); break;
|
|
|
+ case 'deactivate': DBG::stopUserDebug($idUser, User::getID()); break;
|
|
|
+ }
|
|
|
+ return [
|
|
|
+ 'type' => 'success',
|
|
|
+ '__args' => $args,
|
|
|
+ '__$hasDebug' => $hasDebug,
|
|
|
+ 'body' => [
|
|
|
+ 'active' => DBG::hasUserDebug($idUser, User::getID())
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ }
|
|
|
|
|
|
}
|