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

Commit

Permalink
Merge pull request #60 from zanata/force-reject-comment
Browse files Browse the repository at this point in the history
rhbz982916 - force comment on reject
  • Loading branch information
davidmason committed Jul 23, 2013
2 parents 8158398 + 5f2aabe commit 9067f4a
Show file tree
Hide file tree
Showing 23 changed files with 620 additions and 58 deletions.
Expand Up @@ -40,6 +40,7 @@
import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.Type;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.hibernate.validator.constraints.NotEmpty;
import org.zanata.common.ContentState;

import lombok.AccessLevel;
Expand Down Expand Up @@ -73,7 +74,7 @@ public class HTextFlowTargetReviewComment extends ModelEntityBase
@Getter
private HTextFlowTarget textFlowTarget;

@NotNull
@NotEmpty
@Type(type = "text")
@Getter
private String comment;
Expand Down
@@ -0,0 +1,51 @@
/*
* Copyright 2013, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/

package org.zanata.webtrans.client.events;

import com.google.gwt.event.shared.GwtEvent;

public class CommentBeforeSaveEvent extends GwtEvent<CommentBeforeSaveEventHandler>
{
public static Type<CommentBeforeSaveEventHandler> TYPE = new Type<CommentBeforeSaveEventHandler>();

private final TransUnitSaveEvent saveEvent;

public CommentBeforeSaveEvent(TransUnitSaveEvent saveEvent)
{
this.saveEvent = saveEvent;
}

public TransUnitSaveEvent getSaveEvent()
{
return saveEvent;
}

public Type<CommentBeforeSaveEventHandler> getAssociatedType()
{
return TYPE;
}

protected void dispatch(CommentBeforeSaveEventHandler handler)
{
handler.onCommentBeforeSave(this);
}
}
@@ -0,0 +1,29 @@
/*
* Copyright 2013, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/

package org.zanata.webtrans.client.events;

import com.google.gwt.event.shared.EventHandler;

public interface CommentBeforeSaveEventHandler extends EventHandler
{
void onCommentBeforeSave(CommentBeforeSaveEvent event);
}
Expand Up @@ -45,6 +45,7 @@
import org.zanata.webtrans.client.presenter.DocumentListOptionsPresenter;
import org.zanata.webtrans.client.presenter.DocumentListPresenter;
import org.zanata.webtrans.client.presenter.EditorOptionsPresenter;
import org.zanata.webtrans.client.presenter.ForceReviewCommentPresenter;
import org.zanata.webtrans.client.presenter.GlossaryDetailsPresenter;
import org.zanata.webtrans.client.presenter.GlossaryPresenter;
import org.zanata.webtrans.client.presenter.KeyShortcutPresenter;
Expand Down Expand Up @@ -164,6 +165,7 @@ protected void configure()
bindPresenter(NotificationPresenter.class, NotificationDisplay.class, NotificationView.class);
bindPresenter(TransUnitsTablePresenter.class, TransUnitsTableDisplay.class, TransUnitsTableView.class);
bindPresenter(SideMenuPresenter.class, SideMenuDisplay.class, SideMenuView.class);
bind(ForceReviewCommentPresenter.class).asEagerSingleton();

bind(SourceContentsPresenter.class).in(Singleton.class);
bind(TargetContentsDisplay.class).to(TargetContentsView.class);
Expand Down
@@ -0,0 +1,102 @@
/*
* Copyright 2013, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/

package org.zanata.webtrans.client.presenter;

import org.zanata.webtrans.client.events.CommentBeforeSaveEvent;
import org.zanata.webtrans.client.events.CommentBeforeSaveEventHandler;
import org.zanata.webtrans.client.events.NavTransUnitEvent;
import org.zanata.webtrans.client.events.TransUnitSaveEvent;
import org.zanata.webtrans.client.rpc.AbstractAsyncCallback;
import org.zanata.webtrans.client.rpc.CachingDispatchAsync;
import org.zanata.webtrans.client.service.GetTransUnitActionContextHolder;
import org.zanata.webtrans.client.view.ForceReviewCommentDisplay;
import org.zanata.webtrans.shared.rpc.AddReviewCommentAction;
import org.zanata.webtrans.shared.rpc.AddReviewCommentResult;
import com.google.inject.Inject;

import net.customware.gwt.presenter.client.EventBus;
import net.customware.gwt.presenter.client.widget.WidgetPresenter;

/**
* @author Patrick Huang <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
public class ForceReviewCommentPresenter extends WidgetPresenter<ForceReviewCommentDisplay>
implements ForceReviewCommentDisplay.Listener, CommentBeforeSaveEventHandler
{

private final CachingDispatchAsync dispatcher;
private final GetTransUnitActionContextHolder contextHolder;

private TransUnitSaveEvent saveEvent;

@Inject
public ForceReviewCommentPresenter(ForceReviewCommentDisplay display, EventBus eventBus, CachingDispatchAsync dispatcher, GetTransUnitActionContextHolder contextHolder)
{
super(display, eventBus);
this.dispatcher = dispatcher;
this.contextHolder = contextHolder;
display.setListener(this);

eventBus.addHandler(CommentBeforeSaveEvent.TYPE, this);
}

@Override
public void onCommentBeforeSave(CommentBeforeSaveEvent event)
{
saveEvent = event.getSaveEvent();
display.center();
}

@Override
public void addComment(String content)
{
dispatcher.execute(new AddReviewCommentAction(saveEvent.getTransUnitId(), content,
contextHolder.getContext().getDocument().getId()), new AbstractAsyncCallback<AddReviewCommentResult>()
{
@Override
public void onSuccess(AddReviewCommentResult result)
{
display.clearInput();
eventBus.fireEvent(saveEvent);
eventBus.fireEvent(NavTransUnitEvent.NEXT_ENTRY_EVENT);
saveEvent = null;
display.hide();
}
});

}

@Override
protected void onBind()
{
}

@Override
protected void onUnbind()
{
}

@Override
protected void onRevealDisplay()
{
}
}
Expand Up @@ -31,6 +31,7 @@

import org.zanata.common.ContentState;
import org.zanata.webtrans.client.events.CheckStateHasChangedEvent;
import org.zanata.webtrans.client.events.CommentBeforeSaveEvent;
import org.zanata.webtrans.client.events.CopyDataToEditorEvent;
import org.zanata.webtrans.client.events.CopyDataToEditorHandler;
import org.zanata.webtrans.client.events.InsertStringInEditorEvent;
Expand Down Expand Up @@ -689,7 +690,11 @@ public void acceptTranslation(TransUnitId id)
public void rejectTranslation(TransUnitId id)
{
ensureRowSelection(id);
saveCurrent(ContentState.Rejected);
if (display.getCachedState() != ContentState.Rejected)
{
TransUnitSaveEvent event = new TransUnitSaveEvent(getNewTargets(), ContentState.Rejected, display.getId(), display.getVerNum(), display.getCachedTargets());
eventBus.fireEvent(new CommentBeforeSaveEvent(event));
}
}


Expand Down
Expand Up @@ -279,6 +279,12 @@ public void refreshRow(TransUnit updatedTransUnit, EditorClientId editorClientId
// Ignored.
return;
}
if (updateType == TransUnitUpdated.UpdateType.AddComment)
{
targetContentsPresenter.updateCommentCount(updatedTransUnit.getId(), updatedTransUnit.getCommentsCount());
return;
}

if (Objects.equal(selectedId, updatedTransUnit.getId()) && !Objects.equal(editorClientId, translatorService.getCurrentEditorClientId()))
{
// updatedTU is our active row but done by another user
Expand All @@ -290,14 +296,7 @@ public void refreshRow(TransUnit updatedTransUnit, EditorClientId editorClientId
translationHistoryPresenter.displayEntries(latest, Collections.<TransHistoryItem> emptyList(), Collections.<ReviewComment>emptyList());
}
}
if (updateType == TransUnitUpdated.UpdateType.AddComment)
{
targetContentsPresenter.updateCommentCount(updatedTransUnit.getId(), updatedTransUnit.getCommentsCount());
}
else
{
targetContentsPresenter.updateRow(updatedTransUnit);
}
targetContentsPresenter.updateRow(updatedTransUnit);
}

// update type is web editor save or web editor save fuzzy and coming from
Expand Down
Expand Up @@ -59,6 +59,7 @@ public TranslationHistoryPresenter(TranslationHistoryDisplay display, EventBus e
this.contextHolder = contextHolder;

display.setListener(this);
eventBus.addHandler(ReviewCommentEvent.TYPE, this);
}

@Override
Expand Down
Expand Up @@ -553,4 +553,10 @@ public interface WebTransMessages extends Messages

@DefaultMessage("Remove from comparison")
String removeFromComparison();

@DefaultMessage("Why is this translation rejected?")
String rejectCommentTitle();

@DefaultMessage("Confirm rejection")
String confirmRejection();
}
@@ -0,0 +1,83 @@
/*
* Copyright 2013, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/

package org.zanata.webtrans.client.ui;

import org.zanata.webtrans.client.view.ForceReviewCommentDisplay;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.TextArea;

public class ReviewCommentInputWidget extends Composite
{
private static ReviewCommentInputWidgetUiBinder ourUiBinder = GWT.create(ReviewCommentInputWidgetUiBinder.class);
@UiField
TextArea commentTextArea;
@UiField
Button addCommentButton;
private ForceReviewCommentDisplay.Listener listener;

public ReviewCommentInputWidget()
{
initWidget(ourUiBinder.createAndBindUi(this));
commentTextArea.getElement().setAttribute("placeholder", "Add a comment...");
}

@UiHandler("addCommentButton")
public void onAddCommentButtonClick(ClickEvent event)
{
if (!commentTextArea.getValue().trim().isEmpty())
{
listener.addComment(commentTextArea.getText());
}
}

public void setListener(ForceReviewCommentDisplay.Listener listener)
{
this.listener = listener;
}

public void setEnabled(boolean enabled)
{
commentTextArea.setEnabled(enabled);
addCommentButton.setEnabled(enabled);
}

public void clearInput()
{
commentTextArea.setValue("");
}

public void setButtonText(String buttonText)
{
addCommentButton.setText(buttonText);
}

interface ReviewCommentInputWidgetUiBinder extends UiBinder<HTMLPanel, ReviewCommentInputWidget>
{
}
}

0 comments on commit 9067f4a

Please sign in to comment.