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 | 47x 47x 47x 104x 104x 104x 4x 13x 26x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import BaseController from "./BaseController";
import JSONModel from "sap/ui/model/json/JSONModel";
import MessageBox from "sap/m/MessageBox";
import MessageToast from "sap/m/MessageToast";
import { Router$RoutePatternMatchedEvent } from "sap/ui/core/routing/Router";
import { parseJsonArrayOfObjects } from "../model/jsonArrayParser";
import { pickJsonFile } from "../util/JsonFileUpload";
/**
* @namespace de.itsfullofstars.sap.pam.controller
*/
export default class App extends BaseController {
/** Sets up the "navigation" model used to highlight the active nav tab, and wires route tracking. */
public onInit(): void {
this.getView().addStyleClass(this.getOwnerComponent().getContentDensityClass());
this.setModel(new JSONModel({
activeRoute: ""
}), "navigation");
this.getRouter().attachRoutePatternMatched(this.onAnyRouteMatched.bind(this));
}
/**
* Tracks which route is currently active, so the navigation tabs in the
* app toolbar can highlight the current page via color/underline (see
* pamNavTab/pamNavTabActive in css/style.css).
* @param oEvent The routePatternMatched event of the router
*/
private onAnyRouteMatched(oEvent: Router$RoutePatternMatchedEvent): void {
const routeName = oEvent.getParameter("name");
const navigationModel = this.getModel("navigation") as JSONModel;
navigationModel.setProperty("/activeRoute", routeName ?? "");
}
/** Navigates to the Main (product table) route. */
public onNavigateToMain(): void {
this.getRouter().navTo("main");
}
/** Navigates to the SupportStatus route. */
public onNavigateToSupportStatus(): void {
this.getRouter().navTo("supportstatus");
}
/** Navigates to the MyProducts route. */
public onNavigateToMyProducts(): void {
this.getRouter().navTo("myproducts");
}
/** Opens a file picker and replaces the global "pam" model with the uploaded JSON. */
public onUploadPamJson(): void {
pickJsonFile(
(fileContent) => this.replacePamModel(fileContent),
() => MessageBox.error(this.getText("msg.pamFileReadError"))
);
}
/** Opens a file picker and replaces the global "ownProducts" model with the uploaded JSON. */
public onUploadOwnProducts(): void {
pickJsonFile(
(fileContent) => this.replaceOwnProductsModel(fileContent),
() => MessageBox.error(this.getText("msg.ownProductsFileReadError"))
);
}
/**
* Validates the uploaded file content and, on success, replaces the
* "pam" model's data wholesale.
* @param fileContent The raw text content of the uploaded file
*/
private replacePamModel(
fileContent: string
): void {
const result = parseJsonArrayOfObjects(fileContent);
switch (result.kind) {
case "parseError":
MessageBox.error(this.getText("msg.invalidJson"));
return;
case "notArray":
MessageBox.error(this.getText("msg.pamFileMustBeArray"));
return;
case "invalidEntries":
MessageBox.error(this.getText("msg.pamFileInvalidEntries"));
return;
}
const pamModel = this.getOwnerComponent()
.getModel("pam") as JSONModel;
Iif (!pamModel) {
MessageBox.error(
this.getText("msg.pamModelUnavailable")
);
return;
}
pamModel.setData(result.data);
MessageToast.show(
this.getText("msg.pamEntriesLoaded", [result.data.length])
);
}
/**
* Validates the uploaded file content and, on success, replaces the
* "ownProducts" model's data wholesale.
* @param fileContent The raw text content of the uploaded file
*/
private replaceOwnProductsModel(
fileContent: string
): void {
const result = parseJsonArrayOfObjects(fileContent);
switch (result.kind) {
case "parseError":
MessageBox.error(this.getText("msg.invalidJson"));
return;
case "notArray":
MessageBox.error(this.getText("msg.ownProductsFileMustBeArray"));
return;
case "invalidEntries":
MessageBox.error(this.getText("msg.ownProductsFileInvalidEntries"));
return;
}
const ownProductsModel = this.getOwnerComponent()
.getModel("ownProducts") as JSONModel;
Iif (!ownProductsModel) {
MessageBox.error(
this.getText("msg.ownProductsModelUnavailable")
);
return;
}
ownProductsModel.setData(result.data);
MessageToast.show(
this.getText("msg.ownProductsLoaded", [result.data.length])
);
}
}
|