-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create citizen dashboard controller (view applications controller) (#35)
* fix: Make payment amount a double in the db * feat: Add application statuses to string constants * refactor: Use new strategy to populate JTable in dashboard * feat: Add cancel handler for apply view * Add controller to routing * feat: Add session ender convenience method * feat: Add citizen dashboard controller * fix: Change return type of application IDs * refactor: Cache application objects in ApplicationFactory * fix: Rename resource
- Loading branch information
Vishwas Adiga
authored
Nov 7, 2021
1 parent
d8bae4a
commit a15398e
Showing
14 changed files
with
352 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
SIMPLE/src/edu/manipal/icas/simple/controllers/ViewApplicationsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package edu.manipal.icas.simple.controllers; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.awt.event.WindowAdapter; | ||
import java.awt.event.WindowEvent; | ||
|
||
import javax.swing.table.DefaultTableModel; | ||
|
||
import edu.manipal.icas.simple.models.application.Application; | ||
import edu.manipal.icas.simple.models.application.ApplicationQuestion; | ||
import edu.manipal.icas.simple.session.CitizenSession; | ||
import edu.manipal.icas.simple.utils.StringConstants; | ||
import edu.manipal.icas.simple.views.CitizenDashboardView; | ||
import edu.manipal.icas.simple.views.View; | ||
|
||
public class ViewApplicationsController { | ||
private CitizenDashboardView view; | ||
private CitizenSession session; | ||
|
||
public ViewApplicationsController(CitizenDashboardView dashboardView) { | ||
this.view = dashboardView; | ||
initLogoutHandler(); | ||
initNewApplicationHandler(); | ||
initFaqHandler(); | ||
|
||
dashboardView.getFrame().addWindowListener(new WindowAdapter() { | ||
@Override | ||
public void windowActivated(WindowEvent e) { | ||
session = (CitizenSession) SessionController.getController().getCurrentSession(); | ||
initCitizenDetailFields(); | ||
initTrackApplicationFields(); | ||
} | ||
}); | ||
} | ||
|
||
public View getDashboardView() { | ||
return view; | ||
} | ||
|
||
private void initLogoutHandler() { | ||
view.getLogoutButton().addActionListener(new ActionListener() { | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
SessionController.getController().endCurrentSession(); | ||
RouteController.getController().routeTo(Route.CITIZEN_LOGIN); | ||
} | ||
}); | ||
} | ||
|
||
private void initNewApplicationHandler() { | ||
view.getApplicationForNewPassportButton().addActionListener(new ActionListener() { | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
RouteController.getController().routeTo(Route.APPLICATION_FORM); | ||
} | ||
}); | ||
} | ||
|
||
private void initCitizenDetailFields() { | ||
view.getEmailAddressTextField().setText(session.getCitizen().getEmailAddress()); | ||
} | ||
|
||
private void initTrackApplicationFields() { | ||
view.getApplicationIdComboBox().removeAllItems(); | ||
for (Application application : session.getCitizen().getApplications()) { | ||
view.getApplicationIdComboBox().addItem(application.getApplicationId()); | ||
} | ||
|
||
view.getApplicationStatus().setText("-"); | ||
|
||
view.getApplicationIdComboBox().addActionListener(new ActionListener() { | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
Integer selection = (Integer) view.getApplicationIdComboBox().getSelectedItem(); | ||
if (selection == null) | ||
return; | ||
|
||
for (Application application : session.getCitizen().getApplications()) { | ||
if (application.getApplicationId() == selection) { | ||
showTrackingForApplication(application); | ||
break; | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private void initFaqHandler() { | ||
view.getRedirectToAppStepsButton().addActionListener(new ActionListener() { | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
// TODO (mehsheed): Add redirect to FAQ website | ||
} | ||
}); | ||
} | ||
|
||
private void showTrackingForApplication(Application application) { | ||
view.getApplicationStatus().setText(StringConstants.APPLICATION_STATUS_STRINGS.get(application.getStatus())); | ||
DefaultTableModel model = (DefaultTableModel) view.getApplicationTable().getModel(); | ||
|
||
for (int i = model.getRowCount() - 1; i >= 0; --i) { | ||
model.removeRow(i); | ||
} | ||
|
||
model.addRow(new Object[] { "Application ID", application.getApplicationId() }); | ||
model.addRow(new Object[] { "Applicant's Name", application.getApplicant().getName() }); | ||
model.addRow(new Object[] { "Application Created On", application.getDateCreated() }); | ||
model.addRow(new Object[] { "Appointment Scheduled On", application.getDateOfAppointment() }); | ||
model.addRow(new Object[] { "Application Type", application.getType() }); | ||
model.addRow(new Object[] { "Birth Address", application.getBirthAddress() }); | ||
model.addRow(new Object[] { "Permanent Address", application.getPermanentAddress() }); | ||
model.addRow(new Object[] { "Present Address", application.getPresentAddress() }); | ||
model.addRow(new Object[] { "Father's Name", application.getNameOfFather() }); | ||
model.addRow(new Object[] { "Mother's Name", application.getNameOfMother() }); | ||
|
||
for (ApplicationQuestion question : ApplicationQuestion.values()) { | ||
model.addRow(new Object[] { StringConstants.APPLICATION_QUESTIONS.get(question), | ||
application.getAnswerForQuestion(question) ? "Yes" : "No" }); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.