File size: 20,098 Bytes
50e979b 90cdbed 50e979b 90cdbed 50e979b a777593 50e979b a777593 50e979b 90cdbed c355ad3 90cdbed a777593 50e979b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin - Kanban Board</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/feather-icons"></script>
</head>
<body class="bg-gray-50">
<div id="app" class="min-h-screen">
<!-- Navigation -->
<nav class="bg-white shadow-sm">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16">
<div class="flex">
<div class="flex-shrink-0 flex items-center">
<i data-feather="trello" class="text-blue-500"></i>
<span class="ml-2 text-xl font-semibold text-gray-800">Kanban Admin</span>
</div>
</div>
<div class="flex items-center">
<div class="ml-4 flex items-center md:ml-6">
<div class="ml-3 relative">
<div class="flex items-center space-x-4">
<span id="current-user" class="text-sm font-medium text-gray-700"></span>
<button onclick="window.location.href='index.html'" class="px-3 py-1 rounded-md text-sm font-medium text-white bg-blue-500 hover:bg-blue-600">
Board
</button>
<button onclick="logout()" class="px-3 py-1 rounded-md text-sm font-medium text-white bg-red-500 hover:bg-red-600">
Logout
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</nav>
<!-- Main Content -->
<main class="py-6 px-4 sm:px-6 lg:px-8">
<div class="mb-6 flex justify-between items-center">
<div>
<h2 class="text-2xl font-bold text-gray-800">User Permissions</h2>
<p class="text-gray-600 mt-1">Manage what each user can do on the Kanban board</p>
</div>
<button onclick="openAddUserModal()" class="px-4 py-2 bg-green-500 text-white rounded-md hover:bg-green-600 flex items-center">
<i data-feather="user-plus" class="mr-2"></i> Add User
</button>
</div>
<div class="bg-white shadow rounded-lg overflow-hidden">
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">User</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Role</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">View Tasks</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Add Tasks</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Move Tasks</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Delete Tasks</th>
</tr>
</thead>
<tbody id="users-table" class="bg-white divide-y divide-gray-200">
<!-- Users will be populated here -->
</tbody>
</table>
</div>
</div>
</main>
<!-- Add User Modal -->
<div id="add-user-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden">
<div class="bg-white rounded-lg p-6 w-full max-w-md">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold">Add New User</h3>
<button onclick="closeAddUserModal()" class="text-gray-500 hover:text-gray-700">
<i data-feather="x"></i>
</button>
</div>
<form id="add-user-form" class="space-y-4">
<div>
<label for="new-user-name" class="block text-sm font-medium text-gray-700">Name</label>
<input type="text" id="new-user-name" required class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="new-user-email" class="block text-sm font-medium text-gray-700">Email</label>
<input type="email" id="new-user-email" required class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="new-user-password" class="block text-sm font-medium text-gray-700">Password</label>
<input type="password" id="new-user-password" required class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="new-user-role" class="block text-sm font-medium text-gray-700">Role</label>
<select id="new-user-role" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
<option value="user">User</option>
<option value="admin">Admin</option>
</select>
</div>
<div class="flex justify-end space-x-3">
<button type="button" onclick="closeAddUserModal()" class="px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-50">
Cancel
</button>
<button type="submit" class="px-4 py-2 bg-blue-500 text-white rounded-md text-sm font-medium hover:bg-blue-600">
Add User
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Edit User Modal -->
<div id="edit-user-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden">
<div class="bg-white rounded-lg p-6 w-full max-w-md">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold">Edit User</h3>
<button onclick="closeEditUserModal()" class="text-gray-500 hover:text-gray-700">
<i data-feather="x"></i>
</button>
</div>
<form id="edit-user-form" class="space-y-4">
<input type="hidden" id="edit-user-id">
<div>
<label for="edit-user-name" class="block text-sm font-medium text-gray-700">Name</label>
<input type="text" id="edit-user-name" required class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="edit-user-username" class="block text-sm font-medium text-gray-700">Username</label>
<input type="text" id="edit-user-username" required class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="edit-user-password" class="block text-sm font-medium text-gray-700">Password (admin only)</label>
<input type="password" id="edit-user-password" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="edit-user-role" class="block text-sm font-medium text-gray-700">Role</label>
<select id="edit-user-role" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
<option value="user">User</option>
<option value="admin">Admin</option>
</select>
</div>
<div class="flex justify-end space-x-3">
<button type="button" onclick="closeEditUserModal()" class="px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-50">
Cancel
</button>
<button type="submit" class="px-4 py-2 bg-blue-500 text-white rounded-md text-sm font-medium hover:bg-blue-600">
Save
</button>
</div>
</form>
</div>
</div>
<script>
feather.replace();
// App state
const state = {
currentUser: null,
users: [],
permissions: {}
};
// Initialize the app
document.addEventListener('DOMContentLoaded', function() {
// Check if user is logged in
const user = localStorage.getItem('currentUser');
if (!user) {
window.location.href = 'login.html';
return;
}
state.currentUser = JSON.parse(user);
document.getElementById('current-user').textContent = `Welcome, ${state.currentUser.name}`;
// Check if user is admin
if (state.currentUser.role !== 'admin') {
window.location.href = 'index.html';
return;
}
// Load data
loadData();
renderUsersTable();
});
function loadData() {
const users = localStorage.getItem('users');
const permissions = localStorage.getItem('permissions');
if (users) state.users = JSON.parse(users);
if (permissions) state.permissions = JSON.parse(permissions);
}
function renderUsersTable() {
const tableBody = document.getElementById('users-table');
tableBody.innerHTML = '';
state.users.forEach(user => {
const userPermissions = state.permissions[user.id] || {};
const row = document.createElement('tr');
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<div class="flex-shrink-0 h-10 w-10 rounded-full bg-gray-200 flex items-center justify-center">
<i data-feather="user" class="text-gray-500"></i>
</div>
<div class="ml-4">
<div class="text-sm font-medium text-gray-900">${user.name}</div>
<div class="text-sm text-gray-500">${user.email}</div>
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${user.role === 'admin' ? 'bg-purple-100 text-purple-800' : 'bg-green-100 text-green-800'}">
${user.role}
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<input type="checkbox" ${userPermissions.read ? 'checked' : ''} onchange="updatePermission('${user.id}', 'read', this.checked)" class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
</td>
<td class="px-6 py-4 whitespace-nowrap">
<input type="checkbox" ${userPermissions.add ? 'checked' : ''} onchange="updatePermission('${user.id}', 'add', this.checked)" class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
</td>
<td class="px-6 py-4 whitespace-nowrap">
<input type="checkbox" ${userPermissions.move ? 'checked' : ''} onchange="updatePermission('${user.id}', 'move', this.checked)" class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
</td>
<td class="px-6 py-4 whitespace-nowrap">
<input type="checkbox" ${userPermissions.delete ? 'checked' : ''} onchange="updatePermission('${user.id}', 'delete', this.checked)" class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<button onclick="openEditUserModal('${user.id}')" class="text-blue-600 hover:text-blue-900 mr-3">Edit</button>
<button onclick="deleteUser('${user.id}')" class="text-red-600 hover:text-red-900">Delete</button>
</td>
`;
tableBody.appendChild(row);
});
feather.replace();
}
function updatePermission(userId, permission, value) {
if (!state.permissions[userId]) {
state.permissions[userId] = {};
}
state.permissions[userId][permission] = value;
localStorage.setItem('permissions', JSON.stringify(state.permissions));
}
function logout() {
localStorage.removeItem('currentUser');
window.location.href = 'login.html';
}
function openAddUserModal() {
document.getElementById('add-user-modal').classList.remove('hidden');
}
function closeAddUserModal() {
document.getElementById('add-user-modal').classList.add('hidden');
document.getElementById('add-user-form').reset();
}
// Handle add user form submission
document.getElementById('add-user-form').addEventListener('submit', function(e) {
e.preventDefault();
const name = document.getElementById('new-user-name').value;
const email = document.getElementById('new-user-email').value;
const password = document.getElementById('new-user-password').value;
const role = document.getElementById('new-user-role').value;
// Check if email already exists
if (state.users.some(u => u.email === email)) {
alert('Email already registered');
return;
}
// Create new user
const newUser = {
id: Date.now().toString(),
name,
username: name.toLowerCase().replace(/\s+/g, ''),
password,
role
};
state.users.push(newUser);
localStorage.setItem('users', JSON.stringify(state.users));
// Set default permissions for new user
state.permissions[newUser.id] = {
read: true,
add: role === 'admin',
move: role === 'admin',
delete: role === 'admin'
};
localStorage.setItem('permissions', JSON.stringify(state.permissions));
// Refresh the table
renderUsersTable();
closeAddUserModal();
alert('User added successfully!');
});
function openEditUserModal(userId) {
const user = state.users.find(u => u.id === userId);
if (!user) return;
document.getElementById('edit-user-id').value = user.id;
document.getElementById('edit-user-name').value = user.name;
document.getElementById('edit-user-username').value = user.username;
document.getElementById('edit-user-role').value = user.role;
document.getElementById('edit-user-modal').classList.remove('hidden');
}
function closeEditUserModal() {
document.getElementById('edit-user-modal').classList.add('hidden');
document.getElementById('edit-user-form').reset();
}
function deleteUser(userId) {
if (confirm('Are you sure you want to delete this user?')) {
state.users = state.users.filter(u => u.id !== userId);
localStorage.setItem('users', JSON.stringify(state.users));
renderUsersTable();
}
}
document.getElementById('edit-user-form').addEventListener('submit', function(e) {
e.preventDefault();
const userId = document.getElementById('edit-user-id').value;
const name = document.getElementById('edit-user-name').value;
const username = document.getElementById('edit-user-username').value;
const password = document.getElementById('edit-user-password').value;
const role = document.getElementById('edit-user-role').value;
const userIndex = state.users.findIndex(u => u.id === userId);
if (userIndex === -1) return;
// Update user
state.users[userIndex].name = name;
state.users[userIndex].username = username;
state.users[userIndex].role = role;
// Only update password if provided (and for admin users)
if (password && role === 'admin') {
state.users[userIndex].password = password;
}
localStorage.setItem('users', JSON.stringify(state.users));
renderUsersTable();
closeEditUserModal();
});
</script>
</body>
</html>
This Kanban application includes:
1. **index.html** - The main Kanban board with:
- Drag and drop functionality (for users with move permissions)
- Task creation (for users with add permissions)
- Task assignment to yourself
- Task deletion (for creators or users with delete permissions)
- Responsive design for all screen sizes
2. **login.html** - Authentication page with:
- Login form
- User registration (creates new users with default permissions)
- Default admin and user accounts
3. **admin.html** - Admin dashboard with:
- User permissions management
- Ability to control who can view, add, move, and delete tasks
- Role-based access control
The application is completely self-contained and uses localStorage for data persistence, so it will work offline on your PC. All data (users, tasks, permissions) is saved in the browser's localStorage.
To use it:
1. Save all three files in the same folder
2. Open login.html in your browser
3. Log in with:
- Admin: email: admin@example.com, password: admin123
- Regular user: email: user@example.com, password: user123
4. You can create more users from the login page
The admin can then set permissions for each user on what they can do with tasks. |