Skip to content

armgit / dashy

Public Imported from GitHub
0

🚀 A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

:truck: Refactored section helpers into own file

Alicia Sykesaad7ab9b1f8e
diff --git a/src/components/PageStrcture/Footer.vue b/src/components/PageStrcture/Footer.vue
index 252c2abb..8d44b6f6 100644
--- a/src/components/PageStrcture/Footer.vue
+++ b/src/components/PageStrcture/Footer.vue
@@ -12,7 +12,7 @@
<script>
-import { shouldBeVisible } from '@/utils/MiscHelpers';
+import { shouldBeVisible } from '@/utils/SectionHelpers';
export default {
name: 'Footer',
diff --git a/src/components/PageStrcture/Header.vue b/src/components/PageStrcture/Header.vue
index d17a41f4..f0d3f96f 100644
--- a/src/components/PageStrcture/Header.vue
+++ b/src/components/PageStrcture/Header.vue
@@ -13,7 +13,7 @@
<script>
import PageTitle from '@/components/PageStrcture/PageTitle.vue';
import Nav from '@/components/PageStrcture/Nav.vue';
-import { shouldBeVisible } from '@/utils/MiscHelpers';
+import { shouldBeVisible } from '@/utils/SectionHelpers';
export default {
name: 'Header',
diff --git a/src/store.js b/src/store.js
index 38bfb582..4d3dbf85 100644
--- a/src/store.js
+++ b/src/store.js
@@ -4,7 +4,7 @@ import Vuex from 'vuex';
import Keys from '@/utils/StoreMutations';
import ConfigAccumulator from '@/utils/ConfigAccumalator';
import { componentVisibility } from '@/utils/ConfigHelpers';
-import { applyItemId } from '@/utils/MiscHelpers';
+import { applyItemId } from '@/utils/SectionHelpers';
import filterUserSections from '@/utils/CheckSectionVisibility';
import { InfoHandler, InfoKeys } from '@/utils/ErrorHandler';
diff --git a/src/utils/ConfigAccumalator.js b/src/utils/ConfigAccumalator.js
index 041306e9..a1756461 100644
--- a/src/utils/ConfigAccumalator.js
+++ b/src/utils/ConfigAccumalator.js
@@ -13,7 +13,7 @@ import {
layout as defaultLayout,
} from '@/utils/defaults';
import ErrorHandler from '@/utils/ErrorHandler';
-import { applyItemId } from '@/utils/MiscHelpers';
+import { applyItemId } from '@/utils/SectionHelpers';
import conf from '../../public/conf.yml';
export default class ConfigAccumulator {
diff --git a/src/utils/MiscHelpers.js b/src/utils/MiscHelpers.js
index 6886ace2..c560d089 100644
--- a/src/utils/MiscHelpers.js
+++ b/src/utils/MiscHelpers.js
@@ -1,8 +1,5 @@
+/* A collection of generic reusable functions for various string processing tasks */
/* eslint-disable arrow-body-style */
-import { hideFurnitureOn } from '@/utils/defaults';
-
-/* Returns false if page furniture should be hidden on said route */
-export const shouldBeVisible = (routeName) => !hideFurnitureOn.includes(routeName);
/* Very rudimentary hash function for generative icons */
export const asciiHash = (input) => {
@@ -27,31 +24,6 @@ export const sanitize = (string) => {
return string.replace(reg, (match) => (map[match]));
};
-/* Based on section title, item name and index, return a string value for ID */
-const makeItemId = (sectionStr, itemStr, index) => {
- const charSum = sectionStr.split('').map((a) => a.charCodeAt(0)).reduce((x, y) => x + y);
- const itemTitleStr = itemStr.replace(/\s+/g, '-').replace(/[^a-zA-Z ]/g, '').toLowerCase();
- return `${index}_${charSum}_${itemTitleStr}`;
-};
-
-/* Given an array of sections, apply a unique ID to each item, and return modified array */
-export const applyItemId = (inputSections) => {
- const sections = inputSections || [];
- sections.forEach((sec, secIdx) => {
- if (sec.items) {
- sec.items.forEach((item, itemIdx) => {
- sections[secIdx].items[itemIdx].id = makeItemId(sec.name, item.title, itemIdx);
- });
- }
- if (sec.widgets) {
- sec.widgets.forEach((widget, widgetIdx) => {
- sections[secIdx].widgets[widgetIdx].id = makeItemId(sec.name, widget.type, widgetIdx);
- });
- }
- });
- return sections;
-};
-
/* Given a timestamp, returns formatted date, in local format */
export const timestampToDate = (timestamp) => {
const localFormat = navigator.language;
@@ -74,30 +46,6 @@ export const timestampToDateTime = (timestamp) => {
return `${timestampToDate(timestamp)} at ${timestampToTime(timestamp)}`;
};
-/* Given a currency code, return the corresponding unicode symbol */
-export const findCurrencySymbol = (currencyCode) => {
- const code = currencyCode.toUpperCase().trim();
- const currencies = {
- USD: '$', // US Dollar
- EUR: '€', // Euro
- CRC: '₡', // Costa Rican Colón
- GBP: '£', // British Pound Sterling
- ILS: '₪', // Israeli New Sheqel
- INR: '₹', // Indian Rupee
- JPY: '¥', // Japanese Yen
- KRW: '₩', // South Korean Won
- NGN: '₦', // Nigerian Naira
- PHP: '₱', // Philippine Peso
- PLN: 'zł', // Polish Zloty
- PYG: '₲', // Paraguayan Guarani
- THB: '฿', // Thai Baht
- UAH: '₴', // Ukrainian Hryvnia
- VND: '₫', // Vietnamese Dong
- };
- if (currencies[code]) return currencies[code];
- return code;
-};
-
/* Given a 2-digit country code, return path to flag image from Flagpedia */
export const getCountryFlag = (countryCode, dimens) => {
const protocol = 'https';
@@ -108,6 +56,12 @@ export const getCountryFlag = (countryCode, dimens) => {
return `${protocol}://${cdn}/${dimensions}/${country}.${ext}`;
};
+/* Given a currency code, return path to corresponding countries flag icon */
+export const getCurrencyFlag = (currency) => {
+ const cdn = 'https://raw.githubusercontent.com/transferwise/currency-flags';
+ return `${cdn}/master/src/flags/${currency.toLowerCase()}.png`;
+};
+
/* Given a Latitude & Longitude object, and optional zoom level, return link to OSM */
export const getMapUrl = (location, zoom) => {
return `https://www.openstreetmap.org/#map=${zoom || 10}/${location.lat}/${location.lon}`;
@@ -152,3 +106,49 @@ export const roundPrice = (price) => {
export const truncateStr = (str, len = 60, ellipse = '...') => {
return str.length > len + ellipse.length ? `${str.slice(0, len)}${ellipse}` : str;
};
+
+/* Given a currency code, return the corresponding unicode symbol */
+export const findCurrencySymbol = (currencyCode) => {
+ const code = currencyCode.toUpperCase().trim();
+ const currencies = {
+ USD: '$', // US Dollar
+ EUR: '€', // Euro
+ GBP: '£', // British Pound Sterling
+ AFN: '؋', // Afghan Afghani
+ ALL: 'Lek', // Albanian Lek
+ AUD: '$', // Australian Dollar
+ AWG: 'ƒ', // Aruban Guilder
+ BAM: 'KM', // Bosnian Mark
+ BWP: 'P', // Botswana Pula
+ CAD: '$', // Canadian Dollar
+ CNY: '¥', // Chinese Yuan Renminbi
+ CRC: '₡', // Costa Rican Colón
+ CRS: '₡', // Costa Rican Colon
+ CUP: '₱', // Cuban Peso
+ DKK: 'kr', // Danish Krone
+ HKD: '$', // Hong Kong Dollar
+ HUF: 'Ft', // Hungarian Forint
+ HRK: 'kn', // Croatian Kuna
+ ISK: 'kr', // Icelandic Krona
+ ILS: '₪', // Israeli New Sheqel
+ INR: '₹', // Indian Rupee
+ IRR: '﷼', // Iranian Rial
+ JPY: '¥', // Japanese Yen
+ KRW: '₩', // South Korean Won
+ LAK: '₭', // Laos Kip
+ NGN: '₦', // Nigerian Naira
+ NOK: 'kr', // Norwegian Krone
+ PHP: '₱', // Philippine Peso
+ PKR: '₨', // Pakistani Rupee
+ PLN: 'zł', // Polish Zloty
+ PYG: '₲', // Paraguayan Guarani
+ RUB: '₽', // Russian Ruble
+ THB: '฿', // Thai Baht
+ UAH: '₴', // Ukrainian Hryvnia
+ VND: '₫', // Vietnamese Dong
+ YER: '﷼', // Yemen Rial
+ ZWD: 'Z$', // Zimbabwean Dollar
+ };
+ if (currencies[code]) return currencies[code];
+ return `${code} `; // Symbol not found, return text code instead
+};
diff --git a/src/utils/SectionHelpers.js b/src/utils/SectionHelpers.js
new file mode 100644
index 00000000..2d16ba18
--- /dev/null
+++ b/src/utils/SectionHelpers.js
@@ -0,0 +1,31 @@
+/* Helper functions for Sections and Items */
+
+import { hideFurnitureOn } from '@/utils/defaults';
+
+/* Returns false if page furniture should be hidden on said route */
+export const shouldBeVisible = (routeName) => !hideFurnitureOn.includes(routeName);
+
+/* Based on section title, item name and index, return a string value for ID */
+const makeItemId = (sectionStr, itemStr, index) => {
+ const charSum = sectionStr.split('').map((a) => a.charCodeAt(0)).reduce((x, y) => x + y);
+ const itemTitleStr = itemStr.replace(/\s+/g, '-').replace(/[^a-zA-Z ]/g, '').toLowerCase();
+ return `${index}_${charSum}_${itemTitleStr}`;
+};
+
+/* Given an array of sections, apply a unique ID to each item, and return modified array */
+export const applyItemId = (inputSections) => {
+ const sections = inputSections || [];
+ sections.forEach((sec, secIdx) => {
+ if (sec.items) {
+ sec.items.forEach((item, itemIdx) => {
+ sections[secIdx].items[itemIdx].id = makeItemId(sec.name, item.title, itemIdx);
+ });
+ }
+ if (sec.widgets) {
+ sec.widgets.forEach((widget, widgetIdx) => {
+ sections[secIdx].widgets[widgetIdx].id = makeItemId(sec.name, widget.type, widgetIdx);
+ });
+ }
+ });
+ return sections;
+};