-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVueMetadata.ts
52 lines (43 loc) · 1.66 KB
/
VueMetadata.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* This file is part of the Klipper package.
*
* (c) François Pluchino <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import {MetadataManager} from '@klipper/bow/metadata/MetadataManager';
import {MetadataModuleState} from '@klipper/bow/stores/metadata/MetadataModuleState';
import _Vue, {PluginObject} from 'vue';
import {Store} from 'vuex';
/**
* I18n extra vue plugin.
*
* @author François Pluchino <[email protected]>
*/
export default class VueMetadata<S extends MetadataModuleState = MetadataModuleState> implements PluginObject<MetadataManager> {
private readonly metadataManager: MetadataManager;
constructor(store: Store<S>) {
this.metadataManager = new MetadataManager(store);
}
public install(Vue: typeof _Vue): void {
const self = this;
Object.defineProperty(Vue.prototype, '$metadata', {
get(this: Vue): MetadataManager {
return self.metadataManager;
},
});
Vue.prototype.$ml = (name: string): string => {
return self.metadataManager.getLabel(name);
};
Vue.prototype.$mpl = (name: string): string => {
return self.metadataManager.getPluralLabel(name);
};
Vue.prototype.$mfl = (object: string, field: string): string => {
return self.metadataManager.getFieldLabel(object, field);
};
Vue.prototype.$mal = (object: string, association: string): string => {
return self.metadataManager.getAssociationLabel(object, association);
};
}
}