Skip to content

Commit

Permalink
update for nova 3
Browse files Browse the repository at this point in the history
  • Loading branch information
vasishakd committed Aug 25, 2020
1 parent 459a939 commit c22ecc5
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 254 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

You can install the package via composer:

For laravel/nova version 2.10.0+:

`composer require flagstudio/nova-actions-left:^0.2.0`
`composer require flagstudio/nova-actions-left`

For laravel/nova version below 2.10.0:

Expand Down
270 changes: 137 additions & 133 deletions resources/js/components/ResourceTable.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<template>
<table
v-if="resources.length > 0"
class="table w-full"
cellpadding="0"
cellspacing="0"
data-testid="resource-table"
v-if="resources.length > 0"
class="table w-full"
:class="[
`table-${resourceInformation.tableStyle}`,
resourceInformation.showColumnBorders ? 'table-grid' : '',
]"
cellpadding="0"
cellspacing="0"
data-testid="resource-table"
>
<thead>
<tr>
Expand All @@ -19,11 +23,11 @@
<!-- Field Names -->
<th v-for="field in fields" :class="`text-${field.textAlign}`">
<sortable-icon
@sort="requestOrderByChange(field)"
@reset="resetOrderBy(field)"
:resource-name="resourceName"
:uri-key="field.sortableUriKey"
v-if="field.sortable"
@sort="requestOrderByChange(field)"
@reset="resetOrderBy(field)"
:resource-name="resourceName"
:uri-key="field.sortableUriKey"
v-if="field.sortable"
>
{{ field.indexName }}
</sortable-icon>
Expand All @@ -35,145 +39,145 @@
</thead>
<tbody>
<tr
v-for="(resource, index) in resources"
@actionExecuted="$emit('actionExecuted')"
:testId="`${resourceName}-items-${index}`"
:key="resource.id.value"
:delete-resource="deleteResource"
:restore-resource="restoreResource"
is="resource-table-row"
:resource="resource"
:resource-name="resourceName"
:relationship-type="relationshipType"
:via-relationship="viaRelationship"
:via-resource="viaResource"
:via-resource-id="viaResourceId"
:via-many-to-many="viaManyToMany"
:checked="selectedResources.indexOf(resource) > -1"
:actions-are-available="actionsAreAvailable"
:should-show-checkboxes="shouldShowCheckboxes"
:update-selection-status="updateSelectionStatus"
v-for="(resource, index) in resources"
@actionExecuted="$emit('actionExecuted')"
:testId="`${resourceName}-items-${index}`"
:key="resource.id.value"
:delete-resource="deleteResource"
:restore-resource="restoreResource"
is="resource-table-row"
:resource="resource"
:resource-name="resourceName"
:relationship-type="relationshipType"
:via-relationship="viaRelationship"
:via-resource="viaResource"
:via-resource-id="viaResourceId"
:via-many-to-many="viaManyToMany"
:checked="selectedResources.indexOf(resource) > -1"
:actions-are-available="actionsAreAvailable"
:should-show-checkboxes="shouldShowCheckboxes"
:update-selection-status="updateSelectionStatus"
/>
</tbody>
</table>
</template>

<script>
import { InteractsWithResourceInformation } from 'laravel-nova'
import { InteractsWithResourceInformation } from 'laravel-nova'
export default {
mixins: [InteractsWithResourceInformation],
export default {
mixins: [InteractsWithResourceInformation],
props: {
authorizedToRelate: {
type: Boolean,
required: true,
},
resourceName: {
default: null,
},
resources: {
default: [],
},
singularName: {
type: String,
required: true,
},
selectedResources: {
default: [],
},
selectedResourceIds: {},
shouldShowCheckboxes: {
type: Boolean,
default: false,
},
actionsAreAvailable: {
type: Boolean,
default: false,
},
viaResource: {
default: null,
},
viaResourceId: {
default: null,
},
viaRelationship: {
default: null,
},
relationshipType: {
default: null,
},
updateSelectionStatus: {
type: Function,
},
props: {
authorizedToRelate: {
type: Boolean,
required: true,
},
resourceName: {
default: null,
},
resources: {
default: [],
},
singularName: {
type: String,
required: true,
},
selectedResources: {
default: [],
},
selectedResourceIds: {},
shouldShowCheckboxes: {
type: Boolean,
default: false,
},
actionsAreAvailable: {
type: Boolean,
default: false,
},
viaResource: {
default: null,
},
viaResourceId: {
default: null,
},
viaRelationship: {
default: null,
},
relationshipType: {
default: null,
},
updateSelectionStatus: {
type: Function,
},
},
data: () => ({
selectAllResources: false,
selectAllMatching: false,
resourceCount: null,
}),
data: () => ({
selectAllResources: false,
selectAllMatching: false,
resourceCount: null,
}),
methods: {
/**
* Delete the given resource.
*/
deleteResource(resource) {
this.$emit('delete', [resource])
Nova.$emit('metric-refresh')
},
methods: {
/**
* Delete the given resource.
*/
deleteResource(resource) {
this.$emit('delete', [resource])
Nova.$emit('metric-refresh')
},
/**
* Restore the given resource.
*/
restoreResource(resource) {
this.$emit('restore', [resource])
Nova.$emit('metric-refresh')
},
/**
* Restore the given resource.
*/
restoreResource(resource) {
this.$emit('restore', [resource])
Nova.$emit('metric-refresh')
},
/**
* Broadcast that the ordering should be updated.
*/
requestOrderByChange(field) {
this.$emit('order', field)
},
/**
* Broadcast that the ordering should be updated.
*/
requestOrderByChange(field) {
this.$emit('order', field)
},
/**
* Broadcast that the ordering should be reset.
*/
resetOrderBy(field) {
this.$emit('reset-order-by', field)
},
/**
* Broadcast that the ordering should be reset.
*/
resetOrderBy(field) {
this.$emit('reset-order-by', field)
},
},
computed: {
/**
* Get all of the available fields for the resources.
*/
fields() {
if (this.resources) {
return this.resources[0].fields
}
},
computed: {
/**
* Get all of the available fields for the resources.
*/
fields() {
if (this.resources) {
return this.resources[0].fields
}
},
/**
* Determine if the current resource listing is via a many-to-many relationship.
*/
viaManyToMany() {
return (
this.relationshipType == 'belongsToMany' ||
this.relationshipType == 'morphToMany'
)
},
/**
* Determine if the current resource listing is via a many-to-many relationship.
*/
viaManyToMany() {
return (
this.relationshipType == 'belongsToMany' ||
this.relationshipType == 'morphToMany'
)
},
/**
* Determine if the current resource listing is via a has-one relationship.
*/
viaHasOne() {
return (
this.relationshipType == 'hasOne' || this.relationshipType == 'morphOne'
)
},
},
}
/**
* Determine if the current resource listing is via a has-one relationship.
*/
viaHasOne() {
return (
this.relationshipType == 'hasOne' || this.relationshipType == 'morphOne'
)
},
},
}
</script>
Loading

0 comments on commit c22ecc5

Please sign in to comment.