imporove sorting management and reduce repetitive code (#381)

* rework sorting management

* remove fdescribe

* test fixes

* unified desctructor

* unified page reload

* test fixes

* code fixes

* test fixes

* test fixes
This commit is contained in:
Denys Vuika
2018-06-02 16:35:55 +01:00
committed by Cilibiu Bogdan
parent 0ac33f820b
commit 7bb0905045
23 changed files with 195 additions and 486 deletions

View File

@@ -23,12 +23,10 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs/Rx';
import { MinimalNodeEntity } from 'alfresco-js-api';
import { AlfrescoApiService, UserPreferencesService } from '@alfresco/adf-core';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { ContentManagementService } from '../../common/services/content-management.service';
import { NodePermissionService } from '../../common/services/node-permission.service';
@@ -37,41 +35,25 @@ import { PageComponent } from '../page.component';
@Component({
templateUrl: './shared-files.component.html'
})
export class SharedFilesComponent extends PageComponent implements OnInit, OnDestroy {
@ViewChild(DocumentListComponent)
documentList: DocumentListComponent;
private subscriptions: Subscription[] = [];
sorting = [ 'modifiedAt', 'desc' ];
export class SharedFilesComponent extends PageComponent implements OnInit {
constructor(private router: Router,
private route: ActivatedRoute,
route: ActivatedRoute,
private content: ContentManagementService,
private apiService: AlfrescoApiService,
public permission: NodePermissionService,
preferences: UserPreferencesService) {
super(preferences);
const sortingKey = preferences.get(`${this.prefix}.sorting.key`) || 'modifiedAt';
const sortingDirection = preferences.get(`${this.prefix}.sorting.direction`) || 'desc';
this.sorting = [sortingKey, sortingDirection];
super(preferences, route);
}
ngOnInit() {
this.subscriptions = this.subscriptions.concat([
this.content.nodeDeleted.subscribe(() => this.refresh()),
this.content.nodeMoved.subscribe(() => this.refresh()),
this.content.nodeRestored.subscribe(() => this.refresh())
this.content.nodeDeleted.subscribe(() => this.reload()),
this.content.nodeMoved.subscribe(() => this.reload()),
this.content.nodeRestored.subscribe(() => this.reload())
]);
}
ngOnDestroy() {
this.subscriptions.forEach(s => s.unsubscribe());
}
onNodeDoubleClick(link: { nodeId?: string }) {
if (link && link.nodeId) {
this.apiService.nodesApi.getNode(link.nodeId).then(
@@ -88,20 +70,4 @@ export class SharedFilesComponent extends PageComponent implements OnInit, OnDes
isFileSelected(selection: Array<MinimalNodeEntity>): boolean {
return selection && selection.length === 1;
}
refresh(): void {
if (this.documentList) {
this.documentList.resetSelection();
this.documentList.reload();
}
}
onSortingChanged(event: CustomEvent) {
this.preferences.set(`${this.prefix}.sorting.key`, event.detail.key || 'modifiedAt');
this.preferences.set(`${this.prefix}.sorting.direction`, event.detail.direction || 'desc');
}
private get prefix() {
return this.route.snapshot.data.preferencePrefix;
}
}