Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a2c1026
Proyecto
gabyh7922 Jul 30, 2024
798d879
agregando home.js y cambios html
gabyh7922 Aug 4, 2024
e2572d8
dev: creando router
gabyh7922 Aug 5, 2024
5968dd0
Merge pull request #1 from gabyh7922/dev
gabyh7922 Aug 5, 2024
ab12f59
css inicial para home
pame-olguin Aug 7, 2024
5ec3245
recuperacion desde dataverse. cambio de css etc
pame-olguin Aug 7, 2024
1052fe2
Reubicar router, index y html
gabyh7922 Aug 7, 2024
e71d3d2
Merge pull request #2 from gabyh7922/dev
gabyh7922 Aug 7, 2024
07282ad
conflict con dev resuelto.
pame-olguin Aug 7, 2024
f143d52
se agrego contenido de dataFunctions.js desde elproyecto anterior
pame-olguin Aug 7, 2024
b35cd18
css de main a home
pame-olguin Aug 11, 2024
2217f55
pagina inicial arreglado para mostrar de mejor manera los resultados.…
pame-olguin Aug 11, 2024
b12cb64
router navigateTo mejorado para mostrar query string en la barra de n…
pame-olguin Aug 11, 2024
499af9f
logica de click de boton de limpiar simplificado. ahora solo hacemos …
pame-olguin Aug 12, 2024
d7543c0
Refactorizando y creando tarjeta en Detail
gabyh7922 Aug 13, 2024
cacf286
Merge pull request #3 from gabyh7922/dev
gabyh7922 Aug 13, 2024
c949b92
Merge pull request #4 from gabyh7922/dev
gabyh7922 Aug 13, 2024
dc225fa
se agrego definicion de metodo para comunicar con open ai
pame-olguin Aug 13, 2024
02c3017
conflicto resuelto con dev
pame-olguin Aug 13, 2024
1d843f4
subiendo imagenes
gabyh7922 Aug 13, 2024
e987c0e
imagenes
gabyh7922 Aug 13, 2024
16d70e2
pagina Detail ahora tiene su propia tarjeta con js y css.
pame-olguin Aug 13, 2024
989f00a
arreglo de estrucutra de Detail era necesario
pame-olguin Aug 13, 2024
b5bf48f
mejoramiento de css
pame-olguin Aug 13, 2024
6d7fc92
guardar api key ok. metodo para implementacion de comunicacion con Op…
pame-olguin Aug 14, 2024
55c88fe
ccss e imagen
gabyh7922 Aug 18, 2024
d61bb37
creando chat individual y grupal
gabyh7922 Aug 21, 2024
cadd3fa
dev: latest changes
gabyh7922 Aug 25, 2024
c3c83ff
test
gabyh7922 Aug 28, 2024
b0aafd5
Merge pull request #5 from gabyh7922/dev
gabyh7922 Aug 28, 2024
15d2477
test apikey
gabyh7922 Aug 28, 2024
d2179d2
Merge pull request #6 from gabyh7922/dev
gabyh7922 Aug 28, 2024
1510b1d
readme incorporando link de despliegue
gabyh7922 Aug 29, 2024
3f76196
Merge pull request #11 from gabyh7922/dev
gabyh7922 Sep 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
coverage/
node_modules/
.vscode/
.env
*.env
config.js
package-lock.json
858 changes: 47 additions & 811 deletions README.md

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"babel-jest": "^27.0.1",
"css": "^3.0.0",
"eslint": "^8.3.0",
"eslint-plugin-import": "^2.29.1",
"gh-pages": "^3.1.0",
"htmlhint": "^1.0.0",
"jest": "^27.0.1",
Expand All @@ -35,5 +36,10 @@
"createdAt": "2024-07-01T22:30:34.915Z",
"version": "9.1.1",
"commit": "1843c213affffa12aa456fa8842b6d28f97de2d3"
},
"dependencies": {
"axios": "^1.7.4",
"dotenv": "^16.4.5",
"openai": "^4.56.0"
}
}
}
30 changes: 30 additions & 0 deletions src/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { navigateTo } from '../../router.js';

export const renderCard = (card, full_data = false) => { //creando la constante para importarla en view.js

const ul = document.createElement("ul"); //creando el ul
ul.classList.add("card"); //agregando la clase card
ul.setAttribute("itemscope", ""); // Indicando que es un contenedor de datos
ul.setAttribute("itemtype", "https://schema.org/Person"); // Especificando el tipo de datos

ul.addEventListener('click', function () {
navigateTo('/detail', { id: card['id'] });
});

// revisamos si tiene fecha de la muerte. porque no todos tienen este dato
const yearOfDeath = card['facts']['yearOfDeath'] ? card['facts']['yearOfDeath'] : '-';
let datos = `
<li itemprop="image" class="item"><img src="${card['imageUrl']}" alt="Imagen de ${card['name']}" /></li>
<li itemprop="name" class="item">Nombre: ${card['name']}</li>`; //creando tarjeta que contiene informacion, debe ser trabajada en css
if (full_data) {
datos = datos + `<li itemprop="description" class="item">Descripción: ${card['shortDescription']}</li>
<li itemprop="birthDate" class="item">Año de Nacimiento: ${card['facts']['yearOfBirth']}</li>
<li itemprop="deathDate" class="item">Fecha de Muerte: ${yearOfDeath}</li>
<li itemprop="birthPlace" class="item">Lugar de Nacimiento: ${card['facts']['birthPlace']}</li>
<li itemprop="field" class="item">Especialidad: ${card['facts']['mainField']}</li>
`; // si se necesitan todos los datos, se agregan si se pasa el parametro full como true
}

ul.innerHTML = datos; //indicandole al ul que contendra el bloque html de la tarjeta
return ul; //retornando div
}
49 changes: 49 additions & 0 deletions src/categories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import data from './data/dataset.js'; //importa data
import { navigateTo } from './router.js';

export function renderCategories(params) {

const selectBox = document.createElement('select');
selectBox.setAttribute('name', 'mainField');
selectBox.setAttribute('id', 'mainField');
selectBox.setAttribute('data-testid', 'select-filter');

selectBox.addEventListener('change', function (event) {
const selectBoxOrder = document.querySelector('select#orderDir');
navigateTo('/', { category: event.target.value, order: selectBoxOrder.value });
});

const uniqueCategories = [];// array que contendra categorias unicas

// filtrar categorias unicas
for (let i = 0; i < data.length; i++) {

const cardData = data[i];
for (const category of cardData['facts']['mainField']) {
if (!uniqueCategories.includes(category)) {
uniqueCategories.push(category);
}
}
}

// agregando la primera opcion
const defaultOption = document.createElement("option");
defaultOption.value = '';
defaultOption.text = "- Filtrar por Categoría -";
selectBox.add(defaultOption);

// rellenar el selectBox con opciones de categorias unicas que construimos en arriba
for (const uniqueCat of uniqueCategories) {
const option = document.createElement("option");
option.value = uniqueCat;
option.text = uniqueCat;

if (params.category === uniqueCat) {
option.setAttribute('selected', true);
}

selectBox.add(option);
}

return selectBox;
}
307 changes: 307 additions & 0 deletions src/data/dataset.js

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/imagenes/imagen1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/imagenes/imagen2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/imagenes/imagen3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/imagenes/imagen4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/imagenes/th.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
37 changes: 28 additions & 9 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dataverse Chat</title>
<!--Aquí puedes importar tu archivo de CSS para agregar estilos.-->
</head>
<body>
<div id="root"></div>
<script src="index.js" type="module"></script>
</body>

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dataverse Chat</title>
<link rel="stylesheet" href="styles/main.css">
<!--Aquí puedes importar tu archivo de CSS para agregar estilos.-->
<!-- crear carpeta componet colocar todo lo que se vaya a reutilizar tal como renderview para utilizarlo ewn home en carpeta que se llame rendercomponent-->
</head>
<body>
<header>
<h1>MUJERES QUE INSPIRAN</h1>
<button id="return-home" class="hidden">Volver a principal</button>
</header>

<main>
<div id="root"></div>
</main>

<aside id="curious_fact">
<h3>Dato curioso:</h3>
<h4> Mayor participacion segun su ocupacion calculado en porcentaje es: </h4>
</aside>
<footer>Creado por : Gaby Hernández</footer>
<script src="./index.js" type="module"></script>
</body>

</html>
55 changes: 39 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
// En este archivo definirás tus rutas e importarás los componentes que vas a renderizar.
import Home from './views/home/Home.js';
import Detail from './views/detail/Detail.js';
import Error from './views/Error.js';
import Conference from './views/conference/Conference.js';

/*
import Example from './views/Example.js';

Ejemplo de definición de rutas:
// Importa otras vistas según sea necesario
import { setRootEl, setRoutes, onURLChange } from './router.js';

// Define las rutas y las vistas asociadas
const routes = {
"/": Example,
...
}
*/

/*
TODO:
1.- Definir rutas en router.
2.- Pasar "root element" a router.
3.- Invocar el router para renderizar la vista correcta.
*/
'/': Home,
'/detail': Detail,
'/error': Error,
'/conference': Conference,
// Agrega más rutas y vistas aquí
};

// Configura las rutas
setRoutes(routes);

// Asigna el elemento raíz donde se renderizarán las vistas
window.addEventListener("DOMContentLoaded", () => {
// Supongamos que tu elemento raíz en el HTML es un div con id 'root'
const rootElement = document.getElementById('root');
setRootEl(rootElement);



// Maneja la carga de la página inicial
onURLChange(window.location);

// Escucha los cambios de URL (navegación)
window.onpopstate = () => onURLChange(window.location);

const getBackHome = document.getElementsByTagName("header")[0];
getBackHome.addEventListener('click', function () {
document.location.href = "/";
});



});
30 changes: 30 additions & 0 deletions src/lib/apiKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const getApiKey = () => {
// Obtener la API KEY desde Local Storage
try {
const api_key = localStorage.getItem('apiKey');
if (!api_key) {
throw new Error('Api Key not defined!');
}
return api_key;
} catch (error) {
const api_key = prompt("Por favor ingresa una Open AI Key");

// Validar que la clave tiene la longitud correcta
if (!api_key || api_key.length <= 160) {
alert("Api Key invalida, por favor ingresa una Open AI api key");
return null; // Detener la recursión si la clave no es válida
}

setApiKey(api_key);
return api_key; // Retornar la clave válida
}
};

export const setApiKey = (key) => {
// Guardar la API KEY en Local Storage
try {
sessionStorage.setItem('apiKey', key);//permite almacenar datos de forma persistente en el navegador.
} catch (error) {
alert('Error al guardar la API KEY:', error);
}
};
49 changes: 49 additions & 0 deletions src/lib/datafunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export const filterData = (data,value='') => {

// filtrar tarjetas
// Si estamos filtrando por una categoría específica
if( value ){
return data.filter((cardData)=>cardData['facts']['mainField'].includes(value));
}
else{
// por defecto mostrar todos los datos
return data;
}
}

// ORDENAR DATOS
export const sortData = (data,sortOrder='asc') => {

// ordenar por nombre

if( sortOrder === 'desc'){
data.sort((a,b)=>b.name.localeCompare(a.name));
}
else{
// ordenar ascendiente por defecto
data.sort((a,b)=>a.name.localeCompare(b.name));
}


return data;
}

// STATS
export const computeStats = (data) => {
// Usar reduce para contar las ocurrencias de cada campo
const fieldCounts = data.reduce((acc, card) => {
card.facts.mainField.forEach(dato => {
acc[dato] = (acc[dato] || 0) + 1;
});
return acc;
}, {});

const totalItems = data.length;

// Calcular los porcentajes
const fieldPercentages = Object.fromEntries(
Object.entries(fieldCounts).map(([key, value]) => [key, `${Math.round((value / totalItems) * 100)}%`])
);

return fieldPercentages;
}
81 changes: 81 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
let ROUTES = {};
let rootEl;

export const setRootEl = (el) => {
rootEl = el;
};

export const setRoutes = (routes) => {
if (typeof routes !== 'object') {
throw new Error('Routes should be an object.');
}
if (!routes['/error']) {
throw new Error('Routes should define an /error route.');
}
ROUTES = routes;
};

const queryStringToObject = (queryString) => {
const params = new URLSearchParams(queryString);
const queryObject = {};
for (const [key, value] of params) {
queryObject[key] = value;
}
return queryObject;
};

const renderView = (pathname, props = {}) => {
if (!rootEl) {
throw new Error('Root element is not set.');
}

// Clear the root element
rootEl.innerHTML = '';

// Find the correct view in ROUTES for the pathname
const view = ROUTES[pathname] || ROUTES['/error'];

// Render the correct view passing the value of props
const viewEl = view(props);

// Add the view element to the DOM root element
rootEl.appendChild(viewEl);
};

export const navigateTo = (pathname, props = {}) => {
// Update window history with pushState
window.history.pushState({}, pathname, window.location.origin + pathname + objectToQueryString(props));
// Render the view with the pathname and props
renderView(pathname, props);
};

export const onURLChange = (location) => {
const { pathname, search } = location;
// Convert the search params to an object
const queryObject = queryStringToObject(search);
// Render the view with the pathname and query object
renderView(pathname, queryObject);
};

export const objectToQueryString = (props) => {
if (Object.keys(props).length !== 0) {
let str = '?';
for (const i in props) {
str += i + '=' + props[i] + '&';
}

if (str.endsWith("&")) {
str = str.slice(0, -1);
}

return str;
}
else {
return '';
}
}

// Set up the popstate event listener for back/forward navigation
window.onpopstate = () => {
onURLChange(window.location);
};
Loading