Skip to content
Snippets Groups Projects
Commit 8ff177dc authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FEAT #14457 #14136 TIME 1:15 front users import + add var lang

parent 96c253e3
No related branches found
No related tags found
No related merge requests found
...@@ -170,37 +170,30 @@ class CoreController ...@@ -170,37 +170,30 @@ class CoreController
return $response->withStatus(400)->withJson(['errors' => 'Body langId is empty or not a string']); return $response->withStatus(400)->withJson(['errors' => 'Body langId is empty or not a string']);
} }
$content = 'export const LANG_'.strtoupper($body['langId']).' = '.json_encode($body['jsonContent'], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES).';'; $content = json_encode($body['jsonContent'], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
if ($fp = @fopen("src/frontend/lang/lang-{$body['langId']}.ts", 'w')) { if ($fp = @fopen("src/lang/lang-{$body['langId']}.json", 'w')) {
fwrite($fp, $content); fwrite($fp, $content);
fclose($fp); fclose($fp);
return $response->withStatus(204); return $response->withStatus(204);
} else { } else {
return $response->withStatus(400)->withJson(['errors' => "Cannot open file : src/frontend/lang/lang-{$body['langId']}.ts"]); return $response->withStatus(400)->withJson(['errors' => "Cannot open file : src/lang/lang-{$body['langId']}.json"]);
} }
} }
public static function getAvailableCoreLanguages(Request $request, Response $response) public static function getAvailableCoreLanguages(Request $request, Response $response)
{ {
$files = array_diff(scandir('src/frontend/lang'), ['..', '.']); $files = array_diff(scandir('src/lang'), ['..', '.']);
$languages = []; $languages = [];
$arrLanguages = []; $arrLanguages = [];
foreach ($files as $value) { foreach ($files as $value) {
$languages[] = str_replace('.ts', '', $value) ; $languages[] = str_replace('.json', '', $value) ;
} }
foreach ($languages as $file) { foreach ($languages as $file) {
$langName = explode('-', $file)[1]; $langName = explode('-', $file)[1];
$path = 'src/frontend/lang/' . $file . '.ts'; $path = 'src/lang/' . $file . '.json';
$fileContent = file_get_contents($path); $fileContent = file_get_contents($path);
$fileContent = str_replace('export const LANG_'.strtoupper($langName).' =', '', $fileContent);
$fileContent = trim($fileContent);
$fileContent = str_replace(PHP_EOL, '', $fileContent);
$fileContent = str_replace("\", ", "\",", $fileContent);
$fileContent = str_replace(" ", "", $fileContent);
$fileContent = str_replace(",};", "}", $fileContent);
$fileContent = rtrim($fileContent, ";");
$fileContent = json_decode($fileContent); $fileContent = json_decode($fileContent);
$arrLanguages[$langName] = $fileContent; $arrLanguages[$langName] = $fileContent;
} }
......
...@@ -49,7 +49,7 @@ export class UsersExportComponent implements OnInit { ...@@ -49,7 +49,7 @@ export class UsersExportComponent implements OnInit {
exportData() { exportData() {
this.localStorage.save(`exportUsersFields_${this.headerService.user.id}`, JSON.stringify(this.exportModel)); this.localStorage.save(`exportUsersFields_${this.headerService.user.id}`, JSON.stringify(this.exportModel));
this.loadingExport = true; this.loadingExport = true;
this.http.put('../rest/exportUsers', this.exportModel, { responseType: 'blob' }).pipe( this.http.put('../rest/users/export', this.exportModel, { responseType: 'blob' }).pipe(
tap((data: any) => { tap((data: any) => {
if (data.type !== 'text/html') { if (data.type !== 'text/html') {
const downloadLink = document.createElement('a'); const downloadLink = document.createElement('a');
......
<div class="mat-dialog-content-container"> <div class="mat-dialog-content-container">
<h1 mat-dialog-title>Importer des utilisateurs</h1> <h1 mat-dialog-title>{{'lang.usersImport' | translate}}</h1>
<div mat-dialog-content> <div mat-dialog-content>
<mat-toolbar class="import-tool" [class.hide]="csvData.length === 0 || loading"> <mat-toolbar class="import-tool" [class.hide]="csvData.length === 0 || loading">
<input type="file" name="files[]" #uploadFile id="uploadFile" (change)="uploadCsv($event)" accept=".csv" <input type="file" name="files[]" #uploadFile id="uploadFile" (change)="uploadCsv($event)" accept=".csv"
style="flex:1;"> style="flex:1;">
<span class="example-spacer"></span> <span class="example-spacer"></span>
<span style="flex:1;text-align: right;"><i class="fa fa-users" color="primary"></i>&nbsp;Utilisateurs du fichier : <b color="primary">{{countAll}}</b> <span style="flex:1;text-align: right;"><i class="fa fa-users" color="primary"></i>&nbsp;{{'lang.usersOfFile' | translate}} : <b color="primary">{{countAll}}</b>
<ng-container *ngIf="countAll > 10">&nbsp;(10 prévisualisées)</ng-container> <ng-container *ngIf="countAll > 10">&nbsp;(10 {{'lang.previewed' | translate}})</ng-container>
</span> </span>
<span style="flex:1;text-align: right;"><i class="fa fa-user-plus" color="primary"></i>&nbsp;Ajouts : <b color="primary">{{countAdd}}</b></span> <span style="flex:1;text-align: right;"><i class="fa fa-user-plus" color="primary"></i>&nbsp;{{'lang.additions' | translate}} : <b color="primary">{{countAdd}}</b></span>
<span style="flex:1;text-align: right;"><i class="fa fa-user-edit" color="primary"></i>&nbsp;Modifications : <b color="primary">{{countUp}}</b></span> <span style="flex:1;text-align: right;"><i class="fa fa-user-edit" color="primary"></i>&nbsp;{{'lang.modifications' | translate}} : <b color="primary">{{countUp}}</b></span>
</mat-toolbar> </mat-toolbar>
<ng-container *ngIf="loading; else elseTemplate"> <ng-container *ngIf="loading; else elseTemplate">
<div class="loader"> <div class="loader">
...@@ -20,17 +20,17 @@ ...@@ -20,17 +20,17 @@
<div *ngIf="csvData.length === 0" appUploadFileDragDrop (click)="uploadFile.click()" <div *ngIf="csvData.length === 0" appUploadFileDragDrop (click)="uploadFile.click()"
(onFileDropped)="dndUploadFile($event)" (onFileDropped)="dndUploadFile($event)"
class="dndFile"> class="dndFile">
Cliquez ici ou clissez-déposez un fichier csv {{'lang.dndFileCsvDesc' | translate}}
</div> </div>
<mat-table *ngIf="csvData.length > 0" #table [dataSource]="dataSource"> <mat-table *ngIf="csvData.length > 0" #table [dataSource]="dataSource">
<ng-container *ngFor="let column of userColmuns;let i=index;"> <ng-container *ngFor="let column of userColmuns;let i=index;">
<ng-container [matColumnDef]="column"> <ng-container [matColumnDef]="column">
<mat-header-cell *matHeaderCellDef> <mat-header-cell *matHeaderCellDef>
<i class="fas fa-database" color="primary" [title]="'colonne base de données'"></i>&nbsp;<b <i class="fas fa-database" color="primary" [title]="'lang.dbColumn' | translate"></i>&nbsp;<b
color="primary" [title]="'colonne base de données'">{{column}}</b> color="primary" [title]="'lang.dbColumn' | translate">{{column}}</b>
&nbsp;<i class="fas fa-arrows-alt-h"></i>&nbsp; &nbsp;<i class="fas fa-arrows-alt-h"></i>&nbsp;
<i class="fas fa-file-csv" [title]="'colonne fichier csv'"></i>&nbsp;<mat-form-field <i class="fas fa-file-csv" [title]="'lang.csvColumn' | translate"></i>&nbsp;<mat-form-field
[title]="'colonne fichier csv'" (click)="$event.stopPropagation()" [title]="'lang.csvColumn' | translate" (click)="$event.stopPropagation()"
style="width: 80px !important;"> style="width: 80px !important;">
<mat-select [(ngModel)]="associatedColmuns[column]" <mat-select [(ngModel)]="associatedColmuns[column]"
(selectionChange)="changeColumn(column, $event.value)"> (selectionChange)="changeColumn(column, $event.value)">
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
</div> </div>
<span class="divider-modal"></span> <span class="divider-modal"></span>
<div mat-dialog-actions class="actions"> <div mat-dialog-actions class="actions">
<button mat-raised-button mat-button *ngIf="csvData.length > 0" color="primary" [disabled]="loading" (click)="onSubmit()">Valider</button> <button mat-raised-button mat-button *ngIf="csvData.length > 0" color="primary" [disabled]="loading" (click)="onSubmit()">{{'lang.validate' | translate}}</button>
<button mat-raised-button mat-button [disabled]="loading" [mat-dialog-close]="">{{'lang.cancel' | translate }}</button> <button mat-raised-button mat-button [disabled]="loading" [mat-dialog-close]="">{{'lang.cancel' | translate }}</button>
</div> </div>
</div> </div>
\ No newline at end of file
...@@ -166,22 +166,29 @@ export class UsersImportComponent implements OnInit { ...@@ -166,22 +166,29 @@ export class UsersImportComponent implements OnInit {
'phone': element[this.associatedColmuns['phone']] 'phone': element[this.associatedColmuns['phone']]
}); });
}); });
console.log(dataToSend);
}), }),
exhaustMap(() => this.http.put(`../rest/importUsers`, { users: dataToSend })), exhaustMap(() => this.http.put(`../rest/users/import`, { users: dataToSend })),
tap((data: any) => { tap((data: any) => {
/*let text = ''; let text = '';
if (this.functionsService.empty(data.error) ) { if (data.warnings.count > 0) {
text = `<br/>${data.error.count} en erreur : <ul>`; text = `<br/>${data.warning.count} ${this.translate.instant('lang.widthWarnings')} : <ul>`;
data.errors.lines.forEach(element => { data.errors.details.forEach(element => {
text += `<li> ligne : ${element}</li>`; text += `<li> ${this.translate.instant('element.lang')} (${this.translate.instant('lang.line')} : ${element.index + 1})</li>`;
}); });
text += '</ul>'; text += '</ul>';
} }
dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: 'Importer', msg: '<b>' + data.success + '</b> / <b>' + this.countAll + '</b> utilisateurs importés.' + text } });
*/ if (data.errors.count > 0) {
text = `<br/>${data.errors.count} ${this.translate.instant('lang.widthErrors')} : <ul>`;
data.errors.details.forEach(element => {
text += `<li> ${this.translate.instant('element.lang')} (${this.translate.instant('lang.line')} : ${element.index + 1})</li>`;
});
text += '</ul>';
}
dialogRef = this.dialog.open(AlertComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: 'Importer', msg: '<b>' + data.success + '</b> / <b>' + this.countAll + '</b> utilisateurs importés.' + text } });
// FOR TEST // FOR TEST
dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: 'Importer', msg: 'success!' } }); // dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: 'Importer', msg: 'success!' } });
}), }),
exhaustMap(() => dialogRef.afterClosed()), exhaustMap(() => dialogRef.afterClosed()),
tap(() => { tap(() => {
......
This diff is collapsed.
...@@ -1865,5 +1865,16 @@ ...@@ -1865,5 +1865,16 @@
"hideTool": "Cacher la barre d'outils", "hideTool": "Cacher la barre d'outils",
"showTool": "Afficher la barre d'outils", "showTool": "Afficher la barre d'outils",
"rest": "Compte de webservice", "rest": "Compte de webservice",
"mustSuperadmin": "Vous devez être vous-même administrateur pour définir des administrateurs" "mustSuperadmin": "Vous devez être vous-même administrateur pour définir des administrateurs",
"usersImport": "Importer des utilisateurs",
"usersOfFile": "Utilisateur du fichier",
"previewed": "Prévisualisées",
"additions" : "Ajouts",
"modifications" : "Modifications",
"dndFileCsvDesc": "Cliquez ici ou clissez-déposez un fichier csv",
"dbColumn": "Colonne base de données",
"csvColumn": "Colonne fichier csv",
"withWarnings": "avec avertissements",
"withErrors": "avec erreurs",
"line": "ligne"
} }
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment