Skip to content

Commit

Permalink
#1778 Clear search text after adding a new class
Browse files Browse the repository at this point in the history
  • Loading branch information
rassokhina-e committed Jun 19, 2024
1 parent 9923ae1 commit 581379b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
4 changes: 2 additions & 2 deletions assets/app/app/analysis/patternmatching/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ angular.module('a2.analysis.patternmatching', [
if (a2UserPermit.isSuper()) {
return $scope.openExportPopup(exportReport)
}
if (!a2UserPermit.can('manage pattern matchings') || (a2UserPermit.can('manage pattern matchings') && a2UserPermit.getUserRole() !== 'User')) {
if (!a2UserPermit.can('manage pattern matchings') || (a2UserPermit.can('manage pattern matchings') && a2UserPermit.getUserRole() === 'User')) {
return notify.error('You do not have permission to export data');
}
$scope.openExportPopup(exportReport)
Expand Down Expand Up @@ -676,7 +676,7 @@ angular.module('a2.analysis.patternmatching', [
exportPmReport: function ($event) {
$event.stopPropagation();
if (a2UserPermit.isSuper()) return this.setupExportUrl()
if (!a2UserPermit.can('manage pattern matchings') || (a2UserPermit.can('manage pattern matchings') && a2UserPermit.getUserRole() !== 'User')) {
if (!a2UserPermit.can('manage pattern matchings') || (a2UserPermit.can('manage pattern matchings') && a2UserPermit.getUserRole() === 'User')) {
return notify.error('You do not have permission to export Pattern Matching data');
} else return this.setupExportUrl()
},
Expand Down
18 changes: 13 additions & 5 deletions assets/app/app/visualizer/layers/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ angular.module('a2.visualizer.layers.templates', [
self.toggleSpeciesAdd = false;
self.toggleSpeciesSelect = false;
self.toggleSongtypeSelect = false;
self.resetSearch = false;
self.userSearch = '';
self.allSpecies = [];
self.songtypes = [];
Expand All @@ -48,16 +49,22 @@ angular.module('a2.visualizer.layers.templates', [

self.getClasses();

self.onSpeciesExists = function(search) {
console.log('[onSpeciesExists] search', search)
if (!search) {
self.onSpeciesExists = function($select) {
console.log('[onSpeciesExists] search', $select.search)
if (!$select.search) {
self.userSearch = '';
return;
}
self.userSearch = search;
if (self.resetSearch) {
$select.search = '';
self.userSearch = '';
self.resetSearch = false;
return;
}
self.userSearch = $select.search;
const classes = self.project_classes ? self.project_classes.filter(function(cl) {
const species = cl.species_name.toLowerCase()
const searchFormatted = search.toLowerCase()
const searchFormatted = $select.search.toLowerCase()
if (species.indexOf(searchFormatted) != -1) {
return true;
} else return false;
Expand Down Expand Up @@ -135,6 +142,7 @@ angular.module('a2.visualizer.layers.templates', [
.success(function(result) {
notify.log(self.classToAdd.species + ' ' + self.classToAdd.songtype + " added to the project");
self.toggleSongtypeSelect = false;
self.resetSearch = true;
self.userSearch = '';
// Reload the validations list on the Species Presence.
$scope.$broadcast('a2-persisted', {
Expand Down
2 changes: 1 addition & 1 deletion assets/app/app/visualizer/spectrogram-layer/templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ <h3 class="popover-title">
<span class="text-util-gray-01" style="font-size: 12px;line-height: 1.2em;">{{ layer.templates.tempSelected.songtype_name ? layer.templates.tempSelected.songtype_name : $select.selected.songtype_name }}</span>
</div>
</ui-select-match>
<ui-select-choices repeat="class in layer.templates.project_classes | filter:$select.search | orderBy: ['species_name']" refresh="layer.templates.onSpeciesExists($select.search)" refresh-delay="0" position="down">
<ui-select-choices repeat="class in layer.templates.project_classes | filter:$select.search | orderBy: ['species_name']" refresh="layer.templates.onSpeciesExists($select)" refresh-delay="0" position="down">
<div class="row-flex flex-self-align-top flex-direction-column">
<span class="text-insight">{{ class.species_name }}</span>
<span class="text-util-gray-01" style="font-size: 12px;line-height: 1.2em;">{{ class.songtype_name }}</span>
Expand Down
4 changes: 2 additions & 2 deletions assets/app/app/visualizer/validator-main.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</p>
<div class="form-group validator" style="position:relative;" click-outside="hide()">
<ui-select ng-model="selected" on-select="selectClass(selected)" ng-click="onSearchClick()" reset-search-input="false" theme="bootstrap">
<ui-select-match allow-clear="{{$select.selected.species_name || tempSelected.species_name ? true : false}}">
<ui-select-match allow-clear="{{tempSelected.species_name ? true : false}}">
<img ng-if="!tempSelected.species_name" class="pl-absolute-icon" style="width: 16px" src="/images/fi-search.svg">
<span ng-if="!userSearch.length && !tempSelected.species_name" class="placeholder pl-absolute ml-1">Search for species</span>
<div ng-if="userSearch && userSearch.length" class="placeholder pl-absolute ml-1">
Expand All @@ -15,7 +15,7 @@
<span class="text-util-gray-01" style="font-size: 12px;line-height: 1.2em;">{{ tempSelected.songtype_name ? tempSelected.songtype_name : $select.selected.songtype_name }}</span>
</div>
</ui-select-match>
<ui-select-choices repeat="class in classes | filter:$select.search | orderBy: ['species_name']" refresh="onSpeciesExists($select.search)" refresh-delay="0" position="down">
<ui-select-choices repeat="class in classes | filter:$select.search | orderBy: ['species_name']" refresh="onSpeciesExists($select)" refresh-delay="0" position="down">
<div class="row-flex flex-self-align-top flex-direction-column">
<span class="text-insight">{{ class.species_name }}</span>
<span class="text-util-gray-01" style="font-size: 12px;line-height: 1.2em;">{{ class.songtype_name }}</span>
Expand Down
18 changes: 13 additions & 5 deletions assets/app/app/visualizer/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ angular.module('a2.speciesValidator', ['a2.utils', 'a2.infotags', 'a2.directive.
$scope.toggleSpeciesAdd = false;
$scope.toggleSpeciesSelect = false;
$scope.toggleSongtypeSelect = false;
$scope.resetSearch = false;
$scope.userSearch = '';
$scope.allSpecies = [];
$scope.songtypes = [];
Expand All @@ -19,16 +20,22 @@ angular.module('a2.speciesValidator', ['a2.utils', 'a2.infotags', 'a2.directive.
$scope.tempSelected = {}
$scope.timeout;

$scope.onSpeciesExists = function(search) {
console.log('[onSpeciesExists] search', search)
if (!search) {
$scope.onSpeciesExists = function($select) {
console.log('[onSpeciesExists] search', $select.search)
if (!$select.search) {
$scope.userSearch = '';
return;
}
$scope.userSearch = search;
if ($scope.resetSearch) {
$select.search = '';
$scope.userSearch = '';
$scope.resetSearch = false;
return;
}
$scope.userSearch = $select.search;
const classes = $scope.classes ? $scope.classes.filter(function(cl) {
const species = cl.species_name.toLowerCase()
const searchFormatted = search.toLowerCase()
const searchFormatted = $select.search.toLowerCase()
if (species.indexOf(searchFormatted) != -1) {
return true;
} else return false;
Expand Down Expand Up @@ -106,6 +113,7 @@ angular.module('a2.speciesValidator', ['a2.utils', 'a2.infotags', 'a2.directive.
.success(function(result) {
notify.log($scope.classToAdd.species + ' ' + $scope.classToAdd.songtype + " added to the project");
$scope.toggleSongtypeSelect = false;
$scope.resetSearch = true;
$scope.userSearch = '';
load_project_classes().finally(() => {
const newSelectedClass = $scope.classes.find(cl => cl.species_name === $scope.classToAdd.species && cl.songtype_name === $scope.classToAdd.songtype)
Expand Down

0 comments on commit 581379b

Please sign in to comment.