Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
utils
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
EIT-SWE
ux
utils
Commits
c4678c4b
Commit
c4678c4b
authored
Mar 27, 2020
by
Ryan Diehl
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into 'master'
Develop See merge request
!17
parents
b4bcc0f1
ebf706af
Pipeline
#90433
passed with stages
in 4 minutes and 30 seconds
Changes
46
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
46 changed files
with
867 additions
and
4 deletions
+867
-4
.gitignore
.gitignore
+0
-1
angular.json
angular.json
+84
-0
libs/utils/loading-events/README.md
libs/utils/loading-events/README.md
+10
-0
libs/utils/loading-events/jest.config.js
libs/utils/loading-events/jest.config.js
+9
-0
libs/utils/loading-events/ng-package.json
libs/utils/loading-events/ng-package.json
+5
-0
libs/utils/loading-events/src/index.ts
libs/utils/loading-events/src/index.ts
+2
-0
libs/utils/loading-events/src/lib/loading-events.module.spec.ts
...tils/loading-events/src/lib/loading-events.module.spec.ts
+14
-0
libs/utils/loading-events/src/lib/loading-events.module.ts
libs/utils/loading-events/src/lib/loading-events.module.ts
+10
-0
libs/utils/loading-events/src/lib/loading-events.ts
libs/utils/loading-events/src/lib/loading-events.ts
+31
-0
libs/utils/loading-events/src/test-setup.ts
libs/utils/loading-events/src/test-setup.ts
+2
-0
libs/utils/loading-events/tsconfig.json
libs/utils/loading-events/tsconfig.json
+7
-0
libs/utils/loading-events/tsconfig.lib.json
libs/utils/loading-events/tsconfig.lib.json
+20
-0
libs/utils/loading-events/tsconfig.spec.json
libs/utils/loading-events/tsconfig.spec.json
+10
-0
libs/utils/loading-events/tslint.json
libs/utils/loading-events/tslint.json
+7
-0
libs/utils/logger/README.md
libs/utils/logger/README.md
+32
-0
libs/utils/logger/jest.config.js
libs/utils/logger/jest.config.js
+9
-0
libs/utils/logger/ng-package.json
libs/utils/logger/ng-package.json
+5
-0
libs/utils/logger/src/index.ts
libs/utils/logger/src/index.ts
+3
-0
libs/utils/logger/src/lib/log-level.model.ts
libs/utils/logger/src/lib/log-level.model.ts
+12
-0
libs/utils/logger/src/lib/logger.module.spec.ts
libs/utils/logger/src/lib/logger.module.spec.ts
+14
-0
libs/utils/logger/src/lib/logger.module.ts
libs/utils/logger/src/lib/logger.module.ts
+12
-0
libs/utils/logger/src/lib/logger.service.spec.ts
libs/utils/logger/src/lib/logger.service.spec.ts
+17
-0
libs/utils/logger/src/lib/logger.service.ts
libs/utils/logger/src/lib/logger.service.ts
+76
-0
libs/utils/logger/src/test-setup.ts
libs/utils/logger/src/test-setup.ts
+2
-0
libs/utils/logger/tsconfig.json
libs/utils/logger/tsconfig.json
+7
-0
libs/utils/logger/tsconfig.lib.json
libs/utils/logger/tsconfig.lib.json
+20
-0
libs/utils/logger/tsconfig.spec.json
libs/utils/logger/tsconfig.spec.json
+10
-0
libs/utils/logger/tslint.json
libs/utils/logger/tslint.json
+7
-0
libs/utils/package.json
libs/utils/package.json
+3
-1
libs/utils/properties/README.md
libs/utils/properties/README.md
+67
-0
libs/utils/properties/jest.config.js
libs/utils/properties/jest.config.js
+9
-0
libs/utils/properties/ng-package.json
libs/utils/properties/ng-package.json
+5
-0
libs/utils/properties/src/index.ts
libs/utils/properties/src/index.ts
+3
-0
libs/utils/properties/src/lib/properties.config.ts
libs/utils/properties/src/lib/properties.config.ts
+7
-0
libs/utils/properties/src/lib/properties.module.ts
libs/utils/properties/src/lib/properties.module.ts
+11
-0
libs/utils/properties/src/lib/properties.service.spec.ts
libs/utils/properties/src/lib/properties.service.spec.ts
+165
-0
libs/utils/properties/src/lib/properties.service.ts
libs/utils/properties/src/lib/properties.service.ts
+97
-0
libs/utils/properties/src/test-setup.ts
libs/utils/properties/src/test-setup.ts
+2
-0
libs/utils/properties/tsconfig.json
libs/utils/properties/tsconfig.json
+7
-0
libs/utils/properties/tsconfig.lib.json
libs/utils/properties/tsconfig.lib.json
+17
-0
libs/utils/properties/tsconfig.lib.prod.json
libs/utils/properties/tsconfig.lib.prod.json
+6
-0
libs/utils/properties/tsconfig.spec.json
libs/utils/properties/tsconfig.spec.json
+10
-0
libs/utils/properties/tslint.json
libs/utils/properties/tslint.json
+7
-0
nx.json
nx.json
+9
-0
package.json
package.json
+1
-1
tsconfig.json
tsconfig.json
+4
-1
No files found.
.gitignore
View file @
c4678c4b
...
...
@@ -19,7 +19,6 @@
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
...
...
angular.json
View file @
c4678c4b
...
...
@@ -280,6 +280,90 @@
}
}
}
},
"utils-properties"
:
{
"projectType"
:
"library"
,
"root"
:
"libs/utils/properties"
,
"sourceRoot"
:
"libs/utils/properties/src"
,
"prefix"
:
"ut"
,
"architect"
:
{
"lint"
:
{
"builder"
:
"@angular-devkit/build-angular:tslint"
,
"options"
:
{
"tsConfig"
:
[
"libs/utils/properties/tsconfig.lib.json"
,
"libs/utils/properties/tsconfig.spec.json"
],
"exclude"
:
[
"**/node_modules/**"
,
"!libs/utils/properties/**"
]
}
},
"test"
:
{
"builder"
:
"@nrwl/jest:jest"
,
"options"
:
{
"jestConfig"
:
"libs/utils/properties/jest.config.js"
,
"tsConfig"
:
"libs/utils/properties/tsconfig.spec.json"
,
"setupFile"
:
"libs/utils/properties/src/test-setup.ts"
}
}
},
"schematics"
:
{
"@nrwl/angular:component"
:
{
"styleext"
:
"scss"
}
}
},
"utils-logger"
:
{
"projectType"
:
"library"
,
"root"
:
"libs/utils/logger"
,
"sourceRoot"
:
"libs/utils/logger/src"
,
"prefix"
:
"ut"
,
"architect"
:
{
"lint"
:
{
"builder"
:
"@angular-devkit/build-angular:tslint"
,
"options"
:
{
"tsConfig"
:
[
"libs/utils/logger/tsconfig.lib.json"
,
"libs/utils/logger/tsconfig.spec.json"
],
"exclude"
:
[
"**/node_modules/**"
,
"!libs/utils/logger/**"
]
}
},
"test"
:
{
"builder"
:
"@nrwl/jest:jest"
,
"options"
:
{
"jestConfig"
:
"libs/utils/logger/jest.config.js"
,
"tsConfig"
:
"libs/utils/logger/tsconfig.spec.json"
,
"setupFile"
:
"libs/utils/logger/src/test-setup.ts"
}
}
},
"schematics"
:
{
"@nrwl/angular:component"
:
{
"styleext"
:
"scss"
}
}
},
"utils-loading-events"
:
{
"projectType"
:
"library"
,
"root"
:
"libs/utils/loading-events"
,
"sourceRoot"
:
"libs/utils/loading-events/src"
,
"prefix"
:
"ut"
,
"architect"
:
{
"lint"
:
{
"builder"
:
"@angular-devkit/build-angular:tslint"
,
"options"
:
{
"tsConfig"
:
[
"libs/utils/loading-events/tsconfig.lib.json"
,
"libs/utils/loading-events/tsconfig.spec.json"
],
"exclude"
:
[
"**/node_modules/**"
,
"!libs/utils/loading-events/**"
]
}
},
"test"
:
{
"builder"
:
"@nrwl/jest:jest"
,
"options"
:
{
"jestConfig"
:
"libs/utils/loading-events/jest.config.js"
,
"tsConfig"
:
"libs/utils/loading-events/tsconfig.spec.json"
,
"setupFile"
:
"libs/utils/loading-events/src/test-setup.ts"
}
}
},
"schematics"
:
{
"@nrwl/angular:component"
:
{
"styleext"
:
"scss"
}
}
}
},
"cli"
:
{
...
...
libs/utils/loading-events/README.md
0 → 100644
View file @
c4678c4b
# @psu/utils/loading-events
This library is used to dispatch a
`CustomEvent`
to the DOM when the application
is done bootstrapping. Our index.html files show a loading banner outside of Angular.
This library is used to communicate that the app is ready to load, which fades out
the loading banner and fades in the application.
## Running unit tests
Run
`nx test utils-loading-events`
to execute the unit tests.
libs/utils/loading-events/jest.config.js
0 → 100644
View file @
c4678c4b
module
.
exports
=
{
name
:
'
utils-loading-events
'
,
preset
:
'
../../../jest.config.js
'
,
coverageDirectory
:
'
../../../coverage/libs/utils/loading-events
'
,
snapshotSerializers
:
[
'
jest-preset-angular/AngularSnapshotSerializer.js
'
,
'
jest-preset-angular/HTMLCommentSerializer.js
'
]
};
libs/utils/loading-events/ng-package.json
0 → 100644
View file @
c4678c4b
{
"lib"
:
{
"entryFile"
:
"src/index.ts"
}
}
libs/utils/loading-events/src/index.ts
0 → 100644
View file @
c4678c4b
export
{
LoadingEvents
}
from
'
./lib/loading-events
'
;
export
{
LoadingEventsModule
}
from
'
./lib/loading-events.module
'
;
libs/utils/loading-events/src/lib/loading-events.module.spec.ts
0 → 100644
View file @
c4678c4b
import
{
async
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
LoadingEventsModule
}
from
'
./loading-events.module
'
;
describe
(
'
LoadingEventsModule
'
,
()
=>
{
beforeEach
(
async
(()
=>
{
TestBed
.
configureTestingModule
({
imports
:
[
LoadingEventsModule
]
}).
compileComponents
();
}));
it
(
'
should create
'
,
()
=>
{
expect
(
LoadingEventsModule
).
toBeDefined
();
});
});
libs/utils/loading-events/src/lib/loading-events.module.ts
0 → 100644
View file @
c4678c4b
import
{
CommonModule
}
from
'
@angular/common
'
;
import
{
NgModule
}
from
'
@angular/core
'
;
import
{
LoggerModule
}
from
'
@psu/utils/logger
'
;
import
{
LoadingEvents
}
from
'
./loading-events
'
;
@
NgModule
({
imports
:
[
CommonModule
,
LoggerModule
],
providers
:
[
LoadingEvents
]
})
export
class
LoadingEventsModule
{}
libs/utils/loading-events/src/lib/loading-events.ts
0 → 100644
View file @
c4678c4b
import
{
DOCUMENT
}
from
'
@angular/common
'
;
import
{
Inject
,
Injectable
}
from
'
@angular/core
'
;
import
{
Logger
}
from
'
@psu/utils/logger
'
;
@
Injectable
()
export
class
LoadingEvents
{
private
doc
:
Document
;
private
isAppReady
:
boolean
;
constructor
(@
Inject
(
DOCUMENT
)
doc
:
any
,
private
log
:
Logger
)
{
this
.
doc
=
doc
;
this
.
isAppReady
=
false
;
}
public
triggerAppReady
():
void
{
if
(
this
.
isAppReady
)
{
return
;
}
this
.
log
.
debug
(
'
appready event triggered
'
);
this
.
doc
.
dispatchEvent
(
this
.
createEvent
(
'
appready
'
,
true
,
false
));
this
.
isAppReady
=
true
;
}
private
createEvent
(
eventType
:
string
,
bubbles
:
boolean
,
cancelable
:
boolean
):
Event
{
const
customEvent
:
any
=
new
CustomEvent
(
eventType
,
{
bubbles
,
cancelable
});
return
customEvent
;
}
}
libs/utils/loading-events/src/test-setup.ts
0 → 100644
View file @
c4678c4b
import
'
jest-preset-angular
'
;
import
'
../../../../jestGlobalMocks
'
;
libs/utils/loading-events/tsconfig.json
0 → 100644
View file @
c4678c4b
{
"extends"
:
"../../../tsconfig.json"
,
"compilerOptions"
:
{
"types"
:
[
"node"
,
"jest"
]
},
"include"
:
[
"**/*.ts"
]
}
libs/utils/loading-events/tsconfig.lib.json
0 → 100644
View file @
c4678c4b
{
"extends"
:
"./tsconfig.json"
,
"compilerOptions"
:
{
"outDir"
:
"../../../dist/out-tsc"
,
"target"
:
"es2015"
,
"declaration"
:
true
,
"inlineSources"
:
true
,
"types"
:
[],
"lib"
:
[
"dom"
,
"es2018"
]
},
"angularCompilerOptions"
:
{
"annotateForClosureCompiler"
:
true
,
"skipTemplateCodegen"
:
true
,
"strictMetadataEmit"
:
true
,
"fullTemplateTypeCheck"
:
true
,
"strictInjectionParameters"
:
true
,
"enableResourceInlining"
:
true
},
"exclude"
:
[
"src/test-setup.ts"
,
"**/*.spec.ts"
]
}
libs/utils/loading-events/tsconfig.spec.json
0 → 100644
View file @
c4678c4b
{
"extends"
:
"./tsconfig.json"
,
"compilerOptions"
:
{
"outDir"
:
"../../../dist/out-tsc"
,
"module"
:
"commonjs"
,
"types"
:
[
"jest"
,
"node"
]
},
"files"
:
[
"src/test-setup.ts"
],
"include"
:
[
"**/*.spec.ts"
,
"**/*.d.ts"
]
}
libs/utils/loading-events/tslint.json
0 → 100644
View file @
c4678c4b
{
"extends"
:
"../../../tslint.json"
,
"rules"
:
{
"directive-selector"
:
[
true
,
"attribute"
,
"ut"
,
"camelCase"
],
"component-selector"
:
[
true
,
"element"
,
"ut"
,
"kebab-case"
]
}
}
libs/utils/logger/README.md
0 → 100644
View file @
c4678c4b
# @psu/utils/logger
`Logger`
is a simple facade around console logging. In the future, if we are
able to add some type of RESTful logging (Splunk for example), it would go here.
## Usage
1.
Define logger options in your environment files
```
typescript
// environment.ts
export
function
loggerOptions
():
Options
{
return
{
level
:
Level
.
LOG
};
}
export
const
environment
=
{
production
:
false
,
loggerOptions
};
```
2.
Import LoggerModule into your AppModule
```
typescript
imports
:
[
LoggerModule
.
forRoot
(
environment
.
loggerOptions
)];
```
3.
Inject
`Logger`
and log stuff
## Running unit tests
Run
`nx test utils-logger`
to execute the unit tests.
libs/utils/logger/jest.config.js
0 → 100644
View file @
c4678c4b
module
.
exports
=
{
name
:
'
utils-logger
'
,
preset
:
'
../../../jest.config.js
'
,
coverageDirectory
:
'
../../../coverage/libs/utils/logger
'
,
snapshotSerializers
:
[
'
jest-preset-angular/AngularSnapshotSerializer.js
'
,
'
jest-preset-angular/HTMLCommentSerializer.js
'
]
};
libs/utils/logger/ng-package.json
0 → 100644
View file @
c4678c4b
{
"lib"
:
{
"entryFile"
:
"src/index.ts"
}
}
libs/utils/logger/src/index.ts
0 → 100644
View file @
c4678c4b
export
{
Level
}
from
'
./lib/log-level.model
'
;
export
{
LoggerModule
}
from
'
./lib/logger.module
'
;
export
{
Logger
}
from
'
./lib/logger.service
'
;
libs/utils/logger/src/lib/log-level.model.ts
0 → 100644
View file @
c4678c4b
/**
* The available options to set the Level of the Logger.
* See {@link Logger}.
*/
export
enum
Level
{
OFF
=
0
,
ERROR
=
1
,
WARN
=
2
,
INFO
=
3
,
DEBUG
=
4
,
LOG
=
5
}
libs/utils/logger/src/lib/logger.module.spec.ts
0 → 100644
View file @
c4678c4b
import
{
async
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
LoggerModule
}
from
'
./logger.module
'
;
describe
(
'
LoggerModule
'
,
()
=>
{
beforeEach
(
async
(()
=>
{
TestBed
.
configureTestingModule
({
imports
:
[
LoggerModule
]
}).
compileComponents
();
}));
it
(
'
should create
'
,
()
=>
{
expect
(
LoggerModule
).
toBeDefined
();
});
});
libs/utils/logger/src/lib/logger.module.ts
0 → 100644
View file @
c4678c4b
import
{
ModuleWithProviders
,
NgModule
}
from
'
@angular/core
'
;
import
{
Logger
,
Options
}
from
'
./logger.service
'
;
@
NgModule
({})
export
class
LoggerModule
{
public
static
forRoot
(
options
:
()
=>
Options
):
ModuleWithProviders
{
return
{
ngModule
:
LoggerModule
,
providers
:
[{
provide
:
Options
,
useFactory
:
options
},
Logger
]
};
}
}
libs/utils/logger/src/lib/logger.service.spec.ts
0 → 100644
View file @
c4678c4b
import
{
Logger
,
Options
}
from
'
./logger.service
'
;
import
{
TestBed
}
from
'
@angular/core/testing
'
;
describe
(
'
LoggerService
'
,
()
=>
{
let
service
:
Logger
;
beforeEach
(()
=>
{
TestBed
.
configureTestingModule
({
providers
:
[
Logger
,
{
provide
:
Options
,
useValue
:
{}
}]
});
service
=
TestBed
.
get
(
Logger
);
});
it
(
'
should create
'
,
()
=>
{
expect
(
service
).
toBeDefined
();
});
});
libs/utils/logger/src/lib/logger.service.ts
0 → 100644
View file @
c4678c4b
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
Level
}
from
'
./log-level.model
'
;
/**
* Logger options.
* See {@link Logger}.
*
* level - How much detail you want to see in the logs, 0 being off, 1 being the less detailed, 5 being the most. Defaults to LOG.
*/
export
class
Options
{
level
:
Level
;
}
// For browsers that don't implement the debug method, log will be used instead.
const
CONSOLE_DEBUG_METHOD
=
console
[
'
debug
'
]
?
'
debug
'
:
'
log
'
;
const
DEFAULT_OPTIONS
:
Options
=
{
level
:
Level
.
LOG
};
@
Injectable
()
export
class
Logger
{
private
_level
:
Level
;
public
Level
:
any
=
Level
;
constructor
(
options
:
Options
)
{
const
{
level
}
=
Object
.
assign
({},
DEFAULT_OPTIONS
,
options
);
this
.
_level
=
level
;
}
public
error
(
message
?:
any
,
...
optionalParams
:
any
[])
{
if
(
this
.
isErrorEnabled
())
{
console
.
error
.
apply
(
console
,
arguments
);
}
}
public
warn
(
message
?:
any
,
...
optionalParams
:
any
[])
{
if
(
this
.
isWarnEnabled
())
{
console
.
warn
.
apply
(
console
,
arguments
);
}
}
public
info
(
message
?:
any
,
...
optionalParams
:
any
[])
{
if
(
this
.
isInfoEnabled
())
{
// tslint:disable-next-line:no-console
console
.
info
.
apply
(
console
,
arguments
);
}
}
public
debug
(
message
?:
any
,
...
optionalParams
:
any
[])
{
if
(
this
.
isDebugEnabled
())
{
(
<
any
>
console
)[
CONSOLE_DEBUG_METHOD
].
apply
(
console
,
arguments
);
}
}
public
log
(
message
?:
any
,
...
optionalParams
:
any
[])
{
if
(
this
.
isLogEnabled
())
{
// tslint:disable-next-line: no-console
console
.
log
.
apply
(
console
,
arguments
);
}
}
public
isErrorEnabled
=
():
boolean
=>
this
.
level
>=
Level
.
ERROR
;
public
isWarnEnabled
=
():
boolean
=>
this
.
level
>=
Level
.
WARN
;
public
isInfoEnabled
=
():
boolean
=>
this
.
level
>=
Level
.
INFO
;
public
isDebugEnabled
=
():
boolean
=>
this
.
level
>=
Level
.
DEBUG
;
public
isLogEnabled
=
():
boolean
=>
this
.
level
>=
Level
.
LOG
;
public
get
level
():
Level
{
return
this
.
_level
;
}
public
set
level
(
level
:
Level
)
{
this
.
_level
=
level
;
}
}
libs/utils/logger/src/test-setup.ts
0 → 100644
View file @
c4678c4b
import
'
jest-preset-angular
'
;
import
'
../../../../jestGlobalMocks
'
;
libs/utils/logger/tsconfig.json
0 → 100644
View file @
c4678c4b
{
"extends"
:
"../../../tsconfig.json"
,
"compilerOptions"
:
{
"types"
:
[
"node"
,
"jest"
]
},
"include"
:
[
"**/*.ts"
]
}
libs/utils/logger/tsconfig.lib.json
0 → 100644
View file @
c4678c4b
{
"extends"
:
"./tsconfig.json"
,
"compilerOptions"
:
{
"outDir"
:
"../../../dist/out-tsc"
,
"target"
:
"es2015"
,
"declaration"
:
true
,
"inlineSources"
:
true
,
"types"
:
[],
"lib"
:
[
"dom"
,
"es2018"
]
},
"angularCompilerOptions"
:
{
"annotateForClosureCompiler"
:
true
,
"skipTemplateCodegen"
:
true
,
"strictMetadataEmit"
:
true
,
"fullTemplateTypeCheck"
:
true
,
"strictInjectionParameters"
:
true
,
"enableResourceInlining"
:
true
},
"exclude"
:
[
"src/test-setup.ts"
,
"**/*.spec.ts"
]
}
libs/utils/logger/tsconfig.spec.json
0 → 100644
View file @
c4678c4b
{
"extends"
:
"./tsconfig.json"
,
"compilerOptions"
:
{
"outDir"
:
"../../../dist/out-tsc"
,
"module"
:
"commonjs"
,
"types"
:
[
"jest"
,
"node"
]
},
"files"
:
[
"src/test-setup.ts"
],
"include"
:
[
"**/*.spec.ts"
,
"**/*.d.ts"
]
}
libs/utils/logger/tslint.json
0 → 100644
View file @
c4678c4b
{
"extends"
:
"../../../tslint.json"
,
"rules"
:
{
"directive-selector"
:
[
true
,
"attribute"
,
"ut"
,
"camelCase"
],
"component-selector"
:
[
true
,
"element"
,
"ut"
,
"kebab-case"
]
}
}
libs/utils/package.json
View file @
c4678c4b
...
...
@@ -5,7 +5,9 @@
"@angular/common"
:
"^8.0.0"
,
"@angular/core"
:
"^8.0.0"
,
"@angular/cdk"
:
"^8.2.3"
,
"ramda"
:
"^0.27.0"
"ngx-cookie"
:
"^4.1.2"
,
"ramda"
:
"^0.27.0"
,
"short-uuid"
:
"^3.1.1"
},
"private"
:
false
,
"repository"
:
{
...
...
libs/utils/properties/README.md
0 → 100644
View file @
c4678c4b
# @psu/utils/properties
This library handles loading application properties asyncronously.
Typical Angular documentation shows the use of
`environment.ts`
and
`environment.prod.ts`
to
store application properties. However, that strategy means that the properties are compile-time
dependencies - so in order to change a property at runtime, you need to re-compile the whole app.
This library is the first piece of supporting property changes at runtime.
`PropetiesService`
will
load the property file via HTTP, and exposes a
`Promise<T>`
to work with Angular's
`APP_INITIALIZER`
.
## Usage
1.
Import PropertiesModule into your AppModule
2.
Define an interface(s) that describes the shape of your application properties.
```
typescript
import
{
SecurityConfig
}
from
'
@psu/security
'
;
export
interface
MyAppProperties
{
myAppConfig
:
MyAppConfig
;
security
:
SecurityConfig
;
}
export
interface
MyAppConfig
{
someUrl
:
string
;
doStuff
:
boolean
;
}
```
3.
Setup an
[
APP_INITIALIZER
](
https://angular.io/api/core/APP_INITIALIZER
)
to load properties and delay loading of the application by returning a Promise
```
typescript
// inside AppMdoule's providers array:
{
provide
:
MY_APP_CONFIG
,
// provide your app's token
useValue
:
{}
// provide default values for the token
},
{
provide
:
SECURITY_CONFIG
,
useValue
:
{}
},
{
provide
:
APP_INITIALIZER
,
useFactory
:
initProperties
,
multi
:
true
,
deps
:
[
PropertiesService
,
MY_APP_CONFIG
,
// your app config injection token
SECURITY_CONFIG
]
}
// Define the initProperties function
export
function
initProperties
(
propertiesService
:
PropertiesService
<
MyAppProperties
>
,
myAppConfig
:
MyAppConfig
,
securityConfig
:
SecurityConfig
):
()
=>
Promise
<
MyAppProperties
>
{
return
()
=>
propertiesService
.
load
(
'
my-app
'
).
then
(
props
=>
{
// populate injection tokens with values from property file
// "props" is of type MyAppProperties
Object
.
assign
(
myAppConfig
,
p
.
myAppConfig
);
Object
.
assign
(
securityConfig
,
p
.
security
);
});
}
```
## Running unit tests
Run
`ng test utils-properties`
to execute the unit tests.
libs/utils/properties/jest.config.js
0 → 100644
View file @
c4678c4b
module
.
exports
=
{
name
:
'
utils-properties
'
,
preset
:
'
../../../jest.config.js
'
,
coverageDirectory
:
'
../../../coverage/libs/utils/properties
'
,
snapshotSerializers
:
[
'
jest-preset-angular/AngularSnapshotSerializer.js
'
,
'
jest-preset-angular/HTMLCommentSerializer.js
'
]
};
libs/utils/properties/ng-package.json
0 → 100644
View file @
c4678c4b
{
"lib"
:
{
"entryFile"
:
"src/index.ts"
}
}
libs/utils/properties/src/index.ts
0 → 100644
View file @
c4678c4b
export
{
PropertiesConfig
,
PROPERTIES_CONFIG
}
from
'
./lib/properties.config
'
;
export
{
PropertiesModule
}
from
'
./lib/properties.module
'
;
export
{
PropertiesService
}
from
'
./lib/properties.service
'
;
libs/utils/properties/src/lib/properties.config.ts
0 → 100644
View file @
c4678c4b
import
{
InjectionToken
}
from
'
@angular/core
'
;
export
interface
PropertiesConfig
{
propertiesBase
:
string
;
}
export
const
PROPERTIES_CONFIG
=
new
InjectionToken
<
PropertiesConfig
>
(
'
properties.config
'
);
libs/utils/properties/src/lib/properties.module.ts
0 → 100644
View file @
c4678c4b
import
{
CommonModule
}
from
'
@angular/common
'
;
import
{
NgModule
}
from
'
@angular/core
'
;
import
{
LoadingEventsModule
}
from
'
@psu/utils/loading-events
'
;
import
{
LoggerModule
}
from
'
@psu/utils/logger
'
;