1 | import {PreDestroy, Bean, Qualifier, Autowired, PostConstruct, Optional, Context} from './context/context';
|
2 |
|
3 | let themeNames = ['fresh', 'dark', 'blue', 'bootstrap', 'material', 'balham-dark', 'balham'];
|
4 | const themes = themeNames.concat(themeNames.map(name => `theme-${name}`));
|
5 | const themeClass = new RegExp(`ag-(${themes.join('|')})`);
|
6 |
|
7 | const matGridSize = 8;
|
8 | type HardCodedSize = {[key: string]: {[key: string]: number}};
|
9 | const freshGridSize = 4;
|
10 | const balhamGridSize = 4;
|
11 |
|
12 | const HARD_CODED_SIZES: HardCodedSize = {
|
13 | 'ag-theme-material': {
|
14 | headerHeight: matGridSize * 7,
|
15 | virtualItemHeight: matGridSize * 5,
|
16 | rowHeight: matGridSize * 6
|
17 | },
|
18 | 'ag-theme-classic': {
|
19 | headerHeight: 25,
|
20 | virtualItemHeight: freshGridSize * 5,
|
21 | rowHeight: 25
|
22 | },
|
23 | 'ag-theme-balham': {
|
24 | headerHeight: balhamGridSize * 8,
|
25 | virtualItemHeight: balhamGridSize * 7,
|
26 | rowHeight: balhamGridSize * 7
|
27 | }
|
28 | };
|
29 |
|
30 | @Bean('environment')
|
31 | export class Environment {
|
32 | @Autowired('eGridDiv') private eGridDiv: HTMLElement;
|
33 |
|
34 | private gridSize: number;
|
35 | private iconSize: number;
|
36 | private sassVariables: {[key: string]: string} = {};
|
37 |
|
38 |
|
39 |
|
40 | public loadSassVariables(): void {
|
41 | |
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | }
|
57 |
|
58 | public getSassVariable(theme: string, key: string): number {
|
59 | if (theme == 'ag-theme-material') {
|
60 | return HARD_CODED_SIZES['ag-theme-material'][key];
|
61 | }
|
62 | else if (theme == 'ag-theme-balham' || theme == 'ag-theme-balham-dark') {
|
63 | return HARD_CODED_SIZES['ag-theme-balham'][key];
|
64 | }
|
65 | return HARD_CODED_SIZES['ag-theme-classic'][key];
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | }
|
74 |
|
75 | public getTheme(): string {
|
76 | let themeMatch: RegExpMatchArray;
|
77 | let element: HTMLElement = this.eGridDiv;
|
78 |
|
79 | while (element != document.documentElement && themeMatch == null) {
|
80 | themeMatch = element.className.match(themeClass);
|
81 | element = element.parentElement;
|
82 | if (element == null) {
|
83 | break;
|
84 | }
|
85 | }
|
86 |
|
87 | if (themeMatch) {
|
88 | return themeMatch[0];
|
89 | } else {
|
90 | return 'ag-fresh';
|
91 | }
|
92 | }
|
93 | }
|