UNPKG

ngx-academia-uniandes-library

Version:

This library is used for Academia-Uniandes system.

132 lines 6.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var forms_1 = require("@angular/forms"); var Observable_1 = require("rxjs/Observable"); require("rxjs/add/operator/map"); require("rxjs/add/observable/empty"); require("rxjs/add/operator/mergeMap"); require("rxjs/add/operator/switchMap"); require("rxjs/add/operator/debounceTime"); require("rxjs/add/operator/distinctUntilChanged"); var search_combo_box_generic_service_1 = require("./search-combo-box-generic.service"); var search_combo_box_generic_model_1 = require("./search-combo-box-generic.model"); var SearchComboBoxGenericComponent = /** @class */ (function () { function SearchComboBoxGenericComponent(service, cd) { var _this = this; this.service = service; this.cd = cd; this.selectFirst = false; this.data = []; this.itemSelected = new core_1.EventEmitter(); this.noResults = new core_1.EventEmitter(); this.typeLoading = new core_1.EventEmitter(); this.totalRecordsForSearch = new core_1.EventEmitter(); this.dataSource = Observable_1.Observable.create(function (observer) { observer.next(_this.asyncDataSelected); }).mergeMap(function (token) { if (!_this.clearDataTypeObjectIfEmpty(token)) { var dataObserver = _this.searchItems(token, _this.componentModel); return dataObserver; } return Observable_1.Observable.empty(); }); } SearchComboBoxGenericComponent.prototype.ngOnInit = function () { if (this.selectFirst) { this.setInitialValue(null); } this.setPreSelectedValue(); }; SearchComboBoxGenericComponent.prototype.ngOnChanges = function () { this.setPreSelectedValue(); }; SearchComboBoxGenericComponent.prototype.searchItems = function (token, componentModel) { var _this = this; return this.service.getItems(token, componentModel).map(function (values) { if (componentModel.totalRecordsName) { _this.totalRecordsForSearch.emit(values[componentModel.totalRecordsName]); } values[componentModel.collectionName] ? _this.data = values[componentModel.collectionName] : _this.data = values; return _this.data; }); }; SearchComboBoxGenericComponent.prototype.selectItem = function (event) { this.itemSelected.emit(event); }; SearchComboBoxGenericComponent.prototype.typeaheadNoResults = function (event) { if (event) { this.noResults.emit(event); } }; SearchComboBoxGenericComponent.prototype.typeaheadLoading = function (event) { this.typeLoading.emit(event); }; SearchComboBoxGenericComponent.prototype.getIsScrollable = function () { return this.isScrollable ? true : false; }; SearchComboBoxGenericComponent.prototype.setPreSelectedValue = function () { if (this.preSelectedValue !== undefined && this.preSelectedValue !== '') { this.asyncDataSelected = this.preSelectedValue; } else { this.asyncDataSelected = ''; } }; SearchComboBoxGenericComponent.prototype.setInitialValue = function (selectedDependency) { var _this = this; this.searchItems(selectedDependency.name, this.componentModel).subscribe(function (values) { if (selectedDependency) { values.forEach(function (element) { if (element['externalId'] == selectedDependency.externalId) { _this.asyncDataSelected = element[_this.componentModel.optionField]; } }); } else { if (values.length > 0) { _this.asyncDataSelected = values[0][_this.componentModel.optionField]; _this.selectItem(values[0]); _this.cd.detectChanges(); } } }); }; SearchComboBoxGenericComponent.prototype.clearDataTypeObjectIfEmpty = function (token) { if (token === '') { delete this.asyncDataSelected; this.itemSelected.emit(this.asyncDataSelected); return true; } else { return false; } }; SearchComboBoxGenericComponent.decorators = [ { type: core_1.Component, args: [{ selector: 'app-search-combo-box-generic', template: "\n <input #typeAhead [formControl]=\"itemControl\"\n [(ngModel)]=\"asyncDataSelected\"\n [typeahead]=\"dataSource\"\n [typeaheadOptionsLimit]=\"componentModel.optionsLimit || 10 \"\n [typeaheadMinLength]=\"0\"\n [typeaheadScrollable]=\"getIsScrollable()\"\n [typeaheadItemTemplate]=\"customTemplate\"\n (typeaheadNoResults)=\"typeaheadNoResults($event)\"\n (typeaheadLoading)=\"typeaheadLoading($event)\"\n (typeaheadOnSelect)=\"selectItem($event)\"\n typeaheadOptionField=\"{{componentModel.optionField || 'name' }}\"\n placeholder=\"{{(componentModel.placeholder || 'search')|translate}}\"\n class=\"form-control\">\n ", styles: ["\n\n "] },] }, ]; /** @nocollapse */ SearchComboBoxGenericComponent.ctorParameters = function () { return [ { type: search_combo_box_generic_service_1.SearchComboBoxGenericService, }, { type: core_1.ChangeDetectorRef, }, ]; }; SearchComboBoxGenericComponent.propDecorators = { "itemControl": [{ type: core_1.Input },], "componentModel": [{ type: core_1.Input },], "preSelectedValue": [{ type: core_1.Input },], "isScrollable": [{ type: core_1.Input },], "customTemplate": [{ type: core_1.Input },], "selectFirst": [{ type: core_1.Input },], "itemSelected": [{ type: core_1.Output },], "noResults": [{ type: core_1.Output },], "typeLoading": [{ type: core_1.Output },], "totalRecordsForSearch": [{ type: core_1.Output },], }; return SearchComboBoxGenericComponent; }()); exports.SearchComboBoxGenericComponent = SearchComboBoxGenericComponent; //# sourceMappingURL=search-combo-box-generic.component.js.map