Skip to content

Commit

Permalink
feat: Add Support to defince currency (simpleangularcontrols#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjenni authored Jul 31, 2024
1 parent 617096c commit 9546c5e
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ <h2>Input</h2>
[(ngModel)]="values.fieldcurrency2"
disabled="true"
></sac-inputcurrency>
<sac-inputcurrency
name="fieldcurrency3"
label="Preis (Required)"
[(ngModel)]="values.fieldcurrency3"
[isrequired]="true"
validationmessagerequired="Please enter a valid price"
></sac-inputcurrency>
<sac-inputcurrency
name="fieldcurrency4"
label="Preis"
[(ngModel)]="values.fieldcurrency4"
currency="$"
disabled="true"
></sac-inputcurrency>

<sac-inputemail
name="fieldemail1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export class DemoInputComponent {
fieldi3: 0,
fieldcurrency1: 0,
fieldcurrency2: 0,
fieldcurrency3: null,
fieldcurrency4: null,
fieldemail1: '',
fieldemail2: '',
fieldemail3: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class CustomConfigurationService extends SacAbstractConfigurationService
return ControlHeight.Small;
}

public get CurrencyText(): string {
return 'CHF';
}

public get LabelSizeLg(): number | null {
return 3;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ <h2>Input</h2>
[isrequired]="true"
validationmessagerequired="Please enter a valid price"
></sac-inputcurrency>
<sac-inputcurrency
name="fieldcurrency4"
label="Preis"
[(ngModel)]="values.fieldcurrency4"
currency="$"
disabled="true"
></sac-inputcurrency>

<sac-inputemail
name="fieldemail1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class DemoInputComponent {
fieldcurrency1: 0,
fieldcurrency2: 0,
fieldcurrency3: null,
fieldcurrency4: null,
fieldemail1: '',
fieldemail2: '',
fieldemail3: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class CustomConfigurationService extends SacAbstractConfigurationService
return ControlHeight.Default;
}

public get CurrencyText(): string {
return 'CHF';
}

public get LabelSizeLg(): number | null {
return 3;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ <h2>Input</h2>
[isrequired]="true"
validationmessagerequired="Please enter a valid price"
></sac-inputcurrency>
<sac-inputcurrency
name="fieldcurrency4"
label="Preis"
[(ngModel)]="values.fieldcurrency4"
currency="$"
disabled="true"
></sac-inputcurrency>

<sac-inputemail
name="fieldemail1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class DemoInputComponent {
fieldcurrency1: 0,
fieldcurrency2: 0,
fieldcurrency3: null,
fieldcurrency4: null,
fieldemail1: '',
fieldemail2: '',
fieldemail3: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class CustomConfigurationService extends SacAbstractConfigurationService
return ControlHeight.Default;
}

public get CurrencyText(): string {
return 'CHF';
}

public get LabelSizeLg(): number | null {
return 3;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*ngIf="isAdaptiveLabel && !disablelabel"
>{{label}}</label
>
<div class="input-group-addon">CHF</div>
<div class="input-group-addon">{{currency}}</div>
</div>
<div
class="help-block help-block-error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
[ngClass]="[componentHeight | toControlHeight]"
/>
<div class="input-group-append">
<span class="input-group-text">CHF</span>
<span class="input-group-text">{{currency}}</span>
</div>
<div
*ngIf="isinlineerrorenabled && invalid && (dirty || touched)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
[class.is-invalid]="invalid && (dirty || touched)"
[ngClass]="[componentHeight | toControlHeight]"
/>
<span class="input-group-text">CHF</span>
<span class="input-group-text">{{currency}}</span>
<div
*ngIf="isinlineerrorenabled && invalid && (dirty || touched)"
class="invalid-feedback"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import { Directive } from '@angular/core';
import { Directive, Input } from '@angular/core';
import { SacInputDecimalCommon } from './inputdecimal';

/**
* Basis Komponente für SacInputCurrency
*/
@Directive()
export class SacInputCurrencyCommon extends SacInputDecimalCommon {
// #region Properties

@Input()
public currency: string = '';

// #endregion Properties

// #region Protected Methods

/**
* Set currency during initialization if no value is defined.
*/
protected OnClassInit(): void {
super.OnClassInit();

if (!this.currency) {
this.currency = this.configurationService.CurrencyText;
}
}

// #endregion Protected Methods
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export interface ISacConfigurationService {
* Defines the standard height of the components
*/
get ComponentHeight(): ControlHeight | null;
/**
* Defines the standard text for currencies. e.g. $, €, CHF
*/
get CurrencyText(): string;
/**
* default labe size for large devices
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import { SacAbstractConfigurationService } from '@simpleangularcontrols/sac-comm
providedIn: 'root',
})
export class CustomConfigurationService extends SacAbstractConfigurationService {
get ComponentHeight(): ControlHeight | null {
return ControlHeight.Default;
}
get CurrencyText(): string {
return 'CHF';
}
get LabelSizeLg(): number | null {
return 3;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export abstract class SacAbstractConfigurationService
* @inheritdoc
*/
public abstract get ComponentHeight(): ControlHeight | null;
/**
* @inheritdoc
*/
public abstract get CurrencyText(): string;
/**
* @inheritdoc
*/
Expand Down Expand Up @@ -52,10 +56,20 @@ export abstract class SacAbstractConfigurationService
export class SacDefaultConfigurationService extends SacAbstractConfigurationService {
// #region Public Getters And Setters

/**
* @inheritdoc
*/
public get ComponentHeight(): ControlHeight {
return null;
}

/**
* @inheritdoc
*/
public get CurrencyText(): string {
return 'CHF';
}

/**
* @inheritdoc
*/
Expand Down

0 comments on commit 9546c5e

Please sign in to comment.