Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #327 Modifier le switch de sélection des globales dans la liste d… #383

Merged
merged 10 commits into from
Feb 19, 2020
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:

- name: pre-commit hooks
stage: test
# Ce work-around est mis pour corriger une issue du type https://github.com/pypa/virtualenv/issues/1551#issuecomment-584284214 sur travis.
before_install: pip install --user --upgrade six
Lucas-C marked this conversation as resolved.
Show resolved Hide resolved
install: pip install --user pre-commit
script: pre-commit run --all-files

Expand Down
7 changes: 4 additions & 3 deletions src/app/i18n/label_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@
"properties.filter.byValue": "Filter properties by value (filters only on saved values)",
"properties.sort.switch": "Sort properties",
"properties.unspecifiedValues.switch": "Show unfilled properties",
"properties.globalPropertiesValues.switch": "Show global properties",
"properties.onlyRequiredProperties.switch": "Show only required properties ({{numberOfRequired}})",
"properties.deletedOnes.switch": "Show deleted properties",
"properties.globalPropertiesValues.switch": "Display only global properties",
"properties.onlyRequiredProperties.switch": "Display only required properties ({{numberOfRequired}})",
"properties.hide.globalProperties.switch": "Hide global properties ({{globalPropertiesCount}})",
"properties.deletedOnes.switch": "Display deleted properties",
"properties.logicGroup.add": "Add a logic group",
"properties.logicGroup.add.name": "Name",
"properties.logicGroup.update": "Edit the logic group name",
Expand Down
3 changes: 2 additions & 1 deletion src/app/i18n/label_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@
"properties.filter.byValue": "Filtrer par valeur (ne filtre que les valeurs enregistrées)",
"properties.sort.switch": "Tri des propriétés",
"properties.unspecifiedValues.switch": "Afficher les propriétés non renseignées",
"properties.globalPropertiesValues.switch": "Afficher les globales",
"properties.globalPropertiesValues.switch": "Afficher seulement les propriétés globales",
Lucas-C marked this conversation as resolved.
Show resolved Hide resolved
"properties.onlyRequiredProperties.switch": "Afficher seulement les propriétés obligatoires ({{numberOfRequired}})",
"properties.hide.globalProperties.switch": "Masquer les propriétés globales ({{globalPropertiesCount}})",
"properties.deletedOnes.switch": "Afficher les propriétés supprimées",
"properties.logicGroup.add": "Ajouter un groupe logique",
"properties.logicGroup.add.name": "Nom",
Expand Down
12 changes: 6 additions & 6 deletions src/app/module/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ angular.module('hesperides.module', [ 'hesperides.application' ])

// Class methods:
Module.fromPropertiesPath = function (propertiesPath) {
let pathFragments = propertiesPath.split('#');
let name = pathFragments[pathFragments.length - 3];
let version = pathFragments[pathFragments.length - 2];
let moduleType = pathFragments[pathFragments.length - 1];
if (pathFragments[0] !== '' || pathFragments.length < 5 || !['RELEASE', 'WORKINGCOPY'].includes(moduleType)) {
throw new Error(`Invalid propertiesPath provided: ${propertiesPath}`);
const pathFragments = propertiesPath.split('#');
const name = pathFragments[pathFragments.length - 3];
const version = pathFragments[pathFragments.length - 2];
const moduleType = pathFragments[pathFragments.length - 1];
if (pathFragments[0] !== '' || pathFragments.length < 5 || ![ 'RELEASE', 'WORKINGCOPY' ].includes(moduleType)) {
throw new Error(`Invalid propertiesPath provided: ${ propertiesPath }`);
}
return new Module({
name, version,
Expand Down
32 changes: 27 additions & 5 deletions src/app/properties/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,15 @@ angular.module('hesperides.properties', [ 'hesperides.diff', 'hesperides.localCh
}
return count;
};

scope.getGlobalPropertiesCount = function (properties) {
let count = 0;
// ce test est nécessaire car à l'initialisation de la page platform.global_properties est falsy
if (properties) {
count = properties.filter((property) => property.valuedByAGlobal).length;
}
return count;
};
},
};
},
Expand Down Expand Up @@ -1837,10 +1846,11 @@ angular.module('hesperides.properties', [ 'hesperides.diff', 'hesperides.localCh
scope: {
keyValueProperties: '=',
toggle: '=',
disabled: '=',
},
template: '<md-switch id="toggle-global-properties_switch" class="md-primary md-block" ' +
'ng-model="toggle"' +
'ng-disabled="(getNumberOfGlobalProperties(keyValueProperties) <= 0)" ' +
'ng-disabled="(getNumberOfGlobalProperties(keyValueProperties) <= 0) || disabled" ' +
'aria-label="{{ \'properties.globalPropertiesValues.switch\' | translate }}">' +
'{{ \'properties.globalPropertiesValues.switch\' | translate }} ({{ getNumberOfGlobalProperties(keyValueProperties) }})' +
'</md-switch>',
Expand All @@ -1851,7 +1861,7 @@ angular.module('hesperides.properties', [ 'hesperides.diff', 'hesperides.localCh
*/
$scope.getNumberOfGlobalProperties = function (tab) {
var count = 0;
tab = $filter('displayGlobalProperties')(tab, true);
tab = $filter('displayOnlyGlobalProperties')(tab, true);
if (tab) {
_.each(tab, function (item) {
if (item.valuedByAGlobal) {
Expand Down Expand Up @@ -1882,16 +1892,28 @@ angular.module('hesperides.properties', [ 'hesperides.diff', 'hesperides.localCh
})

/**
* Display only the not globals properties
* Display only the globals properties
*/
.filter('displayOnlyGlobalProperties', function () {
return function (items, display) {
return _.filter(items, function (item) {
return !display || (display && item.valuedByAGlobal);
Lucas-C marked this conversation as resolved.
Show resolved Hide resolved
});
};
})

/**
* Filter the globals properties
*/
.filter('displayGlobalProperties', function () {
.filter('hideGlobalProperties', function () {
return function (items, display) {
return _.filter(items, function (item) {
return display || (!display && !item.valuedByAGlobal);
return !display || (display && !item.valuedByAGlobal);
});
};
})


/**
* This is used to filter the 'hesperides predefined properties'.
* Definition of terms:
Expand Down
18 changes: 15 additions & 3 deletions src/app/properties/simple-properties-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,19 @@
<toggle-sort-properties sort-order="order" class="margin-right-2pc"></toggle-sort-properties>
<toggle-deleted-properties class="margin-right-2pc" key-value-properties="properties" toggle="displayDeletedProperties"></toggle-deleted-properties>
<toggle-unspecified-properties class="margin-right-2pc" key-value-properties="properties" toggle="displayUnspecified"></toggle-unspecified-properties>
<toggle-global-properties class="margin-right-2pc" key-value-properties="properties" toggle="displayGlobal"></toggle-global-properties>
<md-switch id="e2e-properties-required-only-switch-button" ng-model="onlyRequiredPropertiesSwitchChanged" class="md-primary md-block" aria-label="{{'properties.onlyRequiredProperties.switch' | translate}}">
<toggle-global-properties class="margin-right-2pc" key-value-properties="properties" toggle="displayGlobal" disabled="globalPropertiesHidden"></toggle-global-properties>
<md-switch id="e2e-hide-global-properties-switch-button"
ng-model="globalPropertiesHidden"
class="md-primary md-block"
aria-label="{{'properties.hide.globalProperties.switch' | translate : {globalPropertiesCount:getGlobalPropertiesCount(properties)} }}"
ng-disabled="displayGlobal || getGlobalPropertiesCount(properties)<=0">
{{'properties.hide.globalProperties.switch' | translate : {globalPropertiesCount:getGlobalPropertiesCount(properties)} }}
</md-switch>
<md-switch
id="e2e-properties-required-only-switch-button"
ng-model="onlyRequiredPropertiesSwitchChanged" class="md-primary md-block"
aria-label="{{'properties.onlyRequiredProperties.switch' | translate}}"
ng-disabled="getNumberOfrequiredProperties(properties) <=0">
{{'properties.onlyRequiredProperties.switch' | translate : {numberOfRequired:getNumberOfrequiredProperties(properties)} }}
</md-switch>
</div>
Expand All @@ -60,11 +71,12 @@
<md-virtual-repeat-container id="vertical-container" class="height-300px">
<div md-virtual-repeat="key_value_property in properties
| hideHesperidesPredefinedProperties
| displayGlobalProperties:displayGlobal
| displayOnlyGlobalProperties:displayGlobal
| displayUnspecifiedProperties:displayUnspecified
| filterProperties:{'name':propertiesKeyFilter, 'filtrable_value':propertiesValueFilter}
| includeDeletedProperties:displayDeletedProperties
| displayOnlyRequiredProperties:onlyRequiredPropertiesSwitchChanged
| hideGlobalProperties:globalPropertiesHidden
| orderBy:'name':order" class="repeated-item" flex>
<!-- Non Global Properties -->
<div layout="row"
Expand Down
33 changes: 32 additions & 1 deletion test/bdd/features/platforms/module-properties-list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,40 @@ Feature: Filter properties and display them as a list
| global-property | global-value |
When I open this platform
And I open the deployed module properties
And I click on the switch to display also the global properties
Then the properties are displayed with dedicated icons

Scenario: Display only the global properties
Given an existing template with this content
"""
{{ simple-property }}
{{ global-property }}
"""
And an existing module with this template
And an existing platform with this module
And the platform has these global properties
| global-property | global-value |
When I open this platform
And I open the deployed module properties
And I click on the switch to display only the global properties
Then the property "global-property" is displayed
Lucas-C marked this conversation as resolved.
Show resolved Hide resolved
And the property "simple-property" is not displayed

Scenario: Hide the global properties
Given an existing template with this content
"""
{{ simple-property }}
{{ global-property }}
"""
And an existing module with this template
And an existing platform with this module
And the platform has these global properties
| global-property | global-value |
When I open this platform
And I open the deployed module properties
And I click on the switch to hide the global properties
Then the property "global-property" is not displayed
Lucas-C marked this conversation as resolved.
Show resolved Hide resolved
And the property "simple-property" is displayed

# Scenario: Find the default value in the placeholder

# Scenario: Find the comment in the placeholder
Expand Down
2 changes: 1 addition & 1 deletion test/bdd/glue/helpers/navigate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ exports.backToFirstTab = async function () {
await browser.switchTo().window(mainTabHandle);
});
await browser.waitForAngular();
};
};
6 changes: 5 additions & 1 deletion test/bdd/glue/scenarios/platforms/module-properties-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ When('I click on the switch to also display the deleted properties', async funct
await send.clickById('toggle-deleted-properties_switch');
});

When('I click on the switch to display also the global properties', async function () {
When('I click on the switch to display only the global properties', async function () {
await send.clickById('toggle-global-properties_switch');
});

When('I click on the switch to hide the global properties', async function () {
await send.clickById('e2e-hide-global-properties-switch-button');
});

Then('only the required properties are displayed', async function () {
await get.elementsByCss('textarea.property-value').then(assert.itemsAreRequired);
});
Expand Down
12 changes: 6 additions & 6 deletions test/unit/module.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Testing hesperides module', function () {
beforeEach(module('hesperides.module'));

describe('Testing the ModuleController', function () {
let injected = {};
const injected = {};

beforeEach(inject(function ($injector, $rootScope, $controller, TechnoService, ModuleService, Module, HesperidesTemplateModal, Template, Page, FileService, Platform) {
injected.Page = Page;
Expand All @@ -48,20 +48,20 @@ describe('Testing hesperides module', function () {
}));

it('should check the page title is set to "Module"', function () {
let { Page } = injected;
let title = Page.title();
const { Page } = injected;
const title = Page.title();
expect(title).toBe('Hesperides > Module');
});

it('can build a "Module" instance from a properties path', function () {
let { Module } = injected;
const { Module } = injected;
expect(Module.fromPropertiesPath('#ABC-1#module-a#1.0#WORKINGCOPY')).toEqual(jasmine.objectContaining({
name: 'module-a',
version: '1.0',
is_working_copy: true,
properties_path: '#ABC-1#module-a#1.0#WORKINGCOPY',
title: 'module-a, 1.0 (working copy)',
technos: [ ],
technos: [ ],
version_id: -1,
}));
expect(Module.fromPropertiesPath('#ABC#DEF#module-b#1.2.3#RELEASE')).toEqual(jasmine.objectContaining({
Expand All @@ -70,7 +70,7 @@ describe('Testing hesperides module', function () {
is_working_copy: false,
properties_path: '#ABC#DEF#module-b#1.2.3#RELEASE',
title: 'module-b, 1.2.3',
technos: [ ],
technos: [ ],
version_id: -1,
}));
expect(() => Module.fromPropertiesPath('#module-b#1.0#WORKINGCOPY')).toThrow();
Expand Down