Skip to content

Commit

Permalink
UI/InputViewControls: JS, move jquerydispatcher to core, externalize …
Browse files Browse the repository at this point in the history
…VCs JS
  • Loading branch information
nhaagen committed Jan 20, 2025
1 parent 1892186 commit 91c96fd
Show file tree
Hide file tree
Showing 15 changed files with 367 additions and 83 deletions.
3 changes: 3 additions & 0 deletions components/ILIAS/UI/UI.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,9 @@ public function init(
new Component\Resource\ComponentJS($this, "js/Progress/dist/progress.min.js");
$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\ComponentJS($this, "js/MainControls/dist/footer.min.js");
$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\ComponentJS($this, "js/Input/ViewControl/dist/input.viewcontrols.min.js");

/*
those are contributed by MediaObjects
$contribute[Component\Resource\PublicAsset::class] = fn() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ export default class JQueryEventDispatcher {
dispatch(element, eventType, data) {
this.#jquery(element).trigger(eventType, data);
}

/**
* @param {HTMLElement} element
* @param {string} eventType
* @param {function} handler
*/
register(element, eventType, handler) {
this.#jquery(element).on(eventType, handler);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*/

import terser from '@rollup/plugin-terser';
import copyright from '../../../../../../../scripts/Copyright-Checker/copyright.js';
import preserveCopyright from '../../../../../../../scripts/Copyright-Checker/preserveCopyright.js';

export default {
input: './src/viewcontrols.js',
output: {
file: './dist/input.viewcontrols.min.js',
format: 'iife',
banner: copyright,
plugins: [
terser({
format: {
comments: preserveCopyright,
},
}),
],
globals: {
il: 'il',
jquery: '$',
},
},
external: ['il', 'jquery'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*/

export default class FieldSelectionFactory {
/**
* @type {JQueryEventDispatcher}
*/
#eventDispatcher;

/**
* @param {JQueryEventDispatcher} eventDispatcher
*/
constructor(eventDispatcher) {
this.#eventDispatcher = eventDispatcher;
}

/**
* @param {HTMLElement} component
* @param {string} internalSignal
* @param {string} containerSubmitSignal
* @param {string} componentName
* @return {void}
*/
init(component, internalSignal, containerSubmitSignal, componentName) {
this.#eventDispatcher.register(
component.ownerDocument,
internalSignal,
(event) => {
const container = event.target.closest('.il-viewcontrol-fieldselection');
const checkbox = container.querySelectorAll('input[type=checkbox]');
const valueContainer = container.querySelector('.il-viewcontrol-value');
const value = Object.values(checkbox).map((o) => (o.checked ? o.value : ''));

valueContainer.innerHTML = '';
value.forEach(
(v) => {
const element = component.ownerDocument.createElement('input');
element.type = 'hidden';
element.name = `${componentName}[]`;
element.value = v;
valueContainer.appendChild(element);
},
);

this.#eventDispatcher.dispatch(event.target, containerSubmitSignal);
return false;
},
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*/

export default class ModeFactory {
/**
* @type {JQueryEventDispatcher}
*/
#eventDispatcher;

/**
* @param {JQueryEventDispatcher} eventDispatcher
*/
constructor(eventDispatcher) {
this.#eventDispatcher = eventDispatcher;
}

/**
* @param {HTMLElement} component
* @param {string} optValue
* @param {string} containerSubmitSignal
* @return {void}
*/
init(component, optValue, containerSubmitSignal) {
component.addEventListener(
'click',
(event) => {
const btn = event.srcElement;
btn.parentElement.querySelectorAll('button').forEach(
(button) => button.classList.remove('engaged'),
);
btn.classList.add('engaged');
btn.closest('.il-viewcontrol')
.querySelector('.il-viewcontrol-value > input')
.value = optValue;
this.#eventDispatcher.dispatch(event.target, containerSubmitSignal);
return false;
},
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*/

export default class PaginationFactory {
/**
* @type {JQueryEventDispatcher}
*/
#eventDispatcher;

/**
* @param {JQueryEventDispatcher} eventDispatcher
*/
constructor(eventDispatcher) {
this.#eventDispatcher = eventDispatcher;
}

/**
* @param {HTMLElement} component
* @param {string} internalSignal
* @param {string} containerSubmitSignal
* @return {void}
*/
init(component, internalSignal, containerSubmitSignal) {
this.#eventDispatcher.register(
component.ownerDocument,
internalSignal,
(event, signalData) => {
const inputs = event.target
.closest('.il-viewcontrol-pagination')
.querySelectorAll('.il-viewcontrol-value input');
inputs[0].value = signalData.options.offset;
inputs[1].value = signalData.options.limit;

this.#eventDispatcher.dispatch(event.target, containerSubmitSignal);
return false;
},
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*/

export default class SortationFactory {
/**
* @type {JQueryEventDispatcher}
*/
#eventDispatcher;

/**
* @param {JQueryEventDispatcher} eventDispatcher
*/
constructor(eventDispatcher) {
this.#eventDispatcher = eventDispatcher;
}

/**
* @param {HTMLElement} component
* @param {string} internalSignal
* @param {string} containerSubmitSignal
* @return {void}
*/
init(component, internalSignal, containerSubmitSignal) {
this.#eventDispatcher.register(
component.ownerDocument,
internalSignal,
(event, signalData) => {
let container = event.target.closest('.il-viewcontrol-fieldselection');
if (signalData.options.parent_container) {
container = component.ownerDocument.querySelector(
`#${signalData.options.parent_container
} .il-viewcontrol-sortation`,
);
} else {
container = event.target.closest('.il-viewcontrol-sortation');
}
const inputs = container.querySelectorAll('.il-viewcontrol-value > input');
const val = signalData.options.value.split(':');
[inputs[0].value, inputs[1].value] = val;

this.#eventDispatcher.dispatch(event.target, containerSubmitSignal);
return false;
},
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*/

import il from 'il';
import $ from 'jquery';
import FieldSelectionFactory from './fieldselection.factory.js';
import SortationFactory from './sortation.factory.js';
import PaginationFactory from './pagination.factory.js';
import ModeFactory from './mode.factory.js';
import JQueryEventDispatcher from '../../../Core/src/jqueryeventdispatcher.js';

const eventDispatcher = new JQueryEventDispatcher($);

il.UI = il.UI || {};
il.UI.Input = il.UI.Input || {};
il.UI.Input.Viewcontrols = il.UI.Input.Viewcontrols || {};
il.UI.Input.Viewcontrols.FieldSelection = new FieldSelectionFactory(eventDispatcher);
il.UI.Input.Viewcontrols.Sortation = new SortationFactory(eventDispatcher);
il.UI.Input.Viewcontrols.Pagination = new PaginationFactory(eventDispatcher);
il.UI.Input.Viewcontrols.Mode = new ModeFactory(eventDispatcher);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions components/ILIAS/UI/resources/js/ViewControl/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
******************************************************************** */

import terser from '@rollup/plugin-terser';
import copyright from '../../../../../../scripts/Copyright-Checker/copyright';
import preserveCopyright from '../../../../../../scripts/Copyright-Checker/preserveCopyright';
import copyright from '../../../../../../scripts/Copyright-Checker/copyright.js';
import preserveCopyright from '../../../../../../scripts/Copyright-Checker/preserveCopyright.js';

export default {
input: './src/viewcontrols.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import il from 'il';
import $ from 'jquery';
import SortationFactory from './sortation.factory';
import PaginationFactory from './pagination.factory';
import JQueryEventDispatcher from './jqueryeventdispatcher';
import SortationFactory from './sortation.factory.js';
import PaginationFactory from './pagination.factory.js';
import JQueryEventDispatcher from '../../Core/src/jqueryeventdispatcher.js';

const eventDispatcher = new JQueryEventDispatcher($);
il.UI = il.UI || {};
Expand Down
Loading

0 comments on commit 91c96fd

Please sign in to comment.