Backend: Created multiple categories for tags, removed specific ones. Frontend: Adapted to new database, deleted processdata.js which is no longer used.

This commit is contained in:
Yohan Boujon 2024-02-11 15:52:51 +01:00
parent 50b39a745b
commit 56f1a37aec
14 changed files with 246 additions and 248 deletions

View file

@ -0,0 +1,13 @@
-- public.categories definition
-- Drop table
-- DROP TABLE public.categories;
CREATE TABLE public.categories (
id serial4 NOT NULL,
"name" text NOT NULL,
icon text NOT NULL,
type_icon text NOT NULL,
CONSTRAINT categories_pk PRIMARY KEY (id)
);

17
backend/db/3_skills.sql Normal file
View file

@ -0,0 +1,17 @@
-- public.skills definition
-- Drop table
-- DROP TABLE public.skills;
CREATE TABLE public.skills (
id serial4 NOT NULL,
category_id int4 DEFAULT nextval('skills_category_seq'::regclass) NOT NULL,
skill text NULL,
icon text NULL,
type_icon text NULL,
color varchar(7) NULL,
is_shown bool NULL,
CONSTRAINT skills_pk PRIMARY KEY (id),
CONSTRAINT skills_categories_fk FOREIGN KEY (category_id) REFERENCES public.categories(id)
);

View file

@ -0,0 +1,13 @@
-- public.categories_text definition
-- Drop table
-- DROP TABLE public.categories_text;
CREATE TABLE public.categories_text (
category_id serial4 NOT NULL,
lang_id serial4 NOT NULL,
"name" text NOT NULL,
CONSTRAINT categories_text_categories_fk FOREIGN KEY (category_id) REFERENCES public.categories(id),
CONSTRAINT categories_text_languages_fk FOREIGN KEY (lang_id) REFERENCES public.languages(id)
);

View file

@ -4,11 +4,11 @@
-- DROP TABLE public.skills; -- DROP TABLE public.skills;
CREATE TABLE public.skills ( CREATE TABLE public.info_text (
softskills text NULL, softskills text NULL,
interests text NULL, interests text NULL,
lang_id serial4 NOT NULL, lang_id int4 NOT NULL,
title text NULL, title text NULL,
description text NULL, description text NULL,
CONSTRAINT skills_languages_fk FOREIGN KEY (lang_id) REFERENCES public.languages(id) CONSTRAINT skills_languages_fk FOREIGN KEY (lang_id) REFERENCES public.languages(id)
); );;

View file

@ -1,14 +0,0 @@
-- public.programming_languages definition
-- Drop table
-- DROP TABLE public.programming_languages;
CREATE TABLE public.programming_languages (
id serial4 NOT NULL,
lang text NOT NULL,
icon text NOT NULL,
type_icon text NOT NULL,
color varchar(7) NULL,
CONSTRAINT programming_languages_pkey PRIMARY KEY (id)
);

View file

@ -1,14 +0,0 @@
-- public.softwares definition
-- Drop table
-- DROP TABLE public.softwares;
CREATE TABLE public.softwares (
id serial4 NOT NULL,
software text NOT NULL,
icon text NOT NULL,
type_icon text NOT NULL,
color varchar(7) NULL,
CONSTRAINT softwares_pkey PRIMARY KEY (id)
);

View file

@ -6,9 +6,7 @@
CREATE TABLE public.project_tags ( CREATE TABLE public.project_tags (
project_id int4 NOT NULL, project_id int4 NOT NULL,
programming_languages_id int4 NULL, skills_id int4 NOT NULL,
softwares_id int4 NULL,
CONSTRAINT project_tags_programming_languages_fk FOREIGN KEY (programming_languages_id) REFERENCES public.programming_languages(id),
CONSTRAINT project_tags_project_fk FOREIGN KEY (project_id) REFERENCES public.project(id), CONSTRAINT project_tags_project_fk FOREIGN KEY (project_id) REFERENCES public.project(id),
CONSTRAINT project_tags_softwares_fk FOREIGN KEY (softwares_id) REFERENCES public.softwares(id) CONSTRAINT project_tags_skills_fk FOREIGN KEY (skills_id) REFERENCES public.skills(id)
); );

View file

@ -57,19 +57,26 @@ pub struct Project {
} }
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
pub struct ProgrammingLanguages { pub struct Categories {
pub lang: Option<String>, pub id: Option<i32>,
pub name: Option<String>
}
#[derive(Deserialize,Serialize,Clone)]
pub struct CategoriesText {
pub icon: Option<String>, pub icon: Option<String>,
pub type_icon: Option<String>, pub type_icon: Option<String>,
pub color: Option<String> pub name: Option<String>
} }
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
pub struct Softwares { pub struct Skills {
pub software: Option<String>, pub id: Option<i32>,
pub skill: Option<String>,
pub icon: Option<String>, pub icon: Option<String>,
pub type_icon: Option<String>, pub type_icon: Option<String>,
pub color: Option<String> pub color: Option<String>,
pub is_shown: Option<bool>
} }
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
@ -81,20 +88,13 @@ pub struct Languages {
} }
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
pub struct Tags { pub struct AllSkills {
pub lang: Option<String>,
pub icon: Option<String>,
pub type_icon: Option<String>,
pub color: Option<String>
}
#[derive(Deserialize, Serialize)]
pub struct AllTags {
pub project_id: Option<i32>, pub project_id: Option<i32>,
pub lang: Option<String>, pub skill: Option<String>,
pub icon: Option<String>, pub icon: Option<String>,
pub type_icon: Option<String>, pub type_icon: Option<String>,
pub color: Option<String> pub color: Option<String>,
pub is_shown: Option<bool>
} }
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
@ -102,3 +102,8 @@ pub struct SimpleProject {
pub project_id: Option<i32>, pub project_id: Option<i32>,
pub title: Option<String> pub title: Option<String>
} }
#[derive(Deserialize,Serialize)]
pub struct Id {
pub id: Option<i32>
}

View file

@ -11,8 +11,8 @@ use tower_http::cors::CorsLayer;
mod db; mod db;
use db::{ use db::{
AllTags, Education, Experience, Info, LangId, Languages, ProgrammingLanguages, Project, AllSkills, Categories, CategoriesText, Education, Experience, Id, Info, LangId, Languages,
SimpleProject, Softwares, Tags, Project, SimpleProject, Skills,
}; };
#[tokio::main] #[tokio::main]
@ -32,17 +32,11 @@ async fn main() -> Result<()> {
.route("/education/:lang_id", get(education)) .route("/education/:lang_id", get(education))
.route("/experience/:lang_id", get(experience)) .route("/experience/:lang_id", get(experience))
.route("/project/:lang_id", get(projects)) .route("/project/:lang_id", get(projects))
.route("/categories/:lang_id", get(categories_text))
.route("/hard_skills", get(hard_skills)) .route("/hard_skills", get(hard_skills))
.route("/tags/:project_id", get(tags)) .route("/tags/:project_id", get(tags))
.route("/tags", get(alltags)) .route("/tags", get(alltags))
.route( .route("/getproject_programming/:lang_id", get(getproject_skills))
"/getproject_programming/:programming_id/:lang_id",
get(getproject_programming),
)
.route(
"/getproject_software/:software_id/:lang_id",
get(getproject_software),
)
.with_state(pool) .with_state(pool)
.layer(CorsLayer::very_permissive()); .layer(CorsLayer::very_permissive());
@ -80,10 +74,10 @@ async fn info(Path(lang_id): Path<i32>, State(pool): State<PgPool>) -> Json<Vec<
(SELECT email FROM public.info LIMIT 1) AS email, (SELECT email FROM public.info LIMIT 1) AS email,
(SELECT birth_year FROM public.info LIMIT 1) AS birth_year, (SELECT birth_year FROM public.info LIMIT 1) AS birth_year,
(SELECT profile_pic FROM public.info LIMIT 1) AS profile_pic, (SELECT profile_pic FROM public.info LIMIT 1) AS profile_pic,
(SELECT title FROM public.skills WHERE lang_id = $1 LIMIT 1) AS title, (SELECT title FROM public.info_text WHERE lang_id = $1 LIMIT 1) AS title,
(SELECT softskills FROM public.skills WHERE lang_id = $1 LIMIT 1) AS softskills, (SELECT softskills FROM public.info_text WHERE lang_id = $1 LIMIT 1) AS softskills,
(SELECT interests FROM public.skills WHERE lang_id = $1 LIMIT 1) AS interests, (SELECT interests FROM public.info_text WHERE lang_id = $1 LIMIT 1) AS interests,
(SELECT description FROM public.skills WHERE lang_id = $1 LIMIT 1) AS description;", (SELECT description FROM public.info_text WHERE lang_id = $1 LIMIT 1) AS description;",
lang_id lang_id
) )
.fetch_all(&pool) .fetch_all(&pool)
@ -166,37 +160,44 @@ ORDER BY p.date_done DESC;",
Json(datas) Json(datas)
} }
async fn hard_skills( async fn categories_text(
Path(lang_id): Path<i32>,
State(pool): State<PgPool>, State(pool): State<PgPool>,
) -> Json<(Vec<ProgrammingLanguages>, Vec<Softwares>, Vec<Languages>)> { ) -> Json<Vec<CategoriesText>> {
let programming_languages = sqlx::query_as!( let categories = sqlx::query_as!(
ProgrammingLanguages, Categories,
"SELECT "select
pl.lang, c.id,
pl.icon, c.name
pl.type_icon, from
pl.color public.categories c
FROM public.programming_languages pl order by
ORDER BY pl.id;" c.id;"
) )
.fetch_all(&pool) .fetch_all(&pool)
.await .await
.unwrap_or(vec![]); .unwrap();
let softwares = sqlx::query_as!( let mut categories_text: Vec<CategoriesText> = Vec::new();
Softwares,
for c in categories {
let temp_category = sqlx::query_as!(
CategoriesText,
"SELECT "SELECT
s.software, (SELECT icon FROM public.categories where id = $1 LIMIT 1) AS icon,
s.icon, (SELECT type_icon FROM public.categories where id = $1 LIMIT 1) AS type_icon,
s.type_icon, (SELECT name FROM public.categories_text WHERE category_id = $1 and lang_id = $2 LIMIT 1) AS name;"
s.color ,c.id.unwrap(),lang_id
FROM public.softwares s ).fetch_all(&pool)
ORDER BY s.id;"
)
.fetch_all(&pool)
.await .await
.unwrap_or(vec![]); .unwrap();
categories_text.push(temp_category[0].clone());
}
Json(categories_text)
}
async fn hard_skills(State(pool): State<PgPool>) -> Json<(Vec<Languages>, Vec<Vec<Skills>>)> {
let languages = sqlx::query_as!( let languages = sqlx::query_as!(
Languages, Languages,
"SELECT "SELECT
@ -210,23 +211,66 @@ async fn hard_skills(
.fetch_all(&pool) .fetch_all(&pool)
.await .await
.unwrap(); .unwrap();
Json((programming_languages, softwares, languages))
let categories = sqlx::query_as!(
Categories,
"select
c.id,
c.name
from
public.categories c
order by
c.id;"
)
.fetch_all(&pool)
.await
.unwrap();
let mut skills: Vec<Vec<Skills>> = Vec::new();
for c in categories {
let skill_list = sqlx::query_as!(
Skills,
"select
s.id,
s.skill,
s.icon,
s.type_icon,
s.color,
s.is_shown
from
public.skills s
where
s.category_id = $1
order by
s.id;",
c.id.unwrap()
)
.fetch_all(&pool)
.await
.unwrap();
skills.push(skill_list);
}
Json((languages, skills))
} }
async fn tags(Path(project_id): Path<i32>, State(pool): State<PgPool>) -> Json<Vec<Tags>> { async fn tags(Path(project_id): Path<i32>, State(pool): State<PgPool>) -> Json<Vec<Skills>> {
let datas = sqlx::query_as!( let datas = sqlx::query_as!(
Tags, Skills,
"SELECT lang, icon, type_icon, color "select
FROM public.programming_languages pl s.id,
JOIN public.project_tags pt ON pl.id = pt.programming_languages_id s.skill,
WHERE pt.project_id = $1 s.icon,
s.type_icon,
UNION ALL s.color,
s.is_shown
SELECT software, icon, type_icon, color from
FROM public.softwares s public.skills s
JOIN public.project_tags pt ON s.id = pt.softwares_id join public.project_tags pt on
WHERE pt.project_id = $1;", s.id = pt.skills_id
where
pt.project_id = $1",
project_id project_id
) )
.fetch_all(&pool) .fetch_all(&pool)
@ -235,19 +279,22 @@ async fn tags(Path(project_id): Path<i32>, State(pool): State<PgPool>) -> Json<V
Json(datas) Json(datas)
} }
async fn alltags(State(pool): State<PgPool>) -> Json<Vec<AllTags>> { async fn alltags(State(pool): State<PgPool>) -> Json<Vec<AllSkills>> {
let datas = sqlx::query_as!( let datas = sqlx::query_as!(
AllTags, AllSkills,
"SELECT project_id, lang, icon, type_icon, color "select
FROM public.programming_languages pl pt.project_id,
JOIN public.project_tags pt ON pl.id = pt.programming_languages_id s.skill,
s.icon,
UNION ALL s.type_icon,
s.color,
SELECT project_id, software, icon, type_icon, color s.is_shown
FROM public.softwares s from
JOIN public.project_tags pt ON s.id = pt.softwares_id public.skills s
ORDER BY project_id;" join public.project_tags pt on
s.id = pt.skills_id
order by
pt.project_id;"
) )
.fetch_all(&pool) .fetch_all(&pool)
.await .await
@ -255,48 +302,49 @@ async fn alltags(State(pool): State<PgPool>) -> Json<Vec<AllTags>> {
Json(datas) Json(datas)
} }
async fn getproject_programming( async fn getproject_skills(
Path(ids): Path<(i32,i32)>, Path(lang_id): Path<i32>,
State(pool): State<PgPool>, State(pool): State<PgPool>,
) -> Json<Vec<SimpleProject>> { ) -> Json<Vec<Vec<SimpleProject>>> {
let (programming_id, lang_id) = ids; let project_ids = sqlx::query_as!(
let datas = sqlx::query_as!( Id,
"select
s.id
from
public.skills s
order by
s.id;"
)
.fetch_all(&pool)
.await
.unwrap();
let mut project_skills: Vec<Vec<SimpleProject>> = Vec::new();
for p in project_ids {
project_skills.push(
sqlx::query_as!(
SimpleProject, SimpleProject,
" SELECT "select
pt.project_id, pt.project_id,
pt.title pt.title
FROM public.project_text pt from
JOIN public.project_tags pta ON (pt.project_id = pta.project_id) AND (pt.lang_id = $1) public.project_text pt
WHERE pta.programming_languages_id = $2 join public.project_tags pta on
ORDER BY pt.project_id;", (pt.project_id = pta.project_id)
and (pt.lang_id = $1)
where
pta.skills_id = $2
order by
pt.project_id;",
lang_id, lang_id,
programming_id p.id.unwrap(),
) )
.fetch_all(&pool) .fetch_all(&pool)
.await .await
.unwrap(); .unwrap(),
Json(datas) );
} }
async fn getproject_software( Json(project_skills)
Path(ids): Path<(i32,i32)>,
State(pool): State<PgPool>,
) -> Json<Vec<SimpleProject>> {
let (software_id, lang_id) = ids;
let datas = sqlx::query_as!(
SimpleProject,
" SELECT
pt.project_id,
pt.title
FROM public.project_text pt
JOIN public.project_tags pta ON (pt.project_id = pta.project_id) AND (pt.lang_id = $1)
WHERE pta.softwares_id = $2
ORDER BY pt.project_id;",
lang_id,
software_id
)
.fetch_all(&pool)
.await
.unwrap();
Json(datas)
} }

View file

@ -118,6 +118,7 @@
function calculateNotification() { function calculateNotification() {
// 19 is arbitrary, based on the pill-notification width (which is around 25.6 px) minus a constant // 19 is arbitrary, based on the pill-notification width (which is around 25.6 px) minus a constant
if (!show_tooltip || tooltip_data.length <= 0) return;
pill_notification.style.left = `${ pill_notification.style.left = `${
main_pill.offsetLeft + main_pill.clientWidth - 19 main_pill.offsetLeft + main_pill.clientWidth - 19
}px`; }px`;

View file

@ -214,7 +214,7 @@
<div class="project-popup-link-container project-popup-tag-container"> <div class="project-popup-link-container project-popup-tag-container">
{#each filteredTags as tag} {#each filteredTags as tag}
<Pill <Pill
name={tag.lang} name={tag.skill}
type_icon={tag.type_icon} type_icon={tag.type_icon}
icon={tag.icon} icon={tag.icon}
color="#F8F1F1" color="#F8F1F1"

View file

@ -1,23 +0,0 @@
function arrangeById(array) {
let newArray = new Array(array.length);
for (const value of array) {
newArray[value.id-1] = value;
}
return newArray;
}
export function processData(data) {
if (data.status === 0) {
const info = data.info[0];
const experiences = data.experience;
const education = data.education;
const skills = data.skills;
const tags = data.tags;
const project_programming = data.project_programming;
const project_software = data.project_software;
return {info, experiences, education, skills, tags, project_programming, project_software};
} else {
return null; // Indicates an error
}
}

View file

@ -57,13 +57,11 @@ export async function load(context) {
} }
} }
// Gathering data from databse // Gathering data from database
const infos = []; const infos = [];
const project_software = [];
const project_programming = [];
const dataToGather = [ const dataToGather = [
`info/${lang_id}`, `education/${lang_id}`, `experience/${lang_id}`, `info/${lang_id}`, `education/${lang_id}`, `experience/${lang_id}`,
`project/${lang_id}`, 'hard_skills', 'tags' `project/${lang_id}`, 'hard_skills', 'tags', `getproject_programming/${lang_id}`, `categories/${lang_id}`
]; ];
for (const url of dataToGather) { for (const url of dataToGather) {
const res = await fetchData(url); const res = await fetchData(url);
@ -77,45 +75,18 @@ export async function load(context) {
} }
} }
// infos[4] = hardskills
// infos[4][1] = Softwares
for (let i = 0; i < infos[4][1].length; i++) {
const res = await fetchData(`getproject_software/${i + 1}/${lang_id}`);
if (res.status == 0) {
project_software.push(res.data);
} else {
return {
status: res.status
}
}
}
// infos[4][0] = Programming Languages
for (let i = 0; i < infos[4][0].length; i++) {
const res = await fetchData(`getproject_programming/${i + 1}/${lang_id}`);
if (res.status == 0) {
project_programming.push(res.data);
} else {
return {
status: res.status
}
}
}
return { return {
status: 0, status: 0,
lang: lang, lang: lang,
info: infos[0], info: infos[0][0],
education: infos[1], education: infos[1],
experience: infos[2], experience: infos[2],
skills: {
project: infos[3], project: infos[3],
programming_languages: infos[4][0], languages: infos[4][0],
softwares: infos[4][1], skills: infos[4][1],
languages: infos[4][2],
},
tags: infos[5], tags: infos[5],
project_programming: project_programming, project_skills: infos[6],
project_software: project_software, categories: infos[7],
text: text, text: text,
}; };
} }

View file

@ -1,6 +1,5 @@
<script> <script>
import SvgIcon from "@jamescoyle/svelte-icon"; import SvgIcon from "@jamescoyle/svelte-icon";
import { processData } from "$lib/js/processdata.js";
import { showSidebar } from "$lib/js/topbar.js"; import { showSidebar } from "$lib/js/topbar.js";
import "$lib/css/base.css"; import "$lib/css/base.css";
import "$lib/css/cv.css"; import "$lib/css/cv.css";
@ -22,8 +21,6 @@
mdiWrench, mdiWrench,
mdiPencil, mdiPencil,
mdiAccount, mdiAccount,
mdiXml,
mdiApplication,
mdiEarth, mdiEarth,
mdiHeart, mdiHeart,
} from "@mdi/js"; } from "@mdi/js";
@ -31,14 +28,14 @@
export let data; export let data;
// Database // Database
const cv = data.status == 0 ? processData(data) : undefined; const cv = data.status == 0 ? data : undefined;
// Language specifications // Language specifications
const text = data.text; const text = data.text;
let flag; let flag;
let otherlang; let otherlang;
if (data.status == 0) { if (data.status == 0) {
for (const lang of cv.skills.languages) { for (const lang of cv.languages) {
if (lang.url_name == data.lang) flag = lang.icon_alpha; if (lang.url_name == data.lang) flag = lang.icon_alpha;
else otherlang = lang.url_name; else otherlang = lang.url_name;
} }
@ -156,54 +153,40 @@
/> />
<Section icon={mdiBriefcase} title={text.experience} /> <Section icon={mdiBriefcase} title={text.experience} />
<SlideShow <SlideShow
data={cv.experiences} data={cv.experience}
type={Experience} type={Experience}
timeline="true" timeline="true"
reverse="true" reverse="true"
/> />
<Section icon={mdiWrench} title={text.projects} /> <Section icon={mdiWrench} title={text.projects} />
<SlideShow <SlideShow
data={cv.skills.project} data={cv.project}
type={Projects} type={Projects}
show_max_index={true} show_max_index={true}
{text} {text}
/> />
<Section icon={mdiPencil} title={text.skills} /> <Section icon={mdiPencil} title={text.skills} />
<SubSection icon={mdiXml} title={text.programming_languages} /> {#each cv.skills as skill, index (index)}
<SubSection icon={cv.categories[index].icon} title={cv.categories[index].name} />
<div class="subsection"> <div class="subsection">
{#if sidebarLoaded} {#if sidebarLoaded}
{#each cv.skills.programming_languages as pilldata, index (index)} {#each skill as pilldata, index (index)}
<Pill <Pill
name={pilldata.lang} name={pilldata.skill}
type_icon={pilldata.type_icon} type_icon={pilldata.type_icon}
icon={pilldata.icon} icon={pilldata.icon}
color={pilldata.color} color={pilldata.color}
show_tooltip={true} show_tooltip={true}
tooltip_data={cv.project_programming[index]} tooltip_data={cv.project_skills[pilldata.id-1]}
{text} {text}
/> />
{/each} {/each}
{/if} {/if}
</div> </div>
<SubSection icon={mdiApplication} title={text.software} />
<div class="subsection">
{#if sidebarLoaded}
{#each cv.skills.softwares as pilldata, index (index)}
<Pill
name={pilldata.software}
type_icon={pilldata.type_icon}
icon={pilldata.icon}
color={pilldata.color}
show_tooltip={true}
tooltip_data={cv.project_software[index]}
{text}
/>
{/each} {/each}
{/if}
</div>
<SubSection icon={mdiEarth} title={text.languages} /> <SubSection icon={mdiEarth} title={text.languages} />
<div class="subsection flag-container end"> <div class="subsection flag-container end">
{#each cv.skills.languages as langdata} {#each cv.languages as langdata}
<FlagComponent <FlagComponent
lang={langdata.lang} lang={langdata.lang}
level={langdata.level} level={langdata.level}