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

JavaScript Discussion :

Portée de variables


Sujet :

JavaScript

  1. #1
    Membre actif Avatar de Zebulon777
    Homme Profil pro
    Informaticien
    Inscrit en
    Février 2005
    Messages
    1 319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien

    Informations forums :
    Inscription : Février 2005
    Messages : 1 319
    Points : 286
    Points
    286
    Par défaut Portée de variables
    Bonjour à tous.

    J'essaye de simplifier une de mes fonctions mais j'ai un problème de portée de variables qui sont écrasées par la dernière instance.
    La fonction suivante fonctionne très bien.

    Code javascript : 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
    140
    141
    142
    function ChargementTableRelance()
    {
        var day = new Date();
        day.setDate(day.getDate() - 1); // On sélectionne le jour précédent
        var mm = ((day.getMonth() + 1) < 10) ? '0' + (day.getMonth() + 1) : (day.getMonth() + 1);
        var dd = (day.getDate() < 10) ? '0' + day.getDate() : day.getDate();
        var dayInit_Rel = day.getFullYear().toString() + mm + dd;
        var dayInitAlt_Rel = dd + "/" + mm + "/" + day.getFullYear(); // Utiliser pour le nouveau DatePicket
    
        let TabRelanceByID = document.getElementById("table_relance");
        let InsertLig = "";
        let InsertCell = "";
        let NomLig = "";
        let NomCell = "";
        let BtnCell = "";
        let NomDate = "";
        let NomDate2 = "";
        let Rel_NomDate = "";
        let TitreExec = "";
        let CmdAExecuter_01 = "";
        let MinutesExec_01 = "";
        let CmdAExecuter_02 = "";
        let MinutesExec_02 = "";
        let CmdAExecuter_03 = "";
        let MinutesExec_03 = "";
        let DateExec = "";
        let JJExec = "";
        let MMExec = "";
        let AAExec = "";
        let Rel_NumLig = 0;
        
    // Relance et envoie les emails pour tous les traitements VISTA pour une date données.
    // => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa    
    // cd $ss
    // sh scripts_batch_auto_guichet.csh JJ MM AAAA    
        Rel_NumLig = Rel_NumLig + 1;
        TitreExec = "Relance et envoie les emails pour tous les traitements VISTA pour une date données => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa";
        TitreExec = TitreExec + "<br />" + "(cd $ss;sh scripts_batch_auto_guichet.csh JJ MM AAAA)";
        NomLig = "L" + twoDigit(Rel_NumLig);
        NomCell = "C01";
        InsertLig = TabRelanceByID.insertRow(-1);
        InsertLig.id = NomLig;
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        InsertCell.innerHTML = TitreExec;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col3");
        NomCell = "C02";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        NomDate = "Rel_date_deb_" + twoDigit(Rel_NumLig)
        Rel_NomDate = "<INPUT class='' name='" + NomDate +"' id='" + NomDate+ "' type='text';></INPUT>";
        InsertCell.innerHTML = Rel_NomDate;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        datePickerInit(dayInitAlt_Rel, NomDate, "dd/mm/yy"); // 
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        NomCell = "C03";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        BtnCell = document.createElement("button");
        BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig);
        BtnCell.title = "Exécution : " + TitreExec;
        DateExec = $('input[name=' + NomDate + ']').val();
        JJExec = DateExec.substr(0, 2);
        MMExec = DateExec.substr(3, 2);
        AAExec = DateExec.substr(6, 4);     
        CmdAExecuter_01 = "cd $ss;";
        CmdAExecuter_01 = CmdAExecuter_01 + "sh scripts_batch_auto_guichet.csh ";
        CmdAExecuter_01 = CmdAExecuter_01 + JJExec + " " + MMExec + " " + AAExec;
        CmdAExecuter_01 = CmdAExecuter_01 + " &";    
        MinutesExec_01 = "1234567";
        BtnCell.onclick = function()
        {
            ExecSSH(CmdAExecuter_01, MinutesExec_01);
        };
        InsertCell.appendChild(BtnCell);
        BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center";
        InsertCell.classList.add("text-center");
        InsertCell.classList.add("CentrageVerticalForce");
        InsertCell.classList.add("Table_Largeur_Col6");
    // Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS
    // cd $ss
    // sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7
    // sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7
    // sh go.fab.stats.vista.annee.candidate.csh aaaa
        Rel_NumLig = Rel_NumLig + 1;
        TitreExec = "Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS";
        TitreExec = TitreExec + "<br />" + "(cd $ss;sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7;<br />sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7;<br />sh go.fab.stats.vista.annee.candidate.csh aaaa)";
        NomLig = "L" + twoDigit(Rel_NumLig);
        NomCell = "C01";
        InsertLig = TabRelanceByID.insertRow(-1);
        InsertLig.id = NomLig;
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        InsertCell.innerHTML = TitreExec;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col3");
        NomCell = "C02";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        NomDate = "Rel_date_deb_" + twoDigit(Rel_NumLig)
        Rel_NomDate = "<INPUT class='' name='" + NomDate +"' id='" + NomDate+ "' type='text';></INPUT>";
        InsertCell.innerHTML = Rel_NomDate;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        datePickerInit(dayInitAlt_Rel, NomDate, "dd/mm/yy"); // 
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        NomCell = "C03";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        BtnCell = document.createElement("button");
        BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig);
        BtnCell.title = "Exécution : " + TitreExec;
        DateExec = $('input[name=' + NomDate + ']').val();
        JJExec = DateExec.substr(0, 2);
        MMExec = DateExec.substr(3, 2);
        AAExec = DateExec.substr(6, 4);     
        CmdAExecuter_02 = "cd $ss;";
        CmdAExecuter_02 = CmdAExecuter_02 + "sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7 ";
        CmdAExecuter_02 = CmdAExecuter_02 + JJExec + " " + MMExec + " " + AAExec + ";";
        CmdAExecuter_02 = CmdAExecuter_02 + "sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7 ";
        CmdAExecuter_02 = CmdAExecuter_02 + JJExec + " " + MMExec + " " + AAExec + ";";
        CmdAExecuter_02 = CmdAExecuter_02 + "sh go.fab.stats.vista.annee.candidate.csh aaaa ";
        CmdAExecuter_02 = CmdAExecuter_02 + AAExec;
        CmdAExecuter_02 = CmdAExecuter_02 + " &";    
        MinutesExec_02 = "1234567";
        BtnCell.onclick = function()
        {
            ExecSSH(CmdAExecuter_02, MinutesExec_02);
        };
        InsertCell.appendChild(BtnCell);
        BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center";
        InsertCell.classList.add("text-center");
        InsertCell.classList.add("CentrageVerticalForce");
        InsertCell.classList.add("Table_Largeur_Col6");
    ...
    ...
    ...

    Mais lorsque j'essaye de limiter le nombre de variables en passant par un tableau, le contenu du tableau est toujours écrasé par la dernière affectation.
    Ainsi je me retrouve avec CmdAExecuter[1] qui contient la même chose que CmdAExecuter[2].

    J'espère que je suis assez clair dans mes explication et que vous pourrez m'aider.
    Merci d'avance.

    Code javascript : 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
    140
    141
    142
    143
    144
    145
    146
    function ChargementTableRelance()
    {
        var day = new Date();
        day.setDate(day.getDate() - 1); // On sélectionne le jour précédent
        var mm = ((day.getMonth() + 1) < 10) ? '0' + (day.getMonth() + 1) : (day.getMonth() + 1);
        var dd = (day.getDate() < 10) ? '0' + day.getDate() : day.getDate();
        var dayInit_Rel = day.getFullYear().toString() + mm + dd;
        var dayInitAlt_Rel = dd + "/" + mm + "/" + day.getFullYear(); // Utiliser pour le nouveau DatePicket
    
        let TabRelanceByID = document.getElementById("table_relance");
        let InsertLig = "";
        let InsertCell = "";
        let NomLig = "";
        let NomCell = "";
        let BtnCell = "";
        let NomDate = "";
        let NomDate2 = "";
        let Rel_NomDate = "";
        let TitreExec = "";
        let CmdAExecuter_01 = "";
        let MinutesExec_01 = "";
        let CmdAExecuter_02 = "";
        let MinutesExec_02 = "";
        let CmdAExecuter_03 = "";
        let MinutesExec_03 = "";
        let DateExec = "";
        let JJExec = "";
        let MMExec = "";
        let AAExec = "";
        let Rel_NumLig = 0;
    	let NumAction = 0;
    	let CmdAExecuter = [];
    	let Minutes = [];
    	let cmd = "";
    	let min = "";
        
    // Relance et envoie les emails pour tous les traitements VISTA pour une date données.
    // => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa    
    // cd $ss
    // sh scripts_batch_auto_guichet.csh JJ MM AAAA    
        Rel_NumLig = Rel_NumLig + 1;
    	NumAction = 1;
        TitreExec = "Relance et envoie les emails pour tous les traitements VISTA pour une date données => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa";
        TitreExec = TitreExec + "<br />" + "(cd $ss;sh scripts_batch_auto_guichet.csh JJ MM AAAA)";
        NomLig = "L" + twoDigit(Rel_NumLig);
        NomCell = "C01";
        InsertLig = TabRelanceByID.insertRow(-1);
        InsertLig.id = NomLig;
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        InsertCell.innerHTML = TitreExec;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col3");
        NomCell = "C02";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        NomDate = "Rel_date_deb_" + twoDigit(Rel_NumLig)
        Rel_NomDate = "<INPUT class='' name='" + NomDate +"' id='" + NomDate+ "' type='text';></INPUT>";
        InsertCell.innerHTML = Rel_NomDate;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        datePickerInit(dayInitAlt_Rel, NomDate, "dd/mm/yy"); // 
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        NomCell = "C03";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        BtnCell = document.createElement("button");
        BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig);
        BtnCell.title = "Exécution : " + TitreExec;
        DateExec = $('input[name=' + NomDate + ']').val();
        JJExec = DateExec.substr(0, 2);
        MMExec = DateExec.substr(3, 2);
        AAExec = DateExec.substr(6, 4);     
        CmdAExecuter[NumAction] = "cd $ss;";
        CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + "sh scripts_batch_auto_guichet.csh ";
        CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + JJExec + " " + MMExec + " " + AAExec;
        CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + " &";    
        Minutes[NumAction] = "1234567";
        BtnCell.onclick = function()
        {
            ExecSSH(CmdAExecuter[NumAction], Minutes[NumAction]);
        };
        InsertCell.appendChild(BtnCell);
        BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center";
        InsertCell.classList.add("text-center");
        InsertCell.classList.add("CentrageVerticalForce");
        InsertCell.classList.add("Table_Largeur_Col6");
    // Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS
    // cd $ss
    // sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7
    // sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7
    // sh go.fab.stats.vista.annee.candidate.csh aaaa
        Rel_NumLig = Rel_NumLig + 1;
    	NumAction = 2;
        TitreExec = "Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS";
        TitreExec = TitreExec + "<br />" + "(cd $ss;sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7;<br />sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7;<br />sh go.fab.stats.vista.annee.candidate.csh aaaa)";
        NomLig = "L" + twoDigit(Rel_NumLig);
        NomCell = "C01";
        InsertLig = TabRelanceByID.insertRow(-1);
        InsertLig.id = NomLig;
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        InsertCell.innerHTML = TitreExec;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col3");
        NomCell = "C02";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        NomDate = "Rel_date_deb_" + twoDigit(Rel_NumLig)
        Rel_NomDate = "<INPUT class='' name='" + NomDate +"' id='" + NomDate+ "' type='text';></INPUT>";
        InsertCell.innerHTML = Rel_NomDate;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        datePickerInit(dayInitAlt_Rel, NomDate, "dd/mm/yy"); // 
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        NomCell = "C03";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        BtnCell = document.createElement("button");
        BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig);
        BtnCell.title = "Exécution : " + TitreExec;
        DateExec = $('input[name=' + NomDate + ']').val();
        JJExec = DateExec.substr(0, 2);
        MMExec = DateExec.substr(3, 2);
        AAExec = DateExec.substr(6, 4);     
        CmdAExecuter[NumAction] = "cd $ss;";
        CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + "sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7 ";
        CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + JJExec + " " + MMExec + " " + AAExec + ";";
        CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + "sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7 ";
        CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + JJExec + " " + MMExec + " " + AAExec + ";";
        CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + "sh go.fab.stats.vista.annee.candidate.csh aaaa ";
        CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + AAExec;
        CmdAExecuter[NumAction] = CmdAExecuter[NumAction] + " &";    
        MinutesExec_02 = "1234567";
        BtnCell.onclick = function()
        {
            ExecSSH(CmdAExecuter[NumAction], MinutesExec[NumAction]);
        };
        InsertCell.appendChild(BtnCell);
        BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center";
        InsertCell.classList.add("text-center");
        InsertCell.classList.add("CentrageVerticalForce");
        InsertCell.classList.add("Table_Largeur_Col6");

    C'est sûrement un truc tout bête, mais impossible de mettre le doigt dessus.
    Zeb'...

  2. #2
    Expert confirmé Avatar de Toufik83
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2012
    Messages
    2 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Suisse

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2012
    Messages : 2 412
    Points : 4 854
    Points
    4 854
    Par défaut
    Bonjour,

    et si tu incrémente la valeur de NumAction avant chaque ajout ?

    Ligne 127 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    AAExec = DateExec.substr(6, 4);
    NumAction++; //incrémenter la variable +1    
    CmdAExecuter[NumAction] = "cd $ss;";
    Toujours le même problème?

    Attention aussi à la ligne 139 :MinutesExec[]NumAction, la variable NumAction doit être à l'intérieur des crochets MinutesExec[NumAction]

  3. #3
    Membre actif Avatar de Zebulon777
    Homme Profil pro
    Informaticien
    Inscrit en
    Février 2005
    Messages
    1 319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien

    Informations forums :
    Inscription : Février 2005
    Messages : 1 319
    Points : 286
    Points
    286
    Par défaut
    Merci pour essayer de m'aider.

    NumAction est bien modifié dans chaque "bloc", c'est justement ce que je croyais qu'il fallait faire pour que mes tableaux ne soient pas écrasé, mais ça ne change rien.
    (Regarde les lignes en bleu)

    Pour ce qui est de l'accolade, ça avait déjà été corrigé.
    Zeb'...

  4. #4
    Membre actif Avatar de Zebulon777
    Homme Profil pro
    Informaticien
    Inscrit en
    Février 2005
    Messages
    1 319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien

    Informations forums :
    Inscription : Février 2005
    Messages : 1 319
    Points : 286
    Points
    286
    Par défaut
    J'ai essayé pas mal de choses dans mon code, mais je ne comprends toujours pas pourquoi tout est à chaque fois écrasé...
    Je m'arrache les cheveux
    Zeb'...

  5. #5
    Membre actif Avatar de Zebulon777
    Homme Profil pro
    Informaticien
    Inscrit en
    Février 2005
    Messages
    1 319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien

    Informations forums :
    Inscription : Février 2005
    Messages : 1 319
    Points : 286
    Points
    286
    Par défaut
    Voila la dernière mouture :
    Code javascript : 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
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
     
    function ChargementTableRelance()
    {
        var day = new Date();
        day.setDate(day.getDate() - 1); // On sélectionne le jour précédent
        var mm = ((day.getMonth() + 1) < 10) ? '0' + (day.getMonth() + 1) : (day.getMonth() + 1);
        var dd = (day.getDate() < 10) ? '0' + day.getDate() : day.getDate();
        var dayInit_Rel = day.getFullYear().toString() + mm + dd;
        var dayInitAlt_Rel = dd + "/" + mm + "/" + day.getFullYear(); // Utiliser pour le nouveau DatePicket
     
        let TabRelanceByID = document.getElementById("table_relance");
     
        let InsertLig = "";
        let InsertCell = "";
        let NomLig = "";
        let NomCell = "";
        let BtnCell = "";
        let NomDate = "";
        let NomDate2 = "";
        let Rel_NomDate = "";
        let TitreExec = "";
        let CmdAExecuter_01 = "";
        let MinutesExec_01 = "";
        let CmdAExecuter_02 = "";
        let MinutesExec_02 = "";
        let CmdAExecuter_03 = "";
        let MinutesExec_03 = "";
        let DateExec = "";
        let JJExec = "";
        let MMExec = "";
        let AAExec = "";
        let Rel_NumLig = 0;
        let Cmd = "";
        let Min = "";
        let NumAction = 0;
        let TabCmd = [];
        let TabMin = [];
     
    // Relance et envoie les emails pour tous les traitements VISTA pour une date données.
    // => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa    
    // cd $ss
    // sh scripts_batch_auto_guichet.csh JJ MM AAAA    
        Rel_NumLig = Rel_NumLig + 1;
        TitreExec = "Relance et envoie les emails pour tous les traitements VISTA pour une date données => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa";
        TitreExec = TitreExec + "<br />" + "(cd $ss;sh scripts_batch_auto_guichet.csh JJ MM AAAA)";
        NomLig = "L" + twoDigit(Rel_NumLig);
        NomCell = "C01";
        InsertLig = TabRelanceByID.insertRow(-1);
        InsertLig.id = NomLig;
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        InsertCell.innerHTML = TitreExec;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col3");
        NomCell = "C02";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        NomDate = "Rel_date_deb_" + twoDigit(Rel_NumLig);
        Rel_NomDate = "<INPUT class='' name='" + NomDate +"' id='" + NomDate+ "' type='text';></INPUT>";
        InsertCell.innerHTML = Rel_NomDate;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        datePickerInit(dayInitAlt_Rel, NomDate, "dd/mm/yy"); // 
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        NomCell = "C03";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        BtnCell = document.createElement("button");
        BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig);
        BtnCell.title = "Exécution : " + TitreExec;
        DateExec = $('input[name=' + NomDate + ']').val();
        JJExec = DateExec.substr(0, 2);
        MMExec = DateExec.substr(3, 2);
        AAExec = DateExec.substr(6, 4);
    //    CmdAExecuter_01 = "cd $ss;";
    //    CmdAExecuter_01 = CmdAExecuter_01 + "sh scripts_batch_auto_guichet.csh ";
    //    CmdAExecuter_01 = CmdAExecuter_01 + JJExec + " " + MMExec + " " + AAExec;
    //    CmdAExecuter_01 = CmdAExecuter_01 + " &";    
    //    MinutesExec_01 = "1234567";
    //    BtnCell.onclick = function()
    //    {
    //        ExecSSH(CmdAExecuter_01, MinutesExec_01);
    //    };
        Cmd = "cd $ss;";
        Cmd = Cmd + "sh scripts_batch_auto_guichet.csh ";
        Cmd = Cmd + JJExec + " " + MMExec + " " + AAExec;
        Cmd = Cmd + " &";    
        Min = "1234567";
        NumAction = 1;
        TabCmd[NumAction] = Cmd;
        TabMin[NumAction] = Min;
        BtnCell.onclick = function()
        {
            ExecSSH(TabCmd[NumAction], TabMin[NumAction]);
        };
        InsertCell.appendChild(BtnCell);
        BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center";
        InsertCell.classList.add("text-center");
        InsertCell.classList.add("CentrageVerticalForce");
        InsertCell.classList.add("Table_Largeur_Col6");
    // Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS
    // cd $ss
    // sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7
    // sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7
    // sh go.fab.stats.vista.annee.candidate.csh aaaa
        Rel_NumLig = Rel_NumLig + 1;
        TitreExec = "Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS";
        TitreExec = TitreExec + "<br />" + "(cd $ss;sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7;<br />sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7;<br />sh go.fab.stats.vista.annee.candidate.csh aaaa)";
        NomLig = "L" + twoDigit(Rel_NumLig);
        NomCell = "C01";
        InsertLig = TabRelanceByID.insertRow(-1);
        InsertLig.id = NomLig;
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        InsertCell.innerHTML = TitreExec;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col3");
        NomCell = "C02";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        NomDate = "Rel_date_deb_" + twoDigit(Rel_NumLig)
        Rel_NomDate = "<INPUT class='' name='" + NomDate +"' id='" + NomDate+ "' type='text';></INPUT>";
        InsertCell.innerHTML = Rel_NomDate;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        datePickerInit(dayInitAlt_Rel, NomDate, "dd/mm/yy"); // 
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        NomCell = "C03";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        BtnCell = document.createElement("button");
        BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig);
        BtnCell.title = "Exécution : " + TitreExec;
        DateExec = $('input[name=' + NomDate + ']').val();
        JJExec = DateExec.substr(0, 2);
        MMExec = DateExec.substr(3, 2);
        AAExec = DateExec.substr(6, 4);     
    //    CmdAExecuter_02 = "cd $ss;";
    //    CmdAExecuter_02 = CmdAExecuter_02 + "sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7 ";
    //    CmdAExecuter_02 = CmdAExecuter_02 + JJExec + " " + MMExec + " " + AAExec + ";";
    //    CmdAExecuter_02 = CmdAExecuter_02 + "sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7 ";
    //    CmdAExecuter_02 = CmdAExecuter_02 + JJExec + " " + MMExec + " " + AAExec + ";";
    //    CmdAExecuter_02 = CmdAExecuter_02 + "sh go.fab.stats.vista.annee.candidate.csh aaaa ";
    //    CmdAExecuter_02 = CmdAExecuter_02 + AAExec;
    //    CmdAExecuter_02 = CmdAExecuter_02 + " &";    
    //    MinutesExec_02 = "1234567";
    //    BtnCell.onclick = function()
    //    {
    //        ExecSSH(CmdAExecuter_02, MinutesExec_02);
    //    };
        Cmd = "cd $ss;";
        Cmd = Cmd + "sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7 ";
        Cmd = Cmd + JJExec + " " + MMExec + " " + AAExec + ";";
        Cmd = Cmd + "sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7 ";
        Cmd = Cmd + JJExec + " " + MMExec + " " + AAExec + ";";
        Cmd = Cmd + "sh go.fab.stats.vista.annee.candidate.csh aaaa ";
        Cmd = Cmd + AAExec;
        Cmd = Cmd + " &";    
        Min = "1234567";
        NumAction = 2;
        TabCmd[NumAction] = Cmd;
        TabMin[NumAction] = Min;
        BtnCell.onclick = function()
        {
            ExecSSH(TabCmd[NumAction], TabMin[NumAction]);
        };
        InsertCell.appendChild(BtnCell);
        BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center";
        InsertCell.classList.add("text-center");
        InsertCell.classList.add("CentrageVerticalForce");
        InsertCell.classList.add("Table_Largeur_Col6");
    // Relance du CRAQ LIGHT
        Rel_NumLig = Rel_NumLig + 1;
        TitreExec = "CRAQ : Relance du CRAQ LIGHT => sera toujours envoyé à <b>philippe.hurdyk@regis-dgac.net</b>";
        TitreExec = TitreExec + "<br />" + "(cd $ss;sh requete_auto_stat_qse_craq.csh philippe.hurdyk@regis-dgac.net  jj mm aaaa)";
        NomLig = "L" + twoDigit(Rel_NumLig);
        NomCell = "C01";
        InsertLig = TabRelanceByID.insertRow(-1);
        InsertLig.id = NomLig;
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        InsertCell.innerHTML = TitreExec;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col3");
        NomCell = "C02";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        NomDate = "Rel_date_deb_" + twoDigit(Rel_NumLig)
        Rel_NomDate = "<INPUT class='' name='" + NomDate +"' id='" + NomDate+ "' type='text';></INPUT>";
        InsertCell.innerHTML = Rel_NomDate;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        datePickerInit(dayInitAlt_Rel, NomDate, "dd/mm/yy"); // 
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col4");
        NomCell = "C03";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        BtnCell = document.createElement("button");
        BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig);
        BtnCell.title = "Exécution : " + TitreExec;
        DateExec = $('input[name=' + NomDate + ']').val();
        JJExec = DateExec.substr(0, 2);
        MMExec = DateExec.substr(3, 2);
        AAExec = DateExec.substr(6, 4);     
    //    CmdAExecuter_03 = "cd $ss;";
    //    CmdAExecuter_03 = CmdAExecuter_03 + "sh requete_auto_stat_qse_craq.csh philippe.hurdyk@regis-dgac.net ";
    //    CmdAExecuter_03 = CmdAExecuter_03 + JJExec + " " + MMExec + " " + AAExec + ";";
    //    CmdAExecuter_03 = CmdAExecuter_03 + " &";    
    //    MinutesExec_03 = "1234567";
    //    BtnCell.onclick = function()
    //    {
    //        ExecSSH(CmdAExecuter_03, MinutesExec_03);
    //    };
        Cmd = "cd $ss;";
        Cmd = Cmd + "sh requete_auto_stat_qse_craq.csh philippe.hurdyk@regis-dgac.net ";
        Cmd = Cmd + JJExec + " " + MMExec + " " + AAExec + ";";
        Cmd = Cmd + " &";    
        Min = "1234567";
        NumAction = 3;
        TabCmd[NumAction] = Cmd;
        TabMin[NumAction] = Min;
        BtnCell.onclick = function()
        {
            ExecSSH(TabCmd[NumAction], TabMin[NumAction]);
        };
        InsertCell.appendChild(BtnCell);
        BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center";
        InsertCell.classList.add("text-center");
        InsertCell.classList.add("CentrageVerticalForce");
        InsertCell.classList.add("Table_Largeur_Col6");
     
    // Relance du CRAQ JOURNALIER    
    // Relance du CRAQ MENSUEL
    // Relance PotAG 
     
     
        console.log("TabCmd[1]="+TabCmd[1]);
        console.log("TabCmd[2]="+TabCmd[2]);
        console.log("TabCmd[3]="+TabCmd[3]);
     
    }
    /*--------------------------------------------------------------------------------------------------------*/
    function ExecSSH(P_Commande, P_Minutes)
    {
        let QuestionExec = "";
        QuestionExec = QuestionExec + "ATTENTION !" + G_CRLF + G_CRLF;
        QuestionExec = QuestionExec + "Le traitement ne pourra pas être interrompu." + G_CRLF + G_CRLF;
        QuestionExec = QuestionExec + "L'action qui sera exécutée est : " + G_CRLF + G_CRLF;
        QuestionExec = QuestionExec + P_Commande + G_CRLF + G_CRLF;
        QuestionExec = QuestionExec + "";
        QuestionExec = QuestionExec + "Veuillez confirmer votre demande S.V.P.";
        let Rep = window.confirm(QuestionExec);
        if (Rep)
        {
            QuestionExec = "Le traitement durera : " + P_Minutes + " minutes." + G_CRLF + G_CRLF;
            QuestionExec = QuestionExec + "CONFIRMEZ-VOUS SON EXECUTION ?"
            Rep = window.confirm(QuestionExec);
            if (Rep)
            {
                sshRun(P_Commande);
            }
            else
            {
                alert("Traitement annulé.")
            }
        }
        else
        {
            alert("Traitement non confirmé => Annulé");
        }
    }

    Les console.log donnent :
    Nom : Sans titre.png
Affichages : 123
Taille : 8,5 Ko
    Donc le contenu de TabCmd est bon.

    Mais dans la fonction ExecSSH, les paramètres contiennent toujours la dernière valeur.
    Je suis totalement paumé, je ne comprends pas.
    Zeb'...

  6. #6
    Expert confirmé Avatar de Toufik83
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2012
    Messages
    2 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Suisse

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2012
    Messages : 2 412
    Points : 4 854
    Points
    4 854
    Par défaut
    Bonjour,

    Tu peux copier le code des fonctions utilisées dans le code comme twoDigit et datePickerInit et sshRun, car je viens de tester et j'ai des erreurs...

  7. #7
    Membre actif Avatar de Zebulon777
    Homme Profil pro
    Informaticien
    Inscrit en
    Février 2005
    Messages
    1 319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien

    Informations forums :
    Inscription : Février 2005
    Messages : 1 319
    Points : 286
    Points
    286
    Par défaut
    Avec plaisir...
    Et merci pour le coup de main.

    TwoDigit met les chiffre sur 2 caractères.
    ExecSSH permet d'exécuter des commandes SSH sur notre réseau.
    datePickerInit est l'initialisation pour une sélection d'une date à travers un calendrier, considère que c'est une date au format JJ/MM/AAAA qui est mise dans des input :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    ...
    NomDate = "Rel_date_deb_" + twoDigit(Rel_NumLig)
        Rel_NomDate = "<INPUT class='' name='" + NomDate +"' id='" + NomDate+ "' type='text';></INPUT>";
        InsertCell.innerHTML = Rel_NomDate;
    ...
    Code javascript : 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
     
    <SCRIPT src="LIBRAIRIES/jquery-ui-1.12.1/datepicker-fr.js"></SCRIPT>
     
     
    function twoDigit(n) {
    // Met les chiffres sur 2 caractères.
      return (n < 10 ? '0' : '') + n
     
    }
     
    function ExecSSH(P_Commande, P_Minutes)
    {
     
    console.log("P_Commande="+P_Commande);
     
        let QuestionExec = "";
        QuestionExec = QuestionExec + "ATTENTION !" + G_CRLF + G_CRLF;
        QuestionExec = QuestionExec + "Le traitement ne pourra pas être interrompu." + G_CRLF + G_CRLF;
        QuestionExec = QuestionExec + "L'action qui sera exécutée est : " + G_CRLF + G_CRLF;
        QuestionExec = QuestionExec + P_Commande + G_CRLF + G_CRLF;
        QuestionExec = QuestionExec + "";
        QuestionExec = QuestionExec + "Veuillez confirmer votre demande S.V.P.";
        let Rep = window.confirm(QuestionExec);
        if (Rep)
        {
            QuestionExec = "Le traitement durera : " + P_Minutes + " minutes." + G_CRLF + G_CRLF;
            QuestionExec = QuestionExec + "CONFIRMEZ-VOUS SON EXECUTION ?"
            Rep = window.confirm(QuestionExec);
            if (Rep)
            {
                sshRun(P_Commande);
            }
            else
            {
                alert("Traitement annulé.")
            }
        }
        else
        {
            alert("Traitement non confirmé => Annulé");
        }
    }
    Zeb'...

  8. #8
    Expert confirmé Avatar de Toufik83
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2012
    Messages
    2 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Suisse

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2012
    Messages : 2 412
    Points : 4 854
    Points
    4 854
    Par défaut
    et celui de sshRun ?

  9. #9
    Membre actif Avatar de Zebulon777
    Homme Profil pro
    Informaticien
    Inscrit en
    Février 2005
    Messages
    1 319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien

    Informations forums :
    Inscription : Février 2005
    Messages : 1 319
    Points : 286
    Points
    286
    Par défaut
    Oups, désolé.
    La voici :
    Code javascript : 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
     
    function sshRun(cmd)
    {
    	let ip = G_SSH_IP;
    	let log = G_SSH_UTIL;
    	let pwd = G_SSH_MDP;
     
    	console.log(log + " " + pwd);
     
    	$.ajax(
        {
            type: "POST",
            url: "./php/sshRun.php",
            async: false,
    		data: {ip: ip, log : log, pwd : pwd, cmd : cmd},
            error : function(data)
            {
                alert("ECHEC DU TEST SSH : " + data);
            },
            success: function(data)
            {
    			console.log(data);
    		}
    	});
    }

    Code php : 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
     
    <?php
    	if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
    	// log in at server1.example.com on port 22
    	if(!($con = ssh2_connect($_POST['ip'], 22)))
    	{
    		echo "fail: unable to establish connection\n";
    	} 
    	else 
    	{
     
     
    		// try to authenticate with username root, password secretpassword
    		if(!ssh2_auth_password($con, $_POST['log'], $_POST['pwd'])) 
    		{
    			echo "fail: unable to authenticate\n";
    		} 
    		else 
    		{
    			// allright, we're in!
    			echo "okay: logged in...\n";
     
    			echo "Exécution de la commande ssh : " . $_POST["cmd"] . "\n";
     
    			$stream = ssh2_exec($con, $_POST["cmd"]);
    			stream_set_blocking($stream, true);
     
    			echo "Output: \n" . stream_get_contents($stream);
     
    			fclose($stream);
    		}
     
    	}
    ?>

    C'est juste une fonction qui nous permet d'exécuter des commande SSH sur nos machines linux, mais ça ne rentre pas en ligne de compte sur mon problème de portées...
    Zeb'...

  10. #10
    Expert confirmé Avatar de Toufik83
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2012
    Messages
    2 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Suisse

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2012
    Messages : 2 412
    Points : 4 854
    Points
    4 854
    Par défaut
    C'est bon j'ai identifié le problème, c'est NumAction qui est utilisé dans tout le script et sa dernière valeur attribuée est 3 (celle de la dernière étape) et donc quand tu fais :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    BtnCell.onclick = function() {
        ExecSSH(TabCmd[NumAction], TabMin[NumAction]);
    };
    La valeur de NumAction reste à 3 et c'est pour ça que cela te renvoi toujours le dernier élément du tableau.

    Pour éviter ceci, n'utilise pas NumAction dans click, essaies comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    TabCmd[1] = Cmd;
    TabMin[1] = Min;
    BtnCell.onclick = function() {
        ExecSSH(TabCmd[1], TabMin[1]);
    };
    utilise les indexes en tant que des chiffres : 1 puis 2 puis 3...

    Remarque : je vois que le code est répétitif et long, tu peux le factoriser en mettant les valeurs dans un tableau puis le parcourir avec une boucle pour créer dynamiquement les données de la page HTML.

  11. #11
    Membre actif Avatar de Zebulon777
    Homme Profil pro
    Informaticien
    Inscrit en
    Février 2005
    Messages
    1 319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien

    Informations forums :
    Inscription : Février 2005
    Messages : 1 319
    Points : 286
    Points
    286
    Par défaut
    Justement, c'est dans me but de factoriser tout ça (d'autant plus qu'il va y en avoir d'autres) que je voulais passer NumAction en paramètres.
    C'est ça que je ne comprends pas : dans le tableau, il y a bien les bonnes valeurs en fonction des indices.

    Ta solution fonctionne, c'est ce que je fais actuellement, mais je voulais justement paramétrer tout ça en vue de factoriser.

    Je suis persuadé qu'il y a une solution, mais je ne la trouve pas, pour le moment.
    Zeb'...

  12. #12
    Expert confirmé Avatar de Toufik83
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2012
    Messages
    2 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Suisse

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2012
    Messages : 2 412
    Points : 4 854
    Points
    4 854
    Par défaut
    L'idée est d'utiliser un tableau contenant des objets comme [{},{},{}] dans lequel tu stockes toutes les informations nécessaires de chaque item pour qu'ensuite le parcourir et générer ton HTML.

    J'essaierais de trouver une solution plus propre et moins longue quand j'aurais un peu de temps.

  13. #13
    Membre actif Avatar de Zebulon777
    Homme Profil pro
    Informaticien
    Inscrit en
    Février 2005
    Messages
    1 319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien

    Informations forums :
    Inscription : Février 2005
    Messages : 1 319
    Points : 286
    Points
    286
    Par défaut
    Alors là, je ne connais pas du tout cette histoire de tableau contenant des objets.
    Si tu as des exemples, je suis preneur.

    Ha, si tu trouves une solution, ça sera génial.

    En tout cas, merci beaucoup pour ton aide précieuse.
    Zeb'...

  14. #14
    Membre actif Avatar de Zebulon777
    Homme Profil pro
    Informaticien
    Inscrit en
    Février 2005
    Messages
    1 319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien

    Informations forums :
    Inscription : Février 2005
    Messages : 1 319
    Points : 286
    Points
    286
    Par défaut
    J'ai un peu simplifié et je continue...

    Code javascript : 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
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
     
    function ChargementTableRelance()
    {
        $('#table_relance').empty();
     
        var day = new Date();
        day.setDate(day.getDate() - 1); // On sélectionne le jour précédent
        var mm = ((day.getMonth() + 1) < 10) ? '0' + (day.getMonth() + 1) : (day.getMonth() + 1);
        var dd = (day.getDate() < 10) ? '0' + day.getDate() : day.getDate();
        var dayInit_Rel = day.getFullYear().toString() + mm + dd;
        var dayInitAlt_Rel = dd + "/" + mm + "/" + day.getFullYear(); // Utiliser pour le nouveau DatePicket
     
        let TabRelanceByID = document.getElementById("table_relance");
     
        let InsertLig = "";
        let InsertCell = "";
        let NomLig = "";
        let NomCell = "";
        let BtnCell = "";
        let NomDate = "";
        let NomDate2 = "";
        let Rel_NomDate = "";
        let TitreExec = "";
        let DateExec = "";
        let JJExec = "";
        let MMExec = "";
        let AAExec = "";
        let Rel_NumLig = 0;
        let Cmd = "";
        let Min = "";
        let NumAction = 0;
        let TabCmd = [];
        let TabMin = [];
     
    // Relance et envoie les emails pour tous les traitements VISTA pour une date données.
    // => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa    
    // cd $ss
    // sh scripts_batch_auto_guichet.csh JJ MM AAAA    
        Rel_NumLig = Rel_NumLig + 1;
        TitreExec = "Relance et envoie les emails pour tous les traitements VISTA pour une date données => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa";
        TitreExec = TitreExec + "<br />" + "(cd $ss;sh scripts_batch_auto_guichet.csh JJ MM AAAA)";
        NomLig = "L" + twoDigit(Rel_NumLig);
        NomCell = "C01";
        InsertLig = TabRelanceByID.insertRow(-1);
        InsertLig.id = NomLig;
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        InsertCell.innerHTML = TitreExec;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col3");
        NomCell = "C02";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        BtnCell = document.createElement("button");
        BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig);
        BtnCell.title = "Exécution : " + TitreExec;
        InsertCell.appendChild(BtnCell);
        BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center";
        InsertCell.classList.add("text-center");
        InsertCell.classList.add("CentrageVerticalForce");
        InsertCell.classList.add("Table_Largeur_Col6");
        BtnCell.onclick = function()
        {
            DateExec = $('#date_deb').datepicker("getDate");
            DateExec = FormatDate2(DateExec, "JJ/MM/AAAA");
            JJExec = DateExec.substr(0, 2);
            MMExec = DateExec.substr(3, 2);
            AAExec = DateExec.substr(6, 4);
            Cmd = "cd $ss;";
            Cmd = Cmd + "sh scripts_batch_auto_guichet.csh ";
            Cmd = Cmd + JJExec + " " + MMExec + " " + AAExec;
            Cmd = Cmd + " &";    
            Min = "1234567";
            NumAction = NumAction + 1;
            TabCmd[NumAction] = Cmd;
            TabMin[NumAction] = Min;
            ExecSSH(TabCmd[NumAction], TabMin[NumAction]);
        };
    // Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS
    // cd $ss
    // sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7
    // sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7
    // sh go.fab.stats.vista.annee.candidate.csh aaaa
        Rel_NumLig = Rel_NumLig + 1;
        TitreExec = "Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS";
        TitreExec = TitreExec + "<br />" + "(cd $ss;sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7;<br />sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7;<br />sh go.fab.stats.vista.annee.candidate.csh aaaa)";
        NomLig = "L" + twoDigit(Rel_NumLig);
        NomCell = "C01";
        InsertLig = TabRelanceByID.insertRow(-1);
        InsertLig.id = NomLig;
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        InsertCell.innerHTML = TitreExec;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col3");
        NomCell = "C02";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        BtnCell = document.createElement("button");
        BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig);
        BtnCell.title = "Exécution : " + TitreExec;
        InsertCell.appendChild(BtnCell);
        BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center";
        InsertCell.classList.add("text-center");
        InsertCell.classList.add("CentrageVerticalForce");
        InsertCell.classList.add("Table_Largeur_Col6");
        BtnCell.onclick = function()
        {
            DateExec = $('#date_deb').datepicker("getDate");
            DateExec = FormatDate2(DateExec, "JJ/MM/AAAA");
            JJExec = DateExec.substr(0, 2);
            MMExec = DateExec.substr(3, 2);
            AAExec = DateExec.substr(6, 4);
            Cmd = "cd $ss;";
            Cmd = Cmd + "sh go.fab.stats.vista.mois_candidate.csh ";
            Cmd = Cmd + MMExec + " " + AAExec + " traitement_tot_dep_arr_aerobahn_v7;";
            Cmd = Cmd + "sh go.fab.stats.vista.mois_candidate.csh ";
            Cmd = Cmd + MMExec + " " + AAExec + " traitement_tot_dep_arr_aerobahn_taxi_time_v7;";
            Cmd = Cmd + "sh go.fab.stats.vista.annee.candidate.csh ";
            Cmd = Cmd + AAExec;
            Cmd = Cmd + " &";    
            Min = "1234567";
            NumAction = NumAction + 1;
            TabCmd[NumAction] = Cmd;
            TabMin[NumAction] = Min;
            ExecSSH(TabCmd[NumAction], TabMin[NumAction]);
        };
    // Relance du CRAQ LIGHT
        Rel_NumLig = Rel_NumLig + 1;
        TitreExec = "CRAQ : Relance du CRAQ LIGHT";
        TitreExec = TitreExec + "<br />" + "(cd $ss;sh requete_auto_stat_qse_craq.csh " + G_UTIL + " jj mm aaaa)";
        NomLig = "L" + twoDigit(Rel_NumLig);
        NomCell = "C01";
        InsertLig = TabRelanceByID.insertRow(-1);
        InsertLig.id = NomLig;
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        InsertCell.innerHTML = TitreExec;
        InsertCell.className = "CentrageVerticalForce";
        InsertCell.classList.add("Table_Largeur_Col3");
        NomCell = "C02";
        InsertCell = InsertLig.insertCell(-1);
        InsertCell.id = NomLig + NomCell;
        BtnCell = document.createElement("button");
        BtnCell.id = "Rel_BTN" + twoDigit(Rel_NumLig);
        BtnCell.title = "Exécution : " + TitreExec;
        InsertCell.appendChild(BtnCell);
        BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center";
        InsertCell.classList.add("text-center");
        InsertCell.classList.add("CentrageVerticalForce");
        InsertCell.classList.add("Table_Largeur_Col6");
        BtnCell.onclick = function()
        {
            DateExec = $('#date_deb').datepicker("getDate");
            DateExec = FormatDate2(DateExec, "JJ/MM/AAAA");
            JJExec = DateExec.substr(0, 2);
            MMExec = DateExec.substr(3, 2);
            AAExec = DateExec.substr(6, 4);
            Cmd = "cd $ss;";
            Cmd = Cmd + "sh requete_auto_stat_qse_craq.csh " + G_UTIL + " ";
            Cmd = Cmd + JJExec + " " + MMExec + " " + AAExec;
            Cmd = Cmd + " &";    
            Min = "1234567";
            NumAction = NumAction + 1;
            TabCmd[NumAction] = Cmd;
            TabMin[NumAction] = Min;
            ExecSSH(TabCmd[NumAction], TabMin[NumAction]);
        };
     
    // Relance du CRAQ JOURNALIER    
    // Relance du CRAQ MENSUEL
    // Relance PotAG 
     
    }

    Je pense que je devrai pouvoir factoriser tout ce qui est avant le BtnCell.onclick.

    A suivre...
    Zeb'...

  15. #15
    Expert confirmé Avatar de Toufik83
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2012
    Messages
    2 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Suisse

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2012
    Messages : 2 412
    Points : 4 854
    Points
    4 854
    Par défaut
    Bonjour,

    Voilà la solution la plus simple que j'ai pu faire sauf qu'il faut remplacer les lignes jQuery par le code js pur pour ne pas mélanger les syntaxes..:
    Code : 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
     
     
     function ChargementTableRelance() {
       $('#table_relance').empty();
     
       var day = new Date();
       day.setDate(day.getDate() - 1); // On sélectionne le jour précédent
       var mm = ((day.getMonth() + 1) < 10) ? '0' + (day.getMonth() + 1) : (day.getMonth() + 1);
       var dd = (day.getDate() < 10) ? '0' + day.getDate() : day.getDate();
       var dayInit_Rel = day.getFullYear().toString() + mm + dd;
       var dayInitAlt_Rel = dd + "/" + mm + "/" + day.getFullYear(); // Utiliser pour le nouveau DatePicket
     
       let TabRelanceByID = document.getElementById("table_relance");
     
       let InsertLig = "";
       let InsertCell = "";
       let NomLig = "";
       let NomCell = "";
       let BtnCell = "";
       let NomDate = "";
       let NomDate2 = "";
       let Rel_NomDate = "";
       let TitreExec = "";
       let DateExec = "";
       let JJExec = "";
       let MMExec = "";
       let AAExec = "";
       let Rel_NumLig = 0;
       let Cmd = "";
       let Min = "";
       let NumAction = 0;
       let TabCmd = [];
       let TabMin = [];
       let G_UTIL = "";
       let data = {
         titre: ["Relance et envoie les emails pour tous les traitements VISTA pour " +
           "une date données => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa<br /> " +
           "(cd $ss;sh scripts_batch_auto_guichet.csh JJ MM AAAA)",
           "Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS" +
           "<br />" + "(cd $ss;sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7;" +
           "<br />sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7;" +
           "<br />sh go.fab.stats.vista.annee.candidate.csh aaaa)",
           "CRAQ : Relance du CRAQ LIGHT<br />(cd $ss;sh requete_auto_stat_qse_craq.csh " + G_UTIL + " jj mm aaaa)"
         ],
         cmd: ['cd $ss;sh scripts_batch_auto_guichet.csh ' + JJExec + " " + MMExec + " " + AAExec + " &",
           "cd $ss;sh go.fab.stats.vista.mois_candidate.csh " + MMExec + " " + AAExec + " traitement_tot_dep_arr_aerobahn_v7;" +
           "sh go.fab.stats.vista.mois_candidate.csh " + MMExec + " " + AAExec + " traitement_tot_dep_arr_aerobahn_taxi_time_v7;" +
           "sh go.fab.stats.vista.annee.candidate.csh " + AAExec + " &",
           "cd $ss;sh requete_auto_stat_qse_craq.csh " + G_UTIL + " " + JJExec + " " + MMExec + " " + AAExec + " &"
         ],
         class: ["CentrageVerticalForce Table_Largeur_Col3",
           "text-center CentrageVerticalForce Table_Largeur_Col6"
         ],
         nom: ['C01', 'C02']
       };
     
        //pour chaque valeur du tableau titre de l'objet data :
       data.titre
         .forEach((vTitre, cTitre) => {
           NomLig = "L" + twoDigit(cTitre + 1);
           InsertLig = TabRelanceByID.insertRow(-1);
           InsertLig.id = NomLig;
           //pour chaque valeur dans data.nom on crée un td :
           data.nom
             .forEach((valNom, cleNom) => {
               InsertCell = InsertLig.insertCell(-1);
               InsertCell.id = NomLig + valNom;
               InsertCell.className = data.class[cleNom];
               //cleNom c'est l'index du tableau, donc soit 0 ou 1, puisqu'il ne contient que deux valeurs "C01" et "C02" 
               switch (cleNom) {
                 case 0:
                   //quand l'index "cleNom" est 0 on met seulement le texte dans le td
                   InsertCell.innerHTML = vTitre;
                   break;
                 case 1:
                   //quand l'index est 1, on crée un bouton avec ses attributs... puis l'insérer dans le td
                   BtnCell = document.createElement("button");
                   BtnCell.id = "Rel_BTN" + twoDigit(cTitre + 1);
                   BtnCell.title = "Exécution : " + vTitre;
                   BtnCell.innerHTML = 'Ok';
                   InsertCell.appendChild(BtnCell);
                   BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center";
                   BtnCell.onclick = function() {
                      DateExec = $('#date_deb').datepicker("getDate");
                      DateExec = FormatDate2(DateExec, "JJ/MM/AAAA");
                      JJExec = DateExec.substr(0, 2);
                      MMExec = DateExec.substr(3, 2);
                      AAExec = DateExec.substr(6, 4);
                      Cmd = data.cmd[cTitre];
                      Min = "1234567";
                      ExecSSH(Cmd, Min);
                   }
                   break;
               }
             });
         });
     }
    Après avoir analyser le code, on voit bien que seulement les titres, id, cmd et class qui changent, donc j'ai utilisé la variable data en tant qu'un objet json {"titre":[..],"cmd":[...],"nom":[...],"class":[...]} contenant les clés titre,cmd,class,nom représentées par des tableaux.

    Les <tr> du tableau HTML sont générés en fonction de la longueur du tableau data.titre (on a 3 titres donc 3 <tr> seront générés), et les <td> en fonction de la longueur du tableau data.nom (2 valeurs, donc 2 td seront générés pour chaque ligne).

  16. #16
    Membre actif Avatar de Zebulon777
    Homme Profil pro
    Informaticien
    Inscrit en
    Février 2005
    Messages
    1 319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien

    Informations forums :
    Inscription : Février 2005
    Messages : 1 319
    Points : 286
    Points
    286
    Par défaut
    Merci beaucoup pour ta solution.
    J'essaye de la mettre en place ASAP, et je te tiens au courant.
    Merci encore pour on aide et ta patience.
    Zeb'...

  17. #17
    Membre actif Avatar de Zebulon777
    Homme Profil pro
    Informaticien
    Inscrit en
    Février 2005
    Messages
    1 319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien

    Informations forums :
    Inscription : Février 2005
    Messages : 1 319
    Points : 286
    Points
    286
    Par défaut
    Voila, j'ai enfin pu prendre le temps de faire le test et c'est presque bon.

    Tout fonctionne, SAUF que les variables G_UTIL, JJExec, MMExec et AAExec ne sont pas prises en comptes.
    Zeb'...

  18. #18
    Membre actif Avatar de Zebulon777
    Homme Profil pro
    Informaticien
    Inscrit en
    Février 2005
    Messages
    1 319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien

    Informations forums :
    Inscription : Février 2005
    Messages : 1 319
    Points : 286
    Points
    286
    Par défaut
    J'ai trouvé.
    Il y avait un problème d'initialisation.

    Code javascript : 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
     
    function ChargementTableRelance() {
        $('#table_relance').empty();
     
        var day = new Date();
        day.setDate(day.getDate() - 1); // On sélectionne le jour précédent
        var mm = ((day.getMonth() + 1) < 10) ? '0' + (day.getMonth() + 1) : (day.getMonth() + 1);
        var dd = (day.getDate() < 10) ? '0' + day.getDate() : day.getDate();
        var dayInit_Rel = day.getFullYear().toString() + mm + dd;
        var dayInitAlt_Rel = dd + "/" + mm + "/" + day.getFullYear(); // Utiliser pour le nouveau DatePicket
     
        let TabRelanceByID = document.getElementById("table_relance");
     
        let InsertLig = "";
        let InsertCell = "";
        let NomLig = "";
        let NomCell = "";
        let BtnCell = "";
        let NomDate = "";
        let NomDate2 = "";
        let Rel_NomDate = "";
        let TitreExec = "";
        let DateExec = "";
        let JJExec = "";
        let MMExec = "";
        let AAExec = "";
        let Rel_NumLig = 0;
        let Cmd = "";
        let Min = "";
        let NumAction = 0;
        let TabCmd = [];
        let TabMin = [];
     
        DateExec = $('#date_deb').datepicker("getDate");
        DateExec = FormatDate2(DateExec, "JJ/MM/AAAA");
        JJExec = DateExec.substr(0, 2);
        MMExec = DateExec.substr(3, 2);
        AAExec = DateExec.substr(6, 4);
     
        let data = {
            titre: ["Relance et envoie les emails pour tous les traitements VISTA pour " +
            "une date données => reconstitue le répertoire $visu/aaaa/mm/oljjmmaaaa<br /> " +
            "(cd $ss;sh scripts_batch_auto_guichet.csh JJ MM AAAA)",
            "Relance fichiers mensuels ou annuels incomplets => IL FAUT EXECUTER LES 3 SCRIPTS" +
            "<br />" + "(cd $ss;sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_v7;" +
            "<br />sh go.fab.stats.vista.mois_candidate.csh mm aaaa traitement_tot_dep_arr_aerobahn_taxi_time_v7;" +
            "<br />sh go.fab.stats.vista.annee.candidate.csh aaaa)",
            "CRAQ : Relance du CRAQ LIGHT<br />(cd $ss;sh requete_auto_stat_qse_craq.csh " + G_UTIL + " jj mm aaaa)",
            "CRAQ : Relance du CRAQ journalier",
            "CRAQ : Relance du CRAQ mensuel",
            "PotAG : Relance du PotAG journalier",
            "PotAG : Relance du PotAG mensuel",
            ],
            cmd: ['cd $ss;sh scripts_batch_auto_guichet.csh ' + JJExec + " " + MMExec + " " + AAExec + " &",
            "cd $ss;sh go.fab.stats.vista.mois_candidate.csh " + MMExec + " " + AAExec + " traitement_tot_dep_arr_aerobahn_v7;" +
            "sh go.fab.stats.vista.mois_candidate.csh " + MMExec + " " + AAExec + " traitement_tot_dep_arr_aerobahn_taxi_time_v7;" +
            "sh go.fab.stats.vista.annee.candidate.csh " + AAExec + " &",
            "cd $ss;sh requete_auto_stat_qse_craq.csh " + G_UTIL + " " + JJExec + " " + MMExec + " " + AAExec + " &",
            "",
            "",
            "",
            ""
            ],
            class: ["CentrageVerticalForce Table_Largeur_Col3",
            "text-center CentrageVerticalForce Table_Largeur_Col6"
            ],
            nom: ['C01', 'C02']
        };
     
        //pour chaque valeur du tableau titre de l'objet data :
        data.titre
            .forEach((vTitre, cTitre) => {
                NomLig = "L" + twoDigit(cTitre + 1);
                InsertLig = TabRelanceByID.insertRow(-1);
                InsertLig.id = NomLig;
        //pour chaque valeur dans data.nom on crée un td :
                data.nom
                    .forEach((valNom, cleNom) => {
                        InsertCell = InsertLig.insertCell(-1);
                        InsertCell.id = NomLig + valNom;
                        InsertCell.className = data.class[cleNom];
        //cleNom c'est l'index du tableau, donc soit 0 ou 1, puisqu'il ne contient que deux valeurs "C01" et "C02" 
                        switch (cleNom) {
                            case 0:
                        //quand l'index "cleNom" est 0 on met seulement le texte dans le td
                                InsertCell.innerHTML = vTitre;
                                break;
                            case 1:
                        //quand l'index est 1, on crée un bouton avec ses attributs... puis l'insérer dans le td
                                BtnCell = document.createElement("button");
                                BtnCell.id = "Rel_BTN" + twoDigit(cTitre + 1);
                                BtnCell.title = "Exécution : " + vTitre;
                                BtnCell.innerHTML = '';
                                InsertCell.appendChild(BtnCell);
                                BtnCell.className = "btn btn-warning fas fa-rocket fa-2x center";
                                BtnCell.onclick = function() {
                                    DateExec = $('#date_deb').datepicker("getDate");
                                    DateExec = FormatDate2(DateExec, "JJ/MM/AAAA");
                                    JJExec = DateExec.substr(0, 2);
                                    MMExec = DateExec.substr(3, 2);
                                    AAExec = DateExec.substr(6, 4);
                                    Cmd = data.cmd[cTitre];
                                    Min = "1234567";
                                    ExecSSH(Cmd, Min);
                                }
                                break;
                        }
                    });
            });
    }

    Encore un grand merci pour ton aide.
    Zeb'...

  19. #19
    Expert confirmé Avatar de Toufik83
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2012
    Messages
    2 412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : Suisse

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2012
    Messages : 2 412
    Points : 4 854
    Points
    4 854
    Par défaut
    Bonjour,

    Tu peux aussi supprimer les autres variables que tu n'utilises pas comme les deux tableaux TabCmd et TabMin et le NumAction :
    let NumAction = 0;let TabCmd = [];let TabMin = [];

  20. #20
    Membre actif Avatar de Zebulon777
    Homme Profil pro
    Informaticien
    Inscrit en
    Février 2005
    Messages
    1 319
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Informaticien

    Informations forums :
    Inscription : Février 2005
    Messages : 1 319
    Points : 286
    Points
    286
    Par défaut
    Absolument, j'avais oublié de le faire.
    Merci.
    Zeb'...

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. [FLASH MX] Portée des variables ???
    Par mic79 dans le forum Flash
    Réponses: 2
    Dernier message: 08/02/2005, 10h21
  2. Portée des variables vbscript vers ASP
    Par Immobilis dans le forum ASP
    Réponses: 3
    Dernier message: 03/11/2004, 10h14
  3. [XSL]Problème de portée des variables
    Par djulesp dans le forum XSL/XSLT/XPATH
    Réponses: 6
    Dernier message: 17/09/2004, 10h34
  4. [Portée] portée des variables
    Par parksto dans le forum Langage
    Réponses: 7
    Dernier message: 09/05/2004, 21h05
  5. [FLASH MX 2004][XML]portée de variable
    Par marco_ dans le forum Flash
    Réponses: 8
    Dernier message: 29/04/2004, 15h47

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