Skip to content

Commit

Permalink
Feature #13992: adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverYoCha committed Apr 2, 2024
1 parent f983a80 commit ef1e817
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#
docTemplate.breadcrumb=Gestion des mod\u00e8les de document
docTemplate.the=le mod\u00e8le de document
docTemplate.restrictedSpaceIds.info=Les mod\u00e8les de document sont \u00e9galement disponibles depuis les espaces enfants des espaces indiqu\u00e9s
docTemplate.restrictedSpaceIds.help=Renseigner dans ce champ une liste d'identifiant d'espace s\u00e9par\u00e9s par des virgules. 'WA38, WA26' par exemple
docTemplate.restrictedSpaceIds.label=Restreindre aux espaces
docTemplate.restrictedToSpaceIds.info=Les mod\u00e8les de document sont \u00e9galement disponibles depuis les espaces enfants des espaces indiqu\u00e9s
docTemplate.restrictedToSpaceIds.help=Renseigner dans ce champ une liste d'identifiant d'espace s\u00e9par\u00e9s par des virgules. 'WA38, WA26' par exemple
docTemplate.restrictedToSpaceIds.label=Restreindre aux espaces
docTemplate.save.name.error.mandatory=Le nom doit \u00eatre renseign\u00e9 pour une des langues
docTemplate.save.content.type=Le mod\u00e8le de document n''est pas un document office
documentTemplate.create.success = Le mod\u00e8le de document <strong>{0}</strong> a bien \u00e9t\u00e9 enregistr\u00e9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#
docTemplate.breadcrumb=Document template management
docTemplate.the=the document template
docTemplate.restrictedSpaceIds.info=Die Dokumentvorlagen werden auch in untergeordneten Bereichen der angegebenen Bereiche bereitgestellt
docTemplate.restrictedSpaceIds.help=F\u00fcgen Sie in dieses Feld eine Liste mit kommagetrennten Raumbezeichnungen ein. 'WA38, WA26' zum Beispiel
docTemplate.restrictedSpaceIds.label=Auf Raum beschr\u00e4nken
docTemplate.restrictedToSpaceIds.info=Die Dokumentvorlagen werden auch in untergeordneten Bereichen der angegebenen Bereiche bereitgestellt
docTemplate.restrictedToSpaceIds.help=F\u00fcgen Sie in dieses Feld eine Liste mit kommagetrennten Raumbezeichnungen ein. 'WA38, WA26' zum Beispiel
docTemplate.restrictedToSpaceIds.label=Auf Raum beschr\u00e4nken
docTemplate.save.name.error.mandatory=The name must be filled in one of the languages
docTemplate.save.content.type=The document template is not an office document
documentTemplate.create.success = Document template <strong>{0}</strong> has been successfully created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#
docTemplate.breadcrumb=Document template management
docTemplate.the=the document template
docTemplate.restrictedSpaceIds.info=The document templates are also provided into child spaces of indicated spaces
docTemplate.restrictedSpaceIds.help=Input a comma-separated list of space identifiers into this field. 'WA38, WA26' for example
docTemplate.restrictedSpaceIds.label=Restrict to space
docTemplate.restrictedToSpaceIds.info=The document templates are also provided into child spaces of indicated spaces
docTemplate.restrictedToSpaceIds.help=Input a comma-separated list of space identifiers into this field. 'WA38, WA26' for example
docTemplate.restrictedToSpaceIds.label=Restrict to space
docTemplate.save.name.error.mandatory=The name must be filled in one of the languages
docTemplate.save.content.type=The document template is not an office document
documentTemplate.create.success = Document template <strong>{0}</strong> has been successfully created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#
docTemplate.breadcrumb=Gestion des mod\u00e8les de document
docTemplate.the=le mod\u00e8le de document
docTemplate.restrictedSpaceIds.info=Les mod\u00e8les de document sont \u00e9galement disponibles depuis les espaces enfants des espaces indiqu\u00e9s
docTemplate.restrictedSpaceIds.help=Renseigner dans ce champ une liste d'identifiant d'espace s\u00e9par\u00e9s par des virgules. 'WA38, WA26' par exemple
docTemplate.restrictedSpaceIds.label=Restreindre aux espaces
docTemplate.restrictedToSpaceIds.info=Les mod\u00e8les de document sont \u00e9galement disponibles depuis les espaces enfants des espaces indiqu\u00e9s
docTemplate.restrictedToSpaceIds.help=Renseigner dans ce champ une liste d'identifiant d'espace s\u00e9par\u00e9s par des virgules. 'WA38, WA26' par exemple
docTemplate.restrictedToSpaceIds.label=Restreindre aux espaces
docTemplate.save.name.error.mandatory=Le nom doit \u00eatre renseign\u00e9 pour une des langues
docTemplate.save.content.type=Le mod\u00e8le de document n''est pas un document office
documentTemplate.create.success = Le mod\u00e8le de document <strong>{0}</strong> a bien \u00e9t\u00e9 enregistr\u00e9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,11 @@ private boolean isTemplateVisibleAccordingToApplication(PublicationTemplate temp

private boolean isTemplateVisibleAccordingToSpace(PublicationTemplate template,
GlobalContext context, OrganizationController oc) {
List<String> restrictedSpaceIds = template.getSpaces();
List<String> restrictedToSpaceIds = template.getSpaces();
List<SpaceInstLight> spacePath = oc.getPathToSpace(context.getSpaceId());
for (SpaceInstLight space : spacePath) {
String spaceId = space.getId();
if (restrictedSpaceIds.contains(spaceId)) {
if (restrictedToSpaceIds.contains(spaceId)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ public void setExtension(final String extension) {
* Sets the space identifiers the document template is restricted to.
* @param spacesIds list of space identifier.
*/
public void setRestrictedSpaceIds(final List<String> spacesIds) {
public void setRestrictedToSpaceIds(final List<String> spacesIds) {
json.getRestrictions().setSpaceIds(spacesIds);
}

/**
* Gets the space identifiers the document template is restricted to.
* @return list of space identifier.
*/
public List<String> getRestrictedSpaceIds() {
public List<String> getRestrictedToSpaceIds() {
return json.getRestrictions().getSpaceIds();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public class DocumentTemplateRestrictionFilter {
* @return true if the document template MUST be kept, false otherwise.
*/
public boolean applyOn(final DocumentTemplate documentTemplate) {
final List<String> restrictedSpaceIds = documentTemplate.getRestrictedSpaceIds();
return restrictedSpaceIds.isEmpty() ||
restrictedSpaceIds.stream().anyMatch(getSpaceIds()::contains);
final List<String> restrictedToSpaceIds = documentTemplate.getRestrictedToSpaceIds();
return restrictedToSpaceIds.isEmpty() ||
restrictedToSpaceIds.stream().anyMatch(getSpaceIds()::contains);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public List<String> getSpaceIds() {
* is no need to specified explicitly them.
* </p>
* <p>
* If an empty list (or a null one) is given, no data about restriction are saved into JSON
* If an empty list (or a null one) is given, no data about restriction is saved into JSON
* model.
* </p>
* @param spaceIds a list of space identifier as string. Null or empty list means no space
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DocumentTemplateRestrictionFilterTest {
void setup() {
final DocumentTemplate notRestricted = new DocumentTemplate();
final DocumentTemplate restricted = new DocumentTemplate();
restricted.setRestrictedSpaceIds(List.of("WA26", "WA25"));
restricted.setRestrictedToSpaceIds(List.of("WA26", "WA25"));
documentTemplates = List.of(notRestricted, restricted);
when(controller.getPathToComponent(anyString())).thenAnswer(a -> {
final String instanceId = a.getArgument(0);
Expand All @@ -84,7 +84,7 @@ void filterWithoutInstanceContext() {
final List<DocumentTemplate> filteredDocumentTemplates = getFilteredDocumentTemplates();
assertThat(filteredDocumentTemplates.size(), is(1));
assertThat(filteredDocumentTemplates.stream()
.map(DocumentTemplate::getRestrictedSpaceIds)
.map(DocumentTemplate::getRestrictedToSpaceIds)
.allMatch(List::isEmpty), is(true));
}

Expand All @@ -95,7 +95,7 @@ void filterWithInstanceContextHostedBySpaceIndicatedIntoRestriction() {
final List<DocumentTemplate> filteredDocumentTemplates = getFilteredDocumentTemplates();
assertThat(filteredDocumentTemplates.size(), is(2));
assertThat(filteredDocumentTemplates.stream()
.map(DocumentTemplate::getRestrictedSpaceIds)
.map(DocumentTemplate::getRestrictedToSpaceIds)
.anyMatch(not(List::isEmpty)), is(true));
}

Expand All @@ -106,7 +106,7 @@ void filterWithInstanceContextHostedBySpaceNotIndicatedIntoRestriction() {
final List<DocumentTemplate> filteredDocumentTemplates = getFilteredDocumentTemplates();
assertThat(filteredDocumentTemplates.size(), is(1));
assertThat(filteredDocumentTemplates.stream()
.map(DocumentTemplate::getRestrictedSpaceIds)
.map(DocumentTemplate::getRestrictedToSpaceIds)
.allMatch(List::isEmpty), is(true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void fromEmptyJson() {
assertThat(template, notNullValue());
assertThat(template.getId(), nullValue());
assertThat(template.getPosition(), is(-1));
assertThat(template.getRestrictedSpaceIds().isEmpty(), is(true));
assertThat(template.getRestrictedToSpaceIds().isEmpty(), is(true));
assertThat(template.getExtension(), nullValue());
assertThat(template.getName("fr"), emptyString());
assertThat(template.getName("en"), emptyString());
Expand All @@ -65,7 +65,7 @@ void fromJson() {
assertThat(template, notNullValue());
assertThat(template.getId(), is("an identifier"));
assertThat(template.getPosition(), is(3));
assertThat(template.getRestrictedSpaceIds().isEmpty(), is(true));
assertThat(template.getRestrictedToSpaceIds().isEmpty(), is(true));
assertThat(template.getExtension(), is("txt"));
assertThat(template.existNameTranslationIn("fr"), is(true));
assertThat(template.getName("fr"), is("Ceci est un test"));
Expand All @@ -87,7 +87,7 @@ void fromJsonWithRestrictions() {
assertThat(template, notNullValue());
assertThat(template.getId(), is("an identifier"));
assertThat(template.getPosition(), is(3));
assertThat(template.getRestrictedSpaceIds(), contains("WA26", "WA25"));
assertThat(template.getRestrictedToSpaceIds(), contains("WA26", "WA25"));
assertThat(template.getExtension(), is("txt"));
assertThat(template.existNameTranslationIn("fr"), is(true));
assertThat(template.getName("fr"), is("Ceci est un test"));
Expand All @@ -114,7 +114,7 @@ void toJson() {
assertThat(json, notNullValue());
assertThat(json.getId(), is("an id"));
assertThat(json.getPosition(), is(4));
assertThat(template.getRestrictedSpaceIds().isEmpty(), is(true));
assertThat(template.getRestrictedToSpaceIds().isEmpty(), is(true));
Map<String, String> translations = json.getNameTranslations();
assertThat(translations, notNullValue());
assertThat(translations.size(), is(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ void encodeWithRestrictedSpaces() {
"\"position\":3,\"restrictions\":{\"spaceIds\":[\"WA26\",\"WA25\"]},"));
}

private void assertEncode(final List<String> restrictedSpaceIds,
private void assertEncode(final List<String> restrictedToSpaceIds,
final String expectedJson) {
JsonDocumentTemplate jsonEntity = new JsonDocumentTemplate();
jsonEntity.setId("an identifier");
jsonEntity.setPosition(3);
jsonEntity.getRestrictions().setSpaceIds(restrictedSpaceIds);
jsonEntity.getRestrictions().setSpaceIds(restrictedToSpaceIds);
jsonEntity.getNameTranslations().put("fr", "Ceci est un test");
jsonEntity.getNameTranslations().put("en", "This is a test");
jsonEntity.setCreatorId("1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ private UploadedFile mergeDocumentTemplateData(DocumentTemplateWebRequestContext
final HttpRequest request = context.getRequest();
ofNullable(request.getParameterAsInteger("position"))
.ifPresent(documentTemplate::setPosition);
ofNullable(request.getParameter("restrictedSpaceIds"))
ofNullable(request.getParameter("restrictedToSpaceIds"))
.map(s -> Stream.of(s.split("[ ,;]"))
.map(String::trim)
.filter(StringUtil::isDefined)
.collect(Collectors.toList()))
.ifPresent(documentTemplate::setRestrictedSpaceIds);
.ifPresent(documentTemplate::setRestrictedToSpaceIds);
DisplayI18NHelper.getLanguages().forEach(l -> {
documentTemplate.setName(request.getParameter("name-" + l), l);
documentTemplate.setDescription(request.getParameter("description-" + l), l);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
<c:set var="documentTemplatePreview" value="<%=PreviewEntity.createFrom(PreviewService.get().getPreview(documentTemplate.getViewerContext(userLanguage)))%>"/>
<jsp:useBean id="documentTemplatePreview" type="org.silverpeas.core.webapi.viewer.PreviewEntity"/>
<img src="${documentTemplatePreview.URL}" alt="${documentTemplateNameSanitized}">
<c:if test="${not empty documentTemplate.restrictedSpaceIds}">
<c:if test="${not empty documentTemplate.restrictedToSpaceIds}">
<c:set var="newStringArray" value="<%=new String[0]%>"/>
<div class="restricted-space-ids inlineMessage">${fn:join(documentTemplate.restrictedSpaceIds.toArray(newStringArray), ', ')}</div>
<div class="restricted-space-ids inlineMessage">${fn:join(documentTemplate.restrictedToSpaceIds.toArray(newStringArray), ', ')}</div>
</c:if>
<c:if test="${not empty documentTemplateDesc}">
<div class="description">${documentTemplateDesc}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
* @returns {Promise<*[]>}
*/
this.listChildrenByIdOrUri = function(idOrUri) {
const uri = StringUtil.defaultStringIfNotDefined(idOrUri).indexOf('/') >= 0
? idOrUri
: BASE_URL + '/' + idOrUri + '/';
const uri = __decodeIdOrUri(idOrUri);
return sp.ajaxRequest(uriDecorator(uri)).sendAndPromiseJsonResponse().then(__spacesDecorator);
};

Expand All @@ -46,12 +44,16 @@
* @returns {Promise<*[]>}
*/
this.getByIdOrUri = function(idOrUri) {
const uri = StringUtil.defaultStringIfNotDefined(idOrUri).indexOf('/') >= 0
? idOrUri
: BASE_URL + '/' + idOrUri;
const uri = __decodeIdOrUri(idOrUri);
return sp.ajaxRequest(uriDecorator(uri)).sendAndPromiseJsonResponse().then(__spaceDecorator);
};

function __decodeIdOrUri(idOrUri) {
return StringUtil.defaultStringIfNotDefined(idOrUri).indexOf('/') >= 0
? idOrUri
: BASE_URL + '/' + idOrUri;
}

/**
* Decorating array of returned spaces.
* @param spaces an array of space data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
<fmt:setLocale value="${lang}"/>
<view:setBundle bundle="${requestScope.resources.multilangBundle}"/>

<fmt:message var="mandatoryLabel" key='GML.requiredField.legend'/>
<fmt:message var="nameLabel" key="GML.name"/>
<fmt:message var="descriptionLabel" key="GML.description"/>
<fmt:message var="nameMandatoryError" key="docTemplate.save.name.error.mandatory"/>
<fmt:message var="restrictedSpaceIdsLabel" key="docTemplate.restrictedSpaceIds.label"/>
<fmt:message var="restrictedSpaceIdsInfo" key="docTemplate.restrictedSpaceIds.info"/>
<fmt:message var="restrictedSpaceIdsHelp" key="docTemplate.restrictedSpaceIds.help"/>
<fmt:message var="restrictedToSpaceIdsLabel" key="docTemplate.restrictedToSpaceIds.label"/>
<fmt:message var="restrictedToSpaceIdsInfo" key="docTemplate.restrictedToSpaceIds.info"/>
<fmt:message var="restrictedToSpaceIdsHelp" key="docTemplate.restrictedToSpaceIds.help"/>
<view:includePlugin name="tags" />

<c:url var="mandatoryIcons" value="/util/icons/mandatoryField.gif"/>
Expand All @@ -55,11 +56,15 @@
<view:includePlugin name="spaceandcomponentselector"/>

<div class="document-template-form">
<div class="legend">
<img src="${mandatoryIcons}" width="5" height="5" alt=""/>&nbsp;
${mandatoryLabel}
</div>
<view:form name="document-template-form" action="#" method="POST">
<div class="fields">
<div class="field">
<label class="txtlibform">${nameLabel}</label>
&nbsp;<img src="${mandatoryIcons}" width="5" height="5" alt="">
&nbsp;<img src="${mandatoryIcons}" width="5" height="5" alt="(${mandatoryLabel})">
</div>
<c:forEach var="language" items="${languages}">
<div class="field languages">
Expand Down Expand Up @@ -87,18 +92,18 @@
</c:if>
</div>
<div class="field restricted-space-ids">
<label class="txtlibform" for="doc_template_restricted-space-ids">
<span>${restrictedSpaceIdsLabel}&nbsp;</span>
<img class="infoBulle" title="${restrictedSpaceIdsInfo}" src="<c:url value="/util/icons/info.gif"/>" alt=""/>
<img class="helpBulle" title="${restrictedSpaceIdsHelp}" src="<c:url value="/util/icons/help.png"/>" alt=""/>
<label class="txtlibform" for="doc_template_restricted-to-space-ids">
<span>${restrictedToSpaceIdsLabel}&nbsp;</span>
<img class="infoBulle" title="${restrictedToSpaceIdsInfo}" src="<c:url value="/util/icons/info.gif"/>" alt=""/>
<img class="helpBulle" title="${restrictedToSpaceIdsHelp}" src="<c:url value="/util/icons/help.png"/>" alt=""/>
</label>
<div class="champs">
<ul id="restricted-space-ids">
<c:forEach var="restrictedSpaceId" items="${documentTemplate.restrictedSpaceIds}">
<c:forEach var="restrictedSpaceId" items="${documentTemplate.restrictedToSpaceIds}">
<li data-value="${restrictedSpaceId}">${restrictedSpaceId}</li>
</c:forEach>
</ul>
<input type="hidden" id="doc_template_restricted-space-ids" name="restrictedSpaceIds"/>
<input type="hidden" id="doc_template_restricted-to-space-ids" name="restrictedToSpaceIds"/>
<div id="scs-popin">
<silverpeas-space-and-component-selector-popin v-bind:admin-access="true"
v-bind:space-selection="selectedSpaces"
Expand All @@ -110,10 +115,6 @@
</div>
</div>
</view:form>
<div class="legend">
<img alt="mandatory" src="${mandatoryIcons}" width="5" height="5"/>&nbsp;
<fmt:message key='GML.requiredField'/>
</div>
<script type="text/javascript">
//# sourceURL=tmp.js
function getTags(tags) {
Expand All @@ -122,7 +123,7 @@
}).join(',');
}
function checkDocumentTemplateForm(callback) {
document.querySelector("#doc_template_restricted-space-ids").value =
document.querySelector("#doc_template_restricted-to-space-ids").value =
getTags(jQuery("#restricted-space-ids").tagit("tags"));
const data = sp.form.serializeJson("form[name='document-template-form']");
const _fileUploadApi = jQuery(".fileUpload").fileUpload('api');
Expand Down Expand Up @@ -181,7 +182,7 @@
tagsChanged : updateSelectedSpaceIdsFromInput
});
updateSelectedSpaceIdsFromInput();
document.querySelector(".tagit-input").setAttribute("aria-description", "${silfn:escapeJs(restrictedSpaceIdsInfo)}");
document.querySelector(".tagit-input").setAttribute("aria-description", "${silfn:escapeJs(restrictedToSpaceIdsInfo)}");
})();
</script>
</div>

0 comments on commit ef1e817

Please sign in to comment.