Angular upgrade
[osm/NG-UI.git] / src / services / SharedService.ts
index ba805e6..00f0a63 100644 (file)
@@ -18,7 +18,6 @@
 /**
  * @file Provider for Shared Service
  */
-import { isNullOrUndefined } from 'util';
 import { HttpErrorResponse, HttpHeaders } from '@angular/common/http';
 import { EventEmitter, Injectable, Output } from '@angular/core';
 import { FormArray, FormGroup } from '@angular/forms';
@@ -128,9 +127,13 @@ export class SharedService {
     // eslint-disable-next-line @typescript-eslint/no-magic-numbers
     private randomStringLength: number = 4;
 
-    /** Max length of Uint8Array */
+    /** express number for rgb manipulation */
     // eslint-disable-next-line @typescript-eslint/no-magic-numbers
-    private unit8Array: number = 255;
+    private colourHour: number = 10;
+
+    /** express number for rgb manipulation*/
+    // eslint-disable-next-line @typescript-eslint/no-magic-numbers
+    private colourMin: number = 5;
 
     /** Instance of the rest service @private */
     private restService: RestService;
@@ -138,10 +141,6 @@ export class SharedService {
     /** Service holds the router information @private */
     private router: Router;
 
-    /** Random color string generator length @private */
-    // eslint-disable-next-line @typescript-eslint/no-magic-numbers
-    private colorStringLength: number = 256;
-
     /** Check for the root directory @private */
     // eslint-disable-next-line @typescript-eslint/no-magic-numbers
     private directoryCount: number = 2;
@@ -260,10 +259,9 @@ export class SharedService {
 
     /** Generate random string @public */
     public randomString(): string {
-        const chars: string = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         let result: string = '';
         for (let randomStringRef: number = this.randomStringLength; randomStringRef > 0; --randomStringRef) {
-            result += chars[Math.floor(Math.random() * chars.length)];
+            result += new Date().getSeconds();
         }
         return result;
     }
@@ -414,6 +412,7 @@ export class SharedService {
             const version: string[] = res.version.split('+');
             if (!isNullOrUndefined(version[0])) {
                 this.osmVersion = version[0];
+                sessionStorage.setItem('version', version[0]);
             } else {
                 this.osmVersion = null;
             }
@@ -425,9 +424,9 @@ export class SharedService {
 
     /** Random RGB color code generator @public */
     public generateColor(): string {
-        const x: number = Math.floor(Math.random() * this.colorStringLength);
-        const y: number = Math.floor(Math.random() * this.colorStringLength);
-        const z: number = Math.floor(Math.random() * this.colorStringLength);
+        const x: number = Math.floor((new Date().getHours()) * this.colourHour);
+        const y: number = Math.floor((new Date().getMinutes()) * this.colourMin);
+        const z: number = Math.floor((new Date().getSeconds()) * this.colourMin);
         return 'rgb(' + x + ',' + y + ',' + z + ')';
     }
 
@@ -468,6 +467,19 @@ export class SharedService {
         }));
     }
 
+    /** Sorting the list based on date @public */
+    public compareFunction = (dir: number, a: string, b: string): number => {
+        const first: number = new Date(a).getTime();
+        const second: number = new Date(b).getTime();
+        if (first < second) {
+            return -1 * dir;
+        }
+        if (first > second) {
+            return dir;
+        }
+        return 0;
+    };
+
     /** Method to validate file extension and size @private */
     private vaildataFileInfo(fileInfo: File, fileType: string): boolean {
         const extension: string = fileInfo.name.substring(fileInfo.name.lastIndexOf('.') + 1);
@@ -501,3 +513,8 @@ export class SharedService {
         };
     }
 }
+
+/** Method to handle null or undefined @public */
+// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
+export const isNullOrUndefined = (data: any): boolean => data === null || data === undefined;
+