Функция всегда возвращает true в режиме prod - PullRequest
0 голосов
/ 20 февраля 2019

Я создаю приложение, чтобы люди могли записываться на некоторые курсы.У меня есть массив в моем компоненте: public corsiSelezionati: {nome: string, sede:string, codice:string}[]

У меня есть onChange() функция, которая запускается каждый раз, когда форма имеет изменение:

onChange($event) {
    try {
        const nome = ($event.target.options[$event.target.options.selectedIndex].text).split('-')[0].trim();
        const sede = ($event.target.options[$event.target.options.selectedIndex].text).split('-')[1].trim();
        const codice = $event.target.options[$event.target.options.selectedIndex].value;
        const corso = {
            nome: nome,
            sede: sede,
            codice: codice
        };
        const turno = $event.path[0].getAttribute('ng-reflect-name');
        switch (turno) {
            case 'g1t1':
            this.corsiSelezionati[0] = corso;
            this.corsiSelezionati[1] = {nome: '', sede: '', codice: ''};
            this.corsiForm.controls['g1t2'].enable();
            this.corsiForm.controls['g1t2'].reset();
            break;
            case 'g1t2':
            this.corsiSelezionati[1] = corso;
            break;
            case 'g2t1':
            this.corsiSelezionati[2] = corso;
            this.corsiSelezionati[3] = {nome: '', sede: '', codice: ''};
            this.corsiForm.controls['g2t2'].enable();
            this.corsiForm.controls['g2t2'].reset();
            break;
            case 'g2t2':
            this.corsiSelezionati[3] = corso;
            break;
            case 'g3t1':
            this.corsiSelezionati[4] = corso;
            this.corsiSelezionati[5] = {nome: '', sede: '', codice: ''};
            this.corsiForm.controls['g3t2'].enable();
            this.corsiForm.controls['g3t2'].reset();
            break;
            case 'g3t2':
            this.corsiSelezionati[5] = corso;
            break;
            default:
            break;
        }
    } catch (error) {
        const nome = ($event.target.options[$event.target.options.selectedIndex].text)
        const turno = $event.path[0].getAttribute('ng-reflect-name');
        if(nome == "Assente"){
            switch (turno) {
                case 'g1t1':
                    this.corsiSelezionati[0] = {nome: 'assente', sede: 'assente', codice: 'assente'};
                    this.corsiSelezionati[1] = {nome: 'assente', sede: 'assente', codice: 'assente'};
                    try {
                        this.corsiForm.controls['g1t2'].disable();
                    } catch (error) {}
                    break;
                case 'g1t2':
                    this.corsiSelezionati[0] = {nome: 'assente', sede: 'assente', codice: 'assente'};
                    this.corsiSelezionati[1] = {nome: 'assente', sede: 'assente', codice: 'assente'};
                    try {
                        this.corsiForm.controls['g1t2'].disable();
                    } catch (error){}
                    break;
                case 'g2t1':
                    this.corsiSelezionati[2] = {nome: 'assente', sede: 'assente', codice: 'assente'};
                    this.corsiSelezionati[3] = {nome: 'assente', sede: 'assente', codice: 'assente'};
                    try{
                        this.corsiForm.controls['g2t2'].disable();
                    } catch(error){}
                    break;
                case 'g2t2':
                    this.corsiSelezionati[2] = {nome: 'assente', sede: 'assente', codice: 'assente'};
                    this.corsiSelezionati[3] = {nome: 'assente', sede: 'assente', codice: 'assente'};
                    try{
                        this.corsiForm.controls['g2t2'].disable();
                    } catch(error){}
                    break;
                case 'g3t1':
                    this.corsiSelezionati[4] = {nome: 'assente', sede: 'assente', codice: 'assente'};
                    this.corsiSelezionati[5] = {nome: 'assente', sede: 'assente', codice: 'assente'};
                    try{
                        this.corsiForm.controls['g3t2'].disable();
                    } catch(error){}
                    break;
                case 'g3t2':
                    this.corsiSelezionati[4] = {nome: 'assente', sede: 'assente', codice: 'assente'};
                    this.corsiSelezionati[5] = {nome: 'assente', sede: 'assente', codice: 'assente'};
                    try{
                        this.corsiForm.controls['g3t2'].disable();
                    } catch(error){}
                    break;
                default:
                    break;
            }
        }

    }

    console.log(this.corsiSelezionati,this.corsiForm);
}

и каждый выбор в формеимеет больше опций, которые проверяются функцией canISub()

canISub(corsiForm: NgForm , row: any[], cell: Corso[], corso: Corso) {

    if (this.corsiSelezionati[0].codice === corso.codice) {return true; }
    if (this.corsiSelezionati[1].codice === corso.codice) {return true; }
    if (this.corsiSelezionati[2].codice === corso.codice) {return true; }
    if (this.corsiSelezionati[3].codice === corso.codice) {return true; }
    if (this.corsiSelezionati[4].codice === corso.codice) {return true; }
    if (this.corsiSelezionati[5].codice === corso.codice) {return true; }

    if(this.table.dataRows.indexOf(row)===1 && this.sediObbligatorie[row.indexOf(cell)] == "") {
      if(corso.sede !== this.corsiSelezionati[row.indexOf(cell) *2 ].sede){
        return true;
      }
    }

    if(this.sediObbligatorie[row.indexOf(cell)] != "" && corso.sede != this.sediObbligatorie[row.indexOf(cell)]) {
        return true;
    }
  }

выбор это в HTML:

<select class="form-control border-input" [name]="names[((row.indexOf(cell))*2)+(table.dataRows.indexOf(row))]" ngModel (change)="onChange($event)" *ngIf="this.ragazzo.turni.indexOf(names[((row.indexOf(cell))*2)+(table.dataRows.indexOf(row))])>=0" required>           
    <option value="assente" *ngIf="table.dataRows.indexOf(row)== 0" [disabled]="absCanI(row,cell)">Assente</option>
    <option *ngFor="let corso of cell" [value]="corso.codice" [disabled]="canISub(corsiForm,row,cell,corso)">{{corso.nome}} - {{corso.sede}}</option>
</select>

Проблема в том, что второй блок инструкций всегда возвращает true, когдав режиме Prod.В режиме разработки работает отлично.

if(this.table.dataRows.indexOf(row)===1 && this.sediObbligatorie[row.indexOf(cell)] == ""){
    if(corso.sede !== this.corsiSelezionati[row.indexOf(cell) *2 ].sede){
        return true;
    }
}

Заранее спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...