@progress/kendo-angular-gauges
Version:
Kendo UI Angular Gauges
99 lines (98 loc) • 3.58 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { Injectable } from '@angular/core';
import * as i0 from "@angular/core";
function isObject(value) {
return typeof value === "object";
}
function diffOptions(original, current) {
if (Object.keys(original).length !== Object.keys(current).length) {
return true;
}
for (const field in original) {
if (field !== 'value' && original.hasOwnProperty(field)) {
const originalValue = original[field];
const currentValue = current[field];
const diff = isObject(originalValue) && isObject(currentValue) ?
diffOptions(originalValue, currentValue) : originalValue !== currentValue;
if (diff) {
return true;
}
}
}
}
function diffPointerOptions(original, current) {
if (!original || !current) {
return true;
}
original = [].concat(original);
current = [].concat(current);
if (original.length !== current.length) {
return true;
}
for (let idx = 0; idx < original.length; idx++) {
if (diffOptions(original[idx], current[idx])) {
return true;
}
}
}
/**
* @hidden
*/
export class ConfigurationService {
options = {};
hasChanges;
valueChange;
copyChanges(prefix, changes) {
for (const propertyName in changes) {
if (!changes.hasOwnProperty(propertyName)) {
continue;
}
const value = changes[propertyName].currentValue;
const optionName = (prefix ? prefix + '.' : '') + propertyName;
this.set(optionName, value);
}
}
read() {
this.hasChanges = false;
this.valueChange = false;
return this.options;
}
readValues() {
this.valueChange = false;
const pointers = [].concat(this.options.pointer);
return pointers.map((pointer) => pointer.value);
}
readValue() {
this.valueChange = false;
return this.options.value;
}
set(field, value) {
const { key, options } = this.optionContext(field);
if (!this.hasChanges && (key === 'value' || (key === 'pointer' && !diffPointerOptions(this.options.pointer, value)))) {
this.valueChange = true;
}
else {
this.hasChanges = true;
this.valueChange = false;
}
options[key] = value;
}
optionContext(field) {
const parts = field.split('.');
let options = this.options;
let key = parts.shift();
while (parts.length > 0) {
options = options[key] = options[key] || {};
key = parts.shift();
}
return { key: key, options: options };
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ConfigurationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ConfigurationService });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ConfigurationService, decorators: [{
type: Injectable
}] });