Merge branch 'feature/customer_pages' of https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend into feature/customer_pages

This commit is contained in:
Lorenz Hilpert
2020-10-02 15:02:40 +02:00
22 changed files with 359 additions and 22 deletions

View File

@@ -1176,6 +1176,46 @@
}
}
}
},
"@core/environment": {
"projectType": "library",
"root": "apps/core/environment",
"sourceRoot": "apps/core/environment/src",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:ng-packagr",
"options": {
"tsConfig": "apps/core/environment/tsconfig.lib.json",
"project": "apps/core/environment/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "apps/core/environment/tsconfig.lib.prod.json"
}
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "apps/core/environment/src/test.ts",
"tsConfig": "apps/core/environment/tsconfig.spec.json",
"karmaConfig": "apps/core/environment/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"apps/core/environment/tsconfig.lib.json",
"apps/core/environment/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "sales"

View File

@@ -0,0 +1,25 @@
# Environment
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 10.1.2.
## Code scaffolding
Run `ng generate component component-name --project environment` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project environment`.
> Note: Don't forget to add `--project environment` or else it will be added to the default project in your `angular.json` file.
## Build
Run `ng build environment` to build the project. The build artifacts will be stored in the `dist/` directory.
## Publishing
After building your library with `ng build environment`, go to the dist folder `cd dist/environment` and run `npm publish`.
## Running unit tests
Run `ng test environment` to execute the unit tests via [Karma](https://karma-runner.github.io).
## Further help
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).

View File

@@ -0,0 +1,35 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma'),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(
__dirname,
'../../../coverage/core/environment'
),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true,
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true,
});
};

View File

@@ -0,0 +1,7 @@
{
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../../dist/core/environment",
"lib": {
"entryFile": "src/public-api.ts"
}
}

View File

@@ -0,0 +1,11 @@
{
"name": "@core/environment",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^10.1.2",
"@angular/core": "^10.1.2"
},
"dependencies": {
"tslib": "^2.0.0"
}
}

View File

@@ -0,0 +1,8 @@
import { NgModule } from '@angular/core';
@NgModule({
declarations: [],
imports: [],
exports: [],
})
export class EnvironmentModule {}

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { EnvironmentService } from './environment.service';
describe('EnvironmentService', () => {
let service: EnvironmentService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(EnvironmentService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,31 @@
import { Injectable } from '@angular/core';
import { fromEvent } from 'rxjs';
import { map, take } from 'rxjs/operators';
@Injectable({
providedIn: 'root',
})
export class EnvironmentService {
constructor() {}
/** Returns whether app is used within native container*/
isNative(): Promise<boolean> {
return fromEvent(window, 'message')
.pipe(
map((evt: MessageEvent) => evt.data),
map((data) => data.status === 'INIT'),
take(1)
)
.toPromise();
}
/** Returns whether current device is mobile phone or tablet */
async isMobile(): Promise<boolean> {
return 'orientation' in window;
}
/** Returns whether current device is desktop */
async isDesktop(): Promise<boolean> {
return !(await this.isMobile());
}
}

View File

@@ -0,0 +1,6 @@
/*
* Public API Surface of environment
*/
export * from './lib/environment.service';
export * from './lib/environment.module';

View File

@@ -0,0 +1,30 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
declare const require: {
context(
path: string,
deep?: boolean,
filter?: RegExp
): {
keys(): string[];
<T>(id: string): T;
};
};
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

View File

@@ -0,0 +1,25 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "../../../out-tsc/lib",
"target": "es2015",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}

View File

@@ -0,0 +1,10 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "./tsconfig.lib.json",
"compilerOptions": {
"declarationMap": false
},
"angularCompilerOptions": {
"enableIvy": false
}
}

View File

@@ -0,0 +1,17 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "../../../out-tsc/spec",
"types": [
"jasmine"
]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}

View File

@@ -0,0 +1,17 @@
{
"extends": "../../../tslint.json",
"rules": {
"directive-selector": [
true,
"attribute",
"lib",
"camelCase"
],
"component-selector": [
true,
"element",
"lib",
"kebab-case"
]
}
}

View File

@@ -38,16 +38,27 @@ export class NativeContainerService {
};
this.sendMessage(scanRequest);
return this.windowMessages.asObservable().pipe(map((message) => message as { status: string; data?: any }));
return this.windowMessages
.asObservable()
.pipe(map((message) => message as { status: string; data?: any }));
}
public sendMessage(message: any) {
this.windowRef.nativeWindow.postMessage({ status: 'IN_PROGRESS', data: 'Scan Started' }, '*');
this.windowRef.nativeWindow.postMessage(
{ status: 'IN_PROGRESS', data: 'Scan Started' },
'*'
);
if (this.isUiWebview()) {
(this.windowRef.nativeWindow as any).webkit.messageHandlers.scanRequest.postMessage(message);
(this.windowRef
.nativeWindow as any).webkit.messageHandlers.scanRequest.postMessage(
message
);
} else {
this.windowRef.nativeWindow.postMessage({ status: 'ERROR', data: 'Not a WebView' }, '*');
this.windowRef.nativeWindow.postMessage(
{ status: 'ERROR', data: 'Not a WebView' },
'*'
);
this.windowRef.nativeWindow.postMessage(message, '*');
}
}
@@ -71,18 +82,26 @@ export class NativeContainerService {
private defineWindowCallback() {
if (this.windowRef.nativeWindow['scanResults'] === undefined) {
this.windowRef.nativeWindow['scanResults'] = (result) => window.postMessage(result, '*');
this.windowRef.nativeWindow['scanResults'] = (result) =>
window.postMessage(result, '*');
}
if (this.windowRef.nativeWindow['isRunningNative'] === undefined) {
this.windowRef.nativeWindow['isRunningNative'] = (_) => window.postMessage({ status: 'INIT', data: 'Is a WebView' }, '*');
this.windowRef.nativeWindow['isRunningNative'] = (_) =>
window.postMessage({ status: 'INIT', data: 'Is a WebView' }, '*');
}
// Try sending ping request, to invoke the containers isRunningNative event
try {
(this.windowRef.nativeWindow as any).webkit.messageHandlers.scanRequest.postMessage('PING');
(this.windowRef
.nativeWindow as any).webkit.messageHandlers.scanRequest.postMessage(
'PING'
);
} catch (error) {
this.windowRef.nativeWindow.postMessage({ status: 'ERROR', data: 'Not a WebView' }, '*');
this.windowRef.nativeWindow.postMessage(
{ status: 'ERROR', data: 'Not a WebView' },
'*'
);
this.windowRef.nativeWindow.postMessage('PING', '*');
}
}

View File

@@ -170,6 +170,8 @@ export abstract class CustomerSearch implements OnInit, OnDestroy {
}
}
scan() {}
navigateToDetails(customerId: number) {
this.router.navigate(['customer', 'search', customerId, 'details']);
}

View File

@@ -32,9 +32,10 @@
<ui-icon icon="close" size="22px"></ui-icon>
</button>
<button
[class.scan]="isMobile && !input?.value?.length"
type="submit"
uiSearchboxSearchButton
(click)="search.search()"
(click)="startSearch()"
[disabled]="searchState === 'fetching'"
>
<ui-icon
@@ -43,11 +44,19 @@
icon="spinner"
size="32px"
></ui-icon>
<ui-icon
*ngIf="searchState !== 'fetching'"
icon="search"
size="24px"
></ui-icon>
<ng-container *ngIf="searchState !== 'fetching'">
<ui-icon
*ngIf="isMobile && !input?.value?.length"
icon="scan"
size="32px"
></ui-icon>
<ui-icon
*ngIf="!isMobile || !!input?.value?.length"
icon="search"
size="24px"
></ui-icon>
</ng-container>
</button>
<ui-searchbox-autocomplete
uiClickOutside

View File

@@ -33,8 +33,15 @@ ui-searchbox {
}
[uiSearchboxSearchButton] {
@apply bg-white text-brand pr-px-25;
@apply bg-white text-brand;
&:not(.scan) {
@apply pr-px-25;
}
&.scan {
@apply bg-brand text-white;
}
.spin {
@apply bg-white text-ucla-blue;
}

View File

@@ -7,7 +7,7 @@ import {
ViewChild,
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { EnvironmentService } from '@core/environment';
import { UiSearchboxAutocompleteComponent } from '@ui/searchbox';
import { Subject } from 'rxjs';
import { delay, takeUntil, tap, withLatestFrom } from 'rxjs/operators';
@@ -22,6 +22,8 @@ import { CustomerSearch } from '../customer-search.service';
export class CustomerSearchMainComponent implements OnInit, OnDestroy {
private destroy$ = new Subject();
protected isMobile: boolean;
@ViewChild(UiSearchboxAutocompleteComponent, {
read: UiSearchboxAutocompleteComponent,
static: false,
@@ -31,11 +33,13 @@ export class CustomerSearchMainComponent implements OnInit, OnDestroy {
constructor(
public search: CustomerSearch,
public cdr: ChangeDetectorRef,
private activatedRoute: ActivatedRoute
private activatedRoute: ActivatedRoute,
public environmentService: EnvironmentService
) {}
ngOnInit() {
this.initAutocomplete();
this.detectDevice();
this.search.parseQueryParams(this.activatedRoute);
this.subscribeToSearchResult();
@@ -66,6 +70,10 @@ export class CustomerSearchMainComponent implements OnInit, OnDestroy {
});
}
async detectDevice() {
this.isMobile = await this.environmentService.isMobile();
}
subscribeToSearchResult() {
this.search.searchResult$
.pipe(takeUntil(this.destroy$), withLatestFrom(this.search.searchState$))
@@ -79,4 +87,16 @@ export class CustomerSearchMainComponent implements OnInit, OnDestroy {
}
});
}
startSearch() {
if (
!this.search.queryControl.value ||
(!this.search.queryControl.value.length &&
this.environmentService.isMobile())
) {
return this.search.scan();
}
return this.search.search();
}
}

View File

@@ -6,7 +6,6 @@ import {
OnDestroy,
OnInit,
Output,
Type,
} from '@angular/core';
@Directive({ selector: '[uiIsInViewport]' })

8
package-lock.json generated
View File

@@ -1554,7 +1554,7 @@
},
"source-map": {
"version": "0.5.7",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel/npm/registry/source-map/-/source-map-0.5.7.tgz",
"integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=",
"dev": true
}
@@ -7869,7 +7869,7 @@
},
"array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel/npm/registry/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=",
"dev": true
},
@@ -16330,7 +16330,7 @@
"dependencies": {
"jsesc": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel/npm/registry/jsesc/-/jsesc-0.5.0.tgz",
"integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=",
"dev": true
}
@@ -17129,7 +17129,7 @@
"dependencies": {
"extend-shallow": {
"version": "2.0.1",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel@Local/npm/registry/extend-shallow/-/extend-shallow-2.0.1.tgz",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel/npm/registry/extend-shallow/-/extend-shallow-2.0.1.tgz",
"integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=",
"dev": true,
"requires": {

View File

@@ -124,6 +124,9 @@
],
"@ui/common": [
"apps/ui/common/src/public-api.ts"
],
"@core/environment": [
"apps/core/environment/src/public-api.ts"
]
}
}