diff --git a/cfg/config.go b/cfg/config.go index a896b12..9e1f207 100755 --- a/cfg/config.go +++ b/cfg/config.go @@ -21,7 +21,7 @@ package cfg /***** Definicion de Constantes Globales - Inicio ****/ /*****************************************************/ const ( - Host = "192.168.0.10" + Host = "192.168.0.12" Port = 5432 User = "postgres" Passwd = "123456789" diff --git a/controller/controller.js b/controller/controller.js index c683c0c..a60d5f8 100644 --- a/controller/controller.js +++ b/controller/controller.js @@ -18,12 +18,12 @@ $(document).ready(function() { } }); + // -- confirmacion de eliminacion de un registro taxonomico $("#ConfirmaDelete").click(function(){ console.log("Entro al click button de Eliminar!") var id_delete = $("#register_delete").text() console.log("A eliminar row ==> " + id_delete) - var name_row = "row_" + id_delete - $("#" + name_row).remove(); + deleteRecord(id_delete) }); // -- click al boton de agregar nuevo registro. @@ -119,14 +119,34 @@ function funcBotonesGrilla(t){ $("#hedit_id").val(array[1]) console.log("#hedit_id ===> " + $("#hedit_id").val()) } + // registro de delete de una tupla. else if (array[0] == "delete") { - console.log("Borrar el primero!") - $("#register_delete").html("") - $("#register_delete").html(array[1]) + console.log("Borrar el primero!"); + $("#register_delete").html(""); + $("#register_delete").html(array[1]); + $("#text_complementario").html(""); + tiene_hijos(array[1]); } } +function tiene_hijos(id_tupla){ + $.ajax({ + type:"POST", + url: "/receiver", + data: "opc=8f14e45fceea167a5a36dedd4bea2543&vid=" + id_tupla, + dataType: "json", + success: function(datos) + { + if (datos == "true") + { + $("#text_complementario").html("El nodo ID [" + id_tupla + "] tiene nodos hijos, seguro desea realizar una eliminacion en cascada?") + + } + } + }); +} + function showGrid(){ console.log("IN showGrid()") $.ajax({ @@ -321,6 +341,27 @@ function updateRecord() } } +// -- Funcion que actualiza el Select de los PID +function deleteRecord(id_tupla) +{ + $.ajax({ + type:"POST", + url: "/receiver", + data: "opc=c9f0f895fb98ab9159f51fd0297e236d&vid=" + id_tupla , + dataType: "json", + success: function(datos) + { + if (datos == "true") + { + $('#Btn_Cerrar-3').trigger('click'); + $.notify("Registro eliminado exitosamente", {position:"bottom right",className:"success"}); + showGrid(); + } + else + $.notify("Registro imposible de eliminar", {position:"bottom right",className:"error"}); + } + }); +} // -- Funcion que actualiza el Select de los PID diff --git a/goFile.go b/goFile.go new file mode 100755 index 0000000..a755a31 --- /dev/null +++ b/goFile.go @@ -0,0 +1,246 @@ +/********************************************************************************/ +/* goFile.go */ +/* */ +/* Descripcion: */ +/* */ +/* */ +/* Autor : Rodrigo G. Higuera M. (RGHM) */ +/* Fecha : 21/07/2020 11:22 */ +/* */ +/* C0pyl3ft - 2020 | Open Source License */ +/********************************************************************************/ +/********************************************************************************/ +/* Ejecucion: */ +/* */ +/* */ +/********************************************************************************/ + +package main + +/**********************************/ +/******** Import Packages *********/ +/**********************************/ +import ( + "fmt" + "log" + "os" + "os/exec" + "strconv" + "time" +) + +/*****************************************************/ +/******** Definicion de Estructuras - Inicio *********/ +/*****************************************************/ + +/*****************************************************/ +/********** Definicion de Estructuras - Fin **********/ +/*****************************************************/ + +/*****************************************************/ +/***** Definicion de Constantes Globales - Inicio ****/ +/*****************************************************/ +const VERSION = "20200721.112233.0001" + +const ( + layoutISO = "2006-01-02 13:21:00" +) + +/*****************************************************/ +/****** Definicion de Constantes Globales - Fin ******/ +/*****************************************************/ + +/*****************************************************/ +/****** Definicion de Variables Globales - Inicio ****/ +/*****************************************************/ +var author string = "Rodrigo G. Higuera M. " +var fechaSystem, Y string +var versionFile string +var PathFile string = "/home/higuerar/go/src/crudgopg/" +var nameFile string +var cl int = 0 + +/*****************************************************/ +/******* Definicion de Variables Globales - Fin ******/ +/*****************************************************/ + +func writeFile(line string) { + if _, err := os.Stat(PathFile); os.IsNotExist(err) { + fmt.Println("def") + f, err := os.Create(PathFile) + if err != nil { + fmt.Println("Error ", err) + f.Close() + return + } + + fmt.Fprintln(f, line) + } else { + // -- Si el fichero ya existe. + x := fmt.Sprintf("cat %s | wc -l", PathFile) + out, err := exec.Command("bash", "-c", x).Output() + if err != nil { + fmt.Printf("Error ==> [%s]", err) + } + fmt.Println("OUT===>" + string(out)) + + line := line + " " + string(out) + // -- open input file + f, err := os.OpenFile(PathFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + log.Println(err) + } + + // -- close fi on exit and check for its returned error + defer func() { + if err := f.Close(); err != nil { + panic(err) + } + }() + + if _, err := f.WriteString(line); err != nil { + log.Println(err) + } + } +} + +func completaEspaciosString(line string, car byte) string { + maxLine := 78 + + for i := len(line); i < maxLine; i++ { + line = line + string(car) + } + + return line +} + +func PrintLineFichero(line, fichero string) { + var c string + if cl == 0 { + c = fmt.Sprintf("echo %s > %s", line, fichero) + } else { + c = fmt.Sprintf("echo %s >> %s", line, fichero) + } + + _, err := exec.Command("bash", "-c", c).Output() + if err != nil { + fmt.Printf("Error ==> [%s]", err) + } else { + cl++ + } +} + +func printHeaderFileGo(fichero string) { + lineAuthor := completaEspaciosString(" @ Autor : "+author, ' ') + lineFecha := completaEspaciosString(" @ Fecha : "+fechaSystem, ' ') + lineTitle := completaEspaciosString(" "+nameFile, ' ') + //fmt.Println("lineAuthor ==> [/*" + lineAuthor + "*/]") + //fmt.Println("lineFecha ==> [/*" + lineFecha + "*/]") + PrintLineFichero("\"/********************************************************************************/\"", fichero) + PrintLineFichero("\"/* */\"", fichero) + PrintLineFichero("\"/*"+lineTitle+"*/\"", fichero) + PrintLineFichero("\"/* */\"", fichero) + PrintLineFichero("\"/* +++ Descripcion: */\"", fichero) + PrintLineFichero("\"/* */\"", fichero) + PrintLineFichero("\"/* */\"", fichero) + PrintLineFichero("\"/*"+lineAuthor+"*/\"", fichero) + PrintLineFichero("\"/*"+lineFecha+"*/\"", fichero) + PrintLineFichero("\"/* */\"", fichero) + PrintLineFichero("\"/* C0pyl3ft - 2020 | Open Source License */\"", fichero) + PrintLineFichero("\"/********************************************************************************/\"", fichero) + PrintLineFichero("\"/********************************************************************************/\"", fichero) + PrintLineFichero("\"/* Ejecucion : */\"", fichero) + PrintLineFichero("\"/* */\"", fichero) + PrintLineFichero("\"/* */\"", fichero) + PrintLineFichero("\"/********************************************************************************/\"", fichero) + PrintLineFichero("\"\"", fichero) + +} + +func printBodyFileGo(fichero string) { + strVersion := fmt.Sprintf("%s", versionFile) + packImport := fmt.Sprintf("'\t''\"%s\"'", "fmt") + PrintLineFichero("\"package main\"", fichero) + PrintLineFichero("\"\"", fichero) + PrintLineFichero("\"/**********************************/\"", fichero) + PrintLineFichero("\"/******** Import Packages *********/\"", fichero) + PrintLineFichero("\"/**********************************/\"", fichero) + PrintLineFichero("\"import (\"", fichero) + //PrintLineFichero(" '\"fmt\"'", fichero) + PrintLineFichero(packImport, fichero) + PrintLineFichero("\")\"", fichero) + PrintLineFichero("\"\"", fichero) + PrintLineFichero("\"\"", fichero) + PrintLineFichero("\"/*****************************************************/\"", fichero) + PrintLineFichero("\"/******** Definicion de Estructuras - Inicio *********/\"", fichero) + PrintLineFichero("\"/*****************************************************/\"", fichero) + PrintLineFichero("\"\"", fichero) + PrintLineFichero("\"/*****************************************************/\"", fichero) + PrintLineFichero("\"/******** Definicion de Estructuras - Fin ************/\"", fichero) + PrintLineFichero("\"/*****************************************************/\"", fichero) + PrintLineFichero("\"\"", fichero) + PrintLineFichero("\"\"", fichero) + PrintLineFichero("\"/*****************************************************/\"", fichero) + PrintLineFichero("\"/***** Definicion de Constantes Globales - Inicio ****/\"", fichero) + PrintLineFichero("\"/*****************************************************/\"", fichero) + PrintLineFichero(" const VERSION = '\""+strVersion+"\"'", fichero) + PrintLineFichero("\"/*****************************************************/\"", fichero) + PrintLineFichero("\"/***** Definicion de Constantes Globales - Fin *******/\"", fichero) + PrintLineFichero("\"/*****************************************************/\"", fichero) + PrintLineFichero("\"\"", fichero) + PrintLineFichero("\"\"", fichero) + PrintLineFichero("\"/*****************************************************/\"", fichero) + PrintLineFichero("\"/****** Definicion de Variables Globales - Inicio ****/\"", fichero) + PrintLineFichero("\"/*****************************************************/\"", fichero) + PrintLineFichero("\"\"", fichero) + PrintLineFichero("\"/*****************************************************/\"", fichero) + PrintLineFichero("\"/****** Definicion de Variables Globales - Fin ******/\"", fichero) + PrintLineFichero("\"/*****************************************************/\"", fichero) + PrintLineFichero("\"\"", fichero) + PrintLineFichero("\"\"", fichero) + PrintLineFichero("\"/*\"", fichero) + PrintLineFichero("\"*\"", fichero) + PrintLineFichero("\"* @author "+author+"\"", fichero) + PrintLineFichero("\"* @date "+fechaSystem+"\"", fichero) + PrintLineFichero("\"* @version "+versionFile+"\"", fichero) + PrintLineFichero("\"* @Company © Development "+Y+"\"", fichero) + PrintLineFichero("\"*\"", fichero) + PrintLineFichero("\"*/\"", fichero) + PrintLineFichero("\"func main() {\"", fichero) + PrintLineFichero("\"\"", fichero) + PrintLineFichero("\"}\"", fichero) + PrintLineFichero("\"\"", fichero) +} + +/* +* +* @author Rodrigo G. Higuera M.(RGHM) +* @date 2020.07.21 11:22 +* @version 20200721.112233.0001 +* @Company © Development 2020 +* + */ +func main() { + fmt.Println("::: Inicio :::") + + dt := time.Now() + fechaSystem = dt.Format("2006.01.02 15:04:05") + v1 := string(dt.Format("20060102")) + v2 := strconv.Itoa(dt.Hour()) + strconv.Itoa(dt.Minute()) + strconv.Itoa(dt.Second()) + Y = strconv.Itoa(dt.Year()) + versionFile = v1 + "." + v2 + "." + "0001" + + // -- se recibe nombre por parametro de nombre de fichero + argCount := len(os.Args[1:]) + if argCount >= 1 { + fn := os.Args[1] + // -- fmt.Println(fn) + nameFile = fn + } else { + nameFile = "nuevo_" + string(dt.Format("20060102")) + ".go" + } + + printHeaderFileGo(PathFile + nameFile) + printBodyFileGo(PathFile + nameFile) + fmt.Println("::: Fin :::") +} diff --git a/goFile.sh b/goFile.sh deleted file mode 100755 index 7d75e0c..0000000 --- a/goFile.sh +++ /dev/null @@ -1,161 +0,0 @@ -#!/bin/bash - -# /********************************************************************************/ -# /* goFile.sh */ -# /* */ -# /* Descripcion: Crea Ficheros Golang nuevos con cabeceras personalizadas. */ -# /* */ -# /* */ -# /* Autor : Rodrigo G. Higuera M. (RGHM) */ -# /* Fecha : 27/06/2020 17.35 */ -# /* */ -# /********************************************************************************/ -# /********************************************************************************/ -# /* Ejecucion: */ -# /* */ -# /* ./UxGitPull.sh => Esta llamada muestra la opciones de uso de la shell */ -# /* ./UxGitPull.sh -h => Esta llamada muestra la opciones de uso de la shell */ -# /* ./UxGitPull.sh -s => Lista los diferentes repositorios almacenados. */ -# /* ./UxGitPull.sh -n X => Realiza git pull al repo Nro. X */ -# /* */ -# /********************************************************************************/ - -#/*********************************************************************************/ -#/************************* CONFIGURACION DE PARAMETROS ***********************/ -#/*********************************************************************************/ -strDate=$(date '+%d/%m/%Y %H:%M'); -strDate2=$(date '+%Y.%m.%d %H:%M'); -strDateV=$(date '+%Y%m%d.%H%M%S'); -V="${strDateV}.0001" -year=$(date '+%Y'); -nameFichero=$1 -max_lenght_field=0 -lineOut="" -author="Rodrigo G. Higuera M.(RGHM)" -authorSpace="Rodrigo_G._Higuera_M._(RGHM)" -email="" -#/*********************************************************************************/ - -# -- Funcion que completa con espacios un string -CompletaEspacios() -{ - max_lenght_field=$2 - varInput=`echo "$1" | sed -r 's/[_]+/ /g'` - lenght_string=0 - lenght_string=`echo -n "${varInput}" | wc -c` - car=" " - str="" - lineOut="" - while [ ${lenght_string} -le ${max_lenght_field} ]; do - str="${str}${car}" - let lenght_string+=1 - done - lineOut="${varInput}"${str} -} - -#-- Imprime la cabecera a mostrar en la Shell -print_head() -{ - echo "/********************************************************************************/" > ${nameFichero} - Line1="${nameFichero}" - CompletaEspacios ${Line1} 47 - echo "/* ${lineOut}*/" >> ${nameFichero} - echo "/* */" >> ${nameFichero} - echo "/* Descripcion: */" >> ${nameFichero} - echo "/* */" >> ${nameFichero} - echo "/* */" >> ${nameFichero} - Line2="${authorSpace}" - CompletaEspacios ${Line2} 67 - echo "/* Autor : ${lineOut}*/" >> ${nameFichero} - echo "/* Fecha : ${strDate} */" >> ${nameFichero} - echo "/* */" >> ${nameFichero} - echo "/* C0pyl3ft - ${year} | Open Source License */" >> ${nameFichero} - echo "/********************************************************************************/" >> ${nameFichero} - echo "/********************************************************************************/" >> ${nameFichero} - echo "/* Ejecucion: */" >> ${nameFichero} - echo "/* */" >> ${nameFichero} - echo "/* */" >> ${nameFichero} - echo "/********************************************************************************/" >> ${nameFichero} - - echo "" >> ${nameFichero} -} - -print_bodyGO() -{ - echo "package main" >> ${nameFichero} - echo " " >> ${nameFichero} - echo "/**********************************/" >> ${nameFichero} - echo "/******** Import Packages *********/" >> ${nameFichero} - echo "/**********************************/" >> ${nameFichero} - echo "import (" >> ${nameFichero} - echo " \"fmt\"" >> ${nameFichero} - echo ")" >> ${nameFichero} - echo " " >> ${nameFichero} - echo " " >> ${nameFichero} - echo "/*****************************************************/" >> ${nameFichero} - echo "/******** Definicion de Estructuras - Inicio *********/" >> ${nameFichero} - echo "/*****************************************************/" >> ${nameFichero} - echo " " >> ${nameFichero} - echo "/*****************************************************/" >> ${nameFichero} - echo "/********** Definicion de Estructuras - Fin **********/" >> ${nameFichero} - echo "/*****************************************************/" >> ${nameFichero} - echo " " >> ${nameFichero} - echo " " >> ${nameFichero} - echo "/*****************************************************/" >> ${nameFichero} - echo "/***** Definicion de Constantes Globales - Inicio ****/" >> ${nameFichero} - echo "/*****************************************************/" >> ${nameFichero} - echo "const VERSION = \"${V}\"" >> ${nameFichero} - echo "/*****************************************************/" >> ${nameFichero} - echo "/****** Definicion de Constantes Globales - Fin ******/" >> ${nameFichero} - echo "/*****************************************************/" >> ${nameFichero} - echo " " >> ${nameFichero} - echo " " >> ${nameFichero} - echo "/*****************************************************/" >> ${nameFichero} - echo "/****** Definicion de Variables Globales - Inicio ****/" >> ${nameFichero} - echo "/*****************************************************/" >> ${nameFichero} - echo " " >> ${nameFichero} - echo "/*****************************************************/" >> ${nameFichero} - echo "/******* Definicion de Variables Globales - Fin ******/" >> ${nameFichero} - echo "/*****************************************************/" >> ${nameFichero} - echo " " >> ${nameFichero} - echo " " >> ${nameFichero} - echo "/*" >> ${nameFichero} - echo "*" >> ${nameFichero} - echo "* @author ${author} ${email}" >> ${nameFichero} - echo "* @date ${strDate2}" >> ${nameFichero} - echo "* @version ${V}" >> ${nameFichero} - echo "* @Company © Development ${year}" >> ${nameFichero} - echo "*" >> ${nameFichero} - echo "*/" >> ${nameFichero} - echo "func main() {" >> ${nameFichero} - echo "" >> ${nameFichero} - echo "}" >> ${nameFichero} -} - - -# /******************************** INICIO *************************************/ -# clear - -# -- se cargan la estructura del programa. -print_head -print_bodyGO - -# -- se cambiar permisologia del archivo creado. -chmod 775 ${nameFichero} - -# -- Libera las variables declaradas -unset strDate -unset strDate2 -unset strDateV -unset V -unset year -unset nameFichero -unset max_lenght_field -unset lineOut -unset author -unset authorSpace -unset email - -# --- salida exitosa del programa -exit 0 -#/******************************** FIN *************************************/ diff --git a/model/crud_sql.go b/model/crud_sql.go index 5909804..b207d3a 100755 --- a/model/crud_sql.go +++ b/model/crud_sql.go @@ -82,6 +82,32 @@ func updateSQL(table, set, where string, db *sql.DB) bool { return true } +/* +* +* @author Rodrigo G. Higuera M.(RGHM) +* @date 2020.07.21 23:47 +* @version 20200721.234700.0001 +* @Company © Development 2020 +* +* @func deleteSQL : Funcion que realiza la operacion de Delete en DDBB. +* * table : Tabla que se accedera para hacer el delete. +* * where : clausula where para eliminar registros. +* * db <*sql.DB> : Instancia de BBDD abierta. + */ +func deleteSQL(table, where string, db *sql.DB) bool { + sql := fmt.Sprintf("DELETE FROM %s WHERE %s ", table, where) + log.Println(sql) + + _, err := db.Exec(sql) + + if err != nil { + panic(err) + return false + } + + return true +} + /* * * @author Rodrigo G. Higuera M.(RGHM) diff --git a/model/receiver.go b/model/receiver.go index 7ee7159..ed10d99 100755 --- a/model/receiver.go +++ b/model/receiver.go @@ -67,6 +67,7 @@ func ProcessAjax(w http.ResponseWriter, r *http.Request) { psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", cfg.Host, cfg.Port, cfg.User, cfg.Passwd, cfg.DBname) fmt.Println(psqlInfo) db, err := sql.Open("postgres", psqlInfo) + defer cerrarDDBB(db) if err != nil { panic(err) @@ -226,8 +227,73 @@ func ProcessAjax(w http.ResponseWriter, r *http.Request) { fmt.Println("===============") fmt.Println(strconv.FormatBool(flag)) json.NewEncoder(w).Encode(strconv.FormatBool(flag)) + } else if o == "8f14e45fceea167a5a36dedd4bea2543" { + // -- determina si el id = ? tiene nodos hijos en la taxonomia. + // -- Return true : en caso de si tener nodos hijos. + // -- Return false : en caso de no tener nodos hijos. + var Fid string + + if public.IsNumeric(r.FormValue("vid")) { + Fid = r.FormValue("vid") + } else { + Fid = "NULL" + } + + cw := fmt.Sprintf(" pid = '%s'", Fid) + cont := SelectCountSQL("\"WorkshopGo\".taxonomy", cw, db) + var r bool + if cont > 0 { + r = true + } else { + r = false + } + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(strconv.FormatBool(r)) + } else if o == "c9f0f895fb98ab9159f51fd0297e236d" { + // -- delete del registro + var Fid string + + if public.IsNumeric(r.FormValue("vid")) { + Fid = r.FormValue("vid") + } else { + Fid = "NULL" + } + + cw := fmt.Sprintf(" pid = '%s'", Fid) + cont := SelectCountSQL("\"WorkshopGo\".taxonomy", cw, db) + var r, flag bool + if cont > 0 { + // -- borrar Hijos + cw = fmt.Sprintf(" pid = '%s'", Fid) + r = deleteSQL("\"WorkshopGo\".taxonomy", cw, db) + + // -- borrar Registro + cw = fmt.Sprintf(" id = '%s'", Fid) + flag = deleteSQL("\"WorkshopGo\".taxonomy", cw, db) + } else { + // -- borrar Registro + r = true + cw = fmt.Sprintf(" id = '%s'", Fid) + flag = deleteSQL("\"WorkshopGo\".taxonomy", cw, db) + } + + w.Header().Set("Content-Type", "application/json") + fmt.Println("Delete") + fmt.Println("===============") + if r { + fmt.Println(strconv.FormatBool(flag)) + json.NewEncoder(w).Encode(strconv.FormatBool(flag)) + } else { + fmt.Println(strconv.FormatBool(false)) + json.NewEncoder(w).Encode(strconv.FormatBool(false)) + } } } } + +func cerrarDDBB(db *sql.DB) { + fmt.Println("Cerrando Conex DDBB") + db.Close() +} diff --git a/view/crud2.html b/view/crud2.html index 03cd9ad..92c1ed9 100644 --- a/view/crud2.html +++ b/view/crud2.html @@ -258,11 +258,13 @@

Taxonomy Register

+
diff --git a/view/css/form.css b/view/css/form.css index 4d7a5fa..31d84db 100644 --- a/view/css/form.css +++ b/view/css/form.css @@ -53,4 +53,9 @@ textarea { #no_data_grid{ margin-top:60px; -} \ No newline at end of file +} + +#text_complementario { + position: relative; + padding: 15px; +}