Skip to content

Commit

Permalink
Simple search UI react to URL changes
Browse files Browse the repository at this point in the history
  • Loading branch information
arildm committed Apr 7, 2024
1 parent a96e9a8 commit e99e4b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@

- Extended support for description on frontpage, with corpus updates [#341](https://github.com/spraakbanken/korp-frontend/issues/341)
- The "medial part" option now includes first/last parts also for lemgram search [#347](https://github.com/spraakbanken/korp-frontend/issues/347)
- Improved UI reactivity for Simple search
- Removed globals `settings`, `currentMode`, `currentModeParallel`, `model`, `CorpusListing`, `ParallelCorpusListing` – import them instead

### Fixed
Expand Down
30 changes: 21 additions & 9 deletions app/scripts/components/simple-search.js
Expand Up @@ -78,11 +78,12 @@ angular.module("korpApp").component("simpleSearch", {
"$location",
"backend",
"$rootScope",
"$scope",
"searches",
"compareSearches",
"$uibModal",
"$timeout",
function ($location, backend, $rootScope, searches, compareSearches, $uibModal, $timeout) {
function ($location, backend, $rootScope, $scope, searches, compareSearches, $uibModal, $timeout) {
const ctrl = this

ctrl.disableLemgramAutocomplete = !settings.autocomplete
Expand All @@ -94,17 +95,16 @@ angular.module("korpApp").component("simpleSearch", {
})

/** Whether tokens should be matched in arbitrary order. */
ctrl.freeOrder = $location.search().in_order != null
ctrl.freeOrder = false
/** Whether the "free order" option is applicable. */
ctrl.freeOrderEnabled = false
ctrl.prefix = $location.search().prefix != null
ctrl.mid_comp = $location.search().mid_comp != null
ctrl.suffix = $location.search().suffix != null
if (settings.input_case_insensitive_default) {
ctrl.isCaseInsensitive = true
ctrl.prefix = false
ctrl.mid_comp = false
ctrl.suffix = false
ctrl.isCaseInsensitive = false

if (settings["input_case_insensitive_default"]) {
$location.search("isCaseInsensitive", "")
} else {
ctrl.isCaseInsensitive = $location.search().isCaseInsensitive != null
}

// triggers watch on searches.activeSearch
Expand Down Expand Up @@ -251,6 +251,18 @@ angular.module("korpApp").component("simpleSearch", {
}
})

// Reach to changes in URL params
$scope.$watch(
() => $location.search(),
(search) => {
ctrl.freeOrder = search.in_order != null
ctrl.prefix = search.prefix != null
ctrl.mid_comp = search.mid_comp != null
ctrl.suffix = search.suffix != null
ctrl.isCaseInsensitive = search.isCaseInsensitive != null
}
)

ctrl.onChange = (output, isRawOutput) => {
if (isRawOutput) {
ctrl.currentText = output
Expand Down

0 comments on commit e99e4b8

Please sign in to comment.