Skip to content

Commit

Permalink
Open select dialog on all types, fetch destination folder from a rela…
Browse files Browse the repository at this point in the history
…tive path
  • Loading branch information
adomi committed Jul 22, 2020
1 parent a5972e7 commit f593bbf
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
[allowDropFiles]="false"
[sorting]="'server'"
[where]="where"
(folderChange)="onFolderChange()"
(folderChange)="onFolderChange($event)"
(ready)="onFolderLoaded()"
data-automation-id="content-node-selector-document-list">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { ImageResolver } from '../document-list/data/image-resolver.model';
import { ContentNodeSelectorService } from './content-node-selector.service';
import { debounceTime, takeUntil } from 'rxjs/operators';
import { CustomResourcesService } from '../document-list/services/custom-resources.service';
import { ShareDataRow } from '../document-list';
import { NodeEntryEvent, ShareDataRow } from '../document-list';
import { Subject } from 'rxjs';

export type ValidationFunction = (entry: Node) => boolean;
Expand Down Expand Up @@ -182,6 +182,10 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy {
@Output()
select: EventEmitter<Node[]> = new EventEmitter<Node[]>();

/** Emitted when the navigation changes. */
@Output()
navigationChange: EventEmitter<NodeEntryEvent> = new EventEmitter<NodeEntryEvent>();

/** Emitted when the select site changes. */
@Output()
siteChange: EventEmitter<string> = new EventEmitter<string>();
Expand Down Expand Up @@ -424,11 +428,12 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy {
/**
* Sets showingSearchResults state to be able to differentiate between search results or folder results
*/
onFolderChange(): void {
onFolderChange($event: NodeEntryEvent): void {
this.showingSearchResults = false;
this.infiniteScroll = false;
this.breadcrumbFolderTitle = null;
this.clearSearch();
this.navigationChange.emit($event);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export interface ContentNodeSelectorComponentData {
showSearch?: boolean;
showFilesInResult?: boolean;
showDropdownSiteList?: boolean;
showUploadButton?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h2>{{title}}</h2>
</header>

<mat-dialog-content>
<adf-content-node-selector-panel
<adf-content-node-selector-panel #selectorPanelComponent
[currentFolderId]="data?.currentFolderId"
[dropdownHideMyFiles]="data?.dropdownHideMyFiles"
[dropdownSiteList]="data?.dropdownSiteList"
Expand All @@ -19,11 +19,18 @@ <h2>{{title}}</h2>
[showDropdownSiteList]="data?.showDropdownSiteList"
[showFilesInResult]="data?.showFilesInResult"
(select)="onSelect($event)"
(siteChange)="onSiteChange($event)">
(siteChange)="onSiteChange($event)"
(navigationChange)="onNavigationChange($event)">
</adf-content-node-selector-panel>
</mat-dialog-content>

<mat-dialog-actions align="end">
<adf-upload-button *ngIf="data?.showUploadButton"
[staticTitle]="'FORM.FIELD.UPLOAD' | translate "
[rootFolderId]="currentDirectoryId"
(success)="onSuccess($event)"
(error)="onError($event)">
</adf-upload-button>
<button
mat-button
(click)="close()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
* limitations under the License.
*/

import { Component, Inject, ViewEncapsulation } from '@angular/core';
import { Component, Inject, ViewChild, ViewEncapsulation } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { TranslationService } from '@alfresco/adf-core';
import { Node } from '@alfresco/js-api';
import { ContentNodeSelectorComponentData } from './content-node-selector.component-data.interface';
import { NodeEntryEvent } from '../document-list';
import { ContentNodeSelectorPanelComponent } from './content-node-selector-panel.component';
import { NotificationService } from '../../../../core/notifications';

@Component({
selector: 'adf-content-node-selector',
Expand All @@ -28,17 +31,22 @@ import { ContentNodeSelectorComponentData } from './content-node-selector.compon
encapsulation: ViewEncapsulation.None
})
export class ContentNodeSelectorComponent {
@ViewChild('selectorPanelComponent', { static: true })
selectorPanelComponent: ContentNodeSelectorPanelComponent;

title: string;
action: string;
buttonActionName: string;
chosenNode: Node[];
currentDirectoryId: string;

constructor(private translation: TranslationService,
private notificationService: NotificationService,
@Inject(MAT_DIALOG_DATA) public data: ContentNodeSelectorComponentData) {
this.action = data.actionName ? data.actionName.toUpperCase() : 'CHOOSE';
this.buttonActionName = `NODE_SELECTOR.${this.action}`;
this.title = data.title;
this.currentDirectoryId = data.currentFolderId;
}

close() {
Expand All @@ -53,6 +61,10 @@ export class ContentNodeSelectorComponent {
this.updateTitle(siteTitle);
}

onNavigationChange(pathElement: NodeEntryEvent) {
this.currentDirectoryId = pathElement.value.id;
}

onClick(): void {
this.data.select.next(this.chosenNode);
this.data.select.complete();
Expand All @@ -67,4 +79,13 @@ export class ContentNodeSelectorComponent {
getTitleTranslation(action: string, name: string): string {
return this.translation.instant(`NODE_SELECTOR.${action}_ITEM`, { name: this.translation.instant(name) });
}

onSuccess($event) {
this.selectorPanelComponent.documentList.reload();
this.notificationService.showInfo(`${$event.value.entry.name} has been uploaded`);
}

onError(error) {
this.notificationService.showError(error);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { BreadcrumbModule } from '../breadcrumb/breadcrumb.module';
import { CoreModule } from '@alfresco/adf-core';
import { DocumentListModule } from '../document-list/document-list.module';
import { NameLocationCellComponent } from './name-location-cell/name-location-cell.component';
import { UploadModule } from '../upload';

@NgModule({
imports: [
Expand All @@ -37,7 +38,8 @@ import { NameLocationCellComponent } from './name-location-cell/name-location-ce
MaterialModule,
SitesDropdownModule,
BreadcrumbModule,
DocumentListModule
DocumentListModule,
UploadModule
],
exports: [
ContentNodeSelectorPanelComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,11 @@
<span *ngIf="isRequired()">*</span>
</label>
<div class="adf-attach-widget-container">
<div id="adf-attach-widget-simple-upload" *ngIf="isSimpleUploadButton() && isUploadButtonVisible()">
<a mat-raised-button color="primary">
<div class="adf-attach-widget__menu-upload" *ngIf="isUploadButtonVisible()">
<button (click)="openSelectDialog()" mat-raised-button color="primary" [id]="field.id">
{{ 'FORM.FIELD.UPLOAD' | translate }}
<mat-icon>file_upload</mat-icon>
<input #uploadFiles
[multiple]="multipleOption"
type="file"
[id]="field.id"
(change)="onAttachFileChanged($event)"/>
</a>
</div>
<div class="adf-attach-widget__menu-upload" *ngIf="isUploadButtonVisible() && isMultipleSourceUpload()">
<button mat-raised-button color="primary" [matMenuTriggerFor]="menu" [id]="field.id">
{{ 'FORM.FIELD.UPLOAD' | translate }}
<mat-icon>attach_file</mat-icon>
<mat-icon>{{getWidgetIcon()}}</mat-icon>
</button>
<mat-menu #menu="matMenu" class="adf-attach-widget__menu-content">
<div *ngIf="isContentSourceSelected()">
<button mat-menu-item
id="attach-{{field.params?.fileSource?.name}}"
(click)="uploadFileFromCS()">
{{field.params?.fileSource?.name}}
<mat-icon>
<img alt="alfresco" class="adf-attach-widget__image-logo"
src="./assets/images/alfresco-flower.svg">
</mat-icon>
</button>
</div>
</mat-menu>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ import { UploadCloudWidgetComponent } from './upload-cloud.widget';
})
export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent
implements OnInit {
static ACS_SERVICE = 'alfresco-content';

typeId = 'AttachFileCloudWidgetComponent';
rootDirectory;

constructor(
formService: FormService,
Expand All @@ -64,18 +64,6 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent
super(formService, thumbnails, processCloudContentService, notificationService, logger);
}

isFileSourceConfigured(): boolean {
return !!this.field.params && !!this.field.params.fileSource;
}

isMultipleSourceUpload(): boolean {
return (
!this.field.readOnly &&
this.isFileSourceConfigured() &&
!this.isOnlyLocalSourceSelected()
);
}

isOnlyLocalSourceSelected(): boolean {
return (
this.field.params &&
Expand All @@ -84,50 +72,32 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent
);
}

isSimpleUploadButton(): boolean {
return (
(this.isUploadButtonVisible() && !this.isFileSourceConfigured()) ||
this.isOnlyLocalSourceSelected()
);
}

isUploadButtonVisible(): boolean {
return (!this.hasFile || this.multipleOption) && !this.field.readOnly;
}

onAttachFileChanged(event: any) {
this.onFileChanged(event);
}

onRemoveAttachFile(file: File | RelatedContentRepresentation | Node) {
this.removeFile(file);
}

uploadFileFromCS() {
this.openSelectDialog();
}

openSelectDialog() {
async openSelectDialog() {
const filesSaved: Node[] = [];

await this.contentNodeSelectorService.fetchNodeIdFromRelativePath('User Homes/hruser/mydir/new').then((nodeId: string) => {
this.rootDirectory = nodeId;
});

const isLocal = this.isOnlyLocalSourceSelected();

this.contentNodeSelectorService
.openUploadFileDialog(this.field.form.contentHost)
.openUploadFileDialog(this.field.form.contentHost, this.rootDirectory, isLocal)
.subscribe((selections: Node[]) => {
selections.forEach(node => (node['isExternal'] = true));
filesSaved.push(selections[0]);
this.fixIncompatibilityFromPreviousAndNewForm(filesSaved);
});
}

isContentSourceSelected(): boolean {
return (
this.field.params &&
this.field.params.fileSource &&
this.field.params.fileSource.serviceId ===
AttachFileCloudWidgetComponent.ACS_SERVICE
);
}

downloadContent(file: Node): void {
this.processCloudContentService.downloadFile(
file.id,
Expand All @@ -139,4 +109,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent
nodeSelector.nodeId = nodeSelector.id;
this.fileClicked(new ContentLinkModel(nodeSelector));
}

getWidgetIcon(): string {
return this.isOnlyLocalSourceSelected() ? 'file_upload' : 'attach_file';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ContentCloudNodeSelectorService {
private dialog: MatDialog) {
}

openUploadFileDialog(contentHost: string): Observable<Node[]> {
openUploadFileDialog(contentHost: string, currentFolderId?: string, showUploadButton?: boolean): Observable<Node[]> {
const changedConfig = this.apiService.lastConfig;
changedConfig.provider = 'ALL';
changedConfig.hostEcm = contentHost.replace('/alfresco', '');
Expand All @@ -44,16 +44,26 @@ export class ContentCloudNodeSelectorService {
const data = <ContentNodeSelectorComponentData> {
title: 'Select a file',
actionName: 'Choose',
currentFolderId: '-my-',
currentFolderId,
select,
isSelectionValid: (entry: Node) => entry.isFile,
showFilesInResult: true
showFilesInResult: true,
showDropdownSiteList: false,
showUploadButton
};

this.openContentNodeDialog(data, 'adf-content-node-selector-dialog', '630px');
return select;
}

async fetchNodeIdFromRelativePath(relativePath: string) {
let nodeId = '';
await this.apiService.getInstance().node.getNode('-root-', { relativePath }).then(node => {
nodeId = node.entry.id;
});
return nodeId;
}

private openContentNodeDialog(data: ContentNodeSelectorComponentData, currentPanelClass: string, chosenWidth: string) {
this.dialog.open(ContentNodeSelectorComponent, { data, panelClass: currentPanelClass, width: chosenWidth });
}
Expand Down

0 comments on commit f593bbf

Please sign in to comment.