Skip to content

Commit

Permalink
feat: model query lab copilot engine
Browse files Browse the repository at this point in the history
  • Loading branch information
meta-d committed Feb 2, 2024
1 parent 2639be2 commit 244a0d1
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h3 class="mb-0 font-semibold">
<mat-icon ngmSuffix>translate</mat-icon>
</ngm-select>

<!-- not yet complete
@if (development) {
<ngm-select [label]="'PAC.MENU.GENERAL.THEME' | translate: { Default: 'Theme' }"
[placeholder]="'PAC.MENU.GENERAL.ThemePlaceholder' | translate: { Default: 'Select Theme' }"
[displayBehaviour]="DisplayBehaviour.descriptionOnly"
Expand All @@ -47,7 +47,8 @@ <h3 class="mb-0 font-semibold">
(ngModelChange)="onThemeSelect($event)"
>
<mat-icon ngmSuffix>dark_mode</mat-icon>
</ngm-select> -->
</ngm-select>
}

<button mat-button (click)="onProfile()">
<mat-icon>account_circle</mat-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { TranslateModule, TranslateService } from '@ngx-translate/core'
import { startWith } from 'rxjs'
import { LANGUAGES, LanguagesMap, Store } from '../../../@core'
import { UserPipe } from '../../../@shared'
import { environment } from 'apps/cloud/src/environments/environment'

@Component({
standalone: true,
Expand All @@ -35,12 +36,13 @@ import { UserPipe } from '../../../@shared'
export class HeaderSettingsComponent {
languages = LANGUAGES
DisplayBehaviour = DisplayBehaviour
development = !environment.production

readonly store = inject(Store)
readonly router = inject(Router)
readonly #translate = inject(TranslateService)

// preferredTheme$ = this.store.preferredTheme$
readonly preferredTheme$ = this.store.preferredTheme$

readonly user$ = toSignal(this.store.user$)
readonly isAuthenticated$ = computed(() => Boolean(this.store.user))
Expand Down
1 change: 1 addition & 0 deletions apps/cloud/src/app/features/features.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
thinkingAvatar="assets/images/copilot_sparkle_thinking.gif"
assistantAvatar="assets/images/copilot_sparkle_resting.gif"
[user]="user$()"
[copilotEngine]="copilotEngine"
cdkDropList
(cdkDropListDropped)="copilotChat.dropCopilot($event)"
(enableCopilot)="toEnableCopilot()"
Expand Down
111 changes: 52 additions & 59 deletions apps/cloud/src/app/features/features.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { Location } from '@angular/common'
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, OnInit, Renderer2, ViewChild, inject } from '@angular/core'
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
DestroyRef,
OnInit,
Renderer2,
ViewChild,
inject
} from '@angular/core'
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop'
import { MatDialog } from '@angular/material/dialog'
import { MatDrawerMode, MatSidenav } from '@angular/material/sidenav'
import {
Event,
NavigationCancel,
Expand All @@ -10,17 +21,20 @@ import {
Router,
RouterEvent
} from '@angular/router'
import { TranslateService } from '@ngx-translate/core'
import { PacMenuItem } from '@metad/cloud/auth'
import { UsersService } from '@metad/cloud/state'
import { isNotEmpty, nonNullable } from '@metad/core'
import { NgmCopilotChatComponent } from '@metad/ocap-angular/copilot'
import { TranslateService } from '@ngx-translate/core'
import { NGXLogger } from 'ngx-logger'
import { NgxPermissionsService, NgxRolesService } from 'ngx-permissions'
import { NgxPopperjsPlacements, NgxPopperjsTriggers } from 'ngx-popperjs'
import { combineLatestWith, firstValueFrom } from 'rxjs'
import { filter, map, startWith, tap } from 'rxjs/operators'
import { NgxPopperjsPlacements, NgxPopperjsTriggers } from 'ngx-popperjs'
import {
AbilityActions,
AnalyticsFeatures,
AnalyticsFeatures as AnalyticsFeaturesEnum,
AnalyticsPermissionsEnum,
EmployeesService,
FeatureEnum,
Expand All @@ -29,22 +43,16 @@ import {
IUser,
MenuCatalog,
PermissionsEnum,
routeAnimations,
RolesEnum,
SelectorService,
Store,
AnalyticsFeatures as AnalyticsFeaturesEnum,
AnalyticsFeatures,
RolesEnum
routeAnimations
} from '../@core'
import { StoryCreationComponent } from '../@shared'
import { AppService } from '../app.service'
import { QueryCreationDialogComponent } from './semantic-model/query-creation.component'
import { ModelCreationComponent } from './semantic-model/creation/creation.component'
import { StoryCreationComponent } from '../@shared'
import { MatDrawerMode, MatSidenav } from '@angular/material/sidenav'
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop'
import { CdkDragDrop } from '@angular/cdk/drag-drop'
import { NgmCopilotChatComponent } from '@metad/ocap-angular/copilot'

import { QueryCreationDialogComponent } from './semantic-model/query-creation.component'
import { CopilotEngine } from '@metad/copilot'

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
Expand All @@ -60,10 +68,11 @@ export class FeaturesComponent implements OnInit {
AbilityActions = AbilityActions

readonly #destroyRef = inject(DestroyRef)

@ViewChild('sidenav') sidenav: MatSidenav
@ViewChild('copilotChat') copilotChat!: NgmCopilotChatComponent

copilotEngine: CopilotEngine
sidenavMode = 'over' as MatDrawerMode
isEmployee: boolean
organization: IOrganization
Expand Down Expand Up @@ -97,10 +106,9 @@ export class FeaturesComponent implements OnInit {
filter(nonNullable),
combineLatestWith(this.translateService.stream('PAC.KEY_WORDS')),
map(([navigation, i18n]) => {

let catalogName: string
let icon: string
switch(navigation.catalog) {
switch (navigation.catalog) {
case MenuCatalog.Project:
catalogName = i18n?.['Project'] ?? 'Project'
icon = 'auto_stories'
Expand Down Expand Up @@ -160,10 +168,9 @@ export class FeaturesComponent implements OnInit {
this.checkForEmployee()
this.logger?.debug(value)
})

readonly user$ = toSignal(this.store.user$)

// private _sidebarContentIndexSub = this.appService.fullscreenIndex$.subscribe((fullscreenIndex) => this.zIndex = fullscreenIndex)

constructor(
public readonly appService: AppService,
private readonly employeeService: EmployeesService,
Expand Down Expand Up @@ -249,7 +256,7 @@ export class FeaturesComponent implements OnInit {
}

refreshMenuItem(item, withOrganizationShortcuts) {
item.title = this.getTranslation('PAC.MENU.'+item.data.translationKey, {Default: item.data.translationKey})
item.title = this.getTranslation('PAC.MENU.' + item.data.translationKey, { Default: item.data.translationKey })
if (item.data.permissionKeys || item.data.hide) {
const anyPermission = item.data.permissionKeys
? item.data.permissionKeys.reduce((permission, key) => {
Expand Down Expand Up @@ -330,19 +337,15 @@ export class FeaturesComponent implements OnInit {
// this.isCollapsedHidden = false
if (event.url.match(/^\/project/g)) {
this.appService.setCatalog({
catalog: MenuCatalog.Project,
catalog: MenuCatalog.Project
})
}
else
if (event.url.match(/^\/project/g)) {
} else if (event.url.match(/^\/project/g)) {
this.appService.setCatalog({
catalog: MenuCatalog.Stories,
catalog: MenuCatalog.Stories
})
}
else if (event.url.match(/^\/story/g)) {
} else if (event.url.match(/^\/story/g)) {
// this.isCollapsedHidden = true
}
else if (event.url.match(/^\/models/g)) {
} else if (event.url.match(/^\/models/g)) {
// this.appService.setCatalog({
// catalog: MenuCatalog.Models,
// id: !event.url.match(/^\/models$/g)
Expand All @@ -354,11 +357,11 @@ export class FeaturesComponent implements OnInit {
})
} else if (event.url.match(/^\/indicator-app/g)) {
this.appService.setCatalog({
catalog: MenuCatalog.IndicatorApp,
catalog: MenuCatalog.IndicatorApp
})
// this.isCollapsedHidden = true
} else {
this.appService.setCatalog({catalog: null})
this.appService.setCatalog({ catalog: null })
}
}

Expand All @@ -380,7 +383,7 @@ export class FeaturesComponent implements OnInit {
onMenuClicked(event, isMobile) {
this.isCollapsed = true
if (isMobile) {
this.isCollapsedHidden=true
this.isCollapsedHidden = true
}
}

Expand All @@ -407,7 +410,7 @@ export class FeaturesComponent implements OnInit {
link: '/home',
data: {
translationKey: 'Today',
featureKey: FeatureEnum.FEATURE_DASHBOARD,
featureKey: FeatureEnum.FEATURE_DASHBOARD
}
},
{
Expand All @@ -416,7 +419,7 @@ export class FeaturesComponent implements OnInit {
link: '/home/catalog',
data: {
translationKey: 'Catalog',
featureKey: FeatureEnum.FEATURE_DASHBOARD,
featureKey: FeatureEnum.FEATURE_DASHBOARD
}
},
{
Expand All @@ -425,7 +428,7 @@ export class FeaturesComponent implements OnInit {
link: '/home/trending',
data: {
translationKey: 'Trending',
featureKey: FeatureEnum.FEATURE_DASHBOARD,
featureKey: FeatureEnum.FEATURE_DASHBOARD
}
},
{
Expand All @@ -434,7 +437,7 @@ export class FeaturesComponent implements OnInit {
link: '/home/insight',
data: {
translationKey: 'Insights',
featureKey: AnalyticsFeatures.FEATURE_INSIGHT,
featureKey: AnalyticsFeatures.FEATURE_INSIGHT
}
}
]
Expand Down Expand Up @@ -470,7 +473,7 @@ export class FeaturesComponent implements OnInit {
translationKey: 'Story',
featureKey: AnalyticsFeatures.FEATURE_STORY,
permissionKeys: [AnalyticsPermissionsEnum.STORIES_VIEW]
},
}
},
{
title: 'Indicators',
Expand All @@ -480,7 +483,7 @@ export class FeaturesComponent implements OnInit {
translationKey: 'Indicators',
featureKey: AnalyticsFeatures.FEATURE_STORY,
permissionKeys: [AnalyticsPermissionsEnum.STORIES_VIEW]
},
}
}
]
},
Expand All @@ -501,7 +504,7 @@ export class FeaturesComponent implements OnInit {
link: '/indicator-app',
data: {
translationKey: 'Indicator App',
featureKey: AnalyticsFeaturesEnum.FEATURE_INDICATOR,
featureKey: AnalyticsFeaturesEnum.FEATURE_INDICATOR
}
},
// {
Expand Down Expand Up @@ -698,7 +701,7 @@ export class FeaturesComponent implements OnInit {
translationKey: 'Tenant',
permissionKeys: [RolesEnum.SUPER_ADMIN]
}
},
}
]
}
]
Expand All @@ -712,18 +715,21 @@ export class FeaturesComponent implements OnInit {
}

async createStory() {
const story = await firstValueFrom(this.dialog.open(StoryCreationComponent, {
data: {
}
}).afterClosed())
const story = await firstValueFrom(
this.dialog
.open(StoryCreationComponent, {
data: {}
})
.afterClosed()
)

if (story) {
this.router.navigate(['story', story.id, 'edit'])
}
}

async createModel() {
const model =await firstValueFrom(this.dialog.open(ModelCreationComponent, {data: {}}).afterClosed())
const model = await firstValueFrom(this.dialog.open(ModelCreationComponent, { data: {} }).afterClosed())
if (model) {
this.router.navigate(['models', model.id])
}
Expand All @@ -736,17 +742,4 @@ export class FeaturesComponent implements OnInit {
toEnableCopilot() {
this.router.navigate(['settings', 'copilot'])
}

/**
* Drop data on copilot chat:
* 1. table schema
* 2. table data
* 3. name of data
*
* @param event
*/
async dropCopilot(event: CdkDragDrop<any[], any[], any>) {
const data = event.item.data
console.log(event)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@

</mat-menu>

<popper-content #ask class="z-[101]">
<!-- <popper-content #ask class="z-[101]">
<div class="flex flex-col bg-white p-2" displayDensity="compact">
<ngm-input class="w-64" [placeholder]="'PAC.MODEL.QUERY.CopilotPlaceholder' | translate: {
Default: 'Ask a question or request, type CTRL + Enter to send'
Expand All @@ -290,4 +290,4 @@
</button>
</ngm-input>
</div>
</popper-content>
</popper-content> -->
Loading

0 comments on commit 244a0d1

Please sign in to comment.