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: dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Jul 21, 2013
1 parent dd62c7a commit ca3d002
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 22 deletions.
144 changes: 144 additions & 0 deletions zanata-war/src/main/java/org/zanata/action/DashboardAction.java
@@ -0,0 +1,144 @@
/*
* Copyright 2010, 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.action;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.management.JpaIdentityStore;
import org.zanata.dao.DocumentDAO;
import org.zanata.dao.ProjectIterationDAO;
import org.zanata.model.HAccount;
import org.zanata.model.HLocale;
import org.zanata.model.HProject;
import org.zanata.model.HProjectIteration;
import org.zanata.service.GravatarService;
import org.zanata.service.LocaleService;

@Name("dashboardAction")
@Scope(ScopeType.PAGE)
public class DashboardAction implements Serializable
{
private static final long serialVersionUID = 1L;

@Logger
private Log log;

@In
private GravatarService gravatarServiceImpl;

@In
private LocaleService localeServiceImpl;

@In
private ProjectIterationDAO projectIterationDAO;

@In(required = false, value = JpaIdentityStore.AUTHENTICATED_USER)
private HAccount authenticatedAccount;

private final int USER_IMAGE_SIZE = 115;

private int SUPPORTED_LOCALES_SIZE;

private final Comparator<HProject> projectCreationDateComparator = new Comparator<HProject>()
{
@Override
public int compare(HProject o1, HProject o2)
{
return o2.getCreationDate().after(o1.getCreationDate()) ? 1 : -1;
}
};

public void init()
{
SUPPORTED_LOCALES_SIZE = localeServiceImpl.getSupportedLocales().size();
}

public String getUserImageUrl()
{
return gravatarServiceImpl.getUserImageUrl(USER_IMAGE_SIZE);
}

public String getUsername()
{
return authenticatedAccount.getPerson().getAccount().getUsername();
}

public String getUserFullName()
{
return authenticatedAccount.getPerson().getName();
}

public int getUserMaintainedProjectsSize()
{
return authenticatedAccount.getPerson().getMaintainerProjects().size();
}

public List<HProject> getUserMaintainedProjects()
{
List<HProject> sortedList = new ArrayList<HProject>();
sortedList.addAll(authenticatedAccount.getPerson().getMaintainerProjects());

Collections.sort(sortedList, projectCreationDateComparator);

return sortedList;
}

public HProjectIteration getLatestVersion(Long projectId)
{
return projectIterationDAO.getLastCreatedVersion(projectId);
}

public int getDocumentCount(Long versionId)
{
HProjectIteration version = projectIterationDAO.findById(versionId, false);
return version.getDocuments().size();
}

public int getEnabledLocalesCount(Long versionId)
{
HProjectIteration version = projectIterationDAO.findById(versionId, false);
Set<HLocale> result = version.getCustomizedLocales();

if(result.isEmpty())
{
result = version.getProject().getCustomizedLocales();

if(result.isEmpty())
{
return SUPPORTED_LOCALES_SIZE;
}
}

return result.size();
}

}
24 changes: 10 additions & 14 deletions zanata-war/src/main/java/org/zanata/dao/ProjectIterationDAO.java
Expand Up @@ -373,19 +373,15 @@ public List<HProjectIteration> searchLikeSlugOrProjectSlug(String searchTerm)
q.setCacheable(false).setComment("ProjectIterationDAO.searchLikeSlugOrProjectSlug");

return q.list();

// final String FIELDS[] = { "slug", GroupSearchBridge.PROJECT_FIELD };
//
// MultiFieldQueryParser parser = new
// MultiFieldQueryParser(Version.LUCENE_29, FIELDS, new
// StandardAnalyzer(Version.LUCENE_29));
// org.apache.lucene.search.Query textQuery = parser.parse(searchTerm);
//
// org.hibernate.search.jpa.FullTextQuery ftQuery =
// entityManager.createFullTextQuery(textQuery, HProjectIteration.class);
// @SuppressWarnings("unchecked")
// List<HProjectIteration> matches = (List<HProjectIteration>)
// ftQuery.getResultList();
// return matches;
}

public HProjectIteration getLastCreatedVersion(Long projectId)
{
Query q = getSession().createQuery("from HProjectIteration t where t.project.id = :projectId order by t.creationDate");
q.setParameter("projectId", projectId);
q.setCacheable(true);
q.setMaxResults(1).setComment("ProjectIterationDAO.getLastCreatedVersion");
return (HProjectIteration)q.uniqueResult();

}
}
2 changes: 2 additions & 0 deletions zanata-war/src/main/resources/messages.properties
Expand Up @@ -106,6 +106,8 @@ jsf.server.EditHomePageCode.tooltip=Edit the home page code as persisted. Useful
jsf.PageTitle=Zanata | Open Translation, for Everyone
jsf.Dashboard=Dashboard
jsf.YourActivity=Your Activity
jsf.Settings=Settings
jsf.Maintainer=Maintainer

#------ [home] > Edit Page Content ------
jsf.EditHomePage=Edit Home Page
Expand Down
5 changes: 5 additions & 0 deletions zanata-war/src/main/webapp/WEB-INF/pages.xml
Expand Up @@ -16,6 +16,11 @@
<action execute="#{userRedirect.redirectToDashboard}"/>
</page>

<page view-id="/dashboard/home.xhtml">
<action execute="#{dashboardAction.init()}"/>
</page>


<!-- Landing page for open id authentication -->
<page view-id="/openid.xhtml">
<navigation>
Expand Down
60 changes: 52 additions & 8 deletions zanata-war/src/main/webapp/dashboard/home.xhtml
Expand Up @@ -16,18 +16,18 @@
<div class="l--float-left w--2-6-s l--push-right-1">
<div class="media--circle">
<s:link id="profile" view="/profile/view.xhtml" propagation="none">
<img src="#{gravatarServiceImpl.getUserImageUrl(115)}" alt="#{personHome.instance.name}"/>
<img src="#{dashboardAction.getUserImageUrl()}" alt="#{dashboardAction.getUsername()}"/>
</s:link>
</div>
</div>

<div class="txt--s-align-right">
<h1 class="delta">#{personHome.instance.name}</h1>
<h1 class="delta">#{dashboardAction.getUserFullName()}</h1>
<ul class="list--no-bullets">
<li>#{personHome.instance.account.username}</li>
<li>#{dashboardAction.getUsername()}</li>
<li>
<s:link id="profile" view="/profile/view.xhtml" propagation="none">
Settings <i aria-hidden="true" class="i i--cog"></i>
#{messages['jsf.Settings']} <i aria-hidden="true" class="i i--cog"></i>
</s:link>
</li>
</ul>
Expand Down Expand Up @@ -56,12 +56,14 @@
<h2 class="delta heading--secondary">#{messages['jsf.MaintainedProjects']}</h2>
</div>
<div class="g__item w--4-10 w--4-10-s txt--align-right txt--s-align-right">
<span class="txt--meta">#{personHome.instance.maintainerProjects.size}<i aria-hidden="true" class="i i--clipboard"></i></span>
<span class="txt--meta">#{dashboardAction.getUserMaintainedProjectsSize()}
<i aria-hidden="true" class="i i--clipboard"></i>
</span>
</div>
</div>
</header>
<ul class="list--no-bullets">
<ui:repeat value="#{personHome.instance.maintainerProjects.toArray()}" var="project">
<ui:repeat value="#{dashboardAction.getUserMaintainedProjects()}" var="project">
<li class="bg--faint l--pad-top-half bg--highest--hover progress-bar__expander dropdown__container">
<div class="g--tight l--pad-h-half">
<div class="g__item w--3-4 w--3-4-s">
Expand All @@ -75,13 +77,55 @@
<div class="g__item w--1-4 w--1-4-s txt--align-right txt--s-align-right">
<ul class=" list--horizontal">
<li>
<span class="txt--meta"><i aria-hidden="true" class="i i--network"></i><span class="is-invisible">Translator</span></span>
<span class="txt--meta">
<i aria-hidden="true" class="i i--network"></i>
<span class="is-invisible">#{messages['jsf.Translator']}</span>
</span>
</li>
<li>
<span class="txt--meta"><i aria-hidden="true" class="i i--pencil"></i><span class="is-invisible">Maintainer</span></span>
<span class="txt--meta">
<i aria-hidden="true" class="i i--pencil"></i>
<span class="is-invisible">#{messages['jsf.Maintainer']}</span>
</span>
</li>
</ul>
</div>
</div>
<div class="l--pad-h-half l--pad-bottom-half">
<div class="dropdown" ng-class="{is-active: is-active}">
<div class="dropdown__toggle" href="#" ng-click="is-active=!is-active">
<i class="i i--arrow-down dropdown__toggle__icon"></i>
<ui:param name="latestVersion" value="#{dashboardAction.getLatestVersion(project.id)}"/>
<ul class="dropdown__toggle__content list--horizontal ">
<li>
<s:link view="/iteration/view.xhtml" title="#{latestVersion.slug}">
<f:param name="projectSlug" value="#{project.slug}"/>
<f:param name="iterationSlug" value="#{latestVersion.slug}"/>
<i aria-hidden="true" class="i i--star-2"></i>
<span class="is-invisible">#{messages['jsf.Version']}</span> #{latestVersion.slug}
</s:link>
</li>
<li>
<a href="#" title="#{dashboardAction.getDocumentCount(latestVersion.id)} #{messages['jsf.Documents']}">
<i aria-hidden="true" class="i i--document-alt-fill"></i>
<span class="is-invisible">#{messages['jsf.Documents']}</span> #{dashboardAction.getDocumentCount(latestVersion.id)}
</a>
</li>
<li>
<a href="#" title="#{dashboardAction.getEnabledLocalesCount(latestVersion.id)} #{messages['jsf.Languages']}">
<i aria-hidden="true" class="i i--globe"></i>
<span class="is-invisible">#{messages['jsf.Languages']}</span> #{dashboardAction.getEnabledLocalesCount(latestVersion.id)}
</a>
</li>
<li>
<a href="#" title="Go to Japanese translation">JP</a>
</li>
<li class="l--float-right">
<span class="txt--state-success">73%</span>
</li>
</ul>
</div>
</div>
</div>
</li>
</ui:repeat>
Expand Down

0 comments on commit ca3d002

Please sign in to comment.