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

Commit

Permalink
fix(glossary details): update glossary link in details page (#1308)
Browse files Browse the repository at this point in the history
* fix(glossary details): update glossary link in details page

https://zanata.atlassian.net/browse/ZNTA-1406

* feat(glossary): encode filter for glossary url
  • Loading branch information
Alex Eng committed Oct 4, 2016
1 parent 0576789 commit 104122f
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 8 deletions.
15 changes: 11 additions & 4 deletions zanata-war/src/main/java/org/zanata/util/UrlUtil.java
Expand Up @@ -34,6 +34,7 @@
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -339,17 +340,23 @@ public String inactiveAccountPage() {
/**
* Get glossary url with dswid parameter
*/
public String glossaryUrl(String qualifiedName, String filter) {
public String glossaryUrl(String qualifiedName, String filter,
LocaleId localeId) {
String url = contextPath + FRONT_END_PREFIX;
if (GlossaryService.isProjectGlossary(qualifiedName)) {
String projectSlug = GlossaryService.getProjectSlug(qualifiedName);
url = url + "/#project/" + projectSlug + "/glossary";
} else {
url = url + "/#glossary";
}
if (StringUtils.isNotBlank(filter)) {
url = url + "&filter=" + filter;
boolean hasFilter = StringUtils.isNotBlank(filter);
if (hasFilter) {
url += "?filter=" + encodeString(filter);
}
return url + "/" + dswidQuery;
if (localeId != null) {
String prefix = hasFilter ? "&" : "?";
url += prefix + "locale=" + localeId;
}
return url;
}
}
Expand Up @@ -12,7 +12,8 @@
color: #888;
}
.container {
height: 30em;
height: 100%;
min-height: 30em;
}
</ui:style>

Expand Down Expand Up @@ -47,7 +48,7 @@

<div class="l--push-top-quarter txt--align-right">
<g:InlineLabel ui:field='lastModified' styleName="txt--understated" />
<g:Anchor styleName="button button--primary l--push-left-quarter" ui:field="link" target="_blank" text="Edit"/>
<g:Anchor styleName="button button--primary l--push-left-quarter" ui:field="link" target="_blank" text="Edit term"/>
</div>
</div>
</g:HTMLPanel>
Expand Down
Expand Up @@ -6,7 +6,8 @@

<ui:style>
.container {
height: 30em;
height: 100%;
min-height: 30em;
}
</ui:style>

Expand Down
Expand Up @@ -74,7 +74,8 @@ public GetGlossaryDetailsResult execute(GetGlossaryDetailsAction action,

String srcContent = srcTerm.getContent();
String qualifiedName = entry.getGlossary().getQualifiedName();
String url = urlUtil.glossaryUrl(qualifiedName, srcContent);
String url = urlUtil.glossaryUrl(qualifiedName, srcContent,
hLocale.getLocaleId());

items.add(new GlossaryDetails(entry.getId(),
srcContent, hGlossaryTerm.getContent(),
Expand Down
89 changes: 89 additions & 0 deletions zanata-war/src/test/java/org/zanata/util/UrlUtilTest.java
@@ -0,0 +1,89 @@
/*
* Copyright 2016, 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.util;

import org.apache.deltaspike.core.spi.scope.window.WindowContext;
import org.jglue.cdiunit.InRequestScope;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.zanata.ZanataJpaTest;
import org.zanata.ZanataTest;
import org.zanata.common.LocaleId;
import org.zanata.servlet.annotations.ContextPath;
import org.zanata.servlet.annotations.ServerPath;
import org.zanata.test.CdiUnitRunner;

import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;

import static org.assertj.core.api.Assertions.assertThat;
import static org.zanata.util.UrlUtil.FRONT_END_PREFIX;

/**
* @author Alex Eng<a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
@RunWith(CdiUnitRunner.class)
public class UrlUtilTest extends ZanataTest {

@Produces @ServerPath String serverPath = "/";
@Produces @ContextPath String contextPath = "";
@Produces @Named("dswidQuery") String dswidQuery = "";
@Produces @Named("dswidParam") String dswidParam = "";

@Produces @Mock
WindowContext windowContext;

@Inject
private UrlUtil urlUtil;

@Test
@InRequestScope
public void systemGlossaryUrlTest() {
String qualifiedName = "global/glossary";
String filter = "string with white space";
LocaleId localeId = LocaleId.FR;

String expectedUrl =
contextPath + FRONT_END_PREFIX + "/#glossary?filter=" +
UrlUtil.encodeString(filter) + "&locale=fr";

String url = urlUtil.glossaryUrl(qualifiedName, filter, localeId);
assertThat(url).isEqualTo(expectedUrl);
}

@Test
@InRequestScope
public void projectGlossaryUrlTest() {
String qualifiedName = "project/project1";
String filter = "string with white space";
LocaleId localeId = LocaleId.FR;

String expectedUrl =
contextPath + FRONT_END_PREFIX + "/#project/project1/glossary?filter=" +
UrlUtil.encodeString(filter) + "&locale=fr";

String url = urlUtil.glossaryUrl(qualifiedName, filter, localeId);
assertThat(url).isEqualTo(expectedUrl);
}
}

0 comments on commit 104122f

Please sign in to comment.