projects/web-mev/src/app/shared/models/file.ts
File or Resource
Resource instance is created when MEV users upload files. Resource instances are initially "unattached" meaning they are associated with their owner, but have not been associated with any user workspaces. Admins can, however, specify a Workspace in their request to create the Resource directly via the API.
Properties |
|
constructor(id: string, url: string, name: string, resource_type: string, readable_resource_type: string, owner_email: string, is_active: boolean, is_public: boolean, status: string, workspaces: Workspace[], created: Date, size: number)
|
| Public created |
Type : Date
|
| Public id |
Type : string
|
| Public is_active |
Type : boolean
|
| Public is_public |
Type : boolean
|
| Public name |
Type : string
|
| Public owner_email |
Type : string
|
| Public readable_resource_type |
Type : string
|
| Public resource_type |
Type : string
|
| Public size |
Type : number
|
| Public status |
Type : string
|
| Public url |
Type : string
|
| Public workspaces |
Type : Workspace[]
|
import { Injectable } from '@angular/core';
import { Workspace } from '@app/features/workspace-manager/models/workspace';
/**
* File or Resource
*
* Resource instance is created when MEV users upload files.
* Resource instances are initially "unattached" meaning they are associated with their owner,
* but have not been associated with any user workspaces.
* Admins can, however, specify a Workspace in their request to create the Resource directly via the API.
*/
export class File {
constructor(
public id: string,
public url: string,
public name: string,
public resource_type: string, // FileType
public readable_resource_type: string,
public owner_email: string,
public is_active: boolean,
public is_public: boolean,
public status: string,
public workspaces: Workspace[],
public created: Date,
public size: number
) {}
}
@Injectable({
providedIn: 'root'
})
export class FileAdapter {
adapt(item: any): File {
const re = /[()]/g;
const created_formatted = item.created.replace(re, '');
const workspace_names = item.workspaces
.map(ws => ws.workspace_name)
.join(', ');
return new File(
item.id,
item.url,
item.name,
item.resource_type,
item.readable_resource_type,
item.owner_email,
item.is_active,
item.is_public,
item.status,
workspace_names,
new Date(created_formatted),
item.size
);
}
}