diff --git a/api/src/database/migrations/20210525A-add-insights.ts b/api/src/database/migrations/20210525A-add-insights.ts index 0dd3f4ff84..a8efab41cf 100644 --- a/api/src/database/migrations/20210525A-add-insights.ts +++ b/api/src/database/migrations/20210525A-add-insights.ts @@ -5,6 +5,7 @@ export async function up(knex: Knex): Promise { table.uuid('id').primary(); table.string('name'); table.string('icon', 30); + table.text('note'); table.timestamp('date_created').defaultTo(knex.fn.now()); table.uuid('user_created').references('id').inTable('directus_users').onDelete('SET NULL'); }); @@ -28,6 +29,6 @@ export async function up(knex: Knex): Promise { } export async function down(knex: Knex): Promise { - await knex.schema.dropTable('directus_dashboards'); await knex.schema.dropTable('directus_panels'); + await knex.schema.dropTable('directus_dashboards'); } diff --git a/app/src/lang/translations/en-US.yaml b/app/src/lang/translations/en-US.yaml index a2b6127f77..0ac407fc76 100644 --- a/app/src/lang/translations/en-US.yaml +++ b/app/src/lang/translations/en-US.yaml @@ -540,6 +540,11 @@ toggle: Toggle icon_on: Icon On icon_off: Icon Off label: Label +insights: Insights +dashboard: Dashboard +panel: Panel +no_dashboards: No Dashboards +no_dashboards_copy: You don’t have any Dashboards yet. image_url: Image Url alt_text: Alternative Text media: Media diff --git a/app/src/modules/insights/index.ts b/app/src/modules/insights/index.ts new file mode 100644 index 0000000000..4c6c1849ba --- /dev/null +++ b/app/src/modules/insights/index.ts @@ -0,0 +1,34 @@ +import { defineModule } from '@/modules/define'; +import InsightsOverview from './routes/overview.vue'; +import InsightsDashboard from './routes/dashboard.vue'; + +export default defineModule({ + id: 'insights', + name: '$t:insights', + icon: 'dashboard', + routes: [ + { + name: 'insights-overview', + path: '/', + component: InsightsOverview, + }, + { + name: 'insights-dashboard', + path: '/:primaryKey', + component: InsightsDashboard, + props: true, + }, + ], + order: 30, + preRegisterCheck(user, permissions) { + const admin = user.role.admin_access; + + if (admin) return true; + + const permission = permissions.find( + (permission) => permission.collection === 'directus_dashboards' && permission.action === 'read' + ); + + return !!permission; + }, +}); diff --git a/app/src/modules/insights/routes/dashboard.vue b/app/src/modules/insights/routes/dashboard.vue new file mode 100644 index 0000000000..60c1540081 --- /dev/null +++ b/app/src/modules/insights/routes/dashboard.vue @@ -0,0 +1,5 @@ + diff --git a/app/src/modules/insights/routes/overview.vue b/app/src/modules/insights/routes/overview.vue new file mode 100644 index 0000000000..5efb53b210 --- /dev/null +++ b/app/src/modules/insights/routes/overview.vue @@ -0,0 +1,78 @@ + + + + + diff --git a/app/src/stores/insights.ts b/app/src/stores/insights.ts index 7535d4412b..22a5000646 100644 --- a/app/src/stores/insights.ts +++ b/app/src/stores/insights.ts @@ -9,7 +9,10 @@ export const useInsightsStore = createStore({ }), actions: { async hydrate() { - const response = await api.get('/dashboards', { params: { limit: -1, fields: ['*', 'panels.*'] } }); + const response = await api.get('/dashboards', { + params: { limit: -1, fields: ['*', 'panels.*'], sort: ['name'] }, + }); + this.state.dashboards = response.data.data; }, dehydrate() { diff --git a/app/src/stores/permissions.ts b/app/src/stores/permissions.ts index f528c6d33b..59690d18c7 100644 --- a/app/src/stores/permissions.ts +++ b/app/src/stores/permissions.ts @@ -47,5 +47,10 @@ export const usePermissionsStore = createStore({ ) || null ); }, + hasPermission(collection: string, action: Permission['action']) { + const userStore = useUserStore(); + if (userStore.state.currentUser?.role?.admin_access === true) return true; + return !!this.getPermissionsForUser(collection, action); + }, }, });