Skip to content

Commit

Permalink
CRUD Service
Browse files Browse the repository at this point in the history
  • Loading branch information
guillainbisimwa committed Jul 8, 2019
1 parent e65cfd1 commit 0e88f34
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 4 deletions.
18 changes: 18 additions & 0 deletions assets/DisplayFrench.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ $(".nav-link-med").text((json.med.plurial).toUpperCase());
$(".nav-link-forme").text((json.forme.plurial).toUpperCase());
$(".nav-link-cat").text((json.cat.plurial).toUpperCase());
$(".nav-link-frnssr").text((json.fournisseur.plurial).toUpperCase());
$(".nav-link-service").text((json.service.plurial).toUpperCase());

//Tab med
//Header of Table
Expand All @@ -62,6 +63,10 @@ $(".tab_frnssr thead tr .2").text(json.fournisseur.designation);
$(".tab_frnssr thead tr .3").text(json.fournisseur.phone);
$(".tab_frnssr thead tr .4").text(json.fournisseur.adress);

//Tab service
$(".tab_service thead tr .1").text(json.nbr);
$(".tab_service thead tr .2").text(json.service.designation);

//Modals Med
$(".med-modal-title").text(json.med.add);
$("label.design_med").text(json.med.designation);
Expand Down Expand Up @@ -92,6 +97,12 @@ $("label.design_frnssr").text(json.fournisseur.designation);
$("#SuppFrnssrModal").find("h3 span").text(json.fournisseur.del_confirm_msg);
$("#SuppFrnssrModal").find("h4").text(json.fournisseur.del);

//Modals service
$(".service-modal-title").text(json.service.add);
$("label.design_service").text(json.service.designation);
$("#SuppServiceModal").find("h3 span").text(json.service.del_confirm_msg);
$("#SuppServiceModal").find("h4").text(json.service.del);

//Med
$("#save_med span").text(json.buttons.add.name);
$("#save_med").find("i").addClass(json.buttons.add.icon);
Expand Down Expand Up @@ -124,6 +135,13 @@ $("#update_frnssr").find("i").addClass(json.buttons.edit.icon);
$("#supp_frnssr span").text(json.buttons.del.name);
$("#supp_frnssr").find("i").addClass(json.buttons.del.icon);

//service
$("#save_service span").text(json.buttons.add.name);
$("#save_service").find("i").addClass(json.buttons.add.icon);
$("#update_service span").text(json.buttons.edit.name);
$("#update_service").find("i").addClass(json.buttons.edit.icon);
$("#supp_service span").text(json.buttons.del.name);
$("#supp_service").find("i").addClass(json.buttons.del.icon);
/**
* ENTREES
*/
Expand Down
10 changes: 10 additions & 0 deletions assets/values/String.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@
"adress":"Adresse",
"phone":"Contact"
},
"service": {
"name": "Service",
"plurial": "Services",
"add": "Ajouter un service",
"del": "Supprimer un service",
"edit": "Modifier un service",
"file_name":"Liste de services",
"del_confirm_msg":"Voulez-vous vraiment supprimer le service : ",
"designation":"Nom du service"
},
"entree": {
"name": "Entrée",
"plurial": "Entrées",
Expand Down
1 change: 1 addition & 0 deletions data/.db/entrees.db
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
{"id_medicament":"iJXu4E0gJivdWFCD","qt":750,"date_":{"$$date":1562238848806},"_id":"cnbHDVi3iYDqNThh"}
{"id_medicament":"ZWmRgB27w2No7Uej","qt":510,"date_":{"$$date":1562238847923},"_id":"dGE0ni4QUgGGRP31"}
{"id_medicament":"ABIUPFG1r6QOosGb","qt":630,"date_":{"$$date":1562238848367},"_id":"eQ2HqCx9xlpb2tSy"}
{"id_medicament":"iQHvMHsjMJSdsyxz","qt":8888,"date_":{"$$date":1562586676531},"_id":"fIjt80GZm9LeRKsW"}
{"id_medicament":"iQHvMHsjMJSdsyxz","qt":90,"date_":{"$$date":1562238846357},"_id":"fNjsFj9hUL9WXohS"}
{"id_medicament":"IBwJbYlOeQRmJ2OI","qt":20,"date_":{"$$date":1562238846138},"_id":"gmOs6NNZQNq6ehhO"}
{"id_medicament":"BX2CfCVyTqeEK1cQ","qt":740,"date_":{"$$date":1562238848774},"_id":"hLf3qegGizaQ3yk4"}
Expand Down
7 changes: 7 additions & 0 deletions data/.db/services.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{"nom_service":"ORL","_id":"EJIQs6vAkTKGlhIB"}
{"nom_service":"STOMATOL","_id":"PQkG6aXop8dcoSk3"}
{"nom_service":"STOMATOLOGIE","_id":"Tx7QP2Krak6azqak"}
{"nom_service":"STOMATO","_id":"yOI2wtGGxOTqGG4O"}
{"$$deleted":true,"_id":"yOI2wtGGxOTqGG4O"}
{"$$deleted":true,"_id":"PQkG6aXop8dcoSk3"}
{"nom_service":"STOMATO","_id":"Tx7QP2Krak6azqak"}
9 changes: 9 additions & 0 deletions data/Service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var Document = require('camo').Document;

class Service extends Document {
constructor() {
super();
this.nom_service = String;
}
}
module.exports = Service
173 changes: 169 additions & 4 deletions renderer-scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ $(document).ready(function() {
const Entree = require('../data/Entree');
const Sortie = require('../data/Sortie');
const Fournisseur = require('../data/Fournisseur');
const Service = require('../data/Service');

//Init tables
var _tab_forme = $("#tab_forme").DataTable();
var _tab_cat = $("#tab_cat").DataTable();
var _tab_med = $("#tab_med").DataTable();
var _tab_fournisseur = $("#tab_frnssr").DataTable();
var _tab_service = $("#tab_service").DataTable();

var tab_uploaded_med = $("#tab_uploaded_med").DataTable(
{
Expand Down Expand Up @@ -106,6 +108,11 @@ $(document).ready(function() {
populateTabFournisseur();
});

// Populate tab service
$(".nav-link-service").click(function(){
populateTabService();
});

//Save forme
$("#save_forme").click(function(){
var _forme = $("#design_forme").val();
Expand Down Expand Up @@ -193,6 +200,24 @@ $(document).ready(function() {
$("#adress_fnssr").val("");
});

//save service
$("#save_service").click(function(){
var _nom_service = $("#nom_service").val();

var service = Service.create({
nom_service: _nom_service
});

service.save().then(function(addedService) {
console.log(addedService._id);
//Close programmaticaly the modal
$("#AddServiceModal .close").click();
$("#nom_service").val("");
populateTabService();
});
$("#nom_service").val("");
});

//Update forme
/**
* https://github.com/scottwrobinson/camo#creating-and-saving
Expand Down Expand Up @@ -249,6 +274,18 @@ $(document).ready(function() {
});
});

//Update fournisseur
$("#update_service").click(function(){
var _id_service = $("#_id_service").val();
var _nom_service = $("#nom_service").val();

Service.findOneAndUpdate({_id:_id_service},{nom_service: _nom_service},{upsert: true}).then(function(updatedService) {
populateTabService();
console.log("_id = ", updatedService._id)
$("#AddServiceModal .close").click();
});
});

//Supprimer une forme
$("#supp_forme").click(function(){
var _id_del_design_forme = $("#_id_del_design_forme").val();
Expand Down Expand Up @@ -303,7 +340,18 @@ $(document).ready(function() {
result_del(deletedFrnssr,del_nom_frnssr,"SuppFrnssrModal");
populateTabFournisseur();
});
});
});

//Supprimer un service
$("#supp_service").click(function(){
var _id_del_service = $("#_id_del_service").val();
var del_nom_service = $("#del_nom_service").text();
Service.deleteOne({_id:_id_del_service}).then(function(deletedService) {
console.log('Deleted ', deletedService, ' service from the database.');
result_del(deletedService,del_nom_service,"SuppServiceModal");
populateTabService();
});
});

//Function, update values before adding forme
function updateValueModalForme(forme,_id){
Expand Down Expand Up @@ -396,6 +444,29 @@ $(document).ready(function() {
$("#adress_fnssr").val("");
}

//Function, update values before adding fournisseur
function updateValueModalService(service,_id){
$("#update_service").css("display","block");
$("#save_service").css("display","none");
$(".service-modal-title").text(json.service.edit);
$(".service-modal-title").css("color","#a11");

$("#nom_service").val(service);
$("#_id_service").val(_id);

//Find is-filled is-focused
$("#AddServiceModal").find(".form-group").addClass("has-danger is-filled is-focused");
}
function addValueModalService(){
$("#update_service").css("display","none");
$("#save_service").css("display","block");
$(".service-modal-title").text(json.service.add);
$(".service-modal-title").css("color","#000");
$("#AddServiceModal").find(".form-group").removeClass("has-danger is-filled is-focused");
$("#nom_service").val("");
$("#_id_service").val("");
}

function addValueModalMed(){
$("#update_med").css("display","none");
$("#save_med").css("display","block");
Expand Down Expand Up @@ -425,12 +496,18 @@ $(document).ready(function() {
$("#_id_del_design_med").val(_id);
}

//Function, update values before adding fournisseur
function delValueModalFrnssr(frnssr,_id){
//Function, update values before adding fournisseur
function delValueModalFrnssr(frnssr,_id){
$("#del_nom_frnssr").text(frnssr);
$("#_id_del_frnssr").val(_id);
}

//Function, update values before adding service
function delValueModalService(service,_id){
$("#del_nom_service").text(service);
$("#_id_del_service").val(_id);
}

//Function populate tab Forme
function populateTabForme(){
var tab_forme = [];
Expand Down Expand Up @@ -727,7 +804,7 @@ $(document).ready(function() {
}

//Function populate tab fournisseur
function populateTabFournisseur(){
function populateTabFournisseur(){
var tab_fournisseur = [];
_tab_fournisseur.destroy();
//$("#tab_fournisseur").empty();
Expand Down Expand Up @@ -816,6 +893,94 @@ $(document).ready(function() {
});
}

function populateTabService(){
var tab_service = [];
_tab_service.destroy();
//$("#tab_service").empty();
Service.find({},{sort:'nom_service'}).then(function(foundService) {
i = 0;
foundService.forEach(function(foundSingleService) {
i++;
var localSingleService = [i, foundSingleService.nom_service,foundSingleService._id];
tab_service.push(Array.from(localSingleService))
});

console.log(Array.from(tab_service))
//_tab_service.DataTable({
_tab_service = $('#tab_service').DataTable({

dom: 'Blfrtip',
select: true,
buttons: [
{
text: '<li class="'+json.buttons.new.icon+'"></li> '+json.buttons.new.name,
action: function ( e, dt, node, config ) {
addValueModalService();
$("#AddServiceModal").modal();
}
},
{
text: '<li class="'+json.buttons.edit.icon+'"></li> '+json.buttons.edit.name,
action: function ( e, dt, node, config ) {
console.log(
'Row data: '+
JSON.stringify( dt.row( { selected: true } ).data() )
);
updateValueModalService(dt.row( { selected: true } ).data()[1], dt.row( { selected: true } ).data()[2]);
$("#AddServiceModal").modal();
},
enabled: false
},
{
text: '<li class=" '+json.buttons.del.icon+'"></li> '+json.buttons.del.name,
action: function ( e, dt, node, config ) {
console.log(
'Row data: '+
JSON.stringify( dt.row( { selected: true } ).data() )
);
delValueModalService(dt.row( { selected: true } ).data()[1], dt.row( { selected: true } ).data()[2]);
$("#SuppServiceModal").modal();
},
enabled: false
},
//'copy', 'csv', 'excel', 'pdf', 'print', "colvis"
{
extend: 'csv',
text: '<i class="'+json.buttons.export.icon+'"></i> '+json.buttons.export.name,
titleAttr: 'CSV',
filename: json.service.file_name,
exportOptions: {
columns: [0, 1]
},
}
],
// ICI on choisi la langue des details du tableau
language:{
url:'./assets/values/French.json'
},
"order": [[ 0, "asc" ]],
// Les donnees sont affichees dans le tableau HTML
data:tab_service,
// On affiche pas la troisieme colonne, elle reprend les _id
"columnDefs": [
{
"targets": [ 2 ],
"visible": false,
"searchable": false
},
],
destroy:true
});

_tab_service.on( 'select deselect', function () {
var selectedRows = _tab_service.rows( { selected: true } ).count();
console.log("ok: "+selectedRows)
_tab_service.button( 1 ).enable( selectedRows === 1 );
_tab_service.button( 2 ).enable( selectedRows === 1 );
});
});
}

//Populate forme SELECTPICKERS
function populateSelectForme(){

Expand Down
Loading

0 comments on commit 0e88f34

Please sign in to comment.