update username filter on input change; fix multiple names/ids

in panoramax a username can resolve to multiple ids (when the same name is used on multiple servers).
further, the username filter input field can contain more than one username
This commit is contained in:
Martin Raifer
2024-07-29 16:15:34 +02:00
parent 608251a6ab
commit f25e94c71b
2 changed files with 28 additions and 23 deletions

View File

@@ -274,15 +274,19 @@ export default {
loadTiles('line', tileUrl, lineMinZoom, projection);
},
getUserId: async function(username){
const requestUrl = userIdUrl.replace('{username}', username);
getUserIds: async function(usernames) {
const requestUrls = usernames.map(username =>
userIdUrl.replace('{username}', username));
const response = await fetch(requestUrl, { method: 'GET' });
if (!response.ok) {
const responses = await Promise.all(requestUrls.map(requestUrl =>
fetch(requestUrl, { method: 'GET' })));
if (responses.some(response => !response.ok)) {
throw new Error(response.status + ' ' + response.statusText);
}
const data = await response.json();
return data.features[0].id;
const data = await Promise.all(responses.map(response => response.json()));
// in panoramax, a username can have multiple ids, when the same name is
// used on different servers
return data.flatMap((d, i) => d.features.filter(f => f.name === usernames[i]).map(f => f.id));
},
getOldestDate: function(){

View File

@@ -14,7 +14,8 @@ export function svgPanoramaxImages(projection, context, dispatch) {
let _panoramax;
let _viewerYaw = 0;
let _selectedSequence;
let _activeId;
let _activeUsernameFilter;
let _activeIds;
function init() {
if (svgPanoramaxImages.initialized) return;
@@ -63,18 +64,18 @@ export function svgPanoramaxImages(projection, context, dispatch) {
});
}
if (username && service) {
if (!_activeId) {
const tempId = await service.getUserId(username);
if (_activeUsernameFilter !== username) {
const tempIds = await service.getUserIds(username);
if (!_activeId) {
_activeId = tempId;
}
_activeUsernameFilter = username;
_activeIds = {};
tempIds.forEach(id => {
_activeIds[id] = true;
})
}
let id = _activeId;
images = images.filter(function(image) {
return id === image.account_id;
return _activeIds[image.account_id];
});
}
@@ -107,18 +108,18 @@ export function svgPanoramaxImages(projection, context, dispatch) {
});
}
if (username && service) {
if (!_activeId) {
const tempId = await service.getUserId(username);
if (_activeUsernameFilter !== username) {
const tempIds = await service.getUserIds(username);
if (!_activeId) {
_activeId = tempId;
}
_activeUsernameFilter = username;
_activeIds = {};
tempIds.forEach(id => {
_activeIds[id] = true;
})
}
let id = _activeId;
sequences = sequences.filter(function(sequence) {
return id === sequence.properties.account_id;
return _activeIds[sequence.properties.account_id];
});
}