this.settings = function(newSettings?: ISettings<T>) { if (ng1.isDefined(newSettings)) { // todo: don't modify newSettings object: this introduces unexpected side effects; // instead take a copy of newSettings if (newSettings.filterOptions){ newSettings.filterOptions = ng1.extend({}, _settings.filterOptions, newSettings.filterOptions); } if (newSettings.groupOptions){ newSettings.groupOptions = ng1.extend({}, _settings.groupOptions, newSettings.groupOptions); } if (ng1.isArray(newSettings.dataset)) { //auto-set the total from passed in dataset newSettings.total = newSettings.dataset.length; } var originalDataset = _settings.dataset; _settings = ng1.extend(_settings, newSettings); if (ng1.isArray(newSettings.dataset)) { optimizeFilterDelay(); } // note: using != as want null and undefined to be treated the same var hasDatasetChanged = newSettings.hasOwnProperty('dataset') && (newSettings.dataset != originalDataset); if (hasDatasetChanged) { if (isCommittedDataset){ this.page(1); // reset page as a new dataset has been supplied } isCommittedDataset = false; var fireEvent = function () { ngTableEventsChannel.publishDatasetChanged(self, newSettings.dataset, originalDataset); }; if (initialEvents){ initialEvents.push(fireEvent); } else { fireEvent(); } } log('ngTable: set settings', _settings); return this; } return _settings; };
angular.forEach(rowLabelsElements, function (rowLabelElement, i) { rowLabelElement = jQuery(rowLabelElement) let rowModel = data[i] let rowText = rowLabelElement.text().trim() if (contentNotSupported || rowModel.content === undefined) { expect(rowText).to.be.eq(rowModel.name) } else { let rowHtmlModel = rowModel.content rowHtmlModel = rowHtmlModel.replace('{{row.model.name}}', rowModel.name) let expectedRowText = rowHtmlModel.replace(/<(?:.|\n)*?>/gm, '').trim() // Strip HTML expect(rowText).to.be.eq(expectedRowText) } if (rowModel.classes) { let rowClasses = rowModel.classes if (!angular.isArray(rowClasses)) { rowClasses = [rowClasses] } angular.forEach(rowClasses, function (rowClass) { expect(rowLabelElement.parents().hasClass(rowClass)).to.be.ok }) } })
/** * Apply locale string in format "...{0}...{1}..." and apply instead of '{n}' params[n] * @param {string} locale text key. This key contains in resources. * @param {strong} defaultValue. Default value if locale resource wasn't found. * @param {Array} params. Additional params. * @returns {string}. Localized text. */ localeTextWithParams(key: string, defaultValue: string, params: string[]): string { let result = this.localeText(key, defaultValue); if (angular.isArray(params)) params.forEach((param, iParam) => result = result.replaceAll(`{${iParam}}`, param)); return result; }
it('should be wrapped in an array if array: true', function() { const m = $umf.compile('/foo?param1', { params: { param1: { array: true } } }); // empty array [] is treated like "undefined" expect(m.format({ param1: undefined })).toBe('/foo'); expect(m.format({ param1: [] })).toBe('/foo'); expect(m.format({ param1: '' })).toBe('/foo'); expect(m.format({ param1: '1' })).toBe('/foo?param1=1'); expect(m.format({ param1: ['1'] })).toBe('/foo?param1=1'); expect(m.format({ param1: ['1', '2'] })).toBe('/foo?param1=1¶m1=2'); expect(m.exec('/foo')).toEqual({ param1: undefined }); expect(m.exec('/foo', {})).toEqual({ param1: undefined }); expect(m.exec('/foo', { param1: '' })).toEqual({ param1: undefined }); expect(m.exec('/foo', { param1: '1' })).toEqual({ param1: ['1'] }); expect(m.exec('/foo', { param1: ['1', '2'] })).toEqual({ param1: ['1', '2'] }); $url.url('/foo'); expect(m.exec($url.path(), $url.search())).toEqual({ param1: undefined }); $url.url('/foo?param1='); expect(m.exec($url.path(), $url.search())).toEqual({ param1: undefined }); $url.url('/foo?param1=bar'); expect(m.exec($url.path(), $url.search())).toEqual({ param1: ['bar'] }); $url.url('/foo?param1=bar¶m1=baz'); if (angular.isArray($url.search())) // conditional for angular 1.0.8 expect(m.exec($url.path(), $url.search())).toEqual({ param1: ['bar', 'baz'] }); expect(m.format({})).toBe('/foo'); expect(m.format({ param1: undefined })).toBe('/foo'); expect(m.format({ param1: '' })).toBe('/foo'); expect(m.format({ param1: 'bar' })).toBe('/foo?param1=bar'); expect(m.format({ param1: ['bar'] })).toBe('/foo?param1=bar'); expect(m.format({ param1: ['bar', 'baz'] })).toBe('/foo?param1=bar¶m1=baz'); });
return function (items: any, filterOn: any) { if (filterOn === false) { return items; } if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) { var hashCheck: any = {}, newItems: any[] = []; var extractValueToCompare = function (item: any) { if (angular.isObject(item) && angular.isString(filterOn)) { return item[filterOn]; } else { return item; } }; angular.forEach(items, (item: any)=> { var valueToCheck, isDuplicate = false; for (var i = 0; i < newItems.length; i++) { if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) { isDuplicate = true; break; } } if (!isDuplicate) { newItems.push(item); } }); items = newItems; } return items; };
export function assignPartialDeep<T extends TPartial, TPartial>( destination: T, partial: TPartial, optionalPropSelector: (key: string, destination: T) => boolean = () => false, customizer: (destValue: any, srcValue: any, key: string) => any = () => undefined ) { const keys = Object.keys(partial); for(const key of keys) { let srcVal = partial[key]; if (srcVal === undefined) { if (optionalPropSelector(key, destination)){ destination[key] = srcVal; } else { // don't assign undefined to destination } continue; } const destVal = destination[key]; const customVal = customizer(destVal, srcVal, key); if (customVal !== undefined){ destination[key] = customVal; } else if (ng1.isArray(srcVal)) { destination[key] = [...srcVal]; } else if (!ng1.isObject(srcVal)) { destination[key] = srcVal; } else { destination[key] = assignPartialDeep(destVal, srcVal); } } return destination; }
const removePrototype = (srcVal: any, objVal: any) => { if (ng1.isObject(objVal) && !ng1.isArray(objVal)) { return _.toPlainObject(objVal); } else { return objVal; } };
constraintFilters.forEach(constraintFilter => { const constraintFilterOperatorValue = constraintFilter && constraintFilter.operator ? constraintFilter.operator.value : ''; if (constraintFilter.field !== null && angular.isObject(constraintFilter.operator) && constraintFilterOperatorValue !== '' && angular.isArray(constraintFilter.values) && constraintFilter.values.length > 0) { const constraintParamPart = {}; constraintParamPart[`fc${counter}`] = constraintFilter.field.sysname; constraintParamPart[`fo${counter}`] = constraintFilterOperatorValue; const constraintOperatorType = this.getFieldFilterOperatorValueType(constraintFilter.operator); if (constraintOperatorType === 'twoValues') { constraintParamPart[`fvl${counter}`] = constraintFilter.values[0]; constraintParamPart[`fvr${counter}`] = constraintFilter.values[1]; } else if (constraintOperatorType === 'twoDates') { constraintParamPart[`fvl${counter}`] = moment(constraintFilter.values[0]).format(this.$izendaSettingsService.getDateFormat().shortDate); constraintParamPart[`fvr${counter}`] = moment(constraintFilter.values[1]).format(this.$izendaSettingsService.getDateFormat().shortDate); } else if (constraintOperatorType === 'oneDate') { constraintParamPart[`fvl${counter}`] = moment(constraintFilter.values[0]).format(this.$izendaSettingsService.getDateFormat().shortDate); } else if (constraintOperatorType === 'field') { const val = angular.isObject(constraintFilter.values[0]) ? constraintFilter.values[0].sysname : ''; constraintParamPart[`fvl${counter}`] = val; } else { constraintParamPart[`fvl${counter}`] = constraintFilter.values.join(','); } angular.extend(queryParams, constraintParamPart); counter++; } });
angular.module("eperusteApp").directive("oikeustarkastelu", function(PerusteprojektiOikeudetService) { return { restrict: "A", link(scope, element: any, attrs: any) { var oikeudet = scope.$eval(attrs.oikeustarkastelu); if (!angular.isArray(oikeudet)) { oikeudet = [oikeudet]; } if ( !_.any(oikeudet, function(o: any) { return PerusteprojektiOikeudetService.onkoOikeudet(o.target, o.permission); }) ) { // Ei toimi jos ng-disabled myös käytössä /* if (element.prop("tagName") === "BUTTON") { element.prop("disabled", true); } else { element.hide(); } */ element.hide(); } } }; });
this.appendTransform = function (defaults: any, transform: any) { // We can't guarantee that the default transformation is an array defaults = angular.isArray(defaults) ? defaults : [defaults]; // Append the new transformation to the defaults return defaults.concat(transform); }