Search in sources :

Example 1 with ReportVisibilityDTO

use of org.activityinfo.shared.dto.ReportVisibilityDTO in project activityinfo by bedatadriven.

the class ShareReportDialog method populateGrid.

private void populateGrid(SchemaDTO schema, ReportVisibilityResult visibility) {
    gridStore.removeAll();
    Set<Integer> indicators = currentReport.getIndicators();
    Map<Integer, ReportVisibilityDTO> databases = Maps.newHashMap();
    for (ReportVisibilityDTO model : visibility.getList()) {
        databases.put(model.getDatabaseId(), model);
    }
    for (UserDatabaseDTO db : schema.getDatabases()) {
        if (hasAny(db, indicators)) {
            if (databases.containsKey(db.getId())) {
                gridStore.add(databases.get(db.getId()));
            } else {
                ReportVisibilityDTO model = new ReportVisibilityDTO();
                model.setDatabaseId(db.getId());
                model.setDatabaseName(db.getName());
                gridStore.add(model);
            }
        }
    }
    if (gridStore.getCount() == 0) {
        MessageBox.alert(I18N.CONSTANTS.share(), "This report is still empty, so it can't yet be shared.", new Listener<MessageBoxEvent>() {

            @Override
            public void handleEvent(MessageBoxEvent be) {
                hide();
            }
        });
    }
}
Also used : ReportVisibilityDTO(org.activityinfo.shared.dto.ReportVisibilityDTO) MessageBoxEvent(com.extjs.gxt.ui.client.event.MessageBoxEvent) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO)

Example 2 with ReportVisibilityDTO

use of org.activityinfo.shared.dto.ReportVisibilityDTO in project activityinfo by bedatadriven.

the class ShareReportDialog method createColumnModel.

private ColumnModel createColumnModel() {
    ColumnConfig icon = new ColumnConfig("icon", "", 26);
    icon.setSortable(false);
    icon.setResizable(false);
    icon.setMenuDisabled(true);
    icon.setRenderer(new GridCellRenderer<ReportVisibilityDTO>() {

        @Override
        public Object render(ReportVisibilityDTO model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ReportVisibilityDTO> store, Grid<ReportVisibilityDTO> grid) {
            return IconImageBundle.ICONS.group().getHTML();
        }
    });
    ColumnConfig name = new ColumnConfig("databaseName", I18N.CONSTANTS.group(), 150);
    name.setRenderer(new GridCellRenderer<ReportVisibilityDTO>() {

        @Override
        public Object render(ReportVisibilityDTO model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ReportVisibilityDTO> store, Grid<ReportVisibilityDTO> grid) {
            return model.getDatabaseName() + " Users";
        }
    });
    visibleColumn = new CheckColumnConfig("visible", I18N.CONSTANTS.shared(), 75);
    visibleColumn.setDataIndex("visible");
    dashboardColumn = new CheckColumnConfig("defaultDashboard", I18N.CONSTANTS.defaultDashboard(), 75);
    dashboardColumn.setDataIndex("defaultDashboard");
    ColumnModel columnModel = new ColumnModel(Arrays.asList(icon, name, visibleColumn, dashboardColumn));
    return columnModel;
}
Also used : ReportVisibilityDTO(org.activityinfo.shared.dto.ReportVisibilityDTO) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) CheckColumnConfig(com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig) ColumnData(com.extjs.gxt.ui.client.widget.grid.ColumnData) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel) CheckColumnConfig(com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig)

Example 3 with ReportVisibilityDTO

use of org.activityinfo.shared.dto.ReportVisibilityDTO in project activityinfo by bedatadriven.

the class UpdateReportVisibilityHandler method execute.

@Override
public void execute(UpdateReportVisibility command, ExecutionContext context, AsyncCallback<VoidResult> callback) {
    SqlUpdate.delete(Tables.REPORT_VISIBILITY).where("reportid", command.getReportId()).execute(context.getTransaction());
    for (ReportVisibilityDTO dto : command.getList()) {
        SqlUpdate.delete(Tables.REPORT_VISIBILITY).where("reportid", command.getReportId()).where("databaseid", dto.getDatabaseId()).execute(context.getTransaction());
        if (dto.isVisible()) {
            SqlInsert.insertInto(Tables.REPORT_VISIBILITY).value("reportid", command.getReportId()).value("databaseid", dto.getDatabaseId()).value("defaultDashboard", dto.isDefaultDashboard()).execute(context.getTransaction());
        }
    }
    callback.onSuccess(null);
}
Also used : ReportVisibilityDTO(org.activityinfo.shared.dto.ReportVisibilityDTO)

Example 4 with ReportVisibilityDTO

use of org.activityinfo.shared.dto.ReportVisibilityDTO in project activityinfo by bedatadriven.

the class ReportVisibilityTest method update.

@Test
public void update() {
    setUser(1);
    ReportVisibilityDTO db1 = new ReportVisibilityDTO();
    db1.setDatabaseId(1);
    db1.setVisible(true);
    db1.setDefaultDashboard(true);
    ReportVisibilityDTO db2 = new ReportVisibilityDTO();
    db2.setDatabaseId(2);
    db2.setVisible(false);
    ReportVisibilityDTO db3 = new ReportVisibilityDTO();
    db3.setDatabaseId(3);
    db3.setVisible(true);
    UpdateReportVisibility update = new UpdateReportVisibility(1, Arrays.asList(db1, db2, db3));
    execute(update);
    ReportVisibilityResult result = execute(new GetReportVisibility(1));
    assertThat(result.getList().size(), equalTo(2));
    // make sure we can still see the report
    ReportsResult visibleToMe = execute(new GetReports());
    assertThat(visibleToMe.getData().size(), equalTo(1));
    // Bavon
    setUser(2);
    ReportsResult visibleToBavon = execute(new GetReports());
    assertThat(visibleToBavon.getData().size(), equalTo(2));
    assertThat(getById(visibleToBavon, 1).isDashboard(), equalTo(true));
    assertThat(getById(visibleToBavon, 2).isDashboard(), equalTo(false));
    // Stefan, no access to db
    setUser(3);
    ReportsResult visibleToStefan = execute(new GetReports());
    assertThat(visibleToStefan.getData().size(), equalTo(0));
}
Also used : ReportVisibilityDTO(org.activityinfo.shared.dto.ReportVisibilityDTO) ReportVisibilityResult(org.activityinfo.shared.command.result.ReportVisibilityResult) ReportsResult(org.activityinfo.shared.command.result.ReportsResult) Test(org.junit.Test)

Aggregations

ReportVisibilityDTO (org.activityinfo.shared.dto.ReportVisibilityDTO)4 MessageBoxEvent (com.extjs.gxt.ui.client.event.MessageBoxEvent)1 CheckColumnConfig (com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig)1 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)1 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)1 ColumnModel (com.extjs.gxt.ui.client.widget.grid.ColumnModel)1 ReportVisibilityResult (org.activityinfo.shared.command.result.ReportVisibilityResult)1 ReportsResult (org.activityinfo.shared.command.result.ReportsResult)1 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)1 Test (org.junit.Test)1