From 3493b2d3861d91fdb47f5496d24b5c66a9a88c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lev=20Z=20Kir=C3=A1ly?= Date: Fri, 13 Oct 2023 14:33:05 +0200 Subject: [PATCH] Refactor method names and stores with camelCase #57 --- components/DictEntry.vue | 8 ++-- components/DictQuery.vue | 28 +++++------ components/MenuBar.vue | 14 +++--- components/Text.vue | 8 ++-- components/VicavMenuItem.vue | 12 ++--- components/VicavMenuSubmenu.vue | 4 +- components/WindowManager.vue | 40 ++++++++-------- store/appData.ts | 4 +- store/wm.ts | 85 ++++++++++++++++++--------------- 9 files changed, 104 insertions(+), 99 deletions(-) diff --git a/components/DictEntry.vue b/components/DictEntry.vue index 57af856..d7098bd 100644 --- a/components/DictEntry.vue +++ b/components/DictEntry.vue @@ -14,7 +14,7 @@ }, }>() - const GetDictEntry = async () => { + const getDictEntry = async () => { const { $api } = useNuxtApp() const id = String(props.params.sid) const dict = String(props.params.dict) @@ -26,12 +26,12 @@ } } - htmlContents.value = await GetDictEntry() + htmlContents.value = await getDictEntry() const domId = 'id-' + Math.floor(Math.random() * 1000000) - const WMStore = useWMStore() + const wmStore = useWMStore() onMounted(() => { - WMStore.SanitizeLinks(domId) + wmStore.sanitizeLinks(domId) }) diff --git a/components/DictQuery.vue b/components/DictQuery.vue index 4151691..368ad05 100644 --- a/components/DictQuery.vue +++ b/components/DictQuery.vue @@ -5,8 +5,8 @@ const props = defineProps(['params']) - const DictStore = useDictStore() - const dictList = computed(() => DictStore.dictList) + const dictStore = useDictStore() + const dictList = computed(() => dictStore.dictList) const dictSelector: Ref<{ [dictId: string]: boolean }> = ref({}) dictList.value.forEach(d => { dictSelector.value[d.coll_name] = (props.params?.dictId == d.coll_name) }) if (!Object.keys(dictSelector.value).some(d => dictSelector.value[d])) { @@ -18,7 +18,7 @@ .join(",") return newString }) - const dictCrossQueryXslt = computed(() => DictStore.dictCrossQueryXslt) + const dictCrossQueryXslt = computed(() => dictStore.dictCrossQueryXslt) const queryString: Ref = ref('') const normalizedQueryString = computed(() => { @@ -36,7 +36,7 @@ return newString }) - const QueryDictionaries = async () => { + const queryDictionaries = async () => { const { $api } = useNuxtApp() $api.baseUrl = ("" + import.meta.env.VITE_APIBASEURL); try { @@ -46,11 +46,11 @@ xslt: dictCrossQueryXslt.value })).text() } catch (error) { - LogError(error) + logError(error) } } - const LogError = async (error: any) => { + const logError = async (error: any) => { let errorXml = (new DOMParser()).parseFromString(await error.text(), 'text/xml') console.error(errorXml) alert( @@ -64,19 +64,19 @@ const resultHtml: Ref = ref('') const domId = 'id-' + Math.floor(Math.random() * 1000000) - const WMStore = useWMStore() + const wmStore = useWMStore() - const QueryButtonClicked = async (e: Event) => { + const queryButtonClicked = async (e: Event) => { e.preventDefault() - resultHtml.value = await QueryDictionaries() + resultHtml.value = await queryDictionaries() nextTick(() => { - WMStore.SanitizeLinks(domId) + wmStore.sanitizeLinks(domId) }) } - const OpenExamples = (e: Event) => { + const openExamples = (e: Event) => { e.preventDefault() - WMStore.Open('Text', 'textQuery: TUNICO DICTIONARY', { id: 'dictFrontPage_Tunis', customClass: 'vicav-cover-page' }) + wmStore.open('Text', 'textQuery: TUNICO DICTIONARY', { id: 'dictFrontPage_Tunis', customClass: 'vicav-cover-page' }) } @@ -91,7 +91,7 @@ placeholder="Search in dictionaries ..." aria-label="Search" /> -
@@ -105,7 +105,7 @@

For details as to how to formulate meaningful dictionary queries consult the - examples of the TUNICO dictionary. + examples of the TUNICO dictionary.

diff --git a/components/MenuBar.vue b/components/MenuBar.vue index d802dc0..9b167ae 100644 --- a/components/MenuBar.vue +++ b/components/MenuBar.vue @@ -11,16 +11,16 @@ AppDataStore.isMobileMenuOpen = !AppDataStore.isMobileMenuOpen } - const WMStore = useWMStore() + const wmStore = useWMStore() const windowList = computed(() => { - return WMStore.windowList.map(w => { return { + return wmStore.windowList.map(w => { return { id: w.id, name: w.id?.toString() + ': ' + w.winBoxOptions?.title }}) }) function SelectWindow(windowId: number | null) { if (windowId != null) { - WMStore.Focus(windowId); + wmStore.focus(windowId); } } @@ -32,7 +32,7 @@ onMounted(() => { windowListDropdown = new $bootstrap.Dropdown(windowListTogglerRef.value) let menuBarHeight = menuBarRef.value.offsetHeight - WMStore.SetTopMargin(menuBarHeight) + wmStore.setTopMargin(menuBarHeight) }) function ToggleWindowListCollapse(e) { AppDataStore.isMobileMenuOpen = false @@ -109,14 +109,14 @@
  • -
  • +
  • - {{ wam.id == WMStore.selectedDesktopArrangeMethodId ? '✓' : '' }} + {{ wam.id == wmStore.selectedDesktopArrangeMethodId ? '✓' : '' }} {{ wam.name }} diff --git a/components/Text.vue b/components/Text.vue index f6987b9..551d8b4 100644 --- a/components/Text.vue +++ b/components/Text.vue @@ -9,7 +9,7 @@ const htmlContents: Ref = ref("") const props = defineProps(['params']) - const GetText = async () => { + const getText = async () => { const { $api } = useNuxtApp() const id = String(props.params.id) $api.baseUrl = ("" + import.meta.env.VITE_APIBASEURL); @@ -19,12 +19,12 @@ console.error(error) } } - htmlContents.value = await GetText() + htmlContents.value = await getText() const domId = 'id-' + Math.floor(Math.random() * 1000000) - const WMStore = useWMStore() + const wmStore = useWMStore() onMounted(() => { - WMStore.SanitizeLinks(domId) + wmStore.sanitizeLinks(domId) }) diff --git a/components/VicavMenuItem.vue b/components/VicavMenuItem.vue index 667bcca..20e1d89 100644 --- a/components/VicavMenuItem.vue +++ b/components/VicavMenuItem.vue @@ -3,7 +3,7 @@ {{ menuNode.name }} @@ -11,20 +11,18 @@ diff --git a/components/VicavMenuSubmenu.vue b/components/VicavMenuSubmenu.vue index 51da91e..080abbb 100644 --- a/components/VicavMenuSubmenu.vue +++ b/components/VicavMenuSubmenu.vue @@ -3,7 +3,7 @@ WMStore.windowList) + const wmStore = useWMStore() + const windowList = computed(() => wmStore.windowList) const windowTypes = { Text: { component: resolveComponent('Text'), @@ -20,20 +20,20 @@ } as IWindowType, } - const newWindow = computed(() => WMStore.newWindow) + const newWindow = computed(() => wmStore.newWindow) watch(newWindow, (window) => { if (window != null) { - NewWindow(window) + createNewWindow(window) } }) - function NewWindow(newWindow: INewWindow) { + function createNewWindow(newWindow: INewWindow) { let windowType = windowTypes[newWindow.windowTypeId as keyof typeof windowTypes] if (windowType === undefined) { - ConsoleWarning("Window type undefined", newWindow) + consoleWarning("Window type undefined", newWindow) return false } if (typeof windowType.component === "string") { - ConsoleWarning("Window type '" + windowType + "' was not resolved", newWindow) + consoleWarning("Window type '" + windowType + "' was not resolved", newWindow) return false } @@ -47,33 +47,33 @@ type: windowType as IWindowType, winBoxOptions: { title: '[' + newWindow.windowTypeId + '] ' + newWindow.title, - top: WMStore.topMargin, + top: wmStore.topMargin, class: windowClasses, }, params: newWindow.params, } - WMStore.AddWindowToList(window) + wmStore.addWindowToList(window) } - function ConsoleWarning(text: string, data: Object) { + function consoleWarning(text: string, data: Object) { console.warn("WindowManager:", text, data); } - function RegisterWindowRef(i: number, ref: any) { - WMStore.RegisterWindowRef(i, ref) + function registerWindowRef(i: number, ref: any) { + wmStore.registerWindowRef(i, ref) } - function RemoveWindowRef(i: number, ref: any) { - WMStore.RemoveWindowRef(i, ref) + function removeWindowRef(i: number, ref: any) { + wmStore.removeWindowRef(i, ref) } - function RegisterClientSize() { - WMStore.RegisterClientSize(document.documentElement.clientWidth, document.documentElement.clientHeight) + function registerClientSize() { + wmStore.registerClientSize(document.documentElement.clientWidth, document.documentElement.clientHeight) } onMounted(() =>{ - RegisterClientSize() - window.addEventListener('resize', RegisterClientSize, true) + registerClientSize() + window.addEventListener('resize', registerClientSize, true) }) @@ -83,8 +83,8 @@ v-for="(window, i) in windowList" :key="window.id?.toString()" :options="window.winBoxOptions" - @open="RegisterWindowRef(i, $event)" - @close="RemoveWindowRef(i, $event)" + @open="registerWindowRef(i, $event)" + @close="removeWindowRef(i, $event)" > { + const getProjectData = async () => { const { $api } = useNuxtApp(); $api.baseUrl = ("" + import.meta.env.VITE_APIBASEURL); try { @@ -59,7 +59,7 @@ export const useAppDataStore = defineStore( } } - GetProjectData() + getProjectData() const isMobileMenuOpen = ref(false); const isMobile = ref(false); diff --git a/store/wm.ts b/store/wm.ts index 5372fa9..654c16c 100644 --- a/store/wm.ts +++ b/store/wm.ts @@ -5,15 +5,15 @@ export const useWMStore = defineStore( 'wm', () => { const topMargin = ref(0) - const SetTopMargin = (heightInPixels: number) => { + const setTopMargin = (heightInPixels: number) => { topMargin.value = heightInPixels } const clientSizeWidth = ref(0) const clientSizeHeight = ref(0) - const RegisterClientSize = (width: number, height: number) => { + const registerClientSize = (width: number, height: number) => { clientSizeWidth.value = width clientSizeHeight.value = height - topMargin.value - ArrangeWindows() + arrangeWindows() } const windowMarginPx = ref(5) // must be in sync with css class .wb-vicav in WindowManager.vue @@ -21,42 +21,42 @@ export const useWMStore = defineStore( const windowList = ref([] as IWindow[]) const newWindow = ref(null as INewWindow|null) - const Open = (windowTypeId: string, windowTitle: string, params: Object|null) => { + const open = (windowTypeId: string, windowTitle: string, params: Object|null) => { newWindow.value = { id: counter.value++, title: windowTitle, windowTypeId, params } nextTick(() => { newWindow.value = null }) } - const AddWindowToList = (window: IWindow) => { + const addWindowToList = (window: IWindow) => { window.winBoxOptions.index = windowList.value.length > 0 ? Math.max(...windowList.value.map(w => parseInt(w.ref.index))) + 1 : 1000 windowList.value.push(window) - ArrangeWindows() + arrangeWindows() } - const RegisterWindowRef = (i: number, ref: HTMLElement) => { + const registerWindowRef = (i: number, ref: HTMLElement) => { windowList.value[i].ref = ref } - const RemoveWindowRef = (i: number, ref: any) => { + const removeWindowRef = (i: number, ref: any) => { let index = windowList.value.findIndex(w => w.ref.id === ref.id); if(index >= 0) { ref.g.remove(); windowList.value.splice(index, 1); } - ArrangeWindows() + arrangeWindows() } - const Focus = (windowId: number) => { + const focus = (windowId: number) => { let window = windowList.value.find(w => w.id == windowId) if (window != null) { window.ref.focus() } } - const ArrangeAllMaximize = () => { + const arrangeAllMaximize = () => { windowList.value.forEach((w, i) => { w.ref .resize(clientSizeWidth.value - 2 * windowMarginPx.value, clientSizeHeight.value - 2 * windowMarginPx.value) @@ -64,11 +64,18 @@ export const useWMStore = defineStore( }) } - const ArrangeNot = () => { - windowList.value.forEach(w => w.ref.removeClass('no-min').removeClass('no-max').removeClass('no-full').removeClass('no-resize').removeClass('no-move')) + const arrangeNot = () => { + windowList.value.forEach( + w => w.ref + .removeClass('no-min') + .removeClass('no-max') + .removeClass('no-full') + .removeClass('no-resize') + .removeClass('no-move') + ) } - const ArrangeTile = () => { + const arrangeTile = () => { let cols = Math.floor(Math.sqrt(windowList.value.length - 1)) + 1 let rows = Math.ceil(windowList.value.length / cols) let windowWidth = Math.floor(clientSizeWidth.value / cols) @@ -84,7 +91,7 @@ export const useWMStore = defineStore( }) } - const ArrangeSmartTile = () => { + const arrangeSmartTile = () => { let N = windowList.value.length let floorSqrtN = Math.floor(Math.sqrt(N)) let innerSquare = Math.pow(floorSqrtN, 2) @@ -108,7 +115,7 @@ export const useWMStore = defineStore( }) } - const ArrangeCascade = () => { + const arrangeCascade = () => { let windowWidth = Math.floor(clientSizeWidth.value / 2) let windowHeight = Math.floor(clientSizeHeight.value / 2) @@ -136,24 +143,24 @@ export const useWMStore = defineStore( const desktopArrangeMethods: Array = [{ id: 0, name: "No arrangement", - method: ArrangeNot, + method: arrangeNot, }, { id: 1, name: "Cascade", - method: ArrangeCascade, + method: arrangeCascade, }, { id: 2, name: "Tile", - method: ArrangeTile, + method: arrangeTile, }, { id: 3, name: "Smart Tile", - method: ArrangeSmartTile, + method: arrangeSmartTile, }] const selectedDesktopArrangeMethodId = ref(3) // TODO: move magic number to settings - const SelectDesktopArrangeMethod = (wam: WindowArrangeMethod) => { + const selectDesktopArrangeMethod = (wam: WindowArrangeMethod) => { let index = desktopArrangeMethods.findIndex(m => m.id === wam.id) if (index >= 0) { selectedDesktopArrangeMethodId.value = wam.id @@ -164,16 +171,16 @@ export const useWMStore = defineStore( } const isMobile = false // @TODO - const ArrangeWindows = async () => { + const arrangeWindows = async () => { await nextTick() if (isMobile) { - ArrangeAllMaximize() + arrangeAllMaximize() } else { desktopArrangeMethods.find(m => m.id === selectedDesktopArrangeMethodId.value)?.method() } } - const SanitizeLinks = (domId: string) => { + const sanitizeLinks = (domId: string) => { console.log('SanitizeLinks starts') document.querySelectorAll(`#${domId} a`) .forEach(a => { @@ -190,16 +197,16 @@ export const useWMStore = defineStore( } e.preventDefault() if (targetType == null || textId == null) { - GetDbSnippet_YesThisIsDeprecatedAndWillBeRemovedASAP(a.href.split("\"")[1]) + getDbSnippet_YesThisIsDeprecatedAndWillBeRemovedASAP(a.href.split("\"")[1]) return } - Open(targetType.charAt(0).toUpperCase() + targetType.slice(1), windowTitle, { id: textId }) + open(targetType.charAt(0).toUpperCase() + targetType.slice(1), windowTitle, { id: textId }) }, false) } }) } - const GetDbSnippet_YesThisIsDeprecatedAndWillBeRemovedASAP = (params: string) => { + const getDbSnippet_YesThisIsDeprecatedAndWillBeRemovedASAP = (params: string) => { console.log('getDBSnippet input: ', params) let splitPoint = params.indexOf(":") let sHead = params.substring(0, splitPoint) @@ -218,11 +225,11 @@ export const useWMStore = defineStore( let st5 = sTail.split(","); sid = st5[0]; dict = st5[1]; - Open ('DictEntry', dict + ': ' + sid, { dict, sid }) + open ('DictEntry', dict + ': ' + sid, { dict, sid }) console.log('getDBSnippet: dictID,', { dict, sid }) break; case "text": - Open('Text', secLabel, { id: snippetID }) + open('Text', secLabel, { id: snippetID }) console.log('getDBSnippet: text,', secLabel, { id: snippetID }) break; default: @@ -234,27 +241,27 @@ export const useWMStore = defineStore( return { topMargin, - SetTopMargin, - RegisterClientSize, + setTopMargin, + registerClientSize, windowList, newWindow, - Open, - AddWindowToList, - RegisterWindowRef, - RemoveWindowRef, - Focus, + open, + addWindowToList, + registerWindowRef, + removeWindowRef, + focus, desktopArrangeMethods, - SelectDesktopArrangeMethod, + selectDesktopArrangeMethod, selectedDesktopArrangeMethodId, - SanitizeLinks, + sanitizeLinks, } }, { logger: { - actions: ["Open"], + actions: ["open"], }, } )