Skip to content

Commit

Permalink
Task-65373: Language version option
Browse files Browse the repository at this point in the history
Task-65423: Add a language
  • Loading branch information
mkrout committed Aug 30, 2023
1 parent 5c2956a commit f8cc717
Show file tree
Hide file tree
Showing 18 changed files with 504 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ public static PageVersion convertPageVersionEntityToPageVersion(PageVersionEntit
if (pageVersionEntity != null) {
pageVersion = new PageVersion();
pageVersion.setName(String.valueOf(pageVersionEntity.getVersionNumber()));
pageVersion.setTitle(pageVersionEntity.getTitle());
pageVersion.setAuthor(pageVersionEntity.getAuthor());
pageVersion.setContent(pageVersionEntity.getContent());
pageVersion.setCreatedDate(pageVersionEntity.getCreatedDate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,14 +1117,14 @@ public void addPageVersion(Page page , String userName) throws WikiException {

pageVersionEntity.setPage(pageEntity);
pageVersionEntity.setVersionNumber(versionNumber);
pageVersionEntity.setName(pageEntity.getName());
pageVersionEntity.setTitle(pageEntity.getTitle());
pageVersionEntity.setName(page.getName());
pageVersionEntity.setTitle(page.getTitle());
if (StringUtils.isNotEmpty(userName)) {
pageVersionEntity.setAuthor(userName);
} else {
pageVersionEntity.setAuthor(pageEntity.getAuthor());
}
pageVersionEntity.setContent(pageEntity.getContent());
pageVersionEntity.setContent(page.getContent());
pageVersionEntity.setSyntax(pageEntity.getSyntax());
pageVersionEntity.setMinorEdit(pageEntity.isMinorEdit());
pageVersionEntity.setComment(pageEntity.getComment());
Expand All @@ -1140,7 +1140,6 @@ public void addPageVersion(Page page , String userName) throws WikiException {
if (pageVersionEntities == null) {
pageVersionEntities = new ArrayList<>();
}

pageVersionEntities.add(pageVersionEntity);
pageEntity.setVersions(pageVersionEntities);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
import org.exoplatform.wiki.service.search.SearchResultType;
import org.exoplatform.wiki.service.search.TitleSearchResult;
import org.exoplatform.wiki.service.search.WikiSearchData;
import org.json.JSONObject;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.gatein.api.EntityNotFoundException;
import org.exoplatform.common.http.HTTPStatus;
import org.exoplatform.commons.utils.HTMLSanitizer;
Expand Down Expand Up @@ -73,7 +74,7 @@
import org.exoplatform.wiki.tree.utils.TreeUtils;
import org.exoplatform.wiki.utils.NoteConstants;
import org.exoplatform.wiki.utils.Utils;

import org.exoplatform.portal.localization.LocaleContextInfoUtils;
import org.exoplatform.services.rest.http.PATCH;

@Path("/notes")
Expand Down Expand Up @@ -328,7 +329,7 @@ public Response getLatestDraftOfPage(@Parameter(description = "Note id", require
DraftPage draftNote = noteService.getLatestDraftPageByUserAndTargetPageAndLang(Long.valueOf(targetPage.getId()),
currentUserId,
lang);
return Response.ok(draftNote != null ? draftNote : JSONObject.NULL).build();
return Response.ok(draftNote != null ? draftNote : org.json.JSONObject.NULL).build();
} catch (Exception e) {
log.error("Can't get draft note {}", noteId, e);
return Response.serverError().entity(e.getMessage()).build();
Expand Down Expand Up @@ -608,35 +609,56 @@ public Response updateNoteById(@Parameter(description = "Note id", required = tr
return Response.status(Response.Status.CONFLICT).entity(NOTE_NAME_EXISTS).build();
}
note_.setToBePublished(note.isToBePublished());
String newNoteName = TitleResolver.getId(note.getTitle(), false);
String newNoteName = note_.getName();
if (!note_.getTitle().equals(note.getTitle()) && !note_.getContent().equals(note.getContent())) {
note_.setTitle(note.getTitle());
note_.setContent(note.getContent());
if (!NoteConstants.NOTE_HOME_NAME.equals(note.getName()) && !note.getName().equals(newNoteName)) {
noteService.renameNote(note_.getWikiType(), note_.getWikiOwner(), note_.getName(), newNoteName, note.getTitle());
note_.setName(newNoteName);
if(StringUtils.isEmpty(note.getLang())) {
newNoteName = TitleResolver.getId(note.getTitle(), false);
note_.setTitle(note.getTitle());
note_.setContent(note.getContent());
if (!NoteConstants.NOTE_HOME_NAME.equals(note.getName()) && !note.getName().equals(newNoteName)) {
noteService.renameNote(note_.getWikiType(), note_.getWikiOwner(), note_.getName(), newNoteName, note.getTitle());
note_.setName(newNoteName);
}
note_ = noteService.updateNote(note_, PageUpdateType.EDIT_PAGE_CONTENT_AND_TITLE, identity);
} else {
note_ = noteService.updateNote(note_, PageUpdateType.EDIT_PAGE_CONTENT_AND_TITLE, identity);
note_.setTitle(note.getTitle());
note_.setContent(note.getContent());
note_.setLang(note.getLang());
}
note_ = noteService.updateNote(note_, PageUpdateType.EDIT_PAGE_CONTENT_AND_TITLE, identity);
noteService.createVersionOfNote(note_, identity.getUserId());
if (!Utils.ANONYM_IDENTITY.equals(identity.getUserId())) {
WikiPageParams noteParams = new WikiPageParams(note_.getWikiType(), note_.getWikiOwner(), newNoteName);
noteService.removeDraftOfNote(noteParams);
}
} else if (!note_.getTitle().equals(note.getTitle())) {
if (!NoteConstants.NOTE_HOME_NAME.equals(note.getName()) && !note.getName().equals(newNoteName)) {
noteService.renameNote(note_.getWikiType(), note_.getWikiOwner(), note_.getName(), newNoteName, note.getTitle());
note_.setName(newNoteName);
if(StringUtils.isEmpty(note.getLang())) {
newNoteName = TitleResolver.getId(note.getTitle(), false);
if (!NoteConstants.NOTE_HOME_NAME.equals(note.getName()) && !note.getName().equals(newNoteName)) {
noteService.renameNote(note_.getWikiType(), note_.getWikiOwner(), note_.getName(), newNoteName, note.getTitle());
note_.setName(newNoteName);
}
note_.setTitle(note.getTitle());
note_ = noteService.updateNote(note_, PageUpdateType.EDIT_PAGE_TITLE, identity);
} else {
note_ = noteService.updateNote(note_, PageUpdateType.EDIT_PAGE_TITLE, identity);
note_.setTitle(note.getTitle());
note_.setLang(note.getLang());
}
note_.setTitle(note.getTitle());
note_ = noteService.updateNote(note_, PageUpdateType.EDIT_PAGE_TITLE, identity);
noteService.createVersionOfNote(note_, identity.getUserId());
if (!Utils.ANONYM_IDENTITY.equals(identity.getUserId())) {
WikiPageParams noteParams = new WikiPageParams(note_.getWikiType(), note_.getWikiOwner(), newNoteName);
noteService.removeDraftOfNote(noteParams);
}
} else if (!note_.getContent().equals(note.getContent())) {
note_.setContent(note.getContent());
note_ = noteService.updateNote(note_, PageUpdateType.EDIT_PAGE_CONTENT, identity);
if(StringUtils.isNotEmpty(note.getLang())) {
note_.setContent(note.getContent());
note_ = noteService.updateNote(note_, PageUpdateType.EDIT_PAGE_CONTENT, identity);
} else {
note_ = noteService.updateNote(note_, PageUpdateType.EDIT_PAGE_CONTENT, identity);
note_.setContent(note.getContent());
note_.setLang(note.getLang());
}
noteService.createVersionOfNote(note_, identity.getUserId());
if (!Utils.ANONYM_IDENTITY.equals(identity.getUserId())) {
WikiPageParams noteParams = new WikiPageParams(note_.getWikiType(), note_.getWikiOwner(), newNoteName);
Expand Down Expand Up @@ -1327,6 +1349,45 @@ public Response searchData(@Context
}


/**
* Return a list of available languages.
*
* @return List of languages
* @throws Exception if an error occured
*/
@GET
@Path("languages")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("users")
public Response getAvailableLanguages(@Context
UriInfo uriInfos,
@QueryParam("lang") String lang
) throws Exception {
try {
Set<Locale> locales = LocaleContextInfoUtils.getSupportedLocales();
List<Locale> localesList = new ArrayList(locales);
JSONArray localesJSON = new JSONArray();
Locale currentLocal= Locale.ENGLISH;
if (!lang.isEmpty()){
currentLocal = Arrays.stream(Locale.getAvailableLocales()).filter(local -> local.getLanguage().equals(lang)).findAny().get();
}
for (Locale locale : localesList) {
JSONObject object = new JSONObject();
if (locale.toString().equals("ma")) {
continue;
} else {
object.put("value", locale.toString());
object.put("text", locale.getDisplayName(currentLocal) + " / " + locale.getDisplayName(locale));
}
localesJSON.add(object);
}
return Response.ok(localesJSON, MediaType.APPLICATION_JSON).build();
} catch (Exception e) {
return Response.status(HTTPStatus.INTERNAL_ERROR).build();
}
}



private List<JsonNodeData> getJsonTree(WikiPageParams params, HashMap<String, Object> context) throws Exception {
Wiki noteBook = noteBookService.getWikiByTypeAndOwner(params.getType(), params.getOwner());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void testCreateVersionHistoryTree() throws Exception {
assertEquals("testCreateVersionHistoryTree-ver2.0", pageVersion.getContent());

pageVersion = itVersions.next();
assertEquals("testCreateVersionHistoryTree-ver1.0", pageVersion.getContent());
assertEquals("testCreateVersionHistoryTree-ver2.0", pageVersion.getContent());

pageVersion = itVersions.next();
assertEquals("testCreateVersionHistoryTree-ver2.0", pageVersion.getContent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ notes.draft.savedDraftStatus=Draft saved
notes.filter.label.all.notes=All
notes.filter.label.published.notes=Published
notes.filter.label.drafts=Drafts
notes.label.translations=Translation:
notes.label.translation.add=Add a new translation:
notes.label.chooseLangage=Choose language
notes.label.translation.originalVersion=Original version
notes.label.noTranslations=No translation



#############################################################################
#SpaceApplications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ notes.filter.label.all.notes=Tous
notes.filter.label.published.notes=Publi\u00E9
notes.filter.label.drafts=Brouillons


notes.label.translations=Translation:
notes.label.translation.add=Ajouter une translation:
notes.label.chooseLangage=Choisir une langue
notes.label.translation.originalVersion=Version originale
notes.label.noTranslations=Pas de translation


#############################################################################
#SpaceApplications
#############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<import>war:/conf/wiki/notification-configuration.xml</import>
<import>war:/conf/wiki/dynamic-container-configuration.xml</import>
<import>war:/conf/wiki/search-configuration.xml</import>
<import>war:/conf/wiki/features-flags-configuration.xml</import>
<import profiles="analytics">war:/conf/wiki/analytics-ui-watchers-configuration.xml</import>

</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.exoplatform.org/xml/ns/kernel_1_3.xsd http://www.exoplatform.org/xml/ns/kernel_1_3.xsd"
xmlns="http://www.exoplatform.org/xml/ns/kernel_1_3.xsd">

<component>
<key>NotesMultilingualFeatureProperties</key>
<type>org.exoplatform.container.ExtendedPropertyConfigurator</type>
<init-params>
<properties-param>
<name>NotesMultilingualFeatureProperties</name>
<description>MultiLang notes enablement flag</description>
<property name="exo.feature.NotesMultilingual.enabled"
value="${exo.feature.NotesMultilingual.enabled:false}" />
</properties-param>
</init-params>
</component>

<external-component-plugins>
<target-component>org.exoplatform.groovyscript.text.TemplateService</target-component>
<component-plugin>
<name>UIPortalApplication-head</name>
<set-method>addTemplateExtension</set-method>
<type>org.exoplatform.groovyscript.text.TemplateExtensionPlugin</type>
<init-params>
<values-param>
<name>templates</name>
<description>The list of templates to include in HTML Page Header with UIPortalApplication.gtmpl</description>
<value>war:/groovy/webui/workspace/UINotesHeadTemplate.gtmpl</value>
</values-param>
</init-params>
</component-plugin>
</external-component-plugins>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%
import org.exoplatform.commons.api.settings.ExoFeatureService;
import org.exoplatform.portal.application.PortalRequestContext;
def rcontext = _ctx.getRequestContext();
ExoFeatureService featureService = uicomponent.getApplicationComponent(ExoFeatureService.class);
def userName = rcontext.getRemoteUser();
%>

<script type="text/javascript" id="notesHeadScripts">
eXo.env.portal.notesMultilingual = <%=featureService.isFeatureActiveForUser("NotesMultilingual", userName)%>;
</script>
44 changes: 43 additions & 1 deletion notes-webapp/src/main/webapp/javascript/eXo/wiki/notesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function getLatestDraftOfPage(noteId) {
});
}

export function getNoteById(noteId,source,type,owner,withChildren) {
export function getNoteById(noteId,lang,source,type,owner,withChildren) {
let url = `${notesConstants.PORTAL}/${notesConstants.PORTAL_REST}/notes/note/${noteId}`;
if (source){
url=`${url}${getSeparator(url)}source=${source}`;
Expand All @@ -53,6 +53,8 @@ export function getNoteById(noteId,source,type,owner,withChildren) {
url=`${url}${getSeparator(url)}noteBookOwner=${owner}`;
} if (withChildren){
url=`${url}${getSeparator(url)}withChildren=${withChildren}`;
}if (lang){
url=`${url}${getSeparator(url)}lang=${lang}`;
}
return fetch(url, {
method: 'GET',
Expand Down Expand Up @@ -339,3 +341,43 @@ export function getNoteVersionsByNoteId(noteId) {
}
});
}

export function getAvailableLanguages() {
const lang = eXo && eXo.env.portal.language || 'en';
return fetch(`${notesConstants.PORTAL}/${notesConstants.PORTAL_REST}/notes/languages?lang=${lang}`, {
method: 'GET',
credentials: 'include',
}).then(resp => {
if (!resp || !resp.ok) {
throw new Error('Response code indicates a server error', resp);
} else {
return resp.json();
}
});
}
export function getNoteLanguages(noteId) {
return fetch(`${notesConstants.PORTAL}/${notesConstants.PORTAL_REST}/notes/note/langs/${noteId}`, {
method: 'GET',
credentials: 'include',
}).then(resp => {
if (!resp || !resp.ok) {
throw new Error('Response code indicates a server error', resp);
} else {
return resp.json();
}
});
}

export function deleteNoteTranslation(noteId, lang) {
return fetch(`${notesConstants.PORTAL}/${notesConstants.PORTAL_REST}/notes/note/translations/${noteId}/${lang}`, {
credentials: 'include',
method: 'DELETE',
}).then((resp) => {
if (resp && resp.ok) {
return resp;
} else {
throw new Error('Error when deleting translation');
}
});
}

12 changes: 11 additions & 1 deletion notes-webapp/src/main/webapp/skin/less/notes/notes.less
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
flex: auto;

img {
height: 40px;
height: 41px;
}

input[type="text"] {
Expand Down Expand Up @@ -1197,3 +1197,13 @@ ul.note-manual-child {

}

.translation-chips .v-chip.v-chip--outlined.v-chip.v-chip {
color: @primaryColor !important;
}

.left-separator {
border-left: solid;
}



Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default {
this.$refs.customPluginsDrawer.close();
},
retrieveNoteChildren(noteId) {
this.$notesService.getNoteById(noteId, '','','',true).then(data => {
this.$notesService.getNoteById(noteId,'', '','','',true).then(data => {
this.noteChildren = data && data.children || [];
});
},
Expand Down
Loading

0 comments on commit f8cc717

Please sign in to comment.