# FilesService

**Kind:** Class

**Source:** `Pams/Web/Pams.Web/Client/app/services/common/files.service.ts` (line 34)

**Part of:** [Pams](subsystem-pams)

`FilesService` manages file-related client operations in the PAMS web application. It supports file type and extension handling, upload popup state, file retrieval, tag lookup, and download actions.

## Methods

| Method | Signature | Returns |
|---|---|---|
| `extractFilesExtension` | `extractFilesExtension(fileName: string, fileType: string)` | `string` |
| `getTypesList` | `getTypesList()` | `any[]` |
| `fetchDownloadFilePath` | `fetchDownloadFilePath(APIUrl: string)` | `number` |
| `openUploadFilePopup` | `openUploadFilePopup(relatedToId: number, relatedToTypeId: number, companyBranchId: number, parentFileID: number, supplierId: number)` | `void` |
| `closeUploadPopup` | `closeUploadPopup()` | `void` |
| `openUploadLogoPopup` | `openUploadLogoPopup()` | `void` |
| `GetFilesByParentFileID` | `GetFilesByParentFileID(CompanyBranchID: number, ParentFileID: number, listNum: number, startRecord: number, pageSize: number, filter: string)` | `void` |
| `GetTagsListByType` | `GetTagsListByType(CompanyBranchID: number, listNum: number, supplierId: number)` | `void` |
| `DownloadFiles` | `DownloadFiles(IDs: number[])` | `void` |
| `getFilesByIdService` | `getFilesByIdService(id: number)` | `void` |
| `LoadtAttached` | `LoadtAttached(id: number, type: number)` | `void` |
| `unAttachFile` | `unAttachFile(id: undefined, type: undefined, fileID: undefined)` | `void` |
| `LoadAttachments` | `LoadAttachments(id: number, type: number)` | `void` |
| `LoadAllDocuments` | `LoadAllDocuments(type: number)` | `void` |
| `getUsersPermission` | `getUsersPermission(relatedToId: number, relatedToTypeId: number)` | `void` |
| `getOneDriveFilesList` | `getOneDriveFilesList(parentId: string)` | `void` |
| `ShareFile` | `ShareFile(entity: OneDriveShareFiles)` | `void` |
| `ShareFiles` | `ShareFiles(entity: OneDriveShareFiles[])` | `void` |
| `UploadFile` | `UploadFile(entity: FileData, acctualFile: File)` | `void` |
| `UploadFiles` | `UploadFiles(entity: FileData[], acctualFiles: File[])` | `void` |
| `UploadDataFile` | `UploadDataFile(entity: FileData)` | `void` |
| `UploadDataFiles` | `UploadDataFiles(entity: FileData[])` | `void` |
| `_UploadFiles` | `_UploadFiles(entities: FileData[], acctualFiles: File[])` | `void` |
| `newUploadFile` | `newUploadFile(entities: FileData, acctualFile: File)` | `void` |
| `saveFilesService` | `saveFilesService(entity: FileData)` | `void` |
| `newSaveFiles` | `newSaveFiles(entities: FileData[])` | `void` |
| `AttachFiles` | `AttachFiles(RelatedToID: number, RelatedToType: number, FilesIDList: number[])` | `void` |
| `AttachSharedFiles` | `AttachSharedFiles(files: AttachedfileView[])` | `void` |
| `UploadWordTemplate` | `UploadWordTemplate(acctualFile: File)` | `void` |
| `UploadFileByModule` | `UploadFileByModule(entity: FileData, acctualFile: File, moduleId: number)` | `void` |
| `DownloadImage` | `DownloadImage(id: string, fileTypeId: number, ApiUrl: string)` | `void` |
| `deleteFilesService` | `deleteFilesService(IDs: number[])` | `void` |
| `getRolesByLibraryId` | `getRolesByLibraryId(LibraryId: number)` | `void` |
| `getPermissionsByLibraryId` | `getPermissionsByLibraryId(LibraryId: number)` | `void` |
| `saveLibraryRoles` | `saveLibraryRoles(LibraryRoles: FilesRoles[])` | `void` |
| `downloadFile` | `downloadFile()` | `Observable<HttpResponse<Blob>>` |
| `getToken` | `getToken()` | `Observable<HttpResponse<string>>` |
| `getOldCloud` | `getOldCloud()` | `void` |
| `moveToNewCloud` | `moveToNewCloud(data: any[])` | `void` |
| `updateOldCloud` | `updateOldCloud(data: any[])` | `void` |

## Properties

| Property | Type |
|---|---|
| `headersProxy` | `any` |
| `TypesList` | `any[]` |
| `_uploadMultiPopupOpend` | `UploadFilePopup` |
| `uploadMultiPopupOpend` | `any` |
| `_uploadPopupOpend` | `boolean` |
| `uploadPopupOpend` | `any` |
| `_uploadLogoPopupOpend` | `boolean` |
| `uploadLogoPopupOpend` | `any` |

## Where it refuses work

- `FilesService` stops the work with an early return when `fileExtension.includes("jpeg") || fileExtension.includes("jpg") || fileExtension.includes…`.
- `FilesService` stops the work with an early return when `APIUrl.includes('production-api')`.

## Diagram

```mermaid
graph LR
  UI[Client Components] --> Service[FilesService]
  Service --> Popups[Upload and Logo Upload Popups]
  Service --> Types[File Types and Extensions]
  Service --> Files[File Retrieval]
  Service --> Tags[Tag Lookup]
  Service --> Downloads[File Downloads]
```

## Usage

```ts
import { FilesService } from './services/common/files.service';

export class FileManagerComponent {
  constructor(private readonly filesService: FilesService) {}

  showUploadDialog(): void {
    this.filesService.openUploadFilePopup();
  }

  closeUploadDialog(): void {
    this.filesService.closeUploadPopup();
  }

  getFileExtension(fileName: string): string {
    return this.filesService.extractFilesExtension(fileName);
  }

  loadFileTypes(): any[] {
    return this.filesService.getTypesList();
  }

  downloadSelectedFiles(): void {
    this.filesService.DownloadFiles();
  }
}
```

## AI Coding Instructions

- Keep upload dialog actions routed through `openUploadFilePopup`, `closeUploadPopup`, and `openUploadLogoPopup` rather than duplicating popup state in components.
- Use `extractFilesExtension` and `getTypesList` when validating or presenting file types in the client UI.
- Call `GetFilesByParentFileID` when loading files associated with a parent file record.
- Use `GetTagsListByType` for type-specific tag data and `getFilesByIdService` for file lookup by identifier.
- Keep download behavior inside `DownloadFiles` and `fetchDownloadFilePath` so components do not construct download paths directly.

## Used by

25 references from 25 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

### Imported by (25)

- `NewBranchComponent` — `Pams/Web/Pams.Web/Client/app/components/configuration/company/main-branch/new.branch.component.ts`:1
- `ProductCategoriesComponent` — `Pams/Web/Pams.Web/Client/app/components/configuration/products/product-categories/product-categories.component.ts`:1
- `NewActivityComponent` — `Pams/Web/Pams.Web/Client/app/components/dashboard/my-desk/activities/new-activity/new-activity.component.ts`:1
- `TopicComponent` — `Pams/Web/Pams.Web/Client/app/components/dashboard/my-desk/activities/topic/topic.component.ts`:1
- `MyDeskComponent` — `Pams/Web/Pams.Web/Client/app/components/dashboard/my-desk/my-desk.component.ts`:1
- `NewTasksComponent` — `Pams/Web/Pams.Web/Client/app/components/dashboard/my-desk/tasks/new-tasks/new-tasks.component.ts`:1
- `FilesComponent` — `Pams/Web/Pams.Web/Client/app/components/files/files.component.ts`:1
- `FileNameAndExtension` — `Pams/Web/Pams.Web/Client/app/components/files/upload-file/upload-file.component.ts`:1

…and 17 more.
