use of org.activityinfo.model.analysis.TableColumn in project activityinfo by bedatadriven.
the class TableViewModelTest method test.
@Test
public void test() {
TableModel tableModel = ImmutableTableModel.builder().formId(setup.getSurveyForm().getFormId()).build();
TableViewModel viewModel = new TableViewModel(setup.getFormStore(), tableModel);
Connection<EffectiveTableModel> view = setup.connect(viewModel.getEffectiveTable());
EffectiveTableModel effectiveTableModel = view.assertLoaded();
EffectiveTableColumn nameColumn = effectiveTableModel.getColumns().get(0);
assertThat(nameColumn.getLabel(), equalTo("Respondent Name"));
// Now verify that we can update the column label
view.resetChangeCounter();
TableColumn updatedColumn = ImmutableTableColumn.builder().from(nameColumn.getModel()).label("MY column").build();
viewModel.update(ImmutableTableModel.builder().from(tableModel).columns(Arrays.asList(updatedColumn)).build());
setup.runScheduled();
// Should receive a change event...
view.assertChanged();
EffectiveTableModel updatedModel = view.assertLoaded();
assertThat(updatedModel.getColumns().get(0).getLabel(), equalTo("MY column"));
}
use of org.activityinfo.model.analysis.TableColumn in project activityinfo by bedatadriven.
the class TableViewModelTest method testSubFormExport.
@Test
public void testSubFormExport() {
IncidentForm incidentForm = setup.getCatalog().getIncidentForm();
TableModel tableModel = ImmutableTableModel.builder().formId(incidentForm.getFormId()).addColumns(ImmutableTableColumn.builder().label("My PCODE").formula(IncidentForm.PROTECTION_CODE_FIELD_ID.asString()).build()).build();
TableViewModel viewModel = new TableViewModel(setup.getFormStore(), tableModel);
Connection<TableModel> exportModel = setup.connect(viewModel.computeExportModel(Observable.just(ReferralSubForm.FORM_ID), Observable.just(ExportScope.SELECTED)));
System.out.println(Json.stringify(exportModel.assertLoaded().toJson(), 2));
assertThat(exportModel.assertLoaded().getFormId(), equalTo(ReferralSubForm.FORM_ID));
assertThat(exportModel.assertLoaded().getColumns(), hasSize(3));
TableColumn firstColumn = exportModel.assertLoaded().getColumns().get(0);
assertThat(firstColumn.getLabel(), equalTo(Optional.of("My PCODE")));
assertThat(firstColumn.getFormula(), equalTo(new CompoundExpr(new SymbolNode(ColumnModel.PARENT_SYMBOL), IncidentForm.PROTECTION_CODE_FIELD_ID).asExpression()));
}
use of org.activityinfo.model.analysis.TableColumn in project activityinfo by bedatadriven.
the class TableViewModel method updateColumnWidth.
@Override
public void updateColumnWidth(String columnId, int newWidth) {
TableModel model = this.tableModel.get();
List<TableColumn> updatedColumns = new ArrayList<>();
for (TableColumn column : model.getColumns()) {
if (column.getId().equals(columnId)) {
updatedColumns.add(ImmutableTableColumn.builder().from(column).width(newWidth).build());
} else {
updatedColumns.add(column);
}
}
tableModel.updateIfNotSame(ImmutableTableModel.builder().from(model).columns(updatedColumns).build());
}
Aggregations