@posiwise/dashboard-module 0.0.84 → 0.0.86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/.eslintrc.json +21 -0
  2. package/ng-package.json +15 -0
  3. package/package.json +10 -23
  4. package/project.json +72 -0
  5. package/{index.d.ts → src/index.ts} +1 -0
  6. package/src/lib/customizer/customizer.component.html +184 -0
  7. package/src/lib/customizer/customizer.component.scss +101 -0
  8. package/src/lib/customizer/customizer.component.ts +13 -0
  9. package/src/lib/dashboard.module.ts +63 -0
  10. package/src/lib/faq/faq.component.html +110 -0
  11. package/src/lib/faq/faq.component.scss +58 -0
  12. package/src/lib/faq/faq.component.spec.ts +143 -0
  13. package/src/lib/faq/faq.component.ts +144 -0
  14. package/src/lib/faq-details/faq-details.component.html +21 -0
  15. package/src/lib/faq-details/faq-details.component.scss +3 -0
  16. package/src/lib/faq-details/faq-details.component.spec.ts +69 -0
  17. package/src/lib/faq-details/faq-details.component.ts +38 -0
  18. package/src/lib/footer/footer.component.html +14 -0
  19. package/src/lib/footer/footer.component.spec.ts +42 -0
  20. package/src/lib/footer/footer.component.ts +24 -0
  21. package/src/lib/home/home.component.html +93 -0
  22. package/src/lib/home/home.component.scss +0 -0
  23. package/src/lib/home/home.component.spec.ts +69 -0
  24. package/src/lib/home/home.component.ts +88 -0
  25. package/src/lib/navbar/navbar.component.html +189 -0
  26. package/src/lib/navbar/navbar.component.scss +92 -0
  27. package/src/lib/navbar/navbar.component.spec.ts +76 -0
  28. package/src/lib/navbar/navbar.component.ts +198 -0
  29. package/src/lib/notifications-page/current-notifications/current-notifications.component.html +61 -0
  30. package/src/lib/notifications-page/current-notifications/current-notifications.component.spec.ts +57 -0
  31. package/src/lib/notifications-page/current-notifications/current-notifications.component.ts +63 -0
  32. package/src/lib/notifications-page/dismissed-notifications/dismissed-notifications.component.html +65 -0
  33. package/src/lib/notifications-page/dismissed-notifications/dismissed-notifications.component.spec.ts +71 -0
  34. package/src/lib/notifications-page/dismissed-notifications/dismissed-notifications.component.ts +79 -0
  35. package/src/lib/notifications-page/notifications-page.component.html +24 -0
  36. package/src/lib/notifications-page/notifications-page.component.scss +28 -0
  37. package/src/lib/notifications-page/notifications-page.component.spec.ts +26 -0
  38. package/src/lib/notifications-page/notifications-page.component.ts +8 -0
  39. package/src/lib/search/search.component.html +215 -0
  40. package/src/lib/search/search.component.scss +98 -0
  41. package/src/lib/search/search.component.spec.ts +64 -0
  42. package/src/lib/search/search.component.ts +50 -0
  43. package/src/lib/sidebar/sidebar-routes.config.ts +355 -0
  44. package/{lib/sidebar/sidebar.metadata.d.ts → src/lib/sidebar/sidebar.metadata.ts} +1 -0
  45. package/src/lib/user-feedback/user-feedback.component.html +53 -0
  46. package/src/lib/user-feedback/user-feedback.component.scss +18 -0
  47. package/src/lib/user-feedback/user-feedback.component.spec.ts +54 -0
  48. package/src/lib/user-feedback/user-feedback.component.ts +83 -0
  49. package/src/lib/user-notifications/user-notifications.component.html +21 -0
  50. package/src/lib/user-notifications/user-notifications.component.scss +21 -0
  51. package/src/lib/user-notifications/user-notifications.component.spec.ts +47 -0
  52. package/src/lib/user-notifications/user-notifications.component.ts +74 -0
  53. package/tsconfig.json +30 -0
  54. package/tsconfig.lib.json +19 -0
  55. package/tsconfig.lib.prod.json +9 -0
  56. package/tsconfig.spec.json +11 -0
  57. package/esm2022/index.mjs +0 -16
  58. package/esm2022/lib/customizer/customizer.component.mjs +0 -17
  59. package/esm2022/lib/dashboard.module.mjs +0 -101
  60. package/esm2022/lib/faq/faq.component.mjs +0 -108
  61. package/esm2022/lib/faq-details/faq-details.component.mjs +0 -38
  62. package/esm2022/lib/footer/footer.component.mjs +0 -22
  63. package/esm2022/lib/home/home.component.mjs +0 -79
  64. package/esm2022/lib/navbar/navbar.component.mjs +0 -162
  65. package/esm2022/lib/notifications-page/current-notifications/current-notifications.component.mjs +0 -58
  66. package/esm2022/lib/notifications-page/dismissed-notifications/dismissed-notifications.component.mjs +0 -73
  67. package/esm2022/lib/notifications-page/notifications-page.component.mjs +0 -14
  68. package/esm2022/lib/search/search.component.mjs +0 -47
  69. package/esm2022/lib/sidebar/sidebar-routes.config.mjs +0 -338
  70. package/esm2022/lib/sidebar/sidebar.metadata.mjs +0 -2
  71. package/esm2022/lib/user-feedback/user-feedback.component.mjs +0 -73
  72. package/esm2022/lib/user-notifications/user-notifications.component.mjs +0 -65
  73. package/esm2022/posiwise-dashboard-module.mjs +0 -5
  74. package/fesm2022/posiwise-dashboard-module.mjs +0 -1106
  75. package/fesm2022/posiwise-dashboard-module.mjs.map +0 -1
  76. package/lib/customizer/customizer.component.d.ts +0 -7
  77. package/lib/dashboard.module.d.ts +0 -28
  78. package/lib/faq/faq.component.d.ts +0 -37
  79. package/lib/faq-details/faq-details.component.d.ts +0 -16
  80. package/lib/footer/footer.component.d.ts +0 -12
  81. package/lib/home/home.component.d.ts +0 -18
  82. package/lib/navbar/navbar.component.d.ts +0 -35
  83. package/lib/notifications-page/current-notifications/current-notifications.component.d.ts +0 -17
  84. package/lib/notifications-page/dismissed-notifications/dismissed-notifications.component.d.ts +0 -18
  85. package/lib/notifications-page/notifications-page.component.d.ts +0 -5
  86. package/lib/search/search.component.d.ts +0 -24
  87. package/lib/sidebar/sidebar-routes.config.d.ts +0 -64
  88. package/lib/user-feedback/user-feedback.component.d.ts +0 -24
  89. package/lib/user-notifications/user-notifications.component.d.ts +0 -20
@@ -0,0 +1,88 @@
1
+ import { Component, Injector, OnDestroy, OnInit } from '@angular/core';
2
+
3
+ import { AppBaseComponent } from '@posiwise/app-base-component';
4
+ import { User } from '@posiwise/common-utilities';
5
+ import { PermissionService, ScriptLoaderService } from '@posiwise/common-services';
6
+
7
+ declare let window: { hopscotch: any };
8
+
9
+ @Component({
10
+ selector: 'pw-home',
11
+ templateUrl: './home.component.html',
12
+ styleUrls: ['./home.component.scss']
13
+ })
14
+ export class HomeComponent extends AppBaseComponent implements OnInit, OnDestroy {
15
+ user: User;
16
+
17
+ private tour = {
18
+ id: 'dashboard',
19
+ steps: []
20
+ };
21
+
22
+ userSlug: string;
23
+
24
+ componentActive = true;
25
+
26
+ selectedSubscriptionSlug: string;
27
+
28
+ constructor(injector: Injector, private scriptLoader: ScriptLoaderService) {
29
+ super(injector);
30
+ }
31
+
32
+ ngOnInit() {
33
+ this.selectedSubscriptionSlug = PermissionService.selectedSubscription?.slug;
34
+ this.userStore().subscribe(state => {
35
+ if (state) {
36
+ this.userService.getCurrentUserObject('active_tips').subscribe(response => {
37
+ if (response?.length) {
38
+ const welcomeTips = response.find(x => x.name === 'welcome');
39
+
40
+ if (welcomeTips) {
41
+ this.tour.steps = JSON.parse(welcomeTips.instructions).steps;
42
+
43
+ this.scriptLoader
44
+ .loadScript('head', '/assets/js/hopscotch.min.js', true)
45
+ .then(() => {
46
+ window.hopscotch.startTour(this.tour);
47
+ // eslint-disable-next-line func-names
48
+ window.hopscotch.nextStep = function () {
49
+ const stepNumber = $('.hopscotch-bubble-number').text();
50
+
51
+ if (this.tour.steps.length === Number(stepNumber)) {
52
+ this.userService
53
+ .postTipsDisregarded({
54
+ tip_id: welcomeTips.id,
55
+ disregarded: true
56
+ })
57
+ .subscribe(() => {
58
+ window?.hopscotch?.endTour();
59
+ });
60
+ } else {
61
+ window.hopscotch.showStep(Number(stepNumber));
62
+ }
63
+ }.bind(this);
64
+ });
65
+ }
66
+ }
67
+ });
68
+ }
69
+ });
70
+
71
+ this.userStore().subscribe({
72
+ next: user => {
73
+ this.user = user;
74
+ if (this.user) {
75
+ this.userSlug = user.slug;
76
+ }
77
+ },
78
+ error: error => this.toast.showToast(error)
79
+ });
80
+ }
81
+
82
+ override ngOnDestroy() {
83
+ if (window?.hopscotch) {
84
+ window?.hopscotch?.endTour();
85
+ }
86
+ super.ngOnDestroy();
87
+ }
88
+ }
@@ -0,0 +1,189 @@
1
+ <!-- Navbar (Header) Starts -->
2
+ <nav class="navbar navbar-expand-lg navbar-light fixed-top bg-faded shadow-sm">
3
+ <div class="container-fluid">
4
+ <div class="navbar-header">
5
+ <button type="button"
6
+ class="navbar-toggle d-lg-none float-start"
7
+ data-bs-toggle="collapse">
8
+ <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span>
9
+ <span class="icon-bar"></span>
10
+ <span class="icon-bar"></span>
11
+ </button>
12
+ <form class="navbar-form navbar-right mt-1"
13
+ role="search"
14
+ (ngSubmit)="onSearch(search)">
15
+ <div class="input-group navbar-search-input">
16
+ <input type="text"
17
+ #search
18
+ class="form-control"
19
+ placeholder="Search" />
20
+ <button class="input-group-text btn"
21
+ type="submit">
22
+ <i class="ft-search" aria-hidden="true"></i>
23
+ </button>
24
+ </div>
25
+ <div id="tips-onboarding-step6"></div>
26
+ </form>
27
+ </div>
28
+ <div class="logo-img">
29
+ <ng-template [ngIf]="logo">
30
+ <img [src]="logo.full"
31
+ onerror="this.onerror=null;this.src='assets/img/logos/logo_text_big_dark.png';"
32
+ alt="img" />
33
+ </ng-template>
34
+ </div>
35
+ <div *rbacAllow="'SuperAdmin'">
36
+ <div class="mb-0">
37
+ <select class="form-select form-control-sm"
38
+ data-flag="true"
39
+ (change)="onLangChange($event.target.value)">
40
+ <option value="en">English</option>
41
+ <option value="es">Spanish</option>
42
+ <option value="de">German</option>
43
+ <option value="pt">Portuguese</option>
44
+ </select>
45
+ </div>
46
+ </div>
47
+ <div class="navbar-container">
48
+ <div id="navbarSupportedContent">
49
+ <ul class="navbar-nav">
50
+ <li class="nav-item"
51
+ ngbDropdown
52
+ #notiDrop="ngbDropdown"
53
+ placement="bottom-left"
54
+ autoClose="true">
55
+ <a class="nav-link position-relative"
56
+ id="dropdownBasic2"
57
+ ngbDropdownToggle
58
+ (click)="checkNoti()">
59
+ <i
60
+ class="ft-bell font-medium-3 blue-grey darken-4"
61
+ aria-hidden="true"
62
+ ></i>
63
+ <span class="notification badge rounded-pill bg-danger"
64
+ *ngIf="notificationCount > 0">
65
+ {{ notificationCount }}
66
+ </span>
67
+ <p class="d-none">Notifications</p>
68
+ </a>
69
+ <div id="tips-onboarding-step5"></div>
70
+ <div ngbDropdownMenu
71
+ aria-labelledby="dropdownBasic2"
72
+ class="notification-dropdown">
73
+ <div class="noti-list"
74
+ *ngIf="noNoti === false">
75
+ <li *ngFor="let noti of notifications; let idx = index"
76
+ #notiRef
77
+ [id]="'noti' + idx"
78
+ [pTooltip]="noti?.content"
79
+ tooltipPosition="top"
80
+ class="dropdown-item noti-container border-bottom border-bottom-blue-grey border-bottom-lighten-4 d-flex align-items-center">
81
+ <div class="d-flex justify-content-between w-100">
82
+ <div>
83
+ <div class="btn btn-circle me-3"
84
+ [ngClass]="{
85
+ 'btn-danger':
86
+ noti.note_type === 'administrative',
87
+ 'btn-secondary':
88
+ noti.note_type === 'object_event',
89
+ 'btn-primary':
90
+ noti.note_type === 'user_generated'
91
+ }">
92
+ <i
93
+ class="fal float-start"
94
+ [ngClass]="{
95
+ 'fa-bell':
96
+ noti.note_type === 'administrative',
97
+ 'fa-share-alt':
98
+ noti.note_type === 'object_event',
99
+ 'fa-bells':
100
+ noti.note_type === 'user_generated'
101
+ }"
102
+ aria-hidden="true"
103
+ ></i>
104
+ </div>
105
+ <div class="d-inline-block text-truncate noti-content">
106
+ {{ noti?.content }}
107
+ <span class="noti-text d-block">
108
+ <span class="fal fa-clock"></span>
109
+ {{ noti?.created_at | sinceAgo }}
110
+ </span>
111
+ </div>
112
+ </div>
113
+ <div>
114
+ <a (click)="dismiss(noti.id, $event)">
115
+ <i class="far fa-times" aria-hidden="true"></i></a>
116
+ </div>
117
+ </div>
118
+ </li>
119
+ </div>
120
+ <div class="noti-list"
121
+ *ngIf="noNoti === true">
122
+ <a class="dropdown-item noti-container border-bottom border-bottom-blue-grey border-bottom-lighten-4">
123
+ <i
124
+ class="ft-bell success float-start d-block font-large-1 mt-1 me-2"
125
+ aria-hidden="true"
126
+ ></i>
127
+ <span class="noti-wrapper">
128
+ <span class="noti-title line-height-1 d-block success">You are all caught up.</span>
129
+ <span class="noti-text">You currently do not have any notifications.</span>
130
+ </span>
131
+ </a>
132
+ </div>
133
+ <a (click)="redirectToNotification()"
134
+ class="noti-footer text-center d-block border-top border-top-blue-grey border-top-lighten-4 text-bold-400 p-3">Read All Notifications</a>
135
+ </div>
136
+ </li>
137
+ <li class="nav-item"
138
+ ngbDropdown
139
+ placement="bottom-left"
140
+ autoClose="true">
141
+ <button class="nav-link position-relative dropdown-toggle"
142
+ type="button"
143
+ id="dropdownBasic3"
144
+ data-bs-toggle="dropdown"
145
+ aria-haspopup="true"
146
+ aria-expanded="false"
147
+ style="border: none">
148
+ <i
149
+ class="ft-user font-medium-3 blue-grey darken-4"
150
+ aria-hidden="true"
151
+ ></i>
152
+ <p class="d-none">User Settings</p>
153
+ </button>
154
+ <div ngbDropdownMenu
155
+ aria-labelledby="dropdownBasic3">
156
+ <button class="dropdown-item py-2"
157
+ [routerLink]="['/members', slug]">
158
+ <i class="ft-edit me-2" aria-hidden="true"></i>
159
+ <span>My Profile</span>
160
+ </button>
161
+ <button class="dropdown-item py-2"
162
+ routerLink="/account/details">
163
+ <i class="ft-user me-2" aria-hidden="true"></i> <span>Account</span>
164
+ </button>
165
+ <button class="dropdown-item py-2"
166
+ routerLink="/settings/communication">
167
+ <i class="ft-settings me-2" aria-hidden="true"></i>
168
+ <span>Settings</span>
169
+ </button>
170
+ <button *ngIf="isSupportMenu"
171
+ class="dropdown-item py-2"
172
+ routerLink="/support">
173
+ <i class="fa fa-question me-2" aria-hidden="true"></i>
174
+ <span>&nbsp;Support</span>
175
+ </button>
176
+ <div class="dropdown-divider"></div>
177
+ <button class="dropdown-item logout"
178
+ (click)="logout()">
179
+ <i class="fa fa-sign-out-alt me-2" aria-hidden="true"></i>
180
+ <span>Logout</span>
181
+ </button>
182
+ </div>
183
+ </li>
184
+ </ul>
185
+ </div>
186
+ </div>
187
+ </div>
188
+ </nav>
189
+ <!-- Navbar (Header) Ends -->
@@ -0,0 +1,92 @@
1
+ .navbar,
2
+ .fixed-top {
3
+ position: fixed !important;
4
+ background-color: rgb(255 255 255);
5
+ padding: 0 30px 5px;
6
+ height: 45px;
7
+ }
8
+
9
+ .mb-0 {
10
+ margin-bottom: -4px !important;
11
+ }
12
+
13
+ .navbar-nav > li {
14
+ margin-right: 20px;
15
+ }
16
+
17
+ .logo-img {
18
+ img {
19
+ margin-right: 15px;
20
+ max-height: 30px;
21
+ }
22
+ }
23
+
24
+ .logo-text {
25
+ color: rgb(0 0 0);
26
+ display: block;
27
+ font-size: 1.4rem;
28
+ font-weight: 400;
29
+ letter-spacing: 2px;
30
+ padding: 5px 0;
31
+ text-align: left;
32
+ text-transform: uppercase;
33
+ }
34
+
35
+ .dropdown-menu {
36
+ left: auto;
37
+ right: 0;
38
+ z-index: 25000 !important;
39
+ }
40
+
41
+ .noti-container {
42
+ cursor: pointer;
43
+ }
44
+
45
+ .noti-content {
46
+ vertical-align: top !important;
47
+ width: 280px;
48
+ }
49
+
50
+ .noti-container,
51
+ .icon-dismiss {
52
+ padding: 15px;
53
+ position: relative;
54
+ z-index: 9;
55
+ }
56
+
57
+ .noti-list {
58
+ max-height: 400px;
59
+ overflow: auto;
60
+ }
61
+
62
+ .nav-link {
63
+ background-color: rgb(255 255 255);
64
+ }
65
+
66
+ @media screen and (max-width: 991px) {
67
+ .navbar {
68
+ padding: 0 30px 5px;
69
+ }
70
+ }
71
+
72
+ @media screen and (max-width: 575px) {
73
+ .navbar {
74
+ padding: 0 15px 5px 10px;
75
+ }
76
+ }
77
+
78
+ @media screen and (max-width: 575px) {
79
+ .noti-content {
80
+ width: 250px;
81
+ }
82
+ }
83
+
84
+ @media only screen and (max-width: 480px) {
85
+ .logo-img {
86
+ max-width: 100px;
87
+
88
+ img {
89
+ width: 100%;
90
+ }
91
+ }
92
+ }
@@ -0,0 +1,76 @@
1
+ import { TestBed } from "@angular/core/testing";
2
+ import { Store } from "@ngrx/store";
3
+ import { PermissionService, NotificationService, UserService, CommonServicesModule } from "@posiwise/common-services";
4
+ import { DEFAULT_USER, TestHelper } from "@posiwise/test-helpers";
5
+ import { MockProvider } from "ng-mocks";
6
+ import { of } from "rxjs";
7
+ import { NavbarComponent } from "./navbar.component";
8
+ import { SharedModule } from "@posiwise/shared-module";
9
+ import { DashboardLibModule } from "../dashboard.module";
10
+
11
+
12
+ class UserServiceMock {
13
+ getUserState() {
14
+ return of({ currentUser: DEFAULT_USER });
15
+ }
16
+ }
17
+ describe('NavbarComponent', () => {
18
+ const data = [
19
+ {
20
+ id: 1,
21
+ note_type: 'administrative',
22
+ content: 'test',
23
+ created_at: '2021-11-26T10:13:10.687+00:00',
24
+ updated_at: '2021-11-26T10:13:10.687+00:00',
25
+ show_on_dashboard: true,
26
+ dismissed: false,
27
+ unread: null
28
+ }
29
+ ];
30
+ const createComponent = TestHelper.createComponentFactory({
31
+ component: NavbarComponent,
32
+ imports: [SharedModule,CommonServicesModule,DashboardLibModule],
33
+ providers: [
34
+ ...TestHelper.TEST_PROVIDERS,
35
+ MockProvider(PermissionService, {
36
+ evaluatePermissions: () => {
37
+ return true;
38
+ }
39
+ }),
40
+ MockProvider(NotificationService, {
41
+ getNotifications: () => of(data),
42
+ notiWebSocket: () => of(data),
43
+ dismissNotification: () => of(JSON.stringify(data)),
44
+ readNotifications: () => of({}),
45
+ showNotifications: () => {}
46
+ }),
47
+ {
48
+ provide: UserService,
49
+ useClass: UserServiceMock
50
+ }
51
+ ]
52
+ });
53
+
54
+ beforeEach(() => {
55
+ TestHelper.setUpPermissionsAndUser();
56
+ });
57
+
58
+ it('should create', async () => {
59
+ const store = TestBed.inject(Store);
60
+ spyOn(store, 'select').and.returnValue(of({ currentUser: DEFAULT_USER }));
61
+ const spectator = await createComponent();
62
+ expect(spectator.component).toBeTruthy();
63
+ });
64
+
65
+ it('should dismiss notification', async () => {
66
+ const store = TestBed.inject(Store);
67
+ spyOn(store, 'select').and.returnValue(of({ currentUser: DEFAULT_USER }));
68
+ const service = TestBed.inject(NotificationService);
69
+ const spy = spyOn(service, 'dismissNotification').and.callThrough();
70
+ const spectator = await createComponent();
71
+ spectator.click('.ft-bell');
72
+ spectator.fixture.detectChanges();
73
+ spectator.click('.noti-container .fa-times');
74
+ expect(spy).toHaveBeenCalledTimes(1);
75
+ });
76
+ });
@@ -0,0 +1,198 @@
1
+ import { Component, Injector, Input, OnDestroy, ViewChild } from '@angular/core';
2
+ import { NgbDropdown, NgbDropdownConfig } from '@ng-bootstrap/ng-bootstrap';
3
+ import { Store } from '@ngrx/store';
4
+ import { AppState, getUser } from '@posiwise/app-store';
5
+ import { orderBy } from 'lodash';
6
+
7
+ import { AppBaseComponent } from '@posiwise/app-base-component';
8
+ import {
9
+ PermissionService,
10
+ ScriptLoaderService,
11
+ NotificationService
12
+ } from '@posiwise/common-services';
13
+
14
+ @Component({
15
+ selector: 'pw-navbar',
16
+ templateUrl: './navbar.component.html',
17
+ styleUrls: ['./navbar.component.scss'],
18
+ providers: [NgbDropdownConfig]
19
+ })
20
+ export class NavbarComponent extends AppBaseComponent implements OnDestroy, OnDestroy {
21
+ @Input() logo: any;
22
+
23
+ @ViewChild('notiDrop', { static: true })
24
+ notiDrop: NgbDropdown;
25
+
26
+ notificationCount = 0;
27
+
28
+ noNoti = true;
29
+
30
+ notifications = [];
31
+
32
+ private notiInterval: number;
33
+
34
+ slug: string;
35
+
36
+ constructor(
37
+ injector: Injector,
38
+ private notificationService: NotificationService,
39
+ config: NgbDropdownConfig,
40
+ private scriptLoader: ScriptLoaderService,
41
+ private store: Store<AppState>
42
+ ) {
43
+ super(injector);
44
+ this.loadExternalScripts();
45
+ config.autoClose = false;
46
+ this.store.select(getUser).subscribe(res => {
47
+ this.slug = res.currentUser ? res.currentUser.slug : '';
48
+ });
49
+
50
+ this.getNotifications();
51
+ this.updateNotifications();
52
+ }
53
+
54
+ override ngOnDestroy() {
55
+ clearInterval(this.notiInterval);
56
+ }
57
+
58
+ get isSupportMenu() {
59
+ return PermissionService.selectedProduct?.gitlab_service_desk_email;
60
+ }
61
+
62
+ private loadExternalScripts() {
63
+ this.scriptLoader.loadScripts(
64
+ 'head',
65
+ [
66
+ 'https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.11/jstree.min.js',
67
+ 'https://cdnjs.cloudflare.com/ajax/libs/quill/1.3.7/quill.min.js',
68
+ 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js'
69
+ ],
70
+ true
71
+ );
72
+
73
+ this.scriptLoader.loadStyle(
74
+ 'https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.11/themes/default/style.min.css'
75
+ );
76
+ }
77
+
78
+ private getNotifications() {
79
+ this.notificationService.getNotifications().subscribe((data: any[]) => {
80
+ this.notificationsCount(data);
81
+
82
+ this.notificationService.notiWebSocket().subscribe(res => {
83
+ if (res) {
84
+ this.notificationsCount([res]);
85
+ }
86
+ });
87
+
88
+ if (data.length > 0) {
89
+ this.notificationService.showNotifications(this.notifications);
90
+ }
91
+ });
92
+ }
93
+
94
+ private notificationsCount(noti: any[]) {
95
+ for (let i = 0; i < noti.length; i++) {
96
+ if (!noti[i]?.dismissed && noti[i].show_on_dashboard) {
97
+ this.notifications.push(noti[i]);
98
+ }
99
+ if (noti[i].unread === true) {
100
+ this.notificationCount++;
101
+ }
102
+ if (noti[i].dismissed === false) {
103
+ this.noNoti = false;
104
+ }
105
+ }
106
+
107
+ this.sortNotifications();
108
+ }
109
+
110
+ private sortNotifications() {
111
+ this.notifications = orderBy(this.notifications, ['id'], ['desc']);
112
+ }
113
+
114
+ private updateNotifications() {
115
+ this.notificationService.getNotifications().subscribe(data => {
116
+ const val = data;
117
+ if (val.length > 0) {
118
+ val.forEach(element => {
119
+ const existNotification = this.notifications.find(
120
+ ({ id }) => element.id === id
121
+ );
122
+ if (!existNotification) {
123
+ if (!element.dismissed && element.show_on_dashboard) {
124
+ this.notifications.push(element);
125
+ }
126
+ if (element.unread === true) {
127
+ this.notificationCount++;
128
+ }
129
+ if (element.dismissed === false) {
130
+ this.noNoti = false;
131
+ }
132
+ }
133
+ });
134
+ }
135
+ this.sortNotifications();
136
+ });
137
+ }
138
+
139
+ checkNoti() {
140
+ if (this.notiDrop.isOpen()) {
141
+ // Mark all Notifications as read
142
+ this.notificationService.readNotifications().subscribe(() => {
143
+ this.notificationCount = 0;
144
+ });
145
+ }
146
+ }
147
+
148
+ dismiss(id: number, _e) {
149
+ this.notificationService.dismissNotification(id).subscribe(data => {
150
+ // Remove notification from notification array
151
+ // TODO: Add animation while removing
152
+ const index = this.notifications.findIndex(x => x.id === id);
153
+ this.notifications.splice(index, 1);
154
+
155
+ if (data) {
156
+ const val = JSON.parse(data);
157
+ if (val.length > 0) {
158
+ val.forEach(element => {
159
+ const existNotification = this.notifications.find(
160
+ ({ key }) => element.id === key
161
+ );
162
+ if (!existNotification) {
163
+ this.notifications.push(element);
164
+ if (element.unread === true) {
165
+ this.notificationCount++;
166
+ }
167
+ }
168
+ });
169
+ }
170
+ }
171
+
172
+ if (this.notifications.length === 0) {
173
+ this.noNoti = true;
174
+ }
175
+
176
+ this.sortNotifications();
177
+ });
178
+ }
179
+
180
+ onLangChange(lang: string) {
181
+ this.translation.setActiveLang(lang);
182
+ }
183
+
184
+ logout() {
185
+ this.router.navigate(['logout']);
186
+ }
187
+
188
+ redirectToNotification() {
189
+ this.notiDrop.close();
190
+ this.router.navigate(['/notifications']);
191
+ }
192
+
193
+ onSearch(search) {
194
+ if (search.value) {
195
+ this.router.navigate(['search'], { queryParams: { keyword: search.value } });
196
+ }
197
+ }
198
+ }