Skip to content

Commit

Permalink
Merge pull request #1149 from mcneilco/release/2024.1.x
Browse files Browse the repository at this point in the history
⬆️ Upmerge release/2024.1.x to release/2024.2.x
  • Loading branch information
brianbolt authored Apr 4, 2024
2 parents 05d2ca1 + 32dff0f commit eedefc6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports.validateCodeTablesEntityBeforeSave = (req, resp) ->
config = require '../conf/compiled/conf.js'
codeTableServiceRoutes = require "./CodeTableServiceRoutes.js"
searchTerm = req.params.searchTerm
codeTableServiceRoutes.getCodeTableValuesInternal req.params.codeType, req.params.codeKind, (results) ->
codeTableServiceRoutes.getCodeTableValuesInternal req.params.codeType, req.params.codeKind, null, (results) ->
if !req.body.data?
data = req.body
else
Expand Down Expand Up @@ -105,15 +105,7 @@ exports.searchCodeTablesEntities = (req, resp) ->
request = require 'request'
config = require '../conf/compiled/conf.js'
codeTableServiceRoutes = require "./CodeTableServiceRoutes.js"
searchTerm = req.params.searchTerm.toLowerCase().trim()
codeTableServiceRoutes.getCodeTableValuesInternal req.params.codeType, req.params.codeKind, (results) ->
searchResults = []
if searchTerm == "*" || searchTerm == ""
searchResults = results
else
for r in results
if (r.code? && r.code.toLowerCase().indexOf(searchTerm) >= 0) || (r.comments? && r.comments.toLowerCase().indexOf(searchTerm) >= 0) || (r.description? && r.description.toLowerCase().indexOf(searchTerm) >= 0) || (r.name? && r.name.toLowerCase().indexOf(searchTerm) >= 0)
searchResults.push(r)
codeTableServiceRoutes.getCodeTableValuesInternal req.params.codeType, req.params.codeKind, searchTerm, (results) ->
resp.json searchResults

exports.getCodeTablesEntities = (req, resp) ->
Expand Down
9 changes: 8 additions & 1 deletion modules/Components/src/client/ACASFormFields.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,11 @@ class ACASFormLSCodeValueFieldController extends ACASFormAbstractFieldController
if @url?
@pickList.url = @url
else
@pickList.url = "/api/codetables/#{mdl.get 'codeType'}/#{mdl.get 'codeKind'}"
## Editable picklists can type ahead serch code tables
## we want to first populate with the matching value only by adding a shortName parameter
@pickList.url = "/api/codetables/#{mdl.get 'codeType'}/#{mdl.get 'codeKind'}/?maxHits=100"
if mdl.get('value')?
@pickList.url = "#{@pickList.url}&shortName=#{mdl.get('value')}"
plOptions =
el: @$('.bv_editablePicklist')
collection: @pickList
Expand Down Expand Up @@ -435,6 +439,9 @@ class ACASFormLSCodeValueFieldController extends ACASFormAbstractFieldController
if @options.autoSavePickListItem? && !@options.autoSavePickListItem
plOptions.autoSave = false

plOptions.autoFetch = true
if @options.autoFetch?
plOptions.autoFetch = @options.autoFetch
@pickListController = new EditablePickListSelect2Controller plOptions
@pickListController.on('change', @handleInputChanged).bind(@)
@pickListController.render()
Expand Down
24 changes: 23 additions & 1 deletion modules/Components/src/client/PickList.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,28 @@ class PickListSelect2Controller extends PickListSelectController
openOnEnter: false
allowClear: true
width: @width

ajax:
url: (params) =>
if !params.term?
params.term = ''
# The URL parameter on for the code service may have e.g. shortName
# as a a parameter, so we need to remove it from the URL
# we use relative paths url in acas currently so we need to add the full path
# to parse the url correctly
urlObj = new URL(@collection.url, "http://localhost")
searchParams = new URLSearchParams()
searchParams.set('labelTextSearchTerm', params.term)
searchParams.set('maxHits', "100")
urlStr = "#{urlObj.pathname}?#{searchParams.toString()}"
return urlStr
dataType: 'json'
delay: 250
processResults: (data, params) =>
@latestData = data
results = for option in data
{id: option.code, text: option.name}
return {results: results}

@setSelectedCode @selectedCode
@rendered = true
@
Expand Down Expand Up @@ -685,6 +706,7 @@ class EditablePickListSelect2Controller extends EditablePickListSelectController
collection: @collection
selectedCode: @options.selectedCode
filters: filters
autoFetch: @options.autoFetch
if @options.insertFirstOption
plOptions.insertFirstOption = @options.insertFirstOption
else if @options.parameter?
Expand Down
20 changes: 11 additions & 9 deletions modules/Components/src/server/routes/CodeTableServiceRoutes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,33 @@ exports.getAllCodeTableValues = (req, resp) ->
)

exports.getCodeTableValues = (req, resp) ->
exports.getCodeTableValuesInternal req.params.type, req.params.kind, (result) ->
exports.getCodeTableValuesInternal req.params.type, req.params.kind, req.query, (result) ->
resp.json result

exports.getCodeTableValuesInternal = (type, kind, cb) ->
exports.getCodeTableValuesInternal = (type, kind, query, cb) ->
if global.specRunnerTestmode
fullCodeTableJSON = require '../public/javascripts/spec/CodeTableJSON.js'
correctCodeTable = _.findWhere(fullCodeTableJSON.codes, {type:type, kind:kind})
cb correctCodeTable['codes']
else
# For backwards compatibility, check if the query parameter is a function
if typeof query == 'function'
console.warn('Deprecation warning: Please provide the query parameter using the new parameter order. The old order will be removed in a future release.')
cb = query
query = null
config = require '../conf/compiled/conf.js'
baseurl = "#{config.all.client.service.persistence.fullpath}ddictvalues/all/#{type}/#{kind}/codetable"
qs = {}
if query?
qs = query
request = require 'request'
request(
method: 'GET'
url: baseurl
qs: qs
json: true
, (error, response, json) =>
if !error && response.statusCode == 200
if json.length > 0 and !json[0].displayOrder? and json[0].name?
json = json.sort (a, b) ->
if a.name.toUpperCase() < b.name.toUpperCase()
return -1
if a.name.toUpperCase() > b.name.toUpperCase()
return 1
return 0
cb json
else
console.log 'got ajax error trying to get code table entries'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ exports.getAllAuthors = (opts, callback) ->
# This is was added for the purpose of allowing additional non-authors to show up in picklists throughout ACAS and Creg
if opts.additionalCodeType? and opts.additionalCodeKind?
codeTableServiceRoutes = require "#{ACAS_HOME}/routes/CodeTableServiceRoutes.js"
codeTableServiceRoutes.getCodeTableValuesInternal opts.additionalCodeType, opts.additionalCodeKind, (codes) ->
codeTableServiceRoutes.getCodeTableValuesInternal opts.additionalCodeType, opts.additionalCodeKind, null, (codes) ->
Array::push.apply json, codes
callback statusCode, json
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3034,7 +3034,7 @@ createDaughterVialFileEntryArray = (csvFileName, callback) =>
)

dealiasPhysicalStates = (fileEntryArray, callback) ->
codeTableRoutes.getCodeTableValuesInternal 'container status', 'physical state', (configuredPhysicalStates) ->
codeTableRoutes.getCodeTableValuesInternal 'container status', 'physical state', null, (configuredPhysicalStates) ->
cleanedFileEntryArray = _.map fileEntryArray, (entry) ->
foundPhysicalState = _.findWhere configuredPhysicalStates, {code: entry.physicalState}
if !foundPhysicalState?
Expand All @@ -3061,7 +3061,7 @@ checkRequiredAttributes = (fileEntryArray, callback) ->
callback requiredAttributeErrors

checkDataTypeErrors = (fileEntryArray, callback) ->
codeTableRoutes.getCodeTableValuesInternal 'container status', 'physical state', (configuredPhysicalStates) ->
codeTableRoutes.getCodeTableValuesInternal 'container status', 'physical state', null, (configuredPhysicalStates) ->
dataTypeErrors = []
_.each fileEntryArray, (entry) ->
foundPhysicalState = _.findWhere configuredPhysicalStates, {code: entry.physicalState}
Expand Down Expand Up @@ -3356,7 +3356,7 @@ updateWellContentSerial = (wellsToUpdate, currentIndex, outerCallback) ->
return

prepareSummaryInfo = (fileEntryArray, cb) ->
codeTableRoutes.getCodeTableValuesInternal 'container status', 'physical state', (configuredPhysicalStates) ->
codeTableRoutes.getCodeTableValuesInternal 'container status', 'physical state', null, (configuredPhysicalStates) ->
summaryInfo =
totalNumberOfVials: fileEntryArray.length
totalsByStates: {}
Expand Down

0 comments on commit eedefc6

Please sign in to comment.