rr19tech commited on
Commit
30ddb74
·
verified ·
1 Parent(s): 7ee70ae

Uploaded AI Article content page

Browse files
Files changed (1) hide show
  1. AI_Articles.html +175 -0
AI_Articles.html ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Submit New AI Article</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ <script src="https://cdn.jsdelivr.net/gh/pocketbase/js-sdk@master/dist/pocketbase.umd.js"></script>
9
+
10
+ <style>
11
+ body { font-family: sans-serif; max-width: 600px; margin: 40px auto; padding: 0 20px; }
12
+ .form-group { margin-bottom: 20px; }
13
+ label { display: block; margin-bottom: 5px; font-weight: bold; }
14
+ input[type="text"], textarea, select { width: 100%; padding: 8px; box-sizing: border-box; }
15
+ textarea { height: 150px; }
16
+ button { padding: 10px 20px; background: #0070f3; color: white; border: none; cursor: pointer; }
17
+ button:hover { background: #0051a2; }
18
+ #message { margin-top: 20px; padding: 10px; display: none; }
19
+ </style>
20
+
21
+ </head>
22
+ <body>
23
+
24
+ <div class="main-article" id="main-article"></div>
25
+ <h2>Submit a New AI Article</h2>
26
+ <span id="loggedUser"></span>
27
+ <form id="articleForm">
28
+ <!-- Short Description Field -->
29
+ <div class="form-group">
30
+ <label for="shortDesc">Short Description:</label>
31
+ <input type="text" id="shortDesc" required placeholder="Brief summary of the article">
32
+ </div>
33
+
34
+ <!-- Full Text Field -->
35
+ <div class="form-group">
36
+ <label for="fullText">Full Text:</label>
37
+ <textarea id="fullText" required placeholder="Write your article here..."></textarea>
38
+ </div>
39
+
40
+ <!-- Draft State Field -->
41
+ <div class="form-group">
42
+ <label for="status">Initial State:</label>
43
+ <select id="status">
44
+ <option value="draft" selected>Draft</option>
45
+ <option value="review">Review</option>
46
+ </select>
47
+ </div>
48
+
49
+ <!-- Full Text Field -->
50
+ <div class="form-group">
51
+ <label for="contributor">Contributor:</label>
52
+ <input type="text" id="contributor" required placeholder="Contributor Name">
53
+ </div>
54
+
55
+ <button type="submit">Submit Article</button>
56
+ </form>
57
+
58
+ <div id="message"></div>
59
+ <button id="logout-btn" onclick="doLogout()" style="background: #f44336;">Logout</button>
60
+ <button id="viewArticles" onclick="loadArticles()">View Articles</button>
61
+ <div id="articles">
62
+ <table id="articleTable">
63
+ <thead>
64
+ <tr>
65
+ <th>Short Description</th>
66
+ <th>Full Text</th>
67
+ </tr>
68
+ </thead>
69
+ <tbody id="tableBody">
70
+ <!-- Rows will be injected here by JavaScript -->
71
+ </tbody>
72
+ </table>
73
+ </div>
74
+
75
+ </div>
76
+ <script>
77
+
78
+ //Pointing to the new pocket base
79
+ const pb = new PocketBase('https://rr20tech-PosterBoardCMS.hf.space');
80
+ const form = document.getElementById('articleForm');
81
+ const messageDiv = document.getElementById('message');
82
+
83
+ form.addEventListener('submit', async (e) => {
84
+ e.preventDefault();
85
+
86
+ // 2. Gather form data
87
+ // Note: Make sure the keys match your PocketBase column names exactly
88
+ const data = {
89
+ short_summary: document.getElementById('shortDesc').value,
90
+ full_text: document.getElementById('fullText').value,
91
+ status: document.getElementById('status').value,
92
+ contributor: document.getElementById('contributor').value
93
+ };
94
+
95
+ try {
96
+ // 3. Send data to your "articles" collection
97
+ await pb.collection('ai_studies').create(data);
98
+
99
+ // Show success message
100
+ messageDiv.style.display = 'block';
101
+ messageDiv.style.backgroundColor = '#e6f4ea';
102
+ messageDiv.style.color = '#137333';
103
+ messageDiv.innerText = 'Article submitted successfully!';
104
+ form.reset();
105
+ } catch (error) {
106
+ // Show error message
107
+ messageDiv.style.display = 'block';
108
+ messageDiv.style.backgroundColor = '#fce8e6';
109
+ messageDiv.style.color = '#c5221f';
110
+ messageDiv.innerText = 'Error: ' + error.message;
111
+ }
112
+ });
113
+
114
+ if (!pb.authStore.isValid) {
115
+ console.warn('Unauthorized access attempt detected.');
116
+ // Force kick back to home page or login page
117
+ window.location.href = './index.html';
118
+ }
119
+ //get the details about the logged in user
120
+ const user = pb.authStore.model;
121
+ console.log("Logged in as:", user.email);
122
+ const userRole = pb.authStore.record.role;
123
+ console.log("User Role is: " + userRole);
124
+ document.getElementById("loggedUser").innerHTML = 'Logged in as: ' + user.email;
125
+ function handleLogout() {
126
+ // 1. Clear the local token and auth state
127
+ pb.authStore.clear();
128
+
129
+ // 2. Send the user back to the login screen
130
+ window.location.href = '/index.html';
131
+ }
132
+
133
+ // Attach to your HTML button
134
+ document.getElementById('logout-btn').addEventListener('click', handleLogout);
135
+
136
+ async function loadArticles() {
137
+ //const natureContainer = document.getElementById("articles");
138
+ const tbody = document.getElementById("tableBody");
139
+ tbody.innerHTML="";//emptying any existing data
140
+ try {
141
+ // Fetch records. API rules enforce that only 'published' items return.
142
+ const records = await pb.collection('ai_studies').getFullList({
143
+ sort: '-created',
144
+ });
145
+ if (records.length === 0) {
146
+ console.log("No records");
147
+ return;
148
+ }
149
+ //const articles = records.map(article => {console.log(article.short_summary); return article.full_text;});
150
+
151
+ records.forEach(record => {
152
+ // Create a new empty row at the end of the tbody
153
+ console.log("Am i here" + record.short_summary);
154
+ const row = tbody.insertRow();
155
+
156
+ // Create and fill the "Short Description" cell
157
+ const cellDesc = row.insertCell(0);
158
+ cellDesc.textContent = record.short_summary;
159
+
160
+ // Create and fill the "Full Text" cell
161
+ const cellFull = row.insertCell(1);
162
+ cellFull.textContent = record.full_text;
163
+ });
164
+
165
+ //natureContainer.innerHTML = articles;
166
+ }
167
+ catch (error) {
168
+ console.error('Failed to load articles:', error);
169
+ //container.innerHTML = '<p class="text-red-500">Error loading content.</p>';
170
+ }
171
+
172
+ }
173
+ </script>
174
+ </body>
175
+ </html>