Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Replace reporting page with stimulus

Oliver Günther5e61b76db48a
diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts
index adc59154e19..7342447aecb 100644
--- a/frontend/src/app/app.module.ts
+++ b/frontend/src/app/app.module.ts
@@ -208,7 +208,6 @@ import {
import {
OpWpDatePickerInstanceComponent,
} from 'core-app/shared/components/datepicker/wp-date-picker-modal/wp-date-picker-instance.component';
-import { ReportingPageComponent } from 'core-app/features/reporting/reporting-page/reporting-page.component';
export function initializeServices(injector:Injector) {
return () => {
@@ -446,6 +445,5 @@ export class OpenProjectModule implements DoBootstrap {
registerCustomElement('opce-global-search-tabs', GlobalSearchTabsComponent, { injector });
registerCustomElement('opce-zen-mode-toggle-button', ZenModeButtonComponent, { injector });
registerCustomElement('opce-colors-autocompleter', ColorsAutocompleterComponent, { injector });
- registerCustomElement('opce-reporting-page', ReportingPageComponent, { injector });
}
}
diff --git a/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine.js b/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine.js
deleted file mode 100644
index e96f4eb46db..00000000000
--- a/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine.js
+++ /dev/null
@@ -1,96 +0,0 @@
-//-- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) the OpenProject GmbH
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License version 3.
-//
-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-// Copyright (C) 2006-2013 Jean-Philippe Lang
-// Copyright (C) 2010-2013 the ChiliProject Team
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-//
-// See COPYRIGHT and LICENSE files for more details.
-//++
-
-import * as jQuery from 'jquery';
-
-/*jslint white: false, nomen: true, devel: true, on: true, debug: false, evil: true, onevar: false, browser: true, white: false, indent: 2 */
-/*global window, $, $$, Reporting, Element */
-
-window.Reporting = (function($) {
- var onload = function (func) {
- $(document).ready(func);
- };
-
- var flash = function (string, type) {
- if (!type) {
- type = "error";
- }
-
- var options = {};
-
- if (type === 'error') {
- options = {
- id: 'errorExplanation',
- class: 'errorExplanation'
- };
- }
- else {
- options = {
- id: 'flash_' + type,
- class: 'flash ' + type
- };
- }
-
- $("#" + options.id).remove();
-
- var flash = $('<div></div>')
- .attr('id', options.id)
- .attr('class', options.class)
- .attr('tabindex', 0)
- .attr('role', 'alert')
- .html(string);
-
- $('#content').prepend(flash);
- $('#' + options.id).focus();
- };
-
- var clearFlash = function () {
- $('div[id^=flash]').remove();
- };
-
- var fireEvent = function (element, event) {
- var evt;
- if (document.createEventObject) {
- // dispatch for IE
- evt = document.createEventObject();
- return element.fireEvent('on' + event, evt);
- } else {
- // dispatch for firefox + others
- evt = document.createEvent("HTMLEvents");
- evt.initEvent(event, true, true); // event type,bubbling,cancelable
- return !element.dispatchEvent(evt);
- }
- };
-
- return {
- fireEvent: fireEvent,
- clearFlash: clearFlash,
- flash: flash,
- onload: onload
- };
-})(jQuery);
diff --git a/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine/controls.js b/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine/controls.js
deleted file mode 100644
index 50fa092cb9b..00000000000
--- a/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine/controls.js
+++ /dev/null
@@ -1,170 +0,0 @@
-//-- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) the OpenProject GmbH
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License version 3.
-//
-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-// Copyright (C) 2006-2013 Jean-Philippe Lang
-// Copyright (C) 2010-2013 the ChiliProject Team
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-//
-// See COPYRIGHT and LICENSE files for more details.
-//++
-
-/*jslint white: false, nomen: true, devel: true, on: true, debug: false, evil: true, onevar: false, browser: true, white: false, indent: 2 */
-/*global window, $, $$, Reporting, Effect, Ajax, Element, selectAllOptions, Form */
-
-Reporting.Controls = function($){
- var toggle_delete_form = function (e) {
- e.preventDefault();
-
- var offset = $('#query-icon-delete').offsetLeft;
- $('#delete_form').css("left", offset + "px").toggle();
- };
-
- var toggle_save_as_form = function (e) {
- e.preventDefault();
-
- var offset = $('#query-icon-save-as').offsetLeft;
- $('#save_as_form')
- .css('left', offset + 'px')
- .toggle();
- };
-
- var clear_query = function (e) {
- e.preventDefault();
-
- Reporting.Filters.clear();
- Reporting.GroupBys.clear();
- };
-
- var send_settings_data = function (targetUrl, callback, failureCallback) {
- var errorCallback = failureCallback || default_failure_callback()
- Reporting.clearFlash();
-
- $.ajax({
- url: targetUrl,
- method: 'POST',
- data: serialize_settings_form(),
- beforeSend: function () {
- $('#ajax-indicator').show();
- },
- error: errorCallback,
- success: callback
- });
- };
-
- var serialize_settings_form = function() {
- var ret_str, grouping_str;
- ret_str = $('#query_form').serialize();
- grouping_str = _.reduce(['rows', 'columns'], function(grouping, type) {
- var element_map = _.map($('#group-by--' + type + ' .group-by--selected-element'), function(group_by) {
- return 'groups[' + type + '][]=' + $(group_by).attr('data-group-by');
- });
-
- return grouping + _.reduce(element_map, function(all_group_str, group_str) {
- return all_group_str + '&' + group_str;
- }, '');
- }, '');
-
- if (grouping_str.length > 0) {
- ret_str += grouping_str;
- }
- return ret_str;
- };
-
- var attach_settings_callback = function (element, callback) {
- if (element === null) {
- return;
- }
- var failureCallback = function (response) {
- $('#result-table').html("");
-
- default_failure_callback(response);
- };
-
- element.on('click', function (e) {
- e.preventDefault();
- send_settings_data($(this).attr("data-target"), callback, failureCallback);
- });
- };
-
- var observe_click = function (element_id, callback) {
- $('#' + element_id).on('click', callback);
- };
-
- var update_result_table = function (response) {
- $('#result-table').html(response);
-
- window.OpenProject.pluginContext
- .valuesPromise()
- .then((context) => {
- context.bootstrap(document.getElementById('result-table'));
- });
- };
-
- var default_failure_callback = function (response) {
- if (response.status >= 400 && response.status < 500) {
- Reporting.flash(response.responseText);
- } else {
- Reporting.flash(I18n.t("js.reporting_engine.label_response_error"));
- }
- };
-
- return {
- attach_settings_callback: attach_settings_callback,
- clear_query: clear_query,
- observe_click: observe_click,
- update_result_table: update_result_table,
- toggle_delete_form: toggle_delete_form,
- toggle_save_as_form: toggle_save_as_form
- };
-}(jQuery);
-
-(function($) {
- Reporting.onload(function () {
- if ($('#query_saved_name').length) {
- // don't concern ourselves with new queries
- if ($('#query_saved_name').attr("data-is_new")) {
- if ($('#query-icon-delete').length) {
- Reporting.Controls.observe_click("query-icon-delete", Reporting.Controls.toggle_delete_form);
- Reporting.Controls.observe_click("query-icon-delete-cancel", Reporting.Controls.toggle_delete_form);
- $('#delete_form').hide();
- }
-
- if ($("#query-breadcrumb-save").length) {
- // When saving an update of an existing query or apply filters, we replace the table on success
- Reporting.Controls.attach_settings_callback($("#query-breadcrumb-save"), Reporting.Controls.update_result_table);
- }
- }
- }
-
- Reporting.Controls.observe_click("query-icon-save-as", Reporting.Controls.toggle_save_as_form);
- Reporting.Controls.observe_click("query-icon-save-as-cancel", Reporting.Controls.toggle_save_as_form);
-
- $('#save_as_form').hide();
-
- // When saving a new query, the success-response is the new saved query's url -> redirect to that
- Reporting.Controls.attach_settings_callback($("#query-icon-save-button"), function (newLocation) {
- document.location = newLocation;
- });
- // When saving an update of an existing query or apply filters, we replace the table on success
- Reporting.Controls.attach_settings_callback($("#query-icon-apply-button"), Reporting.Controls.update_result_table);
- Reporting.Controls.observe_click('query-link-clear', Reporting.Controls.clear_query);
- });
-})(jQuery);
diff --git a/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine/filters.js b/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine/filters.js
deleted file mode 100644
index 14a731127b1..00000000000
--- a/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine/filters.js
+++ /dev/null
@@ -1,358 +0,0 @@
-//-- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) the OpenProject GmbH
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License version 3.
-//
-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-// Copyright (C) 2006-2013 Jean-Philippe Lang
-// Copyright (C) 2010-2013 the ChiliProject Team
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-//
-// See COPYRIGHT and LICENSE files for more details.
-//++
-
-/*jslint white: false, nomen: true, devel: true, on: true, debug: false, evil: true, onevar: false, browser: true, white: false, indent: 2 */
-/*global window, $, $$, Reporting, */
-
-Reporting.Filters = function($){
- var load_available_values_for_filter = function (filter_name, callback_func) {
- var select, radio_options, post_select_values;
- select = $('.filter-value[data-filter-name="' + filter_name + '"]').first();
- // check if we might have a radio-box
- radio_options = $('.' + filter_name + '_radio_option input');
- if (radio_options && radio_options.length !== 0) {
- radio_options.first().checked = true;
- callback_func();
- }
- if (!select.length) {
- return;
- }
- if (select.attr('data-loading') === "ajax" && select.children().length === 0) {
- load_available_values_for_filter_from_remote(select, filter_name, callback_func);
- multi_select(select, false);
- } else {
- callback_func();
- }
- };
-
- var load_available_values_for_filter_from_remote = function(select, filter_name, callback_func) {
- var url = select.attr("data-remote-url"),
- json_post_select_values = select.attr('data-initially-selected'),
- post_select_values;
-
- if (json_post_select_values !== null && json_post_select_values !== undefined) {
- post_select_values = $.parseJSON(json_post_select_values.replace(/'/g, '"'));
- }
-
- if (window.global_prefix === undefined) {
- window.global_prefix = "";
- }
-
- $.ajax({
- url: url,
- method: 'POST',
- data: {
- filter_name: filter_name,
- values: json_post_select_values
- },
- beforeSend: function () {
- $("select[data-filter-name='" + filter_name + "']").attr('disable', true);
- $('#ajax-indicator').show();
- },
- complete: function (xhr) {
- var tagName = select.prop('tagName');
-
- select.html(xhr.responseText);
- $("select[data-filter-name='" + filter_name + "']").removeAttr('disable');
- if (tagName && tagName.toLowerCase() === "select") {
- if (!post_select_values || post_select_values.length === 0) {
- select.selectedIndex = 0;
- } else {
- select_values(select, post_select_values);
- }
- }
- callback_func();
- }
- });
- };
-
- var show_filter = function (field, options) {
- var default_options = {
- callback_func: function () {},
- slowly: false,
- show_filter: true,
- hide_only: false
- };
-
- options = $.extend({}, default_options, options);
-
- var field_el = $('#filter_' + field);
- if (field_el !== null) {
- if (!options.insert_after) {
- options.insert_after = last_visible_filter();
- }
- if (options.insert_after && options.show_filter) {
- // Move the filter down to appear after the last currently visible filter
- if (field_el.attr('id') !== options.insert_after.id) {
- field_el.detach();
- $('#' + options.insert_after.id).after(field_el);
- }
- }
- // the following command might be included into the callback_function (which is called after the ajax request) later
- var display_functor;
- if (options.show_filter) {
- options.slowly ? field_el.fadeIn('slow') : field_el.show();
- load_available_values_for_filter(field, options.callback_func);
- $('#rm_' + field).val(field); // set the value, so the serialized form will return this filter
- value_changed(field);
- } else {
- if (!options.slowly) {
- console.log('hiding for fade', field_el);
- }
- options.slowly ? field_el.fadeOut('slow') : field_el.hide();
-
- if (!options.hide_only) { // remember that this filter used to be selected
- field_el.removeAttr('data-selected');
- }
- $('#rm_' + field).val(""); // reset the value, so the serialized form will not return this filter
- }
- operator_changed(field, $("#operators\\[" + field + "\\]"));
- display_category($('#' + field_el.attr("data-label")));
- }
- };
-
- /**
- * Activates the filter with the given name.
- *
- * @param filter_name Name of the filter to be activated.
- */
- var add_filter = function (filter_name) {
- var field = filter_name;
- // do this immediately instead of in callback to avoid concurrency issues during testing
- select_option_enabled($('#add_filter_select'), filter_name, false);
- show_filter(field, { slowly: true });
- };
-
- var remove_filter = function (field, hide_only) {
- show_filter(field, { show_filter: false, hide_only: hide_only });
- select_option_enabled($("#add_filter_select"), field, true);
- };
-
- var last_visible_filter = function () {
- return $('.advanced-filters--filter:visible').last()[0];
- };
-
- /* Display the given category if any of its filters are visible. Otherwise hide it */
- var display_category = function (label) {
- if (label.length) {
- $('.advanced-filters--filter').each(function() {
- var filter = $(this);
- if (filter.is(':visible') && filter.attr("data-label") === label) {
- $(label).show();
- return;
- }
- $(label).hide();
- });
- }
- };
-
- var operator_changed = function (field, select) {
- var option_tag, arity, forcedType;
- if (select === null) {
- return;
- }
- option_tag = select.find('option[value="' + select.val() + '"]');
- arity = parseInt(option_tag.attr("data-arity"));
- forcedType = option_tag.attr("data-forced");
- change_argument_visibility(field, arity, forcedType);
- };
-
- var value_changed = function (field) {
- var val, filter;
- val = $('#' + field + '_arg_1_val');
- filter = $('#filter_' + field);
- if (!val) {
- return;
- }
- if (val.value === '<<inactive>>') {
- filter.addClass('inactive-filter');
- } else {
- filter.removeClass('inactive-filter');
- }
- };
-
- // 'integers' currently seems to be the only forced typed.
- // See lib/report/operator.rb
- var knownForcedTypes = ['integers'];
-
- // Hides/Displays the various inputs for the filter arguments.
- // Those fields are already completely rendered and are then displayed/hidden
- // depending on the arity of the operator.
- // argNr (the arity) apparently can be 0, 1, 2 and -1. -1 seems to be used for an arity of 1.
- var change_argument_visibility = function (fieldName, argNr, forcedType) {
- const fields = [
- ['#' + fieldName + '_arg_1', [1, 2, -1].includes(argNr)],
- ['#' + fieldName + '_arg_2', argNr === 2]
- ];
-
- for (const [fieldSelector, active] of fields) {
- set_active_state(fieldSelector, active && !forcedType);
- knownForcedTypes.forEach(function (knownForcedType) {
- set_active_state(fieldSelector + '_' + knownForcedType, active && forcedType === knownForcedType);
- });
- }
- };
-
- var set_active_state = function(selector, active) {
- const input = document.querySelector(selector);
-
- if (!input) { return; }
-
- input.hidden = !active;
- for (const child of input.children) {
- child.hidden = !active;
- child.disabled = !active;
- }
- };
-
- var select_option_enabled = function (box, value, state) {
- box.find("[value='" + value + "']").attr('disabled', !state);
- };
-
- var multi_select = function (select, multi) {
- select.attr('multiple', multi);
- if (multi) {
- select.attr('size', 4);
- // deselect first option if it's present
- if (select.find('option')[0]) {
- select.find('option').first().attr('selected', false);
- }
- } else {
- select.attr('size', 1);
- }
- };
-
- var toggle_multi_select = function (select) {
- multi_select(select, !select.attr('multiple'));
- };
-
- var visible_filters = function () {
- return _.map($("#filter_table .advanced-filters--filter:visible"), function(filter) {
- return $(filter).attr("data-filter-name");
- });
- };
-
- var clear = function () {
- _.each(visible_filters(), function (filter) {
- remove_filter(filter);
- });
- };
-
- // Select the given values of the selectBox.
- // Toggle multi-select state of the selectBox depending on how many values were given.
- var select_values = function(selectBox, values_to_select) {
- multi_select(selectBox, values_to_select.length > 1);
- selectBox.val(values_to_select);
- };
-
- var exists = function (filter) {
- return visible_filters().indexOf(filter) > 0;
- };
-
- return {
- add_filter: add_filter,
- clear: clear,
- exists: exists,
- operator_changed: operator_changed,
- remove_filter: remove_filter,
- select_option_enabled: select_option_enabled,
- select_values: select_values,
- toggle_multi_select: toggle_multi_select,
- value_changed: value_changed
- };
-}(jQuery);
-
-(function($) {
- Reporting.onload(function () {
- if ($("#add_filter_select")) {
- $("#add_filter_select").on("change", function () {
- if (!(Reporting.Filters.exists(this.value))) {
- Reporting.Filters.add_filter(this.value);
- var new_filter = this.value;
- this.selectedIndex = 0;
- setTimeout(function () {
- $('#operators\\['+ new_filter +'\\]').focus();
- }, 300);
- }
- });
- }
-
- $(".filter_rem")
- .on("click", function (event) {
- event.preventDefault();
- var filter_name = $(this).closest('li').attr("data-filter-name");
- Reporting.Filters.remove_filter(filter_name);
- })
- .on("keydown", function (event) {
- if (event.keyCode == 13 || event.keyCode == 32) {
- event.preventDefault();
- var filter_name = $(this).closest('li').attr("data-filter-name"),
- prevVisibleFilter = $(this).closest('li').prevAll(':visible').last().find('.advanced-filters--select');
-
- if (prevVisibleFilter.length > 0) {
- prevVisibleFilter.focus();
- } else {
- $('#filters > legend a')[0].focus();
- }
- Reporting.Filters.remove_filter(filter_name);
- }
- });
-
- $(".filter_operator")
- .on("change", function (evt) {
- var filter_name = $(this).attr("data-filter-name");
- Reporting.Filters.operator_changed(filter_name, $(this));
- const argVal = $('#' + filter_name + "_arg_1_val")[0];
- if (argVal) {
- Reporting.fireEvent(argVal, "change");
- }
- });
-
- $(".filter_multi-select")
- .on("click", function () {
- var filter_name = $(this).attr("data-filter-name");
- Reporting.Filters.toggle_multi_select($('#' + filter_name + '_arg_1_val'));
- });
-
- $(".advanced-filters--filter-value .filter-value").each(function () {
- var select = $(this);
- var select_value = select.val();
-
- // Don't try to set multiple on the autocompleters, it is already multi-select
- // and will trigger weird change detection cycles
- if (this.tagName.toLowerCase() !== 'opce-project-autocompleter') {
- select.attr('multiple', select_value && select_value.length > 1);
- }
-
- select.on("change", function (evt) {
- var filter_name = $(this).closest('li').attr("data-filter-name");
- Reporting.Filters.value_changed(filter_name);
- });
- });
- });
-})(jQuery);
diff --git a/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine/group_bys.js b/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine/group_bys.js
deleted file mode 100644
index f97b10824c4..00000000000
--- a/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine/group_bys.js
+++ /dev/null
@@ -1,200 +0,0 @@
-//-- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) the OpenProject GmbH
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License version 3.
-//
-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-// Copyright (C) 2006-2013 Jean-Philippe Lang
-// Copyright (C) 2010-2013 the ChiliProject Team
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-//
-// See COPYRIGHT and LICENSE files for more details.
-//++
-
-/*jslint white: false, nomen: true, devel: true, on: true, debug: false, evil: true, onevar: false, browser: true, white: false, indent: 2 */
-/*global _, dragula, I18n, jQuery, Reporting*/
-
-Reporting.GroupBys = (function($){
- var group_by_container_ids = function() {
- var ids = ['group-by--columns', 'group-by--rows'];
-
- return _.filter(ids, function (i) {
- return $('#' + i).length > 0 ;
- });
- };
-
- var recreate_sortables = function() {
- var containers = $('.group-by--selected-elements')
- .toArray();
-
- dragula(containers,
- {
- // Setting the mirrorContainer to something smaller than the body
- // reduces the performance hit when using dnd.
- mirrorContainer: document.getElementById('group-by--area')
- });
- };
-
- var initialize_drag_and_drop_areas = function() {
- recreate_sortables();
- };
-
- var create_label = function(group_by, text) {
- return $('<label></label>')
- .attr('class', 'in_row group-by--label')
- .attr('for', group_by.attr('id'))
- .attr('id', group_by.attr('id') + '_label')
- .attr('title', text)
- .html(text);
- };
-
- var create_remove_button = function(group_by) {
- var remove_link, remove_icon;
-
- remove_link = $('<a></a>');
- remove_link.attr('class', 'group-by--remove in_row');
- remove_link.attr('id', group_by.attr('id') + '_remove');
- remove_link.attr('href', '');
-
- remove_icon = $('<span><span>');
- remove_icon.attr('class', 'icon-context icon-close icon4');
-
- remove_link.attr('title', I18n.t("js.reporting_engine.label_remove") + ' ' + group_by.find('label').html());
- remove_icon.attr('alt', I18n.t("js.reporting_engine.label_remove") + ' ' + group_by.find('label').html());
-
- remove_link.on('click', function(e) {
- e.preventDefault();
- remove_element_event_action(e, group_by, remove_link);
- });
- remove_link.on('keypress', function(e) {
- /* keyCode 32: Space */
- if (e.keyCode == 32) {
- e.preventDefault();
- remove_element_event_action(e, group_by, remove_link);
- }
- });
- remove_link.append(remove_icon);
- return remove_link;
- };
-
- var remove_element_event_action = function(event, group_by, button) {
- var link_node = group_by.next('span').find('a'),
- select_node = group_by.next('select');
-
- if (link_node.length) {
- link_node.focus();
- }
- else if (select_node.length) {
- select_node.focus();
- }
-
- remove_group_by(button.closest('.group-by--selected-element'));
- };
-
- var create_group_by = function(field, caption) {
- var group_by, label, remove_button;
- group_by = $('<span></span>');
- group_by.attr('class', 'group-by--selected-element');
- group_by.attr('data-group-by', field);
- group_by.uniqueId(); // give it a unique id
-
- label = create_label(group_by, caption);
- group_by.append(label);
-
- remove_button = create_remove_button(group_by);
- group_by.append(remove_button);
-
- return group_by;
- };
-
- // This is whether it is possible to add a new group if <<field>> through the
- // add-group-by select-box or not.
- var adding_group_by_enabled = function(field, state) {
- _.each(['#group-by--add-columns', '#group-by--add-rows'], function(container_id) {
- Reporting.Filters.select_option_enabled($(container_id), field, state);
- });
- };
-
- var remove_group_by = function(group_by) {
- adding_group_by_enabled(group_by.attr('data-group-by'), true);
- group_by.remove();
- };
-
- var add_group_by_from_select = function(select) {
- var jselect = $(select),
- field = jselect.val(),
- container = jselect.closest('.group-by--container'),
- selected_option = jselect.find("[value='" + field + "']").first(),
- caption = selected_option.attr('data-label');
-
- Reporting.GroupBys.add_group_by(field, caption, container);
- jselect.find("[value='']").first().attr('selected', true);
- };
-
- var add_group_by = function(field, caption, container) {
- var group_by, added_container;
- group_by = Reporting.GroupBys.create_group_by(field, caption);
- added_container = container.find('.group-by--selected-elements');
- added_container.append(group_by);
- adding_group_by_enabled(field, false);
- };
-
- var clear = function() {
- _.each(visible_group_bys(), function (group_by) {
- $('#' + group_by + ' .group-by--selected-element').each(function() {
- remove_group_by($(this));
- });
- });
- };
-
- var visible_group_bys = function() {
- var visible = _.filter(group_by_container_ids(), function (container) {
- return $('#' + container).find('[data-group-by]');
- });
-
- return _.flatten(visible);
- };
-
- var exists = function(group_by_name) {
- return _.some(visible_group_bys(), function (grp) {
- return $('#' + grp).attr('data-group-by') === group_by_name;
- });
- };
-
- return {
- add_group_by: add_group_by,
- add_group_by_from_select: add_group_by_from_select,
- clear: clear,
- create_group_by: create_group_by,
- exists: exists,
- group_by_container_ids: group_by_container_ids,
- initialize_drag_and_drop_areas: initialize_drag_and_drop_areas
- };
-
-})(jQuery);
-
-(function($) {
- Reporting.onload(function () {
- Reporting.GroupBys.initialize_drag_and_drop_areas();
- $('#group-by--add-rows, #group-by--add-columns').on('change', function () {
- if (!(Reporting.GroupBys.exists(this.value))) {
- Reporting.GroupBys.add_group_by_from_select(this);
- }
- });
- });
-})(jQuery);
diff --git a/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine/restore_query.js b/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine/restore_query.js
deleted file mode 100644
index ce17752c4e9..00000000000
--- a/frontend/src/app/features/reporting/reporting-page/functionality/reporting_engine/restore_query.js
+++ /dev/null
@@ -1,110 +0,0 @@
-//-- copyright
-// OpenProject is an open source project management software.
-// Copyright (C) the OpenProject GmbH
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License version 3.
-//
-// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-// Copyright (C) 2006-2013 Jean-Philippe Lang
-// Copyright (C) 2010-2013 the ChiliProject Team
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-//
-// See COPYRIGHT and LICENSE files for more details.
-//++
-
-/*jslint white: false, nomen: true, devel: true, on: true, debug: false, evil: true, onevar: false, browser: true, white: false, indent: 2 */
-/*global window, $, $$, Reporting, Effect, Ajax */
-
-Reporting.RestoreQuery = function($){
-
- var select_operator = function (field, operator) {
- var select, i;
- select = $("#operators_" + field);
- if (select === null) {
- return; // there is no such operator select field
- }
- for (i = 0; i < select.options.length; i += 1) {
- if (select.options[i].value === operator) {
- select.selectedIndex = i;
- break;
- }
- }
- Reporting.Filters.operator_changed(field, select);
- };
-
- var disable_select_option = function (select, field) {
- for (var i = 0; i < select.options.length; i += 1) {
- if (select.options[i].value === field) {
- select.options[i].disabled = true;
- break;
- }
- }
- };
-
- var restore_filters = function () {
- var deps = _.each($('.advanced-filters--select.filter-value'), function(select) {
- var jselect = $(select),
- tr = jselect.closest('li');
-
- if (tr.visible()) {
- var filter = tr.attr('data-filter-name');
- var dependent = jselect.attr('data-dependent');
-
- if (filter && dependent) {
- Reporting.Filters.remove_filter(filter, false);
- }
- }
- });
-
- _.each($("li.advanced-filters--filter[data-selected=true]"), function (e) {
- var filter = $(e),
- select = filter.find(".advanced-filters--filter-value select");
- if (select && select.attr("data-dependent")) return;
- var filter_name = filter.attr("data-filter-name");
- Reporting.Filters.add_filter(filter_name);
- });
- };
-
- var restore_group_bys = function () {
- _.each(Reporting.GroupBys.group_by_container_ids(), function(id) {
- var container = $('#' + id),
- selected_containers = container.attr('data-initially-selected'),
- selected_groups;
-
-
- if (selected_containers) {
- selected_groups = $.parseJSON(selected_containers.replace(/'/g, '"'));
- _.each(selected_groups, function(group_and_label) {
- var group, label;
- group = group_and_label[0];
- label = group_and_label[1];
- Reporting.GroupBys.add_group_by(group, label, container);
- });
- }
- });
- };
-
- return {
- restore_group_bys: restore_group_bys,
- restore_filters: restore_filters
- };
-}(jQuery);
-
-Reporting.onload(function () {
- Reporting.RestoreQuery.restore_group_bys();
- Reporting.RestoreQuery.restore_filters();
-});
diff --git a/frontend/src/app/features/reporting/reporting-page/functionality/tablesorter.ts b/frontend/src/app/features/reporting/reporting-page/functionality/tablesorter.ts
deleted file mode 100644
index 3ed64eff6d3..00000000000
--- a/frontend/src/app/features/reporting/reporting-page/functionality/tablesorter.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import 'tablesorter';
-
-/**
- * Ported from legacy asset pipeline reporting
- */
-
-function initTableSorter() {
- // This prevents the tablesorter plugin to check for metadata which is done
- // using eval which conflicts with our csp.
- // Works because of a check in tablesorter:
- // meta = $.metadata ? $header.metadata() : false;
- jQuery.metadata = undefined;
-
- // Override the default texts to enable translations
- jQuery.tablesorter.language = {
- sortAsc: I18n.t('js.sort.sorted_asc'),
- sortDesc: I18n.t('js.sort.sorted_dsc'),
- sortNone: I18n.t('js.sort.sorted_no'),
- sortDisabled: I18n.t('js.sort.sorting_disabled'),
- nextAsc: I18n.t('js.sort.activate_asc'),
- nextDesc: I18n.t('js.sort.activate_dsc'),
- nextNone: I18n.t('js.sort.activate_no'),
- };
-
- jQuery('#sortable-table')
- .not('.tablesorter')
- .tablesorter({
- sortList: [[0, 0]],
- widgets: ['saveSort'],
- widgetOptions: {
- storage_storageType: 's',
- },
- textExtraction(node:HTMLElement) {
- return node.getAttribute('raw-data');
- },
- });
-}
-
-export function registerTableSorter() {
- jQuery(document).ready(() => {
- initTableSorter();
- });
-
- jQuery(document).ajaxComplete(() => {
- initTableSorter();
- });
-}
diff --git a/frontend/src/app/features/reporting/reporting-page/reporting-page.component.ts b/frontend/src/app/features/reporting/reporting-page/reporting-page.component.ts
deleted file mode 100644
index c432d63a030..00000000000
--- a/frontend/src/app/features/reporting/reporting-page/reporting-page.component.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-import { Component, OnInit, ViewEncapsulation } from '@angular/core';
-import { registerTableSorter } from 'core-app/features/reporting/reporting-page/functionality/tablesorter';
-
-@Component({
- // Empty wrapper around legacy backlogs for CSS loading
- // that got removed in the Rails assets pipeline
- encapsulation: ViewEncapsulation.None,
- template: '',
- styleUrls: [
- './styles/reporting.sass',
- ],
- standalone: true,
-})
-export class ReportingPageComponent implements OnInit {
- async ngOnInit() {
- // @ts-expect-error imported JS is not typed
- await import('./functionality/reporting_engine');
- // @ts-expect-error imported JS is not typed
- await import('./functionality/reporting_engine/filters');
- // @ts-expect-error imported JS is not typed
- await import('./functionality/reporting_engine/group_bys');
- // @ts-expect-error imported JS is not typed
- await import('./functionality/reporting_engine/restore_query');
- // @ts-expect-error imported JS is not typed
- await import('./functionality/reporting_engine/controls');
-
- // Register table sorting functionality after reporting engine loaded
- registerTableSorter();
- }
-}
diff --git a/frontend/src/global_styles/content/_index.sass b/frontend/src/global_styles/content/_index.sass
index 02f9dc70042..3d6c4d37060 100644
--- a/frontend/src/global_styles/content/_index.sass
+++ b/frontend/src/global_styles/content/_index.sass
@@ -83,3 +83,4 @@
@import modules/index
@import user-content/index
@import bim/index
+@import reporting/index
diff --git a/frontend/src/app/features/reporting/reporting-page/styles/reporting.sass b/frontend/src/global_styles/content/reporting/_index.sass
similarity index 95%
rename from frontend/src/app/features/reporting/reporting-page/styles/reporting.sass
rename to frontend/src/global_styles/content/reporting/_index.sass
index 2b1e818d705..8a38ac3b6a3 100644
--- a/frontend/src/app/features/reporting/reporting-page/styles/reporting.sass
+++ b/frontend/src/global_styles/content/reporting/_index.sass
@@ -1,5 +1,3 @@
-@import "../../../../../global_styles/fonts/openproject_icon_definitions"
-@import "../../../../../global_styles/openproject/variables"
@import reporting_group_by
@import reporting_table
@import reporting_table_print
diff --git a/frontend/src/app/features/reporting/reporting-page/styles/_reporting_group_by.sass b/frontend/src/global_styles/content/reporting/_reporting_group_by.sass
similarity index 100%
rename from frontend/src/app/features/reporting/reporting-page/styles/_reporting_group_by.sass
rename to frontend/src/global_styles/content/reporting/_reporting_group_by.sass
diff --git a/frontend/src/app/features/reporting/reporting-page/styles/_reporting_table.sass b/frontend/src/global_styles/content/reporting/_reporting_table.sass
similarity index 100%
rename from frontend/src/app/features/reporting/reporting-page/styles/_reporting_table.sass
rename to frontend/src/global_styles/content/reporting/_reporting_table.sass
diff --git a/frontend/src/app/features/reporting/reporting-page/styles/_reporting_table_print.sass b/frontend/src/global_styles/content/reporting/_reporting_table_print.sass
similarity index 100%
rename from frontend/src/app/features/reporting/reporting-page/styles/_reporting_table_print.sass
rename to frontend/src/global_styles/content/reporting/_reporting_table_print.sass
diff --git a/frontend/src/stimulus/controllers/dynamic/reporting/page.controller.ts b/frontend/src/stimulus/controllers/dynamic/reporting/page.controller.ts
new file mode 100644
index 00000000000..1c6c88b3f07
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/reporting/page.controller.ts
@@ -0,0 +1,825 @@
+/*
+ * -- copyright
+ * OpenProject is an open source project management software.
+ * Copyright (C) the OpenProject GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 3.
+ *
+ * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+ * Copyright (C) 2006-2013 Jean-Philippe Lang
+ * Copyright (C) 2010-2013 the ChiliProject Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * See COPYRIGHT and LICENSE files for more details.
+ * ++
+ */
+
+import { Controller } from '@hotwired/stimulus';
+import * as jQuery from 'jquery';
+import 'tablesorter';
+
+declare global {
+ interface Window {
+ global_prefix?:string;
+ }
+}
+
+interface ShowFilterOptions {
+ callback_func?:() => void;
+ slowly?:boolean;
+ show_filter?:boolean;
+ hide_only?:boolean;
+ insert_after?:HTMLElement;
+}
+
+interface IFilters {
+ loadAvailableValuesForFilter:(filterName:string, callbackFunc:() => void) => void;
+ add_filter:(filterName:string) => void;
+ clear:() => void;
+ exists:(filter:string) => boolean;
+ operator_changed:(field:string, select:JQuery) => void;
+ remove_filter:(field:string, hideOnly?:boolean) => void;
+ select_option_enabled:(box:JQuery, value:string, state:boolean) => void;
+ select_values:(selectBox:JQuery, valuesToSelect:string[]) => void;
+ toggle_multi_select:(select:JQuery) => void;
+ value_changed:(field:string) => void;
+}
+
+interface IGroupBys {
+ group_by_container_ids:() => string[];
+ initialize_drag_and_drop_areas:() => void;
+ add_group_by:(field:string, caption:string, container:JQuery) => void;
+ add_group_by_from_select:(select:HTMLSelectElement) => void;
+ clear:() => void;
+ create_group_by:(field:string, caption:string) => JQuery;
+ exists:(groupByName:string) => boolean;
+}
+
+interface IControls {
+ attach_settings_callback:(element:JQuery, callback:(response:string) => void) => void;
+ clear_query:(e:Event) => void;
+ observe_click:(elementId:string, callback:(e:Event) => void) => void;
+ update_result_table:(response:string) => void;
+ toggle_delete_form:(e:Event) => void;
+ toggle_save_as_form:(e:Event) => void;
+}
+
+interface IRestoreQuery {
+ restore_group_bys:() => void;
+ restore_filters:() => void;
+}
+
+export default class PageController extends Controller {
+ private filters!:IFilters;
+ private groupBys!:IGroupBys;
+ private controls!:IControls;
+ private restoreQueryModule!:IRestoreQuery;
+
+ connect() {
+ this.initializeReportingEngine();
+ this.initializeFilters();
+ this.initializeGroupBys();
+ this.initializeControls();
+ this.restoreQuery();
+ this.initTableSorter();
+ }
+
+ disconnect() {
+ // Clean up event handlers if needed
+ }
+
+ // Called from data-action
+ addFilter(evt:InputEvent) {
+ const target = evt.target as HTMLSelectElement;
+ if (!this.filters.exists(target.value)) {
+ this.filters.add_filter(target.value);
+ const newFilter = target.value;
+ target.selectedIndex = 0;
+ setTimeout(() => {
+ jQuery(`#operators\\[${newFilter}\\]`).focus();
+ }, 300);
+ }
+ }
+
+ /**
+ * Ported from legacy asset pipeline reporting
+ */
+ private initTableSorter() {
+ // This prevents the tablesorter plugin to check for metadata which is done
+ // using eval which conflicts with our csp.
+ // Works because of a check in tablesorter:
+ // @ts-expect-error Prevent metadata from accessing metadata
+ jQuery.metadata = undefined;
+
+ // Override the default texts to enable translations
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ jQuery.tablesorter.language = {
+ sortAsc: I18n.t('js.sort.sorted_asc'),
+ sortDesc: I18n.t('js.sort.sorted_dsc'),
+ sortNone: I18n.t('js.sort.sorted_no'),
+ sortDisabled: I18n.t('js.sort.sorting_disabled'),
+ nextAsc: I18n.t('js.sort.activate_asc'),
+ nextDesc: I18n.t('js.sort.activate_dsc'),
+ nextNone: I18n.t('js.sort.activate_no'),
+ };
+
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
+ jQuery('#sortable-table')
+ .not('.tablesorter')
+ .tablesorter({
+ sortList: [[0, 0]],
+ widgets: ['saveSort'],
+ widgetOptions: {
+ storage_storageType: 's',
+ },
+ textExtraction(node:HTMLElement) {
+ return node.getAttribute('raw-data');
+ },
+ });
+ }
+
+ private flash(string:string, type = 'error') {
+ const options = type === 'error'
+ ? { id: 'errorExplanation', class: 'errorExplanation' }
+ : { id: `flash_${type}`, class: `flash ${type}` };
+
+ jQuery(`#${options.id}`).remove();
+
+ const flashElement = jQuery('<div></div>')
+ .attr('id', options.id)
+ .attr('class', options.class)
+ .attr('tabindex', '0')
+ .attr('role', 'alert')
+ .html(string);
+
+ jQuery('#content').prepend(flashElement);
+ jQuery(`#${options.id}`).focus();
+ }
+
+ private clearFlash() {
+ jQuery('div[id^=flash]').remove();
+ }
+
+ private fireEvent(element:HTMLElement, event:string) {
+ const evt = new Event(event, { bubbles: true, cancelable: true });
+ return !element.dispatchEvent(evt);
+ }
+
+ private initializeReportingEngine() {
+ // The main reporting methods are now instance methods on this controller
+ }
+
+ private initializeFilters() {
+ this.filters = {
+ loadAvailableValuesForFilter: (filterName:string, callbackFunc:() => void) => {
+ const select = jQuery(`.filter-value[data-filter-name="${filterName}"]`).first();
+ const radioOptions = jQuery(`.${filterName}_radio_option input`);
+
+ if (radioOptions && radioOptions.length !== 0) {
+ (radioOptions.first()[0] as HTMLInputElement).checked = true;
+ callbackFunc();
+ }
+
+ if (!select.length) {
+ return;
+ }
+
+ if (select.attr('data-loading') === 'ajax' && select.children().length === 0) {
+ this.loadAvailableValuesForFilterFromRemote(select, filterName, callbackFunc);
+ this.multiSelect(select, false);
+ } else {
+ callbackFunc();
+ }
+ },
+
+ add_filter: (filterName:string) => {
+ this.selectOptionEnabled(jQuery('#add_filter_select'), filterName, false);
+ this.showFilter(filterName, { slowly: true });
+ },
+
+ clear: () => {
+ this.visibleFilters().forEach((filter) => {
+ this.filters.remove_filter(filter);
+ });
+ },
+
+ exists: (filter:string) => {
+ return this.visibleFilters().includes(filter);
+ },
+
+ operator_changed: (field:string, select:JQuery) => {
+ this.operatorChanged(field, select);
+ },
+
+ remove_filter: (field:string, hideOnly = false) => {
+ this.showFilter(field, { show_filter: false, hide_only: hideOnly });
+ this.selectOptionEnabled(jQuery('#add_filter_select'), field, true);
+ },
+
+ select_option_enabled: (box:JQuery, value:string, state:boolean) => {
+ this.selectOptionEnabled(box, value, state);
+ },
+
+ select_values: (selectBox:JQuery, valuesToSelect:string[]) => {
+ this.selectValues(selectBox, valuesToSelect);
+ },
+
+ toggle_multi_select: (select:JQuery) => {
+ this.multiSelect(select, !select.attr('multiple'));
+ },
+
+ value_changed: (field:string) => {
+ this.valueChanged(field);
+ },
+ };
+
+ jQuery('.filter_rem')
+ .on('click', (event) => {
+ event.preventDefault();
+ const filterName = jQuery(event.target).closest('li').attr('data-filter-name');
+ if (filterName) {
+ this.filters.remove_filter(filterName);
+ }
+ })
+ .on('keydown', (event) => {
+ if (event.keyCode === 13 || event.keyCode === 32) {
+ event.preventDefault();
+ const filterName = jQuery(event.target).closest('li').attr('data-filter-name');
+ const prevVisibleFilter = jQuery(event.target).closest('li').prevAll(':visible').last()
+ .find('.advanced-filters--select');
+
+ if (prevVisibleFilter.length > 0) {
+ prevVisibleFilter.focus();
+ } else {
+ jQuery('#filters > legend a')[0]?.focus();
+ }
+ if (filterName) {
+ this.filters.remove_filter(filterName);
+ }
+ }
+ });
+
+ jQuery('.filter_operator')
+ .on('change', (evt) => {
+ const target = evt.target as HTMLSelectElement;
+ const filterName = jQuery(target).attr('data-filter-name');
+ if (filterName) {
+ this.filters.operator_changed(filterName, jQuery(target));
+ const argVal = jQuery(`#${filterName}_arg_1_val`)[0];
+ if (argVal) {
+ this.fireEvent(argVal, 'change');
+ }
+ }
+ });
+
+ jQuery('.filter_multi-select')
+ .on('click', (e) => {
+ const target = e.target;
+ const filterName = jQuery(target).attr('data-filter-name');
+ if (filterName) {
+ this.filters.toggle_multi_select(jQuery(`#${filterName}_arg_1_val`));
+ }
+ });
+
+ jQuery('.advanced-filters--filter-value .filter-value').each((index, element) => {
+ const select = jQuery(element);
+ const selectValue = select.val();
+
+ if (element.tagName.toLowerCase() !== 'opce-project-autocompleter') {
+ const isMultiple = selectValue && Array.isArray(selectValue) && selectValue.length > 1;
+ select.attr('multiple', isMultiple ? 'multiple' : null);
+ }
+
+ select.on('change', (evt) => {
+ const filterName = jQuery(evt.target).closest('li').attr('data-filter-name');
+ if (filterName) {
+ this.filters.value_changed(filterName);
+ }
+ });
+ });
+ }
+
+ private loadAvailableValuesForFilterFromRemote(select:JQuery, filterName:string, callbackFunc:() => void) {
+ const url = select.attr('data-remote-url');
+ const jsonPostSelectValues = select.attr('data-initially-selected');
+ let postSelectValues:string[]|undefined;
+
+ if (jsonPostSelectValues !== null && jsonPostSelectValues !== undefined) {
+ postSelectValues = JSON.parse(jsonPostSelectValues.replace(/'/g, '"')) as string[];
+ }
+
+ if (window.global_prefix === undefined) {
+ window.global_prefix = '';
+ }
+
+ void jQuery.ajax({
+ url,
+ method: 'POST',
+ data: {
+ filter_name: filterName,
+ values: jsonPostSelectValues,
+ },
+ beforeSend: () => {
+ jQuery(`select[data-filter-name='${filterName}']`).prop('disabled', true);
+ jQuery('#ajax-indicator').show();
+ },
+ complete: (xhr) => {
+ const tagName = select.prop('tagName') as string;
+
+ select.html(xhr.responseText);
+ jQuery(`select[data-filter-name='${filterName}']`).removeProp('disabled');
+
+ if (tagName && tagName.toLowerCase() === 'select') {
+ if (!postSelectValues || postSelectValues.length === 0) {
+ (select[0] as HTMLSelectElement).selectedIndex = 0;
+ } else {
+ this.selectValues(select, postSelectValues);
+ }
+ }
+ callbackFunc();
+ },
+ });
+ }
+
+ private multiSelect(select:JQuery, multi:boolean) {
+ select.attr('multiple', multi ? 'multiple' : null);
+ if (multi) {
+ select.attr('size', 4);
+ if (select.find('option')[0]) {
+ select.find('option').first().removeAttr('selected');
+ }
+ } else {
+ select.attr('size', 1);
+ }
+ }
+
+ private selectValues(selectBox:JQuery, valuesToSelect:string[]) {
+ this.multiSelect(selectBox, valuesToSelect.length > 1);
+ selectBox.val(valuesToSelect);
+ }
+
+ private showFilter(field:string, options:ShowFilterOptions = {}) {
+ const defaultOptions = {
+ callback_func: () => {
+ },
+ slowly: false,
+ show_filter: true,
+ hide_only: false,
+ };
+
+ options = { ...defaultOptions, ...options };
+
+ const fieldEl = jQuery(`#filter_${field}`);
+ if (fieldEl.length) {
+ if (!options.insert_after) {
+ options.insert_after = this.lastVisibleFilter();
+ }
+
+ if (options.insert_after && options.show_filter) {
+ if (fieldEl.attr('id') !== options.insert_after.id) {
+ fieldEl.detach();
+ jQuery(`#${options.insert_after.id}`).after(fieldEl);
+ }
+ }
+
+ if (options.show_filter) {
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
+ options.slowly ? fieldEl.fadeIn('slow') : fieldEl.show();
+ this.filters.loadAvailableValuesForFilter(field, options.callback_func || (() => {
+ }));
+ jQuery(`#rm_${field}`).val(field);
+ this.valueChanged(field);
+ } else {
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
+ options.slowly ? fieldEl.fadeOut('slow') : fieldEl.hide();
+
+ if (!options.hide_only) {
+ fieldEl.removeAttr('data-selected');
+ }
+ jQuery(`#rm_${field}`).val('');
+ }
+
+ this.operatorChanged(field, jQuery(`#operators\\[${field}\\]`));
+ this.displayCategory(jQuery(`#${fieldEl.attr('data-label')}`));
+ }
+ }
+
+ private lastVisibleFilter() {
+ return jQuery('.advanced-filters--filter:visible').last()[0];
+ }
+
+ private displayCategory(label:JQuery) {
+ if (label.length) {
+ jQuery('.advanced-filters--filter').each(() => {
+ const filter = jQuery(this);
+ if (filter.is(':visible') && filter.attr('data-label') === label.attr('id')) {
+ label.show();
+ return;
+ }
+ label.hide();
+ });
+ }
+ }
+
+ private operatorChanged(field:string, select:JQuery) {
+ if (!select || !select.length) {
+ return;
+ }
+ const optionTag = select.find(`option[value="${select.val() as string}"]`);
+ const arity = parseInt(optionTag.attr('data-arity') as string, 10);
+ const forcedType = optionTag.attr('data-forced') as string;
+ this.changeArgumentVisibility(field, arity, forcedType);
+ }
+
+ private valueChanged(field:string) {
+ const val = jQuery(`#${field}_arg_1_val`);
+ const filter = jQuery(`#filter_${field}`);
+ if (!val.length) {
+ return;
+ }
+ if ((val[0] as HTMLInputElement).value === '<<inactive>>') {
+ filter.addClass('inactive-filter');
+ } else {
+ filter.removeClass('inactive-filter');
+ }
+ }
+
+ private knownForcedTypes = ['integers'];
+
+ private changeArgumentVisibility(fieldName:string, argNr:number, forcedType:string) {
+ const fields:[string, boolean][] = [
+ [`#${fieldName}_arg_1`, [1, 2, -1].includes(argNr)],
+ [`#${fieldName}_arg_2`, argNr === 2],
+ ];
+
+ // eslint-disable-next-line no-restricted-syntax
+ for (const [fieldSelector, active] of fields) {
+ this.setActiveState(fieldSelector, active && !forcedType);
+ this.knownForcedTypes.forEach((knownForcedType) => {
+ this.setActiveState(`${fieldSelector}_${knownForcedType}`, active && forcedType === knownForcedType);
+ });
+ }
+ }
+
+ private setActiveState(selector:string, active:boolean) {
+ const input = document.querySelector(selector) as HTMLElement;
+
+ if (!input) {
+ return;
+ }
+
+ input.hidden = !active;
+ Array.from(input.children).forEach((child) => {
+ (child as HTMLElement).hidden = !active;
+ (child as HTMLInputElement).disabled = !active;
+ });
+ }
+
+ private selectOptionEnabled(box:JQuery, value:string, state:boolean) {
+ box.find(`[value='${value}']`).attr('disabled', state ? null : 'disabled');
+ }
+
+ private visibleFilters() {
+ return jQuery('#filter_table .advanced-filters--filter:visible')
+ .map((i, el) => el.dataset.filterName)
+ .get();
+ }
+
+ private initializeGroupBys() {
+ this.groupBys = {
+ group_by_container_ids: ():string[] => {
+ const ids = ['group-by--columns', 'group-by--rows'];
+ return ids.filter((id) => jQuery(`#${id}`).length > 0);
+ },
+
+ initialize_drag_and_drop_areas: () => {
+ this.recreateSortables();
+ },
+
+ add_group_by: (field:string, caption:string, container:JQuery) => {
+ const groupBy = this.createGroupBy(field, caption);
+ const addedContainer = container.find('.group-by--selected-elements');
+ addedContainer.append(groupBy);
+ this.addingGroupByEnabled(field, false);
+ },
+
+ add_group_by_from_select: (select:HTMLSelectElement) => {
+ const jselect = jQuery(select);
+ const field = jselect.val() as string;
+ const container = jselect.closest('.group-by--container');
+ const selectedOption = jselect.find(`[value='${field}']`).first();
+ const caption = selectedOption.attr('data-label') || '';
+
+ this.groupBys.add_group_by(field, caption, container);
+ jselect.find('[value=\'\']').first().attr('selected', 'selected');
+ },
+
+ clear: () => {
+ this.visibleGroupBys().forEach((groupBy:string) => {
+ jQuery(`#${groupBy} .group-by--selected-element`).each((index, element) => {
+ this.removeGroupBy(jQuery(element));
+ });
+ });
+ },
+
+ create_group_by: (field:string, caption:string) => {
+ return this.createGroupBy(field, caption);
+ },
+
+ exists: (groupByName:string) => {
+ return this.visibleGroupBys().some((grp) =>
+ jQuery(`#${grp}`).attr('data-group-by') === groupByName);
+ },
+ };
+
+ // Initialize drag and drop
+ this.groupBys.initialize_drag_and_drop_areas();
+
+ // Bind group-by events
+ jQuery('#group-by--add-rows, #group-by--add-columns').on('change', (event) => {
+ const target = event.target as HTMLSelectElement;
+ if (!this.groupBys.exists(target.value)) {
+ this.groupBys.add_group_by_from_select(target);
+ }
+ });
+ }
+
+ private recreateSortables() {
+ const containers = jQuery('.group-by--selected-elements').toArray();
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any
+ (dragula as any)(containers, {
+ mirrorContainer: document.getElementById('group-by--area'),
+ });
+ }
+
+ private createLabel(groupBy:JQuery, text:string) {
+ const groupById = groupBy.attr('id') || '';
+ return jQuery('<label></label>')
+ .attr('class', 'in_row group-by--label')
+ .attr('for', groupById)
+ .attr('id', `${groupById}_label`)
+ .attr('title', text)
+ .text(text);
+ }
+
+ private createRemoveButton(groupBy:JQuery) {
+ const removeLink = jQuery('<a></a>')
+ .attr('class', 'group-by--remove in_row')
+ .attr('id', `${groupBy.attr('id')}_remove`)
+ .attr('href', '');
+
+ const removeIcon = jQuery('<span><span>')
+ .attr('class', 'icon-context icon-close icon4');
+
+ const title = `${window.I18n.t('js.reporting_engine.label_remove')} ${groupBy.find('label').html()}`;
+ removeLink.attr('title', title);
+ removeIcon.attr('alt', title);
+
+ removeLink.on('click', (e) => {
+ e.preventDefault();
+ this.removeElementEventAction(groupBy, removeLink);
+ });
+
+ removeLink.on('keypress', (e) => {
+ if (e.keyCode === 32) {
+ e.preventDefault();
+ this.removeElementEventAction(groupBy, removeLink);
+ }
+ });
+
+ removeLink.append(removeIcon);
+ return removeLink;
+ }
+
+ private removeElementEventAction(groupBy:JQuery, button:JQuery) {
+ const linkNode = groupBy.next('span').find('a');
+ const selectNode = groupBy.next('select');
+
+ if (linkNode.length) {
+ linkNode.focus();
+ } else if (selectNode.length) {
+ selectNode.focus();
+ }
+
+ this.removeGroupBy(button.closest('.group-by--selected-element'));
+ }
+
+ private createGroupBy(field:string, caption:string) {
+ const groupBy = jQuery('<span></span>')
+ .attr('class', 'group-by--selected-element')
+ .attr('data-group-by', field);
+
+ groupBy.uniqueId(); // give it a unique id
+
+ const label = this.createLabel(groupBy, caption);
+ groupBy.append(label);
+
+ const removeButton = this.createRemoveButton(groupBy);
+ groupBy.append(removeButton);
+
+ return groupBy;
+ }
+
+ private addingGroupByEnabled(field:string, state:boolean) {
+ ['#group-by--add-columns', '#group-by--add-rows'].forEach((containerId) => {
+ this.filters.select_option_enabled(jQuery(containerId), field, state);
+ });
+ }
+
+ private removeGroupBy(groupBy:JQuery) {
+ this.addingGroupByEnabled(groupBy.attr('data-group-by') as string, true);
+ groupBy.remove();
+ }
+
+ private visibleGroupBys():string[] {
+ return this.groupBys.group_by_container_ids().filter((container:string) =>
+ jQuery(`#${container}`).find('[data-group-by]').length > 0);
+ }
+
+ private initializeControls() {
+ this.controls = {
+ attach_settings_callback: (element:JQuery, callback:(response:string) => void) => {
+ this.attachSettingsCallback(element, callback);
+ },
+
+ clear_query: (e:Event) => {
+ e.preventDefault();
+ this.filters.clear();
+ this.groupBys.clear();
+ },
+
+ observe_click: (elementId:string, callback:(e:Event) => void) => {
+ jQuery(`#${elementId}`).on('click', callback);
+ },
+
+ update_result_table: (response:string) => {
+ jQuery('#result-table').html(response);
+ this.initTableSorter();
+ },
+
+ toggle_delete_form: (e:Event) => {
+ e.preventDefault();
+ const offset = jQuery('#query-icon-delete').offset()?.left || 0;
+ jQuery('#delete_form').css('left', `${offset}px`).toggle();
+ },
+
+ toggle_save_as_form: (e:Event) => {
+ e.preventDefault();
+ const offset = jQuery('#query-icon-save-as').offset()?.left || 0;
+ jQuery('#save_as_form').css('left', `${offset}px`).toggle();
+ },
+ };
+
+ // Bind control events
+ if (jQuery('#query_saved_name').length) {
+ if (jQuery('#query_saved_name').attr('data-is_new')) {
+ if (jQuery('#query-icon-delete').length) {
+ this.controls.observe_click('query-icon-delete', this.controls.toggle_delete_form);
+ this.controls.observe_click('query-icon-delete-cancel', this.controls.toggle_delete_form);
+ jQuery('#delete_form').hide();
+ }
+
+ if (jQuery('#query-breadcrumb-save').length) {
+ this.controls.attach_settings_callback(jQuery('#query-breadcrumb-save'), this.controls.update_result_table);
+ }
+ }
+ }
+
+ this.controls.observe_click('query-icon-save-as', this.controls.toggle_save_as_form);
+ this.controls.observe_click('query-icon-save-as-cancel', this.controls.toggle_save_as_form);
+
+ jQuery('#save_as_form').hide();
+
+ this.controls.attach_settings_callback(jQuery('#query-icon-save-button'), (newLocation:string) => {
+ document.location.href = newLocation;
+ });
+
+ this.controls.attach_settings_callback(jQuery('#query-icon-apply-button'), this.controls.update_result_table);
+
+ this.controls.observe_click('query-link-clear', this.controls.clear_query);
+ }
+
+ private attachSettingsCallback(element:JQuery, callback:(response:string) => void) {
+ if (!element || !element.length) {
+ return;
+ }
+
+ const failureCallback = (response:JQuery.jqXHR) => {
+ jQuery('#result-table').html('');
+ this.defaultFailureCallback(response);
+ };
+
+ element.on('click', (e:Event) => {
+ e.preventDefault();
+ const target = jQuery(e.target as HTMLElement).closest('[data-target]').attr('data-target');
+ this.sendSettingsData(target || '', callback, failureCallback);
+ });
+ }
+
+ private sendSettingsData(targetUrl:string, callback:(response:string) => void, failureCallback?:(response:JQuery.jqXHR) => void) {
+ const errorCallback = failureCallback || this.defaultFailureCallback;
+ this.clearFlash();
+
+ void jQuery.ajax({
+ url: targetUrl,
+ method: 'POST',
+ data: this.serializeSettingsForm(),
+ beforeSend: () => {
+ jQuery('#ajax-indicator').show();
+ },
+ error: errorCallback,
+ success: callback,
+ });
+ }
+
+ private serializeSettingsForm() {
+ let retStr = jQuery('#query_form').serialize();
+ const groupingStr = ['rows', 'columns'].reduce((grouping, type) => {
+ const elementMap = jQuery(`#group-by--${type} .group-by--selected-element`)
+ .map((i, el) => {
+ return `groups[${type}][]=${el.dataset.groupBy as string}`;
+ })
+ .get();
+
+ return grouping + elementMap.reduce((allGroupStr, groupStr) => {
+ return `${allGroupStr}&${groupStr}`;
+ }, '');
+ }, '');
+
+ if (groupingStr.length > 0) {
+ retStr += groupingStr;
+ }
+ return retStr;
+ }
+
+ private defaultFailureCallback = (response:JQuery.jqXHR) => {
+ if (response.status >= 400 && response.status < 500) {
+ this.flash(response.responseText);
+ } else {
+ this.flash(window.I18n.t('js.reporting_engine.label_response_error'));
+ }
+ };
+
+ private restoreQuery() {
+ this.restoreQueryModule = {
+ restore_group_bys: () => {
+ this.groupBys.group_by_container_ids().forEach((id:string) => {
+ const container = jQuery(`#${id}`);
+ const selectedContainers = container.attr('data-initially-selected');
+
+ if (selectedContainers) {
+ const selectedGroups = JSON.parse(selectedContainers.replace(/'/g, '"')) as (string[])[];
+ selectedGroups.forEach((groupAndLabel:[string, string]) => {
+ const [group, label] = groupAndLabel;
+ this.groupBys.add_group_by(group, label, container);
+ });
+ }
+ });
+ },
+
+ restore_filters: () => {
+ jQuery('.advanced-filters--select.filter-value').each((index, element) => {
+ const jselect = jQuery(element);
+ const tr = jselect.closest('li');
+
+ if (tr.is(':visible')) {
+ const filter = tr.attr('data-filter-name');
+ const dependent = jselect.attr('data-dependent');
+
+ if (filter && dependent) {
+ this.filters.remove_filter(filter, false);
+ }
+ }
+ });
+
+ jQuery('li.advanced-filters--filter[data-selected=true]').each((index, element) => {
+ const filter = jQuery(element);
+ const select = filter.find('.advanced-filters--filter-value select');
+ if (select.length && select.attr('data-dependent')) return;
+ const filterName = filter.attr('data-filter-name');
+ if (filterName) {
+ this.filters.add_filter(filterName);
+ }
+ });
+ },
+ };
+
+ // Execute restore operations
+ this.restoreQueryModule.restore_group_bys();
+ this.restoreQueryModule.restore_filters();
+ }
+}
diff --git a/modules/reporting/app/views/cost_reports/index.html.erb b/modules/reporting/app/views/cost_reports/index.html.erb
index f49f8fb7f75..0133a89594b 100644
--- a/modules/reporting/app/views/cost_reports/index.html.erb
+++ b/modules/reporting/app/views/cost_reports/index.html.erb
@@ -35,7 +35,7 @@ See COPYRIGHT and LICENSE files for more details.
<% html_title (@query.persisted? ? "#{t(:label_cost_report)}: #{@query.name}" : t(:label_new_report)) %>
-<%= angular_component_tag "opce-reporting-page" %>
+<% content_controller "reporting--page" %>
<%= render CostReports::IndexPageHeaderComponent.new(query: @query, project: @project) %>
diff --git a/modules/reporting/lib/widget/filters.rb b/modules/reporting/lib/widget/filters.rb
index 0ce8841307b..df020b78446 100644
--- a/modules/reporting/lib/widget/filters.rb
+++ b/modules/reporting/lib/widget/filters.rb
@@ -47,6 +47,9 @@ class Widget::Filters < Widget::Base
select_tag "add_filter_select",
options_for_select([["", ""]] + selectables),
class: "advanced-filters--select",
+ data: {
+ action: "reporting--page#addFilter"
+ },
name: nil
end
diff --git a/modules/reporting/spec/features/support/pages/cost_report_page.rb b/modules/reporting/spec/features/support/pages/cost_report_page.rb
index c10eeac31c7..dc739ef7a60 100644
--- a/modules/reporting/spec/features/support/pages/cost_report_page.rb
+++ b/modules/reporting/spec/features/support/pages/cost_report_page.rb
@@ -79,17 +79,9 @@ module Pages
end
end
- def show_loading_indicator(present: true)
- if present
- expect(page).to have_css("#ajax-indicator")
- else
- expect(page).to have_no_css("#ajax-indicator")
- end
- end
-
def wait_for_page_to_reload
- show_loading_indicator
- show_loading_indicator(present: false)
+ wait_for_network_idle
+ expect(page).to have_no_css("#ajax-indicator")
end
def path
diff --git a/modules/reporting/spec/features/update_cost_report_spec.rb b/modules/reporting/spec/features/update_cost_report_spec.rb
index 6aff880082c..e97abb4ee80 100644
--- a/modules/reporting/spec/features/update_cost_report_spec.rb
+++ b/modules/reporting/spec/features/update_cost_report_spec.rb
@@ -29,7 +29,7 @@
require_relative "../spec_helper"
require_relative "support/pages/cost_report_page"
-RSpec.describe "updating a cost report's cost type", :js, :selenium do
+RSpec.describe "updating a cost report's cost type", :js do
let(:project) { create(:project_with_types, members: { user => create(:project_role) }) }
let(:user) do
create(:admin)
diff --git a/modules/reporting/spec/features/update_entries_spec.rb b/modules/reporting/spec/features/update_entries_spec.rb
index ceb318a6efa..eac0d367e7b 100644
--- a/modules/reporting/spec/features/update_entries_spec.rb
+++ b/modules/reporting/spec/features/update_entries_spec.rb
@@ -66,7 +66,7 @@ RSpec.describe "Updating entries within the cost report", :js do
visit cost_reports_path(project)
report_page.clear
report_page.apply
- report_page.show_loading_indicator present: false
+ report_page.wait_for_page_to_reload
end
it "can edit and delete time entries" do
@@ -85,7 +85,7 @@ RSpec.describe "Updating entries within the cost report", :js do
table.rows_count 1
report_page.switch_to_type "My cool type"
- report_page.show_loading_indicator present: false
+ report_page.wait_for_page_to_reload
table.rows_count 1
@@ -109,7 +109,7 @@ RSpec.describe "Updating entries within the cost report", :js do
# Force a reload of the table (although nothing has changed)
report_page.apply
sleep(1)
- report_page.show_loading_indicator present: false
+ report_page.wait_for_page_to_reload
table.rows_count 1