Skip to content

Commit

Permalink
Re-organize view item routes
Browse files Browse the repository at this point in the history
big213 committed Apr 18, 2021
1 parent f76c92b commit 7a5e28e
Showing 25 changed files with 263 additions and 139 deletions.
10 changes: 0 additions & 10 deletions frontend/components/dialog/editRecordDialog.vue
Original file line number Diff line number Diff line change
@@ -44,8 +44,6 @@ import DeleteRecordInterface from '~/components/interface/crud/deleteRecordInter
import ShareRecordInterface from '~/components/interface/crud/shareRecordInterface.vue'
import RecordActionMenu from '~/components/menu/recordActionMenu.vue'
import { goToPage } from '~/services/base'
const modesMap = {
add: {
icon: 'mdi-plus',
@@ -157,14 +155,6 @@ export default {
this.overrideMode = mode
},
goToPage() {
goToPage(
this,
this.recordInfo.viewRecordRoute,
this.selectedItem,
...arguments
)
},
handleSubmit(data) {
this.close()
this.$emit('handleSubmit', data)
21 changes: 9 additions & 12 deletions frontend/components/interface/crud/shareRecordInterface.vue
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
</template>

<script>
import { copyToClipboard } from '~/services/base'
import { copyToClipboard, generateRecordRouteObject } from '~/services/base'
export default {
props: {
@@ -47,17 +47,14 @@ export default {
computed: {
shareUrl() {
return this.selectedItem &&
this.recordInfo.shareOptions &&
this.recordInfo.viewRecordRoute
? window.location.origin +
this.$router.resolve({
name: this.recordInfo.viewRecordRoute,
query: {
id: this.selectedItem.id,
expand: this.$route.query.expand ?? 0,
},
}).href
const routeObject = generateRecordRouteObject(
this.recordInfo.typename,
this.recordInfo.routeName,
this.selectedItem.id
)
return this.selectedItem && this.recordInfo.shareOptions && routeObject
? window.location.origin + this.$router.resolve(routeObject).href
: ''
},
itemIdentifier() {
17 changes: 15 additions & 2 deletions frontend/components/menu/recordActionMenu.vue
Original file line number Diff line number Diff line change
@@ -143,11 +143,24 @@ export default {
if (this.expandMode === 'emit')
this.$emit('handle-expand-click', expandTypeObject, index)
else
goToPage(this, this.recordInfo.viewRecordRoute, this.item, true, index)
goToPage(
this,
this.recordInfo.typename,
this.recordInfo.routeName,
this.item.id,
true,
index
)
},
goToPage() {
goToPage(this, this.recordInfo.viewRecordRoute, this.item, ...arguments)
goToPage(
this,
this.recordInfo.typename,
this.recordInfo.routeName,
this.item.id,
...arguments
)
},
},
}
2 changes: 1 addition & 1 deletion frontend/components/navigation/adminNavRoutes.vue
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ export default {
permissions: [],
items: Object.values(models).map((recordInfo) => ({
title: capitalizeString(recordInfo.pluralTypename),
to: '/admin?type=' + recordInfo.typename,
to: '/a/crud?type=' + recordInfo.typename,
})),
},
]
37 changes: 30 additions & 7 deletions frontend/components/page/viewRecordPage.vue
Original file line number Diff line number Diff line change
@@ -135,6 +135,8 @@ export default {
loading: {
loadRecord: false,
},
recordInfoChanged: false,
}
},
@@ -186,16 +188,27 @@ export default {
'$route.query.expand'(val) {
this.setExpandTypeObject(val)
},
recordInfo() {
this.recordInfoChanged = true
this.reset()
},
'$route.query.id'() {
// if this was triggered in addition to recordInfo change, do nothing and revert recordInfoChange on next tick
if (this.recordInfoChanged) {
this.$nextTick(() => {
this.recordInfoChanged = false
})
return
}
this.reset()
},
},
mounted() {
// must independently verify existence of item
this.loadRecord().then(() => {
// if expand query param set, set the initial expandTypeObject
if (this.$route.query.expand !== undefined) {
this.setExpandTypeObject(this.$route.query.expand)
}
})
this.reset()
},
methods: {
@@ -311,6 +324,16 @@ export default {
}
this.loading.loadRecord = false
},
reset() {
// must independently verify existence of item
this.loadRecord().then(() => {
// if expand query param set, set the initial expandTypeObject
if (this.$route.query.expand !== undefined) {
this.setExpandTypeObject(this.$route.query.expand)
}
})
},
},
head() {
2 changes: 1 addition & 1 deletion frontend/components/table/common/userColumn.vue
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ export default {
methods: {
openProfile() {
goToPage(this, 'user', this.currentValue, true)
goToPage(this, 'user', 'i-record', this.currentValue.id, true)
},
openWCAProfile(wcaId) {
11 changes: 6 additions & 5 deletions frontend/mixins/crud.js
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ import {
downloadCSV,
handleError,
serializeNestedProperty,
goToPage,
getPaginatorData,
collectPaginatorData,
} from '~/services/base'
@@ -304,6 +303,12 @@ export default {
},

created() {
this.$root.$on('refresh-crud-interface', () => {
this.reset({
resetExpanded: false,
})
})

this.reset({
resetSubscription: true,
initFilters: true,
@@ -327,10 +332,6 @@ export default {
this.updatePageOptions()
},

goToPage() {
goToPage(this, this.recordInfo.viewRecordRoute, ...arguments)
},

handleTableOptionsUpdated() {
this.$nextTick(() => {
switch (this.tableOptionsUpdatedTrigger) {
1 change: 1 addition & 0 deletions frontend/models/apiKey.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ export const ApiKey = <RecordInfo<'apiKey'>>{
name: 'API Key',
pluralName: 'API Keys',
icon: 'mdi-view-grid-plus',
routeName: 'a-view',
renderItem: (item) => item.name,
fields: {
id: {
1 change: 1 addition & 0 deletions frontend/models/event.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ export const Event = <RecordInfo<'event'>>{
name: 'Event',
pluralName: 'Events',
icon: 'mdi-view-grid',
routeName: 'a-view',
renderItem: (item) => item.name,
fields: {
id: {
1 change: 1 addition & 0 deletions frontend/models/personalBest.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ export const PersonalBest = <RecordInfo<'personalBest'>>{
name: 'Personal Best',
pluralName: 'Personal Bests',
icon: 'mdi-timer',
routeName: 'a-view',
renderItem: (item) => item.name,
requiredFields: ['event.id', 'pbClass.id', 'setSize', 'createdBy.id'],
fields: {
1 change: 1 addition & 0 deletions frontend/models/personalBestClass.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ export const PersonalBestClass = <RecordInfo<'personalBestClass'>>{
name: 'Personal Best Type',
pluralName: 'Personal Best Types',
icon: 'mdi-content-copy',
routeName: 'a-view',
renderItem: (item) => item.name,
fields: {
id: {
1 change: 1 addition & 0 deletions frontend/models/product.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ export const Product = <RecordInfo<'product'>>{
name: 'Product',
pluralName: 'Products',
icon: 'mdi-dots-grid',
routeName: 'a-view',
renderItem: (item) => item.name,
fields: {
id: {
1 change: 1 addition & 0 deletions frontend/models/special/myApiKeys.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import { ApiKey } from '..'

const MyApiKeys = <any>{
...ApiKey,
routeName: 'i-view',
}

export { MyApiKeys }
3 changes: 2 additions & 1 deletion frontend/models/special/myPbs.ts
Original file line number Diff line number Diff line change
@@ -2,11 +2,12 @@ import { PersonalBest } from '..'

const MyPbs = <any>{
...PersonalBest,
viewRecordRoute: 'pb',
routeName: 'i-view',
paginationOptions: {
...(!!PersonalBest.paginationOptions && PersonalBest.paginationOptions),
downloadOptions: undefined,
},
enterOptions: {},
}

MyPbs.expandTypes = [
86 changes: 84 additions & 2 deletions frontend/models/special/myProfile.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,90 @@
import { PublicUsers } from '.'
import { User } from '..'
import { PublicPbs } from './publicPbs'
import ViewPbCardInterface from '~/components/interface/viewPbCardInterface.vue'

export const MyProfile = {
...PublicUsers,
...User,
routeName: 'i-view',
editOptions: {
fields: ['isPublic'],
},
paginationOptions: {
...(!!User.paginationOptions && User.paginationOptions),
filters: [],
headers: [
{
field: 'name+avatar',
sortable: false,
},
{
field: 'wcaId',
width: '150px',
sortable: false,
},
{
field: 'country',
width: '100px',
sortable: false,
},
{
field: 'createdAt',
width: '150px',
sortable: true,
},
],
downloadOptions: undefined,
},
viewOptions: {
...(!!User.viewOptions && User.viewOptions),
fields: ['avatar', 'name', 'wcaId', 'country', 'currentUserFollowing'],
},
deleteOptions: undefined,

expandTypes: [
{
component: ViewPbCardInterface,
recordInfo: PublicPbs,
name: 'PB Card',
icon: 'mdi-card-text',
lockedFilters: (_that, item) => {
return [
{
field: 'createdBy.id',
operator: 'eq',
value: item.id,
},
{
field: 'createdBy.isPublic',
operator: 'eq',
value: true,
},
]
},
},
{
recordInfo: PublicPbs,
name: 'All PBs',
excludeFilters: ['createdBy.id', 'isCurrent'],
excludeHeaders: ['createdBy.name+createdBy.avatar+createdBy.id'],
lockedFilters: (_that, item) => {
return [
{
field: 'createdBy.id',
operator: 'eq',
value: item.id,
},
{
field: 'createdBy.isPublic',
operator: 'eq',
value: true,
},
{
field: 'isCurrent',
operator: 'eq',
value: true,
},
]
},
},
],
}
2 changes: 1 addition & 1 deletion frontend/models/special/publicPbs.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ const PublicPbs = <any>{
addOptions: undefined,
editOptions: undefined,
copyOptions: undefined,
expandTypes: undefined,
expandTypes: [],
}

PublicPbs.expandTypes = [
Loading

0 comments on commit 7a5e28e

Please sign in to comment.