From f03f79f1469609e6a1331bed1799d4a852bae575 Mon Sep 17 00:00:00 2001
From: Damien <damien.burel@maarch.org>
Date: Thu, 27 Jun 2019 16:11:24 +0200
Subject: [PATCH] FEAT #10426 TIME 1:00 Delete useless dev dependencies +
 refactoring

---
 angular.json                                  | 18 --------
 package.json                                  |  9 ----
 src/app/user/controllers/UserController.php   |  4 +-
 src/app/user/models/UserModel.php             |  4 +-
 .../sendmail/sendmail.component.ts            | 45 +++++++++----------
 src/frontend/app/app.module.ts                | 10 ++---
 .../app/document/document.component.ts        |  4 +-
 .../document-note-pad.component.ts            |  2 +-
 src/frontend/app/profile/profile.component.ts |  2 +-
 .../app/service/auth-interceptor.service.ts   | 10 ++---
 src/frontend/app/service/auth.guard.ts        |  3 +-
 src/frontend/core/environments/environment.ts |  2 +-
 src/frontend/core/karma.conf.js               | 31 -------------
 src/frontend/core/test.ts                     | 20 ---------
 src/frontend/core/tsconfig.spec.json          |  1 -
 src/frontend/core/tslint.json                 |  2 +-
 tslint.json                                   |  2 +-
 17 files changed, 43 insertions(+), 126 deletions(-)
 delete mode 100644 src/frontend/core/karma.conf.js
 delete mode 100644 src/frontend/core/test.ts

diff --git a/angular.json b/angular.json
index 9b58dcac47..d05d01cfb0 100755
--- a/angular.json
+++ b/angular.json
@@ -68,24 +68,6 @@
             "browserTarget": "parapheur:build"
           }
         },
-        "test": {
-          "builder": "@angular-devkit/build-angular:karma",
-          "options": {
-            "main": "./src/frontend/core/test.ts",
-            "polyfills": "./src/frontend/core/polyfills.ts",
-            "tsConfig": "./src/frontend/core/tsconfig.spec.json",
-            "karmaConfig": "./src/frontend/core/karma.conf.js",
-            "styles": [
-              "./src/frontend/core/styles.scss",
-              "./node_modules/@fortawesome/fontawesome-free/css/all.min.css"
-            ],
-            "scripts": [],
-            "assets": [
-              "src/frontend/core/favicon.ico",
-              "src/frontend/assets"
-            ]
-          }
-        },
         "lint": {
           "builder": "@angular-devkit/build-angular:tslint",
           "options": {
diff --git a/package.json b/package.json
index 0c19da47ce..d2e361e544 100644
--- a/package.json
+++ b/package.json
@@ -56,24 +56,15 @@
     "codelyzer": "~5.0.0",
     "exif-js": "^2.3.0",
     "hammerjs": "^2.0.8",
-    "jasmine-core": "~3.4.0",
-    "jasmine-spec-reporter": "~4.2.1",
     "jquery": "^3.4.0",
-    "karma": "~4.0.1",
-    "karma-chrome-launcher": "~2.2.0",
-    "karma-coverage-istanbul-reporter": "^2.0.5",
-    "karma-jasmine": "~2.0.1",
-    "karma-jasmine-html-reporter": "^1.4.0",
     "ngx-cookie-service": "^2.1.0",
     "ngx-pipes": "^2.5.1",
     "ngx-scroll-event": "^1.0.8",
     "node-sass": "^4.11.0",
     "npm-check-updates": "^3.1.10",
-    "protractor": "^5.4.2",
     "rxjs": "^6.5.1",
     "stylus": "^0.54.5",
     "stylus-loader": "^3.0.2",
-    "ts-node": "~8.0.3",
     "tslint": "~5.15.0",
     "typescript": "3.2.4",
     "typescript-tools": "^0.3.1"
diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php
index 80edcdb4f3..da97e3fe40 100755
--- a/src/app/user/controllers/UserController.php
+++ b/src/app/user/controllers/UserController.php
@@ -126,7 +126,7 @@ class UserController
         }
 
         if (!empty($body['isRest'])) {
-            $body['"isRest"'] = 'true';
+            $body['"isRest"'] = true;
         }
         if (empty($body['picture'])) {
             $body['picture'] = base64_encode(file_get_contents('src/frontend/assets/user_picture.png'));
@@ -220,7 +220,7 @@ class UserController
         }
 
         if (isset($body['isRest'])) {
-            $set['"isRest"'] = $body['isRest'];
+            $set['"isRest"'] = $body['isRest'] ? 'true' : 'false';
         }
 
         UserModel::update([
diff --git a/src/app/user/models/UserModel.php b/src/app/user/models/UserModel.php
index b588ac13b1..4b92238029 100755
--- a/src/app/user/models/UserModel.php
+++ b/src/app/user/models/UserModel.php
@@ -79,7 +79,7 @@ class UserModel
 
     public static function create(array $args)
     {
-        ValidatorModel::notEmpty($args, ['login', 'email', 'firstname', 'lastname', 'mode', 'picture']);
+        ValidatorModel::notEmpty($args, ['login', 'email', 'firstname', 'lastname', 'picture']);
         ValidatorModel::stringType($args, ['login', 'email', 'firstname', 'lastname', 'picture', 'mode']);
 
         $nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'users_id_seq']);
@@ -93,7 +93,7 @@ class UserModel
                 'password'                      => AuthenticationModel::getPasswordHash('maarch'),
                 'firstname'                     => $args['firstname'],
                 'lastname'                      => $args['lastname'],
-                'mode'                          => $args['mode'],
+                '"isRest"'                      => empty($args['isRest']) ? 'false' : 'true',
                 'picture'                       => $args['picture'],
                 'password_modification_date'    => 'CURRENT_TIMESTAMP'
             ]
diff --git a/src/frontend/app/administration/sendmail/sendmail.component.ts b/src/frontend/app/administration/sendmail/sendmail.component.ts
index b835885ed5..b851df86a0 100644
--- a/src/frontend/app/administration/sendmail/sendmail.component.ts
+++ b/src/frontend/app/administration/sendmail/sendmail.component.ts
@@ -9,16 +9,17 @@ import { TranslateService } from '@ngx-translate/core';
 
 
 export interface Sendmail {
-    auth: boolean,
-    from: string,
-    host: string,
-    port: number,
-    type: string,
-    user: string,
-    secure: string,
-    charset: string,
-    password: string,
-    passwordAlreadyExists: boolean
+
+    auth:                   boolean;
+    from:                   string;
+    host:                   string;
+    port:                   number;
+    type:                   string;
+    user:                   string;
+    secure:                 string;
+    charset:                string;
+    password:               string;
+    passwordAlreadyExists:  boolean;
 }
 
 @Component({
@@ -106,11 +107,7 @@ export class SendmailComponent implements OnInit {
     }
 
     canValidate() {
-        if (JSON.stringify(this.sendmail) === JSON.stringify(this.sendmailClone)) {
-            return false;
-        } else {
-            return true;
-        }
+        return JSON.stringify(this.sendmail) !== JSON.stringify(this.sendmailClone);
     }
 
     onSubmit() {
@@ -141,13 +138,13 @@ export class SendmailComponent implements OnInit {
             debug: '',
             error: false
         };
-        let email = {
-            "sender": this.sendmail.from,
-            "recipients": [this.recipientTest],
-            "subject": "[" + this.translate.instant('lang.doNotReply') +"] " + this.translate.instant('lang.emailSendTest'),
-            "status": "EXPRESS",
-            "body": this.translate.instant('lang.emailSendTest'),
-            "isHtml": false
+        const email = {
+            'sender'        : this.sendmail.from,
+            'recipients'    : [this.recipientTest],
+            'subject'       : '[' + this.translate.instant('lang.doNotReply') + '] ' + this.translate.instant('lang.emailSendTest'),
+            'status'        : 'EXPRESS',
+            'body'          : this.translate.instant('lang.emailSendTest'),
+            'isHtml'        : false
         };
         this.emailSendLoading = true;
 
@@ -156,7 +153,7 @@ export class SendmailComponent implements OnInit {
                 finalize(() => this.emailSendLoading = false)
             )
             .subscribe({
-                next: (data : any) => {
+                next: (data: any) => {
                     if (data.isSent) {
                         this.emailSendResult = {
                             icon: 'fa-check green',
@@ -181,7 +178,7 @@ export class SendmailComponent implements OnInit {
         this.sendmail.user = '';
         this.sendmail.password = '';
     }
- 
+
     cancel() {
         this.router.navigate(['/administration']);
     }
diff --git a/src/frontend/app/app.module.ts b/src/frontend/app/app.module.ts
index feeddbd6f0..521deffc5f 100755
--- a/src/frontend/app/app.module.ts
+++ b/src/frontend/app/app.module.ts
@@ -184,11 +184,6 @@ import { AlertComponent } from './plugins/alert.component';
 })
 export class AppModule { }
 
-// For traductions
-export function HttpLoaderFactory(http: HttpClient) {
-  return new TranslateBackendHttpLoader(http);
-}
-
 export class TranslateBackendHttpLoader implements TranslateLoader {
 
   constructor(private http: HttpClient) { }
@@ -203,3 +198,8 @@ export class TranslateBackendHttpLoader implements TranslateLoader {
     return this.http.get(`../rest/languages/` + lang);
   }
 }
+
+// For traductions
+export function HttpLoaderFactory(http: HttpClient) {
+  return new TranslateBackendHttpLoader(http);
+}
diff --git a/src/frontend/app/document/document.component.ts b/src/frontend/app/document/document.component.ts
index 9444e85381..4001618588 100755
--- a/src/frontend/app/document/document.component.ts
+++ b/src/frontend/app/document/document.component.ts
@@ -229,9 +229,9 @@ export class DocumentComponent implements OnInit {
         this.signaturesService.signaturesContent = [];
         this.signaturesService.notesContent = [];
 
-        let notesContent = localStorage.getItem(this.mainDocument.id.toString());
+        const notesContent = localStorage.getItem(this.mainDocument.id.toString());
         if (notesContent) {
-            let storageContent = JSON.parse(notesContent);
+            const storageContent = JSON.parse(notesContent);
             this.signaturesService.notesContent = storageContent['note'];
             this.signaturesService.signaturesContent = storageContent['sign'];
         }
diff --git a/src/frontend/app/documentNotePad/document-note-pad.component.ts b/src/frontend/app/documentNotePad/document-note-pad.component.ts
index 51e860e170..77cacdb6e6 100644
--- a/src/frontend/app/documentNotePad/document-note-pad.component.ts
+++ b/src/frontend/app/documentNotePad/document-note-pad.component.ts
@@ -33,7 +33,7 @@ export class DocumentNotePadComponent implements OnInit {
                 fixWidth: this.signaturesService.x,
                 mobileMode: this.signaturesService.mobileMode
             });
-            $('input[value=\'' + this.signaturesService.userLogged.preferences.writingColor + '\']').click();
+            $('input[value=\'' + this.signaturesService.userLogged.preferences.writingColor + '\']').trigger('click');
         }, 200);
     }
 
diff --git a/src/frontend/app/profile/profile.component.ts b/src/frontend/app/profile/profile.component.ts
index 074ec4abcc..08537f8587 100644
--- a/src/frontend/app/profile/profile.component.ts
+++ b/src/frontend/app/profile/profile.component.ts
@@ -184,7 +184,7 @@ export class ProfileComponent implements OnInit {
     submitProfile() {
         this.disableState = true;
         this.msgButton = 'lang.sending';
-        let profileToSend = {
+        const profileToSend = {
             'firstname': this.profileInfo.firstname,
             'lastname': this.profileInfo.lastname,
             'email': this.profileInfo.email,
diff --git a/src/frontend/app/service/auth-interceptor.service.ts b/src/frontend/app/service/auth-interceptor.service.ts
index ccf8fe9c52..780ec2c75f 100644
--- a/src/frontend/app/service/auth-interceptor.service.ts
+++ b/src/frontend/app/service/auth-interceptor.service.ts
@@ -4,7 +4,7 @@ import { Observable } from 'rxjs';
 import { Router } from '@angular/router';
 import { catchError, switchMap } from 'rxjs/operators';
 import { NotificationService } from './notification.service';
-import { empty } from 'rxjs';
+import { EMPTY } from 'rxjs';
 import { SignaturesContentService } from './signatures.service';
 import { AuthService } from './auth.service';
 
@@ -67,7 +67,7 @@ export class AuthInterceptor implements HttpInterceptor {
                     // Disconnect user if bad token process
                     if (err.status === 401) {
                       this.logout();
-                      return empty();
+                      return EMPTY;
                     }
                   })
                 );
@@ -79,7 +79,7 @@ export class AuthInterceptor implements HttpInterceptor {
                 if (err.status === 401) {
                   this.logout();
                 }
-                return empty();
+                return EMPTY;
               })
             );
           } else {
@@ -90,12 +90,12 @@ export class AuthInterceptor implements HttpInterceptor {
                       this.signaturesService.mainDocumentId = null;
                     }
                     this.router.navigate(['/documents']);
-                    return empty();
+                    return EMPTY;
                   }
                 });
             }
             this.notificationService.handleErrors(error);
-            return empty();
+            return EMPTY;
           }
         })
       );
diff --git a/src/frontend/app/service/auth.guard.ts b/src/frontend/app/service/auth.guard.ts
index 96a3fe81c8..f778b0480a 100644
--- a/src/frontend/app/service/auth.guard.ts
+++ b/src/frontend/app/service/auth.guard.ts
@@ -19,8 +19,7 @@ export class AuthGuard implements CanActivate {
         const tokenInfo = this.authService.getToken();
         if (tokenInfo !== null) {
             if (this.signaturesService.userLogged.id === undefined) {
-                const userInfo = JSON.parse(atob(tokenInfo.split('.')[1])).user;
-                this.signaturesService.userLogged = userInfo;
+                this.signaturesService.userLogged = JSON.parse(atob(tokenInfo.split('.')[1])).user;
 
                 this.translate.use(this.signaturesService.userLogged.preferences.lang);
                 this.cookieService.set('maarchParapheurLang', this.signaturesService.userLogged.preferences.lang);
diff --git a/src/frontend/core/environments/environment.ts b/src/frontend/core/environments/environment.ts
index d1528275ef..4320ad78dc 100644
--- a/src/frontend/core/environments/environment.ts
+++ b/src/frontend/core/environments/environment.ts
@@ -4,7 +4,7 @@
 
 export const environment = {
   production: false,
-  VERSION: require('../../../../package.json').version+' (development mode)',
+  VERSION: require('../../../../package.json').version + ' (development mode)',
   AUTHOR: require('../../../../package.json').author
 };
 
diff --git a/src/frontend/core/karma.conf.js b/src/frontend/core/karma.conf.js
deleted file mode 100644
index b6e00421c9..0000000000
--- a/src/frontend/core/karma.conf.js
+++ /dev/null
@@ -1,31 +0,0 @@
-// Karma configuration file, see link for more information
-// https://karma-runner.github.io/1.0/config/configuration-file.html
-
-module.exports = function (config) {
-  config.set({
-    basePath: '',
-    frameworks: ['jasmine', '@angular-devkit/build-angular'],
-    plugins: [
-      require('karma-jasmine'),
-      require('karma-chrome-launcher'),
-      require('karma-jasmine-html-reporter'),
-      require('karma-coverage-istanbul-reporter'),
-      require('@angular-devkit/build-angular/plugins/karma')
-    ],
-    client: {
-      clearContext: false // leave Jasmine Spec Runner output visible in browser
-    },
-    coverageIstanbulReporter: {
-      dir: require('path').join(__dirname, '../coverage'),
-      reports: ['html', 'lcovonly'],
-      fixWebpackSourcePaths: true
-    },
-    reporters: ['progress', 'kjhtml'],
-    port: 9876,
-    colors: true,
-    logLevel: config.LOG_INFO,
-    autoWatch: true,
-    browsers: ['Chrome'],
-    singleRun: false
-  });
-};
\ No newline at end of file
diff --git a/src/frontend/core/test.ts b/src/frontend/core/test.ts
deleted file mode 100644
index 16317897b1..0000000000
--- a/src/frontend/core/test.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-// This file is required by karma.conf.js and loads recursively all the .spec and framework files
-
-import 'zone.js/dist/zone-testing';
-import { getTestBed } from '@angular/core/testing';
-import {
-  BrowserDynamicTestingModule,
-  platformBrowserDynamicTesting
-} from '@angular/platform-browser-dynamic/testing';
-
-declare const require: any;
-
-// First, initialize the Angular testing environment.
-getTestBed().initTestEnvironment(
-  BrowserDynamicTestingModule,
-  platformBrowserDynamicTesting()
-);
-// Then we find all the tests.
-const context = require.context('./', true, /\.spec\.ts$/);
-// And load the modules.
-context.keys().map(context);
diff --git a/src/frontend/core/tsconfig.spec.json b/src/frontend/core/tsconfig.spec.json
index 0ef7609d3a..895716a905 100644
--- a/src/frontend/core/tsconfig.spec.json
+++ b/src/frontend/core/tsconfig.spec.json
@@ -3,7 +3,6 @@
   "compilerOptions": {
     "outDir": "../out-tsc/spec",
     "types": [
-      "jasmine",
       "node"
     ]
   },
diff --git a/src/frontend/core/tslint.json b/src/frontend/core/tslint.json
index 52e2c1a5a7..78a62a0db6 100644
--- a/src/frontend/core/tslint.json
+++ b/src/frontend/core/tslint.json
@@ -1,5 +1,5 @@
 {
-    "extends": "../tslint.json",
+    "extends": "../../../tslint.json",
     "rules": {
         "directive-selector": [
             true,
diff --git a/tslint.json b/tslint.json
index 4a4e1b6f12..8a06267f75 100755
--- a/tslint.json
+++ b/tslint.json
@@ -120,7 +120,7 @@
     "use-input-property-decorator": true,
     "use-output-property-decorator": true,
     "use-host-property-decorator": true,
-    "no-input-rename": true,
+    "no-input-rename": false,
     "no-output-rename": true,
     "use-life-cycle-interface": true,
     "use-pipe-transform-interface": true,
-- 
GitLab