• Mathias Chouet's avatar
    Materialification des modules de calcul · f8b934b5
    Mathias Chouet authored
    style personnalisé pour les mat-button-toggle
    breakpoint personnalisé "xxs" pour angular-flex
    placement des sous-calculettes répétables
    réparation des select
    erreurs sur les input
    placement des paramètres liés
    simplification du code et nouveau rendu pour les paramètres calculés
    suppression totale de MDBootstrap
    f8b934b5
base-param-input.component.ts 3.27 KiB
// cf. https://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html
import { Component, ChangeDetectorRef } from "@angular/core";
import { Message, ParamDefinition, ParamDomain, ParamDomainValue, Observable, isNumeric } from "jalhyd";
import { I18nService } from "../../services/internationalisation/internationalisation.service";
import { GenericInputComponent } from "../generic-input/generic-input.component";
import { ServiceFactory } from "../../services/service-factory";
export class NgBaseParam extends Observable {
    private _param: ParamDefinition;
    constructor(symb: string, d: ParamDomain | ParamDomainValue, val: number) {
        super();
        this._param = new ParamDefinition(null, symb, d, val);
    public get symbol() {
        return this._param.symbol;
    public get isDefined() {
        return this._param.isDefined;
    public getValue() {
        return this._param.getValue();
    public checkValue(val: number) {
        return this._param.checkValue(val);
    public setValue(val: number) {
        this._param.setValue(val);
        this.notifyObservers(val);
    public get value() {
        return this.getValue();
    public set value(val: number) {
        this.setValue(val);
    public validateModelValue(v: any): { isValid: boolean, message: string } {
        let msg: string;
        let valid = false;
        if (v === null || v === "") {
            // NULL values are always invalid
            msg = ServiceFactory.instance.i18nService.localizeText("ERROR_PARAM_NULL");
        } else {
            try {
                this._param.checkValue(v);
                valid = true;
            } catch (e) {
                if (e instanceof Message) {
                    // @TODO ici au début le service de localisation n'a pas encore chargé ses messages…
                    msg = ServiceFactory.instance.i18nService.localizeMessage(e);
                } else {
                    msg = "invalid value";
        return { isValid: valid, message: msg };
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
} @Component({ selector: "base-param-input", templateUrl: "../generic-input/generic-input.component.html", }) export class BaseParamInputComponent extends GenericInputComponent { constructor(private intlService: I18nService, cdRef: ChangeDetectorRef) { super(cdRef); } /** * paramètre géré */ private get _paramDef(): NgBaseParam { return this._model; } /** * valeur intermédiaire nécessitée par le fait que toutes les valeurs numériques ne sont pas légales * pour NgParameter (l'affecter peut provoquer une exception) et qui permet de faire fonctionner la validation du modèle */ private _tmp: number; protected afterSetModel() { this._tmp = this._paramDef.getValue(); } protected getModelValue(): any { return this._tmp; } protected setModelValue(sender: any, v: any) { this._tmp = v; try { this._paramDef.setValue(v); } catch (e) { // géré par validateModelValue() } } protected validateModelValue(v: any): { isValid: boolean, message: string } { return this._model.validateModelValue(v); } }