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

Commit

Permalink
Implement confirmation message when cancel version copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Aug 11, 2014
1 parent 01b9df8 commit e05ef92
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 30 deletions.
Expand Up @@ -16,13 +16,15 @@
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
@AutoCreate
@Name("copyVersionManager")
@Scope(ScopeType.STATELESS)
@Slf4j
public class CopyVersionManager implements Serializable {
@In
private AsyncTaskManagerService asyncTaskManagerServiceImpl;
Expand All @@ -44,6 +46,8 @@ public void cancelCopyVersion(String projectSlug, String versionSlug) {
handle.forceCancel();
handle.setCancelledTime(System.currentTimeMillis());
handle.setCancelledBy(identity.getCredentials().getUsername());

log.info("Copy version cancelled- {}:{}", projectSlug, versionSlug);
}
}

Expand Down
Expand Up @@ -302,14 +302,6 @@ public void onCopyVersionComplete() {
msgs.format("jsf.copyVersion.Completed", versionSlug));
}

/**
* Prevent getting cached data from hibernate that might be outdated,
* forced to get latest status from Database.
*/
public EntityStatus getStatus() {
return projectIterationDAO.getEntityStatus(projectSlug, versionSlug);
}

public void cancelCopyVersion() {
copyVersionManager.cancelCopyVersion(projectSlug, versionSlug);
conversationScopeMessages.setMessage(FacesMessage.SEVERITY_INFO,
Expand Down
12 changes: 0 additions & 12 deletions zanata-war/src/main/java/org/zanata/dao/ProjectIterationDAO.java
Expand Up @@ -76,18 +76,6 @@ public HProjectIteration getBySlug(@Nonnull String projectSlug,
return getBySlug(project, iterationSlug);
}

public EntityStatus getEntityStatus(@Nonnull String projectSlug,
@Nonnull String versionSlug) {
Query q =
getSession()
.createQuery(
"select v.status from HProjectIteration v where v.slug = :versionSlug and v.project.slug = :projectSlug");
q.setParameter("projectSlug", projectSlug);
q.setParameter("versionSlug", versionSlug);
q.setComment("ProjectDAO.getEntityStatus");
return (EntityStatus) q.uniqueResult();
}

@Nullable
public HProjectIteration getBySlug(@Nonnull HProject project,
@Nonnull String iterationSlug) {
Expand Down
1 change: 1 addition & 0 deletions zanata-war/src/main/resources/messages.properties
Expand Up @@ -355,6 +355,7 @@ jsf.copyVersion.label=Copy from previous version
jsf.copyVersion.processedDocuments=Processed document {0} of {1}
jsf.copyVersion.versionSettingsDisabled=Settings option is disabled temporarily due to copy version.
jsf.copyVersion.processedDocumentsAndPercent=Processed document {0} of {1} - {2}%
jsf.copyVersion.cancel.confirm=Are you sure you wish to stop this copy process? This may leave this version in read-only status.

This comment has been minimized.

Copy link
@carlosmunoz

carlosmunoz Aug 11, 2014

Member

Lets add a statement here letting the user know that they can change it manually.



#------ [home] > Projects > [project-id] > Manage Maintainers ------
Expand Down
Expand Up @@ -17,6 +17,13 @@
<a4j:param name="val1" assignTo="#{versionInfoId}"/>
</a4j:jsFunction>

<a4j:jsFunction name="cancelCopyVersion" limitRender="true"
action="#{projectHomeAction.cancelCopyVersion(projectSlug, versionSlug)}"
render="poll, version-info, messages">
<a4j:param name="val1" assignTo="#{projectSlug}"/>
<a4j:param name="val2" assignTo="#{versionSlug}"/>
</a4j:jsFunction>

<div class="panel">
<div class="panel__header">
<div class="panel__header__actions">
Expand Down Expand Up @@ -194,13 +201,14 @@
value="#{projectHomeAction.getCopyVersionCompletePercent(version.project.slug, version.slug)}"/>
</h:outputFormat>
</s:span>
<a4j:commandButton
styleClass="button--danger txt--mini l--push-left-half"
value="#{msgs['jsf.copyVersion.stop']}" limitRender="true"
rendered="#{s:hasPermission(projectHome.instance, 'update') and projectHomeAction.isVersionCopying(version.project.slug, version.slug)}"
action="#{projectHomeAction.cancelCopyVersion(version.project.slug, version.slug)}"
title="#{msgs['jsf.copyVersion.cancel.message']}"
render="poll, version-info, messages"/>
<s:fragment
rendered="#{s:hasPermission(projectHome.instance, 'update') and projectHomeAction.isVersionCopying(version.project.slug, version.slug)}">
<button class="button--danger txt--mini l--push-left-half"
title="#{msgs['jsf.copyVersion.cancel.message']}"
onclick="if(confirm('#{msgs['jsf.copyVersion.cancel.confirm']}')){cancelCopyVersion('#{version.project.slug}', '#{version.slug}');}return false;">
#{msgs['jsf.copyVersion.stop']}
</button>
</s:fragment>
</div>

<div class="list__item__stats">
Expand Down
6 changes: 3 additions & 3 deletions zanata-war/src/main/webapp/iteration/view.xhtml
Expand Up @@ -179,13 +179,13 @@
</p>

<s:div styleClass="l--push-bottom-half" id="version-info">
<s:fragment rendered="#{versionHomeAction.status eq 'ACTIVE'}">
<s:fragment rendered="#{versionHome.instance.status eq 'ACTIVE'}">
<h1 class="l--push-all-0">
<i class="i--small i--version txt--neutral i--left"></i>
#{versionHomeAction.versionSlug}
</h1>
</s:fragment>
<s:fragment rendered="#{versionHomeAction.status ne 'ACTIVE'}">
<s:fragment rendered="#{versionHome.instance.status ne 'ACTIVE'}">
<h1 class="l--push-all-0 txt--neutral">
<i class="i--small i--version txt--neutral i--left"></i>
#{versionHomeAction.versionSlug}
Expand Down Expand Up @@ -254,7 +254,7 @@
styleClass="panel__header__actions l--push-right-half l--push-bottom-0"
rendered="#{s:hasPermission(versionHomeAction.version, 'update')}">

<a href="javascript:void(0)" onclick="cancelCopyTrans()"
<a href="javascript:void(0)" onclick="if(confirm('#{msgs['jsf.copyVersion.cancel.confirm']}')) {cancelCopyTrans()};"

This comment has been minimized.

Copy link
@carlosmunoz

carlosmunoz Aug 11, 2014

Member

I would leave the if condition inside the cancelCopyTrans method, so we don't have this one line javascript conditional in here.

title="#{msgs['jsf.CopyTrans.cancel']}"
class="button--small button--link">#{msgs['jsf.Cancel']}</a>

Expand Down

1 comment on commit e05ef92

@carlosmunoz
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finished review for this commit.

Please sign in to comment.