1const URLSITE = `${location.protocol}//${location.host}`, 2 MODULE = 'Acordeon', 3 PATH = 'Transparencia', 4 COLUMNS = 'Title,IdPrincipal,item,IdPadre,Pagina'; 5 6export const consulteAcordion = async () => { 7 8 const URL = `${URLSITE}/${PATH}/_api/web/lists/getbytitle('${MODULE}')/items?&select=${COLUMNS}&$orderby=IdPrincipal 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 // Ordenar numéricamente por el campo 'item' considerando numeración decimal 22 const sortedResults = data.d.results.sort((a, b) => { 23 const itemA = a.item || ''; 24 const itemB = b.item || ''; 25 26 // Dividir por puntos y comparar cada parte numéricamente 27 const partsA = itemA.toString().split('.').map(part => parseInt(part) || 0); 28 const partsB = itemB.toString().split('.').map(part => parseInt(part) || 0); 29 30 // Comparar cada nivel de la numeración 31 const maxLength = Math.max(partsA.length, partsB.length); 32 for (let i = 0; i < maxLength; i++) { 33 const partA = partsA[i] || 0; 34 const partB = partsB[i] || 0; 35 36 if (partA !== partB) { 37 return partA - partB; 38 } 39 } 40 41 return 0; 42 }); 43 return sortedResults; 44 } 45 else { 46 const errorData = await response.json(); 47 console.error("Error al consultar el acordeón", errorData); 48 alert(`Error al consultar el acordeón: ${errorData.error.message.value}`); 49 } 50 51 } 52 catch (error) { 53 console.error("Error al consultar el acordeón", error); 54 alert(`Error al consultar el acordeón: ${error.message}`); 55 } 56 57}; 58 59export const getLastIdPrincipal = async() => { 60 const params = ["IdPrincipal"]; 61 const baseUrl = `${location.protocol}//${location.host}`; 62 63 const url = `${baseUrl}/Transparencia/_api/web/lists/getbytitle('Acordeon')/items?$select=${params.join(",")}&$orderby=IdPrincipal&$top=5000`; 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 const sortedItems = data.d.results.sort((a, b) => Number(a.IdPrincipal) - Number(b.IdPrincipal)); 76 return sortedItems[sortedItems.length - 1].IdPrincipal; 77 } else { 78 const errorData = await response.json(); 79 console.error("Error al consultar el último IdPrincipal", errorData); 80 alert(`Error al consultar el último IdPrincipal: ${errorData.error.message.value}`); 81 } 82}; 83 84export const getElementByID = async (id) => { 85 const url = `${location.protocol}//${location.host}/Transparencia/_api/web/lists/getbytitle('Acordeon')/items?$select=${COLUMNS}&$filter=IdPrincipal eq ${id}`; 86 87 const response = await fetch(url, { 88 method: "GET", 89 headers: { 90 Accept: "application/json; odata=verbose", 91 "Content-Type": "application/json; odata=verbose", 92 }, 93 }); 94 95 if (response.ok) { 96 const data = await response.json(); 97 return data.d.results; 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 105export const getIdElementInList = async (id) => { 106 const url = `${location.protocol}//${location.host}/Transparencia/_api/web/lists/getbytitle('Acordeon')/items?$select=ID&$filter=IdPrincipal eq ${id}`; 107 108 const response = await fetch(url, { 109 method: "GET", 110 headers: { 111 Accept: "application/json; odata=verbose", 112 "Content-Type": "application/json; odata=verbose", 113 }, 114 });
115 116 if (response.ok) { 117 const data = await response.json(); 118 console.log("Elemento encontrado:", data.d.results); 119 return data.d.results[0].ID; 120 } else { 121 const errorData = await response.json(); 122 console.error("Error al consultar el IdPrincipal", errorData); 123 alert(`Error al consultar el IdPrincipal: ${errorData.error.message.value}`); 124 } 125}; 126 127// Función para insertar datos en SharePoint 128 export const insertData = async (data) => { 129 const url = `${location.protocol}//${location.host}/Transparencia/_api/web/lists/getbytitle('Acordeon')/items`; 130 const digestElement = document.getElementById("__REQUESTDIGEST"); 131 132 if (!digestElement) { 133 console.error("El elemento __REQUESTDIGEST no se encuentra en la página."); 134 alert("Error de autenticación. El token de solicitud no se encuentra en la página."); 135 return; 136 } 137 138 console.log("Insertando datos:", data); 139 140 try { 141 const response = await fetch(url, { 142 method: "POST", 143 headers: { 144 Accept: "application/json; odata=verbose", 145 "Content-Type": "application/json; odata=verbose", 146 "X-RequestDigest": digestElement.value, 147 }, 148 body: JSON.stringify(data), 149 }); 150 151 if (response.ok) { 152 const responseData = await response.json(); 153 console.log("Datos insertados correctamente:", responseData); 154 return true; 155 } else { 156 const errorResponse = await response.json(); 157 console.error("Error al insertar datos:", errorResponse); 158 alert(`Error al insertar datos: ${errorResponse.error.message.value}`); 159 throw new Error(`Error al insertar datos: ${errorResponse.error.message.value}`); 160 } 161 } catch (error) { 162 console.error("Error al insertar datos:", error); 163 alert(`Error al insertar datos: ${error.message}`); 164 throw error; 165 } 166}; 167 168// Función para actualizar datos en SharePoint 169export const updateData = async (data, id) => { 170 const url = `${location.protocol}//${location.host}/Transparencia/_api/web/lists/getbytitle('Acordeon')/items(${id})`; 171 const digestElement = document.getElementById("__REQUESTDIGEST"); 172 173 if (!digestElement) { 174 console.error("El elemento __REQUESTDIGEST no se encuentra en la página."); 175 alert("Error de autenticación. El token de solicitud no se encuentra en la página."); 176 return; 177 } 178 179 console.log("Actualizando datos:", data); 180 181 try { 182 const response = await fetch(url, { 183 method: "POST", 184 headers: { 185 Accept: "application/json; odata=verbose", 186 "Content-Type": "application/json; odata=verbose", 187 "X-RequestDigest": digestElement.value, 188 "X-HTTP-Method": "MERGE", 189 "If-Match": "*", 190 }, 191 body: JSON.stringify(data), 192 }); 193 194 if (response.ok) { 195 return true; 196 } else { 197 alert(`Error al actualizar datos`); 198 } 199 } catch (error) { 200 console.error("Error al actualizar datos:", error); 201 alert(`Error al actualizar datos: ${error.message}`); 202 throw error; 203 } 204}; 205 206export const deleteData = async (id) => { 207 const url = `${location.protocol}//${location.host}/Transparencia/_api/web/lists/getbytitle('Acordeon')/items(${id})`; 208 const digestElement = document.getElementById("__REQUESTDIGEST"); 209 210 if (!digestElement) { 211 console.error("El elemento __REQUESTDIGEST no se encuentra en la página."); 212 alert("Error de autenticación. El token de solicitud no se encuentra en la página."); 213 return; 214 } 215 216 try { 217 const response = await fetch(url, { 218 method: "POST", 219 headers: { 220 Accept: "application/json; odata=verbose", 221 "Content-Type": "application/json; odata=verbose", 222 "X-RequestDigest": digestElement.value, 223 "X-HTTP-Method": "DELETE", 224 "If-Match": "*", 225 }, 226 }); 227 228 if (response.ok) { 229 return true; 230 } else { 231 const errorResponse = await response.json(); 232 console.error("Error al eliminar datos:", errorResponse); 233 alert(`Error al eliminar datos: ${errorResponse.error.message.value}`); 234 throw new Error(`Error al eliminar datos: ${errorResponse.error.message.value}`); 235 } 236 } catch (error) { 237 console.error("Error al eliminar datos:", error); 238 alert(`Error al eliminar datos: ${error.message}`); 239 throw error; 240 } 241}; 242
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.