|
| 1 | +import { AppConsts } from '@shared/AppConsts'; |
| 2 | +import * as rtlDetect from 'rtl-detect'; |
| 3 | +import { StyleLoaderService } from '@shared/utils/style-loader.service'; |
| 4 | +import { Theme8ThemeAssetContributor } from '@app/shared/layout/themes/theme8/Theme8ThemeAssetContributor'; |
| 5 | +import { Theme2ThemeAssetContributor } from '@app/shared/layout/themes/theme2/Theme2ThemeAssetContributor'; |
| 6 | +import { Theme3ThemeAssetContributor } from '@app/shared/layout/themes/theme3/Theme3ThemeAssetContributor'; |
| 7 | +import { Theme4ThemeAssetContributor } from '@app/shared/layout/themes/theme4/Theme4ThemeAssetContributor'; |
| 8 | +import { Theme5ThemeAssetContributor } from '@app/shared/layout/themes/theme5/Theme5ThemeAssetContributor'; |
| 9 | +import { Theme6ThemeAssetContributor } from '@app/shared/layout/themes/theme6/Theme6ThemeAssetContributor'; |
| 10 | +import { Theme9ThemeAssetContributor } from '@app/shared/layout/themes/theme9/Theme9ThemeAssetContributor'; |
| 11 | +import { Theme7ThemeAssetContributor } from '@app/shared/layout/themes/theme7/Theme7ThemeAssetContributor'; |
| 12 | +import { Theme10ThemeAssetContributor } from '@app/shared/layout/themes/theme10/Theme10ThemeAssetContributor'; |
| 13 | +import { Theme11ThemeAssetContributor } from '@app/shared/layout/themes/theme11/Theme11ThemeAssetContributor'; |
| 14 | +import { Theme12ThemeAssetContributor } from '@app/shared/layout/themes/theme12/Theme12ThemeAssetContributor'; |
| 15 | +import { DefaultThemeAssetContributor } from '@app/shared/layout/themes/default/DefaultThemeAssetContributor'; |
| 16 | +import { ThemeHelper } from '@app/shared/layout/themes/ThemeHelper'; |
| 17 | +import * as _ from 'lodash'; |
| 18 | + |
| 19 | +export class DynamicResourcesHelper { |
| 20 | + |
| 21 | + static loadResources(callback: () => void): void { |
| 22 | + Promise.all([DynamicResourcesHelper.loadStlyes()]) |
| 23 | + .then(() => { |
| 24 | + callback(); |
| 25 | + }); |
| 26 | + } |
| 27 | + |
| 28 | + static loadStlyes(): Promise<any> { |
| 29 | + let theme = "theme2"; // always set theme2 for this project |
| 30 | + //let theme = ThemeHelper.getTheme(); |
| 31 | + |
| 32 | + const isRtl = rtlDetect.isRtlLang(abp.localization.currentLanguage.name); |
| 33 | + |
| 34 | + if (isRtl) { |
| 35 | + document.documentElement.setAttribute('dir', 'rtl'); |
| 36 | + } |
| 37 | + |
| 38 | + const cssPostfix = isRtl ? '-rtl' : ''; |
| 39 | + const styleLoaderService = new StyleLoaderService(); |
| 40 | + |
| 41 | + let styleUrls = [ |
| 42 | + AppConsts.appBaseUrl + '/assets/metronic/themes/' + theme + '/css/style.bundle' + cssPostfix.replace('-', '.') + '.min.css', |
| 43 | + AppConsts.appBaseUrl + '/assets/primeng/datatable/css/primeng.datatable' + cssPostfix + '.min.css', |
| 44 | + AppConsts.appBaseUrl + '/assets/common/styles/metronic-customize.min.css', |
| 45 | + AppConsts.appBaseUrl + '/assets/common/styles/themes/' + theme + '/metronic-customize.min.css', |
| 46 | + AppConsts.appBaseUrl + '/assets/common/styles/metronic-customize-angular.min.css' |
| 47 | + ].concat(DynamicResourcesHelper.getAdditionalThemeAssets()); |
| 48 | + |
| 49 | + styleLoaderService.loadArray(styleUrls); |
| 50 | + |
| 51 | + if (isRtl) { |
| 52 | + styleLoaderService.load( |
| 53 | + AppConsts.appBaseUrl + '/assets/common/styles/abp-zero-template-rtl.min.css' |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + return Promise.resolve(true); |
| 58 | + } |
| 59 | + |
| 60 | + static getAdditionalThemeAssets(): string[] { |
| 61 | + let theme = ThemeHelper.getTheme(); |
| 62 | + |
| 63 | + if (theme === 'default') { |
| 64 | + return new DefaultThemeAssetContributor().getAssetUrls(); |
| 65 | + } |
| 66 | + |
| 67 | + if (theme === 'theme8') { |
| 68 | + return new Theme8ThemeAssetContributor().getAssetUrls(); |
| 69 | + } |
| 70 | + |
| 71 | + if (theme === 'theme2') { |
| 72 | + return new Theme2ThemeAssetContributor().getAssetUrls(); |
| 73 | + } |
| 74 | + |
| 75 | + if (theme === 'theme3') { |
| 76 | + return new Theme3ThemeAssetContributor().getAssetUrls(); |
| 77 | + } |
| 78 | + |
| 79 | + if (theme === 'theme4') { |
| 80 | + return new Theme4ThemeAssetContributor().getAssetUrls(); |
| 81 | + } |
| 82 | + |
| 83 | + if (theme === 'theme5') { |
| 84 | + return new Theme5ThemeAssetContributor().getAssetUrls(); |
| 85 | + } |
| 86 | + |
| 87 | + if (theme === 'theme6') { |
| 88 | + return new Theme6ThemeAssetContributor().getAssetUrls(); |
| 89 | + } |
| 90 | + |
| 91 | + if (theme === 'theme7') { |
| 92 | + return new Theme7ThemeAssetContributor().getAssetUrls(); |
| 93 | + } |
| 94 | + |
| 95 | + if (theme === 'theme9') { |
| 96 | + return new Theme9ThemeAssetContributor().getAssetUrls(); |
| 97 | + } |
| 98 | + |
| 99 | + if (theme === 'theme10') { |
| 100 | + return new Theme10ThemeAssetContributor().getAssetUrls(); |
| 101 | + } |
| 102 | + |
| 103 | + if (theme === 'theme11') { |
| 104 | + return new Theme11ThemeAssetContributor().getAssetUrls(); |
| 105 | + } |
| 106 | + |
| 107 | + if (theme === 'theme12') { |
| 108 | + return new Theme12ThemeAssetContributor().getAssetUrls(); |
| 109 | + } |
| 110 | + |
| 111 | + return []; |
| 112 | + } |
| 113 | +} |
0 commit comments