Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) GSGGR-187 better downloads #43

Merged
merged 10 commits into from
Nov 7, 2024
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ FROM node:22.6.0-slim AS builder
WORKDIR /usr/app

COPY package*.json ./.
RUN npm ci
RUN npm ci --legacy-peer-deps

COPY . .

RUN npm run build
RUN npm run build -- --localize && ls dist/
# Serve with nginx unpprevileged
FROM nginxinc/nginx-unprivileged:stable

Expand All @@ -17,4 +17,4 @@ FROM nginxinc/nginx-unprivileged:stable
COPY nginx/default.conf /etc/nginx/conf.d/default.conf

# Copy build artifacts
COPY --from=builder /usr/app/dist/ /usr/share/nginx/html
COPY --from=builder /usr/app/dist/ /usr/share/nginx/html/
5 changes: 4 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
"projects": {
"front": {
"i18n": {
"sourceLocale": "fr-CH",
"sourceLocale": "fr",
"locales": {
"de": {
"translation": "src/locale/messages.de.xlf"
},
"en": {
"translation": "src/locale/messages.en.xlf"
}
}
},
Expand Down
29 changes: 21 additions & 8 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@

# Extract default language from the headers
#
# map $http_accept_language $accept_language {
# ~*^de de;
# ~*^fr fr;
# ~*^en en;
# }

server {
listen 8080;
server_name localhost;
root /usr/share/nginx/html;
index index.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# Temporarily setting German as default language
set $accept_language "de";

location / {
try_files $uri $uri/ /index.html =404;
# Fallback to default language if no preference defined by browser
if ($accept_language ~ "^$") {
set $accept_language "de";
}

location /welcome {
rewrite ^/welcome/?$ / break;
# Redirect "/" to Angular application in the preferred language of the browser
rewrite ^/$ /$accept_language permanent;

# Everything under the Angular application is always redirected to Angular in the
# correct language
location ~ ^/(fr|de|en) {
try_files $uri /$1/index.html?$args;
}
}
50 changes: 27 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@
"dependencies": {
"@angular/animations": "^16.2.7",
"@angular/cdk": "^16.2.6",
"@angular/common": "^16.2.7",
"@angular/common": "^16.2.12",
"@angular/compiler": "^16.2.12",
"@angular/core": "^16.2.7",
"@angular/forms": "^16.2.7",
"@angular/material": "^16.2.14",
"@angular/platform-browser": "^16.2.12",
"@angular/platform-browser-dynamic": "^16.2.7",
"@angular/platform-browser-dynamic": "^16.2.12",
"@angular/router": "^16.2.7",
"@ngrx/effects": "^16.2.0",
"@ngrx/entity": "^16.2.0",
"@ngrx/store": "^16.2.0",
"angular-auth-oidc-client": "18.0.1",
"angular-auth-oidc-client": "18.0.2",
"angular-split": "^16.2.1",
"jasmine-spec-reporter": "^7.0.0",
"lodash-es": "^4.17.21",
"mime-types": "^2.1.35",
"ol": "^8.1.0",
"ol-ext": "^4.0.24",
"ol-geocoder": "^4.3.1",
"ol-geocoder": "^4.3.3",
"proj4": "^2.9.2",
"rxjs": "~7.8.1",
"tslib": "^2.6.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
<th mat-header-cell *matHeaderCellDef>{{ DOWNLAOD }}</th>
<td mat-cell *matCellDef="let element">
<button class="download-button" mat-raised-button color="primary"
*ngIf="element.status === 'PROCESSED'"
(click)="downloadOrder($event, element.id)">
*ngIf="element.status === 'PROCESSED' && element.download_guid"
(click)="downloadOrder($event, element)">
{{ DOWNLAOD }}
</button>
<span *ngIf="element.status !== 'PROCESSED'">{{ getOrderStatus(element) }}</span>
Expand Down
50 changes: 19 additions & 31 deletions src/app/_components/order-item-view/order-item-view.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Component, Input, OnInit} from '@angular/core';
import {IOrderItem, Order} from '../../_models/IOrder';
import {GeoshopUtils} from '../../_helpers/GeoshopUtils';
import {ApiOrderService} from '../../_services/api-order.service';
import {MatLegacySnackBar as MatSnackBar} from '@angular/material/legacy-snack-bar';
import {ConstantsService} from '../../constants.service';
import { Component, Input, OnInit } from '@angular/core';
import { IOrderItem, Order } from '../../_models/IOrder';
import { ApiOrderService } from '../../_services/api-order.service';
import { MatLegacySnackBar as MatSnackBar } from '@angular/material/legacy-snack-bar';
import { ConstantsService } from '../../constants.service';
import { HttpResponse } from '@angular/common/http';

@Component({
selector: 'gs2-order-item-view',
Expand All @@ -21,7 +21,7 @@ export class OrderItemViewComponent implements OnInit {
readonly DOWNLAOD = ConstantsService.DOWNLAOD;

constructor(private apiOrderService: ApiOrderService,
private snackBar: MatSnackBar) {
private snackBar: MatSnackBar) {
}

ngOnInit(): void {
Expand All @@ -42,34 +42,22 @@ export class OrderItemViewComponent implements OnInit {
return returnValue;
}

downloadOrder(event: MouseEvent, id: number) {
downloadOrder(event: MouseEvent, item: IOrderItem) {
event.stopPropagation();
event.preventDefault();

this.apiOrderService.downloadOrder(id, true).subscribe(link => {
if (!link) {
this.snackBar.open(
'Aucun fichier disponible', 'Ok', {panelClass: 'notification-info'}
);
return;
this.apiOrderService.downloadResult(item.download_guid!).subscribe({
next: (response: HttpResponse<Blob>) => {
const link = document.createElement('a');
// TODO: resolve filename properly after upgrading to the latest Angular
link.download = 'result.zip';
link.href = window.URL.createObjectURL(response.body!);
link.click();
window.URL.revokeObjectURL(link.href);
},
error: (error: any) => {
this.snackBar.open(error.detail ?? 'Aucun fichier disponible', 'Ok', { panelClass: 'notification-info' });
}

if (link.detail) {
this.snackBar.open(
link.detail, 'Ok', {panelClass: 'notification-info'}
);
return;
}

if (link.download_link) {
const downloadLink = link.download_link;
if (downloadLink) {
const urlsParts = downloadLink.split('/');
const filename = urlsParts.pop() || urlsParts.pop();
GeoshopUtils.downloadData(downloadLink, filename || 'download.zip');
}
}

});
}
}
2 changes: 1 addition & 1 deletion src/app/_helpers/GeoshopUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class GeoshopUtils {
total_with_vat_currency: '',
total_with_vat: '',
title: '',
status: 'DRAFT',
order_status: 'DRAFT',
processing_fee_currency: '',
processing_fee: '',
part_vat_currency: '',
Expand Down
Loading