UNPKG

@nodata/render

Version:

Allows to dynamically render nodata components

1 lines 4.14 kB
"use strict";var __extends=this&&this.__extends||function(){var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function o(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(o.prototype=r.prototype,new o)}}(),__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.PresetFilterRenderer=void 0;var rxjs_1=require("rxjs"),operators_1=require("rxjs/operators"),reactive_widget_1=require("@nodata/reactive-widget"),error_1=require("@nodata/error"),action_1=require("@nodata/action"),preset_filter_theme_1=__importDefault(require("./preset-filter-theme")),PresetFilterRenderer=function(e){function t(t){var r=e.call(this)||this;return r.executionContext=null,r.presetFilterView=null,r.executionContext=t,r.executionContext||(r.executionContext=new action_1.DatablockExecutionContext),r}return __extends(t,e),t.prototype.on=function(t){return e.prototype.on.call(this,t),this.onChange(this.onValueUpdate.bind(this)),this.updateTheme(preset_filter_theme_1.default),this},t.prototype.fetch=function(e){var t,r,o=this;return(0,action_1.retrievePresetFilterViewWithPresetFilter)(e).pipe((0,operators_1.tap)((function(e){o.presetFilterView=e,o.updateType(e.type),e.presetFilter.defaultValue&&(r=JSON.parse(e.presetFilter.defaultValue),o.setSelectedValues(e.type,r))})),(0,operators_1.mergeMap)((function(e){return(0,action_1.retrieveDatablockViewPresetFiltersByPresetFilterCode)(e.presetFilter.code)})),(0,operators_1.tap)((function(e){0===e.length&&o.updateSelectableValues([]),t=e.map((function(e){return e.filteredField}))})),(0,operators_1.mergeMap)((function(e){return(0,rxjs_1.forkJoin)(e.map((function(e){return(0,action_1.retrieveDatablockView)(e.idDatablockView)})))})),(0,operators_1.mergeMap)((function(e){return(0,rxjs_1.forkJoin)(e.map((function(e){return(0,action_1.retrieveDatablock)(e.datablock)})))})),(0,operators_1.mergeMap)((function(e){return(0,rxjs_1.combineLatest)(e.map((function(e){return(0,action_1.executeDatablock)(e.id,{executionContext:o.executionContext})})))})),(0,operators_1.map)((function(e){return o.setSelectableValues(t,e,r)})),(0,operators_1.catchError)((function(t){return(0,error_1.rethrowError)(t,"NDR-PF-001",'Unable to fetch presetFilter and values from view "'.concat(e,'".'))})))},t.prototype.showErrorState=function(e){e.className="render-error-placeholder",this.destroy()},t.prototype.initializeExecutionContext=function(e){var t=this;return(0,action_1.retrievePresetFilterViewWithPresetFilter)(e).pipe((0,operators_1.tap)((function(e){return t.executionContext.updateMappingEntry(e.presetFilter.code,e.presetFilter.defaultValue)})),(0,operators_1.map)((function(){return null})),(0,operators_1.catchError)((function(t){return(0,error_1.rethrowError)(t,"NDR-PF-002","Unable to initialize execution context for preset filter view ".concat(e))})))},t.prototype.setSelectedValues=function(e,t){~["dropdown","radio"].indexOf(e)?this.updateSelectedValue(t[0]):"text"===e?this.updateValue(t[0]):this.updateSelectedValues(t)},t.prototype.dedupDatablockOutputsValuesForFields=function(e,t){var r=Array();return t.forEach((function(t,o){t.forEach((function(t){for(var n in t)n===e[o]&&t[n]&&r.push(String(t[n]))}))})),Array.from(new Set(r))},t.prototype.setSelectableValues=function(e,t,r){var o=this.dedupDatablockOutputsValuesForFields(e,t);if(r)for(var n=0,i=r;n<i.length;n++){var a=i[n];"string"!=typeof a&&(a=String(a)),o.includes(a)||o.push(a)}var u=o.map((function(e){return{value:e}}));this.updateSelectableValues(u)},t.prototype.onValueUpdate=function(e){this.presetFilterView&&this.executionContext.updateMappingEntry(this.presetFilterView.presetFilter.code,e)},t}(reactive_widget_1.ReactiveWidget);exports.PresetFilterRenderer=PresetFilterRenderer,exports.default=PresetFilterRenderer;