Skip to content

Commit

Permalink
fix: loaders are not visible on some pages (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev authored Nov 25, 2020
1 parent 5a85e7c commit 4086d43
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 28 deletions.
5 changes: 2 additions & 3 deletions app/frontend/js/components/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
:href="realHref"
@click="$emit('click')"
>
<div class="text-center w-full" v-if="fullWidth">
<span class="text-center w-full" v-if="fullWidth">
<slot />
</div>
</span>
<slot v-else />
</button>
</template>

<script>
export default {
data: () => ({}),
props: [
'to',
'exact',
Expand Down
12 changes: 4 additions & 8 deletions app/frontend/js/components/Index/ResourceFilters.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="relative w-full flex justify-between z-30" v-if="hasFilters">
<div class="relative w-full flex justify-between z-30">
<a-button color="gray" class="focus:outline-none" @click="togglePanel">
<filter-icon class="h-4 mr-2" data-button="resource-filters" /> {{ $t('avo.filters') }}
</a-button>
Expand Down Expand Up @@ -34,14 +34,13 @@
></component>
</template>
<div class="p-4 border-gray-300 border-t">
<a-button color="gray"
<a-button
color="gray"
class="w-full"
:disabled="resetDisabled"
@click="resetFilters"
v-text="'Reset filters'"
/>
>Reset filters</a-button>
</div>

</div>
</div>
</template>
Expand All @@ -66,9 +65,6 @@ export default {
perPageSteps: {},
},
computed: {
hasFilters() {
return this.filters.length > 0
},
resetDisabled() {
if (this.$route.query.filters === undefined) return true
Expand Down
6 changes: 6 additions & 0 deletions app/frontend/js/mixins/loads-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Bus from '@/js/Bus'
import Resource from '@/js/models/Resource'
import hasLoadingBus from '@/js/mixins/has-loading-bus'
import pluralize from 'pluralize'
import replace from 'lodash/replace'

export default {
mixins: [hasLoadingBus],
Expand All @@ -22,6 +23,11 @@ export default {

return `${Avo.rootPath}/avo-api/${this.resourceName}/new`
},
resourceNameFromURL() {
if (!this.resource) return replace(pluralize(this.resourceName, 1), '_', ' ')

return this.resource.singular_name
},
},
methods: {
hydrateRelatedResources(resource) {
Expand Down
16 changes: 12 additions & 4 deletions app/frontend/js/views/ResourceEdit.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<div v-if="resource" :resource-id="resourceId">
<div v-for="panel in resource.panels" :key="panel.name">
<div :resource-id="resourceId">
<div v-for="panel in panels" :key="panel.name">
<panel>
<template #heading>
{{ $t('avo.edit_item', { item: resourceNameSingular.toLowerCase() }) | upperFirst() }}
{{panel.name}}
</template>

<template #tools>
Expand Down Expand Up @@ -48,6 +48,7 @@ import HasForms from '@/js/mixins/has-forms'
import HasUniqueKey from '@/js/mixins/has-unique-key'
import LoadsResource from '@/js/mixins/loads-resource'
import hasUpperFirstFilter from '@/js/mixins/has-upper-first-filter'
import upperFirst from 'lodash/upperFirst'
export default {
mixins: [HasForms, LoadsResource, DealsWithResourceLabels, HasUniqueKey, hasUpperFirstFilter],
Expand All @@ -62,12 +63,17 @@ export default {
'viaResourceId',
],
computed: {
panels() {
if (!this.resource) return [{ name: upperFirst(this.$t('avo.edit_item', { item: this.resourceNameFromURL })) }]
return this.resource.panels
},
cancelActionParams() {
const action = {
name: 'show',
params: {
resourceName: this.resourceName,
resourceId: this.resource.id,
resourceId: this.resourceId,
},
}
Expand All @@ -79,6 +85,8 @@ export default {
return action
},
canUpdate() {
if (!this.resource) return false
return this.resource.authorization.update
},
},
Expand Down
4 changes: 1 addition & 3 deletions app/frontend/js/views/ResourceIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
:resource-name="resourceName"
:via-resource-name="viaResourceName"
:via-resource-id="viaResourceId"
v-if="resources.length > 0"
/>
</div>
<div class="flex justify-end items-center px-6 space-x-3">
Expand Down Expand Up @@ -83,8 +82,7 @@
<loading-overlay class="relative" v-if="viewType === '' && isLoading"/>

<div class="w-full overflow-auto min-h-28 flex flex-col" v-if="viewType === 'table'">
<loading-overlay class="relative" v-if="resources.length === 0 && isLoading"/>
<div class="relative flex-1 flex" v-else>
<div class="relative flex-1 flex">
<loading-overlay v-if="isLoading" />

<resource-table
Expand Down
21 changes: 16 additions & 5 deletions app/frontend/js/views/ResourceNew.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<div v-if="resource">
<div v-for="panel in resource.panels" :key="panel.name">
<div>
<div v-for="panel in panels" :key="panel.name">
<panel>
<template #heading>
{{ $t('avo.create_new_item', { item: resourceNameSingular.toLowerCase() }) | upperFirst() }}
{{panel.name}}
</template>

<template #tools>
Expand All @@ -14,7 +14,11 @@
resourceName: resourceName,
},
}"><arrow-left-icon class="h-4 mr-1"/> {{ $t('avo.cancel') }}</a-button>
<a-button color="green" @click="submitResource"><save-icon class="h-4 mr-1"/> {{ $t('avo.save') }}</a-button>
<a-button
color="green"
@click="submitResource"
v-if="resource"
><save-icon class="h-4 mr-1"/> {{ $t('avo.save') }}</a-button>
</div>
</template>

Expand Down Expand Up @@ -55,13 +59,20 @@ import LoadsResource from '@/js/mixins/loads-resource'
export default {
mixins: [HasForms, LoadsResource, DealsWithResourceLabels, HasUniqueKey],
data: () => ({
resource: {},
resource: null,
form: {},
}),
props: [
'resourceName',
'viaResourceName',
'viaResourceId',
],
computed: {
panels() {
if (!this.resource) return [{ name: (this.$t('avo.create_new_item', { item: this.resourceNameFromURL })) }]
return this.resource.panels
},
},
}
</script>
11 changes: 9 additions & 2 deletions app/frontend/js/views/ResourceShow.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-if="resource" :resource-id="resourceId">
<div :resource-id="resourceId">
<div v-for="panel in panels" :key="panel.name">
<panel>
<template #heading>
Expand Down Expand Up @@ -75,6 +75,7 @@ import HasUpperFirstFilter from '@/js/mixins/has-upper-first-filter'
import LoadsActions from '@/js/mixins/loads-actions'
import LoadsResource from '@/js/mixins/loads-resource'
import Modal from '@/js/components/Modal.vue'
import upperFirst from 'lodash/upperFirst'
export default {
name: 'ResourceShow',
Expand Down Expand Up @@ -107,20 +108,26 @@ export default {
return action
},
fields() {
if (!this.resource) return []
return this.resource.fields
},
panels() {
if (!this.resource) return []
if (!this.resource) return [{ name: this.$t('avo.resource_details', { name: upperFirst(this.resourceNameFromURL) }) }]
return this.resource.panels
},
hasManyRelations() {
return this.fields.filter((field) => ['has_and_belongs_to_many', 'has_many'].indexOf(field.relationship) > -1)
},
canEdit() {
if (!this.resource) return false
return this.resource.authorization.edit
},
canDelete() {
if (!this.resource) return false
return this.resource.authorization.destroy
},
},
Expand Down
13 changes: 10 additions & 3 deletions lib/avo/app/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ class Resource

class << self
def hydrate_resource(model:, resource:, view: :index, user:)
default_panel_name = I18n.t 'avo.resource_details', name: resource.name
case view
when :show
panel_name = I18n.t 'avo.resource_details', name: resource.name.downcase.upcase_first
when :edit
panel_name = I18n.t('avo.edit_item', item: resource.name.downcase).upcase_first
when :create
panel_name = I18n.t('avo.create_new_item', item: resource.name.downcase).upcase_first
end

resource_with_fields = {
id: model.id,
Expand All @@ -26,7 +33,7 @@ def hydrate_resource(model:, resource:, view: :index, user:)
fields: [],
grid_fields: {},
panels: [{
name: default_panel_name,
name: panel_name,
component: 'panel',
}]
}
Expand All @@ -46,7 +53,7 @@ def hydrate_resource(model:, resource:, view: :index, user:)

next if furnished_field.blank?

furnished_field[:panel_name] = default_panel_name
furnished_field[:panel_name] = panel_name
furnished_field[:show_on_show] = field.show_on_show

if field.has_own_panel?
Expand Down

0 comments on commit 4086d43

Please sign in to comment.