IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Angular Discussion :

Angular Dialog avec Datatable


Sujet :

Angular

  1. #1
    Membre confirmé
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Novembre 2017
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2017
    Messages : 124
    Par défaut Angular Dialog avec Datatable
    Bonjour ,

    Cette fois-ci j'ai vraiment pas d'idée sur comment résoudre mon problème..

    Mon besoin : Afficher un dialog qui permet sur click d'un bouton d'edition de mettre à jour le contenu de la datatable.

    Actuellement : Le code html du dialog est OK
    Quelques fonctions de mises à jour sont OK
    Sur click du bouton d'edition la dialog s'affiche mais sans la data.

    Le problème : Je n'ai jamais fais ce type de manipulation avec deux classes dans un meme component.ts.
    L'une des classes doit récupérer la data de l'autre classe.

    Merci pour l'explication !

    Le dialog.html
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    <h2 mat-dialog-title>Moficiation du CheckConfig <strong>{{action}}</strong></h2>
    <mat-dialog-content class="mat-typography" *ngIf="action != 'Delete'">
      <form #userForm="ngForm">
     
     
        <mat-form-field>
          <mat-label>Status</mat-label>
          <select matNativeControl required name="status" [(ngModel)]="local_data.status">
            <option value="OK">OK</option>
            <option value="KO">KO</option>
            <option value="NotListed">NotListed</option>
          </select>
        </mat-form-field>
        <mat-form-field>
          <input type="text" matInput required id="details" name="details" [(ngModel)]="local_data.details"
            placeholder="Détails">
        </mat-form-field>
     
      </form>
    </mat-dialog-content>
     
    <div mat-dialog-actions align="end">
      <button mat-button (click)="doAction()" color="warn">{{action}}</button>
      <button mat-button (click)="closeDialog()" mat-flat-button>Cancel</button>
    </div>


    Le check-config.component.ts
    Code angular : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
     
     
    export class CheckConfigComponent implements OnInit {
    ...
     constructor(private dataService: RestApiService, private changeDetectorRefs: ChangeDetectorRef, private notification: NotificationsService, public dialog: MatDialog) {     
      }
    openDialog(action: string, checkconfig: any) {
        checkconfig.action = action;
        const dialogRef = this.dialog.open(checkconfig, {
          data: checkconfig
      });
     
        dialogRef.afterClosed().subscribe(result => {
            if (result.event === 'Update') {
                this.updateRowData(result.data);
            }});
      }
     
      updateRowData(checkconfig: any) {
        this.dataSource.data = this.dataSource.data.filter((value, key) => {
            if (value.id === checkconfig.id) {
                value.status = checkconfig.status;
                value.details = checkconfig.details;            
            }
            return true;
        });
    }
    ...
    ...
    ...
     
    @Component({
      // tslint:disable-next-line: component-selector
      selector: 'dialog-content',
      templateUrl: 'dialog-content.html',
    })
    // tslint:disable-next-line: component-class-suffix
    export class DialogContent {
      action: string;
      local_data: any;
     
      constructor(
          public dialogRef: MatDialogRef<any>,
          // @Optional() is used to prevent error if no data is passed
          @Optional() @Inject(MAT_DIALOG_DATA) public data: any) {
          // *console.log(data);
          this.local_data = XXXXX;                                                                  //Problème : Comment y mettre la data que j'ai récupéré dans la classe au dessus ?
          this.action = this.local_data.action;
      }
     
      doAction() {
          this.dialogRef.close({ event: this.action, data: this.local_data });
      }
     
      closeDialog() {
          this.dialogRef.close({ event: 'Cancel' });
      }
     
    }
    }

  2. #2
    Membre extrêmement actif
    Avatar de dukoid
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2012
    Messages
    2 100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2012
    Messages : 2 100
    Par défaut
    ou est CheckConfigComponent.html ?

  3. #3
    Membre confirmé
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Novembre 2017
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2017
    Messages : 124
    Par défaut
    Je ne pensais pas qu'il serait utile à la résolution , le voila

    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    <mat-card> 
    <div fxLayout="row wrap">
      <!-- column -->
      <div fxFlex.gt-sm="25" fxFlex.gt-xs="100" fxFlex="100">
        <mat-card>
          <div class="box p-20 bg-info text-center" (click)= "btnCategoryClick('')">
            <h1 class="font-light text-white m-0">{{totalCount}}</h1>
            <h6 class="text-white m-0">Total Configs</h6>
          </div>
        </mat-card>
      </div>
      <!-- column -->
      <!-- column -->
      <div fxFlex.gt-sm="25" fxFlex.gt-xs="100" fxFlex="100">
        <mat-card>
          <div class="box p-20 bg-success text-center" (click)= "btnCategoryClick('OK')">
            <h1 class="font-light text-white m-0">{{OK}}</h1>
            <h6 class="text-white m-0">Status : OK</h6>
          </div>
        </mat-card>
      </div>
      <!-- column -->
      <!-- column -->
      <div fxFlex.gt-sm="25" fxFlex.gt-xs="100" fxFlex="100">
        <mat-card>
          <div class="box p-20 bg-danger text-center" (click)= "btnCategoryClick('KO')">
            <h1 class="font-light text-white m-0">{{KO}}</h1>
            <h6 class="text-white m-0">Status : KO</h6>
          </div>
        </mat-card>
      </div>
      <!-- column -->
      <!-- column -->
      <div fxFlex.gt-sm="25" fxFlex.gt-xs="100" fxFlex="100">
        <mat-card>
          <div class="box p-20 bg-warning text-center" (click)= "btnCategoryClick('Solved')">
            <h1 class="font-light text-white m-0">{{Solved}}</h1>
            <h6 class="text-white m-0">Status : Solved</h6>
          </div>
        </mat-card>
      </div>
      <!-- column -->
    </div>
     
        <mat-card-content *ngIf='dataSource.data.length > 0'>
        <mat-card-title>Voici l'ensemble des problèmes de configuration identifiés</mat-card-title>
     
    	    <mat-form-field class="filter">
        	    <input type="text" placeholder="Filtrez l'information de votre choix" (keyup)="applyFilteringDataTable($event.target.value)" matInput autocomplete="off">
            </mat-form-field>
     
            <mat-table matTableExporter [dataSource]="dataSource" matSort class="mat-elevation-z8" #exporter="matTableExporter" >  
     
                <ng-container matColumnDef="namespacename">
                <mat-header-cell *matHeaderCellDef mat-sort-header>Namespace</mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.namespacename}} </mat-cell>
                </ng-container>
     
                <ng-container matColumnDef="servicename">
                <mat-header-cell *matHeaderCellDef mat-sort-header>Composant</mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.servicename}} </mat-cell>
                </ng-container>    
     
                <ng-container matColumnDef="typeverification">
                <mat-header-cell *matHeaderCellDef mat-sort-header>Type de Vérification</mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.typeverification}} </mat-cell>
                </ng-container>
     
                <ng-container matColumnDef="status">
                <mat-header-cell *matHeaderCellDef mat-sort-header>Status</mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.status}} </mat-cell>
                </ng-container>  
     
                <ng-container matColumnDef="details">
                <mat-header-cell *matHeaderCellDef mat-sort-header>Détails</mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.details}} </mat-cell>
                </ng-container>
     
                <ng-container matColumnDef="reportdate">
                <mat-header-cell *matHeaderCellDef mat-sort-header>Date du signalement</mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.reportdate}} </mat-cell>
                </ng-container>
     
                <ng-container matColumnDef="action">
                    <mat-header-cell *matHeaderCellDef mat-sort-header>Confirmer la correction</mat-header-cell>
                        <mat-cell *matCellDef="let element"> 
                        <a (click)="openDialog('Update',element)" class="m-r-10 cursor-pointer"><i class="fa fa-pencil"></i></a>  
                            <button mat-icon-button color="warn" (click)='putComponentsConfig(element)' aria-label="Confirmer la correction">
                                <mat-icon>verified</mat-icon>
                            </button>
                        </mat-cell>
                </ng-container>
     
                <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
                <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
     
            </mat-table>
     
            <div fxLayout="row">
    	        <div fxFlex.gt-sm="100%" >
                    <mat-card>
                        <mat-card-content>
                            <mat-paginator [pageSize]="10" [pageSizeOptions]="[5, 10, 15, 100]" showFirstLastButtons></mat-paginator>     
                            <div class="button-row align-center">
                                <button mat-raised-button color="accent" matTooltip="Excel, format propriétaire !" matTooltipPosition="above" (click)="exporter.exportTable('xlsx', {fileName:'Liste de l\'ensemble des namespaces', sheet: 'Services', Props: {Author: 'DevOps Team'}})">Excel</button>
                                <button mat-raised-button color="accent" matTooltip="CSV, le format libre des tableurs !" matTooltipPosition="above" (click)="exporter.exportTable('csv', {fileName:'Liste de l\'ensemble des namespaces'})">Csv</button>
                                <button mat-raised-button color="accent" matTooltip="Json, le format structuré de données !" matTooltipPosition="above" (click)="exporter.exportTable('json', {fileName:'Liste de l\'ensemble des namespaces'})">Json</button>
                                <button mat-raised-button color="accent" matTooltip="Txt, un export basique adapté à Teams !" matTooltipPosition="above" (click)="exporter.exportTable('txt', {fileName:'Liste de l\'ensemble des namespaces'})">Txt</button>
                            </div>
                        </mat-card-content>
                    </mat-card>
                </div>
            </div>
        </mat-card-content>
    </mat-card>

  4. #4
    Membre extrêmement actif
    Avatar de dukoid
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2012
    Messages
    2 100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2012
    Messages : 2 100
    Par défaut
    je cherche à comprendre qui imbrique quoi ?

    CheckConfigComponent c'est l'affichage principale
    donc on ouvre une boite de dialog depuis cette page


    je n'ai jamais essayé, peut être comme ça:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    openDialog(action: string, checkconfig: any) {
        checkconfig.action = action;
        const dialogRef = this.dialog.open(
          checkconfig, 
         { data: checkconfig },
          myDataxxxx
    });

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     constructor(
          public dialogRef: MatDialogRef<any>,  @Optional() @Inject(MAT_DIALOG_DATA) public data: any,   myDataXXXX: any) {
          console.log(myDataXXXX);
          this.local_data = myDataXXXX;                                                                  //Problème : Comment y mettre la data que j'ai récupéré dans la classe au dessus ?
          this.action = this.local_data.action;
      }

  5. #5
    Membre confirmé
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Novembre 2017
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2017
    Messages : 124
    Par défaut
    Page principale: check-config.component.html
    Dialog qui se rajoute par dessus : dialog.component.html


    Voila un tuto en ligne qui montre le résultat final :https://www.freakyjolly.com/angular-...-using-dialog/
    Ce sera beaucoup plus clair, ta modif dans le opendialog me semble trés étrange

    La variable "checkconfig" correspond à ma DATA.

  6. #6
    Membre extrêmement actif
    Avatar de dukoid
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2012
    Messages
    2 100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2012
    Messages : 2 100
    Par défaut
    le code précédent que j'ai mis n'est pas bon.

  7. #7
    Membre confirmé
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Novembre 2017
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2017
    Messages : 124
    Par défaut
    En effet, ma variable était incorrect je crois

    Au cas ou je me le code en intégralité :
    check-config.component.html
    Code angular : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
     
    <mat-card> 
    <div fxLayout="row wrap">
      <!-- column -->
      <div fxFlex.gt-sm="25" fxFlex.gt-xs="100" fxFlex="100">
        <mat-card>
          <div class="box p-20 bg-info text-center" (click)= "btnCategoryClick('')">
            <h1 class="font-light text-white m-0">{{totalCount}}</h1>
            <h6 class="text-white m-0">Total Configs</h6>
          </div>
        </mat-card>
      </div>
      <!-- column -->
      <!-- column -->
      <div fxFlex.gt-sm="25" fxFlex.gt-xs="100" fxFlex="100">
        <mat-card>
          <div class="box p-20 bg-success text-center" (click)= "btnCategoryClick('OK')">
            <h1 class="font-light text-white m-0">{{OK}}</h1>
            <h6 class="text-white m-0">Status : OK</h6>
          </div>
        </mat-card>
      </div>
      <!-- column -->
      <!-- column -->
      <div fxFlex.gt-sm="25" fxFlex.gt-xs="100" fxFlex="100">
        <mat-card>
          <div class="box p-20 bg-danger text-center" (click)= "btnCategoryClick('KO')">
            <h1 class="font-light text-white m-0">{{KO}}</h1>
            <h6 class="text-white m-0">Status : KO</h6>
          </div>
        </mat-card>
      </div>
      <!-- column -->
      <!-- column -->
      <div fxFlex.gt-sm="25" fxFlex.gt-xs="100" fxFlex="100">
        <mat-card>
          <div class="box p-20 bg-warning text-center" (click)= "btnCategoryClick('Solved')">
            <h1 class="font-light text-white m-0">{{Solved}}</h1>
            <h6 class="text-white m-0">Status : Solved</h6>
          </div>
        </mat-card>
      </div>
      <!-- column -->
    </div>
     
        <mat-card-content *ngIf='dataSource.data.length > 0'>
        <mat-card-title>Voici l'ensemble des problèmes de configuration identifiés</mat-card-title>
     
    	    <mat-form-field class="filter">
        	    <input type="text" placeholder="Filtrez l'information de votre choix" (keyup)="applyFilteringDataTable($event.target.value)" matInput autocomplete="off">
            </mat-form-field>
     
            <mat-table matTableExporter [dataSource]="dataSource" matSort class="mat-elevation-z8" #exporter="matTableExporter" >  
     
                <ng-container matColumnDef="namespacename">
                <mat-header-cell *matHeaderCellDef mat-sort-header>Namespace</mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.namespacename}} </mat-cell>
                </ng-container>
     
                <ng-container matColumnDef="servicename">
                <mat-header-cell *matHeaderCellDef mat-sort-header>Composant</mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.servicename}} </mat-cell>
                </ng-container>    
     
                <ng-container matColumnDef="typeverification">
                <mat-header-cell *matHeaderCellDef mat-sort-header>Type de Vérification</mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.typeverification}} </mat-cell>
                </ng-container>
     
                <ng-container matColumnDef="status">
    			<mat-header-cell *matHeaderCellDef> Status </mat-header-cell>
    			<mat-cell *matCellDef="let element">
    				<mat-form-field floatLabel="never">
    					<mat-select [(value)]="element.status" placeholder="Status">
    						<mat-option value="Solved">Solved</mat-option>
    						<mat-option value="KO">KO</mat-option>
    					</mat-select>
    				</mat-form-field>
    			</mat-cell>
    		</ng-container> 
     
                <ng-container matColumnDef="details">
                <mat-header-cell *matHeaderCellDef mat-sort-header>Détails</mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.details}} </mat-cell>
                </ng-container>
     
                <ng-container matColumnDef="reportdate">
                <mat-header-cell *matHeaderCellDef mat-sort-header>Date du signalement</mat-header-cell>
                <mat-cell *matCellDef="let element"> {{element.reportdate}} </mat-cell>
                </ng-container>
     
                <ng-container matColumnDef="action">
                    <mat-header-cell *matHeaderCellDef mat-sort-header>Confirmer la correction</mat-header-cell>
                        <mat-cell *matCellDef="let element"> 
                        <a (click)="openDialog('Update',element)" class="m-r-10 cursor-pointer"><i class="fa fa-pencil"></i></a>  
                            <button mat-icon-button color="warn" (click)='putComponentsConfig(element)' aria-label="Confirmer la correction">
                                <mat-icon>verified</mat-icon>
                            </button>
                        </mat-cell>
                </ng-container>
     
                <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
                <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
     
            </mat-table>
     
            <div fxLayout="row">
    	        <div fxFlex.gt-sm="100%" >
                    <mat-card>
                        <mat-card-content>
                            <mat-paginator [pageSize]="10" [pageSizeOptions]="[5, 10, 15, 100]" showFirstLastButtons></mat-paginator>     
                            <div class="button-row align-center">
                                <button mat-raised-button color="accent" matTooltip="Excel, format propriétaire !" matTooltipPosition="above" (click)="exporter.exportTable('xlsx', {fileName:'Liste de l\'ensemble des namespaces', sheet: 'Services', Props: {Author: 'DevOps Team'}})">Excel</button>
                                <button mat-raised-button color="accent" matTooltip="CSV, le format libre des tableurs !" matTooltipPosition="above" (click)="exporter.exportTable('csv', {fileName:'Liste de l\'ensemble des namespaces'})">Csv</button>
                                <button mat-raised-button color="accent" matTooltip="Json, le format structuré de données !" matTooltipPosition="above" (click)="exporter.exportTable('json', {fileName:'Liste de l\'ensemble des namespaces'})">Json</button>
                                <button mat-raised-button color="accent" matTooltip="Txt, un export basique adapté à Teams !" matTooltipPosition="above" (click)="exporter.exportTable('txt', {fileName:'Liste de l\'ensemble des namespaces'})">Txt</button>
                            </div>
                        </mat-card-content>
                    </mat-card>
                </div>
            </div>
        </mat-card-content>
    </mat-card>

    check-config.component.ts
    Code angular : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
     
    import { Component, OnInit, Injectable, ViewChild, ChangeDetectorRef, Optional, Inject  } from '@angular/core';
    import { RestApiService } from '../../shared/rest-api.service';
    import { NotificationsService } from '../../shared/notifications.service';
    import { FormControl } from '@angular/forms';
    import { Observable, of, Subscription } from 'rxjs';
    import { tap, startWith, debounceTime, switchMap, map, filter, distinctUntilChanged } from 'rxjs/operators';
    import {MatPaginator} from '@angular/material/paginator';
    import {MatSort} from '@angular/material/sort';
    import {MatTableDataSource} from '@angular/material/table';
    import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
     
     
    @Injectable({
      providedIn: 'root'
    })
     
    @Component({
      selector: 'app-check-config',
      templateUrl: './check-config.component.html',
      styleUrls: ['./check-config.component.scss']
    })
     
    export class CheckConfigComponent implements OnInit {
     
      myControl2 = new FormControl();
      namespaces = [];
     
     
      displayedColumns: string[] = ['namespacename', 'servicename', 'typeverification', 'status', 'details', 'reportdate', 'action']; 
      dataSource = new MatTableDataSource<any>();
     
      @ViewChild(MatPaginator, {static: false}) paginator!: MatPaginator;
      @ViewChild(MatSort, { static: false }) sort!: MatSort;
      totalCount?: number;
      KO?: number;
      OK?: number;
      Solved?: number;
     
      constructor(private dataService: RestApiService, private changeDetectorRefs: ChangeDetectorRef, private notification: NotificationsService, public dialog: MatDialog) {     
      }
     
      ngOnInit() {     
        this.getAllComponentsConfig();
     
      }
     
      btnCategoryClick(val: string) {
        this.dataSource.filter = val.trim().toLowerCase();
        return this.dataSource.filteredData.length;
     
    }
     
      getAllComponentsConfig(){   
          this.dataService.getFromApiAllComponentsConfig().subscribe( (res) => {       
          this.dataSource = new MatTableDataSource<any>(res);      
          this.changeDetectorRefs.detectChanges();      
          this.dataSource.paginator = this.paginator;
          this.dataSource.sort = this.sort;
          this.dataSource.sort.sort({ id: "dateajout", start: 'desc', disableClear: false }); 
     
          this.totalCount = this.dataSource.data.length;      
          this.OK = this.btnCategoryClick('OK');
          this.Solved = this.btnCategoryClick('Solved');  
          this.KO = this.btnCategoryClick('KO');       
      });
      }
     
      applyFilteringDataTable(filterValue: string){
        this.dataSource.filter = filterValue.trim().toLowerCase();
      }
     
      openDialog(action: string, checkconfig: any) {
        checkconfig.action = action;
        const dialogRef = this.dialog.open(checkconfig, {
          data: checkconfig
      });
     
        dialogRef.afterClosed().subscribe(result => {
            if (result.event === 'Update') {
                this.updateRowData(result.data);
            }});
      }
     
      updateRowData(checkconfig: any) {
        this.dataSource.data = this.dataSource.data.filter((value, key) => {
            if (value.id === checkconfig.id) {
                value.status = checkconfig.status;
                value.details = checkconfig.details;            
            }
            return true;
        });
    }
     
     
     
     
     
     
      putComponentsConfig(checkconfig: any){
        this.dataService.putToApiComponentsConfig(checkconfig).subscribe((res)=>{
          if(res.status == 200){
            this.notification.LittleNotification("La modification du CheckConfig a bien été prise en compte", 3000, "success", false, "top-end");
          }else{
            this.notification.LittleNotification("La modification du CheckConfig est un echec", 3000, "error", false, "top-end");
          }
          // this.datanamespaces = res;
          // this.TraitementChartNX();            
      });
      }
    }
    @Component({
      // tslint:disable-next-line: component-selector
      selector: 'dialog-content',
      templateUrl: 'dialog-content.html',
    })
    // tslint:disable-next-line: component-class-suffix
    export class DialogContent {
      action: string;
      local_data: any;
     
      constructor(
          public dialogRef: MatDialogRef<any>,
          // @Optional() is used to prevent error if no data is passed
          @Optional() @Inject(MAT_DIALOG_DATA) public data: any) {
          // *console.log(data);
          this.local_data = data;
          this.action = this.local_data.action;
      }
     
      doAction() {
          this.dialogRef.close({ event: this.action, data: this.local_data });
      }
     
      closeDialog() {
          this.dialogRef.close({ event: 'Cancel' });
      }
     
    }

    dialog-content.html

    Code angular : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
    <h2 mat-dialog-title>Modification du CheckConfig <strong>{{action}}</strong></h2>
    <mat-dialog-content class="mat-typography" *ngIf="action != 'Delete'">
      <form #userForm="ngForm">
     
     
        <mat-form-field>
          <mat-label>Status</mat-label>
          <select matNativeControl required name="status" [(ngModel)]="local_data.status">
            <option value="OK">OK</option>
            <option value="KO">KO</option>
            <option value="NotListed">NotListed</option>
          </select>
        </mat-form-field>
        <mat-form-field>
          <input type="text" matInput required id="details" name="details" [(ngModel)]="local_data.details"
            placeholder="Détails">
        </mat-form-field>
     
      </form>
    </mat-dialog-content>
     
    <div mat-dialog-actions align="end">
      <button mat-button (click)="doAction()" color="warn">{{action}}</button>
      <button mat-button (click)="closeDialog()" mat-flat-button>Cancel</button>
    </div>

    Résultat : En image lors du clique sur edit
    Lors du clique sur edit, erreur : core.js:4081 ERROR Error: ASSERTION ERROR: Type passed in is not ComponentType, it does not have 'ɵcmp' property.
    Nom : Screenshot_2.png
Affichages : 1465
Taille : 87,1 Ko

  8. #8
    Membre extrêmement actif
    Avatar de dukoid
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2012
    Messages
    2 100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2012
    Messages : 2 100
    Par défaut
    dans l'exemple il passe 2 données: id et title:
    tu pourra faire pareil pour envoyer ce que tu veux à la boite de dialog...


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    git clone https://github.com/StefanosKokkalis/ng-material-dialog-example.git

  9. #9
    Membre confirmé
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Novembre 2017
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2017
    Messages : 124
    Par défaut
    En prenant le code qu'il à fait, sous Angular 10, ça ne compile pas, j'ai cette erreur dans le course-dialog.component.ts :
    src/app/material-component/check-config/course-dialog.component.ts:17:31 - error TS7031: Binding element 'description' implicitly has an 'any' type.

    17 @Inject(MAT_DIALOG_DATA) {description}
    ~~~~~~~~~~~

  10. #10
    Membre confirmé
    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Novembre 2017
    Messages
    124
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 25
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Novembre 2017
    Messages : 124
    Par défaut
    1 ) Ma correction temporaire c'est dans le : tsconfig.base.json , cette variable à mettre à false : "strict":false
    As tu une vrai correction, plutot que celle-ci qui n'est pas top..

    2 ) Par contre une fois que j'ai modifié la data dans le dialog, comment faire pour qu'elle soit modifier dans le tableau ?
    Il existe cette fonction en ligne, mais le problème c'est que mon tableau est dans un composant et le dialog dans un autre.
    Tu sais comment faire ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    updateRowData(checkconfig: any) {
        this.dataSource.data = this.dataSource.data.filter((value, key) => {
            if (value.id === checkconfig.id) {
                value.namespacename = checkconfig.namespacename;
                value.servicename = checkconfig.servicename;            
            }
            return true;
        });
    }


    Réponse (Plus d'infos ici : https://stackblitz.com/edit/angular-wfvqbj ) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    dialogRef.afterClosed().subscribe(
     
          data => {
            console.log("Dialog output:", data)
            mydata.namespacename = data.namespacename;
            mydata.servicename = data.servicename
          }
        );


    3 ) Autre chose : Normalement le dialog doit s'afficher de cette manière, un cadre plutot grand, sans barre : https://prnt.sc/ttcjpy
    Avec le code de Github, l'affichage est petit et la barre sur le coté est vraiment moche : https://prnt.sc/ttcj9q

    J'ai tenté de modifier le css, mais rien n'y fait, je pense pas que ce soit lié à ça. Tu aurais une idée de ce qui peut provoquer ça ?
    (réponse : il y avait un problème dans son html)

    Correction :
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    <mat-dialog-content class="mat-typography">
        <h2 mat-dialog-title>Modification du CheckConfig </h2>        
            <form [formGroup]="form">  
                <mat-form-field>
                    <input matInput
                            placeholder="Course Description"
                        formControlName="description">
                </mat-form-field>
     
                <mat-form-field>
                <mat-label>Status</mat-label>
                <select matNativeControl required name="title">
                    <option value="OK">OK</option>
                    <option value="KO">KO</option>
                    <option value="NotListed">NotListed</option>
                </select>
                </mat-form-field>
     
                <mat-form-field>
                    <input matInput
                            placeholder="{{id}}"
                        formControlName="id">
                </mat-form-field>
     
                <mat-form-field>
                    <input matInput
                            placeholder="{{title}}"
                        formControlName="title">
                </mat-form-field>
            </form>
    </mat-dialog-content>
     
    <div mat-dialog-actions align="end">
        <button mat-button mat-flat-button (click)="close()">Close</button>
        <button mat-button color="warn" (click)="save()" mat-flat-button >Save</button>
    </div>


    Merci pour l'aide Je met en résolu

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. erreur avec datatable
    Par samir dans le forum XMLRAD
    Réponses: 7
    Dernier message: 28/11/2006, 18h09
  2. Réponses: 5
    Dernier message: 13/09/2006, 16h47
  3. pagination avec dataTable
    Par dude666 dans le forum JSF
    Réponses: 4
    Dernier message: 28/08/2006, 11h23
  4. Facelets: problème avec dataTable et Dreamweaver
    Par cyrille37 dans le forum JSF
    Réponses: 2
    Dernier message: 27/07/2006, 16h56
  5. [MFC][DLL]Dialog Avec ActiveX dans une DLL ?
    Par matazz dans le forum MFC
    Réponses: 1
    Dernier message: 16/05/2005, 16h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo