-
-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/AvocadoHQ/avocado
- Loading branch information
Showing
11 changed files
with
254 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<template> | ||
<div class="absolute flex items-center justify-center h-full w-full bg-white bg-opacity-75 z-20"> | ||
<div class="absolute flex items-center justify-center h-full w-full bg-white bg-opacity-75 z-20 rounded-xl"> | ||
<loading-component class="bg-white rounded bg-opacity-75"/> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<div class="relative bg-white rounded-xl shadow-xl mb-8"> | ||
<slot /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<template> | ||
<div v-if="!hidden"> | ||
<div v-if="noResources"> | ||
<pane class="p-6"> | ||
<heading class="mb-4"> | ||
Welcome to Avo 🥑 | ||
</heading> | ||
|
||
<p class="mb-2"> | ||
You haven't generated any Resources. <strong>Resources</strong> are the backbone of Avo. | ||
</p> | ||
|
||
<p class="mb-2"> | ||
To generate a resource run this command. | ||
</p> | ||
|
||
<div class="mb-2 mt-4"> | ||
<code class="block bg-gray-200 px-3 py-2 rounded text-gray-800">bin/rails generate avo:resource Post</code> | ||
</div> | ||
</pane> | ||
</div> | ||
<div v-else> | ||
<div class="mb-4 text-lg font-bold"> | ||
Current resources | ||
</div> | ||
<div class="grid grid-cols-3 col-gap-6"> | ||
<div v-for="resource in resources" :key="resource.name"> | ||
<pane class="p-6"> | ||
<div class="font-semibold leading-tight mb-2 text-lg"> | ||
{{resource.count}} {{resource.name | pluralize(resource.count) | capitalize()}} | ||
</div> | ||
<div class="flex justify-end"> | ||
<router-link :to="{ | ||
name: 'index', | ||
params: { | ||
resourceName: resource.url, | ||
}, | ||
}" | ||
>view all</router-link> | ||
</div> | ||
</pane> | ||
</div> | ||
</div> | ||
</div> | ||
<pane class="p-6" v-if="!hideDocs"> | ||
Read the <a href="https://docs.avohq.io" target="_blank">docs</a> for options on how to customize resources. | ||
</pane> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import Api from '@/js/Api' | ||
import Avo from '@/js/Avo' | ||
import pluralize from 'pluralize' | ||
export default { | ||
data: () => ({ | ||
resources: [], | ||
hidden: true, | ||
hideDocs: false, | ||
}), | ||
props: [], | ||
filters: { | ||
pluralize(value, count) { | ||
return pluralize(value, count) | ||
}, | ||
capitalize(value) { | ||
return value.charAt(0).toUpperCase() + value.slice(1) | ||
}, | ||
}, | ||
computed: { | ||
noResources() { | ||
return this.resources.length === 0 | ||
}, | ||
}, | ||
methods: { | ||
async getResources() { | ||
const { data } = await Api.get(`${Avo.rootPath}/avo-tools/resource-overview`) | ||
this.resources = data.resources | ||
this.hidden = data.hidden | ||
this.hideDocs = data.hide_docs | ||
}, | ||
}, | ||
async mounted() { | ||
await this.getResources() | ||
}, | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
<template> | ||
<heading> | ||
Dashboard | ||
</heading> | ||
<div> | ||
<heading class="pt-4 mb-8"> | ||
Dashboard | ||
</heading> | ||
<resource-overview /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ def initialize | |
end | ||
|
||
fields do | ||
id :ID | ||
id | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |