diff --git a/app/controllers/avo/resource_overview_controller.rb b/app/controllers/avo/resource_overview_controller.rb new file mode 100644 index 0000000000..c27f8a29a0 --- /dev/null +++ b/app/controllers/avo/resource_overview_controller.rb @@ -0,0 +1,21 @@ +require_dependency 'avo/application_controller' + +module Avo + class ResourceOverviewController < ApplicationController + def index + resources = App.get_resources.map do |resource| + { + name: resource.name, + url: resource.url, + count: resource.model.count, + } + end + + render json: { + resources: resources, + hidden: Avo.configuration.hide_resource_overview_component, + hide_docs: Avo.configuration.hide_documentation_link, + } + end + end +end diff --git a/app/frontend/js/components/Index/ItemControls.vue b/app/frontend/js/components/Index/ItemControls.vue index d342fea5be..f574c321dd 100644 --- a/app/frontend/js/components/Index/ItemControls.vue +++ b/app/frontend/js/components/Index/ItemControls.vue @@ -12,7 +12,7 @@ viaResourceId: viaResourceId, } }" - v-tooltip="`View ${this.resourceNameSingular}`" + :title="`View ${this.resourceNameSingular}`" data-control="view" > @@ -29,14 +29,14 @@ viaResourceId: viaResourceId, }, }" - v-tooltip="`Edit ${this.resourceNameSingular}`" + :title="`Edit ${this.resourceNameSingular}`" data-control="edit" > @@ -44,7 +44,7 @@ diff --git a/app/frontend/js/components/LoadingOverlay.vue b/app/frontend/js/components/LoadingOverlay.vue index 5513c7d4fb..778dda6d0a 100644 --- a/app/frontend/js/components/LoadingOverlay.vue +++ b/app/frontend/js/components/LoadingOverlay.vue @@ -1,5 +1,5 @@ diff --git a/app/frontend/js/components/Pane.vue b/app/frontend/js/components/Pane.vue new file mode 100644 index 0000000000..1a9dfb423d --- /dev/null +++ b/app/frontend/js/components/Pane.vue @@ -0,0 +1,5 @@ + diff --git a/app/frontend/js/components/ResourceOverview.vue b/app/frontend/js/components/ResourceOverview.vue new file mode 100644 index 0000000000..ebee3d3d7a --- /dev/null +++ b/app/frontend/js/components/ResourceOverview.vue @@ -0,0 +1,88 @@ + + + diff --git a/app/frontend/js/components/index.js b/app/frontend/js/components/index.js index fba7177ee9..6a92bc41cb 100644 --- a/app/frontend/js/components/index.js +++ b/app/frontend/js/components/index.js @@ -91,6 +91,8 @@ Vue.component('item-controls', require('@/js/components/In Vue.component('view-header', require('@/js/components/ViewHeader.vue').default) Vue.component('view-footer', require('@/js/components/ViewFooter.vue').default) Vue.component('panel', require('@/js/components/Panel.vue').default) +Vue.component('pane', require('@/js/components/Pane.vue').default) +Vue.component('resource-overview', require('@/js/components/ResourceOverview.vue').default) Vue.component('heading', require('@/js/components/Heading.vue').default) Vue.component('a-button', require('@/js/components/Button.vue').default) Vue.component('resources-search', require('@/js/components/ResourcesSearch.vue').default) diff --git a/app/frontend/js/views/Dashboard.vue b/app/frontend/js/views/Dashboard.vue index 1dad42e1a4..f40f6f2da2 100644 --- a/app/frontend/js/views/Dashboard.vue +++ b/app/frontend/js/views/Dashboard.vue @@ -1,5 +1,8 @@ diff --git a/config/routes.rb b/config/routes.rb index 30e5b2b484..760f417fa4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,5 +14,9 @@ post '/avo-api/:resource_name/:id/attach/:attachment_name/:attachment_id', to: 'resources#attach' post '/avo-api/:resource_name/:id/detach/:attachment_name/:attachment_id', to: 'resources#detach' + # Tools + get '/avo-tools/resource-overview', to: 'resource_overview#index' + + # Catch them all get '/:view/(:tool)/(:resource_name)/(:option)', to: 'home#index' end diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index a1c15ce06c..2554b958bf 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -8,6 +8,8 @@ class Configuration attr_accessor :locale attr_accessor :currency attr_accessor :default_view_type + attr_accessor :hide_resource_overview_component + attr_accessor :hide_documentation_link def initialize @root_path = '/avo' @@ -18,6 +20,8 @@ def initialize @locale = 'us-US' @currency = 'USD' @default_view_type = :table + @hide_resource_overview_component = false + @hide_documentation_link = false end end diff --git a/lib/generators/avo/templates/resource.rb b/lib/generators/avo/templates/resource.rb index f780f0b322..1a7ed43a5c 100644 --- a/lib/generators/avo/templates/resource.rb +++ b/lib/generators/avo/templates/resource.rb @@ -7,7 +7,7 @@ def initialize end fields do - id :ID + id end end end diff --git a/spec/requests/avo/resource_overview_request_spec.rb b/spec/requests/avo/resource_overview_request_spec.rb new file mode 100644 index 0000000000..bc34310d1d --- /dev/null +++ b/spec/requests/avo/resource_overview_request_spec.rb @@ -0,0 +1,118 @@ +require 'rails_helper' + +RSpec.describe 'ResourceOverview', type: :request do + context 'configs' do + describe 'with false values' do + it 'returns false values' do + get '/avo/avo-tools/resource-overview' + + expect(response).to have_http_status(200) + + expect(parsed_response['hidden']).to be false + expect(parsed_response['hide_docs']).to be false + end + end + + describe 'with true values' do + around do |spec| + Avo.configuration.hide_resource_overview_component = true + Avo.configuration.hide_documentation_link = true + + spec.run + + Avo.configuration.hide_resource_overview_component = false + Avo.configuration.hide_documentation_link = false + end + + it 'returns true values' do + get '/avo/avo-tools/resource-overview' + + expect(response).to have_http_status(200) + + expect(parsed_response['hidden']).to be true + expect(parsed_response['hide_docs']).to be true + end + end + end + + describe 'without any resources in the DB' do + it 'returns empty response' do + get '/avo/avo-tools/resource-overview' + + expect(response).to have_http_status(200) + + expect(parsed_response['hidden']).to be false + expect(parsed_response['hide_docs']).to be false + expect(parsed_response['resources']).to match_array([ + { + count: 0, + name: 'Team', + url: 'teams', + }, + { + count: 0, + name: 'Project', + url: 'projects', + }, + { + count: 0, + name: 'Post', + url: 'posts', + }, + { + count: 0, + name: 'Team Membership', + url: 'team_memberships', + }, + { + count: 0, + name: 'User', + url: 'users', + }, + ].map(&:deep_stringify_keys)) + end + end + + describe 'with some resources in the DB' do + before do + create_list :user, 3 + create_list :team, 2 + end + + it 'returns non-empty response' do + get '/avo/avo-tools/resource-overview' + + expect(response).to have_http_status(200) + + expect(parsed_response['hidden']).to be false + expect(parsed_response['hide_docs']).to be false + expect(parsed_response['resources']).to match_array([ + { + count: 2, + name: 'Team', + url: 'teams', + }, + { + count: 0, + name: 'Project', + url: 'projects', + }, + { + count: 0, + name: 'Post', + url: 'posts', + }, + { + count: 0, + name: 'Team Membership', + url: 'team_memberships', + }, + { + count: 3, + name: 'User', + url: 'users', + }, + ].map(&:deep_stringify_keys)) + end + end +end