ui5_easy_use
Version:
A utility package for UI5 projects
97 lines (73 loc) • 3.69 kB
JavaScript
sap.ui.define([
"sap/ui/core/UIComponent",
"${ez5.appName}/model/models",
"${ez5.appName}/${ez5.packgName}/auth/Auth",
"${ez5.appName}/${ez5.packgName}/i18n/Language",
"${ez5.appName}/${ez5.packgName}/auth/GetUserSF",
"${ez5.appName}/${ez5.packgName}/Helper/Env",
"${ez5.appName}/${ez5.packgName}/auth/UserFromShell",
"${ez5.appName}/${ez5.packgName}/initapp/LoadJson",
], (UIComponent, models, Auth, Language, GetUserSF, Env, UserFromShell, LoadJson) => {
"use strict";
return UIComponent.extend("${ez5.appName}.Component", {
metadata: {
manifest: "json",
interfaces: [
"sap.ui.core.IAsyncContentCreation"
]
},
async init() {
// ## call the base component's init function
UIComponent.prototype.init.apply(this, arguments);
// ## set the device model
this.setModel(models.createDeviceModel(), "device");
// ==========## Get Env ##========== //
this.env = new Env(this) // Env
this.env.init()
// ==========## Get Models ##========== //
const sNamespace = "${ez5.appName}"; // Replace with your application namespace
const loadJson = new LoadJson(this, sNamespace)
const { modelsJson, modelsData } = await loadJson.getModel(sNamespace)
// ==========## Get User ##========== //
// ## User Id And Rule
this.userInfo = {}
if (!this.env.zVars.isProduction) {
this.userInfo = { userId: "20413", rules: ['normal', 'admin'] } // retur User Id , Rules of the users
} else { // For Sacces Factor (SF) API
this.userFromShell = new UserFromShell(this)
const { userId, rules } = await this.userFromShell.getUserIdAndRole(); // get user Id From Cloude foundtry retur User Id , Rules of the users
if (!userId) { return null }
// ## User Info
this.getUserSF = new GetUserSF(this);
const userInfo = await this.getSlcUserInfo(userId) // Call API
this.userInfo = userInfo[0] // set User Info
this.userInfo['rules'] = rules // Set Rules
}
// ==========## RoleManager - AccessControl (auth) ##========== //
// ## Auth
this.auth = new Auth(this);
await this.auth.start(this.userInfo, this.userInfo['rules']); // Set the user roles
this.getRouter().attachRouteMatched(this.auth._onRouteMatched, this.auth); // for insure the user have access (Rules)
// filter Nav List
this.auth.setFiteredNavList(modelsData, modelsJson, this.userInfo.rules)
// ==========## Language ##========== //
this.language = new Language(this)
await this.language.init()
this.language.replaceModelsJson(modelsJson)
// ## enable routing
this.getRouter().initialize();
},
// ==========## Language ##========== //
onChangeLanguage: function () { // ## Language ============
return this.language.onChangeLanguage()
},
// ==========## Get User ##========== //
getSlcUserInfo: async function (userId) {
return await this.getUserSF.getSlcUsers(userId)
},
// ==========## Get User ##========== //
getAllUserInfo: async function () {
return await this.getUserSF.getAllUsers()
},
});
});