UNPKG

@progress/kendo-angular-gantt

Version:
119 lines (118 loc) 4.85 kB
/**----------------------------------------------------------------------------------------- * 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 { EMPTY, forkJoin, isObservable, of, Subject } from 'rxjs'; import { map, expand, reduce } from 'rxjs/operators'; import { MappingService } from '../common/mapping.service'; import { isPresent, normalizeGanttData } from '../utils'; import * as i0 from "@angular/core"; import * as i1 from "../common/mapping.service"; /** * @hidden */ export class EditService { mapper; showEditingDialog = new Subject(); taskDelete = new Subject(); editEvent = new Subject(); addEvent = new Subject(); taskFormGroup; dataItem; getSelectedItem; hasChildren; fetchChildren; set dependencies(items) { // Can this whole thing be moved to edit-dialog? Dependencies might not be needed here const dataItemId = this.mapper.extractFromTask(this.dataItem, 'id'); this.predecessors = items.filter(item => this.mapper.extractFromDependency(item, 'toId') === dataItemId); this.successors = items.filter(item => this.mapper.extractFromDependency(item, 'fromId') === dataItemId); } get dependencies() { return [...this.predecessors, ...this.successors]; } predecessors = []; successors = []; updatedItems = []; deletedItems = []; constructor(mapper) { this.mapper = mapper; } createEditDialog(dataItem, taskFormGroup, dependencies) { this.dataItem = dataItem; this.taskFormGroup = taskFormGroup; this.dependencies = dependencies; this.showEditingDialog.next(true); } closeEditDialog() { this.showEditingDialog.next(false); this.dataItem = undefined; this.taskFormGroup = undefined; this.dependencies = []; this.updatedItems = []; this.deletedItems = []; } triggerEditEvent(editResultType) { this.editEvent.next({ taskFormGroup: this.taskFormGroup, dataItem: this.dataItem, dependencies: { createdItems: this.getCreatedDependencies(), updatedItems: this.updatedItems, deletedItems: this.deletedItems }, editResultType }); } updateDependencies(item) { if (!this.isNew(item)) { // update const index = this.itemIndex(item, this.updatedItems); if (index !== -1) { this.updatedItems.splice(index, 1, item); } else { this.updatedItems.push(item); } } } getCreatedDependencies() { return this.dependencies.filter(item => this.mapper.extractFromDependency(item, 'id') === null); } deleteDependency(item) { const updatedIndex = this.itemIndex(item, this.updatedItems); if (updatedIndex !== -1) { this.updatedItems.splice(updatedIndex, 1); } if (!this.isNew(item)) { this.deletedItems.push(item); } } loadTasks(initialValues, isInitializer = true) { return forkJoin(initialValues.map(v => this.getElementById(v))).pipe(map((value) => value.reduce((acc, item) => acc = acc.concat(normalizeGanttData(item)), [])), expand(values => { if (values.some(el => this.hasChildren(el))) { return this.loadTasks(values, false); } return EMPTY; }), reduce((acc, values) => acc.concat(values), isInitializer ? [...initialValues] : [])); } getElementById(item) { const children = this.fetchChildren(item); if (isObservable(children)) { return children; } return of(children); } itemIndex = (item, data) => { return data.findIndex(dataItem => this.mapper.extractFromTask(dataItem, 'id') === this.mapper.extractFromTask(item, 'id')); }; isNew(item) { return !isPresent(this.mapper.extractFromDependency(item, 'id')); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: EditService, deps: [{ token: i1.MappingService }], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: EditService }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: EditService, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: i1.MappingService }] });