src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt

changeset 198
94f174d591ab
parent 193
1e4044d29b1c
child 200
a5ddfaf6b469
equal deleted inserted replaced
197:0a2ad22ac656 198:94f174d591ab
143 } else { 143 } else {
144 san 144 san
145 } 145 }
146 } 146 }
147 147
148 private fun feedPath(project: Project) = "feed/${project.node}/issues.rss"
149
148 data class PathInfos( 150 data class PathInfos(
149 val projectInfo: ProjectInfo, 151 val projectInfo: ProjectInfo,
150 val version: Version?, 152 val version: Version?,
151 val component: Component? 153 val component: Component?
152 ) { 154 ) {
153 val issuesHref by lazyOf("projects/${projectInfo.project.node}/issues/${version?.node ?: "-"}/${component?.node ?: "-"}/") 155 val project = projectInfo.project
156 val issuesHref by lazyOf("projects/${project.node}/issues/${version?.node ?: "-"}/${component?.node ?: "-"}/")
154 } 157 }
155 158
156 private fun withPathInfo(http: HttpRequest, dao: DataAccessObject): PathInfos? { 159 private fun withPathInfo(http: HttpRequest, dao: DataAccessObject): PathInfos? {
157 val projectInfo = obtainProjectInfo(http, dao) 160 val projectInfo = obtainProjectInfo(http, dao)
158 if (projectInfo == null) { 161 if (projectInfo == null) {
184 187
185 private fun project(http: HttpRequest, dao: DataAccessObject) { 188 private fun project(http: HttpRequest, dao: DataAccessObject) {
186 withPathInfo(http, dao)?.run { 189 withPathInfo(http, dao)?.run {
187 190
188 val issues = dao.listIssues(IssueFilter( 191 val issues = dao.listIssues(IssueFilter(
189 project = SpecificFilter(projectInfo.project), 192 project = SpecificFilter(project),
190 version = version?.let { SpecificFilter(it) } ?: AllFilter(), 193 version = version?.let { SpecificFilter(it) } ?: AllFilter(),
191 component = component?.let { SpecificFilter(it) } ?: AllFilter() 194 component = component?.let { SpecificFilter(it) } ?: AllFilter()
192 )).sortedWith(DEFAULT_ISSUE_SORTER) 195 )).sortedWith(DEFAULT_ISSUE_SORTER)
193 196
194 with(http) { 197 with(http) {
195 view = ProjectDetails(projectInfo, issues, version, component) 198 view = ProjectDetails(projectInfo, issues, version, component)
199 feedPath = feedPath(project)
196 navigationMenu = activeProjectNavMenu( 200 navigationMenu = activeProjectNavMenu(
197 dao.listProjects(), 201 dao.listProjects(),
198 projectInfo, 202 projectInfo,
199 version, 203 version,
200 component 204 component
259 with(http) { 263 with(http) {
260 view = VersionsView( 264 view = VersionsView(
261 projectInfo, 265 projectInfo,
262 dao.listVersionSummaries(projectInfo.project) 266 dao.listVersionSummaries(projectInfo.project)
263 ) 267 )
268 feedPath = feedPath(projectInfo.project)
264 navigationMenu = activeProjectNavMenu( 269 navigationMenu = activeProjectNavMenu(
265 dao.listProjects(), 270 dao.listProjects(),
266 projectInfo 271 projectInfo
267 ) 272 )
268 styleSheets = listOf("projects") 273 styleSheets = listOf("projects")
288 } 293 }
289 } 294 }
290 295
291 with(http) { 296 with(http) {
292 view = VersionEditView(projectInfo, version) 297 view = VersionEditView(projectInfo, version)
298 feedPath = feedPath(projectInfo.project)
293 navigationMenu = activeProjectNavMenu( 299 navigationMenu = activeProjectNavMenu(
294 dao.listProjects(), 300 dao.listProjects(),
295 projectInfo, 301 projectInfo,
296 selectedVersion = version 302 selectedVersion = version
297 ) 303 )
340 with(http) { 346 with(http) {
341 view = ComponentsView( 347 view = ComponentsView(
342 projectInfo, 348 projectInfo,
343 dao.listComponentSummaries(projectInfo.project) 349 dao.listComponentSummaries(projectInfo.project)
344 ) 350 )
351 feedPath = feedPath(projectInfo.project)
345 navigationMenu = activeProjectNavMenu( 352 navigationMenu = activeProjectNavMenu(
346 dao.listProjects(), 353 dao.listProjects(),
347 projectInfo 354 projectInfo
348 ) 355 )
349 styleSheets = listOf("projects") 356 styleSheets = listOf("projects")
369 } 376 }
370 } 377 }
371 378
372 with(http) { 379 with(http) {
373 view = ComponentEditView(projectInfo, component, dao.listUsers()) 380 view = ComponentEditView(projectInfo, component, dao.listUsers())
381 feedPath = feedPath(projectInfo.project)
374 navigationMenu = activeProjectNavMenu( 382 navigationMenu = activeProjectNavMenu(
375 dao.listProjects(), 383 dao.listProjects(),
376 projectInfo, 384 projectInfo,
377 selectedComponent = component 385 selectedComponent = component
378 ) 386 )
424 } 432 }
425 433
426 val comments = dao.listComments(issue) 434 val comments = dao.listComments(issue)
427 435
428 with(http) { 436 with(http) {
429 view = IssueDetailView(issue, comments, projectInfo.project, version, component) 437 view = IssueDetailView(issue, comments, project, version, component)
438 // TODO: feed path for this particular issue
439 feedPath = feedPath(projectInfo.project)
430 navigationMenu = activeProjectNavMenu( 440 navigationMenu = activeProjectNavMenu(
431 dao.listProjects(), 441 dao.listProjects(),
432 projectInfo, 442 projectInfo,
433 version, 443 version,
434 component 444 component
441 451
442 private fun issueForm(http: HttpRequest, dao: DataAccessObject) { 452 private fun issueForm(http: HttpRequest, dao: DataAccessObject) {
443 withPathInfo(http, dao)?.run { 453 withPathInfo(http, dao)?.run {
444 val issue = dao.findIssue(http.pathParams["issue"]?.toIntOrNull() ?: -1) ?: Issue( 454 val issue = dao.findIssue(http.pathParams["issue"]?.toIntOrNull() ?: -1) ?: Issue(
445 -1, 455 -1,
446 projectInfo.project, 456 project,
447 ) 457 )
448 458
449 // pre-select component, if available in the path info 459 // pre-select component, if available in the path info
450 issue.component = component 460 issue.component = component
451 461
462 view = IssueEditView( 472 view = IssueEditView(
463 issue, 473 issue,
464 projectInfo.versions, 474 projectInfo.versions,
465 projectInfo.components, 475 projectInfo.components,
466 dao.listUsers(), 476 dao.listUsers(),
467 projectInfo.project, 477 project,
468 version, 478 version,
469 component 479 component
470 ) 480 )
481 feedPath = feedPath(projectInfo.project)
471 navigationMenu = activeProjectNavMenu( 482 navigationMenu = activeProjectNavMenu(
472 dao.listProjects(), 483 dao.listProjects(),
473 projectInfo, 484 projectInfo,
474 version, 485 version,
475 component 486 component
503 private fun issueCommit(http: HttpRequest, dao: DataAccessObject) { 514 private fun issueCommit(http: HttpRequest, dao: DataAccessObject) {
504 withPathInfo(http, dao)?.run { 515 withPathInfo(http, dao)?.run {
505 // TODO: throw validator exception instead of using defaults 516 // TODO: throw validator exception instead of using defaults
506 val issue = Issue( 517 val issue = Issue(
507 http.param("id")?.toIntOrNull() ?: -1, 518 http.param("id")?.toIntOrNull() ?: -1,
508 projectInfo.project 519 project
509 ).apply { 520 ).apply {
510 component = dao.findComponent(http.param("component")?.toIntOrNull() ?: -1) 521 component = dao.findComponent(http.param("component")?.toIntOrNull() ?: -1)
511 category = IssueCategory.valueOf(http.param("category") ?: "") 522 category = IssueCategory.valueOf(http.param("category") ?: "")
512 status = IssueStatus.valueOf(http.param("status") ?: "") 523 status = IssueStatus.valueOf(http.param("status") ?: "")
513 subject = http.param("subject") ?: "" 524 subject = http.param("subject") ?: ""
520 } 531 }
521 } 532 }
522 eta = http.param("eta")?.let { if (it.isBlank()) null else Date.valueOf(it) } 533 eta = http.param("eta")?.let { if (it.isBlank()) null else Date.valueOf(it) }
523 534
524 affectedVersions = http.paramArray("affected") 535 affectedVersions = http.paramArray("affected")
525 .mapNotNull { param -> param.toIntOrNull()?.let { Version(it, projectInfo.project.id) } } 536 .mapNotNull { param -> param.toIntOrNull()?.let { Version(it, project.id) } }
526 resolvedVersions = http.paramArray("resolved") 537 resolvedVersions = http.paramArray("resolved")
527 .mapNotNull { param -> param.toIntOrNull()?.let { Version(it, projectInfo.project.id) } } 538 .mapNotNull { param -> param.toIntOrNull()?.let { Version(it, project.id) } }
528 } 539 }
529 540
530 val openId = if (issue.id < 0) { 541 val openId = if (issue.id < 0) {
531 dao.insertIssue(issue) 542 dao.insertIssue(issue)
532 } else { 543 } else {

mercurial