mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
#1407 Domain Printer und Modal Printer
This commit is contained in:
80
angular.json
80
angular.json
@@ -1896,6 +1896,86 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@domain/printer": {
|
||||
"projectType": "library",
|
||||
"root": "apps/domain/printer",
|
||||
"sourceRoot": "apps/domain/printer/src",
|
||||
"prefix": "lib",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:ng-packagr",
|
||||
"options": {
|
||||
"tsConfig": "apps/domain/printer/tsconfig.lib.json",
|
||||
"project": "apps/domain/printer/ng-package.json"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"tsConfig": "apps/domain/printer/tsconfig.lib.prod.json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"builder": "@angular-devkit/build-angular:karma",
|
||||
"options": {
|
||||
"main": "apps/domain/printer/src/test.ts",
|
||||
"tsConfig": "apps/domain/printer/tsconfig.spec.json",
|
||||
"karmaConfig": "apps/domain/printer/karma.conf.js"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": [
|
||||
"apps/domain/printer/tsconfig.lib.json",
|
||||
"apps/domain/printer/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": [
|
||||
"**/node_modules/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@modal/printer": {
|
||||
"projectType": "library",
|
||||
"root": "apps/modal/printer",
|
||||
"sourceRoot": "apps/modal/printer/src",
|
||||
"prefix": "modal",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:ng-packagr",
|
||||
"options": {
|
||||
"tsConfig": "apps/modal/printer/tsconfig.lib.json",
|
||||
"project": "apps/modal/printer/ng-package.json"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"tsConfig": "apps/modal/printer/tsconfig.lib.prod.json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"builder": "@angular-devkit/build-angular:karma",
|
||||
"options": {
|
||||
"main": "apps/modal/printer/src/test.ts",
|
||||
"tsConfig": "apps/modal/printer/tsconfig.spec.json",
|
||||
"karmaConfig": "apps/modal/printer/karma.conf.js"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": [
|
||||
"apps/modal/printer/tsconfig.lib.json",
|
||||
"apps/modal/printer/tsconfig.spec.json"
|
||||
],
|
||||
"exclude": [
|
||||
"**/node_modules/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultProject": "sales"
|
||||
|
||||
25
apps/domain/printer/README.md
Normal file
25
apps/domain/printer/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Printer
|
||||
|
||||
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 printer` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project printer`.
|
||||
|
||||
> Note: Don't forget to add `--project printer` or else it will be added to the default project in your `angular.json` file.
|
||||
|
||||
## Build
|
||||
|
||||
Run `ng build printer` to build the project. The build artifacts will be stored in the `dist/` directory.
|
||||
|
||||
## Publishing
|
||||
|
||||
After building your library with `ng build printer`, go to the dist folder `cd dist/printer` and run `npm publish`.
|
||||
|
||||
## Running unit tests
|
||||
|
||||
Run `ng test printer` 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).
|
||||
32
apps/domain/printer/karma.conf.js
Normal file
32
apps/domain/printer/karma.conf.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// 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/domain/printer'),
|
||||
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,
|
||||
});
|
||||
};
|
||||
7
apps/domain/printer/ng-package.json
Normal file
7
apps/domain/printer/ng-package.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
|
||||
"dest": "../../../dist/domain/printer",
|
||||
"lib": {
|
||||
"entryFile": "src/public-api.ts"
|
||||
}
|
||||
}
|
||||
11
apps/domain/printer/package.json
Normal file
11
apps/domain/printer/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "@domain/printer",
|
||||
"version": "0.0.1",
|
||||
"peerDependencies": {
|
||||
"@angular/common": "^10.1.2",
|
||||
"@angular/core": "^10.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": "^2.0.0"
|
||||
}
|
||||
}
|
||||
6
apps/domain/printer/src/lib/defs/printer.model.ts
Normal file
6
apps/domain/printer/src/lib/defs/printer.model.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export interface Printer {
|
||||
key: string;
|
||||
value: string;
|
||||
description: string;
|
||||
selected: boolean;
|
||||
}
|
||||
8
apps/domain/printer/src/lib/printer.module.ts
Normal file
8
apps/domain/printer/src/lib/printer.module.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
imports: [],
|
||||
exports: [],
|
||||
})
|
||||
export class PrinterModule {}
|
||||
150
apps/domain/printer/src/lib/printer.service.ts
Normal file
150
apps/domain/printer/src/lib/printer.service.ts
Normal file
@@ -0,0 +1,150 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
CatalogPrintService,
|
||||
CheckoutPrintService,
|
||||
ItemDTO,
|
||||
OMSPrintService,
|
||||
PrintRequestOfIEnumerableOfItemDTO,
|
||||
PrintRequestOfIEnumerableOfLong,
|
||||
PrintService,
|
||||
ResponseArgs,
|
||||
} from '@swagger/print';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { catchError, filter, map, switchMap, timeout } from 'rxjs/operators';
|
||||
import { Printer } from './defs/printer.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class PrinterService {
|
||||
constructor(
|
||||
private printService: PrintService,
|
||||
private oMSPrintService: OMSPrintService,
|
||||
private catalogPrintService: CatalogPrintService,
|
||||
private checkoutPrintService: CheckoutPrintService,
|
||||
private http: HttpClient
|
||||
) {}
|
||||
|
||||
getAvailablePrinters(): Observable<Printer[] | { error: string }> {
|
||||
return this.printService.PrintPrinters().pipe(
|
||||
timeout(20000),
|
||||
catchError((error) => of({ error })),
|
||||
map((response: any) => {
|
||||
if (response.error && response.error.status === 503) {
|
||||
return {
|
||||
error: response.message ? response.message : 'Das Backend ist derzeit nicht erreichbar',
|
||||
};
|
||||
}
|
||||
if (response.error && response.error.name === 'TimeoutError') {
|
||||
return { error: response.message ? response.message : 'API Timeout' };
|
||||
}
|
||||
if (response.error) {
|
||||
return {
|
||||
error: response.message ? response.message : response.error.message ? response.error.message : 'Ein Fehler ist aufgetreten',
|
||||
};
|
||||
}
|
||||
|
||||
return response.result.map(
|
||||
(t) =>
|
||||
<Printer>{
|
||||
key: t.key,
|
||||
value: t.value,
|
||||
description: t.description,
|
||||
selected: t.selected,
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
getAvailablePrintersDev() {
|
||||
return this.http.get('http://127.0.0.1:5000/api/printers').pipe(
|
||||
timeout(20000),
|
||||
catchError((error) => {
|
||||
return of({ error });
|
||||
}),
|
||||
map((response: any) => {
|
||||
if (response.error && response.error.status === 503) {
|
||||
return {
|
||||
error: response.message ? response.message : 'Das Backend ist derzeit nicht erreichbar',
|
||||
};
|
||||
}
|
||||
if (response.error && response.error.name === 'TimeoutError') {
|
||||
return { error: response.message ? response.message : 'API Timeout' };
|
||||
}
|
||||
if (response.error) {
|
||||
return {
|
||||
error: response.message ? response.message : response.error.message ? response.error.message : 'Ein Fehler ist aufgetreten',
|
||||
};
|
||||
}
|
||||
return response.result.map(
|
||||
(t) =>
|
||||
<Printer>{
|
||||
key: t.key,
|
||||
value: t.value,
|
||||
description: t.description,
|
||||
selected: t.selected,
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
async printOrder(orderIds: number[], printer: string): Promise<ResponseArgs> {
|
||||
const params = <any>{
|
||||
printer: printer,
|
||||
data: orderIds,
|
||||
};
|
||||
const response = await this.oMSPrintService.OMSPrintAbholscheinById(params).pipe(timeout(20000)).toPromise();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async printProduct(item: ItemDTO, printer: string): Promise<ResponseArgs> {
|
||||
const params = <PrintRequestOfIEnumerableOfItemDTO>{
|
||||
printer: printer,
|
||||
data: [item],
|
||||
};
|
||||
const response = await this.catalogPrintService.CatalogPrintArtikelDetail(params).pipe(timeout(20000)).toPromise();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async printCart(cartId: number, printer: string): Promise<ResponseArgs> {
|
||||
const params = <any>{
|
||||
printer: printer,
|
||||
data: cartId,
|
||||
};
|
||||
const response = await this.checkoutPrintService.CheckoutPrintWarenkorbById(params).pipe(timeout(20000)).toPromise();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async printGoodsInLabel(subsetItemIds: number[]): Promise<ResponseArgs> {
|
||||
const response = await this.getAvailablePrinters()
|
||||
.pipe(
|
||||
filter((data) => Array.isArray(data)),
|
||||
switchMap((printers: Printer[]) => {
|
||||
if (printers && printers.length > 0) {
|
||||
const printer = printers.find((p) => p.selected);
|
||||
if (printer) {
|
||||
const params = <PrintRequestOfIEnumerableOfLong>{
|
||||
data: subsetItemIds,
|
||||
printer: printer.key,
|
||||
};
|
||||
return this.oMSPrintService.OMSPrintAbholfachetikett(params);
|
||||
} else {
|
||||
return of(undefined);
|
||||
}
|
||||
} else {
|
||||
return of(undefined);
|
||||
}
|
||||
}),
|
||||
timeout(20000)
|
||||
)
|
||||
.toPromise();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
6
apps/domain/printer/src/public-api.ts
Normal file
6
apps/domain/printer/src/public-api.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
/*
|
||||
* Public API Surface of printer
|
||||
*/
|
||||
export * from './lib/defs/printer.model';
|
||||
export * from './lib/printer.module';
|
||||
export * from './lib/printer.service';
|
||||
24
apps/domain/printer/src/test.ts
Normal file
24
apps/domain/printer/src/test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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);
|
||||
25
apps/domain/printer/tsconfig.lib.json
Normal file
25
apps/domain/printer/tsconfig.lib.json
Normal 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"
|
||||
]
|
||||
}
|
||||
10
apps/domain/printer/tsconfig.lib.prod.json
Normal file
10
apps/domain/printer/tsconfig.lib.prod.json
Normal 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
|
||||
}
|
||||
}
|
||||
17
apps/domain/printer/tsconfig.spec.json
Normal file
17
apps/domain/printer/tsconfig.spec.json
Normal 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"
|
||||
]
|
||||
}
|
||||
17
apps/domain/printer/tslint.json
Normal file
17
apps/domain/printer/tslint.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "../../../tslint.json",
|
||||
"rules": {
|
||||
"directive-selector": [
|
||||
true,
|
||||
"attribute",
|
||||
"lib",
|
||||
"camelCase"
|
||||
],
|
||||
"component-selector": [
|
||||
true,
|
||||
"element",
|
||||
"lib",
|
||||
"kebab-case"
|
||||
]
|
||||
}
|
||||
}
|
||||
25
apps/modal/printer/README.md
Normal file
25
apps/modal/printer/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Printer
|
||||
|
||||
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 printer` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project printer`.
|
||||
|
||||
> Note: Don't forget to add `--project printer` or else it will be added to the default project in your `angular.json` file.
|
||||
|
||||
## Build
|
||||
|
||||
Run `ng build printer` to build the project. The build artifacts will be stored in the `dist/` directory.
|
||||
|
||||
## Publishing
|
||||
|
||||
After building your library with `ng build printer`, go to the dist folder `cd dist/printer` and run `npm publish`.
|
||||
|
||||
## Running unit tests
|
||||
|
||||
Run `ng test printer` 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).
|
||||
32
apps/modal/printer/karma.conf.js
Normal file
32
apps/modal/printer/karma.conf.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// 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/modal/printer'),
|
||||
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,
|
||||
});
|
||||
};
|
||||
7
apps/modal/printer/ng-package.json
Normal file
7
apps/modal/printer/ng-package.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
|
||||
"dest": "../../../dist/modal/printer",
|
||||
"lib": {
|
||||
"entryFile": "src/public-api.ts"
|
||||
}
|
||||
}
|
||||
11
apps/modal/printer/package.json
Normal file
11
apps/modal/printer/package.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "@modal/printer",
|
||||
"version": "0.0.1",
|
||||
"peerDependencies": {
|
||||
"@angular/common": "^10.1.2",
|
||||
"@angular/core": "^10.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": "^2.0.0"
|
||||
}
|
||||
}
|
||||
22
apps/modal/printer/src/lib/modal-print-cart.component.ts
Normal file
22
apps/modal/printer/src/lib/modal-print-cart.component.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||
import { PrinterComponent } from './modal-printer.component';
|
||||
|
||||
@Component({
|
||||
selector: 'modal-print-cart',
|
||||
templateUrl: 'modal-printer.component.html',
|
||||
styleUrls: ['modal-printer.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class PrintCartComponent extends PrinterComponent {
|
||||
async print() {
|
||||
this.loaded = false;
|
||||
const printResponse = await this.printerService.printCart(this.modalRef.data, this.selectedPrinterValue);
|
||||
|
||||
if (!printResponse.error) {
|
||||
this.modalRef.close();
|
||||
} else {
|
||||
this.setError(printResponse.message);
|
||||
}
|
||||
this.loaded = true;
|
||||
}
|
||||
}
|
||||
22
apps/modal/printer/src/lib/modal-print-order.component.ts
Normal file
22
apps/modal/printer/src/lib/modal-print-order.component.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||
import { PrinterComponent } from './modal-printer.component';
|
||||
|
||||
@Component({
|
||||
selector: 'modal-print-order',
|
||||
templateUrl: 'modal-printer.component.html',
|
||||
styleUrls: ['modal-printer.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class PrintOrderComponent extends PrinterComponent {
|
||||
async print() {
|
||||
this.loaded = false;
|
||||
const printResponse = await this.printerService.printOrder(this.modalRef.data, this.selectedPrinterValue);
|
||||
|
||||
if (!printResponse.error) {
|
||||
this.modalRef.close();
|
||||
} else {
|
||||
this.setError(printResponse.message);
|
||||
}
|
||||
this.loaded = true;
|
||||
}
|
||||
}
|
||||
22
apps/modal/printer/src/lib/modal-print-product.component.ts
Normal file
22
apps/modal/printer/src/lib/modal-print-product.component.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||
import { PrinterComponent } from './modal-printer.component';
|
||||
|
||||
@Component({
|
||||
selector: 'modal-print-product',
|
||||
templateUrl: 'modal-printer.component.html',
|
||||
styleUrls: ['modal-printer.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class PrintProductComponent extends PrinterComponent {
|
||||
async print() {
|
||||
this.loaded = false;
|
||||
const printResponse = await this.printerService.printProduct(this.modalRef.data, this.selectedPrinterValue);
|
||||
|
||||
if (!printResponse.error) {
|
||||
this.modalRef.close();
|
||||
} else {
|
||||
this.setError(printResponse.message);
|
||||
}
|
||||
this.loaded = true;
|
||||
}
|
||||
}
|
||||
31
apps/modal/printer/src/lib/modal-printer.component.html
Normal file
31
apps/modal/printer/src/lib/modal-printer.component.html
Normal file
@@ -0,0 +1,31 @@
|
||||
<div class="wrapper">
|
||||
<div class="actions">
|
||||
<button class="close-btn" (click)="modalRef.close()">
|
||||
<ui-icon icon="close" size="21px"></ui-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="header">
|
||||
<h1>Wählen Sie einen Drucker aus</h1>
|
||||
|
||||
<span *ngIf="error" class="error-message">{{ errorMessage }}</span>
|
||||
</div>
|
||||
|
||||
<ng-container *ngIf="!error">
|
||||
<div class="body">
|
||||
<ui-spinner [show]="!loaded">
|
||||
<ui-select class="select" [(ngModel)]="selectedPrinterValue">
|
||||
<ui-select-option *ngFor="let printer of printers" [label]="printer.text" [value]="printer.key"></ui-select-option>
|
||||
</ui-select>
|
||||
</ui-spinner>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<button class="print-btn" (click)="print()" [disabled]="!loaded">
|
||||
<ui-spinner [show]="!loaded">
|
||||
Drucken
|
||||
</ui-spinner>
|
||||
</button>
|
||||
</div>
|
||||
</ng-container>
|
||||
</div>
|
||||
35
apps/modal/printer/src/lib/modal-printer.component.scss
Normal file
35
apps/modal/printer/src/lib/modal-printer.component.scss
Normal file
@@ -0,0 +1,35 @@
|
||||
.actions {
|
||||
@apply flex flex-row justify-end;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
@apply bg-transparent border-none text-ucla-blue;
|
||||
}
|
||||
|
||||
.header {
|
||||
@apply text-center;
|
||||
|
||||
h1 {
|
||||
@apply font-bold text-center text-xl;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
@apply text-center text-regular font-semibold text-brand;
|
||||
}
|
||||
}
|
||||
|
||||
.body {
|
||||
@apply mt-px-30 flex justify-center;
|
||||
}
|
||||
|
||||
.footer {
|
||||
@apply mt-px-35 text-center;
|
||||
|
||||
.print-btn {
|
||||
@apply border-none outline-none bg-brand text-white font-bold text-cta-l px-px-25 py-px-15 rounded-full my-8;
|
||||
|
||||
&:disabled {
|
||||
@apply bg-inactive-branch;
|
||||
}
|
||||
}
|
||||
}
|
||||
73
apps/modal/printer/src/lib/modal-printer.component.ts
Normal file
73
apps/modal/printer/src/lib/modal-printer.component.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { Printer, PrinterService } from '@domain/printer';
|
||||
import { UiModalRef } from '@ui/modal';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'modal-print-cart',
|
||||
templateUrl: 'modal-printer.component.html',
|
||||
styleUrls: ['modal-printer.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class PrinterComponent implements OnInit, OnDestroy {
|
||||
protected selectedPrinterValue: string;
|
||||
printers: { key: string; text: string; selected: boolean }[] = [];
|
||||
printerSubscription: Subscription;
|
||||
|
||||
error = false;
|
||||
errorMessage = 'Der Druckauftrag konnte nicht ausgeführt werden.';
|
||||
loaded = false;
|
||||
|
||||
constructor(protected printerService: PrinterService, public modalRef: UiModalRef, private cdr: ChangeDetectorRef) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.loadPrinters();
|
||||
}
|
||||
|
||||
loadPrinters() {
|
||||
this.loaded = false;
|
||||
this.error = false;
|
||||
|
||||
this.printerSubscription = this.printerService.getAvailablePrinters().subscribe((response) => {
|
||||
if ((response as { error: string }).error) {
|
||||
const errorResponse = response as { error: string };
|
||||
this.error = true;
|
||||
this.errorMessage = errorResponse.error;
|
||||
return;
|
||||
}
|
||||
|
||||
const result = response as Printer[];
|
||||
this.printers = result.map((t) => {
|
||||
return { key: t.key, text: t.description, selected: t.selected };
|
||||
});
|
||||
const selectedPrinter = this.printers.find((printer) => printer.selected);
|
||||
this.selectedPrinterValue = selectedPrinter ? selectedPrinter.key : this.printers[0].key;
|
||||
|
||||
this.error = false;
|
||||
this.loaded = true;
|
||||
|
||||
if (!this.selectedPrinterValue) {
|
||||
this.error = true;
|
||||
this.errorMessage = 'Keine Drucker verfügbar.';
|
||||
}
|
||||
this.cdr.markForCheck();
|
||||
});
|
||||
}
|
||||
|
||||
setError(errorMessage?: string) {
|
||||
this.error = true;
|
||||
if (!!errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
}
|
||||
|
||||
print() {
|
||||
this.modalRef.close(this.selectedPrinterValue);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (this.printerSubscription) {
|
||||
this.printerSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
18
apps/modal/printer/src/lib/modal-printer.module.ts
Normal file
18
apps/modal/printer/src/lib/modal-printer.module.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { UiIconModule } from '@ui/icon';
|
||||
import { UiModalModule } from '@ui/modal';
|
||||
import { UiSelectModule } from '@ui/select';
|
||||
import { UiSpinnerModule } from 'apps/ui/spinner/src/lib/ui-spinner.module';
|
||||
import { PrintCartComponent } from './modal-print-cart.component';
|
||||
import { PrintOrderComponent } from './modal-print-order.component';
|
||||
import { PrintProductComponent } from './modal-print-product.component';
|
||||
import { PrinterComponent } from './modal-printer.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [PrinterComponent, PrintOrderComponent, PrintCartComponent, PrintProductComponent],
|
||||
imports: [CommonModule, FormsModule, UiModalModule, UiIconModule, UiSelectModule, UiSpinnerModule],
|
||||
exports: [PrinterComponent, PrintOrderComponent, PrintCartComponent, PrintProductComponent],
|
||||
})
|
||||
export class ModalPrinterModule {}
|
||||
9
apps/modal/printer/src/public-api.ts
Normal file
9
apps/modal/printer/src/public-api.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Public API Surface of printer
|
||||
*/
|
||||
|
||||
export * from './lib/modal-printer.module';
|
||||
export * from './lib/modal-printer.component';
|
||||
export * from './lib/modal-print-product.component';
|
||||
export * from './lib/modal-print-cart.component';
|
||||
export * from './lib/modal-print-order.component';
|
||||
24
apps/modal/printer/src/test.ts
Normal file
24
apps/modal/printer/src/test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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);
|
||||
25
apps/modal/printer/tsconfig.lib.json
Normal file
25
apps/modal/printer/tsconfig.lib.json
Normal 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"
|
||||
]
|
||||
}
|
||||
10
apps/modal/printer/tsconfig.lib.prod.json
Normal file
10
apps/modal/printer/tsconfig.lib.prod.json
Normal 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
|
||||
}
|
||||
}
|
||||
17
apps/modal/printer/tsconfig.spec.json
Normal file
17
apps/modal/printer/tsconfig.spec.json
Normal 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"
|
||||
]
|
||||
}
|
||||
17
apps/modal/printer/tslint.json
Normal file
17
apps/modal/printer/tslint.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "../../../tslint.json",
|
||||
"rules": {
|
||||
"directive-selector": [
|
||||
true,
|
||||
"attribute",
|
||||
"modal",
|
||||
"camelCase"
|
||||
],
|
||||
"component-selector": [
|
||||
true,
|
||||
"element",
|
||||
"modal",
|
||||
"kebab-case"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
<ng-container *ngIf="shoppingCart$ | async; let shoppingCart">
|
||||
<div class="card stretch">
|
||||
<div class="cta-print-wrapper">
|
||||
<button class="cta-print">Drucken</button>
|
||||
<button class="cta-print" (click)="openPrintModal()">
|
||||
Drucken
|
||||
</button>
|
||||
</div>
|
||||
<h1 class="header">Warenkorb</h1>
|
||||
<h5 class="sub-header">Überprüfen Sie die Details.</h5>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { DomainCheckoutService } from '@domain/checkout';
|
||||
import { SearchService } from '@swagger/cat';
|
||||
import { AvailabilityDTO, DestinationDTO, ShoppingCartItemDTO } from '@swagger/checkout';
|
||||
import { UiModalService } from '@ui/modal';
|
||||
import { PrintCartComponent } from '@modal/printer';
|
||||
import { first, map, shareReplay, switchMap } from 'rxjs/operators';
|
||||
import { SsoService } from 'sso';
|
||||
import { PurchasingOptionsModalComponent, PurchasingOptionsModalData } from '../modals/purchasing-options-modal';
|
||||
@@ -199,6 +200,14 @@ export class CheckoutReviewComponent {
|
||||
});
|
||||
}
|
||||
|
||||
async openPrintModal() {
|
||||
let shoppingCart = await this.shoppingCart$.pipe(first()).toPromise();
|
||||
this.uiModal.open({
|
||||
content: PrintCartComponent,
|
||||
data: shoppingCart.id,
|
||||
});
|
||||
}
|
||||
|
||||
async updateItemQuantity(shoppingCartItem: ShoppingCartItemDTO, quantity: number) {
|
||||
this.showQuantityControlSpinnerItemId = shoppingCartItem.id;
|
||||
const orderType = shoppingCartItem?.features?.orderType;
|
||||
|
||||
@@ -9,6 +9,7 @@ import { ProductImageModule } from 'apps/cdn/product-image/src/public-api';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { UiSpinnerModule } from 'apps/ui/spinner/src/lib/ui-spinner.module';
|
||||
import { ModalPrinterModule } from '@modal/printer';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -20,6 +21,7 @@ import { UiSpinnerModule } from 'apps/ui/spinner/src/lib/ui-spinner.module';
|
||||
ProductImageModule,
|
||||
FormsModule,
|
||||
UiSpinnerModule,
|
||||
ModalPrinterModule,
|
||||
],
|
||||
exports: [CheckoutReviewComponent],
|
||||
declarations: [CheckoutReviewComponent],
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
{{ displayOrder?.buyer | buyerName }}
|
||||
</div>
|
||||
<div class="grow"></div>
|
||||
<button class="cta-print">Drucken</button>
|
||||
<button class="cta-print" (click)="openPrintModal(displayOrder.id)">Drucken</button>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Component, ChangeDetectionStrategy } from '@angular/core';
|
||||
import { DomainCheckoutService } from '@domain/checkout';
|
||||
import { UiModalService } from '@ui/modal';
|
||||
import { PrintOrderComponent } from '@modal/printer';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
@@ -39,5 +41,12 @@ export class CheckoutSummaryComponent {
|
||||
)
|
||||
);
|
||||
|
||||
constructor(private domainCheckoutService: DomainCheckoutService) {}
|
||||
constructor(private domainCheckoutService: DomainCheckoutService, private uiModal: UiModalService) {}
|
||||
|
||||
openPrintModal(id: number) {
|
||||
this.uiModal.open({
|
||||
content: PrintOrderComponent,
|
||||
data: id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@ import { CheckoutSummaryComponent } from './checkout-summary.component';
|
||||
import { UiIconModule } from '@ui/icon';
|
||||
import { PageCheckoutPipeModule } from '../pipes/page-checkout-pipe.module';
|
||||
import { ProductImageModule } from 'apps/cdn/product-image/src/public-api';
|
||||
import { ModalPrinterModule } from '@modal/printer';
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule, UiIconModule, PageCheckoutPipeModule, ProductImageModule],
|
||||
imports: [CommonModule, UiIconModule, PageCheckoutPipeModule, ProductImageModule, ModalPrinterModule],
|
||||
exports: [CheckoutSummaryComponent],
|
||||
declarations: [CheckoutSummaryComponent],
|
||||
})
|
||||
|
||||
386
package-lock.json
generated
386
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -179,6 +179,12 @@
|
||||
],
|
||||
"@ui/spinner": [
|
||||
"apps/ui/spinner/src/public-api.ts"
|
||||
],
|
||||
"@domain/printer": [
|
||||
"apps/domain/printer/src/public-api.ts"
|
||||
],
|
||||
"@modal/printer": [
|
||||
"apps/modal/printer/src/public-api.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user