Skip to content

Commit

Permalink
Merge pull request #772 from cultuurnet/feature/III-6019
Browse files Browse the repository at this point in the history
III-6019 - As a user I can save a new query on an existing saved search [angular]
  • Loading branch information
brampauwelyn authored Mar 11, 2024
2 parents acc3024 + c1e625f commit 4ac50a1
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 50 deletions.
168 changes: 150 additions & 18 deletions dist/udb3-angular.js

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

26 changes: 13 additions & 13 deletions dist/udb3-angular.min.js

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/core/translations/dutch-translations.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,15 @@ angular.module('udb.core')
viewResults: 'Resultaten bekijken',
yourSearch: 'Jouw zoekopdracht',
save: 'Bewaren',
modal: {
mainTitle: 'Zoekopdracht opslaan',
newTab: 'Nieuwe zoekopdracht',
existingTab: 'Bestaande zoekopdracht',
giveName: 'Geef je zoekopdracht een naam',
selectSavedSearch: 'Kies een bewaarde zoekopdracht',
save: 'Bewaren',
cancel: 'Annuleren'
}
},
manage: 'Beheren',
oneResult: '1 resultaat',
Expand Down
9 changes: 9 additions & 0 deletions src/core/translations/french-translations.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,15 @@ angular.module('udb.core')
viewResults: 'Consulter résultats',
yourSearch: 'Votre recherche',
save: 'Conserver',
modal: {
mainTitle: 'Enregistrer la recherche',
newTab: 'Nouvelle recherche',
existingTab: 'Recherche existante',
giveName: 'Donnez un nom à votre recherche',
selectSavedSearch: 'Choisissez une recherche existante',
save: 'Enregistrer',
cancel: 'Annuler'
}
},
manage: 'Gérer',
oneResult: '1 résultat',
Expand Down
9 changes: 9 additions & 0 deletions src/core/translations/german-translations.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,15 @@ angular.module('udb.core').constant('udbGermanTranslations', {
'viewResults': 'Ergebnisse ansehen',
'yourSearch': 'Ihre Suchanfrage',
'save': 'Speichern',
'modal': {
'mainTitle': 'Suche speichern',
'newTab': 'Neue Suche',
'existingTab': 'Vorhandene Suche',
'giveName': 'Gib deiner Suche einen Namen',
'selectSavedSearch': 'Wähle eine vorhandene Suche',
'save': 'Speichern',
'cancel': 'Abbrechen'
}
},
'manage': 'Verwalten',
'oneResult': '1 Ergebnis',
Expand Down
6 changes: 6 additions & 0 deletions src/core/udb-api.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ function UdbApi(
.then(returnUnwrappedData);
};

this.editSavedSearch = function (searchId, name, query) {
return $http
.put(appConfig.baseUrl + 'saved-searches/v3/' + searchId, {name: name, query: query}, defaultApiConfig)
.then(returnUnwrappedData);
};

/**
* @param {string} queryString - The query used to find offers.
* @param {number} [start] - From which offset the result set should start.
Expand Down
57 changes: 53 additions & 4 deletions src/saved-searches/components/save-search-modal.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,72 @@ angular
.controller('SaveSearchModalController', SaveSearchModalController);

/* @ngInject */
function SaveSearchModalController($scope, $uibModalInstance) {
function SaveSearchModalController($scope, udbApi, $q, $uibModalInstance, $translate) {

var ok = function () {
var ok = function (type) {
var name = $scope.queryName;
var id = $scope.queryId;
$scope.wasSubmitted = true;

if (name) {
$uibModalInstance.close(name);
if (type === 'existing') {
$uibModalInstance.close({id: id, name: name, type: type});
}

if (type === 'new' && name) {
$uibModalInstance.close({name: name, type: type});
}

};

var cancel = function () {
$uibModalInstance.dismiss('cancel');
};

var isTabActive = function (tabId) {
return tabId === $scope.activeTabId;
};

var getSavedSearches = function () {
return udbApi.getSavedSearches().then(function (data) {
var withTranslation = data.map(function (savedSearch) {
var key = 'search.savedSearches.items.' + savedSearch.name.toString();
var translated = $translate.instant(key);
if (translated !== key) {
savedSearch.name = translated;
}
return savedSearch;
});
return $q.resolve(withTranslation);
});
};

var makeTabActive = function (tabId) {
$scope.activeTabId = tabId;
if (tabId === 'existing') {
getSavedSearches().then(function (savedSearches) {
$scope.savedSearches = savedSearches;
});
}
};

var setQueryName = function() {
var selectedSavedSearch = $scope.savedSearches.find(function(savedSearch) {
return savedSearch.id === $scope.queryId;
});

if (selectedSavedSearch) {
$scope.queryName = selectedSavedSearch.name;
}
};

$scope.savedSearches = [];
$scope.cancel = cancel;
$scope.ok = ok;
$scope.isTabActive = isTabActive;
$scope.makeTabActive = makeTabActive;
$scope.setQueryName = setQueryName;
$scope.queryName = '';
$scope.queryId = '';
$scope.activeTabId = 'new';
$scope.wasSubmitted = false;
}
Loading

0 comments on commit 4ac50a1

Please sign in to comment.