diff --git a/ayanova/src/api/enums.js b/ayanova/src/api/enums.js index f2c0021e..5f65afd9 100644 --- a/ayanova/src/api/enums.js +++ b/ayanova/src/api/enums.js @@ -19,6 +19,7 @@ export default { getEnumDisplay(enumKey, enumValue) { // debugger; + enumKey = enumKey.toLowerCase(); if (!window.$gz._.has(window.$gz.store.state.localeText, key)) { return "??" + key; } @@ -31,415 +32,34 @@ export default { // e.g. [{0:"no role"},{1:"Limited role"}] // getEnumList(enumKey) { - // debugger; + //debugger; + //check if list + //if not then fetch it and store it + enumKey = enumKey.toLowerCase(); + if (!window.$gz._.has(window.$gz.store.state.enums, enumKey)) { - return "??" + key; - } - return window.$gz.store.state.localeText[key]; - }, - fetch(keys) { - return new Promise(function fetchLocaleKeysFromServer(resolve) { - // - //step 1: build an array of keys that we don't have already - //Note: this will ensure only unique keys go into the store so it's safe to call this with dupes as can happen - //for example datatables have dynamic column names so they need to fetch on demand - var needIt = []; - for (var i = 0; i < keys.length; i++) { - if (!window.$gz._.has(window.$gz.store.state.localeText, keys[i])) { - needIt.push(keys[i]); - } - } - - if (needIt.length == 0) { - resolve(); - return; - } - - //step 2: get it - fetch( - window.$gz.api.APIUrl("locale/subset"), - window.$gz.api.fetchPostOptions(needIt) - ) - .then(window.$gz.api.status) - .then(window.$gz.api.json) - .then(response => { - window.$gz._.forEach( - response.data, - function commitFetchedLTItemToStore(item) { - window.$gz.store.commit("addLocaleText", item); - } - ); - - resolve(); + var that = this; + (async function() { + await that.fetch(enumKey).then(res => { + //massage the data as necessary + debugger; + console.log(res); + //stuff the data into the store + // window.$gz.store.commit("setEnum", item); + return window.$gz.store.state.enums[enumKey]; }); - }); - }, - //Keys that will always be required for any AyaNova work for any user - coreKeys: [ - //main nav options - "Home", - "Dashboard", - "Schedule", - "MemoList", - "UserSettings", - "Locale", - "SetLoginPassword", - "NotifySubscriptionList", - "UserPreferences", - "Service", - "ClientList", - "HeadOfficeList", - "WorkorderServiceList", - "WorkorderServiceTemplate", - "WorkorderQuoteList", - "WorkorderQuoteTemplate", - "WorkorderPreventiveMaintenanceList", - "WorkorderPreventiveMaintenanceTemplate", - "UnitList", - "UnitModels", - "ContractList", - "ClientServiceRequestList", - "LoanItemList", - "PartList", - "PartByWarehouseInventoryList", - "WorkorderItemPartRequestList", - "InventoryPurchaseOrders", - "InventoryPurchaseOrderReceipts", - "InventoryPartInventoryAdjustments", - "WidgetList", - "VendorList", - "AdministrationGlobalSettings", - "HelpLicense", - "UserList", - "LocalizedTextDesign", - "ReportList", - "ReminderList", - "Inventory", - "Accounting", - "Administration", - "Operations", - "Attachments", - "Review", - "History", - "Statistics", - "Backup", - "ServerJobs", - "ServerLog", - "ServerMetrics", - "NotificationSettings", - "HelpAboutAyaNova", - "MenuHelp", - "More", - "Logout", - //form required options - "Active", - "Add", - "Cancel", - "Close", - "Save", - "Delete", - "OK", - "Print", - "Report", - "WikiPage", - "Duplicate", - "RecordHistory", - "Search", - "TypeToSearchOrAdd", - "NoData", - "ErrorFieldLengthExceeded", - "ErrorStartDateAfterEndDate", - "ErrorRequiredFieldEmpty", - "ErrorFieldValueNotInteger", - "ErrorFieldValueNotDecimal", - "ErrorAPI2000", - "ErrorAPI2001", - "ErrorAPI2002", - "ErrorAPI2003", - "ErrorAPI2004", - "ErrorAPI2005", - "ErrorAPI2010", - "ErrorAPI2020", - "ErrorAPI2030", - "ErrorAPI2200", - "ErrorAPI2201", - "ErrorAPI2202", - "ErrorAPI2203", - "ErrorAPI2204", - "ErrorAPI2205", - "ErrorAPI2206", - "ErrorAPI2207", - "ErrorAPI2208", - "ErrorAPI2209", - "ErrorServerUnresponsive", - "ErrorUserNotAuthenticated", - "ErrorUserNotAuthorized", - "DeletePrompt", - "AreYouSureUnsavedChanges", - "Leave", - "Copy", - "Tags", - "Customize", - "ObjectCustomFieldCustomGrid", - "RowsPerPage", - "PageOfPageText", - "Loading", - "AM", - "PM" - ], - - //////////////////////////////////////////////////////// - // Take in a string that contains one or more - //locale keys between square brackets - //translate each and return the string translated - // - translateString(s) { - var ret = s; - var pattern = /\[(.*?)\]/g; - var match; - while ((match = pattern.exec(s)) != null) { - var foundMatch = match[0]; - var ltKey = match[1]; - var newValue = this.get(ltKey); - ret = ret.replace(foundMatch, newValue); - } - return ret; - }, - //////////////////////////////////////////////////////// - // attempt to determine user's preferred language settings - // As of Jan 2020 all major browsers support - // navigator.languages - // but some use navigator.language (singular) to denote UI language preference - // not browsing language preference - // so the ideal way to do this is to use navigator.languages[0] for the preferred language - // and ignore the singular property since we don't care about the actual browser UI language - // only how the user expects to see the page itself - // - // also for sake of future proofing and edge cases need to have it be manually settable as well - // ############### TODO: modify all of these to put the user's manual override first in line (if there is one) - //https://appmakers.dev/bcp-47-language-codes-list/ - getBrowserLanguages() { - return window.navigator.languages; - }, - getBrowserFirstLanguage() { - return window.navigator.languages[0]; - }, - /////////////////////////////////////////// - // Get users default time zone - //https://www.iana.org/time-zones - //https://en.wikipedia.org/wiki/List_of_tz_database_time_zones - getTimeZoneName() { - return Intl.DateTimeFormat().resolvedOptions().timeZone; - }, - ////////////////////////////////////////////////// - // Get the user's chosen currency name - //https://en.wikipedia.org/wiki/ISO_4217 - getCurrencyName() { - return window.$gz.store.state.locale.currencyName; - }, - ////////////////////////////////////////////////// - // Get the user's chosen 12hr clock - // - getHour12() { - return window.$gz.store.state.locale.hour12; - }, - /////////////////////////////////////////// - // Turn a utc date into a displayable - // short date and time - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString - // - utcDateToShortDateAndTimeLocalized( - value, - timeZoneName, - languageName, - hour12 - ) { - if (!value) { - return ""; - } - if (!timeZoneName) { - timeZoneName = this.getTimeZoneName(); - } - if (!languageName) { - languageName = this.getBrowserLanguages(); - } - - if (!hour12) { - hour12 = this.getHour12(); - } - - //parse the date which is identified as utc ("2020-02-06T18:18:49.148011Z") - var parsedDate = new Date(value); - - //is it a valid date? - if (!(parsedDate instanceof Date && !isNaN(parsedDate))) { - return "not valid"; - } - - return parsedDate.toLocaleString(languageName, { - timeZone: timeZoneName, - dateStyle: "short", - timeStyle: "short", - hour12: hour12 - }); - }, /////////////////////////////////////////// - // Turn a utc date into a displayable - // short date - // - utcDateToShortDateLocalized(value, timeZoneName, languageName) { - if (!value) { - return ""; - } - if (!timeZoneName) { - timeZoneName = this.getTimeZoneName(); - } - if (!languageName) { - languageName = this.getBrowserLanguages(); - } - - //parse the date which is identified as utc ("2020-02-06T18:18:49.148011Z") - var parsedDate = new Date(value); - - //is it a valid date? - if (!(parsedDate instanceof Date && !isNaN(parsedDate))) { - return "not valid"; - } - - return parsedDate.toLocaleDateString(languageName, { - timeZone: timeZoneName, - dateStyle: "short" - }); - }, /////////////////////////////////////////// - // Turn a utc date into a displayable - // short time - // - utcDateToShortTimeLocalized(value, timeZoneName, languageName, hour12) { - if (!value) { - return ""; - } - if (!timeZoneName) { - timeZoneName = this.getTimeZoneName(); - } - if (!languageName) { - languageName = this.getBrowserLanguages(); - } - - if (!hour12) { - hour12 = this.getHour12(); - } - - //parse the date which is identified as utc ("2020-02-06T18:18:49.148011Z") - var parsedDate = new Date(value); - - //is it a valid date? - if (!(parsedDate instanceof Date && !isNaN(parsedDate))) { - return "not valid"; - } - - return parsedDate.toLocaleTimeString(languageName, { - timeZone: timeZoneName, - timeStyle: "short", - hour12: hour12 - }); - }, - /////////////////////////////////////////////// - // Convert a utc date to local time zone - // and return time portion only in iso 8601 - // format (used by time and date picker components) - // - utcDateStringToLocal8601TimeOnlyString(value, timeZoneName) { - if (!value) { - //if no value, return the current time as expected by the time picker + })(); } else { - //ok, the reason for sv-SE is that it's a locale that returns the time already in ISO format and 24hr by default - //that can change over time so if this breaks that's why - //also fr-CA does as well as possibly en-CA - //https://stackoverflow.com/a/58633686/8939 - if (!timeZoneName) { - timeZoneName = this.getTimeZoneName(); + debugger; + return window.$gz.store.state.enums[enumKey]; + } + }, + fetch(enumKey) { + return window.$gz.api.get("EnumPickList/list/" + enumKey).then(res => { + if (res.error) { + throw res.error; } - return new Date(value).toLocaleTimeString("sv-SE", { - timeZone: timeZoneName - }); - } - }, - /////////////////////////////////////////////// - // Convert a local time only string with date string - // to UTC and output as ISO 8601 - // (used by time and date picker components) - // - localTimeDateStringToUTC8601String(value, timeZoneName) { - //https://moment.github.io/luxon/docs/manual/zones.html#creating-datetimes-in-a-zone - if (!timeZoneName) { - timeZoneName = this.getTimeZoneName(); - } - //parse in the time in the currently used timezone - return window.$gz.DateTime.fromISO(value, { - zone: this.timeZoneName - }) - .setZone("utc") //convert to UTC - .toISO(); //output as ISO 8601 - }, - /////////////////////////////////////////////// - // Convert a utc date to local time zone - // and return date only portion only in iso 8601 - // format (used by time and date picker components) - // - utcDateStringToLocal8601DateOnlyString(value, timeZoneName) { - if (!value) { - //if no value, return the current time as expected by the time picker - } else { - //ok, the reason for sv-SE is that it's a locale that returns the time already in ISO format and 24hr by default - //that can change over time so if this breaks that's why - //also fr-CA does as well as possibly en-CA - //https://stackoverflow.com/a/58633686/8939 - if (!timeZoneName) { - timeZoneName = this.getTimeZoneName(); - } - return new Date(value).toLocaleDateString("sv-SE", { - timeZone: timeZoneName - }); - } - }, - /////////////////////////////////////////// - // Turn a decimal number into a local - // currency display - // - currencyLocalized(value, languageName, currencyName) { - if (!value) return ""; - if (!languageName) { - languageName = this.getBrowserLanguages(); - } - if (!currencyName) { - currencyName = this.getCurrencyName(); - } - - return new Intl.NumberFormat(languageName, { - style: "currency", - currency: currencyName - }).format(value); - }, - /////////////////////////////////////////// - // Turn a decimal number into a local - // decimal format display - // - decimalLocalized(value, languageName) { - if (!value) return ""; - if (!languageName) { - languageName = this.getBrowserLanguages(); - } - return new Intl.NumberFormat(languageName, { - minimumFractionDigits: 2 - }).format(value); - }, - //////////////////////////////////////////////////////// - // dynamically set the vuetify language elements from - // users localized text (am/pm etc) - // Keeping vuetify using en locale and just adjusting on top of that - // - setVuetifyDefaultLanguageElements(vm) { - vm.$vuetify.lang.locales.en.close = this.get("OK"); - vm.$vuetify.lang.locales.en.timePicker.am = this.get("AM"); - vm.$vuetify.lang.locales.en.timePicker.pm = this.get("PM"); + return res.data; + }); } }; diff --git a/ayanova/src/components/gz-data-table.vue b/ayanova/src/components/gz-data-table.vue index 556b4628..c4af8d98 100644 --- a/ayanova/src/components/gz-data-table.vue +++ b/ayanova/src/components/gz-data-table.vue @@ -536,6 +536,7 @@ function buildRecords(listData, columndefinitions, filters) { This way entirely bypasses locale stuff //big object so maybe it's own thing, not part of locale at all or locale fronts for it?? */ + window.$gz.enums.getEnumList(columndefinitions[iColumn].et); display = columndefinitions[iColumn].et + "." + display; break; default: diff --git a/ayanova/src/main.js b/ayanova/src/main.js index bdb5ac5d..62e3e867 100644 --- a/ayanova/src/main.js +++ b/ayanova/src/main.js @@ -26,6 +26,7 @@ import gzform from "./api/gzform"; import gzformcustomtemplate from "./api/form-custom-template"; import authorizationroles from "./api/authorizationroles"; import gztype from "./api/ayatype"; +import gzenums from "./api/enums"; import "@/assets/css/main.css"; //controls @@ -53,6 +54,7 @@ window.$gz = { formCustomTemplate: gzformcustomtemplate, type: gztype, role: authorizationroles, + enums: gzenums, eventBus: gzeventbus, menu: gzmenu, dialog: gzdialog,