Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
list all profiles when none match conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
siikamiika committed Mar 6, 2020
1 parent c55e4ac commit 5d93d0d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
10 changes: 7 additions & 3 deletions ext/bg/js/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class Backend {
const {profiles, profileCurrent} = this.options;

if (typeof optionsContext.index === 'number') {
yield {index: optionsContext.index, profile: profiles[optionsContext.index]};
yield {index: optionsContext.index, profile: profiles[optionsContext.index], selected: true};
return;
}

Expand All @@ -233,14 +233,18 @@ class Backend {
for (const profile of profiles) {
const conditionGroups = profile.conditionGroups;
if (conditionGroups.length > 0 && Backend.testConditionGroups(conditionGroups, optionsContext)) {
yield {index: profileIndex, profile, selected: !contextHasResults};
contextHasResults = true;
yield {index: profileIndex, profile};
}
++profileIndex;
}

if (!contextHasResults) {
yield {index: profileCurrent, profile: profiles[profileCurrent]};
profileIndex = 0;
for (const profile of profiles) {
yield {index: profileIndex, profile, selected: profileIndex === profileCurrent};
++profileIndex;
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions ext/mixed/js/display-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,23 @@ class DisplayGenerator {
return node;
}

createProfileSelect(profiles, currentProfileIndex) {
createProfileSelect(profiles) {
const select = document.createElement('select');

let profileIndex = 0;
let selectedIndex = 0;
for (const profile of profiles) {
const option = document.createElement('option');
option.textContent = profile.name;
option.textContent = profile.profile.name;
option.value = profileIndex;
select.appendChild(option);
if (profile.selected) {
selectedIndex = profileIndex;
}
++profileIndex;
}

select.selectedIndex = currentProfileIndex;
select.selectedIndex = selectedIndex;

return select;
}
Expand Down
2 changes: 1 addition & 1 deletion ext/mixed/js/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ class Display {
const profileSelectContainer = document.querySelector('#profile-select');
profileSelectContainer.textContent = '';
if (profiles.length <= 1) { return; }
const profileSelect = this.displayGenerator.createProfileSelect(profiles, this.profileIndex);
const profileSelect = this.displayGenerator.createProfileSelect(profiles);
profileSelect.addEventListener('change', this.onProfileSelect.bind(this));
profileSelectContainer.appendChild(profileSelect);
}
Expand Down
2 changes: 1 addition & 1 deletion ext/mixed/js/profile-switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ class ProfileSwitcher {
}

getProfiles() {
return this._profiles.map((profile) => profile.profile);
return this._profiles;
}
}

0 comments on commit 5d93d0d

Please sign in to comment.