mm-m3-list
Version:
Created as a helper for H5-SDK in order to display a panel B of an M3 panel whether via Bookmark or SearchRequest. Do not use this library to load a transactional program or programs that will require to load thousands of data at one go. By default this
374 lines (367 loc) • 14.3 kB
JavaScript
import * as i0 from '@angular/core';
import { Injectable, EventEmitter, Component, Input, Output, ViewChild, NgModule } from '@angular/core';
import * as i2 from 'ids-enterprise-ng';
import { SohoDataGridComponent, SohoComponentsModule } from 'ids-enterprise-ng';
import { BehaviorSubject } from 'rxjs';
import { finalize } from 'rxjs/operators';
import * as i1 from '@infor-up/m3-odin-angular';
import * as i3 from '@angular/common/http';
import { HttpClientModule } from '@angular/common/http';
import * as i4 from '@angular/common';
import { CommonModule } from '@angular/common';
class MMM3ListService {
constructor() { }
}
MMM3ListService.ɵfac = function MMM3ListService_Factory(t) { return new (t || MMM3ListService)(); };
MMM3ListService.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: MMM3ListService, factory: MMM3ListService.ɵfac, providedIn: 'root' });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MMM3ListService, [{
type: Injectable,
args: [{
providedIn: 'root'
}]
}], function () { return []; }, null); })();
class ProgramInstance {
constructor(formService, instanceId) {
this.formService = formService;
this.instanceId = instanceId;
}
executeCommand(commandType, commandValue, params) {
const request = {
commandType,
commandValue,
params,
instanceId: this.instanceId
};
return this.formService.executeRequest(request);
}
}
class MMM3ListComponent {
constructor(formService, messageService, http) {
this.formService = formService;
this.messageService = messageService;
this.http = http;
/**
* Busy indicator
*/
this.isBusy = false;
/**
* Custom gridOptions. Column definitions will not be overrwitten
*/
this.gridOptions = undefined;
/**
* Columns to be ignored
*/
this.ignoredColumns = [];
/**
* Key-value pair to overwrite the column heading. Key would be the column name and value will be the overriding column label
*/
this.columnHeadings = {};
/**
* Flag if to add the default filterable column from bookmark
*/
this.useDefaultFilter = true;
/**
* List of columns that will have a filter
*/
this.filterables = [];
/**
* List of columns that are editable
*/
this.editables = [];
/**
* Number of page down request for a bookmark. Default would load upto 99 rows
*/
this.requestCount = 3;
/**
* If selection checkbox will be added as a column
*/
this.enableCheckbox = false;
/**
* Emits when first set of data has been loaded
*/
this.firstDataRetrieved = new EventEmitter();
/**
* Emits when data has been loaded
*/
this.dataRetrieved = new EventEmitter();
/**
* Subject and observable for shown records
*/
this.dataSubject$ = new BehaviorSubject([]);
this.data = this.dataSubject$.asObservable();
/**
* Will contain the complete data after all records has been loaded.
* Used for when the gridOption groupable is enabled
*/
this.allItems = [];
/**
* Default gridOptions
*/
this.defaultOptions = {
columns: [],
selectable: 'mixed',
disableRowDeactivation: true,
filterable: false,
paging: false,
rowHeight: 'short'
};
}
ngOnInit() {
this.allItems = [];
if (!this.gridOptions) {
this.gridOptions = this.defaultOptions;
}
else {
this.gridOptions = { ...this.defaultOptions, ...this.gridOptions };
}
}
onResponse(response) {
this.instanceId = response.instanceId;
if (response.result !== 0) {
this.onError(response);
return;
}
if (response.panel.list) {
const panel = response.panel;
const items = panel.list.items;
this.createColumns(panel);
this.allItems = [...this.allItems, ...items];
// Do not show initial data if groupable is used.
// All data needs to be retrieved before showing data.
if (!this.gridOptions.groupable) {
this.dataSubject$.next(items);
}
// Emit event that first set of records has been fetched
setTimeout(() => {
this.firstDataRetrieved.emit();
});
if (this.searchRequest) {
this.dataLoaded();
return;
}
if (this.bookmark && !this.searchRequest) {
if (items.length < 33) {
this.dataLoaded();
return;
}
const programInstance = new ProgramInstance(this.formService, this.instanceId);
this.loadAllRows(programInstance, 1);
}
}
else {
this.dataLoaded();
}
}
createColumns(panel) {
const columns = [];
if (this.gridOptions.columns.length === 0) {
if (this.enableCheckbox) {
columns.push({
id: 'selectionCheckbox',
sortable: false,
resizable: false,
width: 50,
formatter: Soho.Formatters.SelectionCheckbox,
align: 'center'
});
}
panel.list.columns.forEach((col) => {
if (this.ignoredColumns.indexOf(col.fullName) === -1) {
columns.push({
id: col.fullName,
field: col.fullName,
name: this.columnHeadings[col.fullName] ? this.columnHeadings[col.fullName] : col.header,
align: col.isRight ? 'right' : 'left',
filterType: col.positionField && this.useDefaultFilter || this.filterables.indexOf(col.fullName) > -1 ?
col.isRight ? 'integer' : 'text' : null,
editor: this.editables.indexOf(col.fullName) > -1 ? Soho.Editors.Input : null
});
}
});
if (this.additionalColumns) {
this.additionalColumns.forEach((column) => {
if (column.idx) {
columns.splice(column.idx, 0, column);
}
else {
columns.push(column);
}
});
}
this.dataGrid.updateColumns(columns, null);
}
}
/**
* Recursive funciton to load all rows
*/
loadAllRows(programInstance, count) {
if (count > this.requestCount) {
this.dataLoaded();
return;
}
programInstance.executeCommand('PAGE', 'DOWN').subscribe(response => {
const panel = response.panel;
if (panel.list.items.length === 0) {
this.dataLoaded();
return;
}
// Add new data to existing
const newItems = [...this.allItems, ...panel.list.items];
this.allItems = [...newItems];
if (!this.gridOptions.groupable) {
this.dataSubject$.next(newItems);
}
this.loadAllRows(programInstance, ++count);
});
}
openBookmark() {
this.allItems = [];
const defaultBookmark = {
isStateless: false,
values: {}
};
this.isBusy = true;
this.formService
.executeBookmark({ ...defaultBookmark, ...this.bookmark })
.subscribe((r) => this.onResponse(r), (r) => this.onError(r), () => {
if (!this.gridOptions.groupable) {
this.isBusy = false;
}
});
}
executeSearch() {
this.isBusy = true;
this.formService.executeSearch(this.searchRequest).subscribe((r) => {
this.onResponse(r);
}, (r) => {
this.onError(r);
}, () => {
this.isBusy = false;
});
}
selectedRows() {
const selectedRows = [];
this.dataGrid.selectedRows().forEach(item => {
selectedRows.push(item.data);
});
return selectedRows;
}
getItems() {
return this.dataGrid.dataset;
}
updateItems(items) {
this.dataSubject$.next(items);
}
dataLoaded() {
if (this.gridOptions.groupable) {
this.dataSubject$.next(this.allItems);
}
this.closeInstance();
}
closeInstance() {
this.formService
.executeCommand('CLOSE', this.instanceId)
.pipe(finalize(() => {
this.isBusy = false;
setTimeout(() => {
this.dataRetrieved.emit();
});
}))
.subscribe();
return;
}
onError(response) {
const message = response.message || 'Unable to open bookmark';
const buttons = [{ text: 'OK', click: (e, modal) => { modal.close(); } }];
this.messageService.error()
.title('Bookmark error')
.message(message)
.buttons(buttons)
.open();
}
}
MMM3ListComponent.ɵfac = function MMM3ListComponent_Factory(t) { return new (t || MMM3ListComponent)(i0.ɵɵdirectiveInject(i1.FormService), i0.ɵɵdirectiveInject(i2.SohoMessageService), i0.ɵɵdirectiveInject(i3.HttpClient)); };
MMM3ListComponent.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: MMM3ListComponent, selectors: [["mm-m3-list"]], viewQuery: function MMM3ListComponent_Query(rf, ctx) { if (rf & 1) {
i0.ɵɵviewQuery(SohoDataGridComponent, 5);
} if (rf & 2) {
let _t;
i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.dataGrid = _t.first);
} }, inputs: { bookmark: "bookmark", searchRequest: "searchRequest", gridOptions: "gridOptions", additionalColumns: "additionalColumns", ignoredColumns: "ignoredColumns", columnHeadings: "columnHeadings", useDefaultFilter: "useDefaultFilter", filterables: "filterables", editables: "editables", requestCount: "requestCount", enableCheckbox: "enableCheckbox" }, outputs: { firstDataRetrieved: "firstDataRetrieved", dataRetrieved: "dataRetrieved" }, decls: 3, vars: 6, consts: [["soho-busyindicator", "", 3, "activated", "displayDelay"], ["soho-datagrid", "", 3, "gridOptions", "data"]], template: function MMM3ListComponent_Template(rf, ctx) { if (rf & 1) {
i0.ɵɵelementStart(0, "div", 0);
i0.ɵɵelement(1, "div", 1);
i0.ɵɵpipe(2, "async");
i0.ɵɵelementEnd();
} if (rf & 2) {
i0.ɵɵproperty("activated", ctx.isBusy)("displayDelay", 0);
i0.ɵɵadvance(1);
i0.ɵɵproperty("gridOptions", ctx.gridOptions)("data", i0.ɵɵpipeBind1(2, 4, ctx.data));
} }, dependencies: [i2.SohoBusyIndicatorDirective, i2.SohoDataGridComponent, i4.AsyncPipe], encapsulation: 2 });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MMM3ListComponent, [{
type: Component,
args: [{
selector: 'mm-m3-list',
template: `
<div soho-busyindicator [activated]="isBusy" [displayDelay]="0">
<div soho-datagrid [gridOptions]="gridOptions" [data]="data | async"></div>
</div>`
}]
}], function () { return [{ type: i1.FormService }, { type: i2.SohoMessageService }, { type: i3.HttpClient }]; }, { bookmark: [{
type: Input
}], searchRequest: [{
type: Input
}], gridOptions: [{
type: Input
}], additionalColumns: [{
type: Input
}], ignoredColumns: [{
type: Input
}], columnHeadings: [{
type: Input
}], useDefaultFilter: [{
type: Input
}], filterables: [{
type: Input
}], editables: [{
type: Input
}], requestCount: [{
type: Input
}], enableCheckbox: [{
type: Input
}], firstDataRetrieved: [{
type: Output
}], dataRetrieved: [{
type: Output
}], dataGrid: [{
type: ViewChild,
args: [SohoDataGridComponent]
}] }); })();
class MMM3ListModule {
}
MMM3ListModule.ɵfac = function MMM3ListModule_Factory(t) { return new (t || MMM3ListModule)(); };
MMM3ListModule.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: MMM3ListModule });
MMM3ListModule.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule,
HttpClientModule,
SohoComponentsModule] });
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MMM3ListModule, [{
type: NgModule,
args: [{
declarations: [MMM3ListComponent],
imports: [
CommonModule,
HttpClientModule,
SohoComponentsModule
],
exports: [MMM3ListComponent]
}]
}], null, null); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(MMM3ListModule, { declarations: [MMM3ListComponent], imports: [CommonModule,
HttpClientModule,
SohoComponentsModule], exports: [MMM3ListComponent] }); })();
/*
* Public API Surface of mm-m3-list
*/
/**
* Generated bundle index. Do not edit.
*/
export { MMM3ListComponent, MMM3ListModule, MMM3ListService };
//# sourceMappingURL=mm-m3-list.mjs.map