From f4646afbe2c435d231840effb88ad7b7050cf012 Mon Sep 17 00:00:00 2001 From: meta-d Date: Thu, 5 Dec 2024 00:32:26 +0800 Subject: [PATCH 01/11] feat: workspace general settings --- .../@core/services/xpert-workspace.service.ts | 14 ++- .../xpert/workspace/home/home.component.ts | 14 ++- .../settings/general/general.component.html | 64 ++++++++++++ .../settings/general/general.component.scss | 3 + .../settings/general/general.component.ts | 98 +++++++++++++++++++ .../members/members.component.html | 3 +- .../members/members.component.scss | 0 .../members/members.component.ts | 2 +- .../models/models.component.html | 0 .../models/models.component.scss | 0 .../{ => settings}/models/models.component.ts | 0 .../settings/settings.component.html | 21 +++- .../workspace/settings/settings.component.ts | 23 +++-- .../workspace/welcome/welcome.component.ts | 6 +- apps/cloud/src/assets/i18n/zh-Hans.json | 15 ++- apps/cloud/src/styles/components/button.scss | 2 +- .../xpert-workspace/workspace.controller.ts | 16 ++- .../src/xpert-workspace/workspace.service.ts | 26 +++-- .../server-ai/src/xpert/dto/xpert-dsl.dto.ts | 69 +++++++++++++ 19 files changed, 347 insertions(+), 29 deletions(-) create mode 100644 apps/cloud/src/app/features/xpert/workspace/settings/general/general.component.html create mode 100644 apps/cloud/src/app/features/xpert/workspace/settings/general/general.component.scss create mode 100644 apps/cloud/src/app/features/xpert/workspace/settings/general/general.component.ts rename apps/cloud/src/app/features/xpert/workspace/{ => settings}/members/members.component.html (96%) rename apps/cloud/src/app/features/xpert/workspace/{ => settings}/members/members.component.scss (100%) rename apps/cloud/src/app/features/xpert/workspace/{ => settings}/members/members.component.ts (97%) rename apps/cloud/src/app/features/xpert/workspace/{ => settings}/models/models.component.html (100%) rename apps/cloud/src/app/features/xpert/workspace/{ => settings}/models/models.component.scss (100%) rename apps/cloud/src/app/features/xpert/workspace/{ => settings}/models/models.component.ts (100%) diff --git a/apps/cloud/src/app/@core/services/xpert-workspace.service.ts b/apps/cloud/src/app/@core/services/xpert-workspace.service.ts index db5b08dc7..b4339eb65 100644 --- a/apps/cloud/src/app/@core/services/xpert-workspace.service.ts +++ b/apps/cloud/src/app/@core/services/xpert-workspace.service.ts @@ -15,10 +15,14 @@ export class XpertWorkspaceService extends OrganizationBaseCrudService) { return this.selectOrganizationId().pipe( switchMap(() => - this.#refresh.pipe(switchMap(() => this.httpClient.get<{ items: IXpertWorkspace[] }>(this.apiBaseUrl + `/my`))) + this.#refresh.pipe( + switchMap(() => + this.httpClient.get<{ items: IXpertWorkspace[] }>(this.apiBaseUrl + `/my`, { params: toHttpParams(params) }) + ) + ) ) ) } @@ -31,6 +35,10 @@ export class XpertWorkspaceService extends OrganizationBaseCrudService(this.apiBaseUrl + `/${id}/members`, members) } + archive(id: string) { + return this.httpClient.post(this.apiBaseUrl + `/${id}/archive`, {}) + } + refresh() { this.#refresh.next() } @@ -50,4 +58,4 @@ export class XpertWorkspaceBaseCrudService extends OrganizationBaseCrudServic export function injectWorkspaceService() { return inject(XpertWorkspaceService) -} \ No newline at end of file +} diff --git a/apps/cloud/src/app/features/xpert/workspace/home/home.component.ts b/apps/cloud/src/app/features/xpert/workspace/home/home.component.ts index 99fc27133..7bb0aeb02 100644 --- a/apps/cloud/src/app/features/xpert/workspace/home/home.component.ts +++ b/apps/cloud/src/app/features/xpert/workspace/home/home.component.ts @@ -33,6 +33,7 @@ import { injectTags, injectUser, ITag, + OrderTypeEnum, routeAnimations, TagCategoryEnum, ToastrService, @@ -99,7 +100,11 @@ export class XpertWorkspaceHomeComponent { readonly isMobile = this.appService.isMobile readonly lang = this.appService.lang - readonly workspaces = toSignal(this.workspaceService.getAllMy().pipe(map(({ items }) => items)), {initialValue: null}) + readonly workspaces = toSignal( + this.workspaceService.getAllMy({ order: { updatedAt: OrderTypeEnum.DESC } }) + .pipe(map(({ items }) => items)), + {initialValue: null} + ) readonly selectedWorkspaces = model([]) readonly workspace = computed(() => this.workspaces()?.find((_) => _.id === this.selectedWorkspaces()[0]), { equal: (a, b) => a?.id === b?.id @@ -187,6 +192,11 @@ export class XpertWorkspaceHomeComponent { } }) .afterClosed() - .subscribe() + .subscribe((event) => { + if (event === 'deleted' || event === 'archived') { + this.workspaceService.refresh() + this.router.navigate(['/xpert/w']) + } + }) } } diff --git a/apps/cloud/src/app/features/xpert/workspace/settings/general/general.component.html b/apps/cloud/src/app/features/xpert/workspace/settings/general/general.component.html new file mode 100644 index 000000000..e46257669 --- /dev/null +++ b/apps/cloud/src/app/features/xpert/workspace/settings/general/general.component.html @@ -0,0 +1,64 @@ +
+
{{'PAC.Xpert.General' | translate: {Default: 'General'} }}
+
+
+
+ +
+
+
+ + +
+ +
+ +
+
+ {{ 'PAC.KEY_WORDS.DangerZone' | translate: {Default: 'Danger zone'} }} +
+ +
+
+
+
+ {{ 'PAC.Xpert.ArchiveWorkspace' | translate: {Default: 'Archive this workspace'} }} +
+
+ {{ 'PAC.Xpert.ArchiveWorkspaceDesc' | translate: {Default: 'Mark this workspace and all its xperts and toolsets as archived and read-only'} }}. +
+
+ + +
+ +
+ +
+
+
+ {{ 'PAC.Xpert.DeleteWorkspace' | translate: {Default: 'Delete this workspace'} }} +
+
+ {{ 'PAC.Xpert.DeleteWorkspaceDesc' | translate: {Default: 'Once deleted, it will be gone forever. Please be certain'} }}. +
+
+ + +
+
+
+ + @if (loading()) { + + } +
\ No newline at end of file diff --git a/apps/cloud/src/app/features/xpert/workspace/settings/general/general.component.scss b/apps/cloud/src/app/features/xpert/workspace/settings/general/general.component.scss new file mode 100644 index 000000000..b169cbb7c --- /dev/null +++ b/apps/cloud/src/app/features/xpert/workspace/settings/general/general.component.scss @@ -0,0 +1,3 @@ +:host { + @apply flex flex-col; +} \ No newline at end of file diff --git a/apps/cloud/src/app/features/xpert/workspace/settings/general/general.component.ts b/apps/cloud/src/app/features/xpert/workspace/settings/general/general.component.ts new file mode 100644 index 000000000..3153603c5 --- /dev/null +++ b/apps/cloud/src/app/features/xpert/workspace/settings/general/general.component.ts @@ -0,0 +1,98 @@ +import { CdkListboxModule } from '@angular/cdk/listbox' +import { CommonModule } from '@angular/common' +import { Component, effect, input, model, output, signal } from '@angular/core' +import { FormsModule } from '@angular/forms' +import { NgmSpinComponent } from '@metad/ocap-angular/common' +import { TranslateModule } from '@ngx-translate/core' +import { + getErrorMessage, + IfAnimation, + injectToastr, + injectWorkspaceService, + IXpertWorkspace +} from 'apps/cloud/src/app/@core' + +@Component({ + selector: 'xpert-workspace-settings-general', + standalone: true, + imports: [CommonModule, FormsModule, CdkListboxModule, TranslateModule, NgmSpinComponent], + templateUrl: './general.component.html', + styleUrl: './general.component.scss', + animations: [IfAnimation] +}) +export class XpertWorkspaceSettingsGeneralComponent { + readonly workspaceService = injectWorkspaceService() + readonly #toastr = injectToastr() + + // Inputs + readonly workspace = input() + + // Outputs + readonly deleted = output() + readonly archived = output() + + readonly name = model() + + readonly loading = signal(false) + + constructor() { + effect( + () => { + if (this.workspace()) { + this.name.set(this.workspace().name) + } + }, + { allowSignalWrites: true } + ) + } + + update() { + this.loading.set(true) + this.workspaceService + .update(this.workspace().id, { + name: this.name() + }) + .subscribe({ + next: () => { + this.loading.set(false) + this.#toastr.success('PAC.Messages.UpdatedSuccessfully', { Default: 'Updated successfully' }) + }, + error: (error) => { + this.loading.set(false) + this.#toastr.error(getErrorMessage(error)) + } + }) + } + + archive() { + this.loading.set(true) + this.workspaceService.archive(this.workspace().id) + .subscribe({ + next: () => { + this.loading.set(false) + this.archived.emit() + this.#toastr.success('PAC.Messages.ArchivedSuccessfully', { Default: 'Archived successfully' }) + }, + error: (error) => { + this.loading.set(false) + this.#toastr.error(getErrorMessage(error)) + } + }) + } + + delete() { + this.loading.set(true) + this.workspaceService.delete(this.workspace().id) + .subscribe({ + next: () => { + this.loading.set(false) + this.deleted.emit() + this.#toastr.success('PAC.Messages.DeletedSuccessfully', { Default: 'Deleted successfully' }) + }, + error: (error) => { + this.loading.set(false) + this.#toastr.error(getErrorMessage(error)) + } + }) + } +} diff --git a/apps/cloud/src/app/features/xpert/workspace/members/members.component.html b/apps/cloud/src/app/features/xpert/workspace/settings/members/members.component.html similarity index 96% rename from apps/cloud/src/app/features/xpert/workspace/members/members.component.html rename to apps/cloud/src/app/features/xpert/workspace/settings/members/members.component.html index d2d12e93a..51596372d 100644 --- a/apps/cloud/src/app/features/xpert/workspace/members/members.component.html +++ b/apps/cloud/src/app/features/xpert/workspace/settings/members/members.component.html @@ -1,9 +1,10 @@
-
{{'PAC.Xpert.Members' | translate: {Default: 'Members'} }}
+
{{'PAC.Xpert.Members' | translate: {Default: 'Members'} }}
+
diff --git a/apps/cloud/src/app/features/xpert/workspace/members/members.component.scss b/apps/cloud/src/app/features/xpert/workspace/settings/members/members.component.scss similarity index 100% rename from apps/cloud/src/app/features/xpert/workspace/members/members.component.scss rename to apps/cloud/src/app/features/xpert/workspace/settings/members/members.component.scss diff --git a/apps/cloud/src/app/features/xpert/workspace/members/members.component.ts b/apps/cloud/src/app/features/xpert/workspace/settings/members/members.component.ts similarity index 97% rename from apps/cloud/src/app/features/xpert/workspace/members/members.component.ts rename to apps/cloud/src/app/features/xpert/workspace/settings/members/members.component.ts index e6e10b6d2..4be06b9ea 100644 --- a/apps/cloud/src/app/features/xpert/workspace/members/members.component.ts +++ b/apps/cloud/src/app/features/xpert/workspace/settings/members/members.component.ts @@ -9,7 +9,7 @@ import { injectUser, IUser, IXpertWorkspace, XpertWorkspaceService } from 'apps/ import { UserPipe, UserRoleSelectComponent } from 'apps/cloud/src/app/@shared' import { uniqBy } from 'lodash-es' import { EMPTY, filter, switchMap } from 'rxjs' -import { UserProfileInlineComponent } from '../../../../@shared/' +import { UserProfileInlineComponent } from '../../../../../@shared/' @Component({ selector: 'xpert-workspace-members', diff --git a/apps/cloud/src/app/features/xpert/workspace/models/models.component.html b/apps/cloud/src/app/features/xpert/workspace/settings/models/models.component.html similarity index 100% rename from apps/cloud/src/app/features/xpert/workspace/models/models.component.html rename to apps/cloud/src/app/features/xpert/workspace/settings/models/models.component.html diff --git a/apps/cloud/src/app/features/xpert/workspace/models/models.component.scss b/apps/cloud/src/app/features/xpert/workspace/settings/models/models.component.scss similarity index 100% rename from apps/cloud/src/app/features/xpert/workspace/models/models.component.scss rename to apps/cloud/src/app/features/xpert/workspace/settings/models/models.component.scss diff --git a/apps/cloud/src/app/features/xpert/workspace/models/models.component.ts b/apps/cloud/src/app/features/xpert/workspace/settings/models/models.component.ts similarity index 100% rename from apps/cloud/src/app/features/xpert/workspace/models/models.component.ts rename to apps/cloud/src/app/features/xpert/workspace/settings/models/models.component.ts diff --git a/apps/cloud/src/app/features/xpert/workspace/settings/settings.component.html b/apps/cloud/src/app/features/xpert/workspace/settings/settings.component.html index d4df9f975..25b558069 100644 --- a/apps/cloud/src/app/features/xpert/workspace/settings/settings.component.html +++ b/apps/cloud/src/app/features/xpert/workspace/settings/settings.component.html @@ -7,6 +7,18 @@
{{ 'PAC.KEY_WORDS.Workspace' | translate: {Default: 'Workspace'} }}
    + +