Skip to content

Commit

Permalink
Implement front-end routing #18
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jul 31, 2024
1 parent 1475469 commit 6c08f5e
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 107 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Added compatibility with PrimeVue 4 [#16](https://github.com/archesproject/arches-references/pull/16)
- Add compatibility with PrimeVue 4 [#16](https://github.com/archesproject/arches-references/pull/16)
- Add front-end routing [#18](https://github.com/archesproject/arches-references/pull/18)

### Changed
- Generate URIs when not supplied [#17](https://github.com/archesproject/arches-references/pull/17)
- Generate URIs when not supplied [#17](https://github.com/archesproject/arches-references/pull/17)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import ko from 'knockout';
import ControlledListsMain from '@/arches-references/components/ControlledListsMain.vue';
import { definePreset } from '@primevue/themes';
import Aura from '@primevue/themes/aura';

import ControlledListManager from '@/arches-references/plugins/ControlledListManager.vue';
import createVueApplication from 'utils/create-vue-application';
import ControlledListManagerTemplate from 'templates/views/components/plugins/controlled-list-manager.htm';

import { createRouter, createWebHistory } from 'vue-router';

const routes = [
{ path: '/plugins/controlled-list-manager', name: 'splash', component: ControlledListsMain },
{ path: '/plugins/controlled-list-manager/list/:id', name: 'list', component: ControlledListsMain },
{ path: '/plugins/controlled-list-manager/item/:id', name: 'item', component: ControlledListsMain },
];

const router = createRouter({
history: createWebHistory(),
routes,
});

// Much of this might get merged upstream to core arches in 8.0?
const ControlledListsPreset = definePreset(Aura, {
primitive: {
Expand Down Expand Up @@ -65,6 +79,7 @@ const controlledListsTheme = {
ko.components.register('controlled-list-manager', {
viewModel: function() {
createVueApplication(ControlledListManager, controlledListsTheme).then((vueApp) => {
vueApp.use(router);
vueApp.mount('#controlled-list-manager-mounting-point');
});
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<script setup lang="ts">
import arches from "arches";
import { computed, provide, ref } from "vue";
import { useRouter } from "vue-router";
import ConfirmDialog from "primevue/confirmdialog";
import ProgressSpinner from "primevue/progressspinner";
import Splitter from "primevue/splitter";
import SplitterPanel from "primevue/splitterpanel";
import Toast from "primevue/toast";
import {
displayedRowKey,
routes,
selectedLanguageKey,
} from "@/arches-references/constants.ts";
import { dataIsList } from "@/arches-references/utils.ts";
Expand All @@ -21,11 +25,23 @@ import type { Ref } from "vue";
import type { Language } from "arches/arches/app/src/arches/types";
import type { Selectable } from "@/arches-references/types";
const splash = "splash";
const router = useRouter();
const displayedRow: Ref<Selectable | null> = ref(null);
function setDisplayedRow(val: Selectable | null) {
displayedRow.value = val;
function setDisplayedRow(row: Selectable | null) {
displayedRow.value = row;
if (row === null) {
router.push({ name: routes.splash });
return;
}
if (typeof row.id === "number") {
return;
}
if (dataIsList(row)) {
router.push({ name: routes.list, params: { id: row.id } });
} else {
router.push({ name: routes.item, params: { id: row.id } });
}
}
provide(displayedRowKey, { displayedRow, setDisplayedRow });
Expand All @@ -48,37 +64,64 @@ const panel = computed(() => {
</script>

<template>
<div class="list-editor-container">
<ListHeader />
<Splitter style="height: 100%">
<SplitterPanel
:size="34"
:min-size="25"
style="display: flex; flex-direction: column"
>
<Suspense>
<ListTree />
<template #fallback>
<ProgressSpinner />
</template>
</Suspense>
</SplitterPanel>
<SplitterPanel
:size="66"
:min-size="25"
:style="{
margin: '1rem 0rem 4rem 1rem',
overflowY: 'auto',
paddingRight: '4rem',
}"
>
<component
:is="panel"
:key="displayedRow?.id ?? splash"
/>
</SplitterPanel>
</Splitter>
<!-- Subtract size of arches toolbars -->
<div style="width: calc(100vw - 50px); height: calc(100vh - 50px)">
<div class="list-editor-container">
<ListHeader />
<Splitter style="height: 100%">
<SplitterPanel
:size="34"
:min-size="25"
style="display: flex; flex-direction: column"
>
<Suspense>
<ListTree />
<template #fallback>
<ProgressSpinner />
</template>
</Suspense>
</SplitterPanel>
<SplitterPanel
:size="66"
:min-size="25"
:style="{
margin: '1rem 0rem 4rem 1rem',
overflowY: 'auto',
paddingRight: '4rem',
}"
>
<component
:is="panel"
:key="displayedRow?.id ?? routes.splash"
/>
</SplitterPanel>
</Splitter>
</div>
</div>
<Toast />
<ConfirmDialog
:draggable="false"
:pt="{
root: {
style: {
fontSize: 'small',
},
},
header: {
style: {
background: 'var(--p-primary-950)',
color: 'white',
borderRadius: '1rem',
marginBottom: '1rem',
},
},
title: {
style: {
fontWeight: 800,
},
},
}"
/>
</template>

<style scoped>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useGettext } from "vue3-gettext";
import { useConfirm } from "primevue/useconfirm";
import { useToast } from "primevue/usetoast";
import Button from "primevue/button";
import ConfirmDialog from "primevue/confirmdialog";
import SplitButton from "primevue/splitbutton";
import {
Expand Down Expand Up @@ -53,9 +52,8 @@ const isMultiSelecting = defineModel<boolean>("isMultiSelecting", {
required: true,
});
const nextNewList = defineModel<NewControlledList>("nextNewList");
const newListFormValue = defineModel<string>("newListFormValue", {
required: true,
});
const { newListName } = defineProps<{ newListName: string }>();
// For new list entry (input textbox)
const newListCounter = ref(1);
Expand Down Expand Up @@ -102,15 +100,14 @@ const deleteSelectOptions = [
const createList = () => {
const newList: NewControlledList = {
id: newListCounter.value,
name: newListFormValue.value,
name: newListName,
dynamic: false,
search_only: false,
items: [],
nodes: [],
};
nextNewList.value = newList;
newListFormValue.value = "";
newListCounter.value += 1;
tree.value.push(listAsNode(newList, selectedLanguage.value));
Expand Down Expand Up @@ -259,29 +256,6 @@ await fetchListsAndPopulateTree();
:severity="shouldUseContrast() ? CONTRAST : PRIMARY"
@click="createList"
/>
<ConfirmDialog
:draggable="false"
:pt="{
root: {
style: {
fontSize: 'small',
},
},
header: {
style: {
background: 'var(--p-primary-950)',
color: 'white',
borderRadius: '1rem',
marginBottom: '1rem',
},
},
title: {
style: {
fontWeight: 800,
},
},
}"
/>
<SplitButton
class="list-button"
:label="$gettext('Delete')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const selectedLanguage = inject(selectedLanguageKey) as Ref<Language>;
const { setDisplayedRow } = inject(displayedRowKey) as DisplayedRowRefAndSetter;
const updateSelectedAndExpanded = (node: TreeNode) => {
if (isMultiSelecting.value || movingItem.value?.key) {
return;
}
setDisplayedRow(node.data);
expandedKeys.value = {
...expandedKeys.value,
Expand Down Expand Up @@ -170,14 +174,14 @@ const ptNodeContent = ({ instance }: TreePassThroughMethodOptions) => {
<template>
<ListTreeControls
:key="refetcher"
v-model="tree"
v-model:tree="tree"
v-model:rerender-tree="rerenderTree"
v-model:expanded-keys="expandedKeys"
v-model:selected-keys="selectedKeys"
v-model:moving-item="movingItem"
v-model:is-multi-selecting="isMultiSelecting"
v-model:nextNewList="nextNewList"
v-model:newListFormValue="newListFormValue"
:new-list-name="newListFormValue"
/>
<Tree
v-if="tree"
Expand Down
Loading

0 comments on commit 6c08f5e

Please sign in to comment.