X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Fservices%2FSharedService.ts;h=48fbb17e780a6a4bde505c5826479e08e416dbe5;hb=8d538a5aac7b6a7af26d37764dc3291fdb77a2a5;hp=8aee5138217fd364e33b055954ec4d09c985022d;hpb=d477b85279831f43f77d10acfc1912da1fbe6007;p=osm%2FNG-UI.git diff --git a/src/services/SharedService.ts b/src/services/SharedService.ts index 8aee513..48fbb17 100644 --- a/src/services/SharedService.ts +++ b/src/services/SharedService.ts @@ -22,7 +22,8 @@ import { HttpErrorResponse, HttpHeaders } from '@angular/common/http'; import { EventEmitter, Injectable, Output } from '@angular/core'; import { FormArray, FormGroup } from '@angular/forms'; import { Router } from '@angular/router'; -import { CONSTANTNUMBER, ERRORDATA, GETAPIURLHEADER, PACKAGEINFO, PAGERSMARTTABLE, SMARTTABLECLASS, TARSETTINGS } from 'CommonModel'; +import { TranslateService } from '@ngx-translate/core'; +import { CONSTANTNUMBER, ERRORDATA, FILESETTINGS, GETAPIURLHEADER, PACKAGEINFO, PAGERSMARTTABLE, SMARTTABLECLASS, TARSETTINGS } from 'CommonModel'; import { environment } from 'environment'; import * as HttpStatus from 'http-status-codes'; import * as untar from 'js-untar'; @@ -64,6 +65,12 @@ export class SharedService { // tslint:disable-next-line: max-line-length public REGX_PASSWORD_PATTERN: RegExp = new RegExp(/^.*(?=.{8,})((?=.*[!@#$%^&*()\-_=+{};:,<.>]){1})(?=.*\d)((?=.*[a-z]){1})((?=.*[A-Z]){1}).*$/); + /** Variables to hold maxlength for the description @public */ + public MAX_LENGTH_DESCRIPTION: number = 500; + + /** Variables to hold maxlength for the name @public */ + public MAX_LENGTH_NAME: number = 50; + /** FormGroup instance added to the form @ html @public */ public formGroup: FormGroup; @@ -94,24 +101,31 @@ export class SharedService { /** Check for the root directory @private */ private directoryCount: number = 2; - constructor(restService: RestService, router: Router) { + /** Contains tranlsate instance @private */ + private translateService: TranslateService; + + constructor(restService: RestService, router: Router, translateService: TranslateService) { this.restService = restService; this.router = router; + this.translateService = translateService; } /** convert epoch time function @public */ public convertEpochTime(unixtimestamp: number): string { - const monthsArr: string[] = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', - 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; - const date: Date = new Date(unixtimestamp * this.epochTime1000); - const year: number = date.getFullYear(); - const month: string = monthsArr[date.getMonth()]; - const day: number = date.getDate(); - const hours: number = date.getHours(); - const minutes: string = '0' + date.getMinutes(); - const seconds: string = '0' + date.getSeconds(); - return month + '-' + day + '-' + year + ' ' + hours + ':' + minutes.substr(this.epochTimeMinus2) + ':' - + seconds.substr(this.epochTimeMinus2); + if (!isNullOrUndefined(unixtimestamp)) { + const monthsArr: string[] = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', + 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; + const date: Date = new Date(unixtimestamp * this.epochTime1000); + const year: number = date.getFullYear(); + const month: string = monthsArr[date.getMonth()]; + const day: number = date.getDate(); + const hours: number = date.getHours(); + const minutes: string = '0' + date.getMinutes(); + const seconds: string = '0' + date.getSeconds(); + return month + '-' + day + '-' + year + ' ' + hours + ':' + minutes.substr(this.epochTimeMinus2) + ':' + + seconds.substr(this.epochTimeMinus2); + } + return this.translateService.instant('NODATE'); } /** Download Files function @public */ @@ -180,14 +194,15 @@ export class SharedService { const getFoldersFiles: {}[] = extractedFiles; const folderNameStr: string = extractedFiles[0].name; getFoldersFiles.forEach((value: TARSETTINGS) => { + const fileValueObj: FILESETTINGS = this.createFileValueObject(value); const getRootFolder: string[] = value.name.split('/'); if (value.name.startsWith(folderNameStr) && (value.name.endsWith('.yaml') || value.name.endsWith('.yml')) && getRootFolder.length === this.directoryCount) { - tar.append(value.name, packageInfo.descriptor, { type: value.type }); + tar.append(value.name, packageInfo.descriptor, fileValueObj); } else { if (value.type !== 'L') { - tar.append(value.name, new Uint8Array(value.buffer), { type: value.type }); + tar.append(value.name, new Uint8Array(value.buffer), fileValueObj); } } }); @@ -210,6 +225,15 @@ export class SharedService { }); }); } + /** Method to return the file information @public */ + public createFileValueObject(value: TARSETTINGS): FILESETTINGS { + return { + type: value.type, + linkname: value.linkname, + owner: value.uname, + group: value.gname + }; + } /** Method to check given string is JSON or not @public */ public checkJson(jsonString: string): boolean { jsonString = jsonString.replace(/'/g, '"'); @@ -290,6 +314,11 @@ export class SharedService { return tag; } + /** Fetch file extension @public */ + public fetchFileExtension(fileInfo: FileList): string { + return fileInfo[0].name.substring(fileInfo[0].name.lastIndexOf('.') + 1); + } + /** 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);