Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Work in progress: moving download all files to gWT component
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Jan 2, 2013
1 parent 302bf04 commit 2ce8fd7
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 42 deletions.
Expand Up @@ -250,6 +250,11 @@ public static String getVersionFilesURL(WorkspaceId workspaceId)
return getModuleParentBaseUrl() + "iteration/files/" + workspaceId.getProjectIterationId().getProjectSlug() + "/" + workspaceId.getProjectIterationId().getIterationSlug() + "/" + workspaceId.getLocaleId().getId();
}

public static String getFileDownloadURL(WorkspaceId workspaceId, String docId)
{
return getModuleParentBaseUrl() + "rest/file/translation/" + workspaceId.getProjectIterationId().getProjectSlug() + "/" + workspaceId.getProjectIterationId().getIterationSlug() + "/" + workspaceId.getLocaleId().getId() + "/po?docId=" + docId;
}

public static native void redirectToUrl(String url)/*-{
$wnd.location = url;
}-*/;
Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.zanata.webtrans.client.events.DocumentSelectionEvent;
import org.zanata.webtrans.client.events.DocumentSelectionHandler;
import org.zanata.webtrans.client.events.DocumentStatsUpdatedEvent;
import org.zanata.webtrans.client.events.NotificationEvent;
import org.zanata.webtrans.client.events.ProjectStatsUpdatedEvent;
import org.zanata.webtrans.client.events.TransUnitUpdatedEvent;
import org.zanata.webtrans.client.events.TransUnitUpdatedEventHandler;
Expand All @@ -40,6 +41,7 @@
import org.zanata.webtrans.client.history.History;
import org.zanata.webtrans.client.history.HistoryToken;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.service.UserOptionsService;
import org.zanata.webtrans.client.ui.DocumentNode;
import org.zanata.webtrans.client.ui.HasStatsFilter;
Expand All @@ -48,9 +50,13 @@
import org.zanata.webtrans.shared.model.DocumentInfo;
import org.zanata.webtrans.shared.model.TransUnitUpdateInfo;
import org.zanata.webtrans.shared.model.UserWorkspaceContext;
import org.zanata.webtrans.shared.model.WorkspaceId;
import org.zanata.webtrans.shared.rpc.DownloadAllFilesAction;
import org.zanata.webtrans.shared.rpc.NoOpResult;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SingleSelectionModel;
Expand All @@ -67,6 +73,8 @@ public class DocumentListPresenter extends WidgetPresenter<DocumentListDisplay>

private ListDataProvider<DocumentNode> dataProvider;
private HashMap<DocumentId, DocumentNode> nodes;

private final CachingDispatchAsync dispatcher;

/**
* For quick lookup of document id by full path (including document name).
Expand Down Expand Up @@ -100,9 +108,10 @@ public void setSelected(DocumentNode object, boolean selected)
};

@Inject
public DocumentListPresenter(DocumentListDisplay display, EventBus eventBus, UserWorkspaceContext userworkspaceContext, final WebTransMessages messages, History history, UserOptionsService userOptionsService)
public DocumentListPresenter(DocumentListDisplay display, EventBus eventBus, CachingDispatchAsync dispatcher, UserWorkspaceContext userworkspaceContext, final WebTransMessages messages, History history, UserOptionsService userOptionsService)
{
super(display, eventBus);
this.dispatcher = dispatcher;
this.userworkspaceContext = userworkspaceContext;
this.messages = messages;
this.history = history;
Expand Down Expand Up @@ -375,4 +384,24 @@ public void onUserConfigChanged(UserConfigChangeEvent event)
display.updatePageSize(userOptionsService.getConfigHolder().getState().getDocumentListPageSize());
}
}

@Override
public void downloadAllFiles()
{
WorkspaceId workspaceId = userworkspaceContext.getWorkspaceContext().getWorkspaceId();
dispatcher.execute(new DownloadAllFilesAction(workspaceId.getProjectIterationId().getProjectSlug(), workspaceId.getProjectIterationId().getIterationSlug(), workspaceId.getLocaleId().getId()), new AsyncCallback<NoOpResult>()
{
@Override
public void onFailure(Throwable caught)
{
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Warning, "Unable generate all files to download"));
}

@Override
public void onSuccess(NoOpResult result)
{
eventBus.fireEvent(new NotificationEvent(NotificationEvent.Severity.Warning, "Loaded all files"));
}
});
}
}
Expand Up @@ -22,11 +22,12 @@

import java.util.Comparator;

import org.zanata.webtrans.client.Application;
import org.zanata.webtrans.client.resources.WebTransMessages;
import org.zanata.webtrans.client.ui.table.column.RemainingHoursColumn;
import org.zanata.webtrans.client.ui.table.column.StaticWidgetColumn;
import org.zanata.webtrans.client.ui.table.column.StatisticColumn;
import org.zanata.webtrans.client.ui.table.column.TranslatedColumn;
import org.zanata.webtrans.client.ui.table.column.UntranslatedColumn;
import org.zanata.webtrans.shared.model.WorkspaceId;

import com.google.gwt.cell.client.IconCellDecorator;
import com.google.gwt.cell.client.TextCell;
Expand All @@ -37,6 +38,7 @@
import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
import com.google.gwt.user.cellview.client.Header;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SingleSelectionModel;

Expand Down Expand Up @@ -86,12 +88,12 @@ public void setStatsFilter(String option)
private final StatisticColumn statisticColumn;
private final RemainingHoursColumn remainingColumn;

private final TextColumn<DocumentNode> lastModifiedDateColumn;
private final TextColumn<DocumentNode> lastModifiedByColumn;
private final TextColumn<DocumentNode> lastModifiedColumn;
private final StaticWidgetColumn<DocumentNode, Anchor> actionColumn;

private final StatisticHeader statisticColumnHeader;

public DocumentListTable(final org.zanata.webtrans.client.resources.Resources images, final WebTransMessages messages, final ListDataProvider<DocumentNode> dataProvider, final SingleSelectionModel<DocumentNode> selectionModel)
public DocumentListTable(final org.zanata.webtrans.client.resources.Resources images, final WebTransMessages messages, final ListDataProvider<DocumentNode> dataProvider, final SingleSelectionModel<DocumentNode> selectionModel, final WorkspaceId workspaceId)
{
super(15, (CellTableResources) GWT.create(CellTableResources.class));

Expand Down Expand Up @@ -119,34 +121,40 @@ public String getValue(DocumentNode object)
statisticColumn = new StatisticColumn(messages);
remainingColumn = new RemainingHoursColumn(messages);

lastModifiedDateColumn = new TextColumn<DocumentNode>()
lastModifiedColumn = new TextColumn<DocumentNode>()
{
@Override
public String getValue(DocumentNode object)
{
String date = "";
if(object.getDocInfo().getLastChanged() != null)
{
String date = DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_SHORT).format(object.getDocInfo().getLastChanged());
return date;
date = DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_SHORT).format(object.getDocInfo().getLastChanged());
}
return "";

String modifiedBy = object.getDocInfo().getLastModifiedBy();

return modifiedBy + " " + date;
}
};
lastModifiedByColumn = new TextColumn<DocumentNode>()

actionColumn = new StaticWidgetColumn<DocumentNode, Anchor>()
{
@Override
public String getValue(DocumentNode object)
public Anchor getValue(DocumentNode object)
{
return object.getDocInfo().getLastModifiedBy();
Anchor anchor = new Anchor(".po");
anchor.setHref(Application.getFileDownloadURL(workspaceId, object.getDocInfo().getName()));

return anchor;
}
};

directoryColumn.setSortable(true);
documentColumn.setSortable(true);
statisticColumn.setSortable(true);
remainingColumn.setSortable(true);
lastModifiedDateColumn.setSortable(true);
lastModifiedColumn.setSortable(true);


addColumn(directoryColumn, messages.columnHeaderDirectory());
Expand All @@ -163,11 +171,11 @@ public String getValue(DocumentNode object)
remainingColumn.setCellStyleNames("remainingCol");
addColumn(remainingColumn, messages.columnHeaderRemaining());

lastModifiedDateColumn.setCellStyleNames("lastModifiedDateCol");
addColumn(lastModifiedDateColumn, "Last Modified Date");
lastModifiedByColumn.setCellStyleNames("lastModifiedByCol");
addColumn(lastModifiedByColumn, "Last Modified By");
lastModifiedColumn.setCellStyleNames("lastModifiedCol");
addColumn(lastModifiedColumn, "Last Modified");

// actionColumn.setCellStyleNames("actionCol");
// addColumn(actionColumn, "Action");

addSorting(dataProvider);
}
Expand Down Expand Up @@ -224,6 +232,26 @@ public int compare(DocumentNode o1, DocumentNode o2)
return o1.getDocInfo().getStats().getRemainingHours() > o2.getDocInfo().getStats().getRemainingHours() ? 1 : -1;
}
});

columnSortHandler.setComparator(lastModifiedColumn, new Comparator<DocumentNode>()
{
public int compare(DocumentNode o1, DocumentNode o2)
{
if (o1.getDocInfo().getLastChanged() == o2.getDocInfo().getLastChanged())
{
return 0;
}
if (o1.getDocInfo().getLastChanged() == null)
{
return -1;
}
if (o2.getDocInfo().getLastChanged() == null)
{
return 1;
}
return o1.getDocInfo().getLastChanged().after(o2.getDocInfo().getLastChanged()) ? 1 : -1;
}
});
addColumnSortHandler(columnSortHandler);
getColumnSortList().push(directoryColumn);
}
Expand Down
Expand Up @@ -67,6 +67,8 @@ interface Listener
void fireFilterToken(String value);

void fireDocumentSelection(DocumentInfo doc);

void downloadAllFiles();
}

void setThemes(String style);
Expand Down
Expand Up @@ -28,8 +28,10 @@
import org.zanata.webtrans.client.ui.SearchField;
import org.zanata.webtrans.client.ui.table.DocumentListPager;
import org.zanata.webtrans.shared.model.DocumentInfo;
import org.zanata.webtrans.shared.model.UserWorkspaceContext;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
Expand All @@ -43,6 +45,7 @@
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.HasData;
Expand All @@ -68,21 +71,26 @@ public class DocumentListView extends Composite implements DocumentListDisplay,
@UiField
RadioButton statsByMsg, statsByWord;

@UiField
PushButton downloadAllFiles;

@UiField(provided = true)
DocumentListPager pager;

private DocumentListTable documentListTable;

private final Resources resources;
private final WebTransMessages messages;
private final UserWorkspaceContext userworkspaceContext;

private ListDataProvider<DocumentNode> dataProvider;

@Inject
public DocumentListView(Resources resources, WebTransMessages messages)
public DocumentListView(Resources resources, WebTransMessages messages, UserWorkspaceContext userworkspaceContext)
{
this.resources = resources;
this.messages = messages;
this.userworkspaceContext = userworkspaceContext;

dataProvider = new ListDataProvider<DocumentNode>();

Expand All @@ -92,6 +100,8 @@ public DocumentListView(Resources resources, WebTransMessages messages)

initWidget(uiBinder.createAndBindUi(this));

downloadAllFiles.setText("Download all files (zip)");

caseSensitiveCheckBox.setTitle(messages.docListFilterCaseSensitiveDescription());
exactSearchCheckBox.setTitle(messages.docListFilterExactMatchDescription());
statsByMsg.setText(messages.byMessage());
Expand Down Expand Up @@ -173,6 +183,12 @@ public void onStatsByWordChange(ValueChangeEvent<Boolean> event)
}
}

@UiHandler("downloadAllFiles")
public void onDownloadAllFilesClick(ClickEvent event)
{
listener.downloadAllFiles();
}

@Override
public void setStatsFilter(String option)
{
Expand Down Expand Up @@ -208,7 +224,7 @@ public void updateFilter(boolean docFilterCaseSensitive, boolean docFilterExact,
@Override
public void renderTable(SingleSelectionModel<DocumentNode> selectionModel)
{
documentListTable = new DocumentListTable(resources, messages, dataProvider, selectionModel);
documentListTable = new DocumentListTable(resources, messages, dataProvider, selectionModel, userworkspaceContext.getWorkspaceContext().getWorkspaceId());
dataProvider.addDataDisplay(documentListTable);

documentListContainer.clear();
Expand Down
Expand Up @@ -40,6 +40,15 @@
.listContainer
{
padding:10px;
margin-top:25px;
}

.downloadAllFiles
{
width:130px;
margin-top:5px;
position:absolute;
right:5px;
}

</ui:style>
Expand Down Expand Up @@ -67,12 +76,15 @@
</g:HorizontalPanel>
</g:layer>
<g:layer top='32px' bottom="0px">
<g:ScrollPanel styleName="{style.listContainer}">
<g:HTMLPanel width="100%">
<g:FlowPanel ui:field="documentListContainer"/>
<fui:table.DocumentListPager ui:field="pager"/>
</g:HTMLPanel>
</g:ScrollPanel>
<g:HTMLPanel>
<g:PushButton ui:field="downloadAllFiles" addStyleNames="{style.downloadAllFiles}"/>
<g:ScrollPanel styleName="{style.listContainer}">
<g:HTMLPanel width="100%">
<g:FlowPanel ui:field="documentListContainer"/>
<fui:table.DocumentListPager ui:field="pager"/>
</g:HTMLPanel>
</g:ScrollPanel>
</g:HTMLPanel>
</g:layer>
</g:LayoutPanel>
</g:layer>
Expand Down

0 comments on commit 2ce8fd7

Please sign in to comment.