Commit 0f5278be authored by Matija Obreza's avatar Matija Obreza
Browse files

"Manage Content" in Admin's dropdown menu

Flash attributes used when dealing with translation service
parent f4de9c62
......@@ -21,6 +21,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.service.ContentService;
import org.genesys2.spring.RequestAttributeLocaleResolver;
......@@ -41,6 +42,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -63,7 +65,7 @@ public class ArticleController extends BaseController {
@RequestMapping(value = "/transifex", params = { "post" }, method = RequestMethod.POST)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER')")
public String postTotransifex(@RequestParam("slug") String slug, Model model) {
public String postTotransifex(@RequestParam("slug") String slug, RedirectAttributes redirectAttrs) {
if (transifexService == null) {
throw new ResourceNotFoundException("translationService not enabled");
}
......@@ -78,37 +80,33 @@ public class ArticleController extends BaseController {
transifexService.createXhtmlResource(resourceName, article.getTitle(), body);
}
} catch (IOException e) {
model.addAttribute("responseFromTransifex", "article.transifex-failed");
model.addAttribute("article", article);
redirectAttrs.addFlashAttribute("responseFromTransifex", "article.transifex-failed");
e.printStackTrace();
}
model.addAttribute("responseFromTransifex", "article.transifex-resource-updated");
model.addAttribute("article", article);
return "/content/article-edit";
redirectAttrs.addFlashAttribute("responseFromTransifex", "article.transifex-resource-updated");
return "redirect:/content/" + slug + "/edit/" + LocaleContextHolder.getLocale().getLanguage();
}
@RequestMapping(value = "/transifex", params = { "remove" }, method = RequestMethod.POST)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER')")
public String deleteFromtransifex(@RequestParam("slug") String slug, Model model) {
public String deleteFromtransifex(@RequestParam("slug") String slug, RedirectAttributes redirectAttrs) {
if (transifexService == null) {
throw new ResourceNotFoundException("translationService not enabled");
}
Article article = contentService.getGlobalArticle(slug, getLocale());
model.addAttribute("article", article);
try {
if (transifexService.deleteResource("article-" + slug)) {
model.addAttribute("responseFromTransifex", "article.transifex-resource-removed");
redirectAttrs.addFlashAttribute("responseFromTransifex", "article.transifex-resource-removed");
} else {
model.addAttribute("responseFromTransifex", "article.transifex-failed");
redirectAttrs.addFlashAttribute("responseFromTransifex", "article.transifex-failed");
}
} catch (TransifexException e) {
_logger.error(e.getMessage(), e);
model.addAttribute("responseFromTransifex", "article.transifex-failed");
redirectAttrs.addFlashAttribute("responseFromTransifex", "article.transifex-failed");
}
return "/content/article-edit";
return "redirect:/content/" + slug + "/edit/" + LocaleContextHolder.getLocale().getLanguage();
}
@RequestMapping(value = "/translate/{slug}/{language}", method = RequestMethod.GET)
......@@ -172,6 +170,7 @@ public class ArticleController extends BaseController {
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER')")
public String list(ModelMap model, @RequestParam(value = "page", defaultValue = "1") int page,
@RequestParam(value = "language", defaultValue = "") String lang) {
if (!lang.isEmpty()) {
model.addAttribute("pagedData", contentService.listArticlesByLang(lang, new PageRequest(page - 1, 50, new Sort("slug"))));
} else {
......@@ -186,6 +185,7 @@ public class ArticleController extends BaseController {
}
model.addAttribute("languages", locales);
model.addAttribute("language", lang);
return "/content/index";
}
......@@ -206,13 +206,15 @@ public class ArticleController extends BaseController {
return "/content/article";
}
@RequestMapping("{menu}/{url:.+}")
public String viewWithMenu(ModelMap model, @PathVariable(value = "menu") String menuKey, @PathVariable(value = "url") String slug) {
view(model, slug);
_logger.debug("Loading menu " + menuKey);
model.addAttribute("menu", contentService.getMenu(menuKey));
return "/content/article";
String result = view(model, slug);
if (StringUtils.isNotBlank(menuKey)) {
_logger.debug("Loading menu " + menuKey);
model.addAttribute("menu", contentService.getMenu(menuKey));
}
return result;
}
/**
......
......@@ -113,6 +113,7 @@ user.pulldown.logout=Logout
user.pulldown.profile=My profile
user.pulldown.oauth-clients=OAuth clients
user.pulldown.teams=Teams
user.pulldown.manage-content=Manage content
user.pulldown.heading={0}
user.create-new-account=Create an account
......
......@@ -57,6 +57,7 @@
<li><a href="<c:url value="/profile/list" />"><spring:message code="user.pulldown.users" /></a></li>
<li><a href="<c:url value="/team" />"><spring:message code="user.pulldown.teams" /></a></li>
<li><a href="<c:url value="/management/" />"><spring:message code="user.pulldown.oauth-clients" /></a></li>
<li><a href="<c:url value="/content" />"><spring:message code="user.pulldown.manage-content" /></a></li>
</security:authorize>
<li><a href="<c:url value="/profile/${user.username}" />"><spring:message code="user.pulldown.profile"/></a></li>
<li><a id="logout" href="<c:url value="/logout" />"><spring:message code="user.pulldown.logout"/></a>
......
......@@ -12,13 +12,13 @@
</h1>
<div class="main-col-header clearfix">
<div class="nav-header pull-left">
<div class="nav-header">
<div class="results"><spring:message code="paged.totalElements" arguments="${pagedData.totalElements}" /></div>
<div class="pagination">
<div class="pagination pull-left">
<spring:message code="paged.pageOfPages" arguments="${pagedData.number+1},${pagedData.totalPages}" />
<a class="${pagedData.number eq 0 ? 'disabled' :''}" href="?page=${pagedData.number eq 0 ? 1 : pagedData.number}"><spring:message code="pagination.previous-page" /></a> <a href="?page=${pagedData.number + 2}"><spring:message code="pagination.next-page" /></a>
<a class="${pagedData.number eq 0 ? 'disabled' :''}" href="?page=${pagedData.number eq 0 ? 1 : pagedData.number}&amp;language=${language}"><spring:message code="pagination.previous-page" /></a> <a href="?page=${pagedData.number + 2}&amp;language=${language}"><spring:message code="pagination.next-page" /></a>
</div>
<div class="form-group">
<div class="form-group pull-right">
<div class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><c:out value="Languge filtering" /> <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu" id="transifiex_langs">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment