@iobroker/adapter-react-v5 6.1.10 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Components/404.js +13 -13
- package/Components/Loader.js +223 -223
- package/Components/Loaders/PT.css +108 -108
- package/Components/Loaders/PT.js +103 -103
- package/Components/Loaders/Vendor.css +13 -13
- package/Components/Loaders/Vendor.js +7 -7
- package/Components/ObjectBrowser.js +29 -29
- package/Components/UploadImage.js +305 -305
- package/Components/loader.css +221 -221
- package/Components/types.d.ts +82 -82
- package/GenericApp.js +49 -49
- package/LICENSE +22 -22
- package/Prompt.js +7 -7
- package/README.md +1004 -1005
- package/Theme.js +8 -7
- package/assets/devices/Alarm Systems.svg +18 -18
- package/assets/devices/Amplifier.svg +21 -21
- package/assets/devices/Awnings.svg +4 -4
- package/assets/devices/Battery Status.svg +4 -4
- package/assets/devices/Ceiling Spotlights.svg +15 -15
- package/assets/devices/Chandelier.svg +6 -6
- package/assets/devices/Climate.svg +11 -11
- package/assets/devices/Coffee Makers.svg +5 -5
- package/assets/devices/Cold Water.svg +31 -31
- package/assets/devices/Computer.svg +21 -21
- package/assets/devices/Consumption.svg +7 -7
- package/assets/devices/Curtains.svg +43 -43
- package/assets/devices/Dishwashers.svg +11 -11
- package/assets/devices/Doors.svg +5 -5
- package/assets/devices/Doorstep.svg +35 -35
- package/assets/devices/Dryer.svg +13 -13
- package/assets/devices/Fan.svg +20 -20
- package/assets/devices/Floor Lamps.svg +4 -4
- package/assets/devices/Garage Doors.svg +9 -9
- package/assets/devices/Gates.svg +32 -32
- package/assets/devices/Hairdryer.svg +23 -23
- package/assets/devices/Handle.svg +6 -6
- package/assets/devices/Hanging Lamps.svg +8 -8
- package/assets/devices/Heater.svg +44 -44
- package/assets/devices/Hoods.svg +11 -11
- package/assets/devices/Hot Water.svg +9 -9
- package/assets/devices/Humidity.svg +41 -41
- package/assets/devices/Iron.svg +4 -4
- package/assets/devices/Irrigation.svg +22 -22
- package/assets/devices/Led Strip.svg +30 -30
- package/assets/devices/Light.svg +29 -29
- package/assets/devices/Lightings.svg +46 -46
- package/assets/devices/Lock.svg +19 -19
- package/assets/devices/Louvre.svg +6 -6
- package/assets/devices/Mowing Machine.svg +8 -8
- package/assets/devices/Music.svg +12 -12
- package/assets/devices/Outdoor Blinds.svg +6 -6
- package/assets/devices/People.svg +19 -19
- package/assets/devices/Pool.svg +7 -7
- package/assets/devices/Power Consumption.svg +12 -12
- package/assets/devices/Printer.svg +9 -9
- package/assets/devices/Pump.svg +9 -9
- package/assets/devices/Receiver.svg +18 -18
- package/assets/devices/Sconces.svg +9 -9
- package/assets/devices/Security.svg +34 -34
- package/assets/devices/Shading.svg +4 -4
- package/assets/devices/Shutters.svg +10 -10
- package/assets/devices/SmokeDetector.svg +12 -12
- package/assets/devices/Sockets.svg +13 -13
- package/assets/devices/Speaker.svg +35 -35
- package/assets/devices/Stove.svg +11 -11
- package/assets/devices/Table Lamps.svg +11 -11
- package/assets/devices/Temperature Sensors.svg +28 -28
- package/assets/devices/Tv.svg +7 -7
- package/assets/devices/Vacuum Cleaner.svg +15 -15
- package/assets/devices/Ventilation.svg +12 -12
- package/assets/devices/Washing Machines.svg +15 -15
- package/assets/devices/Water Consumption.svg +5 -5
- package/assets/devices/Water Heater.svg +8 -8
- package/assets/devices/Water.svg +40 -40
- package/assets/devices/Weather.svg +28 -28
- package/assets/devices/Window.svg +7 -7
- package/assets/lamp_ceiling.svg +8 -8
- package/assets/lamp_table.svg +7 -7
- package/assets/no_icon.svg +9 -9
- package/assets/rooms/Anteroom.svg +52 -52
- package/assets/rooms/Attic.svg +21 -21
- package/assets/rooms/Balcony.svg +12 -12
- package/assets/rooms/Barn.svg +5 -5
- package/assets/rooms/Basement.svg +4 -4
- package/assets/rooms/Bathroom.svg +38 -38
- package/assets/rooms/Bedroom.svg +5 -5
- package/assets/rooms/Boiler Room.svg +12 -12
- package/assets/rooms/Carport.svg +17 -17
- package/assets/rooms/Cellar.svg +89 -89
- package/assets/rooms/Chamber.svg +9 -9
- package/assets/rooms/Corridor.svg +52 -52
- package/assets/rooms/Dining Area.svg +37 -37
- package/assets/rooms/Dining Room.svg +37 -37
- package/assets/rooms/Dining.svg +37 -37
- package/assets/rooms/Dressing Room.svg +4 -4
- package/assets/rooms/Driveway.svg +14 -14
- package/assets/rooms/Entrance.svg +44 -44
- package/assets/rooms/Equipment Room.svg +14 -14
- package/assets/rooms/Front Yard.svg +64 -64
- package/assets/rooms/Gallery.svg +13 -13
- package/assets/rooms/Garage.svg +20 -20
- package/assets/rooms/Garden.svg +12 -12
- package/assets/rooms/Ground Floor.svg +95 -95
- package/assets/rooms/Guest Bathroom.svg +32 -32
- package/assets/rooms/Guest Room.svg +5 -5
- package/assets/rooms/Gym.svg +4 -4
- package/assets/rooms/Hall.svg +19 -19
- package/assets/rooms/Home Theater.svg +7 -7
- package/assets/rooms/Kitchen.svg +17 -17
- package/assets/rooms/Laundry Room.svg +11 -11
- package/assets/rooms/Living Area.svg +10 -10
- package/assets/rooms/Living Room.svg +10 -10
- package/assets/rooms/Locker Room.svg +16 -16
- package/assets/rooms/Nursery.svg +4 -4
- package/assets/rooms/Office.svg +8 -8
- package/assets/rooms/Outdoors.svg +7 -7
- package/assets/rooms/Playroom.svg +5 -5
- package/assets/rooms/Pool.svg +7 -7
- package/assets/rooms/Rear Wall.svg +30 -30
- package/assets/rooms/Second Floor.svg +95 -95
- package/assets/rooms/Shed.svg +16 -16
- package/assets/rooms/Sleeping Area.svg +22 -22
- package/assets/rooms/Stairway.svg +4 -4
- package/assets/rooms/Stairwell.svg +15 -15
- package/assets/rooms/Storeroom.svg +4 -4
- package/assets/rooms/Summer House.svg +27 -27
- package/assets/rooms/Swimming Pool.svg +21 -21
- package/assets/rooms/Terrace.svg +6 -6
- package/assets/rooms/Toilet.svg +10 -10
- package/assets/rooms/Upstairs.svg +5 -5
- package/assets/rooms/Wardrobe.svg +60 -60
- package/assets/rooms/Washroom.svg +19 -19
- package/assets/rooms/Wc.svg +10 -10
- package/assets/rooms/Windscreen.svg +60 -60
- package/assets/rooms/Workshop.svg +22 -22
- package/assets/rooms/Workspace.svg +8 -8
- package/craco-module-federation.js +71 -71
- package/icons/IconFx.js +1 -1
- package/icons/IconLogout.js +1 -1
- package/index.css +54 -54
- package/modulefederation.admin.config.js +31 -31
- package/package.json +4 -4
- package/src/AdminConnection.tsx +3 -3
- package/src/Components/404.tsx +121 -121
- package/src/Components/ColorPicker.tsx +315 -315
- package/src/Components/ComplexCron.tsx +507 -507
- package/src/Components/CopyToClipboard.tsx +165 -165
- package/src/Components/CustomModal.tsx +163 -163
- package/src/Components/FileBrowser.tsx +2414 -2414
- package/src/Components/FileViewer.tsx +393 -393
- package/src/Components/Icon.tsx +210 -210
- package/src/Components/IconPicker.tsx +149 -149
- package/src/Components/IconSelector.tsx +2202 -2202
- package/src/Components/Image.tsx +176 -176
- package/src/Components/Loader.tsx +304 -304
- package/src/Components/Logo.tsx +166 -166
- package/src/Components/MDUtils.tsx +100 -100
- package/src/Components/ObjectBrowser.tsx +8032 -8032
- package/src/Components/Router.tsx +90 -90
- package/src/Components/SaveCloseButtons.tsx +113 -113
- package/src/Components/Schedule.tsx +1724 -1724
- package/src/Components/SelectWithIcon.tsx +197 -197
- package/src/Components/TabContainer.tsx +55 -55
- package/src/Components/TabContent.tsx +37 -37
- package/src/Components/TabHeader.tsx +19 -19
- package/src/Components/TableResize.tsx +259 -259
- package/src/Components/TextWithIcon.tsx +148 -148
- package/src/Components/ToggleThemeMenu.tsx +34 -34
- package/src/Components/TreeTable.tsx +919 -919
- package/src/Components/UploadImage.tsx +599 -599
- package/src/Components/Utils.tsx +1794 -1794
- package/src/Components/loader.css +221 -221
- package/src/Components/withWidth.tsx +21 -21
- package/src/Connection.tsx +7 -7
- package/src/Dialogs/ComplexCron.tsx +129 -129
- package/src/Dialogs/Confirm.tsx +162 -162
- package/src/Dialogs/Cron.tsx +182 -182
- package/src/Dialogs/Error.tsx +72 -72
- package/src/Dialogs/Message.tsx +71 -71
- package/src/Dialogs/SelectFile.tsx +270 -270
- package/src/Dialogs/SelectID.tsx +298 -298
- package/src/Dialogs/SimpleCron.tsx +100 -100
- package/src/Dialogs/TextInput.tsx +107 -107
- package/src/GenericApp.tsx +976 -976
- package/src/LegacyConnection.tsx +3589 -3589
- package/src/Prompt.tsx +20 -20
- package/src/Theme.tsx +479 -479
- package/src/icons/IconAdapter.tsx +20 -20
- package/src/icons/IconAlias.tsx +20 -20
- package/src/icons/IconChannel.tsx +21 -21
- package/src/icons/IconClearFilter.tsx +22 -22
- package/src/icons/IconClosed.tsx +17 -17
- package/src/icons/IconCopy.tsx +16 -16
- package/src/icons/IconDevice.tsx +27 -27
- package/src/icons/IconDocument.tsx +17 -17
- package/src/icons/IconDocumentReadOnly.tsx +18 -18
- package/src/icons/IconExpert.tsx +18 -18
- package/src/icons/IconFx.tsx +36 -36
- package/src/icons/IconInstance.tsx +20 -20
- package/src/icons/IconLogout.tsx +30 -30
- package/src/icons/IconNoIcon.tsx +19 -19
- package/src/icons/IconOpen.tsx +17 -17
- package/src/icons/IconProps.tsx +15 -15
- package/src/icons/IconState.tsx +17 -17
- package/src/index.css +54 -54
- package/types.d.ts +134 -134
|
@@ -1,393 +1,393 @@
|
|
|
1
|
-
// File viewer in adapter-react does not support write
|
|
2
|
-
// import { Buffer } from 'buffer';
|
|
3
|
-
import React, { Component } from 'react';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
TextField,
|
|
7
|
-
Button,
|
|
8
|
-
Dialog,
|
|
9
|
-
DialogActions,
|
|
10
|
-
DialogContent,
|
|
11
|
-
DialogTitle,
|
|
12
|
-
IconButton,
|
|
13
|
-
} from '@mui/material';
|
|
14
|
-
|
|
15
|
-
// Icons
|
|
16
|
-
import { FaCopy as CopyIcon } from 'react-icons/fa';
|
|
17
|
-
import {
|
|
18
|
-
Close as CloseIcon,
|
|
19
|
-
Save as SaveIcon,
|
|
20
|
-
Brightness6 as Brightness5Icon,
|
|
21
|
-
} from '@mui/icons-material';
|
|
22
|
-
|
|
23
|
-
import type { Connection } from '@iobroker/socket-client';
|
|
24
|
-
|
|
25
|
-
import IconNoIcon from '../icons/IconNoIcon';
|
|
26
|
-
import withWidth from './withWidth';
|
|
27
|
-
import Utils from './Utils';
|
|
28
|
-
import { Translate } from '../types';
|
|
29
|
-
import Icon from './Icon';
|
|
30
|
-
// File viewer in adapter-react does not use ace editor
|
|
31
|
-
// import * as ace from 'ace-builds';
|
|
32
|
-
// import 'ace-builds/src-noconflict/ext-modelist';
|
|
33
|
-
// import Editor from './Editor';
|
|
34
|
-
|
|
35
|
-
// const modelist = ace.require('ace/ext/modelist');
|
|
36
|
-
|
|
37
|
-
const styles: Record<string, React.CSSProperties> = {
|
|
38
|
-
dialog: {
|
|
39
|
-
height: '100%',
|
|
40
|
-
},
|
|
41
|
-
paper: {
|
|
42
|
-
height: 'calc(100% - 64px)',
|
|
43
|
-
},
|
|
44
|
-
content: {
|
|
45
|
-
textAlign: 'center',
|
|
46
|
-
},
|
|
47
|
-
textarea: {
|
|
48
|
-
width: '100%',
|
|
49
|
-
height: '100%',
|
|
50
|
-
},
|
|
51
|
-
img: {
|
|
52
|
-
width: 'auto',
|
|
53
|
-
height: 'calc(100% - 5px)',
|
|
54
|
-
objectFit: 'contain',
|
|
55
|
-
},
|
|
56
|
-
dialogTitle: {
|
|
57
|
-
justifyContent: 'space-between',
|
|
58
|
-
display: 'flex',
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export const EXTENSIONS = {
|
|
63
|
-
images: ['png', 'jpg', 'svg', 'jpeg', 'bmp', 'gif', 'apng', 'avif', 'webp'],
|
|
64
|
-
code: ['js', 'json', 'json5', 'md'],
|
|
65
|
-
txt: ['log', 'txt', 'html', 'css', 'xml', 'ics'],
|
|
66
|
-
audio: ['mp3', 'wav', 'ogg', 'acc'],
|
|
67
|
-
video: ['mp4', 'mov', 'avi'],
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
function bufferToBase64(buffer: Buffer, isFull?: boolean) {
|
|
71
|
-
let binary = '';
|
|
72
|
-
const bytes = new Uint8Array(buffer);
|
|
73
|
-
const len = bytes.byteLength;
|
|
74
|
-
for (let i = 0; i < len && (isFull || i < 50); i++) {
|
|
75
|
-
binary += String.fromCharCode(bytes[i]);
|
|
76
|
-
}
|
|
77
|
-
return window.btoa(binary);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
interface FileViewerProps {
|
|
81
|
-
/** Translation function */
|
|
82
|
-
t: Translate;
|
|
83
|
-
/** Callback when the viewer is closed. */
|
|
84
|
-
onClose: () => void;
|
|
85
|
-
/** The URL (file path) to the file to be displayed. */
|
|
86
|
-
href: string;
|
|
87
|
-
// formatEditFile?: string;
|
|
88
|
-
socket: Connection;
|
|
89
|
-
setStateBackgroundImage: () => void;
|
|
90
|
-
// themeType: ThemeType;
|
|
91
|
-
getStyleBackgroundImage: () => React.CSSProperties | null;
|
|
92
|
-
/** Flag is the js-controller support subscribe on file */
|
|
93
|
-
supportSubscribes?: boolean;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
interface FileViewerState {
|
|
97
|
-
text: string | null;
|
|
98
|
-
code: string | null;
|
|
99
|
-
ext: string | null;
|
|
100
|
-
editing: boolean;
|
|
101
|
-
editingValue: string | null;
|
|
102
|
-
copyPossible: boolean;
|
|
103
|
-
forceUpdate: number;
|
|
104
|
-
changed: boolean;
|
|
105
|
-
imgError: boolean;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
class FileViewer extends Component<FileViewerProps, FileViewerState> {
|
|
109
|
-
private timeout: ReturnType<typeof setTimeout> | null = null;
|
|
110
|
-
|
|
111
|
-
constructor(props: FileViewerProps) {
|
|
112
|
-
super(props);
|
|
113
|
-
const ext = Utils.getFileExtension(props.href);
|
|
114
|
-
|
|
115
|
-
this.state = {
|
|
116
|
-
text: null,
|
|
117
|
-
code: null,
|
|
118
|
-
ext,
|
|
119
|
-
// File viewer in adapter-react does not support write
|
|
120
|
-
editing: /* !!this.props.formatEditFile || */ false,
|
|
121
|
-
editingValue: null,
|
|
122
|
-
copyPossible: !!ext && (EXTENSIONS.code.includes(ext) || EXTENSIONS.txt.includes(ext)),
|
|
123
|
-
forceUpdate: Date.now(),
|
|
124
|
-
changed: false,
|
|
125
|
-
imgError: false,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
readFile() {
|
|
130
|
-
if (this.props.href) {
|
|
131
|
-
const parts = this.props.href.split('/');
|
|
132
|
-
parts.splice(0, 2);
|
|
133
|
-
const adapter = parts[0];
|
|
134
|
-
const name = parts.splice(1).join('/');
|
|
135
|
-
|
|
136
|
-
this.props.socket.readFile(adapter, name)
|
|
137
|
-
.then((data: { data: Buffer; type: string } | { file: string; mimeType: string }) => {
|
|
138
|
-
let fileData: string = '';
|
|
139
|
-
if ((data as { file: string; mimeType: string }).file !== undefined) {
|
|
140
|
-
fileData = (data as { file: string; mimeType: string }).file;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const newState: Partial<FileViewerState> = { copyPossible: this.state.copyPossible, ext: this.state.ext };
|
|
144
|
-
// try to detect valid extension
|
|
145
|
-
if ((data as { data: Buffer; type: string }).type === 'Buffer') {
|
|
146
|
-
if (name.toLowerCase().endsWith('.json5')) {
|
|
147
|
-
newState.ext = 'json5';
|
|
148
|
-
newState.copyPossible = true;
|
|
149
|
-
try {
|
|
150
|
-
fileData = atob(bufferToBase64((data as { data: Buffer; type: string }).data, true));
|
|
151
|
-
} catch {
|
|
152
|
-
console.error('Cannot convert base64 to string');
|
|
153
|
-
fileData = '';
|
|
154
|
-
}
|
|
155
|
-
} else {
|
|
156
|
-
const ext = Utils.detectMimeType(bufferToBase64((data as { data: Buffer; type: string }).data));
|
|
157
|
-
if (ext) {
|
|
158
|
-
newState.ext = ext;
|
|
159
|
-
newState.copyPossible = EXTENSIONS.code.includes(ext) || EXTENSIONS.txt.includes(ext);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (newState.copyPossible) {
|
|
165
|
-
if (newState.ext && EXTENSIONS.txt.includes(newState.ext)) {
|
|
166
|
-
newState.text = fileData;
|
|
167
|
-
newState.editingValue = fileData;
|
|
168
|
-
} else if (newState.ext && EXTENSIONS.code.includes(newState.ext)) {
|
|
169
|
-
newState.code = fileData;
|
|
170
|
-
newState.editingValue = fileData;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
this.setState(newState as FileViewerState);
|
|
175
|
-
})
|
|
176
|
-
.catch(e => window.alert(`Cannot read file: ${e}`));
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
componentDidMount() {
|
|
181
|
-
this.readFile();
|
|
182
|
-
|
|
183
|
-
const parts = this.props.href.split('/');
|
|
184
|
-
parts.splice(0, 2);
|
|
185
|
-
const adapter = parts[0];
|
|
186
|
-
const name = parts.splice(1).join('/');
|
|
187
|
-
|
|
188
|
-
if (this.props.supportSubscribes) {
|
|
189
|
-
this.props.socket.subscribeFiles(adapter, name, this.onFileChanged);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
componentWillUnmount() {
|
|
194
|
-
if (this.timeout) {
|
|
195
|
-
clearTimeout(this.timeout);
|
|
196
|
-
this.timeout = null;
|
|
197
|
-
}
|
|
198
|
-
const parts = this.props.href.split('/');
|
|
199
|
-
parts.splice(0, 2);
|
|
200
|
-
const adapter = parts[0];
|
|
201
|
-
const name = parts.splice(1).join('/');
|
|
202
|
-
if (this.props.supportSubscribes) {
|
|
203
|
-
this.props.socket.subscribeFiles(adapter, name, this.onFileChanged);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
onFileChanged = (id: string, fileName: string, size: number | null) => {
|
|
208
|
-
if (!this.state.changed) {
|
|
209
|
-
if (this.timeout) {
|
|
210
|
-
clearTimeout(this.timeout);
|
|
211
|
-
}
|
|
212
|
-
this.timeout = setTimeout(() => {
|
|
213
|
-
this.timeout = null;
|
|
214
|
-
if (size === null) {
|
|
215
|
-
window.alert('Show file was deleted!');
|
|
216
|
-
} else if (this.state.text !== null || this.state.code !== null) {
|
|
217
|
-
this.readFile();
|
|
218
|
-
} else {
|
|
219
|
-
this.setState({ forceUpdate: Date.now() });
|
|
220
|
-
}
|
|
221
|
-
}, 300);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
// eslint-disable-next-line class-methods-use-this
|
|
226
|
-
writeFile64 = () => {
|
|
227
|
-
/*
|
|
228
|
-
// File viewer in adapter-react does not support write
|
|
229
|
-
const parts = this.props.href.split('/');
|
|
230
|
-
const data = this.state.editingValue;
|
|
231
|
-
parts.splice(0, 2);
|
|
232
|
-
const adapter = parts[0];
|
|
233
|
-
const name = parts.splice(1).join('/');
|
|
234
|
-
this.props.socket.writeFile64(adapter, name, Buffer.from(data).toString('base64'))
|
|
235
|
-
.then(() => this.props.onClose())
|
|
236
|
-
.catch(e => window.alert(`Cannot write file: ${e}`));
|
|
237
|
-
*/
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
static getEditFile(ext: string | null) {
|
|
241
|
-
switch (ext) {
|
|
242
|
-
case 'json':
|
|
243
|
-
return 'json';
|
|
244
|
-
case 'json5':
|
|
245
|
-
return 'json5';
|
|
246
|
-
case 'js':
|
|
247
|
-
return 'javascript';
|
|
248
|
-
case 'html':
|
|
249
|
-
return 'html';
|
|
250
|
-
case 'txt':
|
|
251
|
-
return 'html';
|
|
252
|
-
default:
|
|
253
|
-
// e.g. ace/mode/text
|
|
254
|
-
return 'text';
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
getContent() {
|
|
259
|
-
if (this.state.ext && EXTENSIONS.images.includes(this.state.ext)) {
|
|
260
|
-
if (this.state.imgError) {
|
|
261
|
-
return <IconNoIcon style={{ ...styles.img, ...this.props.getStyleBackgroundImage() }} />;
|
|
262
|
-
}
|
|
263
|
-
return <Icon
|
|
264
|
-
onError={e => {
|
|
265
|
-
(e.target as HTMLImageElement).onerror = null;
|
|
266
|
-
this.setState({ imgError: true });
|
|
267
|
-
}}
|
|
268
|
-
style={{ ...styles.img, ...this.props.getStyleBackgroundImage() }}
|
|
269
|
-
src={`${this.props.href}?ts=${this.state.forceUpdate}`}
|
|
270
|
-
alt={this.props.href}
|
|
271
|
-
/>;
|
|
272
|
-
}
|
|
273
|
-
if (this.state.ext && EXTENSIONS.audio.includes(this.state.ext)) {
|
|
274
|
-
return <div
|
|
275
|
-
style={{
|
|
276
|
-
width: '100%',
|
|
277
|
-
height: '100%',
|
|
278
|
-
display: 'flex',
|
|
279
|
-
justifyContent: 'center',
|
|
280
|
-
alignItems: 'center',
|
|
281
|
-
}}
|
|
282
|
-
>
|
|
283
|
-
{/* eslint-disable-next-line jsx-a11y/media-has-caption */}
|
|
284
|
-
<audio
|
|
285
|
-
style={{ width: '100%' }}
|
|
286
|
-
src={this.props.href}
|
|
287
|
-
controls
|
|
288
|
-
></audio>
|
|
289
|
-
</div>;
|
|
290
|
-
}
|
|
291
|
-
if (this.state.ext && EXTENSIONS.video.includes(this.state.ext)) {
|
|
292
|
-
return (
|
|
293
|
-
<div
|
|
294
|
-
style={{
|
|
295
|
-
width: '100%',
|
|
296
|
-
height: '100%',
|
|
297
|
-
display: 'flex',
|
|
298
|
-
justifyContent: 'center',
|
|
299
|
-
alignItems: 'center',
|
|
300
|
-
}}
|
|
301
|
-
>
|
|
302
|
-
{/* eslint-disable-next-line jsx-a11y/media-has-caption */}
|
|
303
|
-
<video style={{ width: '100%', height: '100%' }} controls>
|
|
304
|
-
<source src={this.props.href} type={`video/${this.state.ext}}`} />
|
|
305
|
-
</video>
|
|
306
|
-
</div>
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
if (this.state.code !== null || this.state.text !== null || this.state.editing) {
|
|
310
|
-
// File viewer in adapter-react does not support write
|
|
311
|
-
// return <Editor
|
|
312
|
-
// mode={FileViewer.getEditFile(this.props.formatEditFile)}
|
|
313
|
-
// themeType={this.props.themeType}
|
|
314
|
-
// value={this.state.editingValue || this.state.code || this.state.text}
|
|
315
|
-
// onChange={this.state.editing ? newValue => this.setState({ editingValue: newValue, changed: true }) : undefined}
|
|
316
|
-
// />;
|
|
317
|
-
return <TextField
|
|
318
|
-
variant="standard"
|
|
319
|
-
style={styles.textarea}
|
|
320
|
-
multiline
|
|
321
|
-
value={this.state.editingValue || this.state.code || this.state.text}
|
|
322
|
-
// onChange={newValue => this.setState({ editingValue: newValue, changed: true })}
|
|
323
|
-
InputProps={{ readOnly: !this.state.editing }}
|
|
324
|
-
/>;
|
|
325
|
-
}
|
|
326
|
-
return null;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
render() {
|
|
330
|
-
return <Dialog
|
|
331
|
-
sx={{
|
|
332
|
-
'&.MuiDialog-scrollPaper': styles.dialog,
|
|
333
|
-
'& .MuiDialog-paper': styles.paper,
|
|
334
|
-
}}
|
|
335
|
-
scroll="paper"
|
|
336
|
-
open={!!this.props.href}
|
|
337
|
-
onClose={() => this.props.onClose()}
|
|
338
|
-
fullWidth
|
|
339
|
-
maxWidth="xl"
|
|
340
|
-
aria-labelledby="ar_dialog_file_view_title"
|
|
341
|
-
>
|
|
342
|
-
<div style={styles.dialogTitle}>
|
|
343
|
-
<DialogTitle id="ar_dialog_file_view_title">{`${this.props.t(this.state.editing ? 'Edit' : 'View')}: ${this.props.href}`}</DialogTitle>
|
|
344
|
-
{this.state.ext && EXTENSIONS.images.includes(this.state.ext) && <div>
|
|
345
|
-
<IconButton
|
|
346
|
-
size="large"
|
|
347
|
-
color="inherit"
|
|
348
|
-
onClick={this.props.setStateBackgroundImage}
|
|
349
|
-
>
|
|
350
|
-
<Brightness5Icon />
|
|
351
|
-
</IconButton>
|
|
352
|
-
</div>}
|
|
353
|
-
</div>
|
|
354
|
-
<DialogContent style={styles.content}>
|
|
355
|
-
{this.getContent()}
|
|
356
|
-
</DialogContent>
|
|
357
|
-
<DialogActions>
|
|
358
|
-
{this.state.copyPossible ?
|
|
359
|
-
<Button
|
|
360
|
-
color="grey"
|
|
361
|
-
onClick={e => {
|
|
362
|
-
e.stopPropagation();
|
|
363
|
-
e.preventDefault();
|
|
364
|
-
Utils.copyToClipboard(this.state.text || this.state.code || '');
|
|
365
|
-
}}
|
|
366
|
-
startIcon={<CopyIcon />}
|
|
367
|
-
>
|
|
368
|
-
{this.props.t('Copy content')}
|
|
369
|
-
</Button> : null}
|
|
370
|
-
{this.state.editing ?
|
|
371
|
-
<Button
|
|
372
|
-
color="grey"
|
|
373
|
-
disabled={this.state.editingValue === this.state.code || this.state.editingValue === this.state.text}
|
|
374
|
-
variant="contained"
|
|
375
|
-
onClick={this.writeFile64}
|
|
376
|
-
startIcon={<SaveIcon />}
|
|
377
|
-
>
|
|
378
|
-
{this.props.t('Save')}
|
|
379
|
-
</Button> : null}
|
|
380
|
-
<Button
|
|
381
|
-
variant="contained"
|
|
382
|
-
onClick={() => this.props.onClose()}
|
|
383
|
-
color="primary"
|
|
384
|
-
startIcon={<CloseIcon />}
|
|
385
|
-
>
|
|
386
|
-
{this.props.t('Close')}
|
|
387
|
-
</Button>
|
|
388
|
-
</DialogActions>
|
|
389
|
-
</Dialog>;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
export default withWidth()(FileViewer);
|
|
1
|
+
// File viewer in adapter-react does not support write
|
|
2
|
+
// import { Buffer } from 'buffer';
|
|
3
|
+
import React, { Component } from 'react';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
TextField,
|
|
7
|
+
Button,
|
|
8
|
+
Dialog,
|
|
9
|
+
DialogActions,
|
|
10
|
+
DialogContent,
|
|
11
|
+
DialogTitle,
|
|
12
|
+
IconButton,
|
|
13
|
+
} from '@mui/material';
|
|
14
|
+
|
|
15
|
+
// Icons
|
|
16
|
+
import { FaCopy as CopyIcon } from 'react-icons/fa';
|
|
17
|
+
import {
|
|
18
|
+
Close as CloseIcon,
|
|
19
|
+
Save as SaveIcon,
|
|
20
|
+
Brightness6 as Brightness5Icon,
|
|
21
|
+
} from '@mui/icons-material';
|
|
22
|
+
|
|
23
|
+
import type { Connection } from '@iobroker/socket-client';
|
|
24
|
+
|
|
25
|
+
import IconNoIcon from '../icons/IconNoIcon';
|
|
26
|
+
import withWidth from './withWidth';
|
|
27
|
+
import Utils from './Utils';
|
|
28
|
+
import { Translate } from '../types';
|
|
29
|
+
import Icon from './Icon';
|
|
30
|
+
// File viewer in adapter-react does not use ace editor
|
|
31
|
+
// import * as ace from 'ace-builds';
|
|
32
|
+
// import 'ace-builds/src-noconflict/ext-modelist';
|
|
33
|
+
// import Editor from './Editor';
|
|
34
|
+
|
|
35
|
+
// const modelist = ace.require('ace/ext/modelist');
|
|
36
|
+
|
|
37
|
+
const styles: Record<string, React.CSSProperties> = {
|
|
38
|
+
dialog: {
|
|
39
|
+
height: '100%',
|
|
40
|
+
},
|
|
41
|
+
paper: {
|
|
42
|
+
height: 'calc(100% - 64px)',
|
|
43
|
+
},
|
|
44
|
+
content: {
|
|
45
|
+
textAlign: 'center',
|
|
46
|
+
},
|
|
47
|
+
textarea: {
|
|
48
|
+
width: '100%',
|
|
49
|
+
height: '100%',
|
|
50
|
+
},
|
|
51
|
+
img: {
|
|
52
|
+
width: 'auto',
|
|
53
|
+
height: 'calc(100% - 5px)',
|
|
54
|
+
objectFit: 'contain',
|
|
55
|
+
},
|
|
56
|
+
dialogTitle: {
|
|
57
|
+
justifyContent: 'space-between',
|
|
58
|
+
display: 'flex',
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const EXTENSIONS = {
|
|
63
|
+
images: ['png', 'jpg', 'svg', 'jpeg', 'bmp', 'gif', 'apng', 'avif', 'webp'],
|
|
64
|
+
code: ['js', 'json', 'json5', 'md'],
|
|
65
|
+
txt: ['log', 'txt', 'html', 'css', 'xml', 'ics'],
|
|
66
|
+
audio: ['mp3', 'wav', 'ogg', 'acc'],
|
|
67
|
+
video: ['mp4', 'mov', 'avi'],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
function bufferToBase64(buffer: Buffer, isFull?: boolean) {
|
|
71
|
+
let binary = '';
|
|
72
|
+
const bytes = new Uint8Array(buffer);
|
|
73
|
+
const len = bytes.byteLength;
|
|
74
|
+
for (let i = 0; i < len && (isFull || i < 50); i++) {
|
|
75
|
+
binary += String.fromCharCode(bytes[i]);
|
|
76
|
+
}
|
|
77
|
+
return window.btoa(binary);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface FileViewerProps {
|
|
81
|
+
/** Translation function */
|
|
82
|
+
t: Translate;
|
|
83
|
+
/** Callback when the viewer is closed. */
|
|
84
|
+
onClose: () => void;
|
|
85
|
+
/** The URL (file path) to the file to be displayed. */
|
|
86
|
+
href: string;
|
|
87
|
+
// formatEditFile?: string;
|
|
88
|
+
socket: Connection;
|
|
89
|
+
setStateBackgroundImage: () => void;
|
|
90
|
+
// themeType: ThemeType;
|
|
91
|
+
getStyleBackgroundImage: () => React.CSSProperties | null;
|
|
92
|
+
/** Flag is the js-controller support subscribe on file */
|
|
93
|
+
supportSubscribes?: boolean;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface FileViewerState {
|
|
97
|
+
text: string | null;
|
|
98
|
+
code: string | null;
|
|
99
|
+
ext: string | null;
|
|
100
|
+
editing: boolean;
|
|
101
|
+
editingValue: string | null;
|
|
102
|
+
copyPossible: boolean;
|
|
103
|
+
forceUpdate: number;
|
|
104
|
+
changed: boolean;
|
|
105
|
+
imgError: boolean;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
class FileViewer extends Component<FileViewerProps, FileViewerState> {
|
|
109
|
+
private timeout: ReturnType<typeof setTimeout> | null = null;
|
|
110
|
+
|
|
111
|
+
constructor(props: FileViewerProps) {
|
|
112
|
+
super(props);
|
|
113
|
+
const ext = Utils.getFileExtension(props.href);
|
|
114
|
+
|
|
115
|
+
this.state = {
|
|
116
|
+
text: null,
|
|
117
|
+
code: null,
|
|
118
|
+
ext,
|
|
119
|
+
// File viewer in adapter-react does not support write
|
|
120
|
+
editing: /* !!this.props.formatEditFile || */ false,
|
|
121
|
+
editingValue: null,
|
|
122
|
+
copyPossible: !!ext && (EXTENSIONS.code.includes(ext) || EXTENSIONS.txt.includes(ext)),
|
|
123
|
+
forceUpdate: Date.now(),
|
|
124
|
+
changed: false,
|
|
125
|
+
imgError: false,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
readFile() {
|
|
130
|
+
if (this.props.href) {
|
|
131
|
+
const parts = this.props.href.split('/');
|
|
132
|
+
parts.splice(0, 2);
|
|
133
|
+
const adapter = parts[0];
|
|
134
|
+
const name = parts.splice(1).join('/');
|
|
135
|
+
|
|
136
|
+
this.props.socket.readFile(adapter, name)
|
|
137
|
+
.then((data: { data: Buffer; type: string } | { file: string; mimeType: string }) => {
|
|
138
|
+
let fileData: string = '';
|
|
139
|
+
if ((data as { file: string; mimeType: string }).file !== undefined) {
|
|
140
|
+
fileData = (data as { file: string; mimeType: string }).file;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const newState: Partial<FileViewerState> = { copyPossible: this.state.copyPossible, ext: this.state.ext };
|
|
144
|
+
// try to detect valid extension
|
|
145
|
+
if ((data as { data: Buffer; type: string }).type === 'Buffer') {
|
|
146
|
+
if (name.toLowerCase().endsWith('.json5')) {
|
|
147
|
+
newState.ext = 'json5';
|
|
148
|
+
newState.copyPossible = true;
|
|
149
|
+
try {
|
|
150
|
+
fileData = atob(bufferToBase64((data as { data: Buffer; type: string }).data, true));
|
|
151
|
+
} catch {
|
|
152
|
+
console.error('Cannot convert base64 to string');
|
|
153
|
+
fileData = '';
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
const ext = Utils.detectMimeType(bufferToBase64((data as { data: Buffer; type: string }).data));
|
|
157
|
+
if (ext) {
|
|
158
|
+
newState.ext = ext;
|
|
159
|
+
newState.copyPossible = EXTENSIONS.code.includes(ext) || EXTENSIONS.txt.includes(ext);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (newState.copyPossible) {
|
|
165
|
+
if (newState.ext && EXTENSIONS.txt.includes(newState.ext)) {
|
|
166
|
+
newState.text = fileData;
|
|
167
|
+
newState.editingValue = fileData;
|
|
168
|
+
} else if (newState.ext && EXTENSIONS.code.includes(newState.ext)) {
|
|
169
|
+
newState.code = fileData;
|
|
170
|
+
newState.editingValue = fileData;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
this.setState(newState as FileViewerState);
|
|
175
|
+
})
|
|
176
|
+
.catch(e => window.alert(`Cannot read file: ${e}`));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
componentDidMount() {
|
|
181
|
+
this.readFile();
|
|
182
|
+
|
|
183
|
+
const parts = this.props.href.split('/');
|
|
184
|
+
parts.splice(0, 2);
|
|
185
|
+
const adapter = parts[0];
|
|
186
|
+
const name = parts.splice(1).join('/');
|
|
187
|
+
|
|
188
|
+
if (this.props.supportSubscribes) {
|
|
189
|
+
this.props.socket.subscribeFiles(adapter, name, this.onFileChanged);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
componentWillUnmount() {
|
|
194
|
+
if (this.timeout) {
|
|
195
|
+
clearTimeout(this.timeout);
|
|
196
|
+
this.timeout = null;
|
|
197
|
+
}
|
|
198
|
+
const parts = this.props.href.split('/');
|
|
199
|
+
parts.splice(0, 2);
|
|
200
|
+
const adapter = parts[0];
|
|
201
|
+
const name = parts.splice(1).join('/');
|
|
202
|
+
if (this.props.supportSubscribes) {
|
|
203
|
+
this.props.socket.subscribeFiles(adapter, name, this.onFileChanged);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
onFileChanged = (id: string, fileName: string, size: number | null) => {
|
|
208
|
+
if (!this.state.changed) {
|
|
209
|
+
if (this.timeout) {
|
|
210
|
+
clearTimeout(this.timeout);
|
|
211
|
+
}
|
|
212
|
+
this.timeout = setTimeout(() => {
|
|
213
|
+
this.timeout = null;
|
|
214
|
+
if (size === null) {
|
|
215
|
+
window.alert('Show file was deleted!');
|
|
216
|
+
} else if (this.state.text !== null || this.state.code !== null) {
|
|
217
|
+
this.readFile();
|
|
218
|
+
} else {
|
|
219
|
+
this.setState({ forceUpdate: Date.now() });
|
|
220
|
+
}
|
|
221
|
+
}, 300);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// eslint-disable-next-line class-methods-use-this
|
|
226
|
+
writeFile64 = () => {
|
|
227
|
+
/*
|
|
228
|
+
// File viewer in adapter-react does not support write
|
|
229
|
+
const parts = this.props.href.split('/');
|
|
230
|
+
const data = this.state.editingValue;
|
|
231
|
+
parts.splice(0, 2);
|
|
232
|
+
const adapter = parts[0];
|
|
233
|
+
const name = parts.splice(1).join('/');
|
|
234
|
+
this.props.socket.writeFile64(adapter, name, Buffer.from(data).toString('base64'))
|
|
235
|
+
.then(() => this.props.onClose())
|
|
236
|
+
.catch(e => window.alert(`Cannot write file: ${e}`));
|
|
237
|
+
*/
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
static getEditFile(ext: string | null) {
|
|
241
|
+
switch (ext) {
|
|
242
|
+
case 'json':
|
|
243
|
+
return 'json';
|
|
244
|
+
case 'json5':
|
|
245
|
+
return 'json5';
|
|
246
|
+
case 'js':
|
|
247
|
+
return 'javascript';
|
|
248
|
+
case 'html':
|
|
249
|
+
return 'html';
|
|
250
|
+
case 'txt':
|
|
251
|
+
return 'html';
|
|
252
|
+
default:
|
|
253
|
+
// e.g. ace/mode/text
|
|
254
|
+
return 'text';
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
getContent() {
|
|
259
|
+
if (this.state.ext && EXTENSIONS.images.includes(this.state.ext)) {
|
|
260
|
+
if (this.state.imgError) {
|
|
261
|
+
return <IconNoIcon style={{ ...styles.img, ...this.props.getStyleBackgroundImage() }} />;
|
|
262
|
+
}
|
|
263
|
+
return <Icon
|
|
264
|
+
onError={e => {
|
|
265
|
+
(e.target as HTMLImageElement).onerror = null;
|
|
266
|
+
this.setState({ imgError: true });
|
|
267
|
+
}}
|
|
268
|
+
style={{ ...styles.img, ...this.props.getStyleBackgroundImage() }}
|
|
269
|
+
src={`${this.props.href}?ts=${this.state.forceUpdate}`}
|
|
270
|
+
alt={this.props.href}
|
|
271
|
+
/>;
|
|
272
|
+
}
|
|
273
|
+
if (this.state.ext && EXTENSIONS.audio.includes(this.state.ext)) {
|
|
274
|
+
return <div
|
|
275
|
+
style={{
|
|
276
|
+
width: '100%',
|
|
277
|
+
height: '100%',
|
|
278
|
+
display: 'flex',
|
|
279
|
+
justifyContent: 'center',
|
|
280
|
+
alignItems: 'center',
|
|
281
|
+
}}
|
|
282
|
+
>
|
|
283
|
+
{/* eslint-disable-next-line jsx-a11y/media-has-caption */}
|
|
284
|
+
<audio
|
|
285
|
+
style={{ width: '100%' }}
|
|
286
|
+
src={this.props.href}
|
|
287
|
+
controls
|
|
288
|
+
></audio>
|
|
289
|
+
</div>;
|
|
290
|
+
}
|
|
291
|
+
if (this.state.ext && EXTENSIONS.video.includes(this.state.ext)) {
|
|
292
|
+
return (
|
|
293
|
+
<div
|
|
294
|
+
style={{
|
|
295
|
+
width: '100%',
|
|
296
|
+
height: '100%',
|
|
297
|
+
display: 'flex',
|
|
298
|
+
justifyContent: 'center',
|
|
299
|
+
alignItems: 'center',
|
|
300
|
+
}}
|
|
301
|
+
>
|
|
302
|
+
{/* eslint-disable-next-line jsx-a11y/media-has-caption */}
|
|
303
|
+
<video style={{ width: '100%', height: '100%' }} controls>
|
|
304
|
+
<source src={this.props.href} type={`video/${this.state.ext}}`} />
|
|
305
|
+
</video>
|
|
306
|
+
</div>
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
if (this.state.code !== null || this.state.text !== null || this.state.editing) {
|
|
310
|
+
// File viewer in adapter-react does not support write
|
|
311
|
+
// return <Editor
|
|
312
|
+
// mode={FileViewer.getEditFile(this.props.formatEditFile)}
|
|
313
|
+
// themeType={this.props.themeType}
|
|
314
|
+
// value={this.state.editingValue || this.state.code || this.state.text}
|
|
315
|
+
// onChange={this.state.editing ? newValue => this.setState({ editingValue: newValue, changed: true }) : undefined}
|
|
316
|
+
// />;
|
|
317
|
+
return <TextField
|
|
318
|
+
variant="standard"
|
|
319
|
+
style={styles.textarea}
|
|
320
|
+
multiline
|
|
321
|
+
value={this.state.editingValue || this.state.code || this.state.text}
|
|
322
|
+
// onChange={newValue => this.setState({ editingValue: newValue, changed: true })}
|
|
323
|
+
InputProps={{ readOnly: !this.state.editing }}
|
|
324
|
+
/>;
|
|
325
|
+
}
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
render() {
|
|
330
|
+
return <Dialog
|
|
331
|
+
sx={{
|
|
332
|
+
'&.MuiDialog-scrollPaper': styles.dialog,
|
|
333
|
+
'& .MuiDialog-paper': styles.paper,
|
|
334
|
+
}}
|
|
335
|
+
scroll="paper"
|
|
336
|
+
open={!!this.props.href}
|
|
337
|
+
onClose={() => this.props.onClose()}
|
|
338
|
+
fullWidth
|
|
339
|
+
maxWidth="xl"
|
|
340
|
+
aria-labelledby="ar_dialog_file_view_title"
|
|
341
|
+
>
|
|
342
|
+
<div style={styles.dialogTitle}>
|
|
343
|
+
<DialogTitle id="ar_dialog_file_view_title">{`${this.props.t(this.state.editing ? 'Edit' : 'View')}: ${this.props.href}`}</DialogTitle>
|
|
344
|
+
{this.state.ext && EXTENSIONS.images.includes(this.state.ext) && <div>
|
|
345
|
+
<IconButton
|
|
346
|
+
size="large"
|
|
347
|
+
color="inherit"
|
|
348
|
+
onClick={this.props.setStateBackgroundImage}
|
|
349
|
+
>
|
|
350
|
+
<Brightness5Icon />
|
|
351
|
+
</IconButton>
|
|
352
|
+
</div>}
|
|
353
|
+
</div>
|
|
354
|
+
<DialogContent style={styles.content}>
|
|
355
|
+
{this.getContent()}
|
|
356
|
+
</DialogContent>
|
|
357
|
+
<DialogActions>
|
|
358
|
+
{this.state.copyPossible ?
|
|
359
|
+
<Button
|
|
360
|
+
color="grey"
|
|
361
|
+
onClick={e => {
|
|
362
|
+
e.stopPropagation();
|
|
363
|
+
e.preventDefault();
|
|
364
|
+
Utils.copyToClipboard(this.state.text || this.state.code || '');
|
|
365
|
+
}}
|
|
366
|
+
startIcon={<CopyIcon />}
|
|
367
|
+
>
|
|
368
|
+
{this.props.t('Copy content')}
|
|
369
|
+
</Button> : null}
|
|
370
|
+
{this.state.editing ?
|
|
371
|
+
<Button
|
|
372
|
+
color="grey"
|
|
373
|
+
disabled={this.state.editingValue === this.state.code || this.state.editingValue === this.state.text}
|
|
374
|
+
variant="contained"
|
|
375
|
+
onClick={this.writeFile64}
|
|
376
|
+
startIcon={<SaveIcon />}
|
|
377
|
+
>
|
|
378
|
+
{this.props.t('Save')}
|
|
379
|
+
</Button> : null}
|
|
380
|
+
<Button
|
|
381
|
+
variant="contained"
|
|
382
|
+
onClick={() => this.props.onClose()}
|
|
383
|
+
color="primary"
|
|
384
|
+
startIcon={<CloseIcon />}
|
|
385
|
+
>
|
|
386
|
+
{this.props.t('Close')}
|
|
387
|
+
</Button>
|
|
388
|
+
</DialogActions>
|
|
389
|
+
</Dialog>;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export default withWidth()(FileViewer);
|