Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Première utilisation de VueJS (#760)
Browse files Browse the repository at this point in the history
* Use VueJS

* Add script vue

* First vuejs plannings

* Liste planning OK

* Inexistante fonction

* Association

* Remove hello

* This is an object

* WIP - JS API call for planning

* main-content is a container for VueJS

* VueJS + axios = first JS call

* Remove php var

* import nouvelle api

* WIP - type_absence

* WIP - use vue for type_absence

* Absence list via Vue and loader

* Security empty list

* Added axios

* Suite rebase

* Encore
  • Loading branch information
prytoegrian authored Dec 27, 2018
1 parent cd4e2b6 commit 1e9037b
Show file tree
Hide file tree
Showing 27 changed files with 405 additions and 521 deletions.
5 changes: 4 additions & 1 deletion App/ProtoControllers/Utilisateur.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ public static function getEmailUtilisateur($login) {
*
* @return array
*/
public static function getListByPlanning($planningId)
public static function getListByPlanning($planningId) : array
{
$planningId = (int) $planningId;
if (NIL_INT === $planningId) {
return [];
}
$sql = \includes\SQL::singleton();
$req = 'SELECT *
FROM conges_users
Expand Down
1 change: 0 additions & 1 deletion App/Tools/destroy
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env php
<?php
require_once 'libraries';
require_once CONFIG_PATH . 'dbconnect.php';

define('INSTALLATION_PATH', PATCH_PATH . DS . 'Installation' . DS);
define('API_SYSPATH', ROOT_PATH . 'vendor' . DS . 'libertempo' . DS . 'api' . DS);
Expand Down
1 change: 0 additions & 1 deletion App/Tools/libraries
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ define('LAST_VERSION_FILE', '/tmp/lt-last-version');
define('LOCALE_PATH', ROOT_PATH . 'locale/');

require_once ROOT_PATH . 'vendor/autoload.php';
require_once INCLUDE_PATH . 'fonctions.php';
if (is_file(CONFIG_PATH . 'dbconnect.php')) {
require_once CONFIG_PATH . 'dbconnect.php';
}
Expand Down
195 changes: 140 additions & 55 deletions App/Views/Configuration/Type_Absence/Liste.php
Original file line number Diff line number Diff line change
@@ -1,68 +1,153 @@
<?php
/*
* $listeTypeConges
* $url
* $nouveauLibelle
* $nouveauLibelleCourt
* $enumTypeConges
* $nouveauType
* $traductions
* $url
* $isCongesExceptionnelsActive
*/
?>
<h1><?= _('config_abs_titre') ?></h1>
<?php foreach ($listeTypeConges as $typeConge => $conges) : ?>
<h2><?= _('divers_' . $typeConge . '_maj_1') ?></h2>
<p><?= _('config_abs_comment_' . $typeConge) ?></p>
<table class="table table-hover table-responsive table-condensed table-striped">
<tr>
<th><?= _('config_abs_libelle') ?></th>
<th><?= _('config_abs_libelle_short') ?></th>
<th></th>
</tr>
<?php if (empty($conges)) : ?>
<tr><td colspan="2"><center><?= _('aucun_resultat') ?></center></td></tr>
<?php else : ?>
<?php foreach ($conges as $conge) : ?>
<div id="inner-content">
<h1><?= _('config_abs_titre') ?></h1>
<div id="loader-bar" class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar"
aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width:100%">
</div>
</div>
<div v-for="(value, key) in absenceTypes">
<h2>{{ titre(key) }}</h2>
<p>{{ commentaire(key) }}</p>
<table class="table table-hover table-responsive table-condensed table-striped">
<tr>
<td><strong><?= $conge['libelle'] ?></strong></td>
<td><?= $conge['libelleCourt'] ?></td>
<th><?= _('config_abs_libelle') ?></th>
<th><?= _('config_abs_libelle_short') ?></th>
<th></th>
</tr>
<tr v-if="!hasAbsences(key)"><td colspan="2"><center><?= _('aucun_resultat') ?></center></td></tr>
<tr v-for="absenceType in value">
<td><strong>{{ absenceType.libelle }}</strong></td>
<td>{{ absenceType.libelleCourt }}</td>
<td class="action">
<?php if (!$conge['typeNatif']) : ?>
<a href="<?= $PHP_SELF ?>?action=modif&id_to_update=<?= $conge['id'] ?>" title=" <?= _('form_modif') ?>"><i class="fa fa-pencil"></i></a>
&nbsp;
<a href="<?= $PHP_SELF ?>?action=suppr&id_to_update=<?= $conge['id'] ?>" title=" <?= _('form_supprim') ?>"><i class="fa fa-times-circle"></i></a>
<?php else : ?>
<div v-if="absenceType.typeNatif">
<i class="fa fa-pencil disabled" title="Type d'absence natif"></i>
&nbsp;
<i class="fa fa-times-circle disabled" title="Type d'absence natif"></i></a>
<?php endif; ?>
<i class="fa fa-times-circle disabled" title="Type d'absence natif"></i>
</div>
<div v-else>
<a :href="linkModification(absenceType.id)" title=" <?= _('form_modif') ?>"><i class="fa fa-pencil"></i></a>
&nbsp;
<a :href="linkSuppression(absenceType.id)" title=" <?= _('form_supprim') ?>"><i class="fa fa-times-circle"></i></a>
</div>
</td>
</tr>
<?php endforeach ; ?>
<?php endif ?>
</table>
<hr/>
<?php endforeach ; ?>
</table>
<hr/>
</div>

<h2><?= _('config_abs_add_type_abs') ?></h2>
<p><?= _('config_abs_add_type_abs_comment') ?></p>
<form action="<?= $url ?>" method="POST">
<table class="table table-hover table-responsive table-condensed table-striped">
<tr>
<th><?= _('config_abs_libelle') ?></th>
<th><?= _('config_abs_libelle_short') ?></th>
<th><?= _('divers_type') ?></th>
</tr><tr>
<td><input class="form-control" type="text" name="tab_new_values[libelle]" size="20" maxlength="20" value="<?= $nouveauLibelle ?>"></td>
<td><input class="form-control" type="text" name="tab_new_values[short_libelle]" size="3" maxlength="3" value="<?= $nouveauLibelleCourt ?>"></td>
<td>
<select class="form-control" name=tab_new_values[type]>
<?php foreach (array_keys($listeTypeConges) as $typeConge) : ?>
<option <?= ($typeConge == $nouveauType) ? 'selected' : '' ?>><?= $typeConge ?></option>
<?php endforeach ;?>
</select>
</td>
</tr>
</table>
<input type="hidden" name="action" value="new">
<hr/>
<input type="submit" class="btn btn-success" value="<?= _('form_ajout') ?>"><br>
</form>
<h2><?= _('config_abs_add_type_abs') ?></h2>
<p><?= _('config_abs_add_type_abs_comment') ?></p>
<form :action="url" method="POST">
<table class="table table-hover table-responsive table-condensed table-striped">
<tr>
<th><?= _('config_abs_libelle') ?></th>
<th><?= _('config_abs_libelle_short') ?></th>
<th><?= _('divers_type') ?></th>
</tr><tr>
<td><input class="form-control" type="text" name="tab_new_values[libelle]" size="20" maxlength="20" :value="nouveauLibelle"></td>
<td><input class="form-control" type="text" name="tab_new_values[short_libelle]" size="3" maxlength="3" :value="nouveauLibelleCourt"></td>
<td>
<select class="form-control" name=tab_new_values[type]>
<option v-for="type in typesGeneraux" :selected="isSelected(type)">{{ type }}</option>
</select>
</td>
</tr>
</table>
<input type="hidden" name="action" value="new">
<hr/>
<input type="submit" class="btn btn-success" value="<?= _('form_ajout') ?>"><br>
</form>
</div>

<script>
axios.defaults.headers.get = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Token': '<?= $_SESSION['token'] ?>',
};

const instance = axios.create({
baseURL: '<?= $baseURIApi ?>',
timeout: 1500
});

var vm = new Vue({
el: '#inner-content',
data: {
absenceTypes : {},
url : '<?= $url ?>',
nouveauLibelle : '<?= $nouveauLibelle ?>',
nouveauLibelleCourt : '<?= $nouveauLibelleCourt ?>',
nouveauType : '<?= $nouveauType ?>',
traductions : <?= json_encode($traductions) ?>,
isCongesExceptionnelsActive: 'true' == "<?= $isCongesExceptionnelsActive ? 'true' : 'false' ?>",
axios : instance
},
computed: {
typesGeneraux : function () {
return Object.keys(this.absenceTypes);
}
},
'methods' : {
hasAbsences: function (type) {
return 0 < this.absenceTypes[type].length;
},
titre: function (type) {
return this.traductions.titres[type];
},
commentaire: function (type) {
return this.traductions.commentaires[type];
},
linkModification : function (id) {
return this.url + '?action=modif&id_to_update=' + id;
},
linkSuppression : function (id) {
return this.url + '?action=suppr&id_to_update=' + id;
},
isSelected : function (type) {
return type == this.nouveauType;
}
},
created () {
var vm = this;
this.axios.get('/absence/type')
.then((response) => {
if (typeof response.data != 'object') {
return;
}
const absenceTypes = response.data.data;
console.log(response.data);
var organisedTypes = {};
for (var i = 0; i < absenceTypes.length; ++i) {
var absenceType = absenceTypes[i];
if (undefined == organisedTypes[absenceType.type]) {
organisedTypes[absenceType.type] = new Array();
}
organisedTypes[absenceType.type].push(absenceType);
}
if (!vm.isisCongesExceptionnelsActive && undefined != organisedTypes['conges_exceptionnels']) {
delete organisedTypes['conges_exceptionnels'];
}

// Finally hide loader and show var
document.getElementById('loader-bar').classList.add('hidden');
vm.absenceTypes = organisedTypes;
})
.catch((error) => {
console.log(error.response);
console.error(error);
})
}
});
</script>
<?php
4 changes: 2 additions & 2 deletions App/Views/Planning/Formulaire/Responsable_Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</thead>
<tbody>
<tr>
<td><?= $planning->name ?><input type="hidden" name="planning_id" value="<?= $planning->id ?>" /></td>
<td><?= $planning['name'] ?><input type="hidden" name="planning_id" value="<?= $planning['id'] ?>" /></td>
<td><input type="hidden" id="<?= $idToggleSemaine ?>" /></td>
</tr>
</tbody>
Expand Down Expand Up @@ -84,7 +84,7 @@
$disabled = (\App\ProtoControllers\Utilisateur::hasSortiesEnCours($utilisateur['login']))
? 'disabled '
: '';
$checked = ($planning->id === $utilisateur['planningId'])
$checked = ($planning['id'] === $utilisateur['planningId'])
? 'checked '
: '';
$nom = \App\ProtoControllers\Utilisateur::getNomComplet($utilisateur['prenom'], $utilisateur['nom']);
Expand Down
121 changes: 89 additions & 32 deletions App/Views/Planning/Liste.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,100 @@
* $titre
* $message
* $listIdUsed
* $plannings
* $isHr
* $lienModif
* $baseURIApi
*/
?>
<?php if ($isHr) : ?>
<a href="<?= ROOT_PATH ?>hr/ajout_planning" style="float:right" class="btn btn-success"><?= _('hr_ajout_planning') ?></a>
<?php endif ?>
<h1><?= $titre ?></h1>
<?= $message ?>
<table class="table table-hover table-responsive table-condensed table-striped">
<thead>
<tr><th><?= _('divers_nom_maj_1') ?></th><th style="width:10%"></th></tr>
</thead>
<tbody>
<?php if (empty($plannings)) : ?>
<tr><td colspan="2"><center><?= _('aucun_resultat') ?></center></td></tr>
<?php else : ?>
<?php foreach ($plannings as $planning) : ?>
<tr><td><?= $planning['name'] ?></td>
<td>
<form action="" method="post" accept-charset="UTF-8"
enctype="application/x-www-form-urlencoded">
<a title="<?= _('form_modif') ?>" href="<?= $lienModif ?>?id=<?= $planning['id'] ?>"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;
<?php if ($isHr) : ?>
<?php if (in_array($planning['id'], $listIdUsed)) : ?>
<button title="<?= _('planning_used') ?>" type="button" class="btn btn-link disabled"><i class="fa fa-times-circle"></i></button>
<?php else : ?>
<input type="hidden" name="planning_id" value="<?= $planning['id'] ?>" />
<div id="inner-content">
<a v-if="isHr" href="<?= ROOT_PATH ?>hr/ajout_planning" style="float:right" class="btn btn-success"><?= _('hr_ajout_planning') ?></a>
<h1><?= $titre ?></h1>
<?= $message ?>
<table class="table table-hover table-responsive table-condensed table-striped">
<thead>
<tr><th><?= _('divers_nom_maj_1') ?></th><th style="width:10%"></th></tr>
</thead>
<tbody>
<tr v-if="!hasPlanning()"><td colspan="2"><center><?= _('aucun_resultat') ?></center></td></tr>
<tr v-for="p in plannings">
<td>{{ p.name }}</td>
<td>
<form action="" method="post" accept-charset="UTF-8"
enctype="application/x-www-form-urlencoded">
<a title="<?= _('form_modif') ?>" :href="linkModification(p.id)"><i class="fa fa-pencil"></i></a>&nbsp;&nbsp;
<span v-if="isHr">
<span v-if="isUsed(p.id)">
<button title="<?= _('planning_used') ?>" type="button" class="btn btn-link disabled"><i class="fa fa-times-circle"></i></button>
</span>
<span v-else>
<input type="hidden" name="planning_id" :value="p.id" />
<input type="hidden" name="_METHOD" value="DELETE" />
<button type="submit" class="btn btn-link" title="<?= _('form_supprim') ?>"><i class="fa fa-times-circle"></i></button>
<?php endif ?>
<?php endif ?>
</span>
</span>
</form>
</td>
</tr>
<?php endforeach ?>
<?php endif ?>
</tbody>
</table>
</tr>
</tbody>
</table>
</div>

<script>
axios.defaults.headers.get = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Token': '<?= $_SESSION['token'] ?>',
};

const instance = axios.create({
baseURL: '<?= $baseURIApi ?>',
timeout: 1500
});

var vm = new Vue({
el: '#inner-content',
data: {
plannings : {},
listIdUsed : <?= json_encode($listIdUsed) ?>,
isHr: 'true' == "<?= $isHr ? 'true' : 'false' ?>",
lienModification : "<?= $lienModif ?>",
statusActive : <?= \App\Models\Planning::STATUS_ACTIVE ?>,
axios : instance
},
computed: {
},
'methods' : {
hasPlanning : function () {
return 0 < Object.keys(this.plannings).length;
},
isUsed : function (id) {
return -1 != this.listIdUsed.indexOf(id);
},
linkModification : function (id) {
return this.lienModification + '&id=' + id;
}
},
created () {
var vm = this;
this.axios.get('/planning')
.then((response) => {
if (typeof response.data != 'object') {
return;
}
const plannings = response.data.data;
var activePlannings = new Array();
for (var i = 0; i < plannings.length; ++i) {
if (plannings[i].status === vm.statusActive) {
activePlannings.push(plannings[i]);
}
}
vm.plannings = activePlannings;
})
.catch((error) => {
console.log(error.response);
console.error(error);
})
}
});
</script>
<?php
Loading

0 comments on commit 1e9037b

Please sign in to comment.