Skip to content

Commit

Permalink
#2 Zwischenstand: TabSheet eingebaut, Filter eingebaut
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanSzczesny committed Jun 16, 2016
1 parent 2a67b0b commit 3bd787c
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.symeda.sormas.api.caze;
package de.symeda.sormas.api;

import java.io.Serializable;

Expand Down
12 changes: 12 additions & 0 deletions sormas-api/src/de/symeda/sormas/api/caze/CaseDto.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.symeda.sormas.api.caze;

import de.symeda.sormas.api.DataTransferObject;
import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.person.PersonDto;

public class CaseDto extends DataTransferObject {
Expand All @@ -9,10 +11,12 @@ public class CaseDto extends DataTransferObject {
public static final String CASE_STATUS = "caseStatus";
public static final String DESCRIPTION = "description";
public static final String PERSON = "personDto";
public static final String DISEASE = "disease";

private CaseStatus caseStatus;
private String description;
private PersonDto personDto;
private Disease disease;

public CaseStatus getCaseStatus() {
return caseStatus;
Expand All @@ -37,4 +41,12 @@ public PersonDto getPerson() {
public void setPersonDto(PersonDto personDto) {
this.personDto = personDto;
}

public Disease getDisease() {
return disease;
}

public void setDisease(Disease disease) {
this.disease = disease;
}
}
2 changes: 1 addition & 1 deletion sormas-api/src/de/symeda/sormas/api/person/PersonDto.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.symeda.sormas.api.person;

import de.symeda.sormas.api.caze.DataTransferObject;
import de.symeda.sormas.api.DataTransferObject;

public class PersonDto extends DataTransferObject {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import java.util.List;
import java.util.Random;

import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.caze.CaseDto;
import de.symeda.sormas.api.caze.CaseStatus;
import de.symeda.sormas.api.person.PersonDto;

public class MockDataGenerator {
Expand Down Expand Up @@ -42,7 +44,7 @@ public class MockDataGenerator {

public static List<CaseDto> createCases() {
List<CaseDto> cases = new ArrayList<CaseDto>();
for (int i = 0; i < 1; i++) {
for (int i = 0; i < 5; i++) {
CaseDto p = createCase();
cases.add(p);
}
Expand All @@ -53,6 +55,8 @@ private static CaseDto createCase() {
CaseDto c = new CaseDto();
c.setUuid(java.util.UUID.randomUUID().toString());
c.setDescription(generateName());
c.setCaseStatus(generateStatus());
c.setDisease(Disease.EBOLA);
return c;
}

Expand All @@ -64,6 +68,10 @@ public static PersonDto createPerson() {
return personDto;
}


private static CaseStatus generateStatus() {
return CaseStatus.values()[random.nextInt(CaseStatus.values().length)];
}

private static String generateName() {
return word1[random.nextInt(word1.length)] + " "
Expand Down
12 changes: 12 additions & 0 deletions sormas-rest/src/main/java/de/symeda/sormas/rest/CaseResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,16 @@ public List<CaseDto> getAllCases() {
// TODO Auto-generated method stub
return null;
}

@Override
public CaseDto saveCase(CaseDto dto) {
// TODO Auto-generated method stub
return null;
}

@Override
public void createDemo() {
// TODO Auto-generated method stub

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.Serializable;

import com.vaadin.server.Page;
import com.vaadin.ui.Component;
import com.vaadin.ui.VerticalLayout;

import de.symeda.sormas.api.FacadeProvider;
import de.symeda.sormas.api.caze.CaseDto;
Expand All @@ -22,13 +24,14 @@ public class CaseController implements Serializable {

private static final long serialVersionUID = 1L;
private CasesView view;
private CaseForm caseEditForm;

public CaseController(CasesView simpleCrudView) {
view = simpleCrudView;
}

public void init() {
editCase(null);
showCaseNavigation(null);
// Hide and disable if not admin
if (!SurveillanceUI.get().getAccessControl().isUserInRole("admin")) {
view.setNewCaseEnabled(false);
Expand All @@ -37,7 +40,7 @@ public void init() {
// Create demo-content
FacadeProvider.getCaseFacade().createDemo();

view.show(FacadeProvider.getCaseFacade().getAllCases());
showCaseOverView();
}

public void cancelCase() {
Expand Down Expand Up @@ -81,7 +84,31 @@ public void enter(String uuidOrNew) {
private CaseDto findCase(String uuid) {
return FacadeProvider.getCaseFacade().getByUuid(uuid);
}


public void showCaseOverView() {
view.clearSelection();
view.edit(null);
view.show(FacadeProvider.getCaseFacade().getAllCases());
}

public void showCaseNavigation(CaseDto caze) {
view.clearSelection();
if (caze == null) {
setFragmentParameter("");
} else {
setFragmentParameter(caze.getUuid());
}
view.edit(caze);
caseEditForm.editCase(caze);
}

public void newCase() {
view.clearSelection();
setFragmentParameter("new");
view.edit(new CaseDto());
}

public void updateCase(CaseDto caze) {
//FacadeProvider.getCaseFacade().update(caze);
view.showSaveNotification(CaseHelper.getShortUuid(caze) + " updated");
Expand All @@ -101,24 +128,22 @@ public void deleteProduct(CaseDto caze) {
setFragmentParameter("");
}

public void editCase(CaseDto caze) {
if (caze == null) {
setFragmentParameter("");
} else {
setFragmentParameter(caze.getUuid());
}
view.edit(caze);
}

public void newCase() {
view.clearSelection();
setFragmentParameter("new");
view.edit(new CaseDto());
}

public void rowSelected(CaseDto product) {
if (SurveillanceUI.get().getAccessControl().isUserInRole("admin")) {
editCase(product);
showCaseNavigation(product);
}
}



public Component getCaseDataView() {
VerticalLayout formLayout = new VerticalLayout();
caseEditForm = new CaseForm(this);
formLayout.addComponent(caseEditForm);
formLayout.setSizeFull();
formLayout.setExpandRatio(caseEditForm, 1);
return formLayout;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.data.util.MethodProperty;
import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.filter.Compare.Equal;
import com.vaadin.data.util.filter.Or;
import com.vaadin.data.util.filter.SimpleStringFilter;
import com.vaadin.ui.Grid;

import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.caze.CaseDto;
import de.symeda.sormas.api.caze.CaseStatus;

public class CaseGrid extends Grid {

Expand All @@ -24,7 +27,7 @@ public CaseGrid() {

BeanItemContainer<CaseDto> container = new BeanItemContainer<CaseDto>(CaseDto.class);
setContainerDataSource(container);
setColumnOrder(CaseDto.UUID, CaseDto.CASE_STATUS, CaseDto.DESCRIPTION);
setColumnOrder(CaseDto.UUID, CaseDto.CASE_STATUS, CaseDto.DISEASE);
getColumn(CaseDto.UUID).setConverter(new Converter<String, String>() {

private static final long serialVersionUID = -5274112323551652930L;
Expand Down Expand Up @@ -61,19 +64,35 @@ public Class<String> getPresentationType() {
* string to look for
*/
public void setFilter(String filterString) {
getContainer().removeAllContainerFilters();
removeAllFilter();
if (filterString.length() > 0) {
SimpleStringFilter nameFilter = new SimpleStringFilter(
"productName", filterString, true, false);
SimpleStringFilter availabilityFilter = new SimpleStringFilter(
"availability", filterString, true, false);
SimpleStringFilter categoryFilter = new SimpleStringFilter(
"category", filterString, true, false);
CaseDto.PERSON, filterString, true, false);
SimpleStringFilter descFilter = new SimpleStringFilter(
CaseDto.DESCRIPTION, filterString, true, false);
SimpleStringFilter statusFilter = new SimpleStringFilter(
CaseDto.CASE_STATUS, filterString, true, false);
getContainer().addContainerFilter(
new Or(nameFilter, availabilityFilter, categoryFilter));
new Or(nameFilter, descFilter, statusFilter));
}

}

public void setFilter(CaseStatus statusToFilter) {
removeAllFilter();
Equal filter = new Equal(CaseDto.CASE_STATUS, statusToFilter);
getContainer().addContainerFilter(filter);
}

public void setFilter(Disease disease) {
removeAllFilter();
Equal filter = new Equal(CaseDto.DISEASE, disease);
getContainer().addContainerFilter(filter);
}

public void removeAllFilter() {
getContainer().removeAllContainerFilters();
}

@SuppressWarnings("unchecked")
private BeanItemContainer<CaseDto> getContainer() {
Expand Down Expand Up @@ -108,4 +127,6 @@ public void refresh(CaseDto caze) {
public void remove(CaseDto caze) {
getContainer().removeItem(caze);
}


}
Loading

0 comments on commit 3bd787c

Please sign in to comment.