[![CircleCI](https://circleci.risk.svc.dbgcloud.io/gh/dev/DAVe-UI-Common.svg?style=shield)](https://circleci.risk.svc.dbgcloud.io/gh/dev/DAVe-UI-Common)
[![Branches](https://github.deutsche-boerse.de/pages/dev/DAVe-Reports/branches.svg)](https://github.deutsche-boerse.de/pages/dev/DAVe-Reports/DAVe-UI-Common)
[![Coverage](https://github.deutsche-boerse.de/pages/dev/DAVe-Reports/coverage.svg)](https://github.deutsche-boerse.de/pages/dev/DAVe-Reports/DAVe-UI-Common/master/coverage)
[![Coverage](https://github.deutsche-boerse.de/pages/dev/DAVe-Reports/karma.svg)](https://github.deutsche-boerse.de/pages/dev/DAVe-Reports/DAVe-UI-Common/master/karma)

# DAVe-UI-Common (Angular 5 and @angular/material based library for DAVe)

Used by:
 - [dev/DAVe-UI](https://github.deutsche-boerse.de/dev/DAVe-UI)
 - [dev/DAVe-MarginEstimator-UI](https://github.deutsche-boerse.de/dev/DAVe-MarginEstimator-UI)

## Browser support (tested via [BrowserStack](https://www.browserstack.com))
| ![Chrome](https://cdn1.iconfinder.com/data/icons/google_jfk_icons_by_carlosjj/32/chrome.png) Chrome | ![Firefox](https://cdn2.iconfinder.com/data/icons/humano2/32x32/apps/firefox-icon.png) Firefox | ![Edge](https://cdn4.iconfinder.com/data/icons/picons-social/57/56-edge-2-32.png) Edge | ![IE](https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/internet_explorer-32.png) IE | ![Safari](https://cdn1.iconfinder.com/data/icons/logotypes/32/safari-32.png) Safari | ![iOS](https://cdn1.iconfinder.com/data/icons/system-shade-circles/512/iOS-32.png) iOS |
|:------:|:-------:|:----:|:------:|:------:|:-------:|
| Latest |  Latest |  16  |   11   |   11   |  9.1+\* |
|  50    |   50    |  15  |  10\*  |   10   |         |
|        |         |  14  |        |   9.1  |         |

\* In IE 10 and iOS the application is working, but with layout issues. 

## Packages

To use in your application add the following packages into your app:
```
@dbg-riskit/dave-ui-auth - JWT based auth module 
@dbg-riskit/dave-ui-charts - Charts based on GoogleCharts
@dbg-riskit/dave-ui-common - Common code 
@dbg-riskit/dave-ui-datatable - Data table module
@dbg-riskit/dave-ui-devkit - Angular and Grunt build tools
@dbg-riskit/dave-ui-dbg-layout - Layout that contains all fonts and logotypes (not available in public NPM registry)
@dbg-riskit/dave-ui-dummy-layout - Layout without fonts and logotypes
@dbg-riskit/dave-ui-error - Errors handling
@dbg-riskit/dave-ui-file - Components for file upload/download
@dbg-riskit/dave-ui-http - HTTP service implementation
@dbg-riskit/dave-ui-logging - Logging service
@dbg-riskit/dave-ui-login - Login components
@dbg-riskit/dave-ui-testing - Testing utilities
@dbg-riskit/dave-ui-view - Common view components
```

For best compatibility you should always bundle also:
``` 
core-js - ES 6 shim (Required for older browsers)
file-saver - Shim for cross-browser download support (Required to allow download)
hammerjs - Used by @angular/material for better UX
web-animations-js - Unified API for cross-browser animations
```

## Usage

Tokens to be provided by application:
```
// For all other modules:
// -------------------------------------
// Date format string (eg. 'dd. MM. yyyy HH:mm:ss')
{
    provide : DATE_FORMAT,
    useValue: 'dd/MM/yyyy HH:mm'
}
// -------------------------------------
```

## Prerequisites (For the first time only)
 
 - Install [npm@5](http://blog.npmjs.org/post/85484771375/how-to-install-npm) first.
 - If you already have NPM update to latest version using `npm i -g npm@5`. Use `sudo` if necessary.
 - You may need to setup http(s) proxy using:
      - `npm config set proxy http://proxy.company.com:8080`
      - `npm config set https-proxy http://proxy.company.com:8080`
 - Run `npm i` to download necessary packages.
 - Run commands in the following section.

## Before each build
To ensure you have always up-to-date dependecies run following commands:

 - Install Grunt CLI using `npm i -g grunt-cli`. Use `sudo` if necessary. 
 - Run `npm up` to update already downloaded packages.

## Build distribution packages

Build all packages using:
```bash
./.circleci/pack.sh
``` 
This will generate multiple `.tgz` packages in `dist` folder that contain all files needed for distribution.

You can (and should) test the packages in your application using:
```bash
npm i <path to DAVe-UI-Common>/dist/dbg-riskit-dave-ui-*.tgz
```

## Publish into NPM repositories

We deploy into private and public NPM repositories. In private we store files that are not supposed to be distributed 
like Eurex and DBG logo, etc.

First set following properties in your environment:
```bash
# Our ptrivate registry
export NPM_PRIVATE_AUTH_URL=https://cmqaart.deutsche-boerse.de/artifactory/api/npm/auth
export NPM_PRIVATE_PASSWORD=...
export NPM_PRIVATE_REGISTRY_URL=https://cmqaart.deutsche-boerse.de/artifactory/api/npm/npm-mdh-dev/
export NPM_PRIVATE_USER_NAME=...

# Token for public NPM registry
export NPM_PUBLIC_TOKEN=...
```

Run:
```bash
npm version patch #(or npm version minor/ npm version major)
grunt dist
./.circleci/publish.sh
```
This will increment the package version, will do a commit into Git and will publish the package into NPM registry.
You have to do a push afterwards:
```bash
git push
```

## Executing tests
To execute all test suites locally you can run one of the following commands:
 - `grunt test` - To run Karma tests in locally installed IE, Chrome, Safari and Firefox
 - `grunt testIE` - To run Karma tests in locally installed IE
 - `grunt testChrome` - To run Karma tests in locally installed Chrome
 - `grunt testFirefox` - To run Karma tests in locally installed Firefox
 - `grunt testSafari` - To run Karma tests in locally installed Safari
 
To execute Karma runner in debug mode use one of the following commands:
```bash
grunt testDebug
grunt testIEDebug
grunt testChromeDebug
grunt testFirefoxDebug
grunt testSafariDebug
```

You can run also tests using [BrowserStack](https://www.browserstack.com) cloud provider. To run these tests you need
to define following environment variables first:
```bash
export BROWSER_STACK_USERNAME=...
export BROWSER_STACK_ACCESS_KEY=...
```
Then you can run:
```bash
grunt testBrowserStack
```

If you are located behind a company proxy you will need to export also `HTTP_PROXY` variable.

Then run `grunt testBrowserStackProxy` instead.

There are also tasks to run BrowserStack based tests only for a selected browser:
```bash
# BrowserStack test tasks
grunt testBrowserStackChrome
grunt testBrowserStackFirefox
grunt testBrowserStackEdge
grunt testBrowserStackIE
grunt testBrowserStackSafari
grunt testBrowserStackIOS

# BrowserStack (behind proxy) test tasks
grunt testBrowserStackProxyChrome
grunt testBrowserStackProxyFirefox
grunt testBrowserStackProxyEdge
grunt testBrowserStackProxyIE
grunt testBrowserStackProxySafari
grunt testBrowserStackProxyIOS

# BrowserStack test tasks (in debug mode)
grunt testBrowserStackChromeDebug
grunt testBrowserStackFirefoxDebug
grunt testBrowserStackEdgeDebug
grunt testBrowserStackIEDebug
grunt testBrowserStackSafariDebug
grunt testBrowserStackIOSDebug

# BrowserStack (behind proxy) test tasks (in debug mode)
grunt testBrowserStackProxyChromeDebug
grunt testBrowserStackProxyFirefoxDebug
grunt testBrowserStackProxyEdgeDebug
grunt testBrowserStackProxyIEDebug
grunt testBrowserStackProxySafariDebug
grunt testBrowserStackProxyIOSDebug
```
