import {combine, createNewContext, derive, input, multiInput, StatesGroup} from "reactivestates"; import {Subject} from "rxjs"; import {opServicesModule} from "../angular-modules"; import {QueryFormResource} from "./api/api-v3/hal-resources/query-form-resource.service"; import {QueryResource} from "./api/api-v3/hal-resources/query-resource.service"; import {SchemaResource} from "./api/api-v3/hal-resources/schema-resource.service"; import {TypeResource} from "./api/api-v3/hal-resources/type-resource.service"; import {WorkPackageResource} from "./api/api-v3/hal-resources/work-package-resource.service"; import { GroupObject, WorkPackageCollectionResource } from "./api/api-v3/hal-resources/wp-collection-resource.service"; import {WorkPackageEditForm} from "./wp-edit-form/work-package-edit-form"; import {WorkPackageTableColumns} from "./wp-fast-table/wp-table-columns"; import {WorkPackageTableFilters} from "./wp-fast-table/wp-table-filters"; import {WorkPackageTableGroupBy} from "./wp-fast-table/wp-table-group-by"; import {WorkPackageTablePagination} from "./wp-fast-table/wp-table-pagination"; import {WorkPackageTableSortBy} from "./wp-fast-table/wp-table-sort-by"; import {WorkPackageTableSum} from "./wp-fast-table/wp-table-sum"; import {WPTableRowSelectionState} from "./wp-fast-table/wp-table.interfaces"; import {whenDebugging} from "../helpers/debug_output"; import {WorkPackageTableHierarchies} from "./wp-fast-table/wp-table-hierarchies"; import {WorkPackageTableTimelineState} from "./wp-fast-table/wp-table-timeline"; import {TableRenderResult} from "./wp-fast-table/builders/primary-render-pass"; import {SwitchState} from "./states/switch-state"; import {WorkPackageTableRelationColumns} from './wp-fast-table/wp-table-relation-columns'; export class States extends StatesGroup { name = "MainStore"; /* /api/v3/work_packages */ workPackages = multiInput(); /* /api/v3/schemas */ schemas = multiInput(); /* /api/v3/types */ types = multiInput(); // Work package table states table = new TableState(); tableRendering = new TableRenderingStates(this.table); // Updater states on user input updates = new UserUpdaterStates(this.table); // Current focused work package (e.g, row preselected for details button) focusedWorkPackage = input(); // Open editing forms editing = multiInput(); } export class TableState { name = "TableStore"; // Current context of table loading context = new SwitchState<'Query loaded'>(); // the query associated with the table query = input(); // the results associated with the table results = input(); // the query form associated with the table form = input(); // Set of work package IDs in strict order of appearance rows = input(); // all groups returned as results groups = input(); // Set of columns in strict order of appearance columns = input(); // Set of filters filters = input(); // Active and available sort by sortBy = input(); // Active and available group by groupBy = input(); // is query summed sum = input(); // pagination information pagination = input(); // Table row selection state selection = input(); // Current state of collapsed groups (if any) collapsedGroups = input<{[identifier:string]: boolean}>(); // Hierarchies of table hierarchies = input(); // State to be updated when the table is up to date rendered = input(); // State to determine timeline visibility timelineVisible = input(); // Subject used to unregister all listeners of states above. stopAllSubscriptions = new Subject(); // Fire when table refresh is required refreshRequired = input(); // Expanded relation columns relationColumns = input(); } export class TableRenderingStates { constructor(private table:TableState) { } // State when all required input states for the current query are ready private combinedTableStates = combine( this.table.rows, this.table.columns, this.table.sum, this.table.groupBy, this.table.sortBy, this.table.relationColumns ); onQueryUpdated = derive(this.combinedTableStates, ($, input) => $.mapTo(null)); } export class UserUpdaterStates { constructor(private table:TableState) { } columnsUpdates = this.table.context.fireOnStateChange(this.table.columns, 'Query loaded'); hierarchyUpdates = this.table.context.fireOnStateChange(this.table.hierarchies, 'Query loaded'); relationUpdates = this.table.context.fireOnStateChange(this.table.relationColumns, 'Query loaded'); } const ctx = createNewContext(); const states = ctx.create(States); whenDebugging(() => { states.enableLog(true); }); opServicesModule.value('states', states);