Search in sources :

Example 1 with SchemaDTO

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

the class ConfigLoader method load.

@Override
public void load(final PageId pageId, final PageState place, final AsyncCallback<Page> callback) {
    GWT.runAsync(new RunAsyncCallback() {

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }

        @Override
        public void onSuccess() {
            final Page page = pageProviders.get(pageId).get();
            if (page == null) {
                callback.onFailure(new Exception("ConfigLoader didn't know how to handle " + place.toString()));
            } else if (page instanceof DbPage) {
                dispatch.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        callback.onFailure(caught);
                    }

                    @Override
                    public void onSuccess(SchemaDTO result) {
                        DbPageState dbPlace = (DbPageState) place;
                        ((DbPage) page).go(result.getDatabaseById(dbPlace.getDatabaseId()));
                        callback.onSuccess(page);
                    }
                });
            } else {
                page.navigate(place);
                callback.onSuccess(page);
            }
        }
    });
}
Also used : RunAsyncCallback(com.google.gwt.core.client.RunAsyncCallback) IndicatorLinkPage(org.activityinfo.client.page.config.link.IndicatorLinkPage) Page(org.activityinfo.client.page.Page) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Example 2 with SchemaDTO

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

the class DetailTab method setSite.

public void setSite(final SiteDTO site) {
    content.setHtml(I18N.CONSTANTS.loading());
    dispatcher.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

        @Override
        public void onFailure(Throwable caught) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onSuccess(SchemaDTO result) {
            render(result, site);
        }
    });
}
Also used : GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Example 3 with SchemaDTO

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

the class PrintDataEntryForm method print.

public void print(final int activityId) {
    setVisible(true);
    dispatcher.execute(new GetSchema(), new MaskingAsyncMonitor(this, I18N.CONSTANTS.loading()), new AsyncCallback<SchemaDTO>() {

        @Override
        public void onFailure(Throwable caught) {
            showError(caught);
        }

        @Override
        public void onSuccess(SchemaDTO result) {
            renderForm(activityId, result);
        }
    });
}
Also used : MaskingAsyncMonitor(org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Example 4 with SchemaDTO

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

the class ItemDetail method create.

static ItemDetail create(RenderContext ctx, Map.Entry<String, Object> entry) {
    ItemDetail d = new ItemDetail();
    Map<String, Object> state = ctx.getState();
    SchemaDTO schema = ctx.getSchema();
    String key = entry.getKey();
    final Object oldValue = state.get(key);
    final Object newValue = entry.getValue();
    state.put(key, newValue);
    final StringBuilder sb = new StringBuilder();
    // basic
    if (key.equals("date1")) {
        addValues(sb, I18N.CONSTANTS.startDate(), oldValue, newValue);
    } else if (key.equals("date2")) {
        addValues(sb, I18N.CONSTANTS.endDate(), oldValue, newValue);
    } else if (key.equals("comments")) {
        addValues(sb, I18N.CONSTANTS.comments(), oldValue, newValue);
    } else if (key.equals("locationId")) {
        // schema loookups
        String oldName = null;
        if (oldValue != null) {
            oldName = ctx.getLocation(toInt(oldValue)).getName();
        }
        String newName = ctx.getLocation(toInt(newValue)).getName();
        addValues(sb, I18N.CONSTANTS.location(), oldName, newName);
    } else if (key.equals("projectId")) {
        String oldName = null;
        if (oldValue != null) {
            oldName = schema.getProjectById(toInt(oldValue)).getName();
        }
        String newName = schema.getProjectById(toInt(newValue)).getName();
        addValues(sb, I18N.CONSTANTS.project(), oldName, newName);
    } else if (key.equals("partnerId")) {
        String oldName = null;
        if (oldValue != null) {
            oldName = schema.getPartnerById(toInt(oldValue)).getName();
        }
        String newName = schema.getPartnerById(toInt(newValue)).getName();
        addValues(sb, I18N.CONSTANTS.partner(), oldName, newName);
    } else if (key.startsWith(IndicatorDTO.PROPERTY_PREFIX)) {
        // custom
        int id = IndicatorDTO.indicatorIdForPropertyName(key);
        IndicatorDTO dto = schema.getIndicatorById(id);
        String name = dto.getName();
        Month m = IndicatorDTO.monthForPropertyName(key);
        if (m != null) {
            name = I18N.MESSAGES.siteHistoryIndicatorName(name, m.toLocalDate().atMidnightInMyTimezone());
        }
        addValues(sb, name, oldValue, newValue, dto.getUnits());
    } else if (key.startsWith(AttributeDTO.PROPERTY_PREFIX)) {
        int id = AttributeDTO.idForPropertyName(key);
        AttributeDTO dto = schema.getAttributeById(id);
        if (Boolean.parseBoolean(newValue.toString())) {
            sb.append(I18N.MESSAGES.siteHistoryAttrAdd(dto.getName()));
        } else {
            sb.append(I18N.MESSAGES.siteHistoryAttrRemove(dto.getName()));
        }
    } else {
        // fallback
        addValues(sb, key, oldValue, newValue);
    }
    d.stringValue = sb.toString();
    return d;
}
Also used : AttributeDTO(org.activityinfo.shared.dto.AttributeDTO) Month(org.activityinfo.shared.command.Month) IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Example 5 with SchemaDTO

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

the class ShareReportDialog method show.

public void show(ReportMetadataDTO metadata) {
    super.show();
    BatchCommand batch = new BatchCommand();
    batch.add(new GetReportModel(metadata.getId()));
    batch.add(new GetSchema());
    batch.add(new GetReportVisibility(metadata.getId()));
    dispatcher.execute(batch, new MaskingAsyncMonitor(grid, I18N.CONSTANTS.loading()), new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onSuccess(BatchResult batch) {
            currentReport = ((ReportDTO) batch.getResult(0)).getReport();
            populateGrid((SchemaDTO) batch.getResult(1), (ReportVisibilityResult) batch.getResult(2));
        }
    });
}
Also used : ReportVisibilityResult(org.activityinfo.shared.command.result.ReportVisibilityResult) GetReportVisibility(org.activityinfo.shared.command.GetReportVisibility) GetReportModel(org.activityinfo.shared.command.GetReportModel) MaskingAsyncMonitor(org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor) ReportDTO(org.activityinfo.shared.dto.ReportDTO) BatchCommand(org.activityinfo.shared.command.BatchCommand) BatchResult(org.activityinfo.shared.command.result.BatchResult) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Aggregations

SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)66 GetSchema (org.activityinfo.shared.command.GetSchema)56 Test (org.junit.Test)41 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)20 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)10 CreateResult (org.activityinfo.shared.command.result.CreateResult)9 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)8 MockEventBus (org.activityinfo.client.MockEventBus)6 HashMap (java.util.HashMap)5 DispatcherStub (org.activityinfo.client.dispatch.DispatcherStub)5 UIConstants (org.activityinfo.client.i18n.UIConstants)5 StateManagerStub (org.activityinfo.client.mock.StateManagerStub)5 OnDataSet (org.activityinfo.server.database.OnDataSet)5 Delete (org.activityinfo.shared.command.Delete)5 Filter (org.activityinfo.shared.command.Filter)5 UpdateEntity (org.activityinfo.shared.command.UpdateEntity)5 AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)5 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)4 CreateEntity (org.activityinfo.shared.command.CreateEntity)4 VoidResult (org.activityinfo.shared.command.result.VoidResult)4