yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
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',
}