]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/octal-to-human-readable.pipe.ts
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / pipes / octal-to-human-readable.pipe.ts
1 import { Pipe, PipeTransform } from '@angular/core';
2
3 @Pipe({
4 name: 'octalToHumanReadable'
5 })
6 export class OctalToHumanReadablePipe implements PipeTransform {
7 transform(value: number, toTableArray = false): any {
8 if (!value) {
9 return [];
10 }
11 const permissionSummary = [];
12 const permissions = ['---', '--x', '-w-', '-wx', 'r--', 'r-x', 'rw-', 'rwx'];
13 const octal = value.toString(8).padStart(7, '0');
14 const digits = octal.split('');
15
16 const fileType = this.getFileTypeSymbol(parseInt(digits[1] + digits[2]));
17 const owner = permissions[parseInt(digits[4])];
18 const group = permissions[parseInt(digits[5])];
19 const others = permissions[parseInt(digits[6])];
20
21 if (toTableArray) {
22 return {
23 owner: this.getItem(owner),
24 group: this.getItem(group),
25 others: this.getItem(others)
26 };
27 }
28
29 if (fileType !== 'directory') {
30 permissionSummary.push({
31 content: fileType,
32 class: 'badge-primary me-1'
33 });
34 }
35
36 if (owner !== '---') {
37 permissionSummary.push({
38 content: `owner: ${owner}`,
39 class: 'badge-primary me-1'
40 });
41 }
42
43 if (group !== '---') {
44 permissionSummary.push({
45 content: `group: ${group}`,
46 class: 'badge-primary me-1'
47 });
48 }
49
50 if (others !== '---') {
51 permissionSummary.push({
52 content: `others: ${others}`,
53 class: 'badge-primary me-1'
54 });
55 }
56
57 if (permissionSummary.length === 0) {
58 return [
59 {
60 content: 'no permissions',
61 class: 'badge-warning me-1',
62 toolTip: `owner: ${owner}, group: ${group}, others: ${others}`
63 }
64 ];
65 }
66
67 return permissionSummary;
68 }
69
70 private getFileTypeSymbol(fileType: number): string {
71 switch (fileType) {
72 case 1:
73 return 'fifo';
74 case 2:
75 return 'character';
76 case 4:
77 return 'directory';
78 case 6:
79 return 'block';
80 case 10:
81 return 'regular';
82 case 12:
83 return 'symbolic-link';
84 default:
85 return '-';
86 }
87 }
88
89 private getItem(item: string) {
90 const returnlist = [];
91 if (item.includes('r')) returnlist.push('read');
92 if (item.includes('w')) returnlist.push('write');
93 if (item.includes('x')) returnlist.push('execute');
94 return returnlist;
95 }
96 }