Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | 47x 47x 47x 47x 47x 47x 47x 47x 47x 45x 47x 47x 47x 47x 47x 47x 6x 4x 8x 8x 8x 3x 9x 9x 3x 15x 15x 3x 3x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 47x 47x 47x 47x 47x 47x 47x 47x 21x 21x 21x 21x 21x 21x 21x 7x 35x 7x 21x 63x 63x 63x 1x 21x 105x 105x 105x 3x 21x 21x 21x 2x 3108x 21x 21x 21x 21x 21x 21x 21x 21x 1x 1x 1x 1x 1x 1x 1x 1554x 1x 1x 8x 1x 1x 1x 113x 113x 113x 113x 113x 113x 113x | import BaseController from "./BaseController";
import Input from "sap/m/Input";
import JSONModel from "sap/ui/model/json/JSONModel";
import SearchField from "sap/m/SearchField";
import Select from "sap/m/Select";
import Table from "sap/m/Table";
import ToggleButton from "sap/m/ToggleButton";
import Filter from "sap/ui/model/Filter";
import FilterOperator from "sap/ui/model/FilterOperator";
import FilterType from "sap/ui/model/FilterType";
import ListBinding from "sap/ui/model/ListBinding";
import Sorter from "sap/ui/model/Sorter";
import Button from "sap/m/Button";
import Dialog from "sap/m/Dialog";
import Popover from "sap/m/Popover";
import Event from "sap/ui/base/Event";
import { compareDates, isDateWithinRelativePeriod } from "../model/germanDate";
import {
FilterOption,
SEARCH_FIELDS,
TEXT_FILTERS,
SELECT_FILTERS,
DATE_FIELDS,
MAINSTREAM_MAINTENANCE_FIELD,
createFilterOptions,
buildFieldDistribution
} from "../model/pamFilters";
import { PamProduct } from "../model/productKey";
interface FilterModelData {
currentStatus: FilterOption[];
unrestrictedAvailable: FilterOption[];
restrictedAvailableNotAllowed: FilterOption[];
mainstreamMaintenance: FilterOption[];
extendedMaintenance: FilterOption[];
}
/**
* @namespace de.itsfullofstars.sap.pam.controller
*/
export default class Main extends BaseController {
private tableBinding?: ListBinding;
/** Sets up the filter/view/viewSettings models and loads the initial filter option values. */
public onInit(): void {
const filterModel = new JSONModel({
currentStatus: [],
unrestrictedAvailable: [],
restrictedAvailableNotAllowed: [],
mainstreamMaintenance: [],
extendedMaintenance: []
});
this.setModel(filterModel, "filter");
this.setModel(new JSONModel({
supportEndHighlightDate: null, // null = no highlighting
showAdvancedFilters: false
}), "view");
const viewSettingsModel = new JSONModel({
heading: this.getText("main.heading", [0]),
columns: {
addOnProductVersion: false,
restrictedAvailableNotAllowed: false,
restrictedAvailableAllowed: false,
readinessStatusForSapHana: false,
readinessDateForSapHana: false,
endOfPriorityOneSupport: false,
endOfSafekeeperService: false,
supportPortalUrl: false
}
});
this.setModel(viewSettingsModel, "viewSettings");
const pamModel = this.getOwnerComponent().getModel("pam") as JSONModel;
Iif (!pamModel) {
return;
}
this.updateFilterValues();
// The "pam" model's data loads asynchronously (manifest "uri"), so it may not
// be available yet when onInit runs - rebuild the filter options once it is.
pamModel.attachRequestCompleted(this.updateFilterValues.bind(this));
}
/** Reacts to the table's list binding changing (e.g. after filtering) by refreshing the heading count. */
private onTableBindingChange(): void {
this.updateTableTitle();
}
/** Attaches the table title's change listener to the current list binding, once. */
public onAfterRendering(): void {
const table = this.byId("pamTable") as Table;
const binding = table.getBinding("items") as ListBinding | undefined;
Eif (binding && this.tableBinding !== binding) {
this.tableBinding = binding;
binding.attachChange(this.onTableBindingChange.bind(this));
}
this.updateTableTitle();
}
/** Re-applies filters/sorting after the global search field's value changes. */
public onSearchChange(): void {
this.applyTableState();
}
/** Re-applies filters/sorting after a filter panel value changes. */
public onFilterChange(): void {
this.applyTableState();
}
/** Updates the sort direction button label and re-applies filters/sorting. */
public onSortChange(): void {
const sortButton = this.byId("sortAscending") as ToggleButton;
sortButton.setText(
sortButton.getPressed()
? this.getText("table.sortAscending")
: this.getText("table.sortDescending")
);
this.applyTableState();
}
/** Clears all filter panel input/select values, without touching search or sorting. */
private resetFilterPanelValues(): void {
TEXT_FILTERS.forEach((filterDefinition) => {
const input = this.byId(filterDefinition.id) as Input;
input.setValue("");
});
SELECT_FILTERS.forEach((filterDefinition) => {
const select = this.byId(filterDefinition.id) as Select;
select.setSelectedKey("");
});
const relativeMaintenanceSelect =
this.byId("filterMainstreamMaintenanceRelative") as Select;
relativeMaintenanceSelect.setSelectedKey("");
}
/**
* Resets only the filter panel's values. Unlike {@link onReset}, the
* table's full-text search and sorting are left untouched.
*/
public onResetFilters(): void {
this.resetFilterPanelValues();
this.applyTableState();
}
/** Resets search, filters and sorting back to their defaults. */
public onReset(): void {
const searchField = this.byId("globalSearch") as SearchField;
searchField.setValue("");
this.resetFilterPanelValues();
const sortField = this.byId("sortField") as Select;
sortField.setSelectedKey("version");
const sortButton = this.byId("sortAscending") as ToggleButton;
sortButton.setPressed(true);
sortButton.setText(this.getText("table.sortAscending"));
this.applyTableState();
}
/** Rebuilds the "filter" model's dropdown options from the current "pam" model data. */
private updateFilterValues(): void {
const pamModel = this.getOwnerComponent().getModel("pam") as JSONModel;
Iif (!pamModel) {
return;
}
const data = pamModel.getData() as PamProduct[];
Iif (!Array.isArray(data)) {
return;
}
const filterModel = this.getModel("filter") as JSONModel;
const allLabel = this.getText("filter.relativeAll");
const filterData: FilterModelData = {
currentStatus: createFilterOptions(data, "status", allLabel),
unrestrictedAvailable: createFilterOptions(data, "ua", allLabel),
restrictedAvailableNotAllowed: createFilterOptions(data, "ra_puna", allLabel),
mainstreamMaintenance: createFilterOptions(data, "eomm", allLabel),
extendedMaintenance: createFilterOptions(data, "eom", allLabel)
};
filterModel.setData(filterData);
}
/** Rebuilds the table's filters and sorter from the current search/filter/sort controls. */
private applyTableState(): void {
const table = this.byId("pamTable") as Table;
const binding = table.getBinding("items") as ListBinding | undefined;
Iif (!binding) {
return;
}
const filters: Filter[] = [];
const searchField = this.byId("globalSearch") as SearchField;
const searchValue = searchField.getValue().trim();
if (searchValue) {
const searchFilters = SEARCH_FIELDS.map((field) => {
return new Filter(
field,
FilterOperator.Contains,
searchValue
);
});
filters.push(
new Filter({
filters: searchFilters,
and: false
})
);
}
TEXT_FILTERS.forEach((filterDefinition) => {
const input = this.byId(filterDefinition.id) as Input;
const value = input.getValue().trim();
if (value) {
filters.push(
new Filter(
filterDefinition.path,
FilterOperator.Contains,
value
)
);
}
});
SELECT_FILTERS.forEach((filterDefinition) => {
const select = this.byId(filterDefinition.id) as Select;
const selectedValue = select.getSelectedKey().trim();
if (selectedValue) {
filters.push(
new Filter(
filterDefinition.path,
FilterOperator.EQ,
selectedValue
)
);
}
});
const relativeMaintenanceSelect =
this.byId("filterMainstreamMaintenanceRelative") as Select;
const relativeMonths = Number(
relativeMaintenanceSelect.getSelectedKey()
);
if (relativeMonths > 0) {
filters.push(
new Filter({
path: MAINSTREAM_MAINTENANCE_FIELD,
test: (value: unknown): boolean => {
return isDateWithinRelativePeriod(value, relativeMonths);
}
})
);
}
binding.filter(filters, FilterType.Application);
const sortField = this.byId("sortField") as Select;
const sortPath = sortField.getSelectedKey();
const sortButton = this.byId("sortAscending") as ToggleButton;
const descending = !sortButton.getPressed();
const sorter = new Sorter({
path: sortPath,
descending,
comparator: DATE_FIELDS.includes(sortPath)
? compareDates
: undefined
});
binding.sort(sorter);
this.updateTableTitle();
}
/** Opens the column-visibility settings popover anchored to the pressed button. */
public onOpenColumnSettings(event: Event): void {
const button = event.getSource<Button>();
const popover = this.byId("columnSettingsPopover") as Popover;
popover.openBy(button);
}
/** Opens the chart analysis dialog with the status distribution of the currently filtered table rows. */
public onShowChartAnalysis(): void {
const table = this.byId("pamTable") as Table;
const binding = table.getBinding("items") as ListBinding | undefined;
Iif (!binding) {
return;
}
const entries = binding
.getContexts(0, binding.getLength())
.map((context) => context.getObject() as PamProduct);
const distribution = buildFieldDistribution(
entries,
"status",
this.getText("chart.unspecifiedValue")
);
const maxCount = distribution.reduce(
(max, entry) => Math.max(max, entry.count),
1
);
this.setModel(
new JSONModel({
totalText: this.getText("chart.entriesShown", [entries.length]),
maxCount,
distribution
}),
"chart"
);
const dialog = this.byId("chartAnalysisDialog") as Dialog;
dialog.open();
}
/** Updates the table heading with the current (filtered) row count. */
private updateTableTitle(): void {
const table = this.byId("pamTable") as Table;
const binding = table.getBinding("items") as ListBinding | undefined;
Iif (!binding) {
return;
}
const count = binding.getLength();
// Don't overwrite with a bogus value while still loading
Iif (count < 0) {
return;
}
const viewSettingsModel =
this.getModel("viewSettings") as JSONModel;
viewSettingsModel.setProperty(
"/heading",
this.getText("main.heading", [count.toLocaleString("de-DE")])
);
}
}
|