From 7c4fa5596112e5a41a445ea3ccd0066cbdf152f1 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Tue, 23 Jun 2020 19:26:57 +0200
Subject: [PATCH] FEAT #13671 TIME 2 front install

---
 .../basket-administration.component.html      |  2 +-
 src/frontend/app/app-common.module.ts         |  4 +-
 .../customization.component.html              | 87 ++++++++++---------
 .../customization/customization.component.ts  | 14 ++-
 .../database/database.component.html          |  5 +-
 .../installer/database/database.component.ts  | 33 +++++--
 .../docservers/docservers.component.html      |  1 +
 .../docservers/docservers.component.ts        | 21 +++++
 .../install-action.component.ts               |  4 +-
 .../app/installer/installer.module.ts         |  2 -
 src/frontend/lang/lang-fr.ts                  |  4 +-
 11 files changed, 116 insertions(+), 61 deletions(-)

diff --git a/src/frontend/app/administration/basket/basket-administration.component.html b/src/frontend/app/administration/basket/basket-administration.component.html
index 7e445b1208b..fd0803d70a6 100755
--- a/src/frontend/app/administration/basket/basket-administration.component.html
+++ b/src/frontend/app/administration/basket/basket-administration.component.html
@@ -220,7 +220,7 @@
                                     </div>
                                 </mat-tab>
                                 <mat-tab label="{{lang.resultPage}}">
-                                    <list-administration [currentBasketGroup]="group" (refreshBasketGroup)="group=$event"></list-administration>
+                                    <list-administration [currentBasketGroup]="group"></list-administration>
                                 </mat-tab>
                             </mat-tab-group>
                         </mat-tab>
diff --git a/src/frontend/app/app-common.module.ts b/src/frontend/app/app-common.module.ts
index 93f9428757e..180da1b1698 100755
--- a/src/frontend/app/app-common.module.ts
+++ b/src/frontend/app/app-common.module.ts
@@ -123,6 +123,8 @@ import { LinkedResourceListComponent } from './linkedResource/linked-resource-li
         ReactiveFormsModule,
         RouterModule,
         AppMaterialModule,
+        AppServiceModule,
+        NotificationModule,
         SmdFabSpeedDialComponent,
         SmdFabSpeedDialTrigger,
         SmdFabSpeedDialActions,
@@ -146,8 +148,6 @@ import { LinkedResourceListComponent } from './linkedResource/linked-resource-li
         FolderMenuComponent,
         FolderActionListComponent,
         LinkedResourceListComponent,
-        AppServiceModule,
-        NotificationModule
     ],
     providers: [],
     entryComponents: [
diff --git a/src/frontend/app/installer/customization/customization.component.html b/src/frontend/app/installer/customization/customization.component.html
index 43e05c08be0..70a0f4a94be 100644
--- a/src/frontend/app/installer/customization/customization.component.html
+++ b/src/frontend/app/installer/customization/customization.component.html
@@ -3,48 +3,51 @@
     <div class="alert-message alert-message-info" role="alert" style="margin-top: 30px;min-width: 100%;">
         {{lang.stepCustomization_desc}}
     </div>
-    <div class="col-md-6">
-        <mat-form-field appearance="outline">
-            <mat-label>{{lang.instanceName}}</mat-label>
-            <input matInput [(ngModel)]="customId">
-        </mat-form-field>
-        <mat-form-field appearance="outline">
-            <mat-label>{{lang.applicationName}}</mat-label>
-            <input matInput [(ngModel)]="appName">
-        </mat-form-field>
-        <div>{{lang.loginMsg}} : </div>
-        <textarea style="padding-top: 10px;" name="loginMsg" id="loginMsg" [(ngModel)]="loginMsg"></textarea>
-        <br />
-        <br />
-        <div>{{lang.homeMsg}} : </div>
-        <textarea style="padding-top: 10px;" name="homeMsg" id="homeMsg" [(ngModel)]="homeMsg"></textarea>
-        <br />
-        <br />
-    </div>
-    <div class="col-md-6">
-        <div>{{lang.chooseLogo}} : </div>
-        <div>
-            <mat-card style="width: 350px;background-size: 100%;cursor: pointer;" matRipple>
-                <img [src]="logoURL()" (click)="uploadLogo.click()" style="width: 100%;"/>
-                <input type="file" name="files[]" #uploadLogo (change)="uploadTrigger($event, 'logo')" accept="image/svg+xml" style="display: none;">
-            </mat-card>
+    <form [formGroup]="stepFormGroup" style="display: content;">
+        <div class="col-md-6">
+            <mat-form-field appearance="outline">
+                <mat-label>{{lang.instanceId}}</mat-label>
+                <input matInput formControlName="customId">
+                <mat-error>Seul les caractères spéciaux - et _ sont autorisés</mat-error>
+            </mat-form-field>
+            <mat-form-field appearance="outline">
+                <mat-label>{{lang.applicationName}}</mat-label>
+                <input matInput formControlName="appName">
+            </mat-form-field>
+            <div>{{lang.loginMsg}} : </div>
+            <textarea style="padding-top: 10px;" name="loginMsg" id="loginMsg" formControlName="loginMsg"></textarea>
+            <br />
+            <br />
+            <div>{{lang.homeMsg}} : </div>
+            <textarea style="padding-top: 10px;" name="homeMsg" id="homeMsg" formControlName="homeMsg"></textarea>
+            <br />
+            <br />
         </div>
-        <br />
-        <div>{{lang.chooseLoginBg}} : </div>
-        <div class="backgroundList">
-            <mat-card (click)="selectedBackground='bodylogin.jpg'" style="opacity: 0.3;" class="backgroundItem"
-                [class.selected]="selectedBackground === 'bodylogin.jpg'"
-                style="background:url(assets/bodylogin.jpg);background-size: cover;">
-            </mat-card>
-            <mat-card *ngFor="let background of backgroundList" (click)="selectedBackground=background.filename"
-                style="opacity: 0.3;" class="backgroundItem"
-                [class.selected]="background.filename === selectedBackground"
-                [style.background]="'url('+background.url+')'">
-            </mat-card>
-            <mat-card style="opacity: 0.3;display: flex;align-items: center;justify-content: center;" class="backgroundItem" (click)="uploadFile.click()">
-                <input type="file" name="files[]" #uploadFile (change)="uploadTrigger($event, 'bg')" accept="image/jpg" style="display: none;">
-                <i class="fa fa-plus" style="font-size: 30px;color: #666;"></i>
-            </mat-card>
+        <div class="col-md-6">
+            <div>{{lang.chooseLogo}} : </div>
+            <div>
+                <mat-card style="width: 350px;background-size: 100%;cursor: pointer;" matRipple>
+                    <img [src]="logoURL()" (click)="uploadLogo.click()" style="width: 100%;"/>
+                    <input type="file" name="files[]" #uploadLogo (change)="uploadTrigger($event, 'logo')" accept="image/svg+xml" style="display: none;">
+                </mat-card>
+            </div>
+            <br />
+            <div>{{lang.chooseLoginBg}} : </div>
+            <div class="backgroundList">
+                <mat-card (click)="stepFormGroup.controls['selectedBackground'].value='bodylogin.jpg'" style="opacity: 0.3;" class="backgroundItem"
+                    [class.selected]="stepFormGroup.controls['selectedBackground'].value === 'bodylogin.jpg'"
+                    style="background:url(assets/bodylogin.jpg);background-size: cover;">
+                </mat-card>
+                <mat-card *ngFor="let background of backgroundList" (click)="stepFormGroup.controls['selectedBackground'].value=background.filename"
+                    style="opacity: 0.3;" class="backgroundItem"
+                    [class.selected]="background.filename === stepFormGroup.controls['selectedBackground'].value"
+                    [style.background]="'url('+background.url+')'">
+                </mat-card>
+                <mat-card style="opacity: 0.3;display: flex;align-items: center;justify-content: center;" class="backgroundItem" (click)="uploadFile.click()">
+                    <input type="file" name="files[]" #uploadFile (change)="uploadTrigger($event, 'bg')" accept="image/jpg" style="display: none;">
+                    <i class="fa fa-plus" style="font-size: 30px;color: #666;"></i>
+                </mat-card>
+            </div>
         </div>
-    </div>
+    </form>
 </div>
\ No newline at end of file
diff --git a/src/frontend/app/installer/customization/customization.component.ts b/src/frontend/app/installer/customization/customization.component.ts
index 2a45c40f434..f65d59638e0 100644
--- a/src/frontend/app/installer/customization/customization.component.ts
+++ b/src/frontend/app/installer/customization/customization.component.ts
@@ -1,9 +1,9 @@
 import { Component, OnInit } from '@angular/core';
-import { FormBuilder, FormGroup, Validators } from '@angular/forms';
-import { NotificationService } from '../../../service/notification/notification.service';
+import { FormBuilder, FormGroup, Validators, ValidatorFn } from '@angular/forms';
 import { LANG } from '../../translate.component';
 import { StepAction } from '../types';
 import { DomSanitizer } from '@angular/platform-browser';
+import { NotificationService } from '../../../service/notification/notification.service';
 
 declare var tinymce: any;
 
@@ -25,14 +25,20 @@ export class CustomizationComponent implements OnInit {
     uploadedLogo: string = '../rest/images?image=logo';
 
     backgroundList: any[] = [];
-
     constructor(
         private _formBuilder: FormBuilder,
         private notify: NotificationService,
         private sanitizer: DomSanitizer
     ) {
+        const valIdentifier: ValidatorFn[] = [Validators.pattern(/^[a-zA-Z0-9_\-]*$/), Validators.required];
+
         this.stepFormGroup = this._formBuilder.group({
             firstCtrl: ['success', Validators.required],
+            customId: ['cs_maarchcourrier', valIdentifier],
+            appName: ['Maarch Courrier 20.10', Validators.required],
+            loginMsg: ['<span style="color:#24b0ed"><strong>Découvrez votre application via</strong></span>&nbsp;<a title="le guide de visite" href="https://docs.maarch.org/gitbook/html/MaarchCourrier/19.04/guu/home.html" target="_blank"><span style="color:#f99830;"><strong>le guide de visite en ligne</strong></span></a>'],
+            homeMsg: ['<p>D&eacute;couvrez <strong>Maarch Courrier 20.10</strong> avec <a title="notre guide de visite" href="https://docs.maarch.org/" target="_blank"><span style="color:#f99830;"><strong>notre guide de visite en ligne</strong></span></a>.</p>'],
+            selectedBackground: ['bodylogin.jpg'],
         });
         this.backgroundList = Array.from({ length: 16 }).map((_, i) => {
             return {
@@ -90,7 +96,7 @@ export class CustomizationComponent implements OnInit {
     getInfoToInstall(): StepAction[] {
         return [{
             body : {
-                customName: this.customId,
+                customId: this.customId,
             },
             description : 'Initialisation de l\'instance',
             route : '../rest/installer/custom',
diff --git a/src/frontend/app/installer/database/database.component.html b/src/frontend/app/installer/database/database.component.html
index f2ac0085f4d..7eff19d1487 100644
--- a/src/frontend/app/installer/database/database.component.html
+++ b/src/frontend/app/installer/database/database.component.html
@@ -27,10 +27,13 @@
             <mat-label>{{lang.dbName}}</mat-label>
             <input matInput formControlName="dbNameCtrl" required>
         </mat-form-field>
+        <div class="alert-message alert-message-info" *ngIf="dbExist" role="alert" style="margin-top: 30px;min-width: 100%;">
+            {{lang.stepEmptyDb}}
+        </div>
         <mat-form-field appearance="outline" floatLabel="never">
             <mat-label>{{lang.dbSample}}</mat-label>
             <mat-select formControlName="dbSampleCtrl">
-                <mat-option *ngFor="let sample of dataSamples" [value]="sample">
+                <mat-option *ngFor="let sample of dataFiles" [value]="sample">
                     {{sample}}
                 </mat-option>
             </mat-select>
diff --git a/src/frontend/app/installer/database/database.component.ts b/src/frontend/app/installer/database/database.component.ts
index ad09d61586b..5587f037ca8 100644
--- a/src/frontend/app/installer/database/database.component.ts
+++ b/src/frontend/app/installer/database/database.component.ts
@@ -7,6 +7,7 @@ import { catchError } from 'rxjs/internal/operators/catchError';
 import { of } from 'rxjs/internal/observable/of';
 import { LANG } from '../../translate.component';
 import { StepAction } from '../types';
+import { FunctionsService } from '../../../service/functions.service';
 
 @Component({
     selector: 'app-database',
@@ -19,16 +20,15 @@ export class DatabaseComponent implements OnInit {
     hide: boolean = true;
 
     connectionState: boolean = false;
+    dbExist: boolean = false;
 
-    dataSamples: string[] = [
-        'data_fr',
-        'data_en'
-    ];
+    dataFiles: string[] = [];
 
     constructor(
         public http: HttpClient,
         private _formBuilder: FormBuilder,
         private notify: NotificationService,
+        private functionsService: FunctionsService,
     ) {
         this.stepFormGroup = this._formBuilder.group({
             dbHostCtrl: ['localhost', Validators.required],
@@ -57,6 +57,20 @@ export class DatabaseComponent implements OnInit {
         this.stepFormGroup.controls['dbNameCtrl'].valueChanges.pipe(
             tap(() => this.stepFormGroup.controls['stateStep'].setValue(''))
         ).subscribe();
+
+        this.getDataFiles();
+    }
+
+    getDataFiles() {
+        this.http.get(`../rest/installer/sqlDataFiles`).pipe(
+            tap((data: any) => {
+                this.dataFiles = data.dataFiles;
+            }),
+            catchError((err: any) => {
+                this.notify.handleSoftErrors(err);
+                return of(false);
+            })
+        ).subscribe();
     }
 
     isValidConnection() {
@@ -75,8 +89,15 @@ export class DatabaseComponent implements OnInit {
 
         this.http.get(`../rest/installer/databaseConnection`, { params: info }).pipe(
             tap((data: any) => {
-                this.notify.success(this.lang.rightInformations);
-                this.stepFormGroup.controls['stateStep'].setValue('success');
+                console.log(this.functionsService.empty(data.warning));
+                if (!this.functionsService.empty(data.warning)) {
+                    this.dbExist = true;
+                    this.stepFormGroup.controls['stateStep'].setValue('');
+                } else {
+                    this.dbExist = false;
+                    this.notify.success(this.lang.rightInformations);
+                    this.stepFormGroup.controls['stateStep'].setValue('success');
+                }
             }),
             catchError((err: any) => {
                 this.notify.error(this.lang.badInformations);
diff --git a/src/frontend/app/installer/docservers/docservers.component.html b/src/frontend/app/installer/docservers/docservers.component.html
index 3c0bdd6e1f0..1d7ca5216b7 100644
--- a/src/frontend/app/installer/docservers/docservers.component.html
+++ b/src/frontend/app/installer/docservers/docservers.component.html
@@ -7,6 +7,7 @@
         <mat-form-field appearance="outline" style="color: initial;">
             <mat-label>{{lang.docserverPath}}</mat-label>
             <input matInput formControlName="docserversPath">
+            <span matSuffix>/__CUSTOM_iD__/</span>
         </mat-form-field>
         <div style="text-align: center;">
             <button mat-raised-button type="button" color="primary" (click)="checkAvailability()" [disabled]="!this.stepFormGroup.controls['docserversPath'].valid">{{lang.checkInformations}}</button>
diff --git a/src/frontend/app/installer/docservers/docservers.component.ts b/src/frontend/app/installer/docservers/docservers.component.ts
index 5e0fc32564e..783340ff9ee 100644
--- a/src/frontend/app/installer/docservers/docservers.component.ts
+++ b/src/frontend/app/installer/docservers/docservers.component.ts
@@ -3,6 +3,9 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
 import { NotificationService } from '../../../service/notification/notification.service';
 import { tap } from 'rxjs/internal/operators/tap';
 import { LANG } from '../../translate.component';
+import { catchError } from 'rxjs/operators';
+import { of } from 'rxjs';
+import { HttpClient } from '@angular/common/http';
 
 @Component({
     selector: 'app-docservers',
@@ -16,6 +19,7 @@ export class DocserversComponent implements OnInit {
     constructor(
         private _formBuilder: FormBuilder,
         private notify: NotificationService,
+        public http: HttpClient,
     ) {
         this.stepFormGroup = this._formBuilder.group({
             docserversPath: ['/opt/maaarch/docservers/', Validators.required],
@@ -41,6 +45,23 @@ export class DocserversComponent implements OnInit {
     }
 
     checkAvailability() {
+        const info = {
+            path: this.stepFormGroup.controls['docserversPath'].value,
+        };
+
+        /*this.http.get(`../rest/installer/docservers`, { params: info }).pipe(
+            tap((data: any) => {
+                this.notify.success(this.lang.rightInformations);
+                this.stepFormGroup.controls['stateStep'].setValue('success');
+            }),
+            catchError((err: any) => {
+                this.notify.error(this.lang.badInformations);
+                this.stepFormGroup.controls['stateStep'].setValue('');
+                return of(false);
+            })
+        ).subscribe();*/
+
+        // FOR TEST
         this.stepFormGroup.controls['stateStep'].setValue('success');
         this.notify.success(this.lang.rightInformations);
     }
diff --git a/src/frontend/app/installer/install-action/install-action.component.ts b/src/frontend/app/installer/install-action/install-action.component.ts
index a781b7ba658..fdf31128a58 100644
--- a/src/frontend/app/installer/install-action/install-action.component.ts
+++ b/src/frontend/app/installer/install-action/install-action.component.ts
@@ -30,9 +30,9 @@ export class InstallActionComponent implements OnInit {
     initSteps() {
         this.data.forEach((step: any, index: number) => {
             if (index === 0) {
-                this.customId = step.body.customName;
+                this.customId = step.body.customId;
             } else {
-                step.body.customName = this.customId;
+                step.body.customId = this.customId;
             }
             this.steps.push(
                 {
diff --git a/src/frontend/app/installer/installer.module.ts b/src/frontend/app/installer/installer.module.ts
index 159a2483f1c..8cbe8921142 100644
--- a/src/frontend/app/installer/installer.module.ts
+++ b/src/frontend/app/installer/installer.module.ts
@@ -1,7 +1,5 @@
 import { NgModule } from '@angular/core';
-
 import { SharedModule } from '../app-common.module';
-
 import { InstallerComponent } from './installer.component';
 import { InstallActionComponent } from './install-action/install-action.component';
 import { WelcomeComponent } from './welcome/welcome.component';
diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts
index 15dcaf9a49c..1f8444b5d67 100755
--- a/src/frontend/lang/lang-fr.ts
+++ b/src/frontend/lang/lang-fr.ts
@@ -1793,5 +1793,7 @@ export const LANG_FR = {
     "indexingModelReassign": "Réaffection du modèle d'enregistrement",
     "updateInformations": "Actualiser les informations",
     "dbSample": "Jeu de données",
-    "chooseLogo": "Choisissez votre logo"
+    "chooseLogo": "Choisissez votre logo",
+    "stepEmptyDb": "Cette base éxiste déjà ! Si celle-ci n'est pas vide, cela peut engendrer une corruption des données éxistantes !",
+    "instanceId": "identifiant de l'instance"
 };
-- 
GitLab