Skip to content

Commit c3a24f2

Browse files
authored
Merge pull request #536 from iyilm4z/ng-remove-jquery-dependency
Remove jquery dependency from angular
2 parents 56014d0 + cb3f054 commit c3a24f2

File tree

16 files changed

+607
-367
lines changed

16 files changed

+607
-367
lines changed

angular/angular.json

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,21 @@
3333
],
3434
"styles": [
3535
"node_modules/famfamfam-flags/dist/sprite/famfamfam-flags.css",
36-
"node_modules/toastr/build/toastr.css",
36+
"node_modules/sweetalert2/dist/sweetalert2.css",
37+
"src/assets/freeze-ui/freeze-ui.css",
3738
"node_modules/@fortawesome/fontawesome-free/css/all.min.css",
3839
"node_modules/admin-lte-css-only/css/adminlte.min.css",
3940
"src/shared/core.less"
4041
],
4142
"scripts": [
42-
"node_modules/jquery/dist/jquery.min.js",
4343
"node_modules/moment/min/moment.min.js",
4444
"node_modules/@aspnet/signalr/dist/browser/signalr.min.js",
45-
"node_modules/toastr/toastr.js",
46-
"node_modules/sweetalert/dist/sweetalert.min.js",
47-
"node_modules/block-ui/jquery.blockUI.js",
48-
"node_modules/spin.js/spin.min.js",
49-
"node_modules/spin.js/jquery.spin.js",
45+
"node_modules/sweetalert2/dist/sweetalert2.js",
46+
"src/assets/freeze-ui/freeze-ui.js",
5047
"node_modules/push.js/bin/push.min.js",
5148
"node_modules/abp-web-resources/Abp/Framework/scripts/abp.js",
52-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.jquery.js",
53-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.toastr.js",
54-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.blockUI.js",
55-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.spin.js",
56-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.sweet-alert.js",
49+
"src/assets/abp-web-resources/abp.sweet-alert.js",
50+
"src/assets/abp-web-resources/abp.freeze-ui.js",
5751
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.moment.js"
5852
]
5953
},
@@ -139,27 +133,21 @@
139133
],
140134
"styles": [
141135
"node_modules/famfamfam-flags/dist/sprite/famfamfam-flags.css",
142-
"node_modules/toastr/build/toastr.css",
136+
"node_modules/sweetalert2/dist/sweetalert2.css",
137+
"src/assets/freeze-ui/freeze-ui.css",
143138
"node_modules/@fortawesome/fontawesome-free/css/all.min.css",
144139
"node_modules/admin-lte-css-only/css/adminlte.min.css",
145140
"src/shared/core.less"
146141
],
147142
"scripts": [
148-
"node_modules/jquery/dist/jquery.min.js",
149143
"node_modules/moment/min/moment.min.js",
150144
"node_modules/@aspnet/signalr/dist/browser/signalr.min.js",
151-
"node_modules/toastr/toastr.js",
152-
"node_modules/sweetalert/dist/sweetalert.min.js",
153-
"node_modules/block-ui/jquery.blockUI.js",
154-
"node_modules/spin.js/spin.min.js",
155-
"node_modules/spin.js/jquery.spin.js",
145+
"node_modules/sweetalert2/dist/sweetalert2.js",
146+
"src/assets/freeze-ui/freeze-ui.js",
156147
"node_modules/push.js/bin/push.min.js",
157148
"node_modules/abp-web-resources/Abp/Framework/scripts/abp.js",
158-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.jquery.js",
159-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.toastr.js",
160-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.blockUI.js",
161-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.spin.js",
162-
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.sweet-alert.js",
149+
"src/assets/abp-web-resources/abp.sweet-alert.js",
150+
"src/assets/abp-web-resources/abp.freeze-ui.js",
163151
"node_modules/abp-web-resources/Abp/Framework/scripts/libs/abp.moment.js"
164152
]
165153
}

angular/package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,16 @@
2626
"abp-ng2-module": "^6.0.0",
2727
"abp-web-resources": "^5.1.1",
2828
"admin-lte-css-only": "^3.0.4",
29-
"block-ui": "^2.70.1",
3029
"core-js": "^3.2.1",
3130
"famfamfam-flags": "^1.0.0",
32-
"jquery": "^3.4.1",
3331
"lodash": "^4.17.4",
3432
"moment": "2.24.0",
3533
"moment-timezone": "^0.5.28",
3634
"ngx-bootstrap": "^5.6.1",
3735
"ngx-pagination": "^5.0.0",
3836
"push.js": "1.0.12",
3937
"rxjs": "^6.4.0",
40-
"spin.js": "^2.3.2",
41-
"sweetalert": "^2.0.8",
42-
"toastr": "^2.1.2",
38+
"sweetalert2": "^9.10.12",
4339
"ts-helpers": "^1.1.2",
4440
"tslib": "^1.10.0",
4541
"web-animations-js": "^2.3.2",
@@ -51,8 +47,6 @@
5147
"@angular/compiler-cli": "^9.1.4",
5248
"@angularclass/hmr": "^2.1.3",
5349
"@types/jasmine": "^3.4.0",
54-
"@types/jquery": "^3.3.37",
55-
"@types/jquery.blockui": "0.0.28",
5650
"@types/lodash": "^4.14.150",
5751
"@types/moment-timezone": "^0.5.12",
5852
"@types/node": "^13.13.4",

angular/src/AppPreBootstrap.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

angular/src/app-initializer.ts

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import { Injectable, Injector } from '@angular/core';
2+
import { PlatformLocation, registerLocaleData } from '@angular/common';
3+
import { HttpClient } from '@angular/common/http';
4+
import * as moment from 'moment';
5+
import * as _ from 'lodash';
6+
import { AppConsts } from '@shared/AppConsts';
7+
import { AppSessionService } from '@shared/session/app-session.service';
8+
import { environment } from './environments/environment';
9+
10+
@Injectable({
11+
providedIn: 'root',
12+
})
13+
export class AppInitializer {
14+
constructor(
15+
private _injector: Injector,
16+
private _platformLocation: PlatformLocation,
17+
private _httpClient: HttpClient
18+
) { }
19+
20+
init(): () => Promise<boolean> {
21+
return () => {
22+
abp.ui.setBusy();
23+
return new Promise<boolean>((resolve, reject) => {
24+
AppConsts.appBaseHref = this.getBaseHref();
25+
const appBaseUrl = this.getDocumentOrigin() + AppConsts.appBaseHref;
26+
this.getApplicationConfig(appBaseUrl, () => {
27+
this.getUserConfiguration(() => {
28+
abp.event.trigger('abp.dynamicScriptsInitialized');
29+
// do not use constructor injection for AppSessionService
30+
const appSessionService = this._injector.get(AppSessionService);
31+
appSessionService.init().then(
32+
(result) => {
33+
abp.ui.clearBusy();
34+
if (this.shouldLoadLocale()) {
35+
const angularLocale = this.convertAbpLocaleToAngularLocale(
36+
abp.localization.currentLanguage.name
37+
);
38+
import(`@angular/common/locales/${angularLocale}.js`).then(
39+
(module) => {
40+
registerLocaleData(module.default);
41+
resolve(result);
42+
},
43+
reject
44+
);
45+
} else {
46+
resolve(result);
47+
}
48+
},
49+
(err) => {
50+
abp.ui.clearBusy();
51+
reject(err);
52+
}
53+
);
54+
});
55+
});
56+
});
57+
};
58+
}
59+
60+
private getBaseHref(): string {
61+
const baseUrl = this._platformLocation.getBaseHrefFromDOM();
62+
if (baseUrl) {
63+
return baseUrl;
64+
}
65+
66+
return '/';
67+
}
68+
69+
private getDocumentOrigin(): string {
70+
if (!document.location.origin) {
71+
const port = document.location.port ? ':' + document.location.port : '';
72+
return (
73+
document.location.protocol + '//' + document.location.hostname + port
74+
);
75+
}
76+
77+
return document.location.origin;
78+
}
79+
80+
private shouldLoadLocale(): boolean {
81+
return (
82+
abp.localization.currentLanguage.name &&
83+
abp.localization.currentLanguage.name !== 'en-US'
84+
);
85+
}
86+
87+
private convertAbpLocaleToAngularLocale(locale: string): string {
88+
if (!AppConsts.localeMappings) {
89+
return locale;
90+
}
91+
92+
const localeMapings = _.filter(AppConsts.localeMappings, { from: locale });
93+
if (localeMapings && localeMapings.length) {
94+
return localeMapings[0]['to'];
95+
}
96+
97+
return locale;
98+
}
99+
100+
private getCurrentClockProvider(
101+
currentProviderName: string
102+
): abp.timing.IClockProvider {
103+
if (currentProviderName === 'unspecifiedClockProvider') {
104+
return abp.timing.unspecifiedClockProvider;
105+
}
106+
107+
if (currentProviderName === 'utcClockProvider') {
108+
return abp.timing.utcClockProvider;
109+
}
110+
111+
return abp.timing.localClockProvider;
112+
}
113+
114+
private getUserConfiguration(callback: () => void): void {
115+
const cookieLangValue = abp.utils.getCookieValue(
116+
'Abp.Localization.CultureName'
117+
);
118+
const token = abp.auth.getToken();
119+
120+
const requestHeaders = {
121+
'Abp.TenantId': `${abp.multiTenancy.getTenantIdCookie()}`,
122+
'.AspNetCore.Culture': `c=${cookieLangValue}|uic=${cookieLangValue}`,
123+
};
124+
125+
if (token) {
126+
requestHeaders['Authorization'] = `Bearer ${token}`;
127+
}
128+
129+
this._httpClient
130+
.get<any>(
131+
`${AppConsts.remoteServiceBaseUrl}/AbpUserConfiguration/GetAll`,
132+
{
133+
headers: requestHeaders,
134+
}
135+
)
136+
.subscribe((response) => {
137+
const result = response.result;
138+
139+
_.merge(abp, result);
140+
141+
abp.clock.provider = this.getCurrentClockProvider(
142+
result.clock.provider
143+
);
144+
145+
moment.locale(abp.localization.currentLanguage.name);
146+
147+
if (abp.clock.provider.supportsMultipleTimezone) {
148+
moment.tz.setDefault(abp.timing.timeZoneInfo.iana.timeZoneId);
149+
}
150+
151+
callback();
152+
});
153+
}
154+
155+
private getApplicationConfig(appRootUrl: string, callback: () => void) {
156+
this._httpClient
157+
.get<any>(`${appRootUrl}assets/${environment.appConfig}`, {
158+
headers: {
159+
'Abp.TenantId': `${abp.multiTenancy.getTenantIdCookie()}`,
160+
},
161+
})
162+
.subscribe((response) => {
163+
AppConsts.appBaseUrl = response.appBaseUrl;
164+
AppConsts.remoteServiceBaseUrl = response.remoteServiceBaseUrl;
165+
AppConsts.localeMappings = response.localeMappings;
166+
167+
callback();
168+
});
169+
}
170+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var abp = abp || {};
2+
(() => {
3+
if (!FreezeUI || !UnFreezeUI) {
4+
return;
5+
}
6+
7+
abp.ui.setBusy = (elm, text, delay) => {
8+
FreezeUI({
9+
element: elm,
10+
text: text ? text : " ",
11+
delay: delay,
12+
});
13+
};
14+
15+
abp.ui.clearBusy = (elm, delay) => {
16+
UnFreezeUI({ element: elm, delay: delay });
17+
};
18+
})();

0 commit comments

Comments
 (0)