diff --git a/index.md b/index.md index 3c8c199f..e68a8ae6 100644 --- a/index.md +++ b/index.md @@ -1,6 +1,6 @@ --- layout: post -title: Create and Compete +title: Flocker Social Media Site search_exclude: true description: Login and explore our social media hub for everything DNHS hide: true diff --git a/navigation/authentication/history.md b/navigation/authentication/history.md index f7c2d5ad..22ae6af1 100644 --- a/navigation/authentication/history.md +++ b/navigation/authentication/history.md @@ -114,4 +114,4 @@ search_exclude: true // Call the fetchData function to initiate the requests fetchData(); - \ No newline at end of file + diff --git a/navigation/authentication/profile.md b/navigation/authentication/profile.md index e34a9f8f..0108e7ad 100644 --- a/navigation/authentication/profile.md +++ b/navigation/authentication/profile.md @@ -23,26 +23,6 @@ show_reading_time: false

-
- -
- - -
-
- - - - - - - - - - -
ThemeName
@@ -60,166 +40,11 @@ import {pythonURI, fetchOptions } from '{{site.baseurl}}/assets/js/api/config.js // Import functions from config.js import { putUpdate, postUpdate, deleteData, logoutUser } from "{{site.baseurl}}/assets/js/api/profile.js"; -// Global variable to hold predefined sections -let predefinedSections = []; - -// Function to fetch sections from kasm2_backend -async function fetchPredefinedSections() { - const URL = pythonURI + "/api/section"; - - try { - const response = await fetch(URL, fetchOptions); - if (!response.ok) { - throw new Error(`Failed to fetch predefined sections: ${response.status}`); - } - - - return await response.json(); - } catch (error) { - console.error('Error fetching predefined sections:', error.message); - return []; // Return empty array on error - } -} - - -// Function to populate section dropdown menu -function populateSectionDropdown(predefinedSections) { - const sectionDropdown = document.getElementById('sectionDropdown'); - sectionDropdown.innerHTML = ''; // Clear existing options - - - predefinedSections.forEach(section => { - const option = document.createElement('option'); - option.value = section.theme; - option.textContent = `${section.theme} - ${section.name}`; - sectionDropdown.appendChild(option); - }); - - - // Display sections in the table - displayProfileSections(); -} - - -// Global variable to hold user sections -let userSections = []; - - -// Function to add a section -window.addSection = async function () { - const dropdown = document.getElementById('sectionDropdown'); - const selectedOption = dropdown.options[dropdown.selectedIndex]; - const theme = selectedOption.value; - const name = selectedOption.textContent.split(' ').slice(1).join(' '); - - - if (!theme || !name) { - document.getElementById('profile-message').textContent = 'Please select a section from the dropdown.'; - return; - } - - - // Clear error message - document.getElementById('profile-message').textContent = ''; - - - // Add section to userSections array if not already added - const sectionExists = userSections.some(section => section.theme === theme && section.name === name); - if (!sectionExists) { - userSections.push({ theme, name }); - - - // Display added section in the table - displayProfileSections(); - - - // Save sections immediately - await saveSections(); - } -} - - -// Function to display added sections in the table -function displayProfileSections() { - const tableBody = document.getElementById('profileResult'); - tableBody.innerHTML = ''; // Clear existing rows - - - // Create a new row and cell for each section - userSections.forEach(section => { - const tr = document.createElement('tr'); - const themeCell = document.createElement('td'); - const nameCell = document.createElement('td'); - - // Fill in the corresponding cells with data - themeCell.textContent = section.theme; - nameCell.textContent = section.name; - - tr.appendChild(themeCell); - tr.appendChild(nameCell); - tr.appendChild(yearCell); - - // Add the row to table - tableBody.appendChild(tr); - }); - } - - -// Function to save sections in the specified format -async function saveSections() { - const sectionThemes = userSections.map(section => section.theme); - - const sectionsData = { - sections: sectionThemes - }; - - const URL = pythonURI + "/api/user/section"; - - const options = { - URL, - body: sectionsData, - message: 'profile-message', - callback: async () => { - console.log('Sections saved successfully!'); - await fetchDataAndPopulateTable(); - } - }; - - - try { - await postUpdate(options); - } catch (error) { - console.error('Error saving sections:', error.message); - document.getElementById('profile-message').textContent = 'Error saving sections: ' + error.message; - } -} - - -// Function to fetch data from the backend and populate the table -async function fetchDataAndPopulateTable() { - const URL = pythonURI + "/api/user/section"; // Endpoint to fetch sections data - - try { - const response = await fetch(URL, fetchOptions); - if (!response.ok) { - throw new Error(`Failed to fetch sections: ${response.status}`); - } - - const sectionsData = await response.json(); - updateTableWithData(sectionsData); // Call function to update table with fetched data - } catch (error) { - console.error('Error fetching sections:', error.message); - // Handle error display or fallback mechanism - } -} - - // Function to update table with fetched data function updateTableWithData(data) { const tableBody = document.getElementById('profileResult'); tableBody.innerHTML = ''; - data.sections.forEach((section, index) => { const tr = document.createElement('tr'); const themeCell = document.createElement('td'); @@ -233,25 +58,18 @@ function updateTableWithData(data) { trashIcon.style.marginLeft = '10px'; themeCell.appendChild(trashIcon); - trashIcon.addEventListener('click', async function (event) { event.preventDefault(); const URL = pythonURI + "/api/user/section"; // Remove the row from the table tr.remove(); - const options = { URL, body: { sections: [section.theme] }, message: 'profile-message', - callback: async () => { - console.log('Section deleted successfully!'); - await fetchDataAndPopulateTable(); - } }; - try { await deleteData(options); } catch (error) { @@ -263,7 +81,6 @@ function updateTableWithData(data) { yearCell.classList.add('editable'); // Make year cell editable yearCell.innerHTML = `${section.year} `; - // Make the year cell editable yearCell.addEventListener('click', function () { const input = document.createElement('input'); @@ -273,10 +90,8 @@ function updateTableWithData(data) { yearCell.innerHTML = ''; yearCell.appendChild(input); - input.focus(); - input.addEventListener('blur', async function () { const newYear = input.value; const URL = pythonURI + "/api/user/section"; @@ -284,13 +99,8 @@ function updateTableWithData(data) { URL, body: { section: { theme: section.theme, year: newYear } }, message: 'profile-message', - callback: async () => { - console.log('Year updated successfully!'); - await fetchDataAndPopulateTable(); - } }; - try { await putUpdate(options); } catch (error) { @@ -298,11 +108,9 @@ function updateTableWithData(data) { document.getElementById('profile-message').textContent = 'Error updating year: ' + error.message; } - yearCell.textContent = newYear; }); - input.addEventListener('keydown', function (event) { if (event.key === 'Enter') { input.blur(); @@ -317,19 +125,16 @@ function updateTableWithData(data) { } - // Function to fetch user profile data async function fetchUserProfile() { const URL = pythonURI + "/api/id/pfp"; // Endpoint to fetch user profile data - try { const response = await fetch(URL, fetchOptions); if (!response.ok) { throw new Error(`Failed to fetch user profile: ${response.status}`); } - const profileData = await response.json(); displayUserProfile(profileData); } catch (error) { @@ -338,7 +143,6 @@ async function fetchUserProfile() { } } - // Function to display user profile data function displayUserProfile(profileData) { const profileImageBox = document.getElementById('profileImageBox'); @@ -352,16 +156,13 @@ function displayUserProfile(profileData) { profileImageBox.innerHTML = '

No profile picture available.

'; } - // Display other profile information as needed // Example: Update HTML elements with profileData.username, profileData.email } - // Function to save profile picture window.saveProfilePicture = async function () { - const fileInput = document.getElementById('profilePicture'); const file = fileInput.files[0]; if (file) { @@ -373,24 +174,19 @@ window.saveProfilePicture = async function () { reader.readAsDataURL(file); } - if (!file) return; - try { const base64String = await convertToBase64(file); await sendProfilePicture(base64String); console.log('Profile picture uploaded successfully!'); - } catch (error) { console.error('Error uploading profile picture:', error.message); // Handle error display or fallback mechanism } } - - // Function to convert file to base64 async function convertToBase64(file) { return new Promise((resolve, reject) => { @@ -401,12 +197,10 @@ async function convertToBase64(file) { }); } - // Function to send profile picture to server async function sendProfilePicture(base64String) { const URL = pythonURI + "/api/id/pfp"; // Adjust endpoint as needed - // Create options object for PUT request const options = { URL, @@ -418,7 +212,6 @@ async function sendProfilePicture(base64String) { } }; - try { await putUpdate(options); } catch (error) { @@ -445,7 +238,6 @@ window.changeUid = async function(uid) { if (uid) { const URL = pythonURI + "/api/user"; // Adjusted endpoint - const options = { URL, body: { uid }, @@ -458,7 +250,6 @@ window.changeUid = async function(uid) { } }; - try { await putUpdate(options); } catch (error) { @@ -468,12 +259,10 @@ window.changeUid = async function(uid) { } } - window.changePassword = async function(password) { if (password) { const URL = pythonURI + "/api/user"; // Adjusted endpoint - const options = { URL, body: { password }, @@ -482,11 +271,9 @@ window.changePassword = async function(password) { console.log('Password updated successfully!'); window.location.href = '/portfolio_2025/login' - } }; - try { alert("You updated your password, so you will automatically be logged out. Be sure to remember your password!"); await putUpdate(options); @@ -498,13 +285,6 @@ window.changePassword = async function(password) { } } - - - - - - - // Function to change Name window.changeName = async function(name) { if (name) { @@ -527,71 +307,36 @@ window.changeName = async function(name) { } } - // Event listener to trigger updateUid function when UID field is changed document.getElementById('newUid').addEventListener('change', function() { const uid = this.value; window.changeUid(uid); - }); - // Event listener to trigger updateName function when Name field is changed document.getElementById('newName').addEventListener('change', function() { const name = this.value; window.changeName(name); - }); - document.getElementById('newPassword').addEventListener('change', function() { const password = this.value; window.changePassword(password); - }); - - - - - - - - - -window.fetchKasmServerNeeded = async function() { - const URL = pythonURI + "/api/user"; // Adjusted endpoint - try { - const response = await fetch(URL, fetchOptions); - if (!response.ok) { - throw new Error(`Failed to fetch kasm_server_needed: ${response.status}`); - } - const userData = await response.json(); - const kasmServerNeeded = userData.kasm_server_needed - // Update checkbox state based on fetched value - const checkbox = document.getElementById('kasmServerNeeded'); - checkbox.checked = kasmServerNeeded; - } catch (error) { - console.error('Error fetching kasm_server_needed:', error.message); - // Handle error display or fallback mechanism - } -}; - // Function to fetch Name from backend window.fetchName = async function() { const URL = pythonURI + "/api/user"; // Adjusted endpoint - try { const response = await fetch(URL, fetchOptions); if (!response.ok) { throw new Error(`Failed to fetch Name: ${response.status}`); } - const data = await response.json(); return data.name; } catch (error) { @@ -600,18 +345,15 @@ window.fetchName = async function() { } }; - // Function to set placeholders for UID and Name window.setPlaceholders = async function() { const uidInput = document.getElementById('newUid'); const nameInput = document.getElementById('newName'); - try { const uid = await window.fetchUid(); const name = await window.fetchName(); - if (uid !== null) { uidInput.placeholder = uid; } @@ -623,16 +365,10 @@ window.setPlaceholders = async function() { } }; - -// Call fetchPredefinedSections and initializeProfileSetup when DOM content is loaded +// Call and initializeProfileSetup when DOM content is loaded document.addEventListener('DOMContentLoaded', async function () { try { - predefinedSections = await fetchPredefinedSections(); - console.log('Predefined Sections:', predefinedSections); - populateSectionDropdown(predefinedSections); // Populate dropdown with fetched sections await fetchUserProfile(); // Fetch user profile data - await fetchDataAndPopulateTable(); // Fetch and populate table with user sections - await fetchKasmServerNeeded(); await setPlaceholders(); } catch (error) { console.error('Initialization error:', error.message);