-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(mail): implement the send mail view #337
Changes from 2 commits
393d5f0
947ac76
cf2f20f
b528570
c4b8f59
8e6b68f
e6322b0
47231b0
d9f5c93
24f387e
355547b
cc54a2d
c7fc6c4
cd0c86e
619dfde
e22c80a
a5a7bda
7bbad19
7ab7abb
7566eb1
97a7bd4
32f321b
98597dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package apply.ui.admin.mail | ||
|
||
import apply.application.EvaluationService | ||
import apply.application.MailTargetService | ||
import apply.application.RecruitmentResponse | ||
import apply.application.RecruitmentService | ||
import apply.domain.evaluation.Evaluation | ||
import apply.domain.evaluationtarget.EvaluationStatus | ||
import apply.ui.admin.BaseLayout | ||
import com.vaadin.flow.component.Component | ||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout | ||
import com.vaadin.flow.component.select.Select | ||
import com.vaadin.flow.router.Route | ||
import support.views.Title | ||
import support.views.createItemSelect | ||
|
||
@Route(value = "group", layout = BaseLayout::class) | ||
class GroupMailFormView( | ||
private val recruitmentService: RecruitmentService, | ||
private val evaluationService: EvaluationService, | ||
private val mailTargetService: MailTargetService | ||
) : MailFormView(mailTargetService) { | ||
private val recruitment: Select<RecruitmentResponse> | ||
private val evaluation: Select<Evaluation> | ||
private val evaluationStatus: Select<EvaluationStatus> | ||
|
||
init { | ||
evaluation = createEvaluationItem() | ||
evaluationStatus = createEvaluationStatusItem(evaluation) | ||
recruitment = createRecruitmentItem(evaluation) | ||
add(Title("그룹 발송"), createMailForm()) | ||
setWidthFull() | ||
} | ||
|
||
override fun createReceiverFilter(): Component { | ||
return HorizontalLayout(recruitment, evaluation, evaluationStatus) | ||
} | ||
|
||
private fun createRecruitmentItem(evaluation: Select<Evaluation>): Select<RecruitmentResponse> { | ||
return createItemSelect<RecruitmentResponse>("모집").apply { | ||
setItems(*recruitmentService.findAll().toTypedArray()) | ||
setItemLabelGenerator { it.title } | ||
addValueChangeListener { | ||
evaluation.apply { | ||
setItems(*evaluationService.findAllByRecruitmentId(it.value.id).toTypedArray()) | ||
setItemLabelGenerator { it.title } | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun createEvaluationItem(): Select<Evaluation> { | ||
return createItemSelect("평가") | ||
} | ||
|
||
private fun createEvaluationStatusItem(evaluation: Select<Evaluation>): Select<EvaluationStatus> { | ||
return createItemSelect<EvaluationStatus>("모집 상태").apply { | ||
setItems(*EvaluationStatus.values()) | ||
setItemLabelGenerator { it.toText() } | ||
addValueChangeListener { | ||
receivers.clear() | ||
val mailTargets = mailTargetService.findMailTargets(evaluation.value.id, it.value).map { it.email } | ||
receivers.addAll( | ||
mailTargets | ||
) | ||
println("조회한 mailTargets: $mailTargets") | ||
println("현재 receivers: $receivers") | ||
} | ||
} | ||
} | ||
|
||
private fun EvaluationStatus.toText() = | ||
when (this) { | ||
EvaluationStatus.WAITING -> "평가 전" | ||
EvaluationStatus.PASS -> "합격" | ||
EvaluationStatus.FAIL -> "탈락" | ||
EvaluationStatus.PENDING -> "보류" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package apply.ui.admin.mail | ||
|
||
import apply.application.ApplicantResponse | ||
import apply.application.ApplicantService | ||
import apply.application.MailTargetService | ||
import apply.ui.admin.BaseLayout | ||
import com.vaadin.flow.component.Component | ||
import com.vaadin.flow.component.button.Button | ||
import com.vaadin.flow.component.dialog.Dialog | ||
import com.vaadin.flow.component.grid.Grid | ||
import com.vaadin.flow.component.html.H2 | ||
import com.vaadin.flow.component.orderedlayout.FlexComponent | ||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout | ||
import com.vaadin.flow.component.orderedlayout.VerticalLayout | ||
import com.vaadin.flow.data.renderer.ComponentRenderer | ||
import com.vaadin.flow.data.renderer.Renderer | ||
import com.vaadin.flow.router.Route | ||
import support.views.Title | ||
import support.views.addSortableColumn | ||
import support.views.createErrorButton | ||
import support.views.createNormalButton | ||
import support.views.createPrimaryButton | ||
import support.views.createSearchBar | ||
|
||
@Route(value = "personal", layout = BaseLayout::class) | ||
class IndividualMailFormView( | ||
private val applicantService: ApplicantService, | ||
mailTargetService: MailTargetService | ||
) : MailFormView(mailTargetService) { | ||
init { | ||
add(Title("개별 발송"), createMailForm()) | ||
setWidthFull() | ||
} | ||
|
||
override fun createReceiverFilter(): Component { | ||
return createNormalButton("지원자 조회") { | ||
Dialog().apply { | ||
width = "800px" | ||
height = "90%" | ||
val applicants = HorizontalLayout().apply { | ||
setWidthFull() | ||
} | ||
add( | ||
H2("지원자 정보 검색"), | ||
HorizontalLayout( | ||
createAddReceivers(), | ||
HorizontalLayout( | ||
createErrorButton("취소") { | ||
close() | ||
} | ||
).apply { | ||
justifyContentMode = FlexComponent.JustifyContentMode.END | ||
defaultHorizontalComponentAlignment = FlexComponent.Alignment.END | ||
} | ||
), | ||
applicants | ||
).apply { | ||
setWidthFull() | ||
} | ||
open() | ||
} | ||
}.apply { isEnabled = true } | ||
} | ||
|
||
private fun createAddReceivers(): Component { | ||
val container = VerticalLayout() | ||
return VerticalLayout( | ||
createSearchBar { | ||
container.removeAll() | ||
val founds = applicantService.findAllByKeyword(it) | ||
if (founds.isNotEmpty()) { | ||
container.add( | ||
createGrid(founds) | ||
) | ||
} | ||
}, | ||
container | ||
) | ||
} | ||
|
||
private fun createGrid(applicantResponse: List<ApplicantResponse>): Component { | ||
return Grid<ApplicantResponse>(10).apply { | ||
addSortableColumn("이름", ApplicantResponse::name) | ||
addSortableColumn("이메일", ApplicantResponse::email) | ||
addColumn(createEditAndDeleteButton()).apply { isAutoWidth = true } | ||
setItems(applicantResponse) | ||
} | ||
} | ||
|
||
private fun createEditAndDeleteButton(): Renderer<ApplicantResponse> { | ||
return ComponentRenderer<Component, ApplicantResponse> { applicantResponse -> | ||
HorizontalLayout( | ||
createAddOrDeleteButton(applicantResponse) | ||
) | ||
} | ||
} | ||
|
||
private fun createAddOrDeleteButton(applicantResponse: ApplicantResponse): Component { | ||
if (this.receivers.contains(applicantResponse.email)) { | ||
return createDeleteButton(applicantResponse) | ||
} | ||
|
||
return createAddButton(applicantResponse) | ||
} | ||
|
||
private fun createAddButton(applicantResponse: ApplicantResponse): Button { | ||
return createPrimaryButton("추가") { | ||
this.receivers.add(applicantResponse.email) | ||
}.apply { | ||
isDisableOnClick = true | ||
} | ||
} | ||
|
||
private fun createDeleteButton(applicantResponse: ApplicantResponse): Button { | ||
return createErrorButton("삭제") { | ||
this.receivers.remove(applicantResponse.email) | ||
}.apply { | ||
isDisableOnClick = true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package apply.ui.admin.mail | ||
|
||
import apply.application.MailTargetService | ||
import com.vaadin.flow.component.Component | ||
import com.vaadin.flow.component.html.H3 | ||
import com.vaadin.flow.component.html.H4 | ||
import com.vaadin.flow.component.orderedlayout.FlexComponent | ||
import com.vaadin.flow.component.orderedlayout.VerticalLayout | ||
import com.vaadin.flow.component.textfield.TextArea | ||
import com.vaadin.flow.component.textfield.TextField | ||
import com.vaadin.flow.router.RoutePrefix | ||
import support.views.createPrimaryButton | ||
|
||
@RoutePrefix(value = "admin/emails") | ||
abstract class MailFormView( | ||
private val mailTargetService: MailTargetService | ||
) : VerticalLayout() { | ||
protected val title: TextField = TextField("메일 제목", "메일 제목 입력") | ||
protected val receivers: MutableList<String> = mutableListOf() | ||
protected val content: TextArea = createMailBody() | ||
|
||
protected fun createMailForm(): Component { | ||
val titleText = VerticalLayout( | ||
H3("메일 제목"), | ||
title.apply { setSizeFull() } | ||
) | ||
|
||
val receivers = VerticalLayout(H4("수신자"), createReceiverFilter()) | ||
val mailBody = VerticalLayout( | ||
content | ||
).apply { | ||
setSizeFull() | ||
} | ||
|
||
val sendButton = VerticalLayout( | ||
createPrimaryButton("전송") { | ||
println("title: ${title.value} receivers: ${this.receivers} content: ${this.content.value}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 혹~시 제가 해당 print문을 못찾는 걸까요?ㅠㅠㅠ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 어.... 이 부분은 아직 혹시 전송 버튼을 눌러도 콘솔 창에 출력이 안된다는 말씀이신가요?? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네네ㅠ콘솔에 안 뜨는것 같아서 남겼는데 제가 못찾는거라면 알려주세요ㅎㅎㅎ |
||
// todo: (print 내용 지우고) mailSender로 메일 보내기! | ||
} | ||
).apply { | ||
setSizeFull() | ||
} | ||
|
||
return VerticalLayout(titleText, receivers, mailBody, sendButton).apply { | ||
setSizeFull() | ||
justifyContentMode = FlexComponent.JustifyContentMode.CENTER | ||
defaultHorizontalComponentAlignment = FlexComponent.Alignment.CENTER | ||
} | ||
} | ||
|
||
private fun createMailBody(): TextArea { | ||
return TextArea("메일 본문").apply { | ||
setSizeFull() | ||
style.set("minHeight", "800px") | ||
placeholder = "메일 본문 입력" | ||
} | ||
} | ||
|
||
abstract fun createReceiverFilter(): Component | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package apply.ui.admin.mail | ||
|
||
import apply.ui.admin.BaseLayout | ||
import com.vaadin.flow.component.Component | ||
import com.vaadin.flow.component.UI | ||
import com.vaadin.flow.component.orderedlayout.FlexComponent | ||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout | ||
import com.vaadin.flow.component.orderedlayout.VerticalLayout | ||
import com.vaadin.flow.router.Route | ||
import support.views.Title | ||
import support.views.createPrimaryButton | ||
|
||
@Route(value = "admin/emails", layout = BaseLayout::class) | ||
class MailSelectionsView : VerticalLayout() { | ||
init { | ||
add(Title("메일 발송"), *createMailTypeButtons()) | ||
} | ||
|
||
private fun createMailTypeButtons(): Array<Component> { | ||
return arrayOf(createGroupMailButton(), createIndividualMailButton()) | ||
} | ||
|
||
private fun createGroupMailButton(): Component { | ||
return HorizontalLayout( | ||
createPrimaryButton("그룹 발송") { | ||
UI.getCurrent().navigate(GroupMailFormView::class.java) | ||
} | ||
).apply { | ||
setWidthFull() | ||
justifyContentMode = FlexComponent.JustifyContentMode.CENTER | ||
} | ||
} | ||
|
||
private fun createIndividualMailButton(): Component { | ||
return HorizontalLayout( | ||
createPrimaryButton("개별 발송") { | ||
UI.getCurrent().navigate(IndividualMailFormView::class.java) | ||
} | ||
).apply { | ||
setWidthFull() | ||
justifyContentMode = FlexComponent.JustifyContentMode.CENTER | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수신자 목록이 모집, 평가, 모집상태 하부에 뜨는게 어떨까요?