Search in sources :

Example 1 with BaseListLoadResult

use of com.extjs.gxt.ui.client.data.BaseListLoadResult in project activityinfo by bedatadriven.

the class LocationTypeProxy method load.

@Override
public void load(DataReader<ListLoadResult<LocationTypeEntry>> reader, Object loadConfig, AsyncCallback<ListLoadResult<LocationTypeEntry>> callback) {
    dispatcher.execute(new GetSchema()).then(new Function<SchemaDTO, ListLoadResult<LocationTypeEntry>>() {

        @Override
        public ListLoadResult<LocationTypeEntry> apply(SchemaDTO schema) {
            // Build a dictionary of databases that have been shared with the user
            Map<Integer, String> databaseNames = new HashMap<>();
            for (UserDatabaseDTO db : schema.getDatabases()) {
                databaseNames.put(db.getId(), db.getName());
            }
            List<LocationTypeEntry> list = new ArrayList<>();
            for (LocationTypeDTO locationType : schema.getCountryById(countryId).getLocationTypes()) {
                if (!locationType.isDeleted()) {
                    if (locationType.getDatabaseId() == null) {
                        list.add(new LocationTypeEntry(locationType));
                    } else {
                        list.add(new LocationTypeEntry(locationType, databaseNames.get(locationType.getDatabaseId())));
                    }
                }
            }
            Collections.sort(list);
            return new BaseListLoadResult<>(list);
        }
    }).then(callback);
}
Also used : UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) LocationTypeDTO(org.activityinfo.legacy.shared.model.LocationTypeDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) Function(com.google.common.base.Function) GetSchema(org.activityinfo.legacy.shared.command.GetSchema)

Example 2 with BaseListLoadResult

use of com.extjs.gxt.ui.client.data.BaseListLoadResult in project activityinfo by bedatadriven.

the class DimensionProxy method load.

@Override
protected void load(Object loadConfig, final AsyncCallback<ListLoadResult<DimensionModel>> callback) {
    final List<DimensionModel> list = Lists.newArrayList();
    list.add(new DimensionModel(DimensionType.Indicator, I18N.CONSTANTS.indicator()));
    list.add(new DimensionModel(DimensionType.Partner, I18N.CONSTANTS.partner()));
    list.add(new DimensionModel(DimensionType.Project, I18N.CONSTANTS.project()));
    list.add(new DimensionModel(DimensionType.Target, I18N.CONSTANTS.realizedOrTargeted()));
    list.add(new DimensionModel(DateUnit.YEAR));
    list.add(new DimensionModel(DateUnit.QUARTER));
    list.add(new DimensionModel(DateUnit.MONTH));
    list.add(new DimensionModel(DateUnit.WEEK_MON));
    list.add(new DimensionModel(DimensionType.Location, I18N.CONSTANTS.location()));
    if (model.getIndicators().isEmpty()) {
        callback.onSuccess(new BaseListLoadResult<>(list));
    } else {
        Dimensions.loadDimensions(dispatcher, model).then(new Function<Dimensions, ListLoadResult<DimensionModel>>() {

            @Override
            public ListLoadResult<DimensionModel> apply(Dimensions input) {
                list.addAll(input.getAttributeDimensions());
                list.addAll(input.getAdminLevelDimensions());
                return new BaseListLoadResult<>(list);
            }
        }).then(callback);
    }
}
Also used : BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) Function(com.google.common.base.Function) DimensionModel(org.activityinfo.ui.client.component.report.editor.pivotTable.DimensionModel)

Aggregations

BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)2 Function (com.google.common.base.Function)2 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)1 LocationTypeDTO (org.activityinfo.legacy.shared.model.LocationTypeDTO)1 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)1 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)1 DimensionModel (org.activityinfo.ui.client.component.report.editor.pivotTable.DimensionModel)1