PageSourceSearch

https://campoalegre-huila.gov.co/SiteAssets/MicrositioMujer/components/home/calendar/API.js

js campoalegre-huila.gov.co collected 2026-09-24 10:18:57 UTC 2,813 bytes, 97 lines download raw bytes

1  let eventsList = [];
2export const getEvents = async (currentMonth, currentYear) => {
3
4
5  if(eventsList.length === 0) {
6    console.log("Fetching events from SharePoint...");
7    eventsList = await getEventsList();
8  }
9
10  if (eventsList.length === 0) {
11    return [];
12  }
13
14  if (eventsList.length > 0) {
15    const events = await Promise.all(
16      eventsList.map(async (event) => ({
17        title: event.Title,
18        date: event.EventDate,
19        endDate: event.EndDate,
20        location: event.Location || "Sin ubicación",
21        description: event.Description || "Sin descripción",
22        link: event.Url || event.Imagen || "#",
23        img: event.Imagen || null,
24      }))
25    );
26
27    let eventsFiltered = [];
28    events.forEach((event) => {
29      const eventDate = new Date(event.date);
30      const localEventDate = new Date(
31        eventDate.getTime() + eventDate.getTimezoneOffset() * 60000
32      );
33      const eventMonth = localEventDate.getMonth();
34      const eventYear = localEventDate.getFullYear();
35      if (currentMonth === eventMonth && currentYear === eventYear) {
36        eventsFiltered.push(event);
37      }
38    });
39
40    const eventsPerDay = formatData(eventsFiltered);
41    return eventsPerDay;
42  }
43};
44
45//Function to get events from SharePoint
46const getEventsList = async () => {
47  const baseUrl = `${location.protocol}//${location.host}`;
48  const library = "CalendarioEventos";
49  const params = ["Title", "EventDate", "EndDate", "Id", "Description", "Url", "Imagen", "Location" ];
50  let url = `${baseUrl}/Mujer/_api/web/lists/getbytitle('${library}')/items?$select=${params.join(
51    ","
52  )}&$orderby=EventDate asc`;
53    let allResults = [];
54
55  try {
56    while (url) {
57      const response = await fetch(url, {
58        method: "GET",
59        headers: {
60          Accept: "application/json;odata=verbose",
61        },
62      });
63
64      const data = await response.json();
65      allResults = allResults.concat(data.d.results);
66
67      // SharePoint pagination: check for __next property
68      url = data.d.__next || null;
69    }
70    return allResults;
71  } catch (error) {
72    console.error("Error al obtener los eventos:", error);
73    return [];
74  }
75};
76
77//Function to group events by day
78const formatData = (events) => {
79  const groupedEvents = events.reduce((acc, event) => {
80    const eventDate = new Date(event.date);
81    const localEventDate = new Date(
82      eventDate.getTime() + eventDate.getTimezoneOffset() * 60000
83    );
84    const day = localEventDate.getDate();
85    if (!acc[day]) {
86      acc[day] = [];
87    }
88    acc[day].push(event);
89    return acc;
90  }, {});
91
92  return Object.keys(groupedEvents).map((day) => ({
93    day: parseInt(day),
94    events: groupedEvents[day],
95  }));
96};
97

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.