#755 Basis-Layout für Kundendetails

This commit is contained in:
Lorenz Hilpert
2020-12-08 14:25:27 +01:00
parent edd79e055a
commit a2914f3ccd
41 changed files with 657 additions and 317 deletions

View File

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

View File

@@ -48,7 +48,7 @@
<button class="button-add-address">Hinzufügen</button>
</div>
<ui-inline-input [label]="payerToAddressString(payer)" *ngFor="let payer of customer.payers">
<!-- <ui-inline-input [label]="payerToAddressString(payer)" *ngFor="let payer of customer.payers">
<input uiInput name="payer" type="radio" />
</ui-inline-input>
@@ -59,7 +59,7 @@
<ui-inline-input [label]="shippingAddressToAddressString(address?.data)" *ngFor="let address of customer.shippingAddresses">
<input uiInput name="shipping" type="radio" />
</ui-inline-input>
</ui-inline-input> -->
<div class="card-customer-footer">
<button class="cta-to-cart">

View File

@@ -3,11 +3,10 @@ import { CommonModule } from '@angular/common';
import { CustomerDetailsComponent } from './customer-details.component';
import { UiIconModule } from '@ui/icon';
import { UiInputModule } from '@ui/input';
import { CustomerDetailsFormsModule } from './details-forms/details-forms.module';
@NgModule({
imports: [CommonModule, UiIconModule, UiInputModule, CustomerDetailsFormsModule],
imports: [CommonModule, UiIconModule, CustomerDetailsFormsModule],
exports: [CustomerDetailsComponent],
declarations: [CustomerDetailsComponent],
})

View File

@@ -1,30 +1,48 @@
<ui-inline-input label="Firmenname" (save)="patchOrganisation('name', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.organisation?.name || ''" />
</ui-inline-input>
<ui-inline-input label="Abteilung" (save)="patchOrganisation('department', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.organisation?.department || ''" />
</ui-inline-input>
<ui-inline-input label="USt-ID" (save)="patchOrganisation('vatId', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.organisation?.vatId || ''" />
</ui-inline-input>
<ui-inline-input label="Anrede">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.gender" />
</ui-inline-input>
<ui-inline-input label="Titel" (save)="patchCustomer('title', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.title || ''" />
</ui-inline-input>
<ui-inline-input label="Vorname" (save)="patchCustomer('firstName', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.firstName || ''" />
</ui-inline-input>
<ui-inline-input label="Nachname" (save)="patchCustomer('lastName', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.lastName || ''" />
</ui-inline-input>
<ui-inline-input label="E-Mail" (save)="patchCommunicationDetails('email', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.communicationDetails?.email || ''" />
</ui-inline-input>
<ui-inline-input label="Festnetznummer" (save)="patchCommunicationDetails('phone', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.communicationDetails?.phone || ''" />
</ui-inline-input>
<ui-inline-input label="Mobilnummer" (save)="patchCommunicationDetails('mobile', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.communicationDetails?.mobile || ''" />
</ui-inline-input>
<ng-container
*ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.organisation?.name, label: 'Firmenname' }"
></ng-container>
<ng-container
*ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.organisation?.department, label: 'Abteilung' }"
></ng-container>
<ng-container
*ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.organisation?.vatId, label: 'USt-ID' }"
></ng-container>
<div class="control-field">
<ui-form-control label="Anrede" variant="inline">
<ui-select #genderControl [(value)]="customer.gender" [disabled]="!genderToggle.toggled">
<ui-select-option [value]="2" label="Herr"></ui-select-option>
<ui-select-option [value]="4" label="Frau"></ui-select-option>
</ui-select>
</ui-form-control>
<button uiToggle #genderToggle="uiToggle" (toggledChange)="genderControl.focus()">Ändern</button>
<button *ngIf="genderToggle.toggled" (click)="genderToggle.close()">Speichern</button>
</div>
<ng-container *ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.title, label: 'Titel' }"></ng-container>
<ng-container *ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.lastName, label: 'Nachname' }"></ng-container>
<ng-container *ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.firstName, label: 'Vorname' }"></ng-container>
<ng-container
*ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.communicationDetails?.email, label: 'E-Mail', type: 'mail' }"
></ng-container>
<ng-container
*ngTemplateOutlet="
controlFieldTemplate;
context: { $implicit: customer.communicationDetails?.phone, label: 'Festnetznummer', type: 'tel' }
"
></ng-container>
<ng-container
*ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.communicationDetails?.mobile, label: 'Mobilnummer', type: 'tel' }"
></ng-container>
<ng-template #controlFieldTemplate let-value let-label="label" let-type="type">
<div class="control-field">
<ui-form-control [label]="label" variant="inline">
<input uiInput #inputControl="uiInput" [type]="type || 'text'" [ngModel]="value" [disabled]="!inputToggle.toggled" />
</ui-form-control>
<button uiToggle #inputToggle="uiToggle" (toggledChange)="inputControl.focus()">Ändern</button>
<button *ngIf="inputToggle.toggled" (click)="inputToggle.close()">Speichern</button>
</div>
</ng-template>

View File

@@ -1,33 +1,53 @@
<ui-inline-input label="Anrede">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.gender" />
</ui-inline-input>
<ui-inline-input label="Titel" (save)="patchCustomer('title', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.title || ''" />
</ui-inline-input>
<ui-inline-input label="Vorname" (save)="patchCustomer('firstName', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.firstName || ''" />
</ui-inline-input>
<ui-inline-input label="Nachname" (save)="patchCustomer('lastName', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.lastName || ''" />
</ui-inline-input>
<ui-inline-input label="E-Mail" (save)="patchCommunicationDetails('email', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.communicationDetails?.email || ''" />
</ui-inline-input>
<ui-inline-input label="Festnetznummer" (save)="patchCommunicationDetails('phone', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.communicationDetails?.phone || ''" />
</ui-inline-input>
<ui-inline-input label="Mobilnummer" (save)="patchCommunicationDetails('mobile', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.communicationDetails?.mobile || ''" />
</ui-inline-input>
<ui-inline-input label="Geburtsdatum">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="(customer?.dateOfBirth | date) || ''" />
</ui-inline-input>
<ui-inline-input label="Firmenname" (save)="patchOrganisation('name', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.organisation?.name || ''" />
</ui-inline-input>
<ui-inline-input label="Abteilung" (save)="patchOrganisation('department', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.organisation?.department || ''" />
</ui-inline-input>
<ui-inline-input label="USt-ID" (save)="patchOrganisation('vatId', $event)">
<input uiInput type="text" [disabled]="customerType !== 'store'" [value]="customer?.organisation?.vatId || ''" />
</ui-inline-input>
<div class="control-field">
<ui-form-control label="Anrede" variant="inline">
<ui-select #genderControl [(value)]="customer.gender" [disabled]="!genderToggle.toggled">
<ui-select-option [value]="2" label="Herr"></ui-select-option>
<ui-select-option [value]="4" label="Frau"></ui-select-option>
</ui-select>
</ui-form-control>
<button uiToggle #genderToggle="uiToggle" (toggledChange)="genderControl.focus()">Ändern</button>
<button *ngIf="genderToggle.toggled" (click)="genderToggle.close()">Speichern</button>
</div>
<ng-container *ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.title, label: 'Titel' }"></ng-container>
<ng-container *ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.firstName, label: 'Vorname' }"></ng-container>
<ng-container *ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.lastName, label: 'Nachname' }"></ng-container>
<ng-container
*ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.communicationDetails?.email, label: 'E-Mail', type: 'mail' }"
></ng-container>
<ng-container
*ngTemplateOutlet="
controlFieldTemplate;
context: { $implicit: customer.communicationDetails?.phone, label: 'Festnetznummer', type: 'tel' }
"
></ng-container>
<ng-container
*ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.communicationDetails?.mobile, label: 'Mobilnummer', type: 'tel' }"
></ng-container>
<ng-container *ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.dateOfBirth, label: 'Geburtsdatum' }"></ng-container>
<ng-container *ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.organisation?.name, label: 'Firma' }"></ng-container>
<ng-container
*ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.organisation?.department, label: 'Abteilung' }"
></ng-container>
<ng-container
*ngTemplateOutlet="controlFieldTemplate; context: { $implicit: customer.organisation?.vatId, label: 'USt-ID' }"
></ng-container>
<ng-template #controlFieldTemplate let-value let-label="label" let-type="type">
<div class="control-field">
<ui-form-control [label]="label" variant="inline">
<input uiInput #inputControl="uiInput" [type]="type || 'text'" [ngModel]="value" [disabled]="!inputToggle.toggled" />
</ui-form-control>
<button uiToggle #inputToggle="uiToggle" (toggledChange)="inputControl.focus()">Ändern</button>
<button *ngIf="inputToggle.toggled" (click)="inputToggle.close()">Speichern</button>
</div>
</ng-template>

View File

@@ -1,10 +1,19 @@
:host {
@apply flex flex-col box-border;
@apply flex flex-col box-border text-regular;
}
ui-inline-input {
@apply mt-px;
}
ui-inline-input:last-child {
@apply mb-px;
.control-field {
@apply flex flex-row bg-white align-middle text-regular p-4 my-px-2;
ui-form-control {
@apply flex-grow;
}
button {
@apply text-brand bg-transparent font-bold border-none outline-none text-cta-l;
}
[uiToggle].toggled {
@apply hidden;
}
}

View File

@@ -1,4 +1,6 @@
import { Component, ChangeDetectionStrategy, Input, Output, EventEmitter } from '@angular/core';
import { Component, ChangeDetectionStrategy, Input, Output, EventEmitter, OnInit, OnChanges, SimpleChanges } from '@angular/core';
import { async } from '@angular/core/testing';
import { FormBuilder, FormGroup } from '@angular/forms';
import { CrmCustomerService } from '@domain/crm';
import { CommunicationDetailsDTO, CustomerDTO, OrganisationDTO } from '@swagger/crm';
@@ -8,7 +10,7 @@ import { CommunicationDetailsDTO, CustomerDTO, OrganisationDTO } from '@swagger/
styleUrls: ['details-forms.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomerDetailsFormsComponent {
export class CustomerDetailsFormsComponent implements OnInit, OnChanges {
@Input()
customerType: 'store';
@@ -18,12 +20,22 @@ export class CustomerDetailsFormsComponent {
@Output()
customerChange = new EventEmitter<CustomerDTO>();
constructor(private customerDetailsService: CrmCustomerService) {}
constructor(private customerDetailsService: CrmCustomerService, private fb: FormBuilder) {}
async patchCustomer(proeprty: keyof CustomerDTO, value: any) {
await this.customerDetailsService.patchCustomer(this.customer.id, { [proeprty]: value }).toPromise();
ngOnInit() {
this.initCustomerForm();
}
initCustomerForm() {
const { fb, customer } = this;
}
ngOnChanges({ customer }: SimpleChanges): void {}
patchCustomer = async (proeprty: keyof CustomerDTO, value: any) => {
await this.customerDetailsService.patchCustomer(this.customer.id, { [proeprty]: value }).toPromise();
};
async patchCommunicationDetails(proeprty: keyof CommunicationDetailsDTO, value: any) {
await this.customerDetailsService.patchCustomer(this.customer.id, { communicationDetails: { [proeprty]: value } }).toPromise();
}

View File

@@ -1,11 +1,16 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { UiFormControlModule } from '@ui/form-control';
import { UiIconModule } from '@ui/icon';
import { UiInputModule } from '@ui/input';
import { UiSelectModule } from '@ui/select';
import { UiToggleModule } from '@ui/toggle';
import { CustomerDetailsFormsB2BComponent } from './details-forms-b2b.component';
import { CustomerDetailsFormsComponent } from './details-forms.component';
@NgModule({
imports: [CommonModule, UiInputModule],
imports: [CommonModule, FormsModule, UiFormControlModule, UiSelectModule, UiToggleModule, UiIconModule, UiInputModule],
declarations: [CustomerDetailsFormsComponent, CustomerDetailsFormsB2BComponent],
exports: [CustomerDetailsFormsComponent, CustomerDetailsFormsB2BComponent],
})

View File

@@ -22,7 +22,7 @@
type="submit"
uiSearchboxSearchButton
(click)="startSearch()"
[disabled]="searchState === 'fetching' || search.queryFilterEmpty$ | async"
[disabled]="searchState === 'fetching' || (search.queryFilterEmpty$ | async)"
>
<ui-icon class="spin" *ngIf="searchState === 'fetching'" icon="spinner" size="32px"></ui-icon>

View File

@@ -1,5 +1,5 @@
{
"includeGoogleAnalytics": false,
"includeGoogleAnalytics": true,
"title": "ISA - local",
"sso": {
"issuer": "https://sso-test.paragon-data.de",
@@ -42,16 +42,14 @@
"print": "https://isa-test.paragon-data.net/print/v1/"
}
},
"taskCalendarModuleOptions": {
"useMock": false,
"endpoints": {
"eis": "https://isa.paragon-data.de/eis/v1/"
}
},
"taskCalendarConfig": {
"monthsOffset": 3,
"weeksOffset": 2
}
}
}

View File

@@ -0,0 +1,25 @@
# FormControl
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 form-control` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project form-control`.
> Note: Don't forget to add `--project form-control` or else it will be added to the default project in your `angular.json` file.
## Build
Run `ng build form-control` to build the project. The build artifacts will be stored in the `dist/` directory.
## Publishing
After building your library with `ng build form-control`, go to the dist folder `cd dist/form-control` and run `npm publish`.
## Running unit tests
Run `ng test form-control` 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,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/ui/form-control'),
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/ui/form-control",
"lib": {
"entryFile": "src/public-api.ts"
}
}

View File

@@ -0,0 +1,11 @@
{
"name": "@ui/form-control",
"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,5 @@
// start:ng42.barrel
export * from './ui-form-control.component';
export * from './ui-form-control.directive';
export * from './ui-form-control.module';
// end:ng42.barrel

View File

@@ -0,0 +1,5 @@
<label *ngIf="label">{{ label }}</label>
<ng-content select="input, ui-select"></ng-content>
<button *ngIf="clearable && control.value && !control.disabled" class="ui-form-control-clear clear" (click)="control.clear()">
<ui-icon icon="close"></ui-icon>
</button>

View File

@@ -0,0 +1,20 @@
:host {
@apply flex flex-row gap-4 bg-white items-center box-border;
}
:host ::ng-deep ui-select,
:host ::ng-deep input {
@apply font-bold flex-grow;
}
:host ::ng-deep input {
@apply outline-none border-none font-bold text-regular;
&:disabled {
@apply bg-white text-black;
}
}
button.clear {
@apply bg-transparent text-ucla-blue border-none outline-none font-bold text-regular;
}

View File

@@ -0,0 +1,53 @@
import {
Component,
ChangeDetectionStrategy,
ContentChild,
Input,
AfterContentInit,
ChangeDetectorRef,
OnDestroy,
HostBinding,
} from '@angular/core';
import { combineLatest, Subscription } from 'rxjs';
import { UiFormControlDirective } from './ui-form-control.directive';
@Component({
selector: 'ui-form-control',
templateUrl: 'ui-form-control.component.html',
styleUrls: ['ui-form-control.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class UiFormControlComponent implements AfterContentInit, OnDestroy {
private subscriptions = new Subscription();
@Input()
@HostBinding('class')
variant: 'inline' | 'default' = 'default';
@Input()
label: string;
@Input()
clearable = true;
@ContentChild(UiFormControlDirective, { read: UiFormControlDirective })
control: UiFormControlDirective<any>;
constructor(private cdr: ChangeDetectorRef) {}
ngAfterContentInit() {
if (this.control) {
this.subscriptions.add(
this.control.changes.subscribe(() => {
this.cdr.markForCheck();
})
);
} else {
console.error('UiFormControlDirective is missing in Template');
}
}
ngOnDestroy() {
this.subscriptions.unsubscribe();
}
}

View File

@@ -0,0 +1,19 @@
import { Directive, EventEmitter } from '@angular/core';
import { NgControl } from '@angular/forms';
@Directive()
export abstract class UiFormControlDirective<T> {
changes = new EventEmitter<string>();
value: T | null;
valueChange = new EventEmitter<T>();
disabled?: boolean;
disabledChange = new EventEmitter<T>();
abstract clear(): void;
abstract focus(): void;
}

View File

@@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { UiFormControlComponent } from './ui-form-control.component';
import { UiIconModule } from '@ui/icon';
@NgModule({
imports: [CommonModule, UiIconModule],
exports: [UiFormControlComponent],
declarations: [UiFormControlComponent],
})
export class UiFormControlModule {}

View File

@@ -0,0 +1,5 @@
/*
* Public API Surface of form-control
*/
export * from './lib';

View 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);

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",
"ui",
"camelCase"
],
"component-selector": [
true,
"element",
"ui",
"kebab-case"
]
}
}

View File

@@ -1,6 +1,4 @@
// start:ng42.barrel
export * from './ui-inline-input.component';
export * from './ui-input.component';
export * from './ui-input.dircetive';
export * from './ui-input.directive';
export * from './ui-input.module';
// end:ng42.barrel

View File

@@ -1,34 +0,0 @@
<label [class.checked]="input?.checked" (click)="input?.toggle()">{{ label }}</label>
<ng-container *ngIf="input?.type === 'radio'">
<ui-icon
[class.disabled]="input?.disabled"
[icon]="input?.checked ? 'radio_checked' : 'radio'"
(click)="input?.toggle()"
size="22px"
></ui-icon>
</ng-container>
<ng-container *ngIf="input?.type === 'checkbox'">
<ui-icon
[class.disabled]="input?.disabled"
[icon]="input?.checked ? 'checkbox_checked' : 'checkbox'"
(click)="input?.toggle()"
size="22px"
></ui-icon>
</ng-container>
<ng-content select="input[uiInput]"></ng-content>
<ng-container *ngIf="input?.type === 'text'">
<button class="clear-input" *ngIf="input?.active && input.value" (click)="input?.clear()">
<ui-icon icon="close" size="23px"></ui-icon>
</button>
<button class="edit-input" *ngIf="!input?.disabled && !input?.active" (click)="input?.activate(); input?.focus()">Ändern</button>
<button class="edit-input save" *ngIf="!input?.disabled && input?.active" (click)="input?.deactivate(); save.emit(input?.value)">
Speichern
</button>
<span class="disabled-label" *ngIf="input?.disabled">
Nicht änderbar
</span>
</ng-container>

View File

@@ -1,57 +0,0 @@
:host {
@apply flex flex-row gap-4 items-center p-4 bg-white text-regular;
}
:host ::ng-deep input {
@apply bg-transparent flex-grow text-regular border-none font-bold;
&:disabled {
@apply bg-transparent;
}
&:focus {
@apply outline-none;
}
}
button.clear-input {
@apply bg-transparent border-none text-ucla-blue p-0;
}
button.edit-input {
@apply bg-transparent border-none text-regular text-brand font-bold p-0;
}
.disabled-label {
@apply text-ucla-blue;
}
:host.input-checkbox,
:host.input-radio {
@apply flex-row-reverse;
& ::ng-deep input {
@apply flex-grow-0;
}
label {
@apply flex-grow;
}
}
:host ::ng-deep input[type='checkbox'],
:host ::ng-deep input[type='radio'] {
@apply hidden;
}
ui-icon {
@apply text-ucla-blue;
}
ui-icon.disabled {
@apply text-cool-grey;
}
label.checked {
@apply font-bold;
}

View File

@@ -1,43 +0,0 @@
import {
Component,
ChangeDetectionStrategy,
Input,
ContentChild,
EventEmitter,
HostBinding,
AfterContentInit,
ChangeDetectorRef,
Output,
} from '@angular/core';
import { UiInputDirective } from './ui-input.dircetive';
@Component({
selector: 'ui-inline-input',
templateUrl: 'ui-inline-input.component.html',
styleUrls: ['ui-inline-input.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class UiInlineInputComponent implements AfterContentInit {
@Input()
label: string;
@ContentChild(UiInputDirective, { read: UiInputDirective })
input: UiInputDirective;
@Output()
save = new EventEmitter<any>();
@HostBinding('class')
get inputType() {
return `input-${this.input?.type}`;
}
constructor(private cdr: ChangeDetectorRef) {}
ngAfterContentInit() {
// TODO: Bessere Lösung benötigt
setInterval(() => {
this.cdr.detectChanges();
}, 100);
}
}

View File

@@ -1,11 +0,0 @@
import { Component, ChangeDetectionStrategy } from '@angular/core';
@Component({
selector: 'ui-input',
templateUrl: 'ui-input.component.html',
styleUrls: ['ui-input.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class UiInputComponent {
constructor() {}
}

View File

@@ -1,65 +0,0 @@
import { Directive, ElementRef, EventEmitter, HostBinding, HostListener, Input, Output, Renderer2 } from '@angular/core';
@Directive({ selector: 'input[uiInput]' })
export class UiInputDirective {
@Input()
disabled: boolean;
active: boolean;
@HostBinding('disabled')
get inputDisabled() {
const isRadioOrCheckbox = this.type === 'checkbox' || this.type === 'radio';
return isRadioOrCheckbox ? this.disabled : this.disabled || !this.active;
}
get value() {
return this.elementRef?.nativeElement?.value;
}
get type() {
return this.elementRef?.nativeElement?.type;
}
get checked() {
return this.elementRef?.nativeElement?.checked;
}
@Output()
events = new EventEmitter<Event>();
constructor(private elementRef: ElementRef, private renderer: Renderer2) {}
activate() {
this.active = true;
}
deactivate() {
this.active = false;
}
focus() {
const native: HTMLInputElement = this.elementRef?.nativeElement;
setTimeout(() => {
native?.focus();
}, 1);
}
clear() {
if (this.elementRef?.nativeElement) {
this.renderer.setProperty(this.elementRef.nativeElement, 'value', '');
}
}
@HostListener('change', ['$event'])
change(event: Event) {
setTimeout(() => {
this.events.emit(event);
}, 1);
}
toggle() {
this.elementRef?.nativeElement?.click();
}
}

View File

@@ -0,0 +1,98 @@
import {
Directive,
ElementRef,
EventEmitter,
forwardRef,
HostBinding,
HostListener,
Input,
OnChanges,
Output,
SimpleChanges,
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { UiFormControlDirective } from '@ui/form-control';
@Directive({
selector: 'input[uiInput]',
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => UiInputDirective),
multi: true,
},
{
provide: UiFormControlDirective,
useExisting: UiInputDirective,
},
],
exportAs: 'uiInput',
})
export class UiInputDirective implements UiFormControlDirective<any>, OnChanges, ControlValueAccessor {
@Output()
changes = new EventEmitter<string>();
@Input()
@HostBinding('value')
value: any;
@Output()
valueChange = new EventEmitter<any>();
@Input()
@HostBinding('disabled')
disabled?: boolean;
@Output()
disabledChange = new EventEmitter<any>();
private onChange = (value: any) => {};
private onTouched = () => {};
constructor(private elementRef: ElementRef) {}
ngOnChanges({ disabled }: SimpleChanges): void {
if (disabled) {
this.changes.emit('disabled');
}
}
writeValue(obj: any): void {
console.log(obj);
this.value = obj || '';
this.changes.emit('value');
}
registerOnChange(fn: any): void {
this.onChange = fn;
}
registerOnTouched(fn: any): void {
this.onTouched = fn;
}
setDisabledState?(isDisabled: boolean): void {
this.disabled = isDisabled;
this.changes.emit('disabled');
}
clear(): void {
this.setValue('');
}
focus(): void {
setTimeout(() => {
this.elementRef?.nativeElement?.focus();
}, 0);
}
@HostListener('keyup', ['$event.target.value'])
setValue(value: any): void {
console.log(value);
if (value !== this.value) {
this.value = value || '';
this.onChange(this.value);
this.valueChange.next(this.value);
this.changes.emit('value');
}
this.onTouched();
}
}

View File

@@ -1,14 +1,11 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { UiIconModule } from '@ui/icon';
import { UiInlineInputComponent } from './ui-inline-input.component';
import { UiInputComponent } from './ui-input.component';
import { UiInputDirective } from './ui-input.dircetive';
import { UiInputDirective } from './ui-input.directive';
@NgModule({
imports: [CommonModule, UiIconModule],
exports: [UiInlineInputComponent, UiInputComponent, UiInputDirective],
declarations: [UiInlineInputComponent, UiInputComponent, UiInputDirective],
imports: [],
exports: [UiInputDirective],
declarations: [UiInputDirective],
providers: [],
})
export class UiInputModule {}

View File

@@ -3,7 +3,7 @@
}
.ui-input-wrapper {
@apply flex flex-row bg-white py-px-5 px-px-10;
@apply flex flex-row bg-white px-px-10;
}
.ui-select-value {
@@ -42,7 +42,7 @@
}
:host ::ng-deep ui-select-option {
@apply py-px-5 px-px-10 cursor-pointer;
@apply py-px-10 px-px-10 cursor-pointer;
&:hover {
@apply bg-glitter;

View File

@@ -7,8 +7,17 @@ import {
HostBinding,
AfterContentInit,
ChangeDetectorRef,
forwardRef,
EventEmitter,
Output,
Self,
Optional,
ElementRef,
OnChanges,
SimpleChanges,
} from '@angular/core';
import { ControlValueAccessor } from '@angular/forms';
import { ControlValueAccessor, NgControl, NG_VALUE_ACCESSOR } from '@angular/forms';
import { UiFormControlDirective } from '@ui/form-control';
import { UiSelectOptionComponent } from './ui-select-option.component';
@Component({
@@ -16,11 +25,28 @@ import { UiSelectOptionComponent } from './ui-select-option.component';
templateUrl: 'ui-select.component.html',
styleUrls: ['ui-select.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => UiSelectComponent),
multi: true,
},
{
provide: UiFormControlDirective,
useExisting: UiSelectComponent,
},
],
})
export class UiSelectComponent implements ControlValueAccessor, AfterContentInit {
export class UiSelectComponent implements UiFormControlDirective<any>, ControlValueAccessor, AfterContentInit, OnChanges {
@Output()
changes = new EventEmitter<string>();
@Input()
value: any;
@Output()
valueChange = new EventEmitter<any>();
get label() {
return this.options.find((o) => o.value === this.value)?.label;
}
@@ -28,6 +54,9 @@ export class UiSelectComponent implements ControlValueAccessor, AfterContentInit
@Input()
disabled: boolean;
@Output()
disabledChange = new EventEmitter<boolean>();
@ContentChildren(UiSelectOptionComponent, { read: UiSelectOptionComponent })
options: QueryList<UiSelectOptionComponent>;
@@ -40,9 +69,24 @@ export class UiSelectComponent implements ControlValueAccessor, AfterContentInit
constructor(private cdr: ChangeDetectorRef) {}
ngOnChanges({ disabled }: SimpleChanges): void {
if (disabled && disabled.currentValue) {
this.close();
}
}
clear(): void {
this.setValue(undefined);
}
focus() {
this.open();
}
writeValue(obj: any): void {
this.value = obj;
this.cdr.markForCheck();
this.changes.emit('value');
}
registerOnChange(fn: any): void {
@@ -59,21 +103,27 @@ export class UiSelectComponent implements ControlValueAccessor, AfterContentInit
this.close();
}
this.cdr.markForCheck();
this.changes.emit('disabled');
}
toggle() {
this.toggled = !this.toggled;
this.cdr.markForCheck();
if (!this.disabled) {
this.toggled = !this.toggled;
this.cdr.markForCheck();
this.changes.emit('toggled');
}
}
open() {
this.toggled = true;
this.cdr.markForCheck();
this.changes.emit('toggled');
}
close() {
this.toggled = false;
this.cdr.markForCheck();
this.changes.emit('toggled');
}
ngAfterContentInit() {
@@ -84,14 +134,21 @@ export class UiSelectComponent implements ControlValueAccessor, AfterContentInit
});
}
setValue(value: any) {
if (value !== this.value) {
this.value = value;
this.onChange(value);
this.valueChange.next(value);
this.changes.emit('value');
}
this.onTouched();
this.cdr.markForCheck();
}
private registerOptionsSelect() {
this.options.forEach((option) => {
option.registerOnSelect((value) => {
if (value !== this.value) {
this.value = value;
this.onChange(value);
}
this.onTouched();
this.setValue(value);
this.close();
});
});

View File

@@ -1,21 +1,29 @@
import { Directive, Input } from '@angular/core';
import { Directive, EventEmitter, HostBinding, HostListener, Input, Output } from '@angular/core';
@Directive({ selector: '[uiToggle]', exportAs: 'uiToggle' })
export class UiToggleDirective {
@Input()
@HostBinding('class.toggled')
toggled = false;
@Output()
toggledChange = new EventEmitter<boolean>();
constructor() {}
@HostListener('click')
toggle() {
this.toggled = !this.toggled;
this.toggledChange.emit(this.toggled);
}
open() {
this.toggled = true;
this.toggledChange.emit(this.toggled);
}
close() {
this.toggled = false;
this.toggledChange.emit(this.toggled);
}
}

View File

@@ -33,6 +33,7 @@ module.exports = {
spacing: {
'cta-x-l': '25px',
'cta-y-l': '20px',
'px-2': '2px',
'px-5': '5px',
'px-8': '8px',
'px-10': '10px',

View File

@@ -142,6 +142,9 @@
],
"@ui/toggle": [
"apps/ui/toggle/src/public-api.ts"
],
"@ui/form-control": [
"apps/ui/form-control/src/public-api.ts"
]
}
}