HRM-10/HRM.UI/ClientApp/src/app/app.topbar.component.js

521 lines
26 KiB
JavaScript
Raw Normal View History

2026-11-03 13:06:00 +06:00
"use strict";
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
var useValue = arguments.length > 2;
for (var i = 0; i < initializers.length; i++) {
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
}
return useValue ? value : void 0;
};
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
var _, done = false;
for (var i = decorators.length - 1; i >= 0; i--) {
var context = {};
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
if (kind === "accessor") {
if (result === void 0) continue;
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
if (_ = accept(result.get)) descriptor.get = _;
if (_ = accept(result.set)) descriptor.set = _;
if (_ = accept(result.init)) initializers.unshift(_);
}
else if (_ = accept(result)) {
if (kind === "field") initializers.unshift(_);
else descriptor[key] = _;
}
}
if (target) Object.defineProperty(target, contextIn.name, descriptor);
done = true;
};
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppTopBarComponent = void 0;
var core_1 = require("@angular/core");
var app_api_service_1 = require("./app.api.service");
var bookmark_1 = require("./_models/Basic/bookmark");
var role_1 = require("./_models/Authentication/role");
var angular_jwt_1 = require("@auth0/angular-jwt");
var enums_1 = require("./_models/enums");
var core_2 = require("@angular/core");
var AppTopBarComponent = function () {
var _classDecorators = [(0, core_1.Component)({
standalone: false,
selector: 'app-topbar',
templateUrl: './app.topbar.component.html',
styleUrls: ['./app.topbar.component.scss'],
})];
var _classDescriptor;
var _classExtraInitializers = [];
var _classThis;
var _instanceExtraInitializers = [];
var _onWindowScroll_decorators;
var _ssNotif_decorators;
var _ssNotif_initializers = [];
var _ssNotif_extraInitializers = [];
var AppTopBarComponent = _classThis = /** @class */ (function () {
function AppTopBarComponent_1(app, appMain, loadingPanel, authService, router, _auth, apiService, menuService, notificationService, dataTransferService, notificationTrigger) {
var _this = this;
var _a, _b;
this.app = (__runInitializers(this, _instanceExtraInitializers), app);
this.appMain = appMain;
this.loadingPanel = loadingPanel;
this.authService = authService;
this.router = router;
this._auth = _auth;
this.apiService = apiService;
this.menuService = menuService;
this.notificationService = notificationService;
this.dataTransferService = dataTransferService;
this.notificationTrigger = notificationTrigger;
this.model = {};
this.loginName = '';
this.selectedMenuName = 'selected Menu';
this.bookmarkIcon = 'pi pi-bookmark';
this.pendingJobDTOs = [];
this.companyNotification = [];
this.pendingJobCount = 0;
this.notificationCount = 0;
this.isSuperUser = false;
this.swithtypeName = undefined;
this.switchUserID = undefined;
this.menuItems = [];
this.activeMenu = null;
this.activeSubMenu = null;
this.mobileMenuOpen = false;
this.mobOpenSection = null;
this.mobOpenSubSection = null;
// Notification panel open/close tracking. Viewed notifications are marked read
// only when the panel CLOSES (see ngDoCheck -> onNotificationPanelClosed).
this.notifPanelWasOpen = false;
this.subscriptions = [];
this.isScrolled = false;
this.ssNotif = __runInitializers(this, _ssNotif_initializers, void 0);
__runInitializers(this, _ssNotif_extraInitializers);
this.app = app;
this.appMain = appMain;
this.loadingPanel = loadingPanel;
this.authService = authService;
this.router = router;
this._auth = _auth;
this.apiService = apiService;
this.menuService = menuService;
this.notificationService = notificationService;
this.dataTransferService = dataTransferService;
this.notificationTrigger = notificationTrigger;
var x = this.apiService.menuItems;
this._auth.menuEvent.subscribe(function (value) { return _this.getloginUser(); });
this.bookmarkIcon = ((_b = (_a = this.menuService) === null || _a === void 0 ? void 0 : _a.clickedMenuItem) === null || _b === void 0 ? void 0 : _b.isBookmarked) ? 'pi pi-bookmark-fill' : 'pi pi-bookmark';
this.pendingJobCount = 0;
var navigation = performance.getEntriesByType('navigation')[0];
if (navigation.type == 'reload') {
this.pendingJobDTOs = JSON.parse(localStorage.getItem('pendingjobs'));
if (this.pendingJobDTOs != undefined) {
this.pendingJobCount = this.pendingJobDTOs != null || this.pendingJobDTOs != undefined
? this.pendingJobDTOs.length
: 0;
}
// Notification list/count are owned by NotificationTriggerService
// (it seeds from localStorage and refreshes from the API on load).
this.menuService.clickedMenuItem = JSON.parse(localStorage.getItem('selectedMenu'));
this.menuService.bookMarkpages = JSON.parse(localStorage.getItem('bookmark'));
var jwtHelper = new angular_jwt_1.JwtHelperService();
var user = jwtHelper.decodeToken(localStorage.getItem('token'));
if (user != undefined) {
this.loginName = user.UserName;
this.isSuperUser = true;
var spItem = localStorage.getItem('switchUserID');
if (spItem != undefined && spItem != null) {
this.isSuperUser = false;
this.swithtypeName = "Switch to Super-User";
this.switchUserID = parseInt(localStorage.getItem('switchUserID'));
}
else if (user.UserType == enums_1.EnumUserType.SuperUser && user.EmployeeID != undefined) {
this.swithtypeName = "Switch to ESS";
}
}
}
if (this.pendingJobDTOs != undefined && this.pendingJobDTOs.length != 0) {
this.pendingJobDTOs = JSON.parse(localStorage.getItem('pendingjobs'));
this.pendingJobCount = this.pendingJobDTOs != null || this.pendingJobDTOs != undefined
? this.pendingJobDTOs.length
: 0;
}
}
AppTopBarComponent_1.prototype.onWindowScroll = function () {
if (this.apiService.isSelService) {
this.isScrolled = window.scrollY > 10;
}
};
AppTopBarComponent_1.prototype.ngOnInit = function () {
var _this = this;
document.addEventListener('click', function (e) {
_this.activeMenu = null;
_this.activeSubMenu = null;
_this.mobileMenuOpen = false;
});
this.loadPendingJobs();
// Notifications: this component is a pure CONSUMER of the shared
// NotificationTriggerService store. It never fetches or counts itself.
this.notificationTrigger.ensureLoaded();
this.subscriptions.push(this.notificationTrigger.notifications$.subscribe(function (list) {
_this.companyNotification = list || [];
}), this.notificationTrigger.unreadCount$.subscribe(function (count) {
_this.notificationCount = count || 0;
}));
};
AppTopBarComponent_1.prototype.ngAfterViewInit = function () {
var _this = this;
this.subscriptions.push(this.notificationTrigger.notificationSource$.subscribe(function () {
_this.appMain.onTopbarItemClick(new MouseEvent('click'), _this.ssNotif.nativeElement);
}));
};
AppTopBarComponent_1.prototype.ngDoCheck = function () {
// Detect the open -> close transition of the shared notification panel.
var isOpen = !!this.ssNotif
&& this.appMain.activeTopbarItem === this.ssNotif.nativeElement;
if (this.notifPanelWasOpen && !isOpen) {
this.onNotificationPanelClosed();
}
this.notifPanelWasOpen = isOpen;
};
/**
* Fires once when the notification panel closes. Hands off to the shared
* store: mark the viewed notifications read -> wait -> re-fetch -> republish.
* companyNotification + notificationCount then update through the
* notifications$ / unreadCount$ subscriptions above - the same path the
* dashboard tile uses, so both stay identical.
*/
AppTopBarComponent_1.prototype.onNotificationPanelClosed = function () {
this.subscriptions.push(this.notificationTrigger.markVisibleAsReadThenRefresh().subscribe());
};
AppTopBarComponent_1.prototype.ngOnDestroy = function () {
this.subscriptions.forEach(function (s) { return s.unsubscribe(); });
};
AppTopBarComponent_1.prototype.loadBookmark = function () {
var _this = this;
this.authService.subject.subscribe(function (resp) {
_this.menuService.bookMarkpages = resp;
}, function () {
}, function () {
});
};
AppTopBarComponent_1.prototype.loadPendingJobs = function () {
var _this = this;
console.log('s2-receive');
this.authService.subject2.subscribe(function (resp) {
_this.pendingJobDTOs = resp;
if (_this.pendingJobDTOs != undefined)
_this.pendingJobCount = _this.pendingJobDTOs.length;
}, function () {
}, function () {
});
};
AppTopBarComponent_1.prototype.toggleFullScreen = function () {
// debugger;
this.apiService.isSelServiceFullScreen = !this.apiService.isSelServiceFullScreen;
};
AppTopBarComponent_1.prototype.openNotifLink = function (url) {
debugger;
if (!url)
return;
var isExternal = /^https?:\/\//i.test(url);
if (isExternal) {
window.open(url, '_blank');
}
else {
this.router.navigateByUrl(url);
}
};
AppTopBarComponent_1.prototype.getloginUser = function () {
var _this = this;
var jwtHelper = new angular_jwt_1.JwtHelperService();
var user = jwtHelper.decodeToken(localStorage.getItem('token'));
this.loginName = user.UserName;
this.isSuperUser = true;
localStorage.removeItem('switchUserID');
this.switchUserID = undefined;
// A fresh login / user-switch just happened - load this user's notifications.
this.notificationTrigger.ensureLoaded();
if ((user.UserType == enums_1.EnumUserType.Employee || user.UserType == enums_1.EnumUserType.User) && user.EmployeeID != undefined) {
// if (this.apiService.isSSO ==true && user.UserType == EnumUserType.User && user.EmployeeID != undefined) {
this.isSuperUser = false;
this.swithtypeName = "Switch to Super-User";
this.switchUserID = undefined;
var userid = undefined;
this.authService.getSwitchUserId(enums_1.EnumUserType.SuperUser).subscribe(function (next) {
userid = next;
}, function (error) {
_this.swithtypeName = undefined;
console.log(error);
}, function () {
if (userid != 0) {
_this.switchUserID = userid;
localStorage.setItem('switchUserID', JSON.stringify(_this.switchUserID));
}
});
}
else if (user.UserType == enums_1.EnumUserType.SuperUser && user.EmployeeID != undefined) {
this.swithtypeName = "Switch to ESS";
}
};
//ngOnInit() {
// this.employee = new Employee();
// this.loadData();
//}
AppTopBarComponent_1.prototype.loadData = function () {
//this.employeeService.getCurrentEmployee().subscribe(
// (resp) => {
// this.employee = resp;
// },
// () => { },
// () => {
// },
//);
};
AppTopBarComponent_1.prototype.login = function () {
var _this = this;
this.authService.login(this.model).subscribe(function (next) {
//show notification
}, function (error) {
console.log(error);
}, function () {
_this.router.navigate(['/training']);
});
};
AppTopBarComponent_1.prototype.loggedIn = function () {
return this.authService.loggedIn();
};
AppTopBarComponent_1.prototype.SwitchUser = function () {
//debugger;
var jwtHelper = new angular_jwt_1.JwtHelperService();
var user = jwtHelper.decodeToken(localStorage.getItem('token'));
this.authService.setIsFromUser(false);
if (user.UserType != enums_1.EnumUserType.SuperUser) {
if (user.UserType == enums_1.EnumUserType.Employee) {
this.swithtypeName = "Switch to ESS";
}
else if (user.UserType == enums_1.EnumUserType.User) {
this.swithtypeName = "Switch to Admin";
this.authService.setIsFromUser(true);
}
user.UserID = this.switchUserID;
user.UserType = enums_1.EnumUserType.SuperUser;
this.authService.setIsFromSuperUser(false);
}
else {
this.authService.setIsFromSuperUser(true);
if (this.swithtypeName === "Switch to Admin") {
user.UserType = enums_1.EnumUserType.User;
}
else if (this.swithtypeName === "Switch to ESS") {
user.UserType = enums_1.EnumUserType.Employee;
}
this.swithtypeName = "Switch to Super-User";
}
return this.switchTheUser(user);
};
AppTopBarComponent_1.prototype.switchTheUser = function (oUser) {
var _this = this;
var data = {
user: oUser,
payrollTypeId: oUser.payrollTypeID,
};
this.loadingPanel.ShowLoadingPanel = true;
this.authService.SwtichUserMode(data).subscribe(function (resp) {
localStorage.setItem('token', resp);
app_api_service_1.ApiService.AuthenticationToken = resp;
}, function (err) {
_this.notificationService.showError('Invalid Login-ID or Password');
_this.loadingPanel.ShowLoadingPanel = false;
}, function () {
var jwtHelper = new angular_jwt_1.JwtHelperService();
var user = jwtHelper.decodeToken(localStorage.getItem('token'));
if (user.UserType != enums_1.EnumUserType.SuperUser) {
_this.swithtypeName = "Switch to ESS";
}
else {
_this.swithtypeName = "Switch to Super-User";
}
if (user.ChangePasswordAtNextLogon === 'True') {
localStorage.removeItem('menuList');
_this._auth.menuEvent.emit(false);
}
else {
_this.authService.GetRolePermissionbyUserID().subscribe(function (menu) {
localStorage.setItem('menuList', JSON.stringify(menu));
}, function (errmenu) {
}, function () {
_this._auth.menuEvent.emit(true);
_this.loadingPanel.ShowLoadingPanel = false;
_this.appMain.IsSelfService();
if (user.UserType == enums_1.EnumUserType.Employee) {
if (_this.apiService.isNewDaswhboard !== undefined) {
if (_this.apiService.isNewDaswhboard === true) {
_this.router.navigate(['/ess/self-dashboard']);
}
else {
_this.router.navigate(['/ess/ess-dashboard']);
}
}
else {
_this.router.navigate(['/ess/self-dashboard']);
}
// this.router.navigate(['/ess/ess-dashboard']);
}
else if (user.UserType == enums_1.EnumUserType.User) {
_this.router.navigate(['/ess/landing-page']);
}
else {
_this.router.navigate(['/']);
}
});
}
});
};
AppTopBarComponent_1.prototype.logout = function () {
this.pendingJobCount = 0;
this.pendingJobDTOs = undefined;
this.authService.logout();
//localStorage.removeItem('forgotpass');
//localStorage.removeItem('token');
//localStorage.removeItem('menuList');
////show notification
//this.router.navigate(['/login']);
};
AppTopBarComponent_1.prototype.onBookMark = function () {
var _this = this;
var bookmark = new bookmark_1.Bookmark();
if (this.menuService.clickedMenuItem !== undefined) {
if (this.menuService.clickedMenuItem.isBookmarked === false) {
bookmark.link = this.menuService.clickedMenuItem.link;
bookmark.description = this.menuService.clickedMenuItem.name;
bookmark.menuCode = this.menuService.clickedMenuItem.menuKey;
this.menuService.bookMarkpages.push(bookmark);
// this.bookmarkIcon = 'pi pi-bookmark-fill' ;
this.menuService.clickedMenuItem.isBookmarked = true;
this.authService.SaveBookmark(bookmark).subscribe(function (x) {
}, function (x) {
_this.notificationService.showError(x.error);
}, function () {
_this.notificationService.showSuccess('You have successfully bookmarked this page.');
_this.getBookmark();
localStorage.setItem('selectedMenu', JSON.stringify(_this.menuService.clickedMenuItem));
});
}
else {
bookmark.link = this.menuService.clickedMenuItem.link;
bookmark.description = this.menuService.clickedMenuItem.name;
bookmark.menuCode = this.menuService.clickedMenuItem.menuKey;
var index = this.menuService.bookMarkpages.findIndex(function (x) { return x.menuCode === bookmark.menuCode; });
this.menuService.bookMarkpages.splice(index, 1);
this.menuService.clickedMenuItem.isBookmarked = false;
this.authService.deleteBookmarkByMenuKey(bookmark).subscribe(function (x) {
}, function (x) {
_this.notificationService.showError(x.error);
}, function () {
_this.notificationService.showSuccess('You have successfully removed bookmark this page.');
_this.getBookmark();
localStorage.setItem('selectedMenu', JSON.stringify(_this.menuService.clickedMenuItem));
});
}
}
};
AppTopBarComponent_1.prototype.bookMarkedLinkClicked = function (b) {
this.menuService.clickedMenuItem = new role_1.RolePermission();
this.menuService.clickedMenuItem.name = b.description;
this.menuService.clickedMenuItem.menuKey = b.menuCode;
this.menuService.clickedMenuItem.isBookmarked = true;
this.router.navigate([b.link]);
};
AppTopBarComponent_1.prototype.ApprovePendingJob = function (dataItem) {
// debugger;
this.dataTransferService.setData(dataItem.id);
this.router.navigateByUrl(dataItem.link);
};
AppTopBarComponent_1.prototype.getBookmark = function () {
var _this = this;
this.authService.getBookmarks()
.subscribe(function (resp) {
if (resp != undefined) {
_this.menuService.bookMarkpages = resp;
}
}, function (x) {
}, function () {
localStorage.removeItem('bookmark');
localStorage.setItem('bookmark', JSON.stringify(_this.menuService.bookMarkpages));
});
};
AppTopBarComponent_1.prototype.handleHrmAiClick = function () {
//this.router.navigate(['/hrmopen-ai/hrm-open-ai-test']);
};
AppTopBarComponent_1.prototype.openMenu = function (menuKey) {
clearTimeout(this.closeTimer);
this.activeMenu = menuKey;
};
AppTopBarComponent_1.prototype.scheduleClose = function () {
};
AppTopBarComponent_1.prototype.toggleMenu = function (event, menuKey) {
event.preventDefault();
event.stopPropagation();
this.activeMenu = menuKey;
this.activeSubMenu = null;
};
AppTopBarComponent_1.prototype.openSubMenu = function (menuKey) {
clearTimeout(this.closeTimer);
this.activeSubMenu = menuKey;
};
AppTopBarComponent_1.prototype.closeSubMenu = function () {
};
AppTopBarComponent_1.prototype.closeAllMenus = function () {
this.activeMenu = null;
this.activeSubMenu = null;
this.mobileMenuOpen = false;
};
AppTopBarComponent_1.prototype.toggleMobileMenu = function (event) {
event.stopPropagation();
this.mobileMenuOpen = !this.mobileMenuOpen;
if (this.mobileMenuOpen) {
this.mobOpenSection = null;
this.mobOpenSubSection = null;
this.appMain.activeTopbarItem = null; // close other dropdowns
}
};
AppTopBarComponent_1.prototype.closeMobileMenu = function () {
this.mobileMenuOpen = false;
this.mobOpenSection = null;
this.mobOpenSubSection = null;
};
AppTopBarComponent_1.prototype.toggleMobSection = function (menuKey) {
this.mobOpenSection = this.mobOpenSection === menuKey ? null : menuKey;
this.mobOpenSubSection = null;
};
AppTopBarComponent_1.prototype.toggleMobSubSection = function (menuKey) {
this.mobOpenSubSection = this.mobOpenSubSection === menuKey ? null : menuKey;
};
return AppTopBarComponent_1;
}());
__setFunctionName(_classThis, "AppTopBarComponent");
(function () {
var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
_onWindowScroll_decorators = [(0, core_2.HostListener)('window:scroll', [])];
_ssNotif_decorators = [(0, core_1.ViewChild)('ssNotif')];
__esDecorate(_classThis, null, _onWindowScroll_decorators, { kind: "method", name: "onWindowScroll", static: false, private: false, access: { has: function (obj) { return "onWindowScroll" in obj; }, get: function (obj) { return obj.onWindowScroll; } }, metadata: _metadata }, null, _instanceExtraInitializers);
__esDecorate(null, null, _ssNotif_decorators, { kind: "field", name: "ssNotif", static: false, private: false, access: { has: function (obj) { return "ssNotif" in obj; }, get: function (obj) { return obj.ssNotif; }, set: function (obj, value) { obj.ssNotif = value; } }, metadata: _metadata }, _ssNotif_initializers, _ssNotif_extraInitializers);
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
AppTopBarComponent = _classThis = _classDescriptor.value;
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
__runInitializers(_classThis, _classExtraInitializers);
})();
return AppTopBarComponent = _classThis;
}();
exports.AppTopBarComponent = AppTopBarComponent;
//# sourceMappingURL=app.topbar.component.js.map