Search in sources :

Example 11 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class FormInputViewModelTest method inputMask.

@Test
public void inputMask() {
    IntakeForm intakeForm = setup.getCatalog().getIntakeForm();
    FormInputViewModelBuilder builder = builderFor(intakeForm);
    FormInputModel inputModel = new FormInputModel(new RecordRef(intakeForm.getFormId(), ResourceId.generateId()));
    // Fill in required fields
    inputModel = inputModel.update(intakeForm.getOpenDateFieldId(), new LocalDate(2017, 1, 1));
    // Does not match input mask "000"
    inputModel = inputModel.update(intakeForm.getRegNumberFieldId(), new FieldInput(TextValue.valueOf("FOOOOO")));
    FormInputViewModel viewModel = builder.build(inputModel);
    assertThat(viewModel.isValid(), equalTo(false));
    assertThat(viewModel.getValidationErrors(intakeForm.getRegNumberFieldId()), not(empty()));
}
Also used : RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) FieldInput(org.activityinfo.ui.client.input.model.FieldInput) LocalDate(org.activityinfo.model.type.time.LocalDate) Test(org.junit.Test)

Example 12 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class LookupKeySetTest method labelTest.

@Test
public void labelTest() {
    NfiForm nfiForm = setup.getNfiForm();
    VillageForm villageForm = setup.getVillageForm();
    AdminLevelForm territoryForm = villageForm.getParentForm();
    AdminLevelForm provinceForm = territoryForm.getParentForm().get();
    Observable<Maybe<RecordTree>> nfiRecordTree = setup.getFormStore().getRecordTree(nfiForm.getRecordRef(0));
    Connection<Maybe<RecordTree>> nfiRecordTreeView = setup.connect(nfiRecordTree);
    RecordTree tree = nfiRecordTreeView.assertLoaded().get();
    LookupKeySet lookupKeySet = new LookupKeySet(tree.getFormTree(), tree.getFormTree().getRootField(nfiForm.getVillageField().getId()).getField());
    assertThat(lookupKeySet.getLookupKeys().size(), equalTo(3));
    ReferenceValue referenceValue = (ReferenceValue) tree.getRoot().get(nfiForm.getVillageField().getId());
    RecordRef villageRef = referenceValue.getOnlyReference();
    RecordTree villageTree = tree.subTree(villageRef);
    referenceValue = (ReferenceValue) villageTree.getRoot().get(villageForm.getAdminFieldId());
    RecordRef territoryRef = referenceValue.getOnlyReference();
    RecordTree territoryTree = villageTree.subTree(territoryRef);
    referenceValue = (ReferenceValue) territoryTree.getRoot().get(territoryForm.getParentFieldId());
    RecordRef provinceRef = referenceValue.getOnlyReference();
    Maybe<String> villageLabel = lookupKeySet.label(tree, villageRef);
    Maybe<String> territoryLabel = lookupKeySet.label(tree, territoryRef);
    Maybe<String> provinceLabel = lookupKeySet.label(tree, provinceRef);
    assertThat(villageLabel, equalTo(Maybe.of("Village 660")));
    assertThat(territoryLabel, equalTo(Maybe.of("Territory 85")));
    assertThat(provinceLabel, equalTo(Maybe.of("Province 11")));
}
Also used : RecordTree(org.activityinfo.model.formTree.RecordTree) Maybe(org.activityinfo.promise.Maybe) LookupKeySet(org.activityinfo.model.formTree.LookupKeySet) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) Test(org.junit.Test)

Example 13 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class LookupViewModelTest method overlappingHierarchies.

@Test
public void overlappingHierarchies() {
    LocaliteForm locationForm = catalog.getLocaliteForm();
    FormTree formTree = catalog.getFormTree(locationForm.getFormId());
    LookupViewModel viewModel = new LookupViewModel(setup.getFormStore(), formTree, locationForm.getAdminField());
    assertThat(viewModel.getLookupKeys(), hasSize(3));
    LookupKeyViewModel province = viewModel.getLookupKeys().get(0);
    assertThat(province.getKeyLabel(), equalTo("Province Name"));
    // The second level should now reflect these choices
    LookupKeyViewModel territory = viewModel.getLookupKeys().get(1);
    assertThat(territory.getKeyLabel(), equalTo("Territory Name"));
    // We also have a third level -- Health Zone or "Zone de Sante" which
    // is related to province, but NOT territory.
    LookupKeyViewModel healthZone = viewModel.getLookupKeys().get(2);
    assertThat(healthZone.getKeyLabel(), equalTo("Zone de Sante Name"));
    // Connect to the lists
    Connection<List<String>> provinceList = setup.connect(province.getChoices());
    Connection<List<String>> territoryList = setup.connect(territory.getChoices());
    Connection<List<String>> zoneList = setup.connect(healthZone.getChoices());
    // Connect to the selection
    Connection<Set<RecordRef>> selection = setup.connect(viewModel.getSelectedRecords());
    // Initially... no selection
    assertThat(selection.assertLoaded().isEmpty(), equalTo(true));
    // Initially the root level should have all choices (16)
    assertThat(provinceList.assertLoaded(), hasSize(catalog.getProvince().getCount()));
    // Select a province.
    viewModel.select(province.getLookupKey(), province.getChoices().get().get(2));
    // Choosing just a province is a valid selection, so we should now have a value
    assertThat(selection.assertLoaded(), hasSize(1));
    // ..and the options available to the second level
    territoryList.assertChanged();
    System.out.println(territoryList.assertLoaded());
    assertThat(territoryList.assertLoaded(), hasSize(7));
    System.out.println(territoryList.assertLoaded());
    // Select a territory
    viewModel.select(territory.getLookupKey(), territoryList.assertLoaded().get(2));
    zoneList.assertChanged();
    // No we should still have only one selected record, but this time
    // territory and not province because province is a parent of territory.
    RecordRef territoryRef = new RecordRef(catalog.getTerritory().getFormId(), ResourceId.valueOf("c23"));
    assertThat(selection.assertLoaded(), contains(territoryRef));
    // We should ALSO be able to select a Zone de Sante
    viewModel.select(healthZone.getLookupKey(), zoneList.assertLoaded().get(5));
    RecordRef zoneRef = new RecordRef(catalog.getHealthZone().getFormId(), ResourceId.valueOf("c165"));
    assertThat(selection.assertLoaded(), containsInAnyOrder(territoryRef, zoneRef));
}
Also used : ColumnSet(org.activityinfo.model.query.ColumnSet) FormTree(org.activityinfo.model.formTree.FormTree) RecordRef(org.activityinfo.model.type.RecordRef) Test(org.junit.Test)

Example 14 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class LookupViewModelTest method overlappingHierarchiesInitialSelection.

@Test
public void overlappingHierarchiesInitialSelection() {
    LocaliteForm locationForm = catalog.getLocaliteForm();
    FormTree formTree = catalog.getFormTree(locationForm.getFormId());
    LookupViewModel viewModel = new LookupViewModel(setup.getFormStore(), formTree, locationForm.getAdminField());
    RecordRef territoryRef = new RecordRef(catalog.getTerritory().getFormId(), ResourceId.valueOf("c23"));
    Connection<Optional<String>> province = setup.connect(viewModel.getLookupKeys().get(0).getSelectedKey());
    Connection<Optional<String>> territory = setup.connect(viewModel.getLookupKeys().get(1).getSelectedKey());
    Connection<Optional<String>> healthZone = setup.connect(viewModel.getLookupKeys().get(2).getSelectedKey());
    // Initially the key value labels should be empty
    assertThat(province.assertLoaded().isPresent(), equalTo(false));
    assertThat(territory.assertLoaded().isPresent(), equalTo(false));
    assertThat(healthZone.assertLoaded().isPresent(), equalTo(false));
    // If the initial selection is a territory then the province and territory labels should be loaded
    viewModel.setInitialSelection(Collections.singleton(territoryRef));
    assertThat(province.assertLoaded().get(), equalTo("Province 11"));
    assertThat(territory.assertLoaded().get(), equalTo("Territory 24"));
    assertThat(healthZone.assertLoaded().isPresent(), equalTo(false));
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) Optional(com.google.common.base.Optional) RecordRef(org.activityinfo.model.type.RecordRef) Test(org.junit.Test)

Example 15 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class TableToolBar method onEditRecord.

private void onEditRecord(SelectEvent event) {
    Optional<RecordRef> selected = viewModel.getSelectedRecordRef().get();
    if (!selected.isPresent()) {
        return;
    }
    FormDialog dialog = new FormDialog(formStore, selected.get());
    dialog.show();
}
Also used : FormDialog(org.activityinfo.ui.client.input.view.FormDialog) RecordRef(org.activityinfo.model.type.RecordRef)

Aggregations

RecordRef (org.activityinfo.model.type.RecordRef)66 Test (org.junit.Test)31 ResourceId (org.activityinfo.model.resource.ResourceId)26 ReferenceValue (org.activityinfo.model.type.ReferenceValue)26 FormInputModel (org.activityinfo.ui.client.input.model.FormInputModel)14 FormInstance (org.activityinfo.model.form.FormInstance)7 FormTree (org.activityinfo.model.formTree.FormTree)7 LocalDate (org.activityinfo.model.type.time.LocalDate)7 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)6 Optional (com.google.common.base.Optional)5 FieldValue (org.activityinfo.model.type.FieldValue)5 FieldInput (org.activityinfo.ui.client.input.model.FieldInput)5 FormClass (org.activityinfo.model.form.FormClass)4 ResultSet (java.sql.ResultSet)3 FormField (org.activityinfo.model.form.FormField)3 RecordTree (org.activityinfo.model.formTree.RecordTree)3 ColumnSet (org.activityinfo.model.query.ColumnSet)3 ColumnView (org.activityinfo.model.query.ColumnView)3 RecordTransaction (org.activityinfo.model.resource.RecordTransaction)3 RecordUpdate (org.activityinfo.model.resource.RecordUpdate)3