Skip to content

Commit

Permalink
#18 Provide a settings console instead of the OSGi config
Browse files Browse the repository at this point in the history
  • Loading branch information
vihnatsenka committed Mar 6, 2024
1 parent 246299b commit 86ab6d9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

public interface UiConfigService {
String[] getExcludedLinksPatterns();
String getSearchPath();
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ int[] allowedStatusCodes() default {
@Activate
@Modified
protected void activate(Configuration configuration) {
searchPath = configuration.searchPath();
searchPath = uiConfigService.getSearchPath();
excludedPaths = configuration.excludedPaths();
checkActivation = configuration.checkActivation();
skipModifiedAfterActivation = configuration.skipModifiedAfterActivation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,27 @@
public class UiConfigServiceImpl implements UiConfigService {
private static final String CONFIG_PATH = "/content/etoolbox-link-inspector/data/config";
private static final String PN_FILTER = "filter";
private static final String PN_PATH = "path";
private static final String DEFAULT_PATH = "/content";

@Reference
private RepositoryHelper repositoryHelper;

@Override
public String[] getExcludedLinksPatterns() {
return getProperty(PN_FILTER, String[].class).orElse(new String[0]);
}

@Override
public String getSearchPath() {
return getProperty(PN_PATH, String.class).orElse(DEFAULT_PATH);
}

private <T> Optional<T> getProperty(String name, Class<T> clazz){
try(ResourceResolver resourceResolver = repositoryHelper.getServiceResourceResolver()){
return Optional.ofNullable(resourceResolver.getResource(CONFIG_PATH))
.map(Resource::getValueMap)
.map(vm->vm.get(PN_FILTER, String[].class))
.orElse(new String[0]);
.map(vm->vm.get(name, clazz));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ private GridResourcesGeneratorImpl getGridResourcesGenerator() throws NoSuchFiel
ExternalLinkChecker externalLinkChecker = mock(ExternalLinkChecker.class);
PrivateAccessor.setField(linkHelper, EXTERNAL_LINK_CHECKER_FIELD, externalLinkChecker);
PrivateAccessor.setField(gridResourcesGenerator, LINK_HELPER_FIELD, linkHelper);
GridResourcesGeneratorImplTest.setUpConfig(gridResourcesGenerator);

when(externalLinkChecker.checkLink(anyString())).thenReturn(HttpStatus.SC_NOT_FOUND);

UiConfigService uiConfigService = mock(UiConfigServiceImpl.class);
when(uiConfigService.getExcludedLinksPatterns()).thenReturn(new String[0]);
when(uiConfigService.getSearchPath()).thenReturn(TEST_FOLDER_PATH);
PrivateAccessor.setField(gridResourcesGenerator, UI_CONFIG_FIELD, uiConfigService);
GridResourcesGeneratorImplTest.setUpConfig(gridResourcesGenerator);

when(externalLinkChecker.checkLink(anyString())).thenReturn(HttpStatus.SC_NOT_FOUND);

return gridResourcesGenerator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void setup() throws NoSuchFieldException {

uiConfigService = mock(UiConfigServiceImpl.class);
when(uiConfigService.getExcludedLinksPatterns()).thenReturn(new String[0]);
when(uiConfigService.getSearchPath()).thenReturn(TEST_FOLDER_PATH);
PrivateAccessor.setField(fixture, UI_CONFIG_FIELD, uiConfigService);
}

Expand All @@ -155,8 +156,6 @@ void testGenerateGridResources() throws NoSuchFieldException, IOException, URISy
assertTrue(CollectionUtils.isEqualCollection(expectedGridResources, gridResources));
}



@Test
void testGenerateFilteredGridResources() throws NoSuchFieldException, IOException, URISyntaxException {
setUpConfig(fixture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/
(function (window, document, $, ELC, Granite, Coral) {
'use strict';
var DIALOG_TITLE_LABEL = Granite.I18n.get('Filter Options');
var SUCCESS_DIALOG_TITLE_LABEL = Granite.I18n.get('Filter Options Applied');
var CANCEL_LABEL = Granite.I18n.get('Cancel');
var SUBMIT_FILTER_LABEL = Granite.I18n.get('Apply');
const DIALOG_TITLE_LABEL = Granite.I18n.get('Filter Options');
const SUCCESS_DIALOG_TITLE_LABEL = Granite.I18n.get('Filter Options Applied');
const CANCEL_LABEL = Granite.I18n.get('Cancel');
const SUBMIT_FILTER_LABEL = Granite.I18n.get('Apply');

var successDialog = new Coral.Dialog().set({
const successDialog = new Coral.Dialog().set({
id : "filter-dialog-success",
closable: Coral.Dialog.closable.ON,
variant: "success",
Expand All @@ -39,12 +39,12 @@
});

function onFilterAction(name, el, config, collection, selections) {
var dialog = document.querySelector('#filter-dialog');
const dialog = document.querySelector('#filter-dialog');
dialog.show();
}

function initActionDialog(){
var dialog = new Coral.Dialog().set({
const dialog = new Coral.Dialog().set({
id : 'filter-dialog',
closable: Coral.Dialog.closable.ON,
backdrop: Coral.Dialog.backdrop.STATIC,
Expand All @@ -54,46 +54,51 @@
}
});

var $cancelBtn = $('<button is="coral-button" variant="default" coral-close>').text(CANCEL_LABEL);
var $updateBtn =
const $cancelBtn = $('<button is="coral-button" variant="default" coral-close>').text(CANCEL_LABEL);
const $updateBtn =
$('<button data-dialog-action is="coral-button" variant="primary" coral-close>').text(SUBMIT_FILTER_LABEL);
$cancelBtn.appendTo(dialog.footer);
$updateBtn.appendTo(dialog.footer);

var filterMultifield = new Coral.Multifield();
const filterMultifield = new Coral.Multifield();
filterMultifield.template.content.appendChild(new Coral.Textfield());

var add = new Coral.Button();
const add = new Coral.Button();
add.label.textContent = 'Add regexp for filtering';
add.setAttribute('coral-multifield-add', '');
filterMultifield.appendChild(add);

dialog.content.appendChild(filterMultifield);
const $rootPathField = $('<input is="coral-textfield" class="elc-replacement-input" name="replacement" value="" required>');
$('<p>').text("Path").appendTo(dialog.content);
$rootPathField.appendTo(dialog.content);
$.ajax({
type: "GET",
url: "/content/etoolbox-link-inspector/data/config.json"
}).done(function (data){
if (data.filter){
for (var f of data.filter){
var item = new Coral.Multifield.Item();
var textField = new Coral.Textfield();
for (let f of data.filter){
const item = new Coral.Multifield.Item();
const textField = new Coral.Textfield();
textField.value = f;
item.content.appendChild(textField);
filterMultifield.items.add(item);
}
$rootPathField.val(data.path);
}
})

function onSubmit(){
var filterMultifieldValues = filterMultifield.items.getAll().map((item) => item.content.children[0].value);
let filterMultifieldValues = filterMultifield.items.getAll().map((item) => item.content.children[0].value);
filterMultifieldValues = !!filterMultifieldValues.length ? filterMultifieldValues : "";
$.ajax({
type: "POST",
url: "/content/etoolbox-link-inspector/data/config",
data: {
'jcr:primaryType': "nt:unstructured",
"filter": filterMultifieldValues,
"filter@TypeHint": "String[]"
"filter@TypeHint": "String[]",
"path": $rootPathField.val()
},
dataType: "json",
encode: true
Expand Down

0 comments on commit 86ab6d9

Please sign in to comment.