Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | <script setup lang="ts"> import { ref, computed, onMounted, watch } from 'vue' import { useI18n } from 'vue-i18n' import { useRouter } from 'vue-router' import { useDeploymentStore } from '@/stores/deployment.store' import DeploymentProgressBar from '@/components/DeploymentProgressBar.vue' import { BarChart3, Search, Check, Users, BookOpen, UserPlus } from 'lucide-vue-next' import { courseApi } from '@/api/course.api' import { userApi } from '@/api/user.api' import { useToast } from '@/composables/useToast' import { useOpenStackCredentialsStore } from '@/stores/openstack-credentials.store' import CredentialMissingBanner from '@/components/CredentialMissingBanner.vue' const { t } = useI18n() const router = useRouter() const store = useDeploymentStore() const toast = useToast() const credStore = useOpenStackCredentialsStore() const courses = ref<any[]>([]) // Zwei separate Listen: Cache (initial) + aktuelle Ansicht (Suche/Filter) const allStudents = ref<any[]>([]) const students = ref<any[]>([]) // Cache-Map für alle jemals gesehenen Studenten (bleibt stabil, keyed by keycloak_id) const studentCache = ref(new Map<string, any>()) const studentSearchQuery = ref('') const loadingCourses = ref(false) const loadingStudents = ref(false) const coursesError = ref<string | null>(null) const studentsError = ref<string | null>(null) // Tab für die Auswahl: 'courses' oder 'individuals' const activeTab = ref<'courses' | 'individuals'>('courses') // Helper: Studenten in Cache speichern (keyed by keycloak_id) // Überschreibe nur, wenn das neue Objekt mehr Infos hat (z.B. firstName) function cacheStudents(list: any[]) { for (const s of list || []) { if (!s?.keycloak_id || typeof s.keycloak_id !== 'string' || !s.keycloak_id.trim()) continue const existing = studentCache.value.get(s.keycloak_id) if (!existing || (s.firstName && !existing.firstName) || (s.lastName && !existing.lastName)) { studentCache.value.set(s.keycloak_id, s) store.studentCache.set(s.keycloak_id, s) } } } // Gefilterte Liste für individuelle Suche: zeigt Suchresultate oder initiale Liste // Gibt IMMER das Objekt aus dem Cache zurück, falls vorhanden const filteredStudents = computed(() => { // Basis: wenn leer, zeige leere Liste (keine Studenten ohne Suche) if (!studentSearchQuery.value.trim()) { return [] } // Backend hat bereits nach username/email/firstName/lastName gefiltert // (Keycloak Admin API ``/users?search=…``) — eine zusätzliche Client-seitige // Filterung mit ``s.username || s.firstName || …`` wäre falsch, weil der // ``||``-Fallback nur das erste truthy Feld in den Vergleich nimmt: ein // User mit ``username="okann"`` und ``firstName="Jeffrey"`` würde bei der // Anfrage „Jeff" rausfallen, obwohl das Backend ihn korrekt zurückgegeben // hat. Daher die Backend-Antwort einfach durchreichen und nur Cache-Objekt // verwenden, falls vorhanden (verhindert Duplikate). return students.value.map((s: any) => { const cached = s?.keycloak_id ? studentCache.value.get(s.keycloak_id) : undefined return cached || s }).filter(Boolean) }) // Ausgewählte Studenten: immer aus Cache auflösen (bleibt stabil, keyed by keycloak_id) const selectedStudents = computed(() => { return store.draft.studentIds .map((kid: string) => studentCache.value.get(kid)) .filter(Boolean) }) // Cache für Studenten pro Kurs (lazy loading) const courseStudentsCache = ref(new Map<string, any[]>()) // Hilfsfunktion: Gibt alle Studenten-IDs eines Kurses zurück (lazy loading) async function getStudentIdsForCourse(courseId: string): Promise<string[]> { // Prüfe Cache if (courseStudentsCache.value.has(courseId)) { const students = courseStudentsCache.value.get(courseId)! return students.map((s: any) => s.keycloak_id) } // Lade Studenten für diesen Kurs try { const res = await courseApi.getById(courseId) const students = res.data.users || [] courseStudentsCache.value.set(courseId, students) // Cache auch in studentCache cacheStudents(students) return students.map((s: any) => s.keycloak_id) } catch (err) { console.error(`Failed to load students for course ${courseId}:`, err) return [] } } // Loading states für Kurse const loadingCourseStudents = ref(new Set<string>()) // Hilfsfunktion: Gibt Anzahl Studenten pro Kurs zurück (lazy loading) function getStudentCountForCourse(courseId: string) { if (courseStudentsCache.value.has(courseId)) { return courseStudentsCache.value.get(courseId)!.length } // Wenn nicht geladen, lade lazy if (!loadingCourseStudents.value.has(courseId)) { loadingCourseStudents.value.add(courseId) getStudentIdsForCourse(courseId).then(() => { loadingCourseStudents.value.delete(courseId) }).catch(() => { loadingCourseStudents.value.delete(courseId) }) } return 0 // Placeholder während loading } // Kurs-Checkbox: checked, wenn alle Studenten des Kurses ausgewählt sind function isCourseSelected(courseId: string) { if (!courseStudentsCache.value.has(courseId)) { return false // Noch nicht geladen } const studentIds = courseStudentsCache.value.get(courseId)!.map((s: any) => s.keycloak_id) return studentIds.length > 0 && studentIds.every((id) => store.draft.studentIds.includes(id)) } // Kurs-Checkbox toggeln: alle Studenten des Kurses auswählen/abwählen const toggleCourse = async (courseId: string) => { const studentIds = await getStudentIdsForCourse(courseId) if (studentIds.length === 0) { toast.warning(t('CourseDetailView.addModal.noUsersFound')) return } const allSelected = studentIds.length > 0 && studentIds.every((id) => store.draft.studentIds.includes(id)) if (allSelected) { // Abwählen: entferne alle Studenten dieses Kurses aus Auswahl store.draft.studentIds = store.draft.studentIds.filter((id: string) => !studentIds.includes(id)) } else { // Auswählen: füge alle Studenten dieses Kurses zur Auswahl hinzu (ohne Duplikate) const set = new Set([...store.draft.studentIds, ...studentIds]) store.draft.studentIds = Array.from(set) } // Kursauswahl-Liste synchronisieren syncCourseSelection() } // Student-Checkbox toggeln (für individuelle Auswahl) const toggleStudent = (studentKeycloakId: string) => { if (!studentKeycloakId || typeof studentKeycloakId !== 'string' || !studentKeycloakId.trim()) return const index = store.draft.studentIds.indexOf(studentKeycloakId) if (index > -1) { store.draft.studentIds.splice(index, 1) } else { store.draft.studentIds.push(studentKeycloakId) } // Nach jedem Toggle: Kursauswahl synchronisieren syncCourseSelection() } // Synchronisiert store.draft.courseIds mit aktuellem Studenten-Selection-State async function syncCourseSelection() { // Für jeden Kurs: Wenn alle Studenten ausgewählt, Kurs in courseIds, sonst raus const newCourseIds: string[] = [] for (const course of courses.value) { if (courseStudentsCache.value.has(course.courseId)) { const studentIds = courseStudentsCache.value.get(course.courseId)!.map((s: any) => s.keycloak_id) if (studentIds.length > 0 && studentIds.every((id) => store.draft.studentIds.includes(id))) { newCourseIds.push(course.courseId) } } } store.draft.courseIds = newCourseIds } const handleNext = () => { // Block if credentials missing — banner already explains why if (!credStore.hasCredential) { toast.warning(t('AppsDetailView.missingCredsTitle')) return } // Prüfe ob Name ausgefüllt ist if (!store.draft.name || store.draft.name.trim() === '') { toast.warning(t('deployment.errors.missingName')) return } // Prüfe ob mindestens ein Student ausgewählt ist if (store.draft.studentIds.length === 0) { toast.warning(t('deployment.errors.missingStudents')) return } router.push({ name: 'deployment.teams' }) } const handleBack = () => { const appId = store.draft.appId if (appId) { router.push({ name: 'apps.detail', params: { id: appId } }) } else { router.push('/apps') } } // Kurse laden async function loadCourses() { loadingCourses.value = true coursesError.value = null try { const res = await courseApi.list(0, 200) courses.value = res.data || [] } catch (err) { coursesError.value = t('CoursesView.toasts.loadError') toast.error(coursesError.value) } finally { loadingCourses.value = false } } // Initiale Studentenliste laden (wird gecacht) async function loadAllStudents() { loadingStudents.value = true studentsError.value = null try { const res = await userApi.list({ role: 'student', limit: 1000 }) allStudents.value = res.data || [] students.value = allStudents.value cacheStudents(allStudents.value) } catch (err) { studentsError.value = t('CourseDetailView.toasts.loadUsersError') toast.error(studentsError.value) } finally { loadingStudents.value = false } } // Suche mit Debouncing let searchTimer: number | undefined watch(studentSearchQuery, (val) => { if (searchTimer) window.clearTimeout(searchTimer) searchTimer = window.setTimeout(async () => { const q = val?.trim() || '' // Leere Suche: zeige initiale Liste (kein erneuter API-Call) if (!q) { students.value = allStudents.value toast.clear() return } // Zu kurze Suche: behalte aktuelle Liste (kein Flackern) if (q.length < 2) { toast.clear() return } // Suche durchführen try { loadingStudents.value = true const res = await userApi.search(q, 50) toast.clear() students.value = res.data || [] cacheStudents(students.value) // Neue Studenten cachen (keyed by keycloak_id) } catch (err) { console.error('User search error:', err) const e: any = err const msg = e?.response?.data?.detail || e?.message || t('CourseDetailView.toasts.loadUsersError') toast.error(msg) } finally { loadingStudents.value = false } }, 300) }) // Beim Mounten Kurse + initiale Studenten laden onMounted(async () => { // Ensure cred state is fresh; banner branch shows when missing if (!credStore.status) await credStore.fetch() await loadCourses() await loadAllStudents() }) </script> <template> <div class="max-w-6xl mx-auto w-full"> <div class="bg-white rounded-2xl p-10 border shadow-sm min-h-[700px] flex flex-col"> <div class="flex items-center gap-3 mb-6"> <h1 class="text-3xl font-bold text-gray-900"> {{ t('deployment.title') }} </h1> <BarChart3 :size="32" class="text-emerald-600" /> </div> <DeploymentProgressBar :current-step="1" /> <CredentialMissingBanner v-if="credStore.isResolved && !credStore.hasCredential" variant="warning" :title="t('AppsDetailView.missingCredsTitle')" :message="t('AppsDetailView.missingCredsText')" :cta="t('AppsDetailView.missingCredsLink')" ctaTo="/user/openstack" next="/deployment/new/config" class="mb-6" /> <template v-if="!credStore.isResolved || credStore.hasCredential"> <div class="mb-8"> <label class="block text-xl font-bold text-gray-900 mb-3"> {{ t('deployment.config.nameLabel') }} </label> <input v-model="store.draft.name" type="text" :placeholder="t('deployment.config.namePlaceholder')" data-testid="deployment-name" class="w-full px-4 py-3 rounded-full border-2 border-gray-300 focus:border-emerald-500 focus:ring-2 focus:ring-emerald-200 outline-none transition-all" /> </div> <div class="flex-grow"> <h2 class="text-xl font-bold text-gray-900 mb-4"> {{ t('deployment.config.targetGroupTitle') }} </h2> <div class="flex border-b border-gray-200 mb-6"> <button @click="activeTab = 'courses'" class="px-6 py-3 font-semibold transition-colors border-b-2" :class="activeTab === 'courses' ? 'border-emerald-500 text-emerald-600' : 'border-transparent text-gray-500 hover:text-gray-700'" > <BookOpen :size="20" class="inline mr-2" /> {{ t('deployment.config.courseLabel') }} </button> <button @click="activeTab = 'individuals'" class="px-6 py-3 font-semibold transition-colors border-b-2" :class="activeTab === 'individuals' ? 'border-emerald-500 text-emerald-600' : 'border-transparent text-gray-500 hover:text-gray-700'" > <UserPlus :size="20" class="inline mr-2" /> {{ t('deployment.config.studentsLabel') }} </button> </div> <div class="grid grid-cols-1 lg:grid-cols-2 gap-8"> <div> <div v-if="activeTab === 'courses'"> <h3 class="text-lg font-semibold text-gray-800 mb-4">{{ t('CoursesView.title') }}</h3> <div class="space-y-3 max-h-[400px] overflow-y-auto"> <div v-for="course in courses" :key="course.courseId" @click="toggleCourse(course.courseId)" :data-testid="`course-${course.courseId}`" class="flex items-center gap-4 p-4 rounded-lg border-2 cursor-pointer transition-all" :class="isCourseSelected(course.courseId) ? 'bg-emerald-50 border-emerald-300' : 'bg-gray-50 border-gray-200 hover:border-gray-300'" > <div class="w-6 h-6 flex items-center justify-center rounded border transition-colors" :class="isCourseSelected(course.courseId) ? 'bg-emerald-500 border-emerald-500' : 'border-gray-400 bg-white'" > <Check v-if="isCourseSelected(course.courseId)" :size="16" class="text-white" /> </div> <div class="flex-grow"> <div class="font-semibold text-gray-900">{{ course.name }}</div> <div class="text-sm text-gray-600"> <span v-if="loadingCourseStudents.has(course.courseId)">{{ t('CoursesView.loading') }}</span> <span v-else>{{ t('DeploymentDetailView.deploymentStudentCount', getStudentCountForCourse(course.courseId)) }}</span> </div> </div> </div> </div> </div> <div v-if="activeTab === 'individuals'"> <h3 class="text-lg font-semibold text-gray-800 mb-4">{{ t('deployment.config.studentsLabel') }}</h3> <div class="relative mb-4"> <Search class="absolute left-4 top-1/2 transform -translate-y-1/2 text-gray-400" :size="20" /> <input v-model="studentSearchQuery" type="text" :placeholder="t('deployment.config.searchPlaceholder')" data-testid="student-search" class="w-full pl-12 pr-4 py-3 rounded-full border-2 border-gray-200 focus:border-emerald-500 outline-none transition-all" /> </div> <div class="bg-gray-50 rounded-lg overflow-hidden border-2 border-gray-200 max-h-[350px] overflow-y-auto"> <div v-for="student in filteredStudents" :key="student.keycloak_id" @click="toggleStudent(student.keycloak_id)" :data-testid="`student-${student.keycloak_id}`" class="flex items-center gap-3 px-4 py-3 cursor-pointer border-b last:border-b-0 border-gray-200 transition-colors select-none" :class="store.draft.studentIds.includes(student.keycloak_id) ? 'bg-emerald-50' : 'hover:bg-gray-100'" > <div class="w-6 h-6 flex items-center justify-center rounded border transition-colors" :class="store.draft.studentIds.includes(student.keycloak_id) ? 'bg-emerald-500 border-emerald-500' : 'border-gray-400 bg-white'" > <Check v-if="store.draft.studentIds.includes(student.keycloak_id)" :size="16" class="text-white" /> </div> <span class="text-gray-700 font-medium"> {{ (student.firstName || student.lastName) ? `${student.firstName || ''} ${student.lastName || ''}`.trim() : (student.username || student.email || student.name || student.keycloak_id) }} </span> </div> <div v-if="filteredStudents.length === 0" class="p-4 text-gray-500 text-center"> {{ t('CourseDetailView.addModal.noUsersFound') }} </div> </div> </div> </div> <div> <h3 class="text-lg font-semibold text-gray-800 mb-4 flex items-center gap-2"> <Users :size="20" /> {{ t('deployment.groups.studentsSelected', { count: selectedStudents.length }) }} </h3> <div class="bg-gray-50 rounded-lg border-2 border-gray-200 p-4 max-h-[400px] overflow-y-auto"> <div v-if="selectedStudents.length === 0" class="text-gray-500 text-center py-8"> {{ t('deployment.assignment.noStudents') }} </div> <div v-else class="space-y-2"> <div v-for="student in selectedStudents" :key="student.keycloak_id" class="flex items-center justify-between bg-white p-3 rounded-lg border border-gray-200" > <span class="text-gray-700 font-medium"> {{ (student.firstName || student.lastName) ? `${student.firstName || ''} ${student.lastName || ''}`.trim() : (student.username || student.email || student.name || student.keycloak_id) }} </span> <button @click="toggleStudent(student.keycloak_id)" class="text-red-500 hover:text-red-700 font-bold text-lg leading-none" :title="t('CourseDetailView.removeModal.remove')" :data-testid="`remove-${student.keycloak_id}`" > × </button> </div> </div> </div> <div class="mt-4 p-4 bg-blue-50 border border-blue-200 rounded-lg"> <p class="text-sm text-blue-800"> <strong>{{ t('deployment.config.infoTitle') }}</strong> {{ t('deployment.config.infoText') }} </p> </div> </div> </div> </div> </template> <div class="flex justify-between items-center mt-8 pt-4 border-t border-gray-200"> <button @click="handleBack" data-testid="btn-back" class="px-8 py-2.5 rounded-full bg-gray-400 text-white font-semibold hover:bg-gray-500 transition-colors" > {{ t('deployment.actions.back') }} </button> <button @click="handleNext" data-testid="btn-next" :disabled="credStore.isResolved && !credStore.hasCredential" class="px-8 py-2.5 rounded-full bg-emerald-700 text-white font-bold hover:bg-emerald-800 transition-colors shadow-lg shadow-emerald-700/20 disabled:opacity-50 disabled:cursor-not-allowed" > {{ t('deployment.actions.next') }} </button> </div> </div> </div> </template> |