Skip to content

Commit

Permalink
util, model, search_controllers: Add plugin hook points
Browse files Browse the repository at this point in the history
Add plugin hook points to be used in plugin cqp_between_tokens.

app/scripts/model.js:
- BaseProxy.expandCQP: Let plugins filter the expanded CQP.

app/scripts/search_controllers.js
- ExtendedSearch: Let plugins filter the extended search CQP expression
  and act when corpus selection is changed.

app/scripts/util.js
- CorpusListing.constructor, .select: Let plugins act on CorpusListing
  after constructing it and when selecting corpora.
  • Loading branch information
janiemi authored and mmatthiesencsc committed Oct 1, 2024
1 parent 2f83138 commit 64d3566
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/scripts/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ class BaseProxy {
}

expandCQP(cqp) {
let result
try {
return CQP.expandOperators(cqp)
result = CQP.expandOperators(cqp)
} catch (e) {
c.warn("CQP expansion failed", cqp, e)
return cqp
result = cqp
}
// Let plugins filter the expanded CQP
result = plugins.callFilters("filterExpandedCQP", result)
return result
}

makeRequest() {
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/search_controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ korpApp.controller("ExtendedSearch", function ($scope, $location, $rootScope, se
if ($rootScope.globalFilter) {
val2 = CQP.stringify(CQP.mergeCqpExprs(CQP.parse(val2 || "[]"), $rootScope.globalFilter))
}
// Let plugins filter the extended search CQP expression
val2 = plugins.callFilters("filterExtendedCQP", val2)
$rootScope.extendedCQP = val2
}

Expand Down Expand Up @@ -488,6 +490,8 @@ korpApp.controller("ExtendedSearch", function ($scope, $location, $rootScope, se
return s.$on("corpuschooserchange", function () {
s.withins = s.getWithins()
s.within = s.withins[0] && s.withins[0].value
// Let plugins act when corpus selection is changed
plugins.callActions("onCorpusChooserChange")
})
})

Expand Down
5 changes: 5 additions & 0 deletions app/scripts/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ window.CorpusListing = class CorpusListing {
"getStructAttrsIntersection",
"getStructAttrs",
])
// Let plugins act on CorpusListing after constructing it
plugins.callActions("onCorpusListingConstructed", this)
}

get(key) {
Expand Down Expand Up @@ -63,6 +65,9 @@ window.CorpusListing = class CorpusListing {

select(idArray) {
this.selected = _.values(_.pick.apply(this, [this.struct].concat(idArray)))
// Let plugins act on CorpusListing when selecting the corpora
// listed in idArray
plugins.callActions("onCorpusListingSelect", this, idArray)
}

mapSelectedCorpora(f) {
Expand Down

0 comments on commit 64d3566

Please sign in to comment.