import { Form } from '../../e2elib/lib/src/pageobjects/form.component';
|
import { ListBase } from '../../libappbase/listbase';
|
import { ListRow } from '../../e2elib/lib/src/pageobjects/list/listrow.component';
|
import { DialogUnitCost } from '../dialogs/dialog.unitcost';
|
import { AppMP } from '../appmp';
|
import { CheckboxBase } from '../../libappbase/checkboxbase';
|
import { QContextMenu } from '../../e2elib/lib/api/pageobjects/qcontextmenu.component';
|
import { ContextMenuSOP } from '../../libappsop/contextmenusop';
|
|
export class FormUnitCost extends Form {
|
public listUnitCost = new ListUnitCost();
|
public cbFilterByAccounts = new CheckboxBase('cbFilterByAccounts');
|
|
public constructor() {
|
super('FormUnitCosts');
|
}
|
|
/**
|
* To pass-in boolean to toggle on FilterByAccount checbox
|
*
|
* @param toBeToggleOn boolean to toggle on or off check box (false | true)
|
*/
|
public async toggleFilterByAccount(toBeToggleOn: boolean): Promise<void> {
|
await this.cbFilterByAccounts.toggle(toBeToggleOn);
|
}
|
}
|
|
export class ListUnitCost extends ListBase {
|
public cmMenu = new QContextMenu('lsContextMenuAccCosts');
|
public dlgUnitCost = new DialogUnitCost();
|
|
public constructor() {
|
super('lsAccountCosts');
|
}
|
|
/**
|
* Check if the context menu item is clickable
|
*
|
* @param menuitem Name of target menu item
|
* @returns An array of combination of boolean and string, where boolean indicate whether the menuItem is clickable and string inidcate the disabled tooltip
|
*/
|
public async verifyIsMenuItemClickable(menuitem: string): Promise<[boolean, string]> {
|
const [isMenuItemClickable, cmMenuItemDisabledTooltip] = await ContextMenuSOP.verifyIsMenuItemClickable(this.cmMenu, menuitem);
|
await this.cmMenu.dismiss();
|
return [isMenuItemClickable, cmMenuItemDisabledTooltip];
|
}
|
|
/**
|
* Open create edit unit cost dialog in the list.
|
*
|
* @param row Row, or rows of unit cost to edit. Create dialog will be triggered if this is undefined. Batch edit will be triggered if
|
* row is of type `ListRow[]`.
|
* @param isCopy Indicate to open the dialog for copy or edit, defaulted to false (edit). Only works if row is of type `ListRow` for now
|
* (until there's batch copy feature in MP)
|
*/
|
public async openEditDialog(row?: ListRow | ListRow[], isCopy: boolean = false): Promise<DialogUnitCost> {
|
if (row !== undefined && !Array.isArray(row)) {
|
await row.rightClick(undefined, this.cmMenu, isCopy ? ListUnitCostContextMenuItem.MenuCopy : ListUnitCostContextMenuItem.MenuEdit);
|
} else if (row === undefined || row.length <= 0) {
|
await this.rightClick(undefined, this.cmMenu, ListUnitCostContextMenuItem.MenuCreate);
|
} else {
|
const modifier = { control: true };
|
await row[0].leftClick();
|
for (let index = 1; index < row.length - 1; index++) {
|
await row[index].leftClick(modifier);
|
}
|
await row[row.length - 1].rightClick(modifier, this.cmMenu, ListUnitCostContextMenuItem.MenuEdit);
|
}
|
await this.dlgUnitCost.waitUntilPresent();
|
return this.dlgUnitCost;
|
}
|
|
/**
|
* Find unit cost by value from the list
|
*
|
* @param unit Unit column value
|
* @param account Account column value
|
* @param costDriver Cost driver column value
|
* @param start Start column value
|
* @returns ListRow that matched or undefined if no row found
|
*/
|
public async getUnitCostRowByValues(unit: string, account: string, costDriver: string, start: string): Promise<ListRow | undefined> {
|
const result = await this.getRowByValue([
|
{ columnID: ListUnitCostColumn.Unit, value: unit },
|
{ columnID: ListUnitCostColumn.Account, value: account },
|
{ columnID: ListUnitCostColumn.CostDriver, value: costDriver },
|
{ columnID: ListUnitCostColumn.Start, value: start },
|
]).catch(() => undefined);
|
|
return result;
|
}
|
|
/**
|
* Open edit unit cost dialog on row action bar page
|
*
|
* @param row Unit cost row to edit
|
*/
|
public async editRowByActionBarPage(row: ListRow): Promise<DialogUnitCost> {
|
await row.leftClick();
|
await AppMP.getInstance().abpData.btnEdit.click();
|
await this.dlgUnitCost.waitUntilPresent();
|
return this.dlgUnitCost;
|
}
|
|
/**
|
* Drag the source list row and drop it on the target list row
|
*
|
* @param sourceRow The list row to be dragged
|
* @param targetRow The list row to be dropped
|
* @returns DialogUnitCost
|
*/
|
public async dragEntityToCreateUnitCost(sourceRow: ListRow | ListRow[], targetRow: ListRow): Promise<DialogUnitCost> {
|
await this.dropRowOnTargetRow(sourceRow, targetRow);
|
await this.dlgUnitCost.waitUntilPresent();
|
return this.dlgUnitCost;
|
}
|
|
/**
|
* Select multiple rows by display name to drag and drop onto a selected element
|
*
|
* @param entityRows Target entity rows to be drag
|
* @param targetElement Target element to drop onto
|
* @returns DialogUnitCost
|
*/
|
public async dragEntitiesToCreateUnitCost(entityRows: ListRow[], targetRow: ListRow): Promise<DialogUnitCost> {
|
for (const [index, entityRow] of entityRows.entries()) {
|
const modifier = index === 0 ? undefined : { control: true };
|
await entityRow.leftClick(modifier);
|
}
|
return this.dragEntityToCreateUnitCost(entityRows, targetRow);
|
}
|
|
/**
|
* Delete pass-in UnitCost row via "Delete" context menu
|
*
|
* @param unitCostRows Target unit cost row(s) to be delete
|
*/
|
public async deleteUnitCostViaContextMenu(unitCostRows: ListRow[]): Promise<void> {
|
for (const [index, row] of unitCostRows.entries()) {
|
const modifiers = index !== 0 ? { control: true } : undefined;
|
|
if (index === unitCostRows.length - 1) {
|
await row.rightClick(modifiers, this.cmMenu, ListUnitCostContextMenuItem.MenuDelete);
|
} else {
|
await row.leftClick(modifiers);
|
}
|
}
|
}
|
|
/**
|
* Delete pass-in UnitCost row via "Delete" action bar button
|
*
|
* @param unitCostRows Target unit cost row(s) to be delete
|
*/
|
public async deleteUnitCostsViaActionBarButton(unitCostRows: ListRow[]): Promise<void> {
|
for (const [index, row] of unitCostRows.entries()) {
|
const modifiers = index !== 0 ? { control: true } : undefined;
|
await row.leftClick(modifiers);
|
}
|
await AppMP.getInstance().abpData.btnDelete.click();
|
}
|
}
|
|
export enum ListUnitCostColumn {
|
Unit = 'Unit',
|
Account = 'Account',
|
CostDriver = 'Cost driver',
|
Cost = 'Cost',
|
UoM = 'UoM',
|
Start = 'Start',
|
End = 'End',
|
}
|
|
export enum ListUnitCostContextMenuItem {
|
// Component names
|
MenuCreate = 'MenuCreate',
|
MenuEdit = 'MenuEdit',
|
MenuCopy = 'MenuCopy',
|
MenuDelete = 'MenuDelete',
|
}
|