RetroPosterBoard / AI_Articles.html
rr19tech's picture
Uploaded AI Article content page
30ddb74 verified
Raw History Blame Contribute Delete
7.13 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Submit New AI Article</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdn.jsdelivr.net/gh/pocketbase/js-sdk@master/dist/pocketbase.umd.js"></script>
<style>
body { font-family: sans-serif; max-width: 600px; margin: 40px auto; padding: 0 20px; }
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 5px; font-weight: bold; }
input[type="text"], textarea, select { width: 100%; padding: 8px; box-sizing: border-box; }
textarea { height: 150px; }
button { padding: 10px 20px; background: #0070f3; color: white; border: none; cursor: pointer; }
button:hover { background: #0051a2; }
#message { margin-top: 20px; padding: 10px; display: none; }
</style>
</head>
<body>
<div class="main-article" id="main-article"></div>
<h2>Submit a New AI Article</h2>
<span id="loggedUser"></span>
<form id="articleForm">
<!-- Short Description Field -->
<div class="form-group">
<label for="shortDesc">Short Description:</label>
<input type="text" id="shortDesc" required placeholder="Brief summary of the article">
</div>
<!-- Full Text Field -->
<div class="form-group">
<label for="fullText">Full Text:</label>
<textarea id="fullText" required placeholder="Write your article here..."></textarea>
</div>
<!-- Draft State Field -->
<div class="form-group">
<label for="status">Initial State:</label>
<select id="status">
<option value="draft" selected>Draft</option>
<option value="review">Review</option>
</select>
</div>
<!-- Full Text Field -->
<div class="form-group">
<label for="contributor">Contributor:</label>
<input type="text" id="contributor" required placeholder="Contributor Name">
</div>
<button type="submit">Submit Article</button>
</form>
<div id="message"></div>
<button id="logout-btn" onclick="doLogout()" style="background: #f44336;">Logout</button>
<button id="viewArticles" onclick="loadArticles()">View Articles</button>
<div id="articles">
<table id="articleTable">
<thead>
<tr>
<th>Short Description</th>
<th>Full Text</th>
</tr>
</thead>
<tbody id="tableBody">
<!-- Rows will be injected here by JavaScript -->
</tbody>
</table>
</div>
</div>
<script>
//Pointing to the new pocket base
const pb = new PocketBase('https://rr20tech-PosterBoardCMS.hf.space');
const form = document.getElementById('articleForm');
const messageDiv = document.getElementById('message');
form.addEventListener('submit', async (e) => {
e.preventDefault();
// 2. Gather form data
// Note: Make sure the keys match your PocketBase column names exactly
const data = {
short_summary: document.getElementById('shortDesc').value,
full_text: document.getElementById('fullText').value,
status: document.getElementById('status').value,
contributor: document.getElementById('contributor').value
};
try {
// 3. Send data to your "articles" collection
await pb.collection('ai_studies').create(data);
// Show success message
messageDiv.style.display = 'block';
messageDiv.style.backgroundColor = '#e6f4ea';
messageDiv.style.color = '#137333';
messageDiv.innerText = 'Article submitted successfully!';
form.reset();
} catch (error) {
// Show error message
messageDiv.style.display = 'block';
messageDiv.style.backgroundColor = '#fce8e6';
messageDiv.style.color = '#c5221f';
messageDiv.innerText = 'Error: ' + error.message;
}
});
if (!pb.authStore.isValid) {
console.warn('Unauthorized access attempt detected.');
// Force kick back to home page or login page
window.location.href = './index.html';
}
//get the details about the logged in user
const user = pb.authStore.model;
console.log("Logged in as:", user.email);
const userRole = pb.authStore.record.role;
console.log("User Role is: " + userRole);
document.getElementById("loggedUser").innerHTML = 'Logged in as: ' + user.email;
function handleLogout() {
// 1. Clear the local token and auth state
pb.authStore.clear();
// 2. Send the user back to the login screen
window.location.href = '/index.html';
}
// Attach to your HTML button
document.getElementById('logout-btn').addEventListener('click', handleLogout);
async function loadArticles() {
//const natureContainer = document.getElementById("articles");
const tbody = document.getElementById("tableBody");
tbody.innerHTML="";//emptying any existing data
try {
// Fetch records. API rules enforce that only 'published' items return.
const records = await pb.collection('ai_studies').getFullList({
sort: '-created',
});
if (records.length === 0) {
console.log("No records");
return;
}
//const articles = records.map(article => {console.log(article.short_summary); return article.full_text;});
records.forEach(record => {
// Create a new empty row at the end of the tbody
console.log("Am i here" + record.short_summary);
const row = tbody.insertRow();
// Create and fill the "Short Description" cell
const cellDesc = row.insertCell(0);
cellDesc.textContent = record.short_summary;
// Create and fill the "Full Text" cell
const cellFull = row.insertCell(1);
cellFull.textContent = record.full_text;
});
//natureContainer.innerHTML = articles;
}
catch (error) {
console.error('Failed to load articles:', error);
//container.innerHTML = '<p class="text-red-500">Error loading content.</p>';
}
}
</script>
</body>
</html>