diff --git a/js-src/conquer/map-node.ts b/js-src/conquer/map-node.ts index fad0011..e46dd70 100644 --- a/js-src/conquer/map-node.ts +++ b/js-src/conquer/map-node.ts @@ -15,6 +15,7 @@ import ConquerTeam from '@burguillosinfo/conquer/team'; export default class MapNode { private feature: Feature | null = null; private callbacks: Record void>> = {} + private cachedTeam: ConquerTeam | null = null; constructor( @JsonProperty() private uuid: string, @@ -30,10 +31,13 @@ export default class MapNode { } public async getTeam(): Promise { - if (this.team === null) { - return null; + if (this.cachedTeam === null) { + if (this.team === null) { + return null; + } + this.cachedTeam = await ConquerTeam.getTeam(this.team); } - return ConquerTeam.getTeam(this.team); + return this.cachedTeam; } diff --git a/js-src/conquer/user.ts b/js-src/conquer/user.ts index f8a4786..4202ad7 100644 --- a/js-src/conquer/user.ts +++ b/js-src/conquer/user.ts @@ -27,6 +27,7 @@ export default class ConquerUser { private uuid: string; @JsonProperty() private team: string | null; + private cachedTeam: ConquerTeam | null = null; constructor(kind: string, uuid: string, username: string, is_admin = false, registration_date: string | null = null, last_activity: string | null = null) { this.kind = kind; @@ -38,10 +39,13 @@ export default class ConquerUser { } public async getTeam(): Promise { - if (this.team === null) { - return null; + if (this.cachedTeam === null) { + if (this.team === null) { + return null; + } + this.cachedTeam = await ConquerTeam.getTeam(this.team); } - return ConquerTeam.getTeam(this.team); + return this.cachedTeam; } public static async getSelfUser(): Promise { diff --git a/public/js/bundle.js b/public/js/bundle.js index d15cf80..be294bd 100644 --- a/public/js/bundle.js +++ b/public/js/bundle.js @@ -210,7 +210,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! typescript-json-serializer */ \"./node_modules/typescript-json-serializer/dist/index.esm.js\");\n/* harmony import */ var ol_style_Style__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ol/style/Style */ \"./node_modules/ol/style/Style.js\");\n/* harmony import */ var ol_Feature__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ol/Feature */ \"./node_modules/ol/Feature.js\");\n/* harmony import */ var ol_style_Circle__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ol/style/Circle */ \"./node_modules/ol/style/Circle.js\");\n/* harmony import */ var ol_geom_Point__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ol/geom/Point */ \"./node_modules/ol/geom/Point.js\");\n/* harmony import */ var ol_style_Fill__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ol/style/Fill */ \"./node_modules/ol/style/Fill.js\");\n/* harmony import */ var ol_style_Stroke__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ol/style/Stroke */ \"./node_modules/ol/style/Stroke.js\");\n/* harmony import */ var _burguillosinfo_conquer_interface_node_view__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/node-view */ \"./js-src/conquer/interface/node-view.ts\");\n/* harmony import */ var _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer/serializer */ \"./js-src/conquer/serializer.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_select_team__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/select-team */ \"./js-src/conquer/interface/select-team.ts\");\n/* harmony import */ var _burguillosinfo_conquer_team__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @burguillosinfo/conquer/team */ \"./js-src/conquer/team.ts\");\nvar __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __metadata = (undefined && undefined.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};\nvar __param = (undefined && undefined.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};\nvar MapNode_1;\n\n\n\n\n\n\n\n\n\n\n\nlet MapNode = MapNode_1 = class MapNode {\n constructor(uuid, coordinate_1, coordinate_2, type, name, description, kind, is_near, team) {\n this.uuid = uuid;\n this.coordinate_1 = coordinate_1;\n this.coordinate_2 = coordinate_2;\n this.type = type;\n this.name = name;\n this.description = description;\n this.kind = kind;\n this.is_near = is_near;\n this.team = team;\n this.feature = null;\n this.callbacks = {};\n }\n async getTeam() {\n if (this.team === null) {\n return null;\n }\n return _burguillosinfo_conquer_team__WEBPACK_IMPORTED_MODULE_4__[\"default\"].getTeam(this.team);\n }\n async fetch() {\n const urlNode = new URL('/conquer/node/' + this.uuid, window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n const response = await fetch(urlNode);\n let responseBody;\n const errorThrow = new Error('Unable to fetch node updated.');\n try {\n responseBody = await response.json();\n }\n catch (error) {\n console.error('Error parseando json: ' + responseBody);\n console.error(error);\n throw errorThrow;\n }\n if (response.status !== 200) {\n console.error(responseBody.error);\n throw errorThrow;\n }\n const node = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_2__[\"default\"].deserialize(responseBody, MapNode_1);\n if (!(node instanceof MapNode_1)) {\n console.error('Unexpected JSON value for MapNode.');\n throw errorThrow;\n }\n return node;\n }\n click(interfaceManager) {\n const viewNodeInterface = new _burguillosinfo_conquer_interface_node_view__WEBPACK_IMPORTED_MODULE_1__[\"default\"](this);\n viewNodeInterface.on('close', () => {\n interfaceManager.remove(viewNodeInterface);\n });\n viewNodeInterface.on('update-nodes', () => {\n this.runCallbacks('update-nodes');\n });\n viewNodeInterface.on('open-select-team', () => {\n this.openSelectTeam(interfaceManager);\n });\n interfaceManager.push(viewNodeInterface);\n this.runCallbacks('click');\n }\n openSelectTeam(interfaceManager) {\n const selectTeamUI = new _burguillosinfo_conquer_interface_select_team__WEBPACK_IMPORTED_MODULE_3__[\"default\"](this);\n selectTeamUI.on('update-nodes', () => {\n this.runCallbacks('update-nodes');\n });\n selectTeamUI.on('close', () => {\n interfaceManager.remove(selectTeamUI);\n });\n interfaceManager.push(selectTeamUI);\n }\n on(eventName, callback) {\n if (this.callbacks[eventName] === undefined) {\n this.callbacks[eventName] = [];\n }\n this.callbacks[eventName].push(callback);\n }\n runCallbacks(eventName) {\n const callbacks = this.callbacks[eventName];\n if (callbacks === undefined) {\n return;\n }\n for (const callback of callbacks) {\n callback();\n }\n }\n getType() {\n return this.type;\n }\n isNear() {\n return this.is_near;\n }\n getName() {\n return this.name;\n }\n getDescription() {\n return this.description;\n }\n getId() {\n return 'node-' + this.uuid;\n }\n getUUID() {\n return this.uuid;\n }\n getFeature() {\n if (this.feature === null) {\n this.feature = new ol_Feature__WEBPACK_IMPORTED_MODULE_5__[\"default\"]({\n geometry: new ol_geom_Point__WEBPACK_IMPORTED_MODULE_6__[\"default\"]([this.coordinate_1, this.coordinate_2]),\n type: 'node-' + this.uuid,\n });\n }\n return this.feature;\n }\n async getStyle() {\n const team = await this.getTeam();\n let color = 'white';\n if (team !== null) {\n color = team.getColor();\n }\n return new ol_style_Style__WEBPACK_IMPORTED_MODULE_7__[\"default\"]({\n image: new ol_style_Circle__WEBPACK_IMPORTED_MODULE_8__[\"default\"]({\n radius: 14,\n fill: new ol_style_Fill__WEBPACK_IMPORTED_MODULE_9__[\"default\"]({ color: color }),\n stroke: new ol_style_Stroke__WEBPACK_IMPORTED_MODULE_10__[\"default\"]({\n color: 'gray',\n width: 2,\n })\n })\n });\n }\n};\nMapNode = MapNode_1 = __decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonObject)(),\n __param(0, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(1, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(2, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(3, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(4, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(5, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(6, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(7, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(8, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __metadata(\"design:paramtypes\", [String, Number, Number, String, String, String, String, Boolean, String])\n], MapNode);\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (MapNode);\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/map-node.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! typescript-json-serializer */ \"./node_modules/typescript-json-serializer/dist/index.esm.js\");\n/* harmony import */ var ol_style_Style__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ol/style/Style */ \"./node_modules/ol/style/Style.js\");\n/* harmony import */ var ol_Feature__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ol/Feature */ \"./node_modules/ol/Feature.js\");\n/* harmony import */ var ol_style_Circle__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ol/style/Circle */ \"./node_modules/ol/style/Circle.js\");\n/* harmony import */ var ol_geom_Point__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ol/geom/Point */ \"./node_modules/ol/geom/Point.js\");\n/* harmony import */ var ol_style_Fill__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ol/style/Fill */ \"./node_modules/ol/style/Fill.js\");\n/* harmony import */ var ol_style_Stroke__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ol/style/Stroke */ \"./node_modules/ol/style/Stroke.js\");\n/* harmony import */ var _burguillosinfo_conquer_interface_node_view__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/node-view */ \"./js-src/conquer/interface/node-view.ts\");\n/* harmony import */ var _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer/serializer */ \"./js-src/conquer/serializer.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_select_team__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/select-team */ \"./js-src/conquer/interface/select-team.ts\");\n/* harmony import */ var _burguillosinfo_conquer_team__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @burguillosinfo/conquer/team */ \"./js-src/conquer/team.ts\");\nvar __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __metadata = (undefined && undefined.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};\nvar __param = (undefined && undefined.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};\nvar MapNode_1;\n\n\n\n\n\n\n\n\n\n\n\nlet MapNode = MapNode_1 = class MapNode {\n constructor(uuid, coordinate_1, coordinate_2, type, name, description, kind, is_near, team) {\n this.uuid = uuid;\n this.coordinate_1 = coordinate_1;\n this.coordinate_2 = coordinate_2;\n this.type = type;\n this.name = name;\n this.description = description;\n this.kind = kind;\n this.is_near = is_near;\n this.team = team;\n this.feature = null;\n this.callbacks = {};\n this.cachedTeam = null;\n }\n async getTeam() {\n if (this.cachedTeam === null) {\n if (this.team === null) {\n return null;\n }\n this.cachedTeam = await _burguillosinfo_conquer_team__WEBPACK_IMPORTED_MODULE_4__[\"default\"].getTeam(this.team);\n }\n return this.cachedTeam;\n }\n async fetch() {\n const urlNode = new URL('/conquer/node/' + this.uuid, window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n const response = await fetch(urlNode);\n let responseBody;\n const errorThrow = new Error('Unable to fetch node updated.');\n try {\n responseBody = await response.json();\n }\n catch (error) {\n console.error('Error parseando json: ' + responseBody);\n console.error(error);\n throw errorThrow;\n }\n if (response.status !== 200) {\n console.error(responseBody.error);\n throw errorThrow;\n }\n const node = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_2__[\"default\"].deserialize(responseBody, MapNode_1);\n if (!(node instanceof MapNode_1)) {\n console.error('Unexpected JSON value for MapNode.');\n throw errorThrow;\n }\n return node;\n }\n click(interfaceManager) {\n const viewNodeInterface = new _burguillosinfo_conquer_interface_node_view__WEBPACK_IMPORTED_MODULE_1__[\"default\"](this);\n viewNodeInterface.on('close', () => {\n interfaceManager.remove(viewNodeInterface);\n });\n viewNodeInterface.on('update-nodes', () => {\n this.runCallbacks('update-nodes');\n });\n viewNodeInterface.on('open-select-team', () => {\n this.openSelectTeam(interfaceManager);\n });\n interfaceManager.push(viewNodeInterface);\n this.runCallbacks('click');\n }\n openSelectTeam(interfaceManager) {\n const selectTeamUI = new _burguillosinfo_conquer_interface_select_team__WEBPACK_IMPORTED_MODULE_3__[\"default\"](this);\n selectTeamUI.on('update-nodes', () => {\n this.runCallbacks('update-nodes');\n });\n selectTeamUI.on('close', () => {\n interfaceManager.remove(selectTeamUI);\n });\n interfaceManager.push(selectTeamUI);\n }\n on(eventName, callback) {\n if (this.callbacks[eventName] === undefined) {\n this.callbacks[eventName] = [];\n }\n this.callbacks[eventName].push(callback);\n }\n runCallbacks(eventName) {\n const callbacks = this.callbacks[eventName];\n if (callbacks === undefined) {\n return;\n }\n for (const callback of callbacks) {\n callback();\n }\n }\n getType() {\n return this.type;\n }\n isNear() {\n return this.is_near;\n }\n getName() {\n return this.name;\n }\n getDescription() {\n return this.description;\n }\n getId() {\n return 'node-' + this.uuid;\n }\n getUUID() {\n return this.uuid;\n }\n getFeature() {\n if (this.feature === null) {\n this.feature = new ol_Feature__WEBPACK_IMPORTED_MODULE_5__[\"default\"]({\n geometry: new ol_geom_Point__WEBPACK_IMPORTED_MODULE_6__[\"default\"]([this.coordinate_1, this.coordinate_2]),\n type: 'node-' + this.uuid,\n });\n }\n return this.feature;\n }\n async getStyle() {\n const team = await this.getTeam();\n let color = 'white';\n if (team !== null) {\n color = team.getColor();\n }\n return new ol_style_Style__WEBPACK_IMPORTED_MODULE_7__[\"default\"]({\n image: new ol_style_Circle__WEBPACK_IMPORTED_MODULE_8__[\"default\"]({\n radius: 14,\n fill: new ol_style_Fill__WEBPACK_IMPORTED_MODULE_9__[\"default\"]({ color: color }),\n stroke: new ol_style_Stroke__WEBPACK_IMPORTED_MODULE_10__[\"default\"]({\n color: 'gray',\n width: 2,\n })\n })\n });\n }\n};\nMapNode = MapNode_1 = __decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonObject)(),\n __param(0, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(1, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(2, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(3, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(4, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(5, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(6, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(7, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(8, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __metadata(\"design:paramtypes\", [String, Number, Number, String, String, String, String, Boolean, String])\n], MapNode);\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (MapNode);\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/map-node.ts?"); /***/ }), @@ -254,7 +254,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @burguillosinfo/conquer/serializer */ \"./js-src/conquer/serializer.ts\");\n/* harmony import */ var typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! typescript-json-serializer */ \"./node_modules/typescript-json-serializer/dist/index.esm.js\");\n/* harmony import */ var _burguillosinfo_conquer_team__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer/team */ \"./js-src/conquer/team.ts\");\nvar __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __metadata = (undefined && undefined.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};\nvar ConquerUser_1;\n\n\n\nlet ConquerUser = ConquerUser_1 = class ConquerUser {\n constructor(kind, uuid, username, is_admin = false, registration_date = null, last_activity = null) {\n this.kind = kind;\n this.uuid = uuid;\n this.username = username;\n this.is_admin = is_admin;\n this.registration_date = registration_date;\n this.last_activity = last_activity;\n }\n async getTeam() {\n if (this.team === null) {\n return null;\n }\n return _burguillosinfo_conquer_team__WEBPACK_IMPORTED_MODULE_2__[\"default\"].getTeam(this.team);\n }\n static async getSelfUser() {\n const urlUser = new URL('/conquer/user', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n try {\n const response = await fetch(urlUser);\n if (response.status !== 200) {\n throw new Error('Invalid response fetching user.');\n }\n const userData = await response.json();\n const user = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].deserialize(userData, ConquerUser_1);\n if (!(user instanceof ConquerUser_1)) {\n throw new Error('Unable to parse user.');\n }\n return user;\n }\n catch (error) {\n console.error(error);\n return null;\n }\n }\n getUsername() {\n if (this.username === null) {\n throw new Error('User username cannot be null.');\n }\n return this.username;\n }\n isAdmin() {\n return this.is_admin;\n }\n};\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", Boolean)\n], ConquerUser.prototype, \"is_admin\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerUser.prototype, \"kind\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", Object)\n], ConquerUser.prototype, \"last_activity\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", Object)\n], ConquerUser.prototype, \"registration_date\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerUser.prototype, \"username\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerUser.prototype, \"uuid\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", Object)\n], ConquerUser.prototype, \"team\", void 0);\nConquerUser = ConquerUser_1 = __decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonObject)(),\n __metadata(\"design:paramtypes\", [String, String, String, Object, Object, Object])\n], ConquerUser);\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ConquerUser);\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/user.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @burguillosinfo/conquer/serializer */ \"./js-src/conquer/serializer.ts\");\n/* harmony import */ var typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! typescript-json-serializer */ \"./node_modules/typescript-json-serializer/dist/index.esm.js\");\n/* harmony import */ var _burguillosinfo_conquer_team__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer/team */ \"./js-src/conquer/team.ts\");\nvar __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __metadata = (undefined && undefined.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};\nvar ConquerUser_1;\n\n\n\nlet ConquerUser = ConquerUser_1 = class ConquerUser {\n constructor(kind, uuid, username, is_admin = false, registration_date = null, last_activity = null) {\n this.cachedTeam = null;\n this.kind = kind;\n this.uuid = uuid;\n this.username = username;\n this.is_admin = is_admin;\n this.registration_date = registration_date;\n this.last_activity = last_activity;\n }\n async getTeam() {\n if (this.cachedTeam === null) {\n if (this.team === null) {\n return null;\n }\n this.cachedTeam = await _burguillosinfo_conquer_team__WEBPACK_IMPORTED_MODULE_2__[\"default\"].getTeam(this.team);\n }\n return this.cachedTeam;\n }\n static async getSelfUser() {\n const urlUser = new URL('/conquer/user', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n try {\n const response = await fetch(urlUser);\n if (response.status !== 200) {\n throw new Error('Invalid response fetching user.');\n }\n const userData = await response.json();\n const user = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].deserialize(userData, ConquerUser_1);\n if (!(user instanceof ConquerUser_1)) {\n throw new Error('Unable to parse user.');\n }\n return user;\n }\n catch (error) {\n console.error(error);\n return null;\n }\n }\n getUsername() {\n if (this.username === null) {\n throw new Error('User username cannot be null.');\n }\n return this.username;\n }\n isAdmin() {\n return this.is_admin;\n }\n};\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", Boolean)\n], ConquerUser.prototype, \"is_admin\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerUser.prototype, \"kind\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", Object)\n], ConquerUser.prototype, \"last_activity\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", Object)\n], ConquerUser.prototype, \"registration_date\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerUser.prototype, \"username\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerUser.prototype, \"uuid\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", Object)\n], ConquerUser.prototype, \"team\", void 0);\nConquerUser = ConquerUser_1 = __decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonObject)(),\n __metadata(\"design:paramtypes\", [String, String, String, Object, Object, Object])\n], ConquerUser);\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ConquerUser);\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/user.ts?"); /***/ }),