Skip to content

Commit

Permalink
Added sharing to home page
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianPienaar committed Sep 24, 2023
1 parent f3b74a0 commit b6e87af
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 6 deletions.
16 changes: 16 additions & 0 deletions frontend/src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -386,5 +386,21 @@ <h2 class="folderName">{{getCurrentFolderName()}}</h2>
</p-dialog>
</div>
<!-- TODO FileManagerPopup above-->

<!-- TODO FileManagerPopup below-->
<div class="fileOperations-container">
<p-dialog [(visible)]="sharePopup" [modal]="true" [style]="{ width: '50vw', minWidth: 'min(500px,100vw)' }"
header="Share" [focusOnShow]="true" (keydown.escape)="sharePopup = false" (click)="$event.stopPropagation()">
<div class="fileOperations" style="display: grid; width:80%;">
<input placeholder="User Email" class="fileOperations-entity" [(ngModel)]="recipientEmail" label="Name: " pInputText
type="text" [style]="{width: '100%', marginTop: '20px'}" (keydown.enter)="shareDocument()" />
<br />
<div style="display:flex; justify-content: space-around;">
<p-button (click)="shareDocument()" label="Share" [style]="{width:'200px'}"></p-button>
</div>
</div>
</p-dialog>
</div>
<!-- TODO FileManagerPopup above-->

</div>
73 changes: 67 additions & 6 deletions frontend/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class HomeComponent implements OnInit, AfterViewInit {
public editToggle: boolean = false;
public valueBeforeEdit: string = '';
public colInspect: any;

public moveDialogVisible: boolean = false;
public entityToMove: any;
public destinationDirectory: any;
Expand All @@ -90,12 +91,15 @@ export class HomeComponent implements OnInit, AfterViewInit {
renameDialogVisible: boolean = false;
documentLockedPopup: boolean = false;
openLockedDocumentPopup: boolean = false;
sharePopup: boolean = false;
removeDocumentLock: boolean = false;

public entityName: string = '';
entityRename: string = '';
uploadedFiles: any[] = [];
contextMenuItems: any[];
public userDocumentPassword: string = '';
recipientEmail: string = '';
documentPromise: Promise<any> | null = null;

currentFolders: any[] = []; //Holds an array of objects representing folders.
Expand Down Expand Up @@ -192,6 +196,13 @@ export class HomeComponent implements OnInit, AfterViewInit {
}
},
},
{
label: 'Share',
icon: 'pi pi-share-alt',
command: () => {
this.sharePopup = true;
},
},
];
}

Expand Down Expand Up @@ -811,8 +822,20 @@ export class HomeComponent implements OnInit, AfterViewInit {
},
},
{
separator: true,
},
label: 'Share',
icon: 'pi pi-fw pi-share-alt',
command: () => {
if (this.getSelected().length === 1 && this.getSelected()[0].Type === 'file')
this.sharePopup = true;
else
this.messageService.add({
severity: 'warn',
summary: 'Please select a File to Share',
detail: '',
});
},

}
// {//TODO implement downloading a file from the database
// label: 'Export',
// icon: 'pi pi-fw pi-external-link',
Expand Down Expand Up @@ -1138,8 +1161,8 @@ export class HomeComponent implements OnInit, AfterViewInit {
// toastPoppedUp = true;
// continue;
// } else {
this.delete(entity);
itemDeleted = true;
this.delete(entity);
itemDeleted = true;
// }
}

Expand Down Expand Up @@ -1464,11 +1487,13 @@ export class HomeComponent implements OnInit, AfterViewInit {
this.contextMenuItems[0].disabled = true;
this.contextMenuItems[4].disabled = true;
this.contextMenuItems[6].disabled = true;
this.contextMenuItems[7].disabled = true;
}
else {
this.contextMenuItems[0].disabled = false;
this.contextMenuItems[4].disabled = false;
this.contextMenuItems[6].disabled = false;
this.contextMenuItems[7].disabled = false;
}

if (node.Selected) {
Expand All @@ -1477,8 +1502,10 @@ export class HomeComponent implements OnInit, AfterViewInit {
if (this.getSelected().length === 1) {
if (node.Type === 'folder') {
this.contextMenuItems[6].disabled = true;
this.contextMenuItems[7].disabled = true;
} else {
this.contextMenuItems[6].disabled = false;
this.contextMenuItems[7].disabled = false;
if (node.SafeLock) {
this.contextMenuItems[6] = {
label: 'Remove Lock',
Expand Down Expand Up @@ -1792,7 +1819,7 @@ export class HomeComponent implements OnInit, AfterViewInit {

handleTouchEnd(event: any, obj: any, type: string) {
if (this.touchObj == obj) {
if(this.contextMenuVisible) {
if (this.contextMenuVisible) {
this.contextMenuVisible = false;
this.contextMenu.hide();
return;
Expand Down Expand Up @@ -1821,7 +1848,7 @@ export class HomeComponent implements OnInit, AfterViewInit {
}

handleDirectoryRightClick(event: any) {
if(this.getSelected().length > 0) return;
if (this.getSelected().length > 0) return;
this.contextMenu.hide();
this.contextMenuItems[0].disabled = true;
this.contextMenuItems[3].disabled = true;
Expand All @@ -1841,11 +1868,45 @@ export class HomeComponent implements OnInit, AfterViewInit {
},
};
this.contextMenuItems[6].disabled = true;
this.contextMenuItems[7].disabled = true;
this.contextMenu.cd.detectChanges();
this.contextMenuVisible = true;
this.contextMenu.position(event);
this.contextMenu.show(event);
}

async shareDocument() {
const selected = this.getSelected()[0];
console.log(selected);
if (selected.length > 1 || selected.type === 'folder') {
return;
}

if (this.recipientEmail === '') {
this.messageService.add({
severity: 'error',
summary: 'Error',
detail: 'Please enter a recipient email',
});
return;
}
else {
this.loading = true;
await this.fileService.shareDocument(selected.MarkdownID, this.recipientEmail).then((data) => {
if (data) {
this.messageService.add({
severity: 'success',
summary: 'Success',
detail: 'Document shared successfully',
});
this.sharePopup = false;
this.recipientEmail = '';
}
this.loading = false;
});
this.loading = false;
}
}

protected readonly focus = focus;
}

0 comments on commit b6e87af

Please sign in to comment.