Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sc-4135] Restore action menu in expanded tile #612

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions app.babel
Original file line number Diff line number Diff line change
Expand Up @@ -9579,6 +9579,26 @@
</translation>
</translations>
</concept_node>
<concept_node>
<name>resource.delete_resource_title</name>
<description/>
<comment/>
<default_text/>
<translations>
<translation>
<language>ca-ES</language>
<approved>false</approved>
</translation>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-ES</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>resource.delete_resource_warning</name>
<description/>
Expand Down Expand Up @@ -9619,6 +9639,26 @@
</translation>
</translations>
</concept_node>
<concept_node>
<name>resource.delete_resources_title</name>
<description/>
<comment/>
<default_text/>
<translations>
<translation>
<language>ca-ES</language>
<approved>false</approved>
</translation>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-ES</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>resource.delete_resources_warning</name>
<description/>
Expand Down Expand Up @@ -10659,6 +10699,46 @@
</translation>
</translations>
</concept_node>
<concept_node>
<name>resource.reprocess_resource_description</name>
<description/>
<comment/>
<default_text/>
<translations>
<translation>
<language>ca-ES</language>
<approved>false</approved>
</translation>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-ES</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>resource.reprocess_resource_title</name>
<description/>
<comment/>
<default_text/>
<translations>
<translation>
<language>ca-ES</language>
<approved>false</approved>
</translation>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-ES</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node>
<name>resource.resource_page_number</name>
<description/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export class ResourceListComponent implements OnInit, OnDestroy {
.openConfirm({
title,
description: message,
confirmLabel: 'generic.delete',
isDestructive: true,
})
.onClose.pipe(
Expand Down
107 changes: 88 additions & 19 deletions apps/dashboard/src/app/resources/resource-viewer.service.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import { filter, map, switchMap, take, tap } from 'rxjs';
import { filter, map, Observable, switchMap, take, tap } from 'rxjs';
import { SisModalService } from '@nuclia/sistema';
import { SDKService, STFTrackingService } from '@flaps/core';
import { Injectable } from '@angular/core';
import { Injectable, NgZone } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Router } from '@angular/router';
import { FieldFullId } from '@nuclia/core';

@Injectable({
providedIn: 'root',
})
export class ResourceViewerService {
private widgetId?: string;

constructor(
private router: Router,
private sdk: SDKService,
private translation: TranslateService,
private modalService: SisModalService,
private trackingService: STFTrackingService,
private zone: NgZone,
) {}

init(widgetId: string) {
this.widgetId = widgetId;
this.sdk.currentKb.pipe(take(1)).subscribe((kb) => {
const waitForWidget = window.setInterval(() => {
const widget = document.getElementById(widgetId) as unknown as any;
Expand All @@ -32,18 +37,33 @@ export class ResourceViewerService {
if (kb.admin || kb.contrib) {
actions.push(
{
label: this.translation.instant('generic.edit'),
label: this.translation.instant('resource.menu.edit'),
destructive: false,
action: this.edit.bind(this),
},
{
label: this.translation.instant('resource.menu.annotate'),
destructive: false,
action: this.annotate.bind(this),
},
{
label: this.translation.instant('resource.menu.classify'),
destructive: false,
action: this.classify.bind(this),
},
{
label: this.translation.instant('generic.reindex'),
destructive: false,
action: this.reindex.bind(this),
},
{
label: this.translation.instant('generic.delete'),
destructive: true,
action: this.delete.bind(this),
},
);
}
widget.setActions(actions);
widget.setTileMenu(actions);
widget.addEventListener('search', () => this.trackingService.logEvent('search'));
clearInterval(waitForWidget);
}
Expand All @@ -60,48 +80,77 @@ export class ResourceViewerService {
});
}

delete(uid: string) {
delete(fullId: FieldFullId) {
this.modalService
.openConfirm({
title: 'generic.alert',
title: 'resource.delete_resource_title',
description: 'resource.delete_resource_warning',
confirmLabel: 'generic.delete',
isDestructive: true,
})
.onClose.pipe(
filter((confirm) => !!confirm),
tap(() => this.closeViewer()),
switchMap(() => this.sdk.currentKb),
take(1),
switchMap((kb) => kb.getResource(uid)),
switchMap((kb) => kb.getResource(fullId.resourceId)),
switchMap((res) => res.delete()),
tap(() => this.closeViewer()),
)
.subscribe(() => {
this.reloadSearch();
setTimeout(() => {
this.sdk.refreshCounter(true);
}, 1000);
});
}

edit(uid: string) {
this.sdk.currentKb
.pipe(
edit(fullId: FieldFullId) {
this.getResourcesBasePath().subscribe((basePath) => {
this.closeViewer();
this.navigateTo(`${basePath}/${fullId.resourceId}/edit`);
});
}

annotate(fullId: FieldFullId) {
this.getResourcesBasePath().subscribe((basePath) => {
this.closeViewer();
this.navigateTo(`${basePath}/${fullId.resourceId}/edit/annotation`);
});
}

classify(fullId: FieldFullId) {
this.getResourcesBasePath().subscribe((basePath) => {
this.closeViewer();
this.navigateTo(`${basePath}/${fullId.resourceId}/edit/classification`);
});
}

reindex(fullId: FieldFullId) {
this.modalService
.openConfirm({
title: 'resource.reprocess_resource_title',
description: 'resource.reprocess_resource_description',
})
.onClose.pipe(
filter((confirm) => !!confirm),
tap(() => this.closeViewer()),
switchMap(() => this.sdk.currentKb),
take(1),
filter((kb) => !!kb.admin || !!kb.contrib),
switchMap((kb) => kb.getResource(fullId.resourceId)),
switchMap((res) => res.reprocess()),
)
.subscribe((kb) => {
this.closeViewer();
this.router.navigate([`/at/${kb.account}/${kb.slug}/resources/${uid}/edit/profile`]);
});
.subscribe();
}

showUID(uid: string) {
showUID(fullId: FieldFullId) {
this.sdk.currentKb
.pipe(
take(1),
map(
(kb) =>
`<pre><code class="endpoint">${this.sdk.nuclia.rest.getFullUrl(kb.path)}/resource/${uid}</code></pre>`,
`<pre><code class="endpoint">${this.sdk.nuclia.rest.getFullUrl(kb.path)}/resource/${
fullId.resourceId
}</code></pre>`,
),
switchMap(
(uidEndpoint) =>
Expand All @@ -117,6 +166,26 @@ export class ResourceViewerService {
}

closeViewer() {
(document.getElementById('search-widget') as unknown as any)?.displayResource('');
if (this.widgetId) {
(document.getElementById(this.widgetId) as unknown as any)?.closePreview();
}
}

reloadSearch() {
const searchBar = document.querySelector('nuclia-search-bar') as any;
if (typeof searchBar?.reloadSearch === 'function') {
searchBar.reloadSearch();
}
}

private getResourcesBasePath(): Observable<string> {
return this.sdk.currentKb.pipe(
take(1),
filter((kb) => !!kb.admin || !!kb.contrib),
map((kb) => `/at/${kb.account}/${kb.slug}/resources`),
);
}
private navigateTo(path: string) {
this.zone.run(() => this.router.navigate([path]));
}
}
14 changes: 10 additions & 4 deletions apps/dashboard/src/app/search/search.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ChangeDetectionStrategy, Component, OnDestroy } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { BackendConfigurationService, SDKService } from '@flaps/core';
import { distinctUntilKeyChanged, forkJoin, map, switchMap, tap } from 'rxjs';
import { DEFAULT_FEATURES_LIST } from '../widgets/widget-features';
import { DomSanitizer } from '@angular/platform-browser';
import { TranslateService } from '@ngx-translate/core';
import { TrainingType } from '@nuclia/core';
import { ResourceViewerService } from '../resources/resource-viewer.service';

const searchWidgetId = 'search-bar';
const searchResultsId = 'search-results';
Expand All @@ -15,7 +16,7 @@ const searchResultsId = 'search-results';
styleUrls: ['./search.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SearchComponent implements OnDestroy {
export class SearchComponent implements OnDestroy, OnInit {
searchWidget = this.sdk.currentKb.pipe(
distinctUntilKeyChanged('id'),
tap(() => {
Expand Down Expand Up @@ -59,15 +60,20 @@ export class SearchComponent implements OnDestroy {
private sanitized: DomSanitizer,
private backendConfig: BackendConfigurationService,
private translation: TranslateService,
private viewerService: ResourceViewerService,
) {}

ngOnInit() {
this.viewerService.init(searchResultsId);
}

ngOnDestroy() {
const searchBarElement = document.querySelector('nuclia-search-bar') as any;
const searchResultsElement = document.querySelector('nuclia-search-results') as any;
if (typeof searchBarElement.$destroy === 'function') {
if (typeof searchBarElement?.$destroy === 'function') {
searchBarElement.$destroy();
}
if (typeof searchResultsElement.$destroy === 'function') {
if (typeof searchResultsElement?.$destroy === 'function') {
searchResultsElement.$destroy();
}
}
Expand Down
Loading