| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import {EnumChoice, EnumChoices} from "~/types/types";
- import * as _ from "lodash";
- import {Rest} from "~/services/queries/rest";
- class EnumDataProvider{
- private $rest: Rest
- private i18n:any
- constructor($rest: Rest, i18n:any) {
- this.$rest = $rest
- this.i18n = i18n
- }
- public async get(type: string){
- const enums:EnumChoices = []
- const response = await this.$rest.getCollection(`/api/enum/${type}`)
- if(response){
- _.each(response['items'], (item, key) =>{
- const entry:EnumChoice = {
- value: key,
- label: this.i18n.t(item)
- };
- enums.push(entry)
- })
- }
- return this.sortEnum(enums)
- }
- public sortEnum(enums:EnumChoices){
- return enums.sort( (a, b) => {
- if (a.label > b.label)
- return 1;
- if (a.label < b.label)
- return -1;
- return 0;
- });
- }
- }
- export const $enumDataProvider = ($rest:Rest, i18n:any) => new EnumDataProvider($rest,i18n);
|