diff options
author | 2018-03-01 08:30:15 -0600 | |
---|---|---|
committer | 2018-03-01 08:33:56 -0600 | |
commit | 2c977e2b66ced314a4f51121801f62fe5c3c05e4 (patch) | |
tree | d93b360d7a6502a6aff1f30ba7f96c3e14f8911c /src/app/shared/services | |
parent | 912f105d12fe6f8dc3a2d409938c87016204debe (diff) |
Initial seed code contribution for CDT
Issue-ID: APPC-682
Change-Id: I0331ffce2a430195c29d0d1b2295966f9eb28699
Signed-off-by: Skip Wonnell <skip@att.com>
Diffstat (limited to 'src/app/shared/services')
-rw-r--r-- | src/app/shared/services/emitter.service.spec.ts | 40 | ||||
-rw-r--r-- | src/app/shared/services/emitter.service.ts | 42 | ||||
-rw-r--r-- | src/app/shared/services/httpUtil/http-util.service.spec.ts | 39 | ||||
-rw-r--r-- | src/app/shared/services/httpUtil/http-util.service.ts | 57 | ||||
-rw-r--r-- | src/app/shared/services/mapping-editor.service.ts | 684 | ||||
-rw-r--r-- | src/app/shared/services/notification.service.ts | 58 | ||||
-rw-r--r-- | src/app/shared/services/paramShare.service.ts | 85 | ||||
-rw-r--r-- | src/app/shared/services/utilityService/utility.service.spec.ts | 64 | ||||
-rw-r--r-- | src/app/shared/services/utilityService/utility.service.ts | 62 |
9 files changed, 1131 insertions, 0 deletions
diff --git a/src/app/shared/services/emitter.service.spec.ts b/src/app/shared/services/emitter.service.spec.ts new file mode 100644 index 0000000..f12154f --- /dev/null +++ b/src/app/shared/services/emitter.service.spec.ts @@ -0,0 +1,40 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +*/ + + +/* tslint:disable:no-unused-variable */ + +import {inject, TestBed} from '@angular/core/testing'; +import {EmitterService} from './emitter.service'; + +describe('EmitterService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [EmitterService] + }); + }); + + it('should ...', inject([EmitterService], (service: EmitterService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/shared/services/emitter.service.ts b/src/app/shared/services/emitter.service.ts new file mode 100644 index 0000000..1cedc63 --- /dev/null +++ b/src/app/shared/services/emitter.service.ts @@ -0,0 +1,42 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +*/ + + +import {EventEmitter, Injectable} from '@angular/core'; + +@Injectable() +export class EmitterService { + private static _emitters: { + [ID: string]: EventEmitter<any> + } = {}; + + constructor() { + } + + static get(ID: string): EventEmitter<any> { + if (!this._emitters[ID]) + this._emitters[ID] = new EventEmitter(); + return this._emitters[ID]; + } + +} diff --git a/src/app/shared/services/httpUtil/http-util.service.spec.ts b/src/app/shared/services/httpUtil/http-util.service.spec.ts new file mode 100644 index 0000000..c6923bb --- /dev/null +++ b/src/app/shared/services/httpUtil/http-util.service.spec.ts @@ -0,0 +1,39 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +*/ + +/* tslint:disable:no-unused-variable */ + +import {inject, TestBed} from '@angular/core/testing'; +import {HttpUtilService} from './http-util.service'; + +describe('HttpUtilService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [HttpUtilService] + }); + }); + + it('should ...', inject([HttpUtilService], (service: HttpUtilService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/src/app/shared/services/httpUtil/http-util.service.ts b/src/app/shared/services/httpUtil/http-util.service.ts new file mode 100644 index 0000000..35c5047 --- /dev/null +++ b/src/app/shared/services/httpUtil/http-util.service.ts @@ -0,0 +1,57 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +*/ +import { observable } from 'rxjs/symbol/observable'; +import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/toPromise'; +import { Injectable } from '@angular/core'; +import { Http, Response, Headers, RequestOptions } from '@angular/http'; + +@Injectable() +export class HttpUtilService { + headers: Headers; + options: RequestOptions + constructor (private http: Http) { + this.headers = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON + // this.options = new RequestOptions({headers: this.headers}); // + } + + get(req) { + + return this + .http + .get(req.url, this.options) + .map((res: Response) => res.json()) + } + + post(req) { + + this.headers.append('Authorization', 'Basic ' + btoa('m97292@appc.att.com:enc:Ai8KDxN7EANwATsV')); + this.options = new RequestOptions({ headers: this.headers }); + + return this + .http + .post(req.url, req.data, this.options) + .map((res: Response) => res.json()) + } + +}
\ No newline at end of file diff --git a/src/app/shared/services/mapping-editor.service.ts b/src/app/shared/services/mapping-editor.service.ts new file mode 100644 index 0000000..00ef211 --- /dev/null +++ b/src/app/shared/services/mapping-editor.service.ts @@ -0,0 +1,684 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +*/ + + +import {Injectable} from '@angular/core'; +import {ConfigMapping} from '../models/index'; +import {Observable} from 'rxjs/Observable'; +import {Observer} from 'rxjs/Observer'; +import 'rxjs/add/operator/share'; + + +@Injectable() +export class MappingEditorService { + + editor: any; + session: any; + editorContent: string; + configMappings: Array<ConfigMapping> = []; + paramContent: string = '{}'; + + KEY_EXPRESSION: string = '\\${\\(.+?\\)}';//new RegExp('${.+?}'); // \${.+?} + //SYNC_KEY_EXPRESSION: string = '\\${\\)}'; + KEY_START: string = '${('; + KEY_MID: string = ')=('; + KEY_END: string = ')}'; + KEY_START_LENGTH: number = 3; + KEY_MID_LENGTH: number = 3; + KEY_END_LENGTH: number = 2; + SYNC_T_KEY_EXPRESSION: string = '\\${.+?\\}'; + T_KEY_EXPRESSION: string = '\\${.+?}';//new RegExp('${.+?}'); // \${.+?} + T_KEY_START: string = '${'; + T_KEY_END: string = '}'; + T_KEY_START_LENGTH: number = 2; + T_KEY_END_LENGTH: number = 1; + checkSpecialCharsReg: RegExp = /[^\w\s-_]/gi; + public paramData = []; + public referenceNameObjects: any; + prmName: string = ''; + prmValue: string = ''; + navChange$: Observable<any>; + public fromScreen: any = ''; + public storedTemplateData: any; + public storedTemplateMappingData: any; + public fileType: any; + public hasErrorCode: boolean = false; + public appDataObject: any; + public downloadDataObject: any; + public markedarr: any; + public tempAllData: any; + public latestAction: any; + public selectedWord: any; + identifier: any; + private _navItem = {}; + private _observer: Observer<any>; + private referenceList = []; + + constructor() { + this.navChange$ = new Observable(observer => + this._observer = observer).share(); + } + + setSelectedWord(selectedWord: any) { + this.selectedWord = selectedWord; + } + + getSelectedWord() { + return this.selectedWord; + } + + changeNav(object) { + this._navItem = object; + // this._observer.next(object); + this.referenceNameObjects = object; + } + + changeNavAppData(object) { + this._navItem = object; + // this._observer.next(object); + this.appDataObject = object; + } + + changeNavDownloadData(object) { + this._navItem = object; + // this._observer.next(object); + this.downloadDataObject = object; + } + + saveLatestAction(data) { + this.latestAction = data; + } + + saveLatestIdentifier(identifier) { + this.identifier = identifier; + } + + public getParamContent() { + return this.paramContent; + } + + saveTempAllData(data) { + this.tempAllData = data; + } + + navItem() { + return this._navItem; + } + + public setParamContent(paramContent: string): void { + this.paramContent = paramContent; + // localStorage["paramContent"]=paramContent; + } + + public initialise(editor: any, editorContent: string, modal: any): void { + this.editor = editor; + this.editor.session = editor.session; + this.editor.selection.session.$backMarkers = {}; + this.editorContent = editorContent; + this.editor.$blockScrolling = Infinity; + this.editor.$blockSelectEnabled = false; + this.initialiseCommands(modal); + this.editor.setValue(this.editorContent); + this.refreshEditor(); + } + + + public initialiseCommands(modal): void { + /* this.editor.commands.addCommand({ + name: 'annotateCommand', + bindKey: { win: 'ENTER', mac: 'ENTER' }, + exec: (editor: any) => { + this.handleAnnotation(modal); + } + });*/ + + + this.editor.commands.addCommand({ + name: 'keyCompletionCommand', + bindKey: {win: 'Ctrl-s', mac: 'Command-s'}, + exec: (editor: any) => { + this.handlekeyCompletion(); + } + }); + + this.editor.commands.addCommand({ + name: 'autoAnnotateCommand', + bindKey: {win: 'Ctrl-2', mac: 'Command-2'}, + exec: (editor: any) => { + this.autoAnnotateDataForParams(this.fileType); + } + }); + + this.editor.commands.addCommand({ + name: 'autoAnnotateCommand', + bindKey: {win: 'Ctrl-shift-z', mac: 'Command-shift-z'}, + exec: (editor: any) => { + this.removeTheSelectedMarkers(); + } + }); + } + + public getStartBeforeAfterSelection(selection: any, beforeCount: number, afterCount: number) { + let newSelctionRange: any = JSON.parse(JSON.stringify(selection)); + if (selection) { + let newBeforeColumn: number = selection.start.column - beforeCount; + let newAfterColumn: number = selection.end.column + afterCount; + newSelctionRange.start.column = newBeforeColumn; + newSelctionRange.end.column = newAfterColumn; + } + return newSelctionRange; + } + + public checkToDataAdd(value: string): boolean { + let toAdd = false; + if (value && (value.startsWith('"') || value.startsWith('>')) + && (value.endsWith('"') || value.endsWith('<')) + && !value.startsWith('"${') + ) { + toAdd = true; + } + return toAdd; + } + + public autoAnnotateDataForParams(fileType: any): boolean { + this.paramContent = localStorage['paramsContent']; + //console.log("Param content=="+ this.paramContent) + var mergeStatus: boolean = false; + if (this.paramContent) { + var paramJson: JSON = JSON.parse(this.paramContent); + for (var prop in paramJson) { + let value: string = paramJson[prop]; + if (value) { + var occurances = this.editor.findAll(value, {regExp: false}); + var ranges = this.editor.getSelection().getAllRanges(); + if (ranges) { + + for (var r = 0; r < ranges.length; r++) { + let selectedRange: any = ranges[r]; + let selectedWord: string = this.editor.session.getTextRange(selectedRange); + let prefixSuffixselectedWord: string = this.editor.session.getTextRange(this.getStartBeforeAfterSelection(selectedRange, 1, 1)); + if (selectedWord && this.checkComments(selectedRange) && this.checkDelimiters(selectedRange) && this.checkApplied(selectedRange)) { + let replaceWord: any = this.KEY_START + selectedWord + this.KEY_MID + prop + this.KEY_END; + this.editor.session.replace(selectedRange, replaceWord); + mergeStatus = true; + } + } + } + } + } + } + return mergeStatus; + } + + /* syncTemplateNames() { + if (this.paramContent != '{}') { + var paramJson: JSON = JSON.parse(this.paramContent); + for (var prop in paramJson) { + let value: string = paramJson[prop] + if (value) { + var occurances = this.editor.findAll(value, { regExp: false }); + var ranges = this.editor.getSelection().getAllRanges(); + if (ranges) { + for (var r = 0; r < ranges.length; r++) { + let selectedRange: any = ranges[r]; + let selectedWord: string = this.editor.session.getTextRange(selectedRange); + let prefixSuffixselectedWord: string = this.editor.session.getTextRange(this.getStartBeforeAfterSelection(selectedRange, 1, 1)); + if (selectedWord && this.checkApplied(selectedRange)) { + let replaceWord: any = this.KEY_START + selectedWord + this.KEY_MID + prop + this.KEY_END; + this.editor.session.replace(selectedRange, replaceWord); + } + } + } + } + } + for (var prop in paramJson) { + var occurances = this.editor.findAll(prop, { regExp: false }); + var ranges = this.editor.getSelection().getAllRanges(); + if (ranges) { + for (var r = 0; r < ranges.length; r++) { + let selectedRange: any = ranges[r]; + let selectedWord: string = this.editor.session.getTextRange(selectedRange); + if (selectedWord && this.checkApplied(selectedRange)) { + let replaceWord: any = '(' + paramJson[prop] + this.KEY_MID + selectedWord + ')'; + this.editor.session.replace(selectedRange, replaceWord); + } + } + } + else { + this.replaceNamesWithBlankValues(); + } + } + } + else { + this.replaceNamesWithBlankValues() + } + }*/ + + + checkComments(selectedRange: any) { + var tempStartColumn = selectedRange.start.column; + var result = false; + selectedRange.start.column = 0; + if (this.editor.session.getTextRange(selectedRange).trim().startsWith('//')) { + result = false; + } else { + result = true; + } + selectedRange.start.column = tempStartColumn; + return result; + } + + checkApplied(selectedRange: any) { + var tempStartColumn = selectedRange.start.column; + for (var i = selectedRange.start.column; i >= 0; i--) { + selectedRange.start.column = i; + if (this.editor.session.getTextRange(selectedRange).startsWith(this.KEY_START) + || this.editor.session.getTextRange(selectedRange).startsWith(this.T_KEY_START)) { + selectedRange.start.column = tempStartColumn; + return false; + } else if (this.editor.session.getTextRange(selectedRange).startsWith(this.KEY_END) + || this.editor.session.getTextRange(selectedRange).startsWith(this.T_KEY_END)) { + selectedRange.start.column = tempStartColumn; + return true; + } + + } + selectedRange.start.column = tempStartColumn; + return true; + + } + + checkDelimiters(selectedRange: any) { + let result = false; + let actualText = this.editor.session.getTextRange(selectedRange); + var tempStartColumn = selectedRange.start.column; + var tempEndcolumn = selectedRange.end.column; + + selectedRange.start.column = selectedRange.start.column - 1; + selectedRange.end.column = selectedRange.end.column + 1; + if ((this.editor.session.getTextRange(selectedRange).startsWith(' ') + || this.editor.session.getTextRange(selectedRange).startsWith('"') + || this.editor.session.getTextRange(selectedRange).startsWith('>')) + && (this.editor.session.getTextRange(selectedRange).endsWith(' ') + || this.editor.session.getTextRange(selectedRange).endsWith('"') + || this.editor.session.getTextRange(selectedRange).endsWith(',') + || this.editor.session.getTextRange(selectedRange).endsWith(actualText) + || this.editor.session.getTextRange(selectedRange).endsWith('<'))) { + result = true; + } + + //Ignore the JSON key names(which ends with :) + selectedRange.end.column = selectedRange.end.column + 1; + if (this.editor.session.getTextRange(selectedRange).endsWith('":')) { + result = false; + } else { + selectedRange.end.column = selectedRange.end.column + 1; + if (this.editor.session.getTextRange(selectedRange).endsWith('" :')) { + result = false; + } + } + selectedRange.start.column = tempStartColumn; + selectedRange.end.column = tempEndcolumn; + return result; + } + + checkAppliedForNamesOnly(selectedRange: any) { + var tempStartColumn = selectedRange.start.column; + for (var i = selectedRange.start.column; i >= 0; i--) { + selectedRange.start.column = i; + if (this.editor.session.getTextRange(selectedRange).startsWith(this.KEY_START)) { + selectedRange.start.column = tempStartColumn; + return false; + } else if (this.editor.session.getTextRange(selectedRange).startsWith(this.KEY_END)) { + selectedRange.start.column = tempStartColumn; + return true; + } + + } + selectedRange.start.column = tempStartColumn; + return true; + + } + + checkToDataAddForJson(value: string): boolean { + let toAdd = false; + if (value && !value.startsWith('"${') && !value.startsWith('(')) { + toAdd = true; + } + return toAdd; + } + + public autoAnnotateTemplateForParam(): void { + var occurances = this.editor.findAll(this.T_KEY_EXPRESSION, {regExp: true}); + var ranges = this.editor.getSelection().getAllRanges(); + if (ranges) { + for (var r = 0; r < ranges.length; r++) { + let selectedRange: any = ranges[r]; + let selectedWord: string = this.editor.session.getTextRange(selectedRange); + if (selectedWord) { + let key: string = selectedWord.substring(this.T_KEY_START_LENGTH, selectedWord.lastIndexOf(this.T_KEY_END)); + let value: string = this.getValueForKey(key); + let replaceWord: any = this.KEY_START + value + this.KEY_MID + key + this.KEY_END; + this.editor.session.replace(selectedRange, replaceWord); + } + } + } + + } + + /* + * Once you save command is triggered, We need to re populate all the params, which may be defined new + * and auto populate the key if any of the values maps to the keys + */ + public handlekeyCompletion(): void { + this.refreshEditor(); + } + + /* public handleAnnotation(modal): void { + let selectedWord: string = this.editor.session.getTextRange(this.editor.selectionRange); + this.setSelectedWord(selectedWord); + modal.open(); + + /* let selectedWord: string = this.editor.session.getTextRange(this.editor.selectionRange); + if (selectedWord) { + if (selectedWord.startsWith('${(')) { + var replaceWord = selectedWord.substring(3, selectedWord.indexOf(')=(')); + this.editor.session.replace(this.editor.session.selection.getRange(), replaceWord); + } else { + let mappingKey = this.getKeysForValues(selectedWord); + var replaceWord = '${(' + selectedWord + ')=()}'; + this.editor.session.replace(this.editor.session.selection.getRange(), replaceWord); + } + } + this.refreshEditor(); + }*/ + + public checkMethodCall(modal): void { +//this.handleAnnotation(modal) + } + + public refreshEditor(): void { + if (this.editor) { + + // this.replaceNamesWithBlankValues(); + var occurances = this.editor.findAll(this.KEY_EXPRESSION, {regExp: true}); + //console.log("Occurances from save" + occurances) + var ranges = this.editor.getSelection().getAllRanges(); + if (ranges) { + this.refreshParams(ranges); + } + + occurances = this.editor.findAll(this.KEY_EXPRESSION, {regExp: true}); + ranges = this.editor.getSelection().getAllRanges(); + if (ranges) { + this.populateMissingKeys(ranges); + } + this.refreshMarker(); + } + // console.log("Param data from refresh editor=="+this.paramData) + + } + + replaceNamesWithBlankValues() { + var occurances = this.editor.findAll(this.SYNC_T_KEY_EXPRESSION, {regExp: true}); + var ranges = this.editor.getSelection().getAllRanges(); + if (occurances > 0) { + if (ranges) { + for (var r = 0; r < ranges.length; r++) { + let selectedRange: any = ranges[r]; + // console.log("Selected range == " + selectedRange) + let selectedWord: string = this.editor.session.getTextRange(selectedRange); + let specialKeys = (selectedWord.substring(2, selectedWord.length - 1)).match(this.checkSpecialCharsReg); + // console.log("Selected word == " + selectedWord.length) + //if (!selectedWord.startsWith('<') || !selectedWord.startsWith('{')) { + if (selectedWord && this.checkAppliedForNamesOnly(selectedRange) && !specialKeys) { + let replaceWord: any = this.KEY_START + '' + this.KEY_MID + selectedWord.substring(2, selectedWord.length - 1) + this.KEY_END; + this.editor.session.replace(selectedRange, replaceWord); + } + // } + } + } + } + } + + public refreshParams(ranges: any): void { + // console.log("This param content==="+ this.paramContent); + var paramData = []; + if (this.paramContent === undefined) this.paramContent = '{}'; + if (this.editor && ranges) { + var paramJson: JSON = JSON.parse(this.paramContent); + this.hasErrorCode = false; + for (var r = 0; r < ranges.length; r++) { + let keyValue: string = this.editor.session.getTextRange(ranges[r]); + //console.log("keyValues==="+keyValue) + if (keyValue && keyValue.startsWith(this.KEY_START) && keyValue.endsWith(this.KEY_END) && keyValue.includes(this.KEY_MID)) { + let key: string = keyValue.substring(keyValue.indexOf(this.KEY_MID) + this.KEY_MID_LENGTH, keyValue.indexOf(this.KEY_END)); + let value: string = keyValue.substring(this.KEY_START_LENGTH, keyValue.indexOf(this.KEY_MID)); + let specialKeys = key.match(this.checkSpecialCharsReg); + //console.log("Special keys=="+specialKeys) + //console.log("Keys=="+key+",values=="+value); + if (specialKeys && specialKeys.length) { + // this.paramData = []; + // this.hasErrorCode = true; + // break; + } else { + if (this.fromScreen === 'TemplateScreen') { + if (key) { + paramJson[key] = value; + var obj: any = {'paramName': '', 'paramValue': ''}; + obj.paramName = key; + obj.paramValue = value; + paramData.push(obj); + } + + } + else if (this.fromScreen === 'MappingScreen') { + if (key) { + paramJson[key] = value; + var obj: any = {'paramName': '', 'paramValue': ''}; + obj.paramName = key; + obj.paramValue = value; + + paramData.push(obj); + + } + } + } + } + } + // console.log("Param data=="+ JSON.stringify(paramData)) + this.paramData = paramData; + this.paramContent = JSON.stringify(paramJson); + + } + } + + public populateMissingKeys(ranges: any): void { + if (this.editor && ranges) { + // Populate missing keys + for (var r = 0; r < ranges.length; r++) { + let keyValue: string = this.editor.session.getTextRange(ranges[r]); + if (keyValue && keyValue.startsWith(this.KEY_START) && keyValue.endsWith(this.KEY_END) && keyValue.includes(this.KEY_MID)) { + let key: string = keyValue.substring(keyValue.indexOf(this.KEY_MID) + this.KEY_MID_LENGTH, keyValue.indexOf(this.KEY_END)); + let value: string = keyValue.substring(this.KEY_START_LENGTH, keyValue.indexOf(this.KEY_MID)); + if (!key && value) { + let keyFromStore = ''; + if (keyFromStore) { + let replaceWord: string = '${(' + value + ')=(' + keyFromStore + ')}'; + this.editor.session.replace(ranges[r], replaceWord); + } + } + } + } + + } + } + + public refreshMarker(): void { + if (this.editor) { + this.hasErrorCode = false; + var occurances = this.editor.findAll(this.KEY_EXPRESSION, {regExp: true}); + var ranges = this.editor.getSelection().getAllRanges(); + var keysList = []; + // Populate missing keys + for (var r = 0; r < ranges.length; r++) { + let keyValue: string = this.editor.session.getTextRange(ranges[r]); + if (keyValue && keyValue.startsWith(this.KEY_START) && keyValue.endsWith(this.KEY_END) && keyValue.includes(this.KEY_MID)) { + let key: string = keyValue.substring(keyValue.indexOf(this.KEY_MID) + this.KEY_MID_LENGTH, keyValue.indexOf(this.KEY_END)); + let value: string = keyValue.substring(this.KEY_START_LENGTH, keyValue.indexOf(this.KEY_MID)); + let specialKeys = key.match(this.checkSpecialCharsReg); + if (specialKeys && specialKeys.length) { + this.hasErrorCode = true; + break; + } + if (!key && value) { + this.editor.session.addMarker(ranges[r], 'warningMarker', 'text'); + } else { + if (keysList.indexOf(key) > -1) { + this.editor.session.addMarker(ranges[r], 'warningMarker', 'text'); + } else { + this.editor.session.addMarker(ranges[r], 'keyedMarker', 'text'); + } + keysList.push(key); + } + // Refresh Markers + } + } + this.editor.clearSelection(); + this.editor.exitMultiSelectMode(); + } + } + + public getKeysForValues(value: string): string { + var key: string = undefined; + if (this.paramContent && value) { + var paramJson: JSON = JSON.parse(this.paramContent); + for (var prop in paramJson) { + if (value === paramJson[prop]) { + key = prop; + } + } + } + return key; + } + + public getValueForKey(key: string): string { + var value: string = undefined; + if (key) { + var paramJson: JSON = JSON.parse(this.paramContent); + if (paramJson) { + value = paramJson[key]; + } + } + return value; + } + + public generateTemplate(templateEditor: any): void { + if (templateEditor) { + templateEditor.setValue(this.editor.getValue()); + var occurances = templateEditor.findAll(this.KEY_EXPRESSION, {regExp: true}); + var ranges = templateEditor.getSelection().getAllRanges(); + if (ranges) { + for (var r = 0; r < ranges.length; r++) { + let keyValue: string = templateEditor.session.getTextRange(ranges[r]); + if (keyValue && keyValue.startsWith(this.KEY_START) && keyValue.endsWith(this.KEY_END) && keyValue.includes(this.KEY_MID)) { + let key: string = keyValue.substring(keyValue.indexOf(this.KEY_MID) + this.KEY_MID_LENGTH, keyValue.indexOf(this.KEY_END)); + let value: string = keyValue.substring(this.KEY_START_LENGTH, keyValue.indexOf(this.KEY_MID)); + if (key && value) { + let replaceWord: string = '${' + key + '}'; + templateEditor.session.replace(ranges[r], replaceWord); + } + } + } + templateEditor.clearSelection(); + templateEditor.exitMultiSelectMode(); + templateEditor.session.$backMarkers = {}; + + } + } + } + + public generateParams(paramsEditor: any, paramsKeyValueEditor: any): JSON { + if (paramsEditor && paramsKeyValueEditor) { + var occurances = this.editor.findAll(this.KEY_EXPRESSION, {regExp: true}); + var ranges = this.editor.getSelection().getAllRanges(); + if (ranges) { + let paramsJSON: JSON = JSON.parse('{}'); + for (var r = 0; r < ranges.length; r++) { + let keyValue: string = this.editor.session.getTextRange(ranges[r]); + if (keyValue && keyValue.startsWith(this.KEY_START) && keyValue.endsWith(this.KEY_END) && keyValue.includes(this.KEY_MID)) { + let key: string = keyValue.substring(keyValue.indexOf(this.KEY_MID) + this.KEY_MID_LENGTH, keyValue.indexOf(this.KEY_END)); + let value: string = keyValue.substring(this.KEY_START_LENGTH, keyValue.indexOf(this.KEY_MID)); + if (key) { + paramsJSON[key] = value; + } + } + } + + var propertyContent = []; + for (var prop in paramsJSON) { + propertyContent.push(prop + '=' + paramsJSON[prop]); + } + this.editor.clearSelection(); + this.editor.exitMultiSelectMode(); + return paramsJSON; + } + } + } + + setTemplateDataForStore(templateData: any) { + this.storedTemplateData = templateData; + } + + getTemplateDataFromStore() { + return this.storedTemplateData; + } + + removeTheSelectedMarkers() { + var arr: any = []; + arr = this.markedarr; + this.editor.selection.session.$backMarkers = {}; + } + + getsaveMarkers() { + this.markedarr = [...this.editor.selection.session.$selectionMarkers]; + } + + getTemplateMappingDataFromStore() { + return this.storedTemplateMappingData; + } + + setTemplateMappingDataFromStore(templateMappingData: any) { + this.storedTemplateMappingData = templateMappingData; + } + + public setReferenceList(references) { + this.referenceList = references; + } + + public getReferenceList() { + return this.referenceList; + } + + +}
\ No newline at end of file diff --git a/src/app/shared/services/notification.service.ts b/src/app/shared/services/notification.service.ts new file mode 100644 index 0000000..428f9a2 --- /dev/null +++ b/src/app/shared/services/notification.service.ts @@ -0,0 +1,58 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +*/ + + +import {EventEmitter, Injectable} from '@angular/core'; +import {Notification} from '../models/Notification'; + +@Injectable() +export class NotificationService { + + public notificationsEvent: EventEmitter<Notification>; + + constructor() { + this.notificationsEvent = new EventEmitter<Notification>(); + } + + public add(_notification: Notification) { + this.notificationsEvent.emit(_notification); + } + + public notifySuccessMessage(_message: string) { + this.add(new Notification('success', _message)); + } + + public notifyErrorMessage(_message: string) { + console.error(_message); + this.add(new Notification('error', _message)); + } + + public notifyInfoMessage(_message: string) { + this.add(new Notification('info', _message)); + } + + public notifyAlertMessage(_message: string) { + this.add(new Notification('alert', _message)); + } + +} diff --git a/src/app/shared/services/paramShare.service.ts b/src/app/shared/services/paramShare.service.ts new file mode 100644 index 0000000..559b448 --- /dev/null +++ b/src/app/shared/services/paramShare.service.ts @@ -0,0 +1,85 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +*/ + + +import {Injectable} from '@angular/core'; + +@Injectable() +export class ParamShareService { + + public sharedData: { [index: string]: string; } = {}; + + //Stubbing Name-Value pairs for templateData->will come from Template Generation Component/Editor + public templateData: {}; + public displayData: {}; + public paramData = []; + + + setData(data) { + this.sharedData = data; + } + + getData() { + return this.sharedData; + } + + setTemplateData1() { + /* Stubbing **/ + var paramData = [ + {paramName: 'A-IP', paramValue: '234'}, + {paramName: 'B-IP', paramValue: '10.168.15.15'}, + {paramName: 'C-IP', paramValue: '100.168.150.15'}, + {paramName: 'D-IP', paramValue: '900.168.150.15'}, + {paramName: 'hostIP', paramValue: '200.168.150.15'}, + {paramName: 'hostnameIP', paramValue: '300.168.150.15'}, + {paramName: 'R-IP', paramValue: '400.168.150.15'}, + {paramName: 'someIP', paramValue: '500.168.150.15'} + + ]; + this.templateData = paramData; + } + + setTemplateData(data) { + this.templateData = data; + } + + getTemplateData() { + return (this.templateData); + } + + setDisplayData(data: any[]) { + this.displayData = data.slice(0); + } + + getDisplayData() { + return this.displayData; + } + + setSessionParamData(data) { + this.paramData = data; + } + + getSessionParamData() { + return this.paramData; + } +} diff --git a/src/app/shared/services/utilityService/utility.service.spec.ts b/src/app/shared/services/utilityService/utility.service.spec.ts new file mode 100644 index 0000000..c11927a --- /dev/null +++ b/src/app/shared/services/utilityService/utility.service.spec.ts @@ -0,0 +1,64 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +*/ + + +/* tslint:disable:no-unused-variable */ + +import {inject, TestBed} from '@angular/core/testing'; +import {UtilityService} from './utility.service'; +import {NotificationsService} from 'angular2-notifications'; + +describe('UtilityService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [UtilityService, NotificationsService] + }); + }); + + it('should create a service...', inject([UtilityService], (service: UtilityService) => { + expect(service).toBeTruthy(); + })); + + + it('should apply slashes for a string...', inject([UtilityService], (service: UtilityService) => { + let text = {'vnf-host-ip-address': '135.21.166.36'}; + + expect(service.appendSlashes(JSON.stringify(text))).toEqual('{\\"vnf-host-ip-address\\":\\"135.21.166.36\\"}'); + })); + + + it('should check for status 401', inject([UtilityService], (service: UtilityService) => { + let data = {output: {status: {code: 401}}}; + + expect(service.checkResult(data)).toBeFalsy(); + })); + + + it('should check for status 400', inject([UtilityService], (service: UtilityService) => { + let data = {output: {status: {code: 400}}}; + + expect(service.checkResult(data)).toBeTruthy(); + })); + + +}); diff --git a/src/app/shared/services/utilityService/utility.service.ts b/src/app/shared/services/utilityService/utility.service.ts new file mode 100644 index 0000000..11fa888 --- /dev/null +++ b/src/app/shared/services/utilityService/utility.service.ts @@ -0,0 +1,62 @@ +/* +============LICENSE_START========================================== +=================================================================== +Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. +=================================================================== + +Unless otherwise specified, all software contained herein is licensed +under the Apache License, Version 2.0 (the License); +you may not use this software except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +ECOMP is a trademark and service mark of AT&T Intellectual Property. +============LICENSE_END============================================ +*/ + + +import {Injectable} from '@angular/core'; +import {NotificationsService} from 'angular2-notifications'; + +@Injectable() +export class UtilityService { + + private successMessage = 'Retrieved artifact successfully'; + private failureMessage = 'There is no artifact saved in APPC for the selected action!'; + + constructor(private notificationService: NotificationsService) { + } + + randomId() { + let x = (new Date().getUTCMilliseconds()) * Math.random(); + return (x + '').substr(4, 12); + + + } + + appendSlashes(artifactData) { + return artifactData.replace(/"/g, '\\"'); + } + + checkResult(result: any) { + + if (result.output.status.code == '401') { + this.notificationService.info('Information', this.failureMessage); + return false; + } + else if (result.output.status.code == '400') { + this.notificationService.success('Success', this.successMessage); + return true; + } + + } + + +} |