# FilesService

**Kind:** Class

**Source:** `Frontend/src/app/services/common/files.service.ts` (line 33)

**Part of:** [Frontend](subsystem-frontend-src-app)

`FilesService` manages file-related UI actions and data requests in the frontend. It handles upload popup state, file metadata lookups, parent-file queries, tag and category retrieval, 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` |
| `GetCategoriesList` | `GetCategoriesList()` | `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)` | `void` |
| `revokeObjectURL` | `revokeObjectURL(url: string)` | `void` |
| `deleteFilesService` | `deleteFilesService(IDs: number[])` | `void` |
| `getRolesByLibraryId` | `getRolesByLibraryId(LibraryId: number)` | `void` |
| `getPermissionsByLibraryId` | `getPermissionsByLibraryId(LibraryId: number)` | `void` |
| `saveLibraryRoles` | `saveLibraryRoles(LibraryRoles: FilesRoles[])` | `void` |
| `getOldCloud` | `getOldCloud()` | `void` |
| `moveToNewCloud` | `moveToNewCloud(data: any[])` | `void` |
| `updateOldCloud` | `updateOldCloud(data: any[])` | `void` |
| `updateFileCategory` | `updateFileCategory(fileCategory: EditAttachedCategory)` | `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
  Component --> FilesService
  FilesService --> UploadPopup[Upload Popup]
  FilesService --> LogoUploadPopup[Logo Upload Popup]
  FilesService --> FileMetadata[File Types and Extensions]
  FilesService --> FileQueries[Files, Tags, Categories]
  FilesService --> Download[Download Files]
```

## Usage

```ts
import { Component } from '@angular/core';
import { FilesService } from '../services/common/files.service';

@Component({
  selector: 'app-file-manager',
  template: `
    <button (click)="openUpload()">Upload file</button>
    <button (click)="download()">Download</button>
  `
})
export class FileManagerComponent {
  constructor(private readonly filesService: FilesService) {}

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

  download(): void {
    this.filesService.DownloadFiles();
  }

  loadFileMetadata(): void {
    const extension = this.filesService.extractFilesExtension();
    const types = this.filesService.getTypesList();

    console.log({ extension, types });
  }
}
```

## AI Coding Instructions

- Keep file popup actions inside `FilesService` by calling `openUploadFilePopup`, `closeUploadPopup`, or `openUploadLogoPopup` from components.
- Use `extractFilesExtension` and `getTypesList` when preparing file upload or filtering UI state.
- Call `GetFilesByParentFileID`, `GetTagsListByType`, and `GetCategoriesList` through this service rather than duplicating file lookup logic in components.
- Keep download behavior routed through `DownloadFiles` and path-related handling through `fetchDownloadFilePath`.

## Used by

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

### Imported by (37)

- `MrqDetailsComponent` — `Frontend/src/app/components/MRQ/mrq-details/mrq-details.component.ts`:1
- `BillOfMaterialsDetailsComponent` — `Frontend/src/app/components/bill-of-materials/bill-of-materials-details/bill-of-materials-details.component.ts`:1
- `NewBranchComponent` — `Frontend/src/app/components/configuration/company/main-branch/new.branch.component.ts`:1
- `ProductCategoriesComponent` — `Frontend/src/app/components/configuration/products/product-categories/product-categories.component.ts`:1
- `ProductsDetailsComponent` — `Frontend/src/app/components/configuration/products/products-details/products-details.component.ts`:1
- `OverallAnalysisYearMap` — `Frontend/src/app/components/dashboard/_principalReport/principal-report.component.ts`:1
- `NewActivityComponent` — `Frontend/src/app/components/dashboard/my-desk/activities/new-activity/new-activity.component.ts`:1
- `TopicComponent` — `Frontend/src/app/components/dashboard/my-desk/activities/topic/topic.component.ts`:1

…and 29 more.
