1const URLSITE = `${location.protocol}//${location.host}`, 2 MODULE = 'Acordeon', 3 PATH = 'Transparencia', 4 COLUMNS = 'Title,IdPrincipal,item,IdPadre,Pagina,Orden'; 5 6export const consulteAcordion = async () => { 7 8 const URL = `${URLSITE}/${PATH}/_api/web/lists/getbytitle('${MODULE}')/items?&select=${COLUMNS}&$orderby=Orden asc&$top=1000`; 9 10 try { 11 const response = await fetch(URL, { 12 method: "GET", 13 headers: { 14 "Accept": "application/json;odata=verbose", 15 "Content-Type": "application/json;odata=verbose" 16 } 17 }); 18 19 if (response.ok) { 20 const data = await response.json(); 21 return data.d.results; 22 } 23 else { 24 const errorData = await response.json(); 25 console.error("Error al consultar el acordeón", errorData); 26 alert(`Error al consultar el acordeón: ${errorData.error.message.value}`); 27 } 28 29 } 30 catch (error) { 31 console.error("Error al consultar el acordeón", error); 32 alert(`Error al consultar el acordeón: ${error.message}`); 33 } 34 35}; 36 37export const getLastIdPrincipal = async() => { 38 const params = ["IdPrincipal"]; 39 const baseUrl = `${location.protocol}//${location.host}`; 40 41 const url = `${baseUrl}/Transparencia/_api/web/lists/getbytitle('Acordeon')/items?$select=${params.join(",")}&$orderby=IdPrincipal&$top=5000`; 42 43 const response = await fetch(url, { 44 method: "GET", 45 headers: { 46 Accept: "application/json; odata=verbose", 47 "Content-Type": "application/json; odata=verbose", 48 }, 49 }); 50 51 if (response.ok) { 52 const data = await response.json(); 53 const sortedItems = data.d.results.sort((a, b) => Number(a.IdPrincipal) - Number(b.IdPrincipal)); 54 return sortedItems[sortedItems.length - 1].IdPrincipal; 55 } else { 56 const errorData = await response.json(); 57 console.error("Error al consultar el último IdPrincipal", errorData); 58 alert(`Error al consultar el último IdPrincipal: ${errorData.error.message.value}`); 59 } 60}; 61 62export const getElementByID = async (id) => { 63 const url = `${location.protocol}//${location.host}/Transparencia/_api/web/lists/getbytitle('Acordeon')/items?$select=${COLUMNS}&$filter=IdPrincipal eq ${id}`; 64 65 const response = await fetch(url, { 66 method: "GET", 67 headers: { 68 Accept: "application/json; odata=verbose", 69 "Content-Type": "application/json; odata=verbose", 70 }, 71 }); 72 73 if (response.ok) { 74 const data = await response.json(); 75 return data.d.results; 76 } else { 77 const errorData = await response.json(); 78 console.error("Error al consultar el IdPrincipal", errorData); 79 alert(`Error al consultar el IdPrincipal: ${errorData.error.message.value}`); 80 } 81}; 82 83export const getIdElementInList = async (id) => { 84 const url = `${location.protocol}//${location.host}/Transparencia/_api/web/lists/getbytitle('Acordeon')/items?$select=ID&$filter=IdPrincipal eq ${id}`; 85 86 const response = await fetch(url, { 87 method: "GET", 88 headers: { 89 Accept: "application/json; odata=verbose", 90 "Content-Type": "application/json; odata=verbose", 91 }, 92 }); 93 94 if (response.ok) { 95 const data = await response.json(); 96 console.log("Elemento encontrado:", data.d.results); 97 return data.d.results[0].ID; 98 } else { 99 const errorData = await response.json(); 100 console.error("Error al consultar el IdPrincipal", errorData); 101 alert(`Error al consultar el IdPrincipal: ${errorData.error.message.value}`); 102 } 103}; 104 105// Función para insertar datos en SharePoint 106 export const insertData = async (data) => { 107 const url = `${location.protocol}//${location.host}/Transparencia/_api/web/lists/getbytitle('Acordeon')/items`; 108 const digestElement = document.getElementById("__REQUESTDIGEST"); 109 110 if (!digestElement) { 111 console.error("El elemento __REQUESTDIGEST no se encuentra en la página."); 112 alert("Error de autenticación. El token de solicitud no se encuentra en la página."); 113 return; 114 } 115 116 console.log("Insertando datos:", data); 117 118 try { 119 const response = await fetch(url, { 120 method: "POST", 121 headers: { 122 Accept: "application/json; odata=verbose", 123 "Content-Type": "application/json; odata=verbose", 124 "X-RequestDigest": digestElement.value, 125 }, 126 body: JSON.stringify(data), 127 }); 128 129 if (response.ok) { 130 const responseData = await response.json(); 131 console.log("Datos insertados correctamente:", responseData); 132 return true; 133 } else { 134 const errorResponse = await response.json(); 135 console.error("Error al insertar datos:", errorResponse); 136 alert(`Error al insertar datos: ${errorResponse.error.message.value}`); 137 throw new Error(`Error al insertar datos: ${errorResponse.error.message.value}`); 138 } 139 } catch (error) { 140 console.error("Error al insertar datos:", error); 141 alert(`Error al insertar datos: ${error.message}`); 142 throw error; 143 } 144}; 145 146// Función para actualizar datos en SharePoint 147export const updateData = async (data, id) => { 148 const url = `${location.protocol}//${location.host}/Transparencia/_api/web/lists/getbytitle('Acordeon')/items(${id})`; 149 const digestElement = document.getElementById("__REQUESTDIGEST"); 150 151 if (!digestElement) { 152 console.error("El elemento __REQUESTDIGEST no se encuentra en la página."); 153 alert("Error de autenticación. El token de solicitud no se encuentra en la página."); 154 return; 155 } 156 157 console.log("Actualizando datos:", data); 158 159 try { 160 const response = await fetch(url, { 161 method: "POST", 162 headers: { 163 Accept: "application/json; odata=verbose", 164 "Content-Type": "application/json; odata=verbose", 165 "X-RequestDigest": digestElement.value, 166 "X-HTTP-Method": "MERGE", 167 "If-Match": "*", 168 }, 169 body: JSON.stringify(data), 170 }); 171 172 if (response.ok) { 173 return true; 174 } else { 175 alert(`Error al actualizar datos: ${errorResponse.error.message.value}`); 176 throw new Error(`Error al actualizar datos: ${errorResponse.error.message.value}`); 177 } 178 } catch (error) { 179 console.error("Error al actualizar datos:", error); 180 alert(`Error al actualizar datos: ${error.message}`); 181 throw error; 182 } 183}; 184 185export const deleteData = async (id) => { 186 const url = `${location.protocol}//${location.host}/Transparencia/_api/web/lists/getbytitle('Acordeon')/items(${id})`; 187 const digestElement = document.getElementById("__REQUESTDIGEST"); 188 189 if (!digestElement) { 190 console.error("El elemento __REQUESTDIGEST no se encuentra en la página."); 191 alert("Error de autenticación. El token de solicitud no se encuentra en la página."); 192 return; 193 } 194 195 try { 196 const response = await fetch(url, { 197 method: "POST", 198 headers: { 199 Accept: "application/json; odata=verbose", 200 "Content-Type": "application/json; odata=verbose", 201 "X-RequestDigest": digestElement.value, 202 "X-HTTP-Method": "DELETE", 203 "If-Match": "*", 204 }, 205 }); 206 207 if (response.ok) { 208 return true; 209 } else { 210 const errorResponse = await response.json(); 211 console.error("Error al eliminar datos:", errorResponse); 212 alert(`Error al eliminar datos: ${errorResponse.error.message.value}`); 213 throw new Error(`Error al eliminar datos: ${errorResponse.error.message.value}`); 214 } 215 } catch (error) { 216 console.error("Error al eliminar datos:", error); 217 alert(`Error al eliminar datos: ${error.message}`); 218 throw error; 219 } 220}; 221
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.