@bnsights/bbsf-utilities 1.0.34 → 1.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/README.md +8 -0
  2. package/karma.conf.js +44 -0
  3. package/ng-package.json +10 -0
  4. package/package.json +20 -28
  5. package/src/lib/bbsf-utilities.module.ts +52 -0
  6. package/src/lib/shared/authentication/auth.service.ts +242 -0
  7. package/src/lib/shared/config/environment.ts +16 -0
  8. package/src/lib/shared/config/word/constants.js +133 -0
  9. package/src/lib/shared/config/word/docx-document.js +482 -0
  10. package/src/lib/shared/config/word/helpers/index.js +3 -0
  11. package/src/lib/shared/config/word/helpers/render-document-file.js +334 -0
  12. package/src/lib/shared/config/word/helpers/xml-builder.js +2165 -0
  13. package/src/lib/shared/config/word/html-to-docx.js +259 -0
  14. package/src/lib/shared/config/word/index.js +63 -0
  15. package/src/lib/shared/config/word/namespaces.js +40 -0
  16. package/src/lib/shared/config/word/schemas/content-types.js +26 -0
  17. package/src/lib/shared/config/word/schemas/core.js +44 -0
  18. package/src/lib/shared/config/word/schemas/document-rels.js +17 -0
  19. package/src/lib/shared/config/word/schemas/document.template.js +119 -0
  20. package/src/lib/shared/config/word/schemas/font-table.js +41 -0
  21. package/src/lib/shared/config/word/schemas/generic-rels.js +11 -0
  22. package/src/lib/shared/config/word/schemas/index.js +12 -0
  23. package/src/lib/shared/config/word/schemas/numbering.js +18 -0
  24. package/src/lib/shared/config/word/schemas/rels.js +12 -0
  25. package/src/lib/shared/config/word/schemas/settings.js +14 -0
  26. package/src/lib/shared/config/word/schemas/styles.js +152 -0
  27. package/src/lib/shared/config/word/schemas/theme.js +199 -0
  28. package/src/lib/shared/config/word/schemas/web-settings.js +10 -0
  29. package/src/lib/shared/config/word/utils/color-conversion.js +60 -0
  30. package/src/lib/shared/config/word/utils/list.js +55 -0
  31. package/src/lib/shared/config/word/utils/unit-conversion.js +53 -0
  32. package/src/lib/shared/config/word/utils/url.js +8 -0
  33. package/src/lib/shared/config/word/utils/vnode.js +3 -0
  34. package/src/lib/shared/config/word/word-work/assets/contentTypesXml.ts +1 -0
  35. package/src/lib/shared/config/word/word-work/assets/documentXmlRels.ts +1 -0
  36. package/src/lib/shared/config/word/word-work/assets/index.ts +3 -0
  37. package/src/lib/shared/config/word/word-work/assets/relsXml.ts +1 -0
  38. package/src/lib/shared/config/word/word-work/index.ts +8 -0
  39. package/src/lib/shared/config/word/word-work/internal.ts +69 -0
  40. package/src/lib/shared/config/word/word-work/templates/documentTemplate.ts +58 -0
  41. package/src/lib/shared/config/word/word-work/templates/index.ts +3 -0
  42. package/src/lib/shared/config/word/word-work/templates/mhtDocumentTemplate.ts +21 -0
  43. package/src/lib/shared/config/word/word-work/templates/mhtPartTemplate.ts +14 -0
  44. package/src/lib/shared/config/word/word-work/utils.ts +27 -0
  45. package/src/lib/shared/models/AreaModel.ts +5 -0
  46. package/{lib/shared/models/ErrorModel.d.ts → src/lib/shared/models/ErrorModel.ts} +5 -2
  47. package/src/lib/shared/models/RequestOptionsModel.ts +13 -0
  48. package/src/lib/shared/models/WordDocumentModel.ts +19 -0
  49. package/src/lib/shared/services/AppearanceConfiguration.service.ts +30 -0
  50. package/src/lib/shared/services/configuration.service.ts +18 -0
  51. package/src/lib/shared/services/controlvalidation.service.ts +194 -0
  52. package/src/lib/shared/services/environment.service.ts +56 -0
  53. package/src/lib/shared/services/masterlayout.service.ts +89 -0
  54. package/src/lib/shared/services/requesthandler.service.ts +241 -0
  55. package/src/lib/shared/services/stylesbundle.service.ts +52 -0
  56. package/src/lib/shared/services/translate.service.ts +8 -0
  57. package/src/lib/shared/services/translationresolver.service.ts +16 -0
  58. package/src/lib/shared/services/utility.service.ts +94 -0
  59. package/src/lib/shared/services/word-document.service.ts +36 -0
  60. package/src/public-api.ts +27 -0
  61. package/src/test.ts +26 -0
  62. package/tsconfig.lib.json +39 -0
  63. package/tsconfig.lib.prod.json +11 -0
  64. package/tsconfig.spec.json +17 -0
  65. package/tslint.json +17 -0
  66. package/bnsights-bbsf-utilities-1.0.34.tgz +0 -0
  67. package/bnsights-bbsf-utilities.d.ts +0 -4
  68. package/bnsights-bbsf-utilities.metadata.json +0 -1
  69. package/bundles/bnsights-bbsf-utilities.umd.js +0 -4865
  70. package/bundles/bnsights-bbsf-utilities.umd.js.map +0 -1
  71. package/esm2015/bnsights-bbsf-utilities.js +0 -5
  72. package/esm2015/lib/bbsf-utilities.module.js +0 -52
  73. package/esm2015/lib/shared/authentication/auth.service.js +0 -236
  74. package/esm2015/lib/shared/config/environment.js +0 -12
  75. package/esm2015/lib/shared/config/word/constants.js +0 -105
  76. package/esm2015/lib/shared/config/word/docx-document.js +0 -351
  77. package/esm2015/lib/shared/config/word/helpers/index.js +0 -4
  78. package/esm2015/lib/shared/config/word/helpers/render-document-file.js +0 -278
  79. package/esm2015/lib/shared/config/word/helpers/xml-builder.js +0 -1765
  80. package/esm2015/lib/shared/config/word/html-to-docx.js +0 -195
  81. package/esm2015/lib/shared/config/word/index.js +0 -55
  82. package/esm2015/lib/shared/config/word/namespaces.js +0 -37
  83. package/esm2015/lib/shared/config/word/schemas/content-types.js +0 -26
  84. package/esm2015/lib/shared/config/word/schemas/core.js +0 -29
  85. package/esm2015/lib/shared/config/word/schemas/document-rels.js +0 -16
  86. package/esm2015/lib/shared/config/word/schemas/document.template.js +0 -109
  87. package/esm2015/lib/shared/config/word/schemas/font-table.js +0 -40
  88. package/esm2015/lib/shared/config/word/schemas/generic-rels.js +0 -11
  89. package/esm2015/lib/shared/config/word/schemas/index.js +0 -13
  90. package/esm2015/lib/shared/config/word/schemas/numbering.js +0 -19
  91. package/esm2015/lib/shared/config/word/schemas/rels.js +0 -11
  92. package/esm2015/lib/shared/config/word/schemas/settings.js +0 -13
  93. package/esm2015/lib/shared/config/word/schemas/styles.js +0 -149
  94. package/esm2015/lib/shared/config/word/schemas/theme.js +0 -200
  95. package/esm2015/lib/shared/config/word/schemas/web-settings.js +0 -9
  96. package/esm2015/lib/shared/config/word/utils/color-conversion.js +0 -60
  97. package/esm2015/lib/shared/config/word/utils/list.js +0 -51
  98. package/esm2015/lib/shared/config/word/utils/unit-conversion.js +0 -30
  99. package/esm2015/lib/shared/config/word/utils/url.js +0 -9
  100. package/esm2015/lib/shared/config/word/utils/vnode.js +0 -3
  101. package/esm2015/lib/shared/config/word/word-work/templates/documentTemplate.js +0 -54
  102. package/esm2015/lib/shared/config/word/word-work/templates/index.js +0 -4
  103. package/esm2015/lib/shared/config/word/word-work/templates/mhtDocumentTemplate.js +0 -22
  104. package/esm2015/lib/shared/config/word/word-work/templates/mhtPartTemplate.js +0 -10
  105. package/esm2015/lib/shared/config/word/word-work/utils.js +0 -26
  106. package/esm2015/lib/shared/models/AreaModel.js +0 -3
  107. package/esm2015/lib/shared/models/ErrorModel.js +0 -3
  108. package/esm2015/lib/shared/models/RequestOptionsModel.js +0 -11
  109. package/esm2015/lib/shared/models/WordDocumentModel.js +0 -8
  110. package/esm2015/lib/shared/services/AppearanceConfiguration.service.js +0 -37
  111. package/esm2015/lib/shared/services/configuration.service.js +0 -26
  112. package/esm2015/lib/shared/services/controlvalidation.service.js +0 -168
  113. package/esm2015/lib/shared/services/environment.service.js +0 -48
  114. package/esm2015/lib/shared/services/masterlayout.service.js +0 -96
  115. package/esm2015/lib/shared/services/requesthandler.service.js +0 -206
  116. package/esm2015/lib/shared/services/stylesbundle.service.js +0 -56
  117. package/esm2015/lib/shared/services/translate.service.js +0 -13
  118. package/esm2015/lib/shared/services/translationresolver.service.js +0 -20
  119. package/esm2015/lib/shared/services/utility.service.js +0 -96
  120. package/esm2015/lib/shared/services/word-document.service.js +0 -39
  121. package/esm2015/public-api.js +0 -20
  122. package/fesm2015/bnsights-bbsf-utilities.js +0 -4634
  123. package/fesm2015/bnsights-bbsf-utilities.js.map +0 -1
  124. package/lib/bbsf-utilities.module.d.ts +0 -6
  125. package/lib/shared/authentication/auth.service.d.ts +0 -41
  126. package/lib/shared/config/environment.d.ts +0 -1
  127. package/lib/shared/config/word/constants.d.ts +0 -124
  128. package/lib/shared/config/word/docx-document.d.ts +0 -73
  129. package/lib/shared/config/word/helpers/index.d.ts +0 -1
  130. package/lib/shared/config/word/helpers/render-document-file.d.ts +0 -4
  131. package/lib/shared/config/word/helpers/xml-builder.d.ts +0 -14
  132. package/lib/shared/config/word/html-to-docx.d.ts +0 -1
  133. package/lib/shared/config/word/index.d.ts +0 -1
  134. package/lib/shared/config/word/namespaces.d.ts +0 -36
  135. package/lib/shared/config/word/schemas/content-types.d.ts +0 -1
  136. package/lib/shared/config/word/schemas/core.d.ts +0 -1
  137. package/lib/shared/config/word/schemas/document-rels.d.ts +0 -1
  138. package/lib/shared/config/word/schemas/document.template.d.ts +0 -4
  139. package/lib/shared/config/word/schemas/font-table.d.ts +0 -1
  140. package/lib/shared/config/word/schemas/generic-rels.d.ts +0 -1
  141. package/lib/shared/config/word/schemas/index.d.ts +0 -12
  142. package/lib/shared/config/word/schemas/numbering.d.ts +0 -1
  143. package/lib/shared/config/word/schemas/rels.d.ts +0 -1
  144. package/lib/shared/config/word/schemas/settings.d.ts +0 -1
  145. package/lib/shared/config/word/schemas/styles.d.ts +0 -1
  146. package/lib/shared/config/word/schemas/theme.d.ts +0 -1
  147. package/lib/shared/config/word/schemas/web-settings.d.ts +0 -1
  148. package/lib/shared/config/word/utils/color-conversion.d.ts +0 -7
  149. package/lib/shared/config/word/utils/list.d.ts +0 -6
  150. package/lib/shared/config/word/utils/unit-conversion.d.ts +0 -29
  151. package/lib/shared/config/word/utils/url.d.ts +0 -1
  152. package/lib/shared/config/word/utils/vnode.d.ts +0 -1
  153. package/lib/shared/config/word/word-work/templates/documentTemplate.d.ts +0 -12
  154. package/lib/shared/config/word/word-work/templates/index.d.ts +0 -3
  155. package/lib/shared/config/word/word-work/templates/mhtDocumentTemplate.d.ts +0 -1
  156. package/lib/shared/config/word/word-work/templates/mhtPartTemplate.d.ts +0 -1
  157. package/lib/shared/config/word/word-work/utils.d.ts +0 -1
  158. package/lib/shared/models/AreaModel.d.ts +0 -4
  159. package/lib/shared/models/RequestOptionsModel.d.ts +0 -11
  160. package/lib/shared/models/WordDocumentModel.d.ts +0 -16
  161. package/lib/shared/services/AppearanceConfiguration.service.d.ts +0 -11
  162. package/lib/shared/services/configuration.service.d.ts +0 -7
  163. package/lib/shared/services/controlvalidation.service.d.ts +0 -19
  164. package/lib/shared/services/environment.service.d.ts +0 -13
  165. package/lib/shared/services/masterlayout.service.d.ts +0 -24
  166. package/lib/shared/services/requesthandler.service.d.ts +0 -32
  167. package/lib/shared/services/stylesbundle.service.d.ts +0 -9
  168. package/lib/shared/services/translate.service.d.ts +0 -3
  169. package/lib/shared/services/translationresolver.service.d.ts +0 -8
  170. package/lib/shared/services/utility.service.d.ts +0 -21
  171. package/lib/shared/services/word-document.service.d.ts +0 -5
  172. package/public-api.d.ts +0 -16
@@ -0,0 +1,58 @@
1
+ export const defaultMargins = {
2
+ top: 1440,
3
+ right: 1440,
4
+ bottom: 1440,
5
+ left: 1440,
6
+ header: 720,
7
+ footer: 720,
8
+ gutter: 0,
9
+ }
10
+
11
+ export type Margins = typeof defaultMargins
12
+
13
+ export type Orient = 'landscape' | 'portrait'
14
+
15
+ export const documentTemplate = (width: number, height: number, orient: string, margins: Margins) => {
16
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
17
+ <w:document
18
+ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
19
+ xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
20
+ xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
21
+ xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
22
+ xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
23
+ xmlns:ns6="http://schemas.openxmlformats.org/schemaLibrary/2006/main"
24
+ xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"
25
+ xmlns:ns8="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing"
26
+ xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram"
27
+ xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
28
+ xmlns:ns11="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"
29
+ xmlns:dsp="http://schemas.microsoft.com/office/drawing/2008/diagram"
30
+ xmlns:ns13="urn:schemas-microsoft-com:office:excel"
31
+ xmlns:o="urn:schemas-microsoft-com:office:office"
32
+ xmlns:v="urn:schemas-microsoft-com:vml"
33
+ xmlns:w10="urn:schemas-microsoft-com:office:word"
34
+ xmlns:ns17="urn:schemas-microsoft-com:office:powerpoint"
35
+ xmlns:odx="http://opendope.org/xpaths"
36
+ xmlns:odc="http://opendope.org/conditions"
37
+ xmlns:odq="http://opendope.org/questions"
38
+ xmlns:odi="http://opendope.org/components"
39
+ xmlns:odgm="http://opendope.org/SmartArt/DataHierarchy"
40
+ xmlns:ns24="http://schemas.openxmlformats.org/officeDocument/2006/bibliography"
41
+ xmlns:ns25="http://schemas.openxmlformats.org/drawingml/2006/compatibility"
42
+ xmlns:ns26="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas">
43
+ <w:body>
44
+ <w:altChunk r:id="htmlChunk" />
45
+ <w:sectPr>
46
+ <w:pgSz w:w="${width}" w:h="${height}" w:orient="${orient}" />
47
+ <w:pgMar w:top="${margins.top}"
48
+ w:right="${margins.right}"
49
+ w:bottom="${margins.bottom}"
50
+ w:left="${margins.left}"
51
+ w:header="${margins.header}"
52
+ w:footer="${margins.footer}"
53
+ w:gutter="${margins.gutter}"/>
54
+ </w:sectPr>
55
+ </w:body>
56
+ </w:document>
57
+ `
58
+ }
@@ -0,0 +1,3 @@
1
+ export * from './documentTemplate'
2
+ export * from './mhtDocumentTemplate'
3
+ export * from './mhtPartTemplate'
@@ -0,0 +1,21 @@
1
+ export const mhtDocumentTemplate = (htmlSource: string, contentParts: string) => {
2
+ debugger;
3
+ return `MIME-Version: 1.0
4
+ Content-Type: multipart/related;
5
+ type="text/html";
6
+ boundary="----=mhtDocumentPart"
7
+
8
+
9
+ ------=mhtDocumentPart
10
+ Content-Type: text/html;
11
+ charset="utf-8"
12
+ Content-Transfer-Encoding: quoted-printable
13
+ Content-Location: file:///C:/fake/document.html
14
+
15
+ ${htmlSource}
16
+
17
+ ${contentParts}
18
+
19
+ ------=mhtDocumentPart--
20
+ `
21
+ }
@@ -0,0 +1,14 @@
1
+ export const mhtPartTemplate = (
2
+ contentType: string,
3
+ contentEncoding: string,
4
+ contentLocation: string,
5
+ encodedContent: string,
6
+ ) => {
7
+ return `------=mhtDocumentPart
8
+ Content-Type: ${contentType}
9
+ Content-Transfer-Encoding: ${contentEncoding}
10
+ Content-Location: ${contentLocation}
11
+
12
+ ${encodedContent}
13
+ `
14
+ }
@@ -0,0 +1,27 @@
1
+ import { mhtDocumentTemplate, mhtPartTemplate } from './templates'
2
+
3
+ export function getMHTdocument(htmlSource: string) {
4
+ debugger
5
+ const ref = _prepareImageParts(htmlSource)
6
+ const imageContentPartsString = ref.imageContentParts.join('\n')
7
+ htmlSource = ref.htmlSource.replace(/\=/g, '=3D')
8
+ return mhtDocumentTemplate(htmlSource, imageContentPartsString)
9
+ }
10
+
11
+ function _prepareImageParts(htmlSource: string) {
12
+ debugger
13
+ const imageContentParts: string[] = []
14
+ const inlinedSrcPattern = /"data:(\w+\/\w+);(\w+),(\S+)"/g
15
+ const inlinedReplacer = (match: string, contentType: string, contentEncoding: string, encodedContent: string) => {
16
+ const index = imageContentParts.length
17
+ const extension = contentType.split('/')[1]
18
+ const contentLocation = `file:///C:/fake/image${index}.${extension}`
19
+ imageContentParts.push(mhtPartTemplate(contentType, contentEncoding, contentLocation, encodedContent))
20
+ return `\"${contentLocation}\"`
21
+ }
22
+ if (!/<img/g.test(htmlSource)) {
23
+ return { htmlSource, imageContentParts }
24
+ }
25
+ htmlSource = htmlSource.replace(inlinedSrcPattern, inlinedReplacer)
26
+ return { htmlSource, imageContentParts }
27
+ }
@@ -0,0 +1,5 @@
1
+ export class AreaModel
2
+ {
3
+ PermissionSetID: number
4
+ AreaUrl:string;
5
+ }
@@ -1,5 +1,8 @@
1
- export declare class ErrorModel {
1
+ export class ErrorModel {
2
+
2
3
  field: string;
3
4
  controlName: string;
4
5
  message: string;
5
- }
6
+
7
+ }
8
+
@@ -0,0 +1,13 @@
1
+ import { FormGroup } from "@angular/forms";
2
+
3
+ export class RequestOptionsModel {
4
+ disableSuccessNotification: boolean=false;
5
+ disableBlockUI: boolean = false;
6
+ disableErrorHandler: boolean = false;
7
+ customSuccessMessage: string;
8
+ customErrorMessage: string;
9
+ responseType:any=""
10
+ formGroup: FormGroup = null
11
+ castResponsetoClass: boolean = true;
12
+
13
+ }
@@ -0,0 +1,19 @@
1
+ export class WordDocumentModel
2
+ {
3
+ header:string;
4
+ footer:string;
5
+ body:string;
6
+ options:DocumentOptionsModel=new DocumentOptionsModel()
7
+ }
8
+ export class DocumentOptionsModel
9
+ {
10
+ pageHeight:number;
11
+ pageWidth:number;
12
+ top:number;
13
+ bottom:number;
14
+ left:number;
15
+ right:number;
16
+ isLandscape:boolean;
17
+ showPaging:boolean;
18
+
19
+ }
@@ -0,0 +1,30 @@
1
+ import { Injectable } from "@angular/core";
2
+ import { TranslateService } from "@ngx-translate/core";
3
+ import { ConfigurationService } from "./configuration.service";
4
+
5
+ @Injectable({
6
+ providedIn: 'root'
7
+ })
8
+ export class AppearanceConfigurationService {
9
+ constructor(private configService: ConfigurationService) {
10
+ }
11
+
12
+ getLayoutTheme() {
13
+ return this.configService.getConfigurationValue('AnonymousLayout_Theme');
14
+ }
15
+ getFooterText() {
16
+ return this.configService.getConfigurationValue('AnonymousLayout_FooterText');
17
+ }
18
+ getPageTitle() {
19
+ return this.configService.getConfigurationValue('AnonymousLayout_PageTitle');
20
+ }
21
+ getFavIcon() {
22
+ return this.configService.getConfigurationValue('AnonymousLayout_FavIcon');
23
+ }
24
+ getCustomStyles() {
25
+ return this.configService.getConfigurationValue('AnonymousLayout_CustomStyles');
26
+ }
27
+ getLogo() {
28
+ return this.configService.getConfigurationValue('AnonymousLayout_Logo');
29
+ }
30
+ }
@@ -0,0 +1,18 @@
1
+ import { HttpClient } from "@angular/common/http";
2
+ import { Injectable } from "@angular/core";
3
+ import { TranslateService } from "@ngx-translate/core";
4
+
5
+ @Injectable({
6
+ providedIn: 'root'
7
+ })
8
+ export class ConfigurationService {
9
+ static JsonData:any[]=[]
10
+ constructor(private httpClient: HttpClient){
11
+ this.httpClient.get("./assets/config/configurations.json").subscribe(data =>{
12
+ ConfigurationService.JsonData = data as any[];
13
+ })
14
+ }
15
+ getConfigurationValue(key:string) {
16
+ return ConfigurationService.JsonData[key];
17
+ }
18
+ }
@@ -0,0 +1,194 @@
1
+ import { Injectable, Optional, Host, SkipSelf, Component } from '@angular/core';
2
+ import { IndividualConfig, ToastrService } from 'ngx-toastr';
3
+ import { BlockUI, NgBlockUI } from 'ng-block-ui';
4
+ import { AbstractControl, ControlContainer, ControlValueAccessor, NG_VALUE_ACCESSOR, FormControl, FormsModule, FormGroup } from '@angular/forms';
5
+ import { TranslateService } from '@ngx-translate/core';
6
+ import { HttpErrorResponse } from '@angular/common/http';
7
+ import { ErrorModel } from '../models/ErrorModel';
8
+ import { UtilityService } from './utility.service';
9
+ import { RequestOptionsModel } from '../models/RequestOptionsModel';
10
+
11
+
12
+
13
+ @Injectable({
14
+ providedIn: 'root'
15
+ })
16
+ export class ControlValidationService {
17
+ private requestOptions: RequestOptionsModel = new RequestOptionsModel();
18
+
19
+ constructor(private utilityService: UtilityService) {
20
+ }
21
+
22
+ isCreatedBefor = false;
23
+
24
+ @BlockUI() blockUI: NgBlockUI;
25
+
26
+ showGlobalError(errorMessage?: string | string[], formId?: string, deleteOld?: boolean) {
27
+ let globalErorrElement = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger')
28
+ if (globalErorrElement.length > 0) {
29
+ this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
30
+ }
31
+ if (this.isCreatedBefor == true) {
32
+ this.removeElementsByClass('alert alert-InvalidValidation bg-light-danger text-danger');
33
+ }
34
+ // tslint:disable-next-line: prefer-const
35
+ if (!formId)
36
+ formId = "currentForm"
37
+ var object = document.getElementById(formId);
38
+ const tagName = 'div';
39
+ // tslint:disable-next-line: prefer-const
40
+ var elementToAppend = document.createElement(tagName); // Your tag name here
41
+ let message: string | string[] = "";
42
+
43
+ if (!errorMessage || (typeof errorMessage == "string")) {
44
+ if (localStorage.getItem('language') == "ar")
45
+ message = errorMessage ? errorMessage : "لديك بعص الأخطاء . من فضلك قم بالمراجعه ";
46
+ else
47
+ message = errorMessage ? errorMessage : "You have some validation errors. Please check below"
48
+ elementToAppend.innerHTML = "<ul class='list-unstyled m-0 py-3 d-flex align-items-center fs-6'><li><i class='fa fa-times-circle text-danger me-3 fs-2'></i>" + message + "</li></ul>";
49
+ elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
50
+ elementToAppend.id += 'errorId';
51
+ // tslint:disable-next-line: prefer-for-of
52
+ const elementToAppen = elementToAppend.cloneNode(true);
53
+ // let targetElement = object.getElementsByClassName("b-control")[0];
54
+ object.insertBefore(elementToAppen, object.firstChild);
55
+ }
56
+ else {
57
+ let ul = document.createElement("ul");
58
+ elementToAppend.appendChild(ul);
59
+
60
+ for (const iterator of errorMessage) {
61
+ let li = document.createElement("li");
62
+ li.innerHTML = iterator;
63
+ ul.appendChild(li);
64
+ }
65
+
66
+ elementToAppend.className += 'alert alert-InvalidValidation bg-light-danger text-danger';
67
+ elementToAppend.id += 'errorId';
68
+ // tslint:disable-next-line: prefer-for-of
69
+ const elementToAppen = elementToAppend.cloneNode(true);
70
+ // let targetElement = object.getElementsByClassName("b-control")[0];
71
+ object.insertBefore(elementToAppen, object.firstChild);
72
+ }
73
+
74
+ this.isCreatedBefor = true;
75
+ }
76
+
77
+ RemoveGlobalError() {
78
+ const removedList = document.getElementsByClassName('alert alert-InvalidValidation bg-light-danger text-danger');
79
+ // tslint:disable-next-line: prefer-for-of
80
+ for (let index = 0; index < removedList.length; index++) {
81
+ const element = removedList[index];
82
+ element.remove();
83
+ }
84
+ this.isCreatedBefor = false;
85
+ }
86
+
87
+ showInputErro(errors: any) {
88
+ // show error on top of form
89
+ this.showGlobalError();
90
+ // remove old error from server
91
+ this.removeElementsByClass('errortemplet');
92
+ // Looping in error Object
93
+ for (const key in errors) {
94
+ if (errors.hasOwnProperty(key)) {
95
+ for (const iterator of errors[key]) {
96
+ const input = document.querySelectorAll('[ng-reflect-name=' + key + ']')[0];
97
+ if ((input.attributes['ng-reflect-name'].value as string) === key) {
98
+ this.removeElementsByClass('erroclass-' + key);
99
+ const tagName = 'p'
100
+ const elementToAppend = document.createElement(tagName); // Your tag name here
101
+ elementToAppend.innerHTML = iterator;
102
+ elementToAppend.style.color = 'red'
103
+ elementToAppend.className += 'errortemplet erroclass-' + key;
104
+ const elementToappen = elementToAppend.cloneNode(true);
105
+ input.parentNode.insertBefore(elementToappen, input.lastChild);
106
+ break;
107
+ }
108
+ }
109
+ }
110
+ }
111
+ }
112
+
113
+ removeElementsByClass(className) {
114
+ const elements = document.getElementsByClassName(className);
115
+ while (elements.length > 0) {
116
+ elements[0].parentNode.removeChild(elements[0]);
117
+ }
118
+ }
119
+
120
+ renderServerErrors(form: FormGroup, err: HttpErrorResponse, requestOptions: RequestOptionsModel, formId?: string) {
121
+ if (err.error == null) {
122
+ return;
123
+ }
124
+ let errorsArray: string[] = [];
125
+
126
+ this.requestOptions = requestOptions;
127
+
128
+ if (err.error.validation_errors) {
129
+ err.error.validation_errors.forEach((element: ErrorModel) => {
130
+ let fieldName = element.field;
131
+ let controlName = element.controlName;
132
+ let message = element.message;
133
+ if (form == null) {
134
+ this.requestOptions.customErrorMessage ? this.utilityService.notifyErrorMessage(this.requestOptions.customErrorMessage) : this.utilityService.notifyErrorMessage(`${message}`);
135
+ }
136
+ else if (controlName && !this.hasControlName(form, controlName)) {
137
+ errorsArray.push(`${fieldName}: ${message}`);
138
+ }
139
+ else {
140
+ this.setFieldError(form, controlName, fieldName, message);
141
+ this.showGlobalError(null, formId);
142
+ }
143
+ });
144
+
145
+ if (errorsArray.length > 0)
146
+ this.showGlobalError(errorsArray, formId)
147
+ }
148
+
149
+ }
150
+
151
+ private hasControlName(form: FormGroup, controlName: string): boolean {
152
+ let control = form.get(controlName);
153
+ return control != null;
154
+ }
155
+
156
+ private setFieldError(form: FormGroup, controlName: string, fieldName: string, message: string) {
157
+ let control = null
158
+
159
+ if (controlName)
160
+ control = this.getControlFormNameByFieldName(form, controlName);
161
+ else
162
+ control = this.getControlFormNameByFieldName(form, fieldName.split('.')[0]);
163
+
164
+ let errors = { "errorMassage": message };
165
+ let fieldNameArray = fieldName.split('.');
166
+ if (fieldNameArray.length >= 1) {
167
+ switch (fieldNameArray[fieldNameArray.length - 1].toLocaleLowerCase()) {
168
+ case "english":
169
+ let englishControl = control.get("English")
170
+ englishControl.setErrors(errors);
171
+ break;
172
+ case "arabic":
173
+ let arabicControl = control.get("Arabic")
174
+ arabicControl.setErrors(errors);
175
+ break;
176
+ default:
177
+ control.setErrors(errors);
178
+ }
179
+ }
180
+ else {
181
+ this.requestOptions.customErrorMessage ? this.utilityService.notifyErrorMessage(this.requestOptions.customErrorMessage) : this.utilityService.notifyErrorMessage(`${message}`)
182
+ }
183
+ }
184
+
185
+ private getControlFormNameByFieldName(form: FormGroup, fieldName: string) {
186
+ const formControls = form.controls;
187
+ let controlName = Object.keys(formControls).find(c => c.toLocaleLowerCase() === fieldName.toLocaleLowerCase());
188
+ let control = form.get(controlName);
189
+ return control;
190
+ }
191
+
192
+
193
+
194
+ }
@@ -0,0 +1,56 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { environment } from '../config/environment';
3
+ import { AreaModel } from '../models/AreaModel';
4
+
5
+ @Injectable({
6
+ providedIn: 'root'
7
+ })
8
+ export class EnvironmentService {
9
+
10
+
11
+ static AreaList: AreaModel[] = []
12
+
13
+ getEnvironmentObject() {
14
+ return environment;
15
+ }
16
+
17
+ getBaseUrl() {
18
+ let Url = environment["BBSF_BaseURL"]
19
+ return Url;
20
+ }
21
+ getApiUrl() {
22
+ let Url = environment["BBSF_ApiUrl"]
23
+ return Url;
24
+ }
25
+
26
+ getProductionMode() {
27
+ let Mode = environment["BBSF_IsProduction"] as boolean
28
+
29
+ return Mode;
30
+ }
31
+
32
+ getDefaultLanguage() {
33
+ let Mode = environment["BBSF_DefaultLanguage"] as string
34
+ return Mode;
35
+ }
36
+ getIdentityServerUrl() {
37
+ let Url = environment["BBSF_IdentityServerUrl"]
38
+ return Url;
39
+ }
40
+ getIsIdentityServerExternal() {
41
+ let Mode = environment["BBSF_IsExternalIdentityServer"] as string
42
+ return Mode;
43
+ }
44
+ getIsIdentityServerClientId() {
45
+ let Mode = environment["BBSF_IdentityServer_Client_Id"] as string
46
+ return Mode;
47
+ }
48
+
49
+ getIsIdentityServerClientSecret() {
50
+ let Mode = environment["BBSF_IdentityServer_Client_Secret"] as string
51
+ return Mode;
52
+ }
53
+
54
+
55
+
56
+ }
@@ -0,0 +1,89 @@
1
+ import { HttpParams } from '@angular/common/http';
2
+ import { Injectable } from '@angular/core';
3
+ import { Router } from '@angular/router';
4
+ import { TranslateService } from '@ngx-translate/core';
5
+ import { AuthService } from '../authentication/auth.service';
6
+ import { EnvironmentService } from './environment.service';
7
+ import { RequestHandlerService } from './requesthandler.service';
8
+ import { StylesBundleService } from './stylesbundle.service';
9
+
10
+ @Injectable({
11
+ providedIn: 'root',
12
+ })
13
+ export class MasterLayoutService {
14
+ ApiUrl = '/api/Home/';
15
+ constructor(private router: Router, private http: RequestHandlerService, private authService: AuthService, private stylesBundleService: StylesBundleService, private translate: TranslateService, private environmentService: EnvironmentService) { }
16
+
17
+ switchLang(lang: string, bundleEnglishName: string, bundleArabicName: string) {
18
+ this.changeLanguage(lang).subscribe((result) => {
19
+ this.updateUserInfo().subscribe((Value) => {
20
+ let UserInfoObject = Value;
21
+ this.authService.getUser();
22
+ this.authService.user.profile = Object.assign(
23
+ this.authService.user.profile,
24
+ UserInfoObject
25
+ );
26
+ this.authService.storUser(this.authService.user);
27
+ this.stylesBundleService.loadThemes(
28
+ lang,
29
+ bundleEnglishName,
30
+ bundleArabicName
31
+ );
32
+ localStorage.setItem('language', lang);
33
+ this.translate.use(lang);
34
+ });
35
+ });
36
+ }
37
+
38
+ reloadComponent() {
39
+ let currentUrl = this.router.url;
40
+ this.router.routeReuseStrategy.shouldReuseRoute = () => false;
41
+ this.router.onSameUrlNavigation = 'reload';
42
+ this.router.navigate([currentUrl]);
43
+ }
44
+
45
+ private changeLanguage(key: string) {
46
+ let params = new HttpParams();
47
+ params = params.append('UserId', this.authService.user.profile.id);
48
+ params = params.append('LanguageKey', key);
49
+ return this.http.post(this.ApiUrl + 'UpdateLanguage', null, null, params);
50
+ }
51
+
52
+ getUserClaims() {
53
+ return this.http.get(this.ApiUrl + 'GetUserClaims', null, null);
54
+ }
55
+
56
+ logError(error: string) {
57
+ let params = new HttpParams();
58
+ params = params.append('error', error);
59
+ return this.http.post(this.ApiUrl + 'LogError', null, null, params);
60
+ }
61
+
62
+ private updateUserInfo() {
63
+ let isExternal = this.environmentService.getIsIdentityServerExternal().toLowerCase() == 'true';
64
+ if (isExternal)
65
+ return this.getUserClaims();
66
+ return this.http.get('/connect/userinfo');
67
+ }
68
+
69
+ switchRole(permissionSetID: string) {
70
+ this.updateRole(permissionSetID).subscribe((result) => {
71
+ this.updateUserInfo().subscribe((Value) => {
72
+ let UserInfoObject = Value;
73
+ this.authService.getUser();
74
+ this.authService.user.profile = Object.assign(
75
+ this.authService.user.profile,
76
+ UserInfoObject
77
+ );
78
+ this.authService.storUser(this.authService.user);
79
+ });
80
+ });
81
+ }
82
+
83
+ private updateRole(permissionSetID: string) {
84
+ let params = new HttpParams();
85
+ params = params.append('UserId', this.authService.user.profile.id);
86
+ params = params.append('RoleID', permissionSetID);
87
+ return this.http.post(this.ApiUrl + 'SwitchRole', null, null, params);
88
+ }
89
+ }