use of org.activityinfo.shared.dto.ReportMetadataDTO in project activityinfo by bedatadriven.
the class ReportGridPanel method showEmailDialog.
private void showEmailDialog() {
EmailDialog dialog = new EmailDialog(dispatcher);
final ReportMetadataDTO selected = grid.getSelectionModel().getSelectedItem();
dialog.show(selected, new EmailDialog.Callback() {
@Override
public void onUpdated() {
store.update(selected);
}
});
}
use of org.activityinfo.shared.dto.ReportMetadataDTO in project activityinfo by bedatadriven.
the class ReportGridPanel method delete.
private void delete() {
final ReportMetadataDTO report = grid.getSelectionModel().getSelectedItem();
MessageBox.confirm(I18N.CONSTANTS.delete(), I18N.MESSAGES.confirmDeleteReport(report.getTitle()), new Listener<MessageBoxEvent>() {
@Override
public void handleEvent(MessageBoxEvent be) {
if (be.getButtonClicked().getItemId().equals(Dialog.YES)) {
dispatcher.execute(new DeleteReport(report.getId()), new MaskingAsyncMonitor(ReportGridPanel.this, I18N.CONSTANTS.delete()), new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
// handled by monitor
}
@Override
public void onSuccess(VoidResult result) {
grid.getStore().remove(report);
}
});
}
}
});
}
use of org.activityinfo.shared.dto.ReportMetadataDTO in project activityinfo by bedatadriven.
the class ReportGridPanel method createColumnModel.
private ColumnModel createColumnModel() {
ColumnConfig dashboard = new ColumnConfig("dashboard", "", 28);
dashboard.setHeader(IconImageBundle.ICONS.star().getHTML());
dashboard.setResizable(false);
dashboard.setMenuDisabled(true);
dashboard.setRenderer(new GridCellRenderer<ReportMetadataDTO>() {
@Override
public Object render(ReportMetadataDTO model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ReportMetadataDTO> store, Grid<ReportMetadataDTO> grid) {
return "<div style='cursor:pointer'>" + (model.isDashboard() ? IconImageBundle.ICONS.star().getHTML() : IconImageBundle.ICONS.starWhite().getHTML()) + "</div>";
}
});
ColumnConfig title = new ColumnConfig("title", I18N.CONSTANTS.title(), 150);
ColumnConfig owner = new ColumnConfig("ownerName", I18N.CONSTANTS.ownerName(), 100);
owner.setRenderer(new GridCellRenderer<ReportMetadataDTO>() {
@Override
public Object render(ReportMetadataDTO model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ReportMetadataDTO> store, Grid<ReportMetadataDTO> grid) {
if (model.getAmOwner()) {
return "Me";
} else {
return model.getOwnerName();
}
}
});
ColumnConfig email = new ColumnConfig("email", I18N.CONSTANTS.emailSubscription(), 100);
email.setRenderer(new GridCellRenderer<ReportMetadataDTO>() {
@Override
public Object render(ReportMetadataDTO model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ReportMetadataDTO> store, Grid<ReportMetadataDTO> grid) {
switch(model.getEmailDelivery()) {
case NONE:
return "<i>" + I18N.CONSTANTS.none() + "</i>";
case MONTHLY:
return I18N.CONSTANTS.monthly();
case WEEKLY:
default:
return I18N.CONSTANTS.weekly();
}
}
});
return new ColumnModel(Arrays.asList(dashboard, title, owner, email));
}
use of org.activityinfo.shared.dto.ReportMetadataDTO in project activityinfo by bedatadriven.
the class GetReportModelHandler method loadMetadata.
private void loadMetadata(final Integer reportId, final ExecutionContext context, final ReportDTO reportDTO, final AsyncCallback<ReportDTO> callback) {
final int userId = context.getUser().getId();
SqlQuery mySubscriptions = SqlQuery.selectAll().from("reportsubscription").where("userId").equalTo(userId);
SqlQuery myDatabases = SqlQuery.selectSingle("d.databaseid").from("userdatabase", "d").leftJoin(SqlQuery.selectAll().from(Tables.USER_PERMISSION, "UserPermission").where("UserPermission.UserId").equalTo(userId), "p").on("p.DatabaseId = d.DatabaseId").where("d.ownerUserId").equalTo(userId).or("p.AllowView").equalTo(1);
SqlQuery.select().appendColumn("r.reportTemplateId", "reportId").appendColumn("r.title", "title").appendColumn("r.ownerUserId", "ownerUserId").appendColumn("o.name", "ownerName").appendColumn("s.dashboard", "dashboard").appendColumn("s.emaildelivery", "emaildelivery").appendColumn("s.emailday", "emailday").appendColumn(SqlQuery.selectSingle("max(defaultDashboard)").from("reportvisibility", "v").where("v.databaseId").in(myDatabases).whereTrue("v.reportid = r.reportTemplateId"), "defaultDashboard").from("reporttemplate", "r").leftJoin("userlogin o").on("o.userid = r.ownerUserId").leftJoin(mySubscriptions, "s").on("r.reportTemplateId = s.reportId").where("r.ownerUserId").equalTo(userId).where("r.reportTemplateId").equalTo(reportId).execute(context.getTransaction(), new SqlResultCallback() {
@Override
public void onSuccess(final SqlTransaction tx, final SqlResultSet results) {
List<ReportMetadataDTO> dtos = Lists.newArrayList();
for (SqlResultSetRow row : results.getRows()) {
ReportMetadataDTO dto = new ReportMetadataDTO();
dto.setId(row.getInt("reportId"));
dto.setAmOwner(row.getInt("ownerUserId") == userId);
dto.setOwnerName(row.getString("ownerName"));
dto.setTitle(row.getString("title"));
dto.setEditAllowed(dto.getAmOwner());
if (!row.isNull("emaildelivery")) {
dto.setEmailDelivery(EmailDelivery.valueOf(row.getString("emaildelivery")));
}
if (row.isNull("emailday")) {
dto.setDay(1);
} else {
dto.setDay(row.getInt("emailday"));
}
if (row.isNull("dashboard")) {
// inherited from database-wide visibility
dto.setDashboard(!row.isNull("defaultDashboard") && row.getBoolean("defaultDashboard"));
} else {
dto.setDashboard(row.getBoolean("dashboard"));
}
dtos.add(dto);
}
if (dtos.size() == 0) {
ReportMetadataDTO dummy = new ReportMetadataDTO();
dummy.setId(reportId);
dtos.add(dummy);
}
// there should be only one result
reportDTO.setReportMetadataDTO(dtos.get(0));
// exit handler with both the report and metadata objects
// filled
callback.onSuccess(reportDTO);
}
});
}
use of org.activityinfo.shared.dto.ReportMetadataDTO in project activityinfo by bedatadriven.
the class GetReportsHandler method execute.
@Override
public void execute(final GetReports command, final ExecutionContext context, final AsyncCallback<ReportsResult> callback) {
// note that we are excluding reports with a null title-- these
// reports have not yet been explicitly saved by the user
SqlQuery mySubscriptions = SqlQuery.selectAll().from(Tables.REPORT_SUBSCRIPTION).where("userId").equalTo(context.getUser().getUserId());
SqlQuery myDatabases = SqlQuery.selectSingle("d.databaseid").from(Tables.USER_DATABASE, "d").leftJoin(SqlQuery.selectAll().from(Tables.USER_PERMISSION).where("userpermission.UserId").equalTo(context.getUser().getId()), "p").on("p.DatabaseId = d.DatabaseId").where("d.ownerUserId").equalTo(context.getUser().getUserId()).or("p.AllowView").equalTo(1);
SqlQuery.select().appendColumn("r.reportTemplateId", "reportId").appendColumn("r.title", "title").appendColumn("r.ownerUserId", "ownerUserId").appendColumn("o.name", "ownerName").appendColumn("s.dashboard", "dashboard").appendColumn("s.emaildelivery", "emaildelivery").appendColumn("s.emailday", "emailday").appendColumn(SqlQuery.selectSingle("max(defaultDashboard)").from(Tables.REPORT_VISIBILITY, "v").where("v.databaseId").in(myDatabases).whereTrue("v.reportid=r.reportTemplateId"), "defaultDashboard").from(Tables.REPORT_TEMPLATE, "r").leftJoin(Tables.USER_LOGIN, "o").on("o.userid=r.ownerUserId").leftJoin(mySubscriptions, "s").on("r.reportTemplateId=s.reportId").whereTrue("r.title is not null").where("r.ownerUserId").equalTo(context.getUser().getId()).or("r.reportTemplateId").in(SqlQuery.select("reportId").from(Tables.REPORT_VISIBILITY, "v").where("v.databaseid").in(myDatabases)).execute(context.getTransaction(), new SqlResultCallback() {
@Override
public void onSuccess(final SqlTransaction tx, final SqlResultSet results) {
List<ReportMetadataDTO> dtos = Lists.newArrayList();
for (SqlResultSetRow row : results.getRows()) {
ReportMetadataDTO dto = new ReportMetadataDTO();
dto.setId(row.getInt("reportId"));
dto.setAmOwner(row.getInt("ownerUserId") == context.getUser().getId());
dto.setOwnerName(row.getString("ownerName"));
dto.setTitle(row.getString("title"));
dto.setEditAllowed(dto.getAmOwner());
if (!row.isNull("emaildelivery")) {
dto.setEmailDelivery(EmailDelivery.valueOf(row.getString("emaildelivery")));
}
if (row.isNull("emailday")) {
dto.setDay(1);
} else {
dto.setDay(row.getInt("emailday"));
}
if (row.isNull("dashboard")) {
// inherited from database-wide visibility
dto.setDashboard(!row.isNull("defaultDashboard") && row.getBoolean("defaultDashboard"));
} else {
dto.setDashboard(row.getBoolean("dashboard"));
}
dtos.add(dto);
}
callback.onSuccess(new ReportsResult(dtos));
}
});
}
Aggregations