Skip to content

Commit c0f186b

Browse files
committed
Added @kephas/ui to Angular 12 build system
1 parent 9d1bbe4 commit c0f186b

File tree

15 files changed

+340
-24
lines changed

15 files changed

+340
-24
lines changed

src/angular.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,37 @@
126126
}
127127
}
128128
}
129+
},
130+
"@kephas/ui": {
131+
"projectType": "library",
132+
"root": "projects/kephas/ui",
133+
"sourceRoot": "projects/kephas/ui/src",
134+
"prefix": "lib",
135+
"architect": {
136+
"build": {
137+
"builder": "@angular-devkit/build-angular:ng-packagr",
138+
"options": {
139+
"project": "projects/kephas/ui/ng-package.json"
140+
},
141+
"configurations": {
142+
"production": {
143+
"tsConfig": "projects/kephas/ui/tsconfig.lib.prod.json"
144+
},
145+
"development": {
146+
"tsConfig": "projects/kephas/ui/tsconfig.lib.json"
147+
}
148+
},
149+
"defaultConfiguration": "production"
150+
},
151+
"test": {
152+
"builder": "@angular-devkit/build-angular:karma",
153+
"options": {
154+
"main": "projects/kephas/ui/src/test.ts",
155+
"tsConfig": "projects/kephas/ui/tsconfig.spec.json",
156+
"karmaConfig": "projects/kephas/ui/karma.conf.js"
157+
}
158+
}
159+
}
129160
}
130161
},
131162
"defaultProject": "@kephas/core"

src/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"pack-reflection": "ng build --project=@kephas/reflection",
1212
"pack-messaging": "ng build --project=@kephas/messaging",
1313
"pack-commands": "ng build --project=@kephas/commands",
14-
"pack-all": "ng build --project=@kephas/core && ng build --project=@kephas/reflection && ng build --project=@kephas/messaging && ng build --project=@kephas/commands"
14+
"pack-ui": "ng build --project=@kephas/ui",
15+
"pack-all": "ng build --project=@kephas/core && ng build --project=@kephas/reflection && ng build --project=@kephas/messaging && ng build --project=@kephas/commands && ng build --project=@kephas/ui"
1516
},
1617
"private": true,
1718
"dependencies": {
Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
# Commands
1+
# Kephas.Commands
22

3-
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 12.2.0.
4-
5-
## Code scaffolding
6-
7-
Run `ng generate component component-name --project commands` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project commands`.
8-
> Note: Don't forget to add `--project commands` or else it will be added to the default project in your `angular.json` file.
9-
10-
## Build
11-
12-
Run `ng build commands` to build the project. The build artifacts will be stored in the `dist/` directory.
13-
14-
## Publishing
15-
16-
After building your library with `ng build commands`, go to the dist folder `cd dist/commands` and run `npm publish`.
17-
18-
## Running unit tests
19-
20-
Run `ng test commands` to execute the unit tests via [Karma](https://karma-runner.github.io).
21-
22-
## Further help
23-
24-
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
3+
Provides the commands infrastructure.

src/projects/kephas/ui/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Kephas.UI
2+
3+
Provides a common infrastructure for UI components.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
module.exports = function (config) {
5+
config.set({
6+
basePath: '',
7+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8+
plugins: [
9+
require('karma-jasmine'),
10+
require('karma-chrome-launcher'),
11+
require('karma-jasmine-html-reporter'),
12+
require('karma-coverage'),
13+
require('@angular-devkit/build-angular/plugins/karma')
14+
],
15+
client: {
16+
jasmine: {
17+
// you can add configuration options for Jasmine here
18+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19+
// for example, you can disable the random execution with `random: false`
20+
// or set a specific seed with `seed: 4321`
21+
},
22+
clearContext: false // leave Jasmine Spec Runner output visible in browser
23+
},
24+
jasmineHtmlReporter: {
25+
suppressAll: true // removes the duplicated traces
26+
},
27+
coverageReporter: {
28+
dir: require('path').join(__dirname, '../../../coverage/kephas/ui'),
29+
subdir: '.',
30+
reporters: [
31+
{ type: 'html' },
32+
{ type: 'text-summary' }
33+
]
34+
},
35+
reporters: ['progress', 'kjhtml'],
36+
port: 9876,
37+
colors: true,
38+
logLevel: config.LOG_INFO,
39+
autoWatch: true,
40+
browsers: ['Chrome'],
41+
singleRun: false,
42+
restartOnFileChange: true
43+
});
44+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
3+
"dest": "../../../dist/kephas/ui",
4+
"lib": {
5+
"entryFile": "src/public-api.ts",
6+
"umdModuleIds": {
7+
"@kephas/core": "@kephas/core"
8+
}
9+
}
10+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@kephas/ui",
3+
"version": "1.0.0-preview.1",
4+
"description": "Provides a common infrastructure for UI components.",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/kephas-software/kephas-js/tree/master/src/projects/kephas/ui"
8+
},
9+
"keywords": [
10+
"kephas",
11+
"ui"
12+
],
13+
"author": {
14+
"name": "Kephas Software SRL"
15+
},
16+
"license": "MIT",
17+
"peerDependencies": {
18+
"@kephas/core": "^1.0.0-preview.1"
19+
},
20+
"dependencies": {
21+
"tslib": "^2.3.0"
22+
},
23+
"devDependencies": {
24+
"typescript": "4.2.4"
25+
}
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect } from 'chai';
2+
import 'mocha';
3+
4+
import { AppServiceInfoRegistry, Logger, LiteCompositionContext } from '@kephas/core';
5+
import { NotificationService } from '.';
6+
7+
describe('NotificationService.composition', () => {
8+
it('should be registered as service', () => {
9+
expect(AppServiceInfoRegistry.Instance.isServiceContract(NotificationService)).is.true;
10+
expect(AppServiceInfoRegistry.Instance.isService(NotificationService)).is.true;
11+
});
12+
13+
it('should be properly initialized', () => {
14+
let injector = new LiteCompositionContext(AppServiceInfoRegistry.Instance);
15+
let logger = injector.get(Logger);
16+
let notification = injector.get(NotificationService);
17+
18+
expect(notification).is.not.null;
19+
expect(notification["logger"]).is.equal(logger);
20+
});
21+
});
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import { SingletonAppServiceContract, AppService, Priority, Logger, LogLevel } from '@kephas/core';
2+
3+
/**
4+
* Notification service.
5+
*
6+
* @export
7+
* @class NotificationService
8+
*/
9+
@AppService({ overridePriority: Priority.Low })
10+
@SingletonAppServiceContract()
11+
export class NotificationService {
12+
/**
13+
* Gets or sets the logger.
14+
*
15+
* @protected
16+
* @type {Logger}
17+
* @memberof NotificationService
18+
*/
19+
protected logger: Logger;
20+
21+
/**
22+
* Creates an instance of Notification.
23+
* @param {Logger} [logger] Optional. The logger.
24+
* @memberof NotificationService
25+
*/
26+
constructor(logger?: Logger) {
27+
this.logger = logger || new Logger();
28+
}
29+
30+
/**
31+
* Notifies the message at error level.
32+
*
33+
* @param {*} data The information to be displayed.
34+
* @memberof NotificationService
35+
*/
36+
public notifyError(data: any) {
37+
// debugger;
38+
const severityString = data.severity || LogLevel[LogLevel.Error];
39+
const severity = severityString === LogLevel[LogLevel.Warning]
40+
? LogLevel.Warning
41+
: LogLevel.Error;
42+
this.show(this.formatData(data), severity);
43+
}
44+
45+
/**
46+
* Notifies the message at warning level.
47+
*
48+
* @param {*} data The information to be displayed.
49+
* @memberof NotificationService
50+
*/
51+
public notifyWarning(data: any) {
52+
// debugger;
53+
const severityString = data.severity || LogLevel[LogLevel.Warning];
54+
const severity = severityString === LogLevel[LogLevel.Warning]
55+
? LogLevel.Warning
56+
: LogLevel.Error;
57+
this.show(this.formatData(data), severity);
58+
}
59+
60+
/**
61+
* Notifies the message at information level.
62+
*
63+
* @param {*} data The information to be displayed.
64+
* @memberof NotificationService
65+
*/
66+
public notifyInfo(data: any) {
67+
this.show(this.formatData(data), LogLevel.Info);
68+
}
69+
70+
/**
71+
* Shows the notification.
72+
*
73+
* @protected
74+
* @param {*} formattedData The formatted data.
75+
* @param {LogLevel} severity The severity.
76+
* @memberof NotificationService
77+
*/
78+
protected show(formattedData: any, severity: LogLevel) {
79+
this.logger.log(severity, null, formattedData);
80+
}
81+
82+
/**
83+
* Formats the data. By default it returns a formatted string.
84+
*
85+
* @protected
86+
* @param {*} data The information to be formatted.
87+
* @returns {string}
88+
* @memberof NotificationService
89+
*/
90+
protected formatData(data: any): any {
91+
if (!data) {
92+
return 'Unknown error. Please check the client and server logs for more information.';
93+
}
94+
95+
if (data.message && data.url) {
96+
return `${data.message} (url: ${data.url}).`;
97+
}
98+
99+
if (typeof (data) === 'object') {
100+
if (data.error) {
101+
// this is the case of Kendo data objects.
102+
if (typeof data.error === 'object') {
103+
if (data.error.responseStatus) {
104+
return data.error.responseStatus.message;
105+
}
106+
}
107+
return data.error;
108+
}
109+
110+
if (data.message) {
111+
return data.message;
112+
}
113+
}
114+
115+
return data;
116+
}
117+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*
2+
* Public API Surface of ui
3+
*/
4+
5+
export { NotificationService } from './lib/notificationService';

0 commit comments

Comments
 (0)