Skip to content

Commit

Permalink
fix: Fix layman layer deletion
Browse files Browse the repository at this point in the history
refs Handle failed layer deletion #3114
  • Loading branch information
DailisLangovskis authored and fzadrazil committed Jun 17, 2022
1 parent be5aa7a commit f797f2c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
5 changes: 4 additions & 1 deletion projects/hslayers/src/common/layman/layman.service.ts
Expand Up @@ -99,7 +99,10 @@ export class HsCommonLaymanService {
this.detectAuthChange(endpoint, app);
break;
default:
simplifiedResponse = responseBody.message + ' ' + responseBody.detail;
simplifiedResponse = responseBody.message;
if (responseBody.detail) {
simplifiedResponse = simplifiedResponse + ' ' + responseBody.detail;
}
}
//If response is object, it is an error response
this.hsToastService.createToastPopupMessage(
Expand Down
Expand Up @@ -205,10 +205,17 @@ export class HsCatalogueListItemComponent implements OnInit {
);
const confirmed = await dialog.waitResult();
if (confirmed == 'yes') {
await this.hsLaymanService.removeLayer(this.app, layer.name);
this.appRef.catalogEntries = this.appRef.catalogEntries.filter((item) => {
return item.id != layer.id;
});
const success = await this.hsLaymanService.removeLayer(
this.app,
layer.name
);
if (success) {
this.appRef.catalogEntries = this.appRef.catalogEntries.filter(
(item) => {
return item.id != layer.id;
}
);
}
}
}
}
12 changes: 8 additions & 4 deletions projects/hslayers/src/components/save-map/layman.service.ts
Expand Up @@ -875,7 +875,8 @@ export class HsLaymanService implements HsSaverService {
async removeLayer(
app: string,
layer?: Layer<Source> | string
): Promise<void> {
): Promise<boolean> {
let success: boolean;
return new Promise((resolve, reject): void => {
if (this.deleteQuery) {
this.deleteQuery.unsubscribe();
Expand Down Expand Up @@ -919,6 +920,7 @@ export class HsLaymanService implements HsSaverService {
response,
app
);
success = false;
} else {
let message = 'LAYMAN.layerSuccessfullyRemoved';
if (!layer) {
Expand All @@ -936,21 +938,22 @@ export class HsLaymanService implements HsSaverService {
},
app
);
success = true;
}
}
),
catchError((e) => {
this.hsToastService.createToastPopupMessage(
this.hsLanguageService.getTranslation(
'COMMON.warning',
'LAYMAN.deleteLayersRequest',
undefined,
app
),
this.hsLanguageService.getTranslationIgnoreNonExisting(
'SAVECOMPOSITION',
'removeLayerError',
{
error: e.error.message,
error: e.error.message ?? e.message,
layer:
layer instanceof Layer
? (layer as Layer<Source>).get('title')
Expand All @@ -961,13 +964,14 @@ export class HsLaymanService implements HsSaverService {
{serviceCalledFrom: 'HsLaymanService'},
app
);
success = false;
return of(e);
})
);
observables.push(response);
});
this.deleteQuery = forkJoin(observables).subscribe(() => {
resolve();
resolve(success);
});
});
}
Expand Down

0 comments on commit f797f2c

Please sign in to comment.