Join with the users table to display who made each history entry

pull/14/head
Sam Bosley 13 years ago
parent 31507eee84
commit b4e6408de2

@ -64,16 +64,11 @@ public class TaskCommentsFragment extends CommentsFragment {
@Override
protected Cursor getCursor() {
Query taskQuery = queryForTask(task, UpdateAdapter.USER_TABLE_ALIAS, UpdateAdapter.USER_ACTIVITY_PROPERTIES, UpdateAdapter.USER_PROPERTIES);
int length = UpdateAdapter.USER_ACTIVITY_PROPERTIES.length + UpdateAdapter.USER_PROPERTIES.length;
Property<?>[] paddingArray = new Property<?>[Math.max(0, length - UpdateAdapter.HISTORY_PROPERTIES.length)];
for (int i = 0; i < paddingArray.length; i++) {
paddingArray[i] = UpdateAdapter.PADDING_PROPERTY;
}
Query historyQuery = Query.select(AndroidUtilities.addToArray(UpdateAdapter.HISTORY_PROPERTIES, paddingArray)).from(History.TABLE)
Query historyQuery = Query.select(AndroidUtilities.addToArray(UpdateAdapter.HISTORY_PROPERTIES, UpdateAdapter.USER_PROPERTIES)).from(History.TABLE)
.where(Criterion.and(History.TABLE_ID.eq(NameMaps.TABLE_ID_TASKS), History.TARGET_ID.eq(task.getUuid())))
.from(History.TABLE);
.from(History.TABLE)
.join(Join.left(User.TABLE.as(UpdateAdapter.USER_TABLE_ALIAS), History.USER_UUID.eq(Field.field(UpdateAdapter.USER_TABLE_ALIAS + "." + User.UUID.name)))); //$NON-NLS-1$;
Query resultQuery = taskQuery.union(historyQuery).orderBy(Order.desc("1")); //$NON-NLS-1$

@ -206,10 +206,10 @@ public class UpdateAdapter extends CursorAdapter {
History history = mh.history;
if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(type)) {
readUserActivityProperties(cursor, update);
readUserProperties(cursor, user);
} else {
readHistoryProperties(cursor, history);
}
readUserProperties(cursor, user);
setFieldContentsAndVisibility(view, update, user, history, type);
}
@ -247,7 +247,7 @@ public class UpdateAdapter extends CursorAdapter {
if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(type)) {
setupUserActivityRow(view, activity, user);
} else if (NameMaps.TABLE_ID_HISTORY.equals(type)) {
setupHistoryRow(view, history);
setupHistoryRow(view, history, user);
}
}
@ -286,7 +286,7 @@ public class UpdateAdapter extends CursorAdapter {
}
}
private void setupHistoryRow(View view, History history) {
private void setupHistoryRow(View view, History history, User user) {
final AsyncImageView pictureView = (AsyncImageView)view.findViewById(R.id.picture);
pictureView.setVisibility(View.GONE);
@ -294,7 +294,7 @@ public class UpdateAdapter extends CursorAdapter {
commentPictureView.setVisibility(View.GONE);
final TextView nameView = (TextView)view.findViewById(R.id.title); {
nameView.setText(getHistoryComment((AstridActivity) fragment.getActivity(), history, linkColor, fromView));
nameView.setText(getHistoryComment((AstridActivity) fragment.getActivity(), history, user, linkColor, fromView));
}
final TextView date = (TextView)view.findViewById(R.id.date); {
@ -430,7 +430,7 @@ public class UpdateAdapter extends CursorAdapter {
}
@SuppressWarnings("nls")
public static String getHistoryComment(final AstridActivity context, History history, String linkColor, String fromView) {
public static String getHistoryComment(final AstridActivity context, History history, User user, String linkColor, String fromView) {
boolean hasTask = false;
JSONArray taskAttrs = null;
if (!TextUtils.isEmpty(history.getValue(History.TASK))) {
@ -599,7 +599,16 @@ public class UpdateAdapter extends CursorAdapter {
if (TextUtils.isEmpty(result))
result = context.getString(R.string.history_default, column, newValue);
return result;
String userDisplay;
if (history.getValue(History.USER_UUID).equals(Task.USER_ID_SELF) || history.getValue(History.USER_UUID).equals(ActFmPreferenceService.userId())) {
userDisplay = context.getString(R.string.update_string_user_self);
} else if (user == null) {
userDisplay = context.getString(R.string.ENA_no_user);
} else {
userDisplay = user.getDisplayName(USER_NAME, USER_FIRST_NAME, USER_LAST_NAME);
}
return userDisplay + " " + result;
}
private static String dateString(Context context, String value, String other) {

@ -172,20 +172,12 @@ public class TagDataService {
public Cursor getActivityAndHistoryForTagData(TagData tagData, Criterion extraCriterion, String userTableAlias, Property<?>...userProperties) {
Query activityQuery = queryForTagData(tagData, extraCriterion, userTableAlias, UpdateAdapter.USER_ACTIVITY_PROPERTIES, userProperties)
.from(UserActivity.TABLE);
int length = UpdateAdapter.USER_ACTIVITY_PROPERTIES.length;
if (userProperties != null)
length += userProperties.length;
Property<?>[] paddingArray = new Property<?>[Math.max(0, length - UpdateAdapter.HISTORY_PROPERTIES.length)];
for (int i = 0; i < paddingArray.length; i++) {
paddingArray[i] = UpdateAdapter.PADDING_PROPERTY;
}
Query historyQuery = Query.select(AndroidUtilities.addToArray(UpdateAdapter.HISTORY_PROPERTIES, paddingArray)).from(History.TABLE)
Query historyQuery = Query.select(AndroidUtilities.addToArray(UpdateAdapter.HISTORY_PROPERTIES, userProperties)).from(History.TABLE)
.where(Criterion.or(Criterion.and(History.TABLE_ID.eq(NameMaps.TABLE_ID_TAGS), History.TARGET_ID.eq(tagData.getUuid())),
Criterion.and(History.TABLE_ID.eq(NameMaps.TABLE_ID_TASKS), History.TARGET_ID.in(Query.select(TaskToTagMetadata.TASK_UUID)
.from(Metadata.TABLE).where(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY), TaskToTagMetadata.TAG_UUID.eq(tagData.getUuid())))))))
.from(History.TABLE);
.join(Join.left(User.TABLE.as(userTableAlias), History.USER_UUID.eq(Field.field(userTableAlias + "." + User.UUID.name)))); //$NON-NLS-1$
Query resultQuery = activityQuery.union(historyQuery).orderBy(Order.desc("1")); //$NON-NLS-1$

Loading…
Cancel
Save