diff --git a/.htaccess b/.htaccess index 5ce41cb..de6d1b9 100644 --- a/.htaccess +++ b/.htaccess @@ -1,9 +1,11 @@ php_flag display_errors on Options -Indexes +RedirectMatch 404 /\.idea RedirectMatch 404 /\.git RedirectMatch 404 /src RedirectMatch 404 /test +RedirectMatch 404 /core RewriteEngine On RewriteRule ^api(/.*)?$ /index.php?api=$1 [L,QSA] diff --git a/core/Api/Parameter/Parameter.class.php b/core/Api/Parameter/Parameter.class.php index 8a8c08c..1fdcb7d 100644 --- a/core/Api/Parameter/Parameter.class.php +++ b/core/Api/Parameter/Parameter.class.php @@ -16,6 +16,8 @@ class Parameter { // only internal access const TYPE_RAW = 8; + + // only json will work here i guess const TYPE_ARRAY = 9; const names = array('Integer', 'Float', 'Boolean', 'String', 'Date', 'Time', 'DateTime', 'E-Mail', 'Raw', 'Array'); diff --git a/core/Api/Routes/Fetch.class.php b/core/Api/Routes/Fetch.class.php index 7ff247e..3462263 100644 --- a/core/Api/Routes/Fetch.class.php +++ b/core/Api/Routes/Fetch.class.php @@ -38,7 +38,7 @@ class Fetch extends Request { "request" => $row["request"], "action" => $row["action"], "target" => $row["target"], - "extra" => $row["extra"], + "extra" => $row["extra"] ?? "", "active" => intval($row["active"]), ); } diff --git a/core/Api/Routes/Save.class.php b/core/Api/Routes/Save.class.php new file mode 100644 index 0000000..f32616b --- /dev/null +++ b/core/Api/Routes/Save.class.php @@ -0,0 +1,99 @@ + new Parameter('routes',Parameter::TYPE_ARRAY, false) + )); + + $this->loginRequired = true; + $this->csrfTokenRequired = true; + $this->requiredGroup = USER_GROUP_ADMIN; + } + + public function execute($values = array()) { + if(!parent::execute($values)) { + return false; + } + + if (!$this->validateRoutes()) { + return false; + } + + + $sql = $this->user->getSQL(); + + // DELETE old rules + $this->success = ($sql->truncate("Route")->execute() !== FALSE); + $this->lastError = $sql->getLastError(); + + // INSERT new routes + if ($this->success) { + $stmt = $sql->insert("Route", array("request", "action", "target", "extra", "active")); + foreach($this->routes as $route) { + $stmt->addRow($route["request"], $route["action"], $route["target"], $route["extra"], $route["active"]); + } + $this->success = ($stmt->execute() !== FALSE); + $this->lastError = $sql->getLastError(); + } + + return $this->success; + } + + private function validateRoutes() { + + $this->routes = array(); + $keys = array( + "request" => Parameter::TYPE_STRING, + "action" => Parameter::TYPE_STRING, + "target" => Parameter::TYPE_STRING, + "extra" => Parameter::TYPE_STRING, + "active" => Parameter::TYPE_BOOLEAN + ); + + $actions = array( + "redirect_temporary", "redirect_permanently", "static", "dynamic" + ); + + foreach($this->getParam("routes") as $index => $route) { + foreach($keys as $key => $expectedType) { + if (!array_key_exists($key, $route)) { + return $this->createError("Route $index missing key: $key"); + } + + $value = $route[$key]; + $type = Parameter::parseType($value); + if ($type !== $expectedType && ($key !== "active" || !is_null($value))) { + $expectedTypeName = Parameter::names[$expectedType]; + $gotTypeName = Parameter::names[$type]; + return $this->createError("Route $index has invalid value for key: $key, expected: $expectedTypeName, got: $gotTypeName"); + } + } + + $action = $route["action"]; + if (!in_array($action, $actions)) { + return $this->createError("Invalid action: $action"); + } + + if(empty($route["request"])) { + return $this->createError("Request cannot be empty."); + } + + if(empty($route["target"])) { + return $this->createError("Target cannot be empty."); + } + + $this->routes[] = $route; + } + + return true; + } +} \ No newline at end of file diff --git a/core/Configuration/CreateDatabase.class.php b/core/Configuration/CreateDatabase.class.php index 7a9c36d..e6e0556 100755 --- a/core/Configuration/CreateDatabase.class.php +++ b/core/Configuration/CreateDatabase.class.php @@ -129,8 +129,7 @@ class CreateDatabase { ->primaryKey("uid"); $queries[] = $sql->insert("Route", array("request", "action", "target")) - ->addRow("/admin(/.*)?", "dynamic", "\\Core\\Documents\\AdminDashboard") - ->addRow("/api/(.*)", "dynamic", "\\Core\\Api\\$1"); + ->addRow("/admin(/.*)?", "dynamic", "\\Documents\\AdminDashboard"); return $queries; } diff --git a/js/admin.min.js b/js/admin.min.js index db3f285..2f5eef0 100644 --- a/js/admin.min.js +++ b/js/admin.min.js @@ -7559,7 +7559,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return API; });\n/* harmony import */ var babel_polyfill__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babel-polyfill */ \"./node_modules/babel-polyfill/lib/index.js\");\n/* harmony import */ var babel_polyfill__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babel_polyfill__WEBPACK_IMPORTED_MODULE_0__);\nfunction asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }\n\nfunction _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, \"next\", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, \"throw\", err); } _next(undefined); }); }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\n\n\nvar API = /*#__PURE__*/function () {\n function API() {\n _classCallCheck(this, API);\n\n this.loggedIn = false;\n this.user = {};\n }\n\n _createClass(API, [{\n key: \"csrfToken\",\n value: function csrfToken() {\n return this.loggedIn ? this.user.session.csrf_token : null;\n }\n }, {\n key: \"apiCall\",\n value: function () {\n var _apiCall = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(method, params) {\n var response;\n return regeneratorRuntime.wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n params = params || {};\n params.csrf_token = this.csrfToken();\n _context.next = 4;\n return fetch(\"/api/\" + method, {\n method: 'post',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify(params)\n });\n\n case 4:\n response = _context.sent;\n _context.next = 7;\n return response.json();\n\n case 7:\n return _context.abrupt(\"return\", _context.sent);\n\n case 8:\n case \"end\":\n return _context.stop();\n }\n }\n }, _callee, this);\n }));\n\n function apiCall(_x, _x2) {\n return _apiCall.apply(this, arguments);\n }\n\n return apiCall;\n }()\n }, {\n key: \"fetchUser\",\n value: function () {\n var _fetchUser = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {\n var response, data;\n return regeneratorRuntime.wrap(function _callee2$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n _context2.next = 2;\n return fetch(\"/api/user/info\");\n\n case 2:\n response = _context2.sent;\n _context2.next = 5;\n return response.json();\n\n case 5:\n data = _context2.sent;\n this.user = data[\"user\"];\n this.loggedIn = data[\"loggedIn\"];\n return _context2.abrupt(\"return\", data && data.success && data.loggedIn);\n\n case 9:\n case \"end\":\n return _context2.stop();\n }\n }\n }, _callee2, this);\n }));\n\n function fetchUser() {\n return _fetchUser.apply(this, arguments);\n }\n\n return fetchUser;\n }()\n }, {\n key: \"logout\",\n value: function () {\n var _logout = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {\n return regeneratorRuntime.wrap(function _callee3$(_context3) {\n while (1) {\n switch (_context3.prev = _context3.next) {\n case 0:\n return _context3.abrupt(\"return\", this.apiCall(\"user/logout\"));\n\n case 1:\n case \"end\":\n return _context3.stop();\n }\n }\n }, _callee3, this);\n }));\n\n function logout() {\n return _logout.apply(this, arguments);\n }\n\n return logout;\n }()\n }, {\n key: \"getNotifications\",\n value: function () {\n var _getNotifications = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {\n return regeneratorRuntime.wrap(function _callee4$(_context4) {\n while (1) {\n switch (_context4.prev = _context4.next) {\n case 0:\n return _context4.abrupt(\"return\", this.apiCall(\"notifications/fetch\"));\n\n case 1:\n case \"end\":\n return _context4.stop();\n }\n }\n }, _callee4, this);\n }));\n\n function getNotifications() {\n return _getNotifications.apply(this, arguments);\n }\n\n return getNotifications;\n }()\n }, {\n key: \"fetchUsers\",\n value: function () {\n var _fetchUsers = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {\n var pageNum,\n _args5 = arguments;\n return regeneratorRuntime.wrap(function _callee5$(_context5) {\n while (1) {\n switch (_context5.prev = _context5.next) {\n case 0:\n pageNum = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : 1;\n return _context5.abrupt(\"return\", this.apiCall(\"user/fetch\", {\n page: pageNum\n }));\n\n case 2:\n case \"end\":\n return _context5.stop();\n }\n }\n }, _callee5, this);\n }));\n\n function fetchUsers() {\n return _fetchUsers.apply(this, arguments);\n }\n\n return fetchUsers;\n }()\n }, {\n key: \"fetchGroups\",\n value: function () {\n var _fetchGroups = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {\n var pageNum,\n _args6 = arguments;\n return regeneratorRuntime.wrap(function _callee6$(_context6) {\n while (1) {\n switch (_context6.prev = _context6.next) {\n case 0:\n pageNum = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : 1;\n return _context6.abrupt(\"return\", this.apiCall(\"groups/fetch\", {\n page: pageNum\n }));\n\n case 2:\n case \"end\":\n return _context6.stop();\n }\n }\n }, _callee6, this);\n }));\n\n function fetchGroups() {\n return _fetchGroups.apply(this, arguments);\n }\n\n return fetchGroups;\n }()\n }, {\n key: \"inviteUser\",\n value: function () {\n var _inviteUser = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(username, email) {\n return regeneratorRuntime.wrap(function _callee7$(_context7) {\n while (1) {\n switch (_context7.prev = _context7.next) {\n case 0:\n return _context7.abrupt(\"return\", this.apiCall(\"user/invite\", {\n username: username,\n email: email\n }));\n\n case 1:\n case \"end\":\n return _context7.stop();\n }\n }\n }, _callee7, this);\n }));\n\n function inviteUser(_x3, _x4) {\n return _inviteUser.apply(this, arguments);\n }\n\n return inviteUser;\n }()\n }, {\n key: \"createUser\",\n value: function () {\n var _createUser = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(username, email, password, confirmPassword) {\n return regeneratorRuntime.wrap(function _callee8$(_context8) {\n while (1) {\n switch (_context8.prev = _context8.next) {\n case 0:\n return _context8.abrupt(\"return\", this.apiCall(\"user/create\", {\n username: username,\n email: email,\n password: password,\n confirmPassword: confirmPassword\n }));\n\n case 1:\n case \"end\":\n return _context8.stop();\n }\n }\n }, _callee8, this);\n }));\n\n function createUser(_x5, _x6, _x7, _x8) {\n return _createUser.apply(this, arguments);\n }\n\n return createUser;\n }()\n }, {\n key: \"getStats\",\n value: function () {\n var _getStats = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() {\n return regeneratorRuntime.wrap(function _callee9$(_context9) {\n while (1) {\n switch (_context9.prev = _context9.next) {\n case 0:\n return _context9.abrupt(\"return\", this.apiCall(\"stats\"));\n\n case 1:\n case \"end\":\n return _context9.stop();\n }\n }\n }, _callee9, this);\n }));\n\n function getStats() {\n return _getStats.apply(this, arguments);\n }\n\n return getStats;\n }()\n }, {\n key: \"getRoutes\",\n value: function () {\n var _getRoutes = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {\n return regeneratorRuntime.wrap(function _callee10$(_context10) {\n while (1) {\n switch (_context10.prev = _context10.next) {\n case 0:\n return _context10.abrupt(\"return\", this.apiCall(\"routes/fetch\"));\n\n case 1:\n case \"end\":\n return _context10.stop();\n }\n }\n }, _callee10, this);\n }));\n\n function getRoutes() {\n return _getRoutes.apply(this, arguments);\n }\n\n return getRoutes;\n }()\n }]);\n\n return API;\n}();\n\n\n;\n\n//# sourceURL=webpack:///./src/api.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return API; });\n/* harmony import */ var babel_polyfill__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babel-polyfill */ \"./node_modules/babel-polyfill/lib/index.js\");\n/* harmony import */ var babel_polyfill__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babel_polyfill__WEBPACK_IMPORTED_MODULE_0__);\nfunction asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }\n\nfunction _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, \"next\", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, \"throw\", err); } _next(undefined); }); }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\n\n\nvar API = /*#__PURE__*/function () {\n function API() {\n _classCallCheck(this, API);\n\n this.loggedIn = false;\n this.user = {};\n }\n\n _createClass(API, [{\n key: \"csrfToken\",\n value: function csrfToken() {\n return this.loggedIn ? this.user.session.csrf_token : null;\n }\n }, {\n key: \"apiCall\",\n value: function () {\n var _apiCall = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(method, params) {\n var response;\n return regeneratorRuntime.wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n params = params || {};\n params.csrf_token = this.csrfToken();\n _context.next = 4;\n return fetch(\"/api/\" + method, {\n method: 'post',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify(params)\n });\n\n case 4:\n response = _context.sent;\n _context.next = 7;\n return response.json();\n\n case 7:\n return _context.abrupt(\"return\", _context.sent);\n\n case 8:\n case \"end\":\n return _context.stop();\n }\n }\n }, _callee, this);\n }));\n\n function apiCall(_x, _x2) {\n return _apiCall.apply(this, arguments);\n }\n\n return apiCall;\n }()\n }, {\n key: \"fetchUser\",\n value: function () {\n var _fetchUser = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {\n var response, data;\n return regeneratorRuntime.wrap(function _callee2$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n _context2.next = 2;\n return fetch(\"/api/user/info\");\n\n case 2:\n response = _context2.sent;\n _context2.next = 5;\n return response.json();\n\n case 5:\n data = _context2.sent;\n this.user = data[\"user\"];\n this.loggedIn = data[\"loggedIn\"];\n return _context2.abrupt(\"return\", data && data.success && data.loggedIn);\n\n case 9:\n case \"end\":\n return _context2.stop();\n }\n }\n }, _callee2, this);\n }));\n\n function fetchUser() {\n return _fetchUser.apply(this, arguments);\n }\n\n return fetchUser;\n }()\n }, {\n key: \"logout\",\n value: function () {\n var _logout = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {\n return regeneratorRuntime.wrap(function _callee3$(_context3) {\n while (1) {\n switch (_context3.prev = _context3.next) {\n case 0:\n return _context3.abrupt(\"return\", this.apiCall(\"user/logout\"));\n\n case 1:\n case \"end\":\n return _context3.stop();\n }\n }\n }, _callee3, this);\n }));\n\n function logout() {\n return _logout.apply(this, arguments);\n }\n\n return logout;\n }()\n }, {\n key: \"getNotifications\",\n value: function () {\n var _getNotifications = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {\n return regeneratorRuntime.wrap(function _callee4$(_context4) {\n while (1) {\n switch (_context4.prev = _context4.next) {\n case 0:\n return _context4.abrupt(\"return\", this.apiCall(\"notifications/fetch\"));\n\n case 1:\n case \"end\":\n return _context4.stop();\n }\n }\n }, _callee4, this);\n }));\n\n function getNotifications() {\n return _getNotifications.apply(this, arguments);\n }\n\n return getNotifications;\n }()\n }, {\n key: \"fetchUsers\",\n value: function () {\n var _fetchUsers = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {\n var pageNum,\n _args5 = arguments;\n return regeneratorRuntime.wrap(function _callee5$(_context5) {\n while (1) {\n switch (_context5.prev = _context5.next) {\n case 0:\n pageNum = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : 1;\n return _context5.abrupt(\"return\", this.apiCall(\"user/fetch\", {\n page: pageNum\n }));\n\n case 2:\n case \"end\":\n return _context5.stop();\n }\n }\n }, _callee5, this);\n }));\n\n function fetchUsers() {\n return _fetchUsers.apply(this, arguments);\n }\n\n return fetchUsers;\n }()\n }, {\n key: \"fetchGroups\",\n value: function () {\n var _fetchGroups = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {\n var pageNum,\n _args6 = arguments;\n return regeneratorRuntime.wrap(function _callee6$(_context6) {\n while (1) {\n switch (_context6.prev = _context6.next) {\n case 0:\n pageNum = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : 1;\n return _context6.abrupt(\"return\", this.apiCall(\"groups/fetch\", {\n page: pageNum\n }));\n\n case 2:\n case \"end\":\n return _context6.stop();\n }\n }\n }, _callee6, this);\n }));\n\n function fetchGroups() {\n return _fetchGroups.apply(this, arguments);\n }\n\n return fetchGroups;\n }()\n }, {\n key: \"inviteUser\",\n value: function () {\n var _inviteUser = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(username, email) {\n return regeneratorRuntime.wrap(function _callee7$(_context7) {\n while (1) {\n switch (_context7.prev = _context7.next) {\n case 0:\n return _context7.abrupt(\"return\", this.apiCall(\"user/invite\", {\n username: username,\n email: email\n }));\n\n case 1:\n case \"end\":\n return _context7.stop();\n }\n }\n }, _callee7, this);\n }));\n\n function inviteUser(_x3, _x4) {\n return _inviteUser.apply(this, arguments);\n }\n\n return inviteUser;\n }()\n }, {\n key: \"createUser\",\n value: function () {\n var _createUser = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(username, email, password, confirmPassword) {\n return regeneratorRuntime.wrap(function _callee8$(_context8) {\n while (1) {\n switch (_context8.prev = _context8.next) {\n case 0:\n return _context8.abrupt(\"return\", this.apiCall(\"user/create\", {\n username: username,\n email: email,\n password: password,\n confirmPassword: confirmPassword\n }));\n\n case 1:\n case \"end\":\n return _context8.stop();\n }\n }\n }, _callee8, this);\n }));\n\n function createUser(_x5, _x6, _x7, _x8) {\n return _createUser.apply(this, arguments);\n }\n\n return createUser;\n }()\n }, {\n key: \"getStats\",\n value: function () {\n var _getStats = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() {\n return regeneratorRuntime.wrap(function _callee9$(_context9) {\n while (1) {\n switch (_context9.prev = _context9.next) {\n case 0:\n return _context9.abrupt(\"return\", this.apiCall(\"stats\"));\n\n case 1:\n case \"end\":\n return _context9.stop();\n }\n }\n }, _callee9, this);\n }));\n\n function getStats() {\n return _getStats.apply(this, arguments);\n }\n\n return getStats;\n }()\n }, {\n key: \"getRoutes\",\n value: function () {\n var _getRoutes = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {\n return regeneratorRuntime.wrap(function _callee10$(_context10) {\n while (1) {\n switch (_context10.prev = _context10.next) {\n case 0:\n return _context10.abrupt(\"return\", this.apiCall(\"routes/fetch\"));\n\n case 1:\n case \"end\":\n return _context10.stop();\n }\n }\n }, _callee10, this);\n }));\n\n function getRoutes() {\n return _getRoutes.apply(this, arguments);\n }\n\n return getRoutes;\n }()\n }, {\n key: \"saveRoutes\",\n value: function () {\n var _saveRoutes = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11(routes) {\n return regeneratorRuntime.wrap(function _callee11$(_context11) {\n while (1) {\n switch (_context11.prev = _context11.next) {\n case 0:\n return _context11.abrupt(\"return\", this.apiCall(\"routes/save\", {\n \"routes\": routes\n }));\n\n case 1:\n case \"end\":\n return _context11.stop();\n }\n }\n }, _callee11, this);\n }));\n\n function saveRoutes(_x9) {\n return _saveRoutes.apply(this, arguments);\n }\n\n return saveRoutes;\n }()\n }]);\n\n return API;\n}();\n\n\n;\n\n//# sourceURL=webpack:///./src/api.js?"); /***/ }), @@ -7713,7 +7713,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return PageOverview; });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _elements_alert__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../elements/alert */ \"./src/elements/alert.js\");\n/* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! react-router-dom */ \"./node_modules/react-router-dom/esm/react-router-dom.js\");\n/* harmony import */ var _elements_icon__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../elements/icon */ \"./src/elements/icon.js\");\n/* harmony import */ var react_tooltip__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! react-tooltip */ \"./node_modules/react-tooltip/dist/index.es.js\");\n/* harmony import */ var react_select__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! react-select */ \"./node_modules/react-select/dist/react-select.browser.esm.js\");\nfunction _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }\n\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nfunction _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\n\n\n\n\n\n\n\nvar PageOverview = /*#__PURE__*/function (_React$Component) {\n _inherits(PageOverview, _React$Component);\n\n var _super = _createSuper(PageOverview);\n\n function PageOverview(props) {\n var _this;\n\n _classCallCheck(this, PageOverview);\n\n _this = _super.call(this, props);\n _this.parent = {\n api: props.api\n };\n _this.state = {\n routes: [],\n errors: []\n };\n _this.options = {\n \"redirect_temporary\": \"Redirect Temporary\",\n \"redirect_permanently\": \"Redirect Permanently\",\n \"static\": \"Serve Static\",\n \"dynamic\": \"Load Dynamic\"\n };\n return _this;\n }\n\n _createClass(PageOverview, [{\n key: \"buildOption\",\n value: function buildOption(key) {\n if (_typeof(key) === 'object' && key.hasOwnProperty(\"key\") && key.hasOwnProperty(\"label\")) {\n return key;\n } else {\n return {\n value: key,\n label: this.options[key]\n };\n }\n }\n }, {\n key: \"removeError\",\n value: function removeError(i) {\n if (i >= 0 && i < this.state.errors.length) {\n var errors = this.state.errors.slice();\n errors.splice(i, 1);\n this.setState(_objectSpread(_objectSpread({}, this.state), {}, {\n errors: errors\n }));\n }\n }\n }, {\n key: \"componentDidMount\",\n value: function componentDidMount() {\n var _this2 = this;\n\n this.parent.api.getRoutes().then(function (res) {\n if (res.success) {\n _this2.setState(_objectSpread(_objectSpread({}, _this2.state), {}, {\n routes: res.routes\n }));\n } else {\n var errors = _this2.state.errors.slice();\n\n errors.push({\n title: \"Error fetching routes\",\n message: res.msg\n });\n\n _this2.setState(_objectSpread(_objectSpread({}, _this2.state), {}, {\n errors: errors\n }));\n }\n });\n }\n }, {\n key: \"render\",\n value: function render() {\n var _this3 = this;\n\n var errors = [];\n var rows = [];\n\n var _loop = function _loop(i) {\n errors.push( /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_alert__WEBPACK_IMPORTED_MODULE_1__[\"default\"], _extends({\n key: \"error-\" + i,\n onClose: function onClose() {\n return _this3.removeError(i);\n }\n }, _this3.state.errors[i])));\n };\n\n for (var i = 0; i < this.state.errors.length; i++) {\n _loop(i);\n }\n\n var options = [];\n\n for (var key in Object.keys(this.options)) {\n options.push(this.buildOption(key));\n }\n\n var _loop2 = function _loop2(_i) {\n var route = _this3.state.routes[_i];\n rows.push( /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"tr\", {\n key: \"route-\" + _i\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", {\n className: \"align-middle\"\n }, route.request), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", {\n className: \"text-center\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](react_select__WEBPACK_IMPORTED_MODULE_5__[\"default\"], {\n options: options,\n value: _this3.buildOption(route.action),\n onChange: function onChange(selectedOption) {\n return _this3.changeAction(_i, selectedOption);\n }\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", {\n className: \"align-middle\"\n }, route.target), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", {\n className: \"align-middle\"\n }, route.extra), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", {\n className: \"text-center\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"input\", {\n type: \"checkbox\",\n checked: route.active === 1,\n onChange: function onChange(e) {\n return _this3.changeActive(_i, e);\n }\n }))));\n };\n\n for (var _i = 0; _i < this.state.routes.length; _i++) {\n _loop2(_i);\n }\n\n return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](react__WEBPACK_IMPORTED_MODULE_0__[\"Fragment\"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"content-header\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"container-fluid\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"row mb-2\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"col-sm-6\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"h1\", {\n className: \"m-0 text-dark\"\n }, \"Routes & Pages\")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"col-sm-6\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"ol\", {\n className: \"breadcrumb float-sm-right\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"li\", {\n className: \"breadcrumb-item\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](react_router_dom__WEBPACK_IMPORTED_MODULE_2__[\"Link\"], {\n to: \"/admin/dashboard\"\n }, \"Home\")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"li\", {\n className: \"breadcrumb-item active\"\n }, \"Pages\")))))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"content\"\n }, errors, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"content-fluid\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"row\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"col-lg-8 col-12\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"table\", {\n className: \"table\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"thead\", {\n className: \"thead-dark\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"tr\", null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", null, \"Request\\xA0\", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"question-circle\",\n style: {\n \"color\": \"#0069d9\"\n },\n \"data-tip\": \"The request, the user is making. Can also be interpreted as a regular expression.\",\n \"data-type\": \"info\",\n \"data-place\": \"bottom\",\n \"data-effect\": \"solid\"\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", {\n style: {\n minWidth: \"250px\"\n }\n }, \"Action\\xA0\", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"question-circle\",\n style: {\n \"color\": \"#0069d9\"\n },\n \"data-tip\": \"The action to be taken\",\n \"data-type\": \"info\",\n \"data-place\": \"bottom\",\n \"data-effect\": \"solid\"\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", null, \"Target\\xA0\", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"question-circle\",\n style: {\n \"color\": \"#0069d9\"\n },\n \"data-tip\": \"Any URL if action is redirect or static. Path to a class inheriting from Document, \" + \"if dynamic is chosen\",\n \"data-type\": \"info\",\n \"data-place\": \"bottom\",\n \"data-effect\": \"solid\"\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", null, \"Extra\\xA0\", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"question-circle\",\n style: {\n \"color\": \"#0069d9\"\n },\n \"data-tip\": \"If action is dynamic, a view name can be entered here, otherwise leave empty.\",\n \"data-type\": \"info\",\n \"data-place\": \"bottom\",\n \"data-effect\": \"solid\"\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", {\n className: \"text-center\"\n }, \"Active\\xA0\", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"question-circle\",\n style: {\n \"color\": \"#0069d9\"\n },\n \"data-tip\": \"True, if the route is currently active.\",\n \"data-type\": \"info\",\n \"data-place\": \"bottom\",\n \"data-effect\": \"solid\"\n })))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"tbody\", null, rows)))))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](react_tooltip__WEBPACK_IMPORTED_MODULE_4__[\"default\"], null));\n }\n }, {\n key: \"changeAction\",\n value: function changeAction(index, selectedOption) {\n if (index < 0 || index >= this.state.routes.length) return;\n var routes = this.state.routes.slice();\n routes[index].action = selectedOption;\n this.setState(_objectSpread(_objectSpread({}, this.state), {}, {\n routes: routes\n }));\n }\n }, {\n key: \"changeActive\",\n value: function changeActive(index, e) {\n if (index < 0 || index >= this.state.routes.length) return;\n var routes = this.state.routes.slice();\n routes[index].active = e.target.checked ? 1 : 0;\n this.setState(_objectSpread(_objectSpread({}, this.state), {}, {\n routes: routes\n }));\n }\n }]);\n\n return PageOverview;\n}(react__WEBPACK_IMPORTED_MODULE_0__[\"Component\"]);\n\n\n\n//# sourceURL=webpack:///./src/views/pages.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return PageOverview; });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _elements_alert__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../elements/alert */ \"./src/elements/alert.js\");\n/* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! react-router-dom */ \"./node_modules/react-router-dom/esm/react-router-dom.js\");\n/* harmony import */ var _elements_icon__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../elements/icon */ \"./src/elements/icon.js\");\n/* harmony import */ var react_tooltip__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! react-tooltip */ \"./node_modules/react-tooltip/dist/index.es.js\");\n/* harmony import */ var react_select__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! react-select */ \"./node_modules/react-select/dist/react-select.browser.esm.js\");\nfunction _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }\n\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nfunction _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\n\n\n\n\n\n\n\nvar PageOverview = /*#__PURE__*/function (_React$Component) {\n _inherits(PageOverview, _React$Component);\n\n var _super = _createSuper(PageOverview);\n\n function PageOverview(props) {\n var _this;\n\n _classCallCheck(this, PageOverview);\n\n _this = _super.call(this, props);\n _this.parent = {\n api: props.api\n };\n _this.state = {\n routes: [],\n errors: [],\n isResetting: false,\n isSaving: false\n };\n _this.optionMap = {\n \"redirect_temporary\": \"Redirect Temporary\",\n \"redirect_permanently\": \"Redirect Permanently\",\n \"static\": \"Serve Static\",\n \"dynamic\": \"Load Dynamic\"\n };\n _this.options = [];\n\n for (var key in _this.optionMap) {\n _this.options.push(_this.buildOption(key));\n }\n\n return _this;\n }\n\n _createClass(PageOverview, [{\n key: \"buildOption\",\n value: function buildOption(key) {\n if (_typeof(key) === 'object' && key.hasOwnProperty(\"key\") && key.hasOwnProperty(\"label\")) {\n return key;\n } else if (typeof key === 'string') {\n return {\n value: key,\n label: this.optionMap[key]\n };\n } else {\n return this.options[key];\n }\n }\n }, {\n key: \"removeError\",\n value: function removeError(i) {\n if (i >= 0 && i < this.state.errors.length) {\n var errors = this.state.errors.slice();\n errors.splice(i, 1);\n this.setState(_objectSpread(_objectSpread({}, this.state), {}, {\n errors: errors\n }));\n }\n }\n }, {\n key: \"componentDidMount\",\n value: function componentDidMount() {\n this.fetchRoutes();\n }\n }, {\n key: \"render\",\n value: function render() {\n var _this2 = this;\n\n var errors = [];\n var rows = [];\n\n var _loop = function _loop(i) {\n errors.push( /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_alert__WEBPACK_IMPORTED_MODULE_1__[\"default\"], _extends({\n key: \"error-\" + i,\n onClose: function onClose() {\n return _this2.removeError(i);\n }\n }, _this2.state.errors[i])));\n };\n\n for (var i = 0; i < this.state.errors.length; i++) {\n _loop(i);\n }\n\n var inputStyle = {\n fontFamily: \"Courier\",\n paddingTop: \"14px\"\n };\n\n var _loop2 = function _loop2(_i) {\n var route = _this2.state.routes[_i];\n rows.push( /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"tr\", {\n key: \"route-\" + _i\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", {\n className: \"align-middle\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"input\", {\n type: \"text\",\n maxLength: 128,\n style: inputStyle,\n className: \"form-control\",\n value: route.request,\n onChange: function onChange(e) {\n return _this2.changeRequest(_i, e);\n }\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", {\n className: \"text-center\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](react_select__WEBPACK_IMPORTED_MODULE_5__[\"default\"], {\n options: _this2.options,\n value: _this2.buildOption(route.action),\n onChange: function onChange(selectedOption) {\n return _this2.changeAction(_i, selectedOption);\n }\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", {\n className: \"align-middle\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"input\", {\n type: \"text\",\n maxLength: 128,\n style: inputStyle,\n className: \"form-control\",\n value: route.target,\n onChange: function onChange(e) {\n return _this2.changeTarget(_i, e);\n }\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", {\n className: \"align-middle\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"input\", {\n type: \"text\",\n maxLength: 64,\n style: inputStyle,\n className: \"form-control\",\n value: route.extra,\n onChange: function onChange(e) {\n return _this2.changeExtra(_i, e);\n }\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", {\n className: \"text-center\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"input\", {\n type: \"checkbox\",\n checked: route.active === 1,\n onChange: function onChange(e) {\n return _this2.changeActive(_i, e);\n }\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"td\", null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](react_tooltip__WEBPACK_IMPORTED_MODULE_4__[\"default\"], {\n id: \"delete-\" + _i\n }), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"trash\",\n style: {\n color: \"red\",\n cursor: \"pointer\"\n },\n \"data-tip\": \"Click to delete this route\",\n \"data-type\": \"warning\",\n \"data-place\": \"right\",\n \"data-for\": \"delete-\" + _i,\n \"data-effect\": \"solid\",\n onClick: function onClick() {\n return _this2.removeRoute(_i);\n }\n }))));\n };\n\n for (var _i = 0; _i < this.state.routes.length; _i++) {\n _loop2(_i);\n }\n\n return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](react__WEBPACK_IMPORTED_MODULE_0__[\"Fragment\"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"content-header\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"container-fluid\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"row mb-2\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"col-sm-6\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"h1\", {\n className: \"m-0 text-dark\"\n }, \"Routes & Pages\")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"col-sm-6\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"ol\", {\n className: \"breadcrumb float-sm-right\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"li\", {\n className: \"breadcrumb-item\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](react_router_dom__WEBPACK_IMPORTED_MODULE_2__[\"Link\"], {\n to: \"/admin/dashboard\"\n }, \"Home\")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"li\", {\n className: \"breadcrumb-item active\"\n }, \"Pages\")))))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"content\"\n }, errors, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"content-fluid\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"row\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"col-lg-10 col-12\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"table\", {\n className: \"table\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"thead\", {\n className: \"thead-dark\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"tr\", null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"th\", null, \"Request\\xA0\", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"question-circle\",\n style: {\n \"color\": \"#17a2b8\"\n },\n \"data-tip\": \"The request, the user is making. Can also be interpreted as a regular expression.\",\n \"data-type\": \"info\",\n \"data-place\": \"bottom\"\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"th\", {\n style: {\n minWidth: \"250px\"\n }\n }, \"Action\\xA0\", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"question-circle\",\n style: {\n \"color\": \"#17a2b8\"\n },\n \"data-tip\": \"The action to be taken\",\n \"data-type\": \"info\",\n \"data-place\": \"bottom\"\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"th\", null, \"Target\\xA0\", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"question-circle\",\n style: {\n \"color\": \"#17a2b8\"\n },\n \"data-tip\": \"Any URL if action is redirect or static. Path to a class inheriting from Document, \" + \"if dynamic is chosen\",\n \"data-type\": \"info\",\n \"data-place\": \"bottom\"\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"th\", null, \"Extra\\xA0\", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"question-circle\",\n style: {\n \"color\": \"#17a2b8\"\n },\n \"data-tip\": \"If action is dynamic, a view name can be entered here, otherwise leave empty.\",\n \"data-type\": \"info\",\n \"data-place\": \"bottom\"\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"th\", {\n className: \"text-center\"\n }, \"Active\\xA0\", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"question-circle\",\n style: {\n \"color\": \"#17a2b8\"\n },\n \"data-tip\": \"True, if the route is currently active.\",\n \"data-type\": \"info\",\n \"data-place\": \"bottom\"\n })), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"th\", null))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"tbody\", null, rows)), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"button\", {\n className: \"btn btn-info\",\n onClick: function onClick() {\n return _this2.onAddRoute();\n },\n disabled: this.state.isResetting || this.state.isSaving\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"plus\"\n }), \"\\xA0Add new Route\"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"button\", {\n className: \"btn btn-secondary ml-2\",\n onClick: function onClick() {\n return _this2.onResetRoutes();\n },\n disabled: this.state.isResetting || this.state.isSaving\n }, this.state.isResetting ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"span\", null, \"Resetting\\xA0\", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"circle-notch\"\n })) : \"Reset\"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"button\", {\n className: \"btn btn-success ml-2\",\n onClick: function onClick() {\n return _this2.onSaveRoutes();\n },\n disabled: this.state.isResetting || this.state.isSaving\n }, this.state.isSaving ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"span\", null, \"Saving\\xA0\", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_3__[\"default\"], {\n icon: \"circle-notch\"\n })) : \"Save\")))))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](react_tooltip__WEBPACK_IMPORTED_MODULE_4__[\"default\"], {\n \"data-effect\": \"solid\"\n }));\n }\n }, {\n key: \"onResetRoutes\",\n value: function onResetRoutes() {\n this.setState(_objectSpread(_objectSpread({}, this.state), {}, {\n isResetting: true\n }));\n this.fetchRoutes();\n }\n }, {\n key: \"onSaveRoutes\",\n value: function onSaveRoutes() {\n var _this3 = this;\n\n this.setState(_objectSpread(_objectSpread({}, this.state), {}, {\n isSaving: true\n }));\n var routes = [];\n\n for (var i = 0; i < this.state.routes.length; i++) {\n var _route$extra;\n\n var route = this.state.routes[i];\n routes.push({\n request: route.request,\n action: _typeof(route.action) === 'object' ? route.action.value : route.action,\n target: route.target,\n extra: (_route$extra = route.extra) !== null && _route$extra !== void 0 ? _route$extra : \"\",\n active: route.active === 1\n });\n }\n\n this.parent.api.saveRoutes(routes).then(function (res) {\n if (res.success) {\n _this3.setState(_objectSpread(_objectSpread({}, _this3.state), {}, {\n isSaving: false\n }));\n } else {\n var errors = _this3.state.errors.slice();\n\n errors.push({\n title: \"Error saving routes\",\n message: res.msg\n });\n\n _this3.setState(_objectSpread(_objectSpread({}, _this3.state), {}, {\n errors: errors,\n isSaving: false\n }));\n }\n });\n }\n }, {\n key: \"changeRoute\",\n value: function changeRoute(index, key, value) {\n if (index < 0 || index >= this.state.routes.length) return;\n var routes = this.state.routes.slice();\n routes[index][key] = value;\n this.setState(_objectSpread(_objectSpread({}, this.state), {}, {\n routes: routes\n }));\n }\n }, {\n key: \"removeRoute\",\n value: function removeRoute(index) {\n if (index < 0 || index >= this.state.routes.length) return;\n var routes = this.state.routes.slice();\n routes.splice(index, 1);\n this.setState(_objectSpread(_objectSpread({}, this.state), {}, {\n routes: routes\n }));\n }\n }, {\n key: \"onAddRoute\",\n value: function onAddRoute() {\n var routes = this.state.routes.slice();\n routes.push({\n request: \"\",\n action: \"dynamic\",\n target: \"\",\n extra: \"\",\n active: true\n });\n this.setState(_objectSpread(_objectSpread({}, this.state), {}, {\n routes: routes\n }));\n }\n }, {\n key: \"changeAction\",\n value: function changeAction(index, selectedOption) {\n this.changeRoute(index, \"action\", selectedOption);\n }\n }, {\n key: \"changeActive\",\n value: function changeActive(index, e) {\n this.changeRoute(index, \"active\", e.target.checked ? 1 : 0);\n }\n }, {\n key: \"changeRequest\",\n value: function changeRequest(index, e) {\n this.changeRoute(index, \"request\", e.target.value);\n }\n }, {\n key: \"changeTarget\",\n value: function changeTarget(index, e) {\n this.changeRoute(index, \"target\", e.target.value);\n }\n }, {\n key: \"changeExtra\",\n value: function changeExtra(index, e) {\n this.changeRoute(index, \"extra\", e.target.value);\n }\n }, {\n key: \"fetchRoutes\",\n value: function fetchRoutes() {\n var _this4 = this;\n\n this.parent.api.getRoutes().then(function (res) {\n if (res.success) {\n _this4.setState(_objectSpread(_objectSpread({}, _this4.state), {}, {\n routes: res.routes,\n isResetting: false\n }));\n\n react_tooltip__WEBPACK_IMPORTED_MODULE_4__[\"default\"].rebuild();\n } else {\n var errors = _this4.state.errors.slice();\n\n errors.push({\n title: \"Error fetching routes\",\n message: res.msg\n });\n\n _this4.setState(_objectSpread(_objectSpread({}, _this4.state), {}, {\n errors: errors,\n isResetting: false\n }));\n }\n });\n }\n }]);\n\n return PageOverview;\n}(react__WEBPACK_IMPORTED_MODULE_0__[\"Component\"]);\n\n\n\n//# sourceURL=webpack:///./src/views/pages.js?"); /***/ }), diff --git a/src/src/api.js b/src/src/api.js index a5a3ad0..64ffc11 100644 --- a/src/src/api.js +++ b/src/src/api.js @@ -61,4 +61,8 @@ export default class API { async getRoutes() { return this.apiCall("routes/fetch"); } + + async saveRoutes(routes) { + return this.apiCall("routes/save", { "routes": routes }); + } }; \ No newline at end of file diff --git a/src/src/views/pages.js b/src/src/views/pages.js index 5d5cf9c..7db466d 100644 --- a/src/src/views/pages.js +++ b/src/src/views/pages.js @@ -15,22 +15,31 @@ export default class PageOverview extends React.Component { this.state = { routes: [], - errors: [] + errors: [], + isResetting: false, + isSaving: false }; - this.options = { + this.optionMap = { "redirect_temporary": "Redirect Temporary", "redirect_permanently": "Redirect Permanently", "static": "Serve Static", "dynamic": "Load Dynamic", }; + + this.options = []; + for (let key in this.optionMap) { + this.options.push(this.buildOption(key)); + } } buildOption(key) { if (typeof key === 'object' && key.hasOwnProperty("key") && key.hasOwnProperty("label")) { return key; + } else if (typeof key === 'string') { + return { value: key, label: this.optionMap[key] }; } else { - return { value: key, label: this.options[key] }; + return this.options[key]; } } @@ -43,15 +52,7 @@ export default class PageOverview extends React.Component { } componentDidMount() { - this.parent.api.getRoutes().then((res) => { - if (res.success) { - this.setState({...this.state, routes: res.routes}); - } else { - let errors = this.state.errors.slice(); - errors.push({ title: "Error fetching routes", message: res.msg }); - this.setState({...this.state, errors: errors}); - } - }); + this.fetchRoutes() } render() { @@ -63,27 +64,41 @@ export default class PageOverview extends React.Component { errors.push( this.removeError(i)} {...this.state.errors[i]}/>) } - let options = []; - for (let key in Object.keys(this.options)) { - options.push(this.buildOption(key)); - } + const inputStyle = { fontFamily: "Courier", paddingTop: "14px" }; for (let i = 0; i < this.state.routes.length; i++) { let route = this.state.routes[i]; rows.push( - {route.request} - - this.changeRequest(i, e)} /> + + + this.changeTarget(i, e)} /> + + + this.changeExtra(i, e)} /> - {route.target} - {route.extra} this.changeActive(i, e)} /> + + + this.removeRoute(i)}/> + ); } @@ -108,76 +123,152 @@ export default class PageOverview extends React.Component { {errors}
-
+
- + {rows}
+ Request  - - - + data-type={"info"} data-place={"bottom"}/> + + Action  - - - + data-type={"info"} data-place={"bottom"}/> + + Target  - - - + data-type={"info"} data-place={"bottom"}/> + + Extra  - - - + data-type={"info"} data-place={"bottom"}/> + + Active  - - + data-type={"info"} data-place={"bottom"}/> +
+
+ + + +
- + } - changeAction(index, selectedOption) { + onResetRoutes() { + this.setState({ ...this.state, isResetting: true }); + this.fetchRoutes(); + } + + onSaveRoutes() { + this.setState({ ...this.state, isSaving: true }); + + let routes = []; + for (let i = 0; i < this.state.routes.length; i++) { + let route = this.state.routes[i]; + routes.push({ + request: route.request, + action: typeof route.action === 'object' ? route.action.value : route.action, + target: route.target, + extra: route.extra ?? "", + active: route.active === 1 + }); + } + + this.parent.api.saveRoutes(routes).then((res) => { + if (res.success) { + this.setState({...this.state, isSaving: false}); + } else { + let errors = this.state.errors.slice(); + errors.push({ title: "Error saving routes", message: res.msg }); + this.setState({...this.state, errors: errors, isSaving: false}); + } + }); + } + + changeRoute(index, key, value) { if (index < 0 || index >= this.state.routes.length) return; let routes = this.state.routes.slice(); - routes[index].action = selectedOption; - this.setState({ - ...this.state, - routes: routes - }); + routes[index][key] = value; + this.setState({ ...this.state, routes: routes }); + } + + removeRoute(index) { + if (index < 0 || index >= this.state.routes.length) + return; + let routes = this.state.routes.slice(); + routes.splice(index, 1); + this.setState({ ...this.state, routes: routes }); + } + + + onAddRoute() { + let routes = this.state.routes.slice(); + routes.push({ request: "", action: "dynamic", target: "", extra: "", active: 1 }); + this.setState({ ...this.state, routes: routes }); + } + + changeAction(index, selectedOption) { + this.changeRoute(index, "action", selectedOption); } changeActive(index, e) { - if (index < 0 || index >= this.state.routes.length) - return; + this.changeRoute(index, "active", e.target.checked ? 1 : 0); + } - let routes = this.state.routes.slice(); - routes[index].active = e.target.checked ? 1 : 0; - this.setState({ - ...this.state, - routes: routes + changeRequest(index, e) { + this.changeRoute(index, "request", e.target.value); + } + + changeTarget(index, e) { + this.changeRoute(index, "target", e.target.value); + } + + changeExtra(index, e) { + this.changeRoute(index, "extra", e.target.value); + } + + fetchRoutes() { + this.parent.api.getRoutes().then((res) => { + if (res.success) { + this.setState({...this.state, routes: res.routes, isResetting: false}); + ReactTooltip.rebuild(); + } else { + let errors = this.state.errors.slice(); + errors.push({ title: "Error fetching routes", message: res.msg }); + this.setState({...this.state, errors: errors, isResetting: false}); + } }); } } \ No newline at end of file