Merge pull request #1153 from Alfresco/dev-pionnegu-ACA-2651

[ACA-2651] Viewer - toolbar disappears after marking / removing a specific file as favourite
This commit is contained in:
Denys Vuika 2019-07-12 09:42:21 +01:00 committed by GitHub
commit 1640a16c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 97 additions and 16 deletions

View File

@ -43,8 +43,8 @@ import { NodePermissionService } from '@alfresco/aca-shared';
import { BreakpointObserver } from '@angular/cdk/layout';
import {
AppStore,
SetSelectedNodesAction,
getCurrentFolder
getCurrentFolder,
SetSelectedNodesAction
} from '@alfresco/aca-shared/store';
import { Directionality } from '@angular/cdk/bidi';

View File

@ -1,8 +1,8 @@
<div class="line">
<span *ngIf="isFile" (click)="showPreview()" class="link">
<span *ngIf="isFile" (click)="showPreview($event)" class="link">
{{ name$ | async }}
</span>
<span *ngIf="!isFile" (click)="navigate()" class="bold link">
<span *ngIf="!isFile" (click)="navigate($event)" class="bold link">
{{ name$ | async }}
</span>
<span>{{ title$ | async }}</span>

View File

@ -121,11 +121,13 @@ export class SearchResultsRowComponent implements OnInit, OnDestroy {
return this.node.entry.isFile;
}
showPreview() {
showPreview(event: MouseEvent) {
event.stopPropagation();
this.store.dispatch(new ViewFileAction(this.node));
}
navigate() {
navigate(event: MouseEvent) {
event.stopPropagation();
this.store.dispatch(new NavigateToFolder(this.node));
}
}

View File

@ -23,10 +23,70 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { TestBed } from '@angular/core/testing';
import { ToggleFavoriteComponent } from './toggle-favorite.component';
import { Store } from '@ngrx/store';
import { ExtensionService } from '@alfresco/adf-extensions';
import { CoreModule } from '@alfresco/adf-core';
import { Router } from '@angular/router';
import { of } from 'rxjs';
describe('ToggleFavoriteComponent', () => {
it('should be defined', () => {
expect(ToggleFavoriteComponent).toBeDefined();
let component: ToggleFavoriteComponent;
let fixture;
let router;
const mockRouter = {
url: 'some-url'
};
const mockStore = <any>{
dispatch: jasmine.createSpy('dispatch'),
select: jasmine.createSpy('select').and.returnValue(
of({
nodes: []
})
)
};
beforeEach(() => {
TestBed.configureTestingModule({
imports: [CoreModule.forRoot()],
declarations: [ToggleFavoriteComponent],
providers: [
ExtensionService,
{ provide: Store, useValue: mockStore },
{ provide: Router, useValue: mockRouter }
]
});
fixture = TestBed.createComponent(ToggleFavoriteComponent);
component = fixture.componentInstance;
router = TestBed.get(Router);
});
afterEach(() => {
mockStore.dispatch.calls.reset();
});
it('should get selection data on initialization', () => {
expect(mockStore.select).toHaveBeenCalled();
});
it('should not dispatch reload if route is not specified', () => {
component.data = "['/reload_on_this_route']";
fixture.detectChanges();
component.onToggleEvent();
expect(mockStore.dispatch).not.toHaveBeenCalled();
});
it('should dispatch reload if route is specified', () => {
component.data = "['/reload_on_this_route']";
router.url = '/reload_on_this_route';
fixture.detectChanges();
component.onToggleEvent();
expect(mockStore.dispatch).toHaveBeenCalled();
});
});

View File

@ -23,15 +23,16 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, ViewEncapsulation } from '@angular/core';
import { Component, ViewEncapsulation, OnInit, Input } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import { SelectionState } from '@alfresco/adf-extensions';
import { SelectionState, ExtensionService } from '@alfresco/adf-extensions';
import {
AppStore,
ReloadDocumentListAction,
getAppSelection
} from '@alfresco/aca-shared/store';
import { Router } from '@angular/router';
@Component({
selector: 'app-toggle-favorite',
@ -54,14 +55,30 @@ import {
encapsulation: ViewEncapsulation.None,
host: { class: 'app-toggle-favorite' }
})
export class ToggleFavoriteComponent {
export class ToggleFavoriteComponent implements OnInit {
@Input() data: any;
selection$: Observable<SelectionState>;
private reloadOnRoutes: string[] = [];
constructor(private store: Store<AppStore>) {
constructor(
private store: Store<AppStore>,
private extensionService: ExtensionService,
private router: Router
) {
this.selection$ = this.store.select(getAppSelection);
}
ngOnInit() {
if (this.data) {
this.reloadOnRoutes = this.extensionService.runExpression(
`$( ${this.data} )`
);
}
}
onToggleEvent() {
this.store.dispatch(new ReloadDocumentListAction());
if (this.reloadOnRoutes.includes(this.router.url)) {
this.store.dispatch(new ReloadDocumentListAction());
}
}
}

View File

@ -12,7 +12,10 @@
<ng-container *ngFor="let child of actionRef.children; trackBy: trackById">
<ng-container [ngSwitch]="child.type">
<ng-container *ngSwitchCase="'custom'">
<adf-dynamic-component [id]="child.component"></adf-dynamic-component>
<adf-dynamic-component
[id]="child.component"
[data]="child.data"
></adf-dynamic-component>
</ng-container>
<ng-container *ngSwitchDefault>
<app-toolbar-menu-item [actionRef]="child"></app-toolbar-menu-item>

View File

@ -111,7 +111,6 @@ export class ContentManagementService {
node.entry.isFavorite = true;
});
this.store.dispatch(new SetSelectedNodesAction(nodes));
this.store.dispatch(new ReloadDocumentListAction());
});
}
}
@ -123,7 +122,6 @@ export class ContentManagementService {
node.entry.isFavorite = false;
});
this.store.dispatch(new SetSelectedNodesAction(nodes));
this.store.dispatch(new ReloadDocumentListAction());
});
}
}

View File

@ -356,6 +356,7 @@
"comment": "workaround for Recent Files and Search API issue",
"type": "custom",
"order": 400,
"data": "['/favorites', '/favorite/libraries']",
"component": "app.toolbar.toggleFavorite",
"rules": {
"visible": "canToggleFavorite"