Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .sequelizerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const path = require('path');

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions app/public/components/buttons/dataActionButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export default function dataActionButtons(model, applicableDataActions, dataMode

applicableDataActions[dataActions.showFilteringPanel] && dataModel
? h('button.btn.icon-only-button', {
className: dataModel.filterPanelVisible ? 'btn-primary' : 'btn-secondary',
className: dataModel.isFilterPanelVisible ? 'btn-primary' : 'btn-secondary',
onclick: () => dataModel.toggleFilterPanelVisibility(),
}, dataModel.filterPanelVisible ? h('.slider-20-off-white.abs-center') : h('.slider-20-primary.abs-center'))
}, dataModel.isFilterPanelVisible ? h('.slider-20-off-white.abs-center') : h('.slider-20-primary.abs-center'))
: '');
}
2 changes: 1 addition & 1 deletion app/public/components/flags/flagsVisualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import { h } from '/js/src/index.js';
import flagVisualization from './flagVisualization.js';
import { RCT } from '../../../../config.js';
import { RCT } from '../../config.js';
const { flagReasonColors } = RCT.quality;

function filterDistinct(a) {
Expand Down
2 changes: 1 addition & 1 deletion app/public/model/data/FetchedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

const defaultPageNumber = 1;

import { RCT } from '../../../config.js';
import { RCT } from '../../config.js';
import { shouldDisplayDetectorField } from '../../utils/dataProcessing/dataProcessingUtils.js';
const DRF = RCT.dataResponseFields;

Expand Down
12 changes: 6 additions & 6 deletions app/public/model/filtering/FilterModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ export default class FilterModel extends Observable {
}
}

buildSingleFilterPhrase(field, type, value) {
return `filter[${field}]${this.buildOperatorPhrase(type, value)}`;
}

get filterObjects() {
return Object.entries(this._activeFilters)
.map(([field, typeToValues]) =>
Object.entries(typeToValues)
.map(([type, values]) => values.map((value) => ({ field, type, value })))).flat(2);
}

isAnyFilterActive() {
get isAnyFilterActive() {
return Object.keys(this._activeFilters).length > 0;
}

buildSingleFilterPhrase(field, type, value) {
return `filter[${field}]${this.buildOperatorPhrase(type, value)}`;
}

buildFilterPhrase() {
get filterPhrase() {
return this.filterObjects.map(({ field, type, value }) => this.buildSingleFilterPhrase(field, type, value)).join('&');
}
}
4 changes: 2 additions & 2 deletions app/public/views/flags/overview/flagsContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import { h } from '/js/src/index.js';
import flagsVisualization from '../../../components/flags/flagsVisualization.js';
import flagsTable from './flagsTable.js';
import flagBreadCrumbs from '../../../../components/flags/flagBreadcrumbs.js';
import { noRunNumbers } from '../../../../utils/defaults.js';
import flagBreadCrumbs from '../../../components/flags/flagBreadcrumbs.js';
import { noRunNumbers } from '../../../utils/defaults.js';
import noSubPageSelected from '../../userView/data/table/noSubPageSelected.js';
import dataActionButtons, { dataActions } from '../../../components/buttons/dataActionButtons.js';

Expand Down
2 changes: 1 addition & 1 deletion app/public/views/flags/overview/flagsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* or submit itself to any jurisdiction.
*/

import { noRunNumbers } from '../../../../utils/defaults.js';
import { noRunNumbers } from '../../../utils/defaults.js';
import noSubPageSelected from '../../userView/data/table/noSubPageSelected.js';
import flagsContent from './flagsContent.js';

Expand Down
2 changes: 1 addition & 1 deletion app/public/views/flags/overview/flagsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

import { h } from '/js/src/index.js';
import { RCT } from '../../../../config.js';
import { RCT } from '../../../config.js';
import flagsTableHeader from '../table/flagsTableHeader.js';
import flagsTableRow from '../table/flagsTableRow.js';
import pagesCellsSpecials from '../../userView/data/pagesCellsSpecials.js';
Expand Down
12 changes: 6 additions & 6 deletions app/public/views/periods/PeriodsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default class PeriodsModel extends Observable {
});
this._fields = periodsActiveColumns;

this._filterPanelVisible = false;
this._isFilterPanelVisible = false;
this._shouldHideSelectedPeriods = false;
this._sortingRowVisible = false;

Expand Down Expand Up @@ -75,7 +75,7 @@ export default class PeriodsModel extends Observable {

this._allPeriods = RemoteData.notAsked();

const endpoint = `/api/periods/?${encodeURI(this._filtering.buildFilterPhrase())}`;
const endpoint = `/api/periods/?${encodeURI(this._filtering.filterPhrase)}`;
try {
const { items, totalCount } = await getRemoteDataSlice(endpoint);
this._allPeriods = RemoteData.success([...items]);
Expand All @@ -97,7 +97,7 @@ export default class PeriodsModel extends Observable {
* @type {Period[]}
*/

const filterPhrase = this._filtering.buildFilterPhrase();
const { filterPhrase } = this._filtering;

if (this._allPeriods.kind === 'NotAsked') {
await this.fetchAllPeriods();
Expand Down Expand Up @@ -177,8 +177,8 @@ export default class PeriodsModel extends Observable {
return Object.keys(this._fields).map((field) => ({ ...this._fields[field] })).filter((field) => field.visible);
}

get filterPanelVisible() {
return this._filterPanelVisible;
get isFilterPanelVisible() {
return this._isFilterPanelVisible;
}

get fields() {
Expand All @@ -202,7 +202,7 @@ export default class PeriodsModel extends Observable {
}

toggleFilterPanelVisibility() {
this._filterPanelVisible = !this._filterPanelVisible;
this._isFilterPanelVisible = !this._isFilterPanelVisible;
this.notify();
}

Expand Down
4 changes: 2 additions & 2 deletions app/public/views/periods/overview/periodsContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export default function periodsContent(periodsModel, model) {
title(pageName)),
dataActionButtons(dataAccess, applicableDataActions, periodsModel)),

periodsModel.filterPanelVisible ? filteringPanel(periodsModel) : '',
periodsModel.filtering.isAnyFilterActive() ? activeFilters(periodsModel.filtering) : '',
periodsModel.isFilterPanelVisible ? filteringPanel(periodsModel) : '',
periodsModel.filtering.isAnyFilterActive ? activeFilters(periodsModel.filtering) : '',

periods.length > 0
? periodsModel.visibleFields.length > 0
Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
"eslint:show:linux": "npm run eslint; firefox ./reports/static/static-analysis.html",
"eslint:show:macos": "npm run eslint; open -a firefox ./reports/static/static-analysis.html",
"static": "npm run eslint",
"coverage:test": "mocha --exit test/* $MOCHA_OPTIONS",
"coverage:test": "bash -c \"$( echo \"mocha --exit test/* $MOCHA_OPTIONS\" )\" ",
"coverage:report": "nyc report --report=html --report=json",
"coverage": "nyc npm run coverage:test && npm run coverage:report",
"start:test": "npm run coverage",
"setup:test": "./scripts/setup-frontend-on-mocha-tests-environemt.sh",
"start:test": "npm run setup:test && npm run coverage",
"reports:show": "open ./reports/**/*.html",
"reports:clean": "rm -rf ./reports; rm -rf .nyc_output",
"start:dev": "nodemon app/main.js --watch main.js --watch app --ignore app/public",
Expand Down Expand Up @@ -71,6 +72,7 @@
"chai": "^4.3.6",
"eslint": "^8.49.0",
"eslint-output": "^3.0.1",
"esm-wallaby": "^3.2.26",
"mocha": "^10.1.0",
"nodemon": "^3.0.1",
"nyc": "^15.1.0",
Expand Down
66 changes: 66 additions & 0 deletions scripts/setup-frontend-on-mocha-tests-environemt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

usage() {
cat << USAGE >&2

The script adjust @aliceo2/web-ui frontend dependencies
to be used within backend unit test environment with mocha.
The only and the first (optional) argument is path
to node_modules directory where the framework is installed.
It is resolved to <THIS_SCRIPT_DIR>/../node_modules by default.

USAGE
exit 1;
}


if [ "$RUNNING_ENV" != 'DOCKER' ]; then
echo \
"Warning!!! This script is intended
to setup environment in docker container.
If, indeed, it was an attempt to run on docker
container check whether env var RUNNING_ENV has
proper value assign, it should be 'DOCKER' ";
exit 1;
fi


NODE_MODULES_DIR_PATH=${1:-$(dirname $(realpath $0) )/../node_modules}
if [ -z "$NODE_MODULES_DIR_PATH" ]; then
echo "Path to node_modules not specified, it must be given as first argument";
fi

FRONTEND_DIR="$NODE_MODULES_DIR_PATH/@aliceo2/web-ui/Frontend/";

SRC_MOCHA_CODE=$(dirname $0)/web-ui-renderers.mocha.js;



NODEJS_WINDOW_CODE="
// Provide pseudo window object with uploaded mithril
const m = () => ({});
m.render = () => ({});
const window = {
location: new URL('http://localhost:8081/?personid=0&name=_&token=_&username=_&access=_'),
history: {
replaceState: () => ({}),
},
m,
requestAnimationFrame: () => ({}),
cancelAnimationFrame: () => ({}),
};
"

rm -rf /js
if ! cp -r $FRONTEND_DIR/js /js; then
usage
fi

TARGET_SRC_DIR=/js/src/
for fp in $(ls $TARGET_SRC_DIR ); do
FPATH=$TARGET_SRC_DIR/$fp;
echo "$NODEJS_WINDOW_CODE" $'\n' "$(cat $FPATH)" > $FPATH;
done;

FILE_TO_BE_REPLACED_PATH="/js/src/renderer.js";
echo "$( cat "$FILE_TO_BE_REPLACED_PATH" | grep -v "import '/mithril/mithril.min.js'" )" > "$FILE_TO_BE_REPLACED_PATH";
2 changes: 2 additions & 0 deletions test/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
const UtilitiesSuite = require('./utils');
const ComponentsSuite = require('./components');
const PeriodsSuite = require('./periods');
const ModelsSuite = require('./models');

module.exports = () => {
describe('Components', ComponentsSuite);
describe('Utilities', UtilitiesSuite);
describe('Periods', PeriodsSuite);
describe('Models', ModelsSuite);
};
76 changes: 76 additions & 0 deletions test/public/models/FilterModel.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

const req = require('esm-wallaby')(module);
const assert = require('assert');

const FilterModel = req('../../../app/public/model/filtering/FilterModel.js').default;

module.exports = () => {
describe('Class instance creation', () => {
const filterModel = new FilterModel();
it('should instantiate the class with no active filters', () => {
assert.equal(filterModel.isAnyFilterActive, false);
});
});

describe('Adding a new filter', () => {
const filterModel = new FilterModel();
it('should add a new filter', () => {
filterModel.addFilter('name', 'LHC', 'match');
filterModel.addFilter('name', 'zt', 'exclude');

const expectedFilterObjects = [
{ field: 'name', type: 'match', value: 'LHC' },
{ field: 'name', type: 'exclude', value: 'zt' },
];
assert.equal(filterModel.isAnyFilterActive, true);
assert.deepEqual(filterModel.filterObjects, expectedFilterObjects);
});
});

describe('Removing filters', () => {
const filterModel = new FilterModel();
filterModel.addFilter('name', 'LHC', 'match');
filterModel.addFilter('name', 'zt', 'exclude');

it('should remove a specified filter', () => {
filterModel.removeFilter('name', 'zt', 'exclude');

const expectedFilterObjects = [{ field: 'name', type: 'match', value: 'LHC' }];
assert.deepEqual(filterModel.filterObjects, expectedFilterObjects);
});
});

describe('Reseting', () => {
const filterModel = new FilterModel();
filterModel.addFilter('name', 'LHC', 'match');
filterModel.addFilter('name', 'zt', 'exclude');

it('should reset the filter model', () => {
filterModel.reset();
assert.equal(filterModel.isAnyFilterActive, false);
});
});

describe('Building filter phrases', () => {
const filterModel = new FilterModel();
filterModel.addFilter('year', '2020', 'from');

const expectedFilterPhrase = 'filter[year][gte]=2020';

it('should build a correct filter phrase', () => {
assert.equal(filterModel.filterPhrase, expectedFilterPhrase);
});
});
};
18 changes: 18 additions & 0 deletions test/public/models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

const filterSuite = require('./FilterModel.test');

module.exports = () => {
describe('Filter model', filterSuite);
};