[ADF-2373] added filtering for membership on site dropdown (#3031)

* [ADF-2373] added filtering for membership on site dropdown

* [ADF-2373] added test for new site service method

* [ADF-2373] added filtering for site membering to the sites dropdown

* [ADF-2373] added another check into sites tests

* [ADF-2373] added a fix for the site dropdown tests

* [ADF-2373] fixed broken test check

* [ADF-2373] added PR review changes
This commit is contained in:
Vito
2018-03-06 16:28:30 +00:00
committed by Eugenio Romano
parent 0f64af39d9
commit 52df355e90
7 changed files with 213 additions and 20 deletions

View File

@@ -16,9 +16,14 @@
*/
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
import { SitesService } from '@alfresco/adf-core';
import { SitesService, LogService } from '@alfresco/adf-core';
import { SitePaging, SiteEntry } from 'alfresco-js-api';
export enum Relations {
Members = 'members',
Containers = 'containers'
}
@Component({
selector: 'adf-sites-dropdown',
styleUrls: ['./sites-dropdown.component.scss'],
@@ -48,6 +53,9 @@ export class DropdownSitesComponent implements OnInit {
@Input()
placeholder: string = 'DROPDOWN.PLACEHOLDER_LABEL';
@Input()
relations: string;
/** Emitted when the user selects a site. When the default option is selected,
* an empty model is emitted.
*/
@@ -58,14 +66,14 @@ export class DropdownSitesComponent implements OnInit {
public MY_FILES_VALUE = '-my-';
constructor(private sitesService: SitesService) {
constructor(private sitesService: SitesService,
private logService: LogService) {
}
ngOnInit() {
if (!this.siteList) {
this.setDefaultSiteList();
}
}
selectedSite(event: any) {
@@ -73,24 +81,42 @@ export class DropdownSitesComponent implements OnInit {
}
private setDefaultSiteList() {
this.sitesService.getSites().subscribe((result) => {
this.siteList = result;
let extendedOptions = null;
if (this.relations) {
extendedOptions = { relations: [this.relations] };
}
this.sitesService.getSites(extendedOptions).subscribe((result) => {
if (!this.hideMyFiles) {
let myItem = { entry: { id: '-my-', guid: '-my-', title: 'DROPDOWN.MY_FILES_OPTION' } };
this.siteList = this.relations === Relations.Members ? this.filteredResultsByMember(result) : result;
this.siteList.list.entries.unshift(myItem);
if (!this.hideMyFiles) {
let myItem = { entry: { id: '-my-', guid: '-my-', title: 'DROPDOWN.MY_FILES_OPTION' } };
if (!this.value) {
this.value = '-my-';
}
this.siteList.list.entries.unshift(myItem);
if (!this.value) {
this.value = '-my-';
}
}
this.selected = this.siteList.list.entries.find(site => site.entry.id === this.value);
},
(error) => {
this.selected = this.siteList.list.entries.find(site => site.entry.id === this.value);
},
(error) => {
this.logService.error(error);
});
}
private filteredResultsByMember(sites: SitePaging): SitePaging {
const loggedUserName = this.sitesService.getEcmCurrentLoggedUserName();
sites.list.entries = sites.list.entries.filter( (site) => this.isCurrentUserMember(site, loggedUserName));
return sites;
}
private isCurrentUserMember(site, loggedUserName): boolean {
return site.entry.visibility === 'PUBLIC' ||
!!site.relations.members.list.entries.find((member) => {
return member.entry.id === loggedUserName;
});
}
}