Youen 1 year ago
parent
commit
3d37a66702
  1. 2
      extend.php
  2. 128
      js/dist/forum.js
  3. 2
      js/dist/forum.js.map
  4. 32
      js/src/forum/components/GlobalMapPage.tsx
  5. 3
      js/src/forum/index.js
  6. 8
      js/src/forum/models/UserLocation.ts
  7. 2
      src/Api/Controller/ListUserLocationsController.php

2
extend.php

@ -59,5 +59,5 @@ return [
->addFilterMutator(UserLocationFilterMutator::class),
(new Extend\Routes('api'))
->get('/user-locations', 'user-locations.index', Api\Controller\ListUserLocationsController::class)
->get('/userlocations', 'userlocations.index', Api\Controller\ListUserLocationsController::class)
];

128
js/dist/forum.js vendored

@ -16486,9 +16486,16 @@ var GlobalMapPage = /*#__PURE__*/function (_Page) {
this.userMarkers = L.markerClusterGroup({
maxClusterRadius: 40
});
this.map.addLayer(this.userMarkers); // begin fetching users
this.map.addLayer(this.userMarkers);
var usersExpirationDelay = 10 * 60; // in seconds
this.fetchUsers(0);
if ((flarum_forum_app__WEBPACK_IMPORTED_MODULE_1___default().store).lastFetchedUserLocations && Date.now() - (flarum_forum_app__WEBPACK_IMPORTED_MODULE_1___default().store).lastFetchedUserLocations < usersExpirationDelay * 1000) {
// reuse data from the store
this.displayUsers(flarum_forum_app__WEBPACK_IMPORTED_MODULE_1___default().store.all('users'));
} else {
// begin fetching users
this.fetchUsers(0);
}
}
} else {
this.map = null;
@ -16499,31 +16506,39 @@ var GlobalMapPage = /*#__PURE__*/function (_Page) {
var _this = this;
var maxLocationsPerRequest = 50;
flarum_forum_app__WEBPACK_IMPORTED_MODULE_1___default().store.find('user-locations', {
flarum_forum_app__WEBPACK_IMPORTED_MODULE_1___default().store.find('userlocations', {
page: {
limit: maxLocationsPerRequest,
offset: offset
}
}).then(function (response) {
for (var _iterator = _createForOfIteratorHelperLoose(response), _step; !(_step = _iterator()).done;) {
var item = _step.value;
var user = item.data.attributes;
var marker = L.marker([parseFloat(user.location_latitude), parseFloat(user.location_longitude)], {
icon: _this.userMarkerIcon
});
marker.bindPopup('<a href="/u/' + escapeHtml(user.username) + '">' + escapeHtml(user.displayName) + '</a>');
_this.userMarkers.addLayer(marker);
}
_this.displayUsers(response);
if (response.length == maxLocationsPerRequest) {
// we need to fetch more users
_this.fetchUsers(offset + response.length);
} else {// finished fetching all users
} else {
// finished fetching all users
(flarum_forum_app__WEBPACK_IMPORTED_MODULE_1___default().store).lastFetchedUserLocations = Date.now();
}
});
};
_proto.displayUsers = function displayUsers(users) {
for (var _iterator = _createForOfIteratorHelperLoose(users), _step; !(_step = _iterator()).done;) {
var item = _step.value;
var user = item.data.attributes;
if (user.location_latitude) {
var marker = L.marker([parseFloat(user.location_latitude), parseFloat(user.location_longitude)], {
icon: this.userMarkerIcon
});
marker.bindPopup('<a href="/u/' + escapeHtml(user.username) + '">' + escapeHtml(user.displayName) + '</a>');
this.userMarkers.addLayer(marker);
}
}
};
return GlobalMapPage;
}((flarum_common_components_Page__WEBPACK_IMPORTED_MODULE_2___default()));
@ -16553,21 +16568,23 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var flarum_common_Model__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! flarum/common/Model */ "flarum/common/Model");
/* harmony import */ var flarum_common_Model__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(flarum_common_Model__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var _components_AddLocationComponent__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./components/AddLocationComponent */ "./src/forum/components/AddLocationComponent.js");
/* harmony import */ var flarum_forum_components_UserCard__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! flarum/forum/components/UserCard */ "flarum/forum/components/UserCard");
/* harmony import */ var flarum_forum_components_UserCard__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(flarum_forum_components_UserCard__WEBPACK_IMPORTED_MODULE_6__);
/* harmony import */ var flarum_forum_components_HeaderPrimary__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! flarum/forum/components/HeaderPrimary */ "flarum/forum/components/HeaderPrimary");
/* harmony import */ var flarum_forum_components_HeaderPrimary__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(flarum_forum_components_HeaderPrimary__WEBPACK_IMPORTED_MODULE_7__);
/* harmony import */ var flarum_common_components_Link__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! flarum/common/components/Link */ "flarum/common/components/Link");
/* harmony import */ var flarum_common_components_Link__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(flarum_common_components_Link__WEBPACK_IMPORTED_MODULE_8__);
/* harmony import */ var leaflet__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! leaflet */ "./node_modules/leaflet/dist/leaflet-src.js");
/* harmony import */ var leaflet__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(leaflet__WEBPACK_IMPORTED_MODULE_9__);
/* harmony import */ var leaflet_markercluster__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! leaflet.markercluster */ "./node_modules/leaflet.markercluster/dist/leaflet.markercluster-src.js");
/* harmony import */ var leaflet_markercluster__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__webpack_require__.n(leaflet_markercluster__WEBPACK_IMPORTED_MODULE_10__);
/* harmony import */ var _components_GlobalMapPage__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./components/GlobalMapPage */ "./src/forum/components/GlobalMapPage.tsx");
/* harmony import */ var _less_forum_less__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./../../../less/forum.less */ "../less/forum.less");
/* harmony import */ var _node_modules_leaflet_dist_leaflet_css__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./../../node_modules/leaflet/dist/leaflet.css */ "./node_modules/leaflet/dist/leaflet.css");
/* harmony import */ var _node_modules_leaflet_markercluster_dist_MarkerCluster_css__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./../../node_modules/leaflet.markercluster/dist/MarkerCluster.css */ "./node_modules/leaflet.markercluster/dist/MarkerCluster.css");
/* harmony import */ var _node_modules_leaflet_markercluster_dist_MarkerCluster_Default_css__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./../../node_modules/leaflet.markercluster/dist/MarkerCluster.Default.css */ "./node_modules/leaflet.markercluster/dist/MarkerCluster.Default.css");
/* harmony import */ var _models_UserLocation__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./models/UserLocation */ "./src/forum/models/UserLocation.ts");
/* harmony import */ var flarum_forum_components_UserCard__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! flarum/forum/components/UserCard */ "flarum/forum/components/UserCard");
/* harmony import */ var flarum_forum_components_UserCard__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(flarum_forum_components_UserCard__WEBPACK_IMPORTED_MODULE_7__);
/* harmony import */ var flarum_forum_components_HeaderPrimary__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! flarum/forum/components/HeaderPrimary */ "flarum/forum/components/HeaderPrimary");
/* harmony import */ var flarum_forum_components_HeaderPrimary__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(flarum_forum_components_HeaderPrimary__WEBPACK_IMPORTED_MODULE_8__);
/* harmony import */ var flarum_common_components_Link__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! flarum/common/components/Link */ "flarum/common/components/Link");
/* harmony import */ var flarum_common_components_Link__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(flarum_common_components_Link__WEBPACK_IMPORTED_MODULE_9__);
/* harmony import */ var leaflet__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! leaflet */ "./node_modules/leaflet/dist/leaflet-src.js");
/* harmony import */ var leaflet__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__webpack_require__.n(leaflet__WEBPACK_IMPORTED_MODULE_10__);
/* harmony import */ var leaflet_markercluster__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! leaflet.markercluster */ "./node_modules/leaflet.markercluster/dist/leaflet.markercluster-src.js");
/* harmony import */ var leaflet_markercluster__WEBPACK_IMPORTED_MODULE_11___default = /*#__PURE__*/__webpack_require__.n(leaflet_markercluster__WEBPACK_IMPORTED_MODULE_11__);
/* harmony import */ var _components_GlobalMapPage__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./components/GlobalMapPage */ "./src/forum/components/GlobalMapPage.tsx");
/* harmony import */ var _less_forum_less__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ./../../../less/forum.less */ "../less/forum.less");
/* harmony import */ var _node_modules_leaflet_dist_leaflet_css__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ./../../node_modules/leaflet/dist/leaflet.css */ "./node_modules/leaflet/dist/leaflet.css");
/* harmony import */ var _node_modules_leaflet_markercluster_dist_MarkerCluster_css__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ./../../node_modules/leaflet.markercluster/dist/MarkerCluster.css */ "./node_modules/leaflet.markercluster/dist/MarkerCluster.css");
/* harmony import */ var _node_modules_leaflet_markercluster_dist_MarkerCluster_Default_css__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ./../../node_modules/leaflet.markercluster/dist/MarkerCluster.Default.css */ "./node_modules/leaflet.markercluster/dist/MarkerCluster.Default.css");
@ -16591,11 +16608,12 @@ flarum_forum_app__WEBPACK_IMPORTED_MODULE_0___default().initializers.add('justov
(flarum_common_models_User__WEBPACK_IMPORTED_MODULE_3___default().prototype).location_city = flarum_common_Model__WEBPACK_IMPORTED_MODULE_4___default().attribute('location_city');
(flarum_common_models_User__WEBPACK_IMPORTED_MODULE_3___default().prototype).location_latitude = flarum_common_Model__WEBPACK_IMPORTED_MODULE_4___default().attribute('location_latitude');
(flarum_common_models_User__WEBPACK_IMPORTED_MODULE_3___default().prototype).location_longitude = flarum_common_Model__WEBPACK_IMPORTED_MODULE_4___default().attribute('location_longitude');
app.store.models.userlocations = _models_UserLocation__WEBPACK_IMPORTED_MODULE_6__["default"];
app.routes['justoverclock.global-map'] = {
path: '/global-map',
component: _components_GlobalMapPage__WEBPACK_IMPORTED_MODULE_11__["default"]
component: _components_GlobalMapPage__WEBPACK_IMPORTED_MODULE_12__["default"]
};
(0,flarum_common_extend__WEBPACK_IMPORTED_MODULE_1__.extend)((flarum_forum_components_UserCard__WEBPACK_IMPORTED_MODULE_6___default().prototype), 'infoItems', function (items) {
(0,flarum_common_extend__WEBPACK_IMPORTED_MODULE_1__.extend)((flarum_forum_components_UserCard__WEBPACK_IMPORTED_MODULE_7___default().prototype), 'infoItems', function (items) {
var user = this.attrs.user;
if (user.location_latitude()) {
@ -16604,7 +16622,7 @@ flarum_forum_app__WEBPACK_IMPORTED_MODULE_0___default().initializers.add('justov
}), -100);
}
});
(0,flarum_common_extend__WEBPACK_IMPORTED_MODULE_1__.extend)((flarum_forum_components_UserCard__WEBPACK_IMPORTED_MODULE_6___default().prototype), 'oncreate', function (originalResult, vnode) {
(0,flarum_common_extend__WEBPACK_IMPORTED_MODULE_1__.extend)((flarum_forum_components_UserCard__WEBPACK_IMPORTED_MODULE_7___default().prototype), 'oncreate', function (originalResult, vnode) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = app.forum.attribute('baseUrl') + '/assets/extensions/justoverclock-users-map-location/leaflet.edgebuffer.js';
@ -16652,7 +16670,7 @@ flarum_forum_app__WEBPACK_IMPORTED_MODULE_0___default().initializers.add('justov
items.add('location', m(_components_AddLocationComponent__WEBPACK_IMPORTED_MODULE_5__["default"], null));
});
});
(0,flarum_common_extend__WEBPACK_IMPORTED_MODULE_1__.extend)((flarum_forum_components_HeaderPrimary__WEBPACK_IMPORTED_MODULE_7___default().prototype), 'onupdate', function () {
(0,flarum_common_extend__WEBPACK_IMPORTED_MODULE_1__.extend)((flarum_forum_components_HeaderPrimary__WEBPACK_IMPORTED_MODULE_8___default().prototype), 'onupdate', function () {
var homeLink = document.getElementById('home-link');
if (homeLink) {
@ -16664,7 +16682,7 @@ flarum_forum_app__WEBPACK_IMPORTED_MODULE_0___default().initializers.add('justov
globalMapLink = document.createElement('span');
globalMapLink.setAttribute('id', 'global-map-link');
(_homeLink$parentEleme = homeLink.parentElement) == null ? void 0 : _homeLink$parentEleme.append(globalMapLink);
m.render(globalMapLink, m((flarum_common_components_Link__WEBPACK_IMPORTED_MODULE_8___default()), {
m.render(globalMapLink, m((flarum_common_components_Link__WEBPACK_IMPORTED_MODULE_9___default()), {
href: "/global-map",
id: "map-link",
"class": "Button Button--primary"
@ -16674,6 +16692,48 @@ flarum_forum_app__WEBPACK_IMPORTED_MODULE_0___default().initializers.add('justov
});
/***/ }),
/***/ "./src/forum/models/UserLocation.ts":
/*!******************************************!*\
!*** ./src/forum/models/UserLocation.ts ***!
\******************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ UserLocation)
/* harmony export */ });
/* harmony import */ var _babel_runtime_helpers_esm_inheritsLoose__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @babel/runtime/helpers/esm/inheritsLoose */ "./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js");
/* harmony import */ var flarum_common_Model__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! flarum/common/Model */ "flarum/common/Model");
/* harmony import */ var flarum_common_Model__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(flarum_common_Model__WEBPACK_IMPORTED_MODULE_1__);
var UserLocation = /*#__PURE__*/function (_Model) {
(0,_babel_runtime_helpers_esm_inheritsLoose__WEBPACK_IMPORTED_MODULE_0__["default"])(UserLocation, _Model);
function UserLocation() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _Model.call.apply(_Model, [this].concat(args)) || this;
_this.username = flarum_common_Model__WEBPACK_IMPORTED_MODULE_1___default().attribute('username');
_this.displayName = flarum_common_Model__WEBPACK_IMPORTED_MODULE_1___default().attribute('displayName');
_this.location_latitude = flarum_common_Model__WEBPACK_IMPORTED_MODULE_1___default().attribute('location_latitude');
_this.location_longitude = flarum_common_Model__WEBPACK_IMPORTED_MODULE_1___default().attribute('location_longitude');
return _this;
}
return UserLocation;
}((flarum_common_Model__WEBPACK_IMPORTED_MODULE_1___default()));
/***/ }),
/***/ "./node_modules/leaflet.markercluster/dist/MarkerCluster.Default.css":

2
js/dist/forum.js.map vendored

File diff suppressed because one or more lines are too long

32
js/src/forum/components/GlobalMapPage.tsx

@ -67,8 +67,15 @@ export default class GlobalMapPage extends Page {
this.userMarkers = L.markerClusterGroup({ maxClusterRadius: 40 });
this.map.addLayer(this.userMarkers);
// begin fetching users
this.fetchUsers(0);
let usersExpirationDelay = 10 * 60; // in seconds
if(app.store.lastFetchedUserLocations && Date.now() - app.store.lastFetchedUserLocations < usersExpirationDelay * 1000)
{
// reuse data from the store
this.displayUsers(app.store.all('users'));
} else {
// begin fetching users
this.fetchUsers(0);
}
}
} else {
this.map = null;
@ -77,13 +84,8 @@ export default class GlobalMapPage extends Page {
fetchUsers(offset) {
let maxLocationsPerRequest = 50;
app.store.find('user-locations', { page: { limit: maxLocationsPerRequest, offset: offset } }).then((response) => {
for(let item of response) {
let user = item.data.attributes;
let marker = L.marker([parseFloat(user.location_latitude), parseFloat(user.location_longitude)], { icon: this.userMarkerIcon });
marker.bindPopup('<a href="/u/'+escapeHtml(user.username)+'">'+escapeHtml(user.displayName)+'</a>');
this.userMarkers.addLayer(marker);
}
app.store.find('userlocations', { page: { limit: maxLocationsPerRequest, offset: offset } }).then((response) => {
this.displayUsers(response);
if(response.length == maxLocationsPerRequest) {
// we need to fetch more users
@ -91,7 +93,19 @@ export default class GlobalMapPage extends Page {
}
else {
// finished fetching all users
app.store.lastFetchedUserLocations = Date.now();
}
});
}
displayUsers(users) {
for(let item of users) {
let user = item.data.attributes;
if(user.location_latitude) {
let marker = L.marker([parseFloat(user.location_latitude), parseFloat(user.location_longitude)], { icon: this.userMarkerIcon });
marker.bindPopup('<a href="/u/'+escapeHtml(user.username)+'">'+escapeHtml(user.displayName)+'</a>');
this.userMarkers.addLayer(marker);
}
}
}
}

3
js/src/forum/index.js

@ -4,6 +4,7 @@ import SettingsPage from 'flarum/forum/components/SettingsPage';
import User from 'flarum/common/models/User';
import Model from 'flarum/common/Model';
import AddLocationComponent from './components/AddLocationComponent';
import UserLocation from './models/UserLocation';
import UserCard from 'flarum/forum/components/UserCard';
import HeaderPrimary from 'flarum/forum/components/HeaderPrimary';
import Link from 'flarum/common/components/Link';
@ -24,6 +25,8 @@ app.initializers.add('justoverclock/users-map-location', (app) => {
User.prototype.location_latitude = Model.attribute('location_latitude');
User.prototype.location_longitude = Model.attribute('location_longitude');
app.store.models.userlocations = UserLocation;
app.routes['justoverclock.global-map'] = { path: '/global-map', component: GlobalMapPage };
extend(UserCard.prototype, 'infoItems', function (items) {

8
js/src/forum/models/UserLocation.ts

@ -0,0 +1,8 @@
import Model from 'flarum/common/Model';
export default class UserLocation extends Model {
username = Model.attribute('username');
displayName = Model.attribute('displayName');
location_latitude = Model.attribute('location_latitude');
location_longitude = Model.attribute('location_longitude');
}

2
src/Api/Controller/ListUserLocationsController.php

@ -88,7 +88,7 @@ class ListUserLocationsController extends AbstractListController
//}
$document->addPaginationLinks(
$this->url->to('api')->route('user-locations.index'),
$this->url->to('api')->route('userlocations.index'),
$request->getQueryParams(),
$offset,
$limit,

Loading…
Cancel
Save