Skip to content

Commit

Permalink
Merge pull request #2471 from sam-warren/EMBCESSMOD-5590
Browse files Browse the repository at this point in the history
EMBCESSMOD-5590: UI changes for better UX in file uploader
  • Loading branch information
GeorgeWalker authored Oct 2, 2024
2 parents 23301f9 + 229fcba commit e2350b2
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 63 deletions.
59 changes: 52 additions & 7 deletions suppliers/src/UI/embc-supplier/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions suppliers/src/UI/embc-supplier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"@angular/platform-browser-dynamic": "^17.3.9",
"@angular/router": "^17.3.9",
"@bcgov/bootstrap-v5-theme": "^1.0.1",
"@fortawesome/angular-fontawesome": "^0.14.0",
"@fortawesome/fontawesome-free": "^5.13.0",
"@fortawesome/free-solid-svg-icons": "^6.6.0",
"@ng-bootstrap/ng-bootstrap": "^16.0.0",
"angular-oauth2-oidc": "^17.0.2",
"bootstrap": "^4.3.1",
Expand Down
2 changes: 1 addition & 1 deletion suppliers/src/UI/embc-supplier/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<app-toasts></app-toasts>
<app-header></app-header>

<main class="fill-body background">
Expand All @@ -8,7 +9,6 @@
@if (noticeMsg && !siteDown) {
<app-banner [bannerMsg]="noticeMsg" bannerType="Notice"></app-banner>
}

<router-outlet></router-outlet>
</div>
</main>
Expand Down
3 changes: 2 additions & 1 deletion suppliers/src/UI/embc-supplier/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { AuthenticationService } from './core/services/authentication.service';
import { ConfigService } from './core/services/config.service';
import { SupplierService } from './core/services/supplier.service';
import { SupplierHttpService } from './core/services/supplierHttp.service';
import { ToastsContainer } from './core/components/toasts/toasts-container.component';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
standalone: true,
imports: [BannerComponent, FooterComponent, HeaderComponent, RouterOutlet]
imports: [BannerComponent, FooterComponent, HeaderComponent, RouterOutlet, ToastsContainer]
})
export class AppComponent implements OnInit, OnDestroy {
title = 'embc-supplier';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<!-- <label class="requiredField" for="fileDrop">Attach a photo/scanned copy of your invoice</label> -->
@if (showToast) {
<div>
<app-toasts aria-live="polite" aria-atomic="true"></app-toasts>
</div>
}
<div class="drag-drop" appDragDrop (fileDropped)="onInvoiceDropped($event)">
<input
type="file"
Expand Down Expand Up @@ -34,8 +29,11 @@
@for (attach of invoiceAttachments; track attach; let fileIndex = $index) {
<div class="attach-list">
<div class="row file-style">
<p>{{ attach }}</p>
<i (click)="deleteAttachedInvoice(fileIndex)" class="fas fa-trash-alt"></i>
<div class="row">
<fa-icon class="file-icon" [icon]="getFileImage(attach)"></fa-icon>
<p>{{ attach }}</p>
</div>
<fa-icon class="click-icon" [icon]="faTrash" (click)="deleteAttachedInvoice(fileIndex)"></fa-icon>
</div>
</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@

.file-style {
justify-content: space-between;
padding-left: 9px;
padding-right: 9px;
padding-top: 5px;
padding-left: 20px;
padding-right: 20px;
}

.drag-text {
Expand Down Expand Up @@ -120,3 +121,12 @@
font-size: 13px;
font-weight: lighter;
}

.click-icon {
cursor: pointer;
}

.file-icon {
margin-left: 20px;
margin-right: 10px;
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import { Component, Output, EventEmitter, Input, OnInit } from '@angular/core';
import { ToastService } from 'src/app/core/services/toast.service';
import { Toast, ToastService } from 'src/app/core/services/toast.service';
import { WarningService } from 'src/app/core/services/warning.service';
import * as constant from 'src/app/core/services/globalConstants';
import { DragDropDirective } from '../../directives/DragDrop.directive';
import { ToastsComponent } from '../toasts/toasts.component';
import { faFileImage, faFilePdf, faTrash } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';

@Component({
selector: 'app-file-upload',
templateUrl: './fileUpload.component.html',
styleUrls: ['./fileUpload.component.scss'],
standalone: true,
imports: [ToastsComponent, DragDropDirective]
imports: [DragDropDirective, FontAwesomeModule]
})
export class FileUploadComponent implements OnInit {
@Output() attachedFile = new EventEmitter<any>();
@Output() deleteFile = new EventEmitter<any>();
@Input() reloadedFiles: any;
@Input() noOfAttachments: number;
showToast = false;
invoiceAttachments: string[] = [];
attachSizeError = false;
faTrash = faTrash;
faFilePdf = faFilePdf;
faFileImage = faFileImage;

constructor(
public toastService: ToastService,
Expand All @@ -41,9 +44,6 @@ export class FileUploadComponent implements OnInit {
* @param event : File drop event
*/
onInvoiceDropped(event: any) {
if (this.showToast) {
this.showToast = !this.showToast;
}
if (this.attachSizeError) {
this.attachSizeError = !this.attachSizeError;
}
Expand Down Expand Up @@ -72,6 +72,7 @@ export class FileUploadComponent implements OnInit {
} else {
this.invoiceAttachments.push(e.name);
this.attachedFile.emit(e);
this.toastService.show(e.name + " uploaded successfully", { classname: 'bg-success text-light', delay: 3000, })
}
}
}
Expand All @@ -85,4 +86,12 @@ export class FileUploadComponent implements OnInit {
this.invoiceAttachments.splice(fileIndex, 1);
this.deleteFile.emit(fileIndex);
}

getFileImage(file: string) {
if (file.includes('.pdf')) {
return faFilePdf;
} else {
return faFileImage;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="toast-container">
@for (toast of toastService.toasts; track toast) {
<ngb-toast
[class]="toast.classname"
[autohide]="true"
[delay]="toast.delay || 5000"
(hidden)="toastService.remove(toast)"
>
{{ toast.text }}
<fa-icon class="close-icon" [icon]="closeIcon" (click)="toastService.remove(toast)"></fa-icon>
</ngb-toast>
}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.toast-container {
z-index: 1200;
top: 0 !important;
right: 0 !important;
position: fixed;
padding: 10px;

.close-icon {
cursor: pointer;
margin-left: 5px;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component, inject } from '@angular/core';

import { ToastService } from "../../services/toast.service";
import { NgTemplateOutlet } from '@angular/common';
import { NgbToastModule } from '@ng-bootstrap/ng-bootstrap';
import { faXmark } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';

@Component({
selector: 'app-toasts',
standalone: true,
imports: [NgbToastModule, NgTemplateOutlet, FontAwesomeModule],
templateUrl: "./toasts-container.component.html",
styleUrls: ["./toasts-container.component.scss"]
})

export class ToastsContainer {
closeIcon = faXmark;
toastService = inject(ToastService);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { Injectable, TemplateRef } from '@angular/core';
import { Injectable } from '@angular/core';

export interface Toast {
text: string;
classname?: string;
delay?: number;
}

@Injectable({ providedIn: 'root' })
export class ToastService {
toasts: any[] = [];
toasts: Toast[] = [];

show(textOrTpl: string | TemplateRef<any>, options: any = {}) {
this.toasts.push({ textOrTpl, ...options });
show(text: string, options: Partial<Toast> = {}) {
this.toasts.push({ text, ...options });
}

remove(toast) {
remove(toast: Toast) {
this.toasts = this.toasts.filter((t) => t !== toast);
}

clear() {
this.toasts.splice(0, this.toasts.length);
}
}

0 comments on commit e2350b2

Please sign in to comment.