Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

List Component: Adds the ability to navigate on row click #170

Merged
merged 3 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions demo/components/magazines/CreateMagazines.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-card>
<v-img
src="banner.png"
aspect-ratio="4"
/>
<v-img src="banner.png" aspect-ratio="4" />
<v-card-title primary-title>
<h3 class="headline mb-2">New Magazine</h3>
</v-card-title>
Expand Down
5 changes: 1 addition & 4 deletions demo/components/magazines/ShowMagazines.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
<v-layout>
<v-flex xs12 sm6 offset-sm3>
<v-card>
<v-img
src="banner.png"
aspect-ratio="4"
/>
<v-img src="banner.png" aspect-ratio="4" />
<v-card-title primary-title>
<h3 class="headline mb-2">Magazine</h3>
</v-card-title>
Expand Down
65 changes: 31 additions & 34 deletions demo/va-auth-adapter/axios.adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@ export default (client, options = {}) => {
AUTH_CHECK_REQUEST,
} = AuthActionTypes

const {
authFields,
authUrl,
storageKey,
userField,
} = Object.assign({
authFields: { username: 'username', password: 'password' },
storageKey: 'token',
userField: 'user',
}, options);
const { authFields, authUrl, storageKey, userField } = Object.assign(
{
authFields: { username: 'username', password: 'password' },
storageKey: 'token',
userField: 'user',
},
options
)

switch (type) {
case AUTH_LOGIN_REQUEST:
return new Promise((resolve, reject) => {
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
[authFields.username]: params.username,
[authFields.password]: params.password
[authFields.password]: params.password,
}
const method = 'post'
const url = authUrl
Expand Down Expand Up @@ -53,31 +51,30 @@ export default (client, options = {}) => {
})

case AUTH_CHECK_REQUEST:
return new Promise((resolve, reject) => {
const token = localStorage.getItem(storageKey)
if (token) {
const url = authUrl
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
token,
return new Promise((resolve, reject) => {
const token = localStorage.getItem(storageKey)
if (token) {
const url = authUrl
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
token,
}
const method = 'get'
client({ url, headers, method })
.then(response => {
const { data } = response
const { [userField]: user } = data
resolve(user)
})
.catch(error => {
reject(error)
})
} else {
reject('Authentication failed.')
}
const method = 'get'
client({ url, headers, method })
.then(response => {
const { data } = response
const { [userField]: user } = data
resolve(user)
})
.catch(error => {
reject(error)
})
} else {
reject('Authentication failed.')
}
})

})
default:
return Promise.reject(`Unsupported @va-auth action type: ${type}`);
return Promise.reject(`Unsupported @va-auth action type: ${type}`)
}
}
}
37 changes: 15 additions & 22 deletions src/components/Actions/List/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,24 @@
v-for="(item, index) in items"
:key="keys.containerFields(item[resourceIdName])"
:name="names.containerFields(index)"
@click="onRowClicked(item[resourceIdName])"
>
<td
class="text-xs-left"
v-for="field in fields"
:key="keys.elementField(label(field), index)"
:name="names.elementField(label(field), index)"
>
<a
:name="names.elementField(resourceIdName, index)"
v-if="label(field) === resourceIdName && hasShow"
@click="onIdClick(item[resourceIdName])"
>
<component
:name="names.elementField(label(field))"
:is="type(field)"
v-bind:value="item[label(field)]"
v-bind="args(field)"
/>
</a>
<span v-else>
<component
:name="names.elementField(label(field), index)"
:is="type(field)"
v-bind:value="item[label(field)]"
v-bind="args(field)"
/>
</span>
<component
:name="
label(field) === resourceIdName
? names.elementField(label(field))
: names.elementField(label(field), index)
"
:is="type(field)"
v-bind:value="item[label(field)]"
v-bind="args(field)"
/>
</td>
<td>
<EditButton
Expand Down Expand Up @@ -256,8 +247,10 @@ export default {
onCreateClick() {
this.$router.push({ name: `${this.resourceName}/create` })
},
onIdClick(id) {
this.$router.push({ name: `${this.resourceName}/show`, params: { id } })
onRowClicked(id) {
if (this.hasShow) {
this.$router.push({ name: `${this.resourceName}/show`, params: { id } })
}
},
},
created() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/UiComponents/DeleteButton/DeleteButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<v-btn
v-bind="buttonProps"
:name="names.deleteButton"
@click="onDelete()"
@click.stop="onDelete()"
icon
v-on="on"
>
Expand Down
8 changes: 7 additions & 1 deletion src/components/UiComponents/EditButton/EditButton.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<template>
<v-tooltip bottom>
<template v-slot:activator="{ on }">
<v-btn v-bind="buttonProps" :name="name" @click="onEdit()" icon v-on="on">
<v-btn
v-bind="buttonProps"
:name="name"
@click.stop="onEdit()"
icon
v-on="on"
>
<v-icon v-bind="iconProps">{{
UI_CONTENT.RESOURCE_EDIT_BUTTON
}}</v-icon>
Expand Down