SearchAppMenu.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. import React from 'react';
  2. import { makeStyles, useTheme, withStyles } from '@material-ui/core/styles';
  3. import { useEffect } from 'react';
  4. import AppBar from '@material-ui/core/AppBar';
  5. import Toolbar from '@material-ui/core/Toolbar';
  6. import Typography from '@material-ui/core/Typography';
  7. import Button from '@material-ui/core/Button';
  8. import IconButton from '@material-ui/core/IconButton';
  9. import MenuIcon from '@material-ui/icons/Menu';
  10. import clsx from 'clsx';
  11. import Drawer from '@material-ui/core/Drawer';
  12. import List from '@material-ui/core/List';
  13. import CssBaseline from '@material-ui/core/CssBaseline';
  14. import Divider from '@material-ui/core/Divider';
  15. import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
  16. import ChevronRightIcon from '@material-ui/icons/ChevronRight';
  17. import ListItem from '@material-ui/core/ListItem';
  18. import ListItemIcon from '@material-ui/core/ListItemIcon';
  19. import ListItemText from '@material-ui/core/ListItemText';
  20. import InfoIcon from '@material-ui/icons/Info';
  21. import InboxIcon from '@material-ui/icons/MoveToInbox';
  22. import MailIcon from '@material-ui/icons/Mail';
  23. import ImageList from './imageList';
  24. import PhotoIcon from '@material-ui/icons/Photo';
  25. import ShareIcon from '@material-ui/icons/Share';
  26. import PhotoAlbumIcon from '@material-ui/icons/PhotoAlbum';
  27. import LibraryAddCheckIcon from '@material-ui/icons/LibraryAddCheck';
  28. import Grid from '@material-ui/core/Grid';
  29. import DeleteIcon from '@material-ui/icons/Delete';
  30. import CloudUploadIcon from '@material-ui/icons/CloudUpload';
  31. import HelpOutlineIcon from '@material-ui/icons/HelpOutline';
  32. import SettingsIcon from '@material-ui/icons/Settings';
  33. import Avatar from '@material-ui/core/Avatar';
  34. import Icon from '@material-ui/core/Icon';
  35. import AddCircle from '@material-ui/icons/AddCircle';
  36. import CloudIcon from '@material-ui/icons/Cloud';
  37. import LinearProgress from '@material-ui/core/LinearProgress';
  38. import Modal from '@material-ui/core/Modal';
  39. import Backdrop from '@material-ui/core/Backdrop';
  40. import Fade from '@material-ui/core/Fade';
  41. import ListItemAvatar from '@material-ui/core/ListItemAvatar';
  42. import ImageIcon from '@material-ui/icons/Image';
  43. import WorkIcon from '@material-ui/icons/Work';
  44. import BeachAccessIcon from '@material-ui/icons/BeachAccess';
  45. import Paper from '@material-ui/core/Paper';
  46. import TodayIcon from '@material-ui/icons/Today';
  47. import CropOriginalIcon from '@material-ui/icons/CropOriginal';
  48. import CameraIcon from '@material-ui/icons/Camera';
  49. import LocationOnIcon from '@material-ui/icons/LocationOn';
  50. import CloseIcon from '@material-ui/icons/Close';
  51. import ListSubheader from '@material-ui/core/ListSubheader';
  52. import Fab from '@material-ui/core/Fab';
  53. import AddIcon from '@material-ui/icons/Add';
  54. import ArrowBackIosIcon from '@material-ui/icons/ArrowBackIos';
  55. import ArrowForwardIosIcon from '@material-ui/icons/ArrowForwardIos';
  56. import GridList from '@material-ui/core/GridList';
  57. import GridListTile from '@material-ui/core/GridListTile';
  58. import FolderList from './FolderList';
  59. import Snackbar from '@material-ui/core/Snackbar';
  60. import MuiAlert from '@material-ui/lab/Alert';
  61. const drawerWidth = 240;
  62. const BorderLinearProgress = withStyles((theme) => ({
  63. colorPrimary: {
  64. backgroundColor: theme.palette.grey[theme.palette.type === 'light' ? 200 : 700],
  65. },
  66. bar: {
  67. borderRadius: 5,
  68. backgroundColor: '#1a90ff',
  69. },
  70. }))(LinearProgress);
  71. const useStyles = makeStyles((theme) => ({
  72. root: {
  73. flexGrow: 1,
  74. },
  75. menuButton: {
  76. marginRight: theme.spacing(2),
  77. },
  78. title: {
  79. flexGrow: 1,
  80. },
  81. toolbar: {
  82. display: 'flex',
  83. alignItems: 'center',
  84. justifyContent: 'flex-end',
  85. padding: theme.spacing(0, 1),
  86. // necessary for content to be below app bar
  87. ...theme.mixins.toolbar,
  88. },
  89. root: {
  90. display: 'flex',
  91. },
  92. appBar: {
  93. zIndex: theme.zIndex.drawer + 1,
  94. transition: theme.transitions.create(['width', 'margin'], {
  95. easing: theme.transitions.easing.sharp,
  96. duration: theme.transitions.duration.leavingScreen,
  97. }),
  98. },
  99. appBarShift: {
  100. marginLeft: drawerWidth,
  101. width: `calc(100% - ${drawerWidth}px)`,
  102. transition: theme.transitions.create(['width', 'margin'], {
  103. easing: theme.transitions.easing.sharp,
  104. duration: theme.transitions.duration.enteringScreen,
  105. }),
  106. },
  107. menuButton: {
  108. marginRight: 36,
  109. },
  110. hide: {
  111. display: 'none',
  112. },
  113. drawer: {
  114. width: drawerWidth,
  115. flexShrink: 0,
  116. whiteSpace: 'nowrap',
  117. },
  118. drawerOpen: {
  119. width: drawerWidth,
  120. transition: theme.transitions.create('width', {
  121. easing: theme.transitions.easing.sharp,
  122. duration: theme.transitions.duration.enteringScreen,
  123. }),
  124. },
  125. drawerClose: {
  126. transition: theme.transitions.create('width', {
  127. easing: theme.transitions.easing.sharp,
  128. duration: theme.transitions.duration.leavingScreen,
  129. }),
  130. overflowX: 'hidden',
  131. width: theme.spacing(7) + 1,
  132. [theme.breakpoints.up('sm')]: {
  133. width: theme.spacing(9) + 1,
  134. },
  135. },
  136. toolbar: {
  137. display: 'flex',
  138. alignItems: 'center',
  139. justifyContent: 'flex-end',
  140. padding: theme.spacing(0, 1),
  141. // necessary for content to be below app bar
  142. ...theme.mixins.toolbar,
  143. },
  144. content: {
  145. flexGrow: 1,
  146. padding: theme.spacing(3),
  147. },
  148. modal: {
  149. display: 'flex',
  150. alignItems: 'center',
  151. justifyContent: 'center',
  152. },
  153. paper: {
  154. backgroundColor: theme.palette.background.paper,
  155. width: '100%',
  156. height: '100%',
  157. //boxShadow: theme.shadows[5],
  158. //padding: theme.spacing(2, 4, 3),
  159. },
  160. fabL: {
  161. position: 'absolute',
  162. bottom: '50%',
  163. left: theme.spacing(2),
  164. },
  165. fabR: {
  166. position: 'absolute',
  167. bottom: '50%',
  168. //left: `calc(95% - ${theme.spacing(2)}px)`,
  169. //right: theme.spacing(2),
  170. right: `calc(${theme.spacing(2)}px + ( 100vw / 4 ))`,
  171. Mcontainer: {
  172. display: "flex",
  173. flexWrap: "wrap",
  174. position: "absolute",
  175. top: 0,
  176. left: 0,
  177. height: "100%",
  178. width: "100%",
  179. alignItems: "center"
  180. },
  181. },
  182. }));
  183. function Alert(props) {
  184. return <MuiAlert elevation={6} variant="filled" {...props} />;
  185. }
  186. export default function Main(props) {
  187. //FOR AJAX
  188. const classes = useStyles();
  189. const [error, setError] = React.useState(null);
  190. const [isLoaded, setIsLoaded] = React.useState(false);
  191. const [items, setItems] = React.useState([]);
  192. //END
  193. const theme = useTheme();
  194. const [open, setOpen] = React.useState(false);
  195. const handleDrawerOpen = () => {
  196. setOpen(true);
  197. };
  198. const handleDrawerClose = () => {
  199. setOpen(false);
  200. };
  201. const [Settingopen, setSettingOpen] = React.useState(false);
  202. const handleSettingOpen = () => {
  203. setSettingOpen(true);
  204. };
  205. const handleSettingClose = () => {
  206. setSettingOpen(false);
  207. };
  208. const [Alertopen, setAlertOpen] = React.useState(false);
  209. const handleAlertClick = () => {
  210. setAlertOpen(true);
  211. };
  212. const handleAlertClose = (event, reason) => {
  213. if (reason === 'clickaway') {
  214. return;
  215. }
  216. setAlertOpen(false);
  217. };
  218. const [Imagelistopen, setImagelistOpen] = React.useState(true);
  219. const [Folderlistopen, setFolderlistOpen] = React.useState(false);
  220. const [folderName, setFolderName] = React.useState('user:/Photo/Photo/uploads/');
  221. const setFolderNameF = (folderN) => {
  222. setFolderName(folderN);
  223. console.log("3" + folderName);
  224. setImagelistOpen(true);
  225. setFolderlistOpen(false);
  226. }
  227. const handleClick = value => () => {
  228. console.log(value);
  229. switch (value) {
  230. case "Photos":
  231. setImagelistOpen(true);
  232. setFolderlistOpen(false);
  233. break;
  234. case "Albums":
  235. setFolderlistOpen(true);
  236. setImagelistOpen(false);
  237. break;
  238. //case "Sharing":
  239. //setAlertOpen(true);
  240. //case "Utilities":
  241. //setAlertOpen(true);
  242. }
  243. }
  244. useEffect(() => {
  245. fetch("/backend_test/config", {})
  246. /*
  247. fetch("/system/ajgi/interface?script=/Photo/backend/listFolder.js", {
  248. method: 'post',
  249. body: JSON.stringify({ folder: folderName })
  250. })
  251. */
  252. .then(res => res.json())
  253. .then(
  254. (result) => {
  255. setIsLoaded(true);
  256. setItems(result);
  257. },
  258. // Note: it's important to handle errors here
  259. // instead of a catch() block so that we don't swallow
  260. // exceptions from actual bugs in components.
  261. (error) => {
  262. setIsLoaded(true);
  263. setError(error);
  264. }
  265. )
  266. }, [])
  267. if (error) {
  268. return <div>Error: {error.message} (Config.js)</div>;
  269. } else if (!isLoaded) {
  270. return <div><LinearProgress /></div>;
  271. } else {
  272. return (
  273. <div className={classes.root}>
  274. <AppBar position="fixed" style={{ background: '#2196f3' }} className={
  275. clsx(classes.appBar, {
  276. [classes.appBarShift]: open,
  277. })
  278. }>
  279. <Toolbar >
  280. <IconButton edge="start" onClick={handleDrawerOpen} className={
  281. clsx(classes.menuButton, {
  282. [classes.hide]: open,
  283. })
  284. } className={classes.menuButton} color="inherit" aria-label="menu">
  285. <MenuIcon />
  286. </IconButton>
  287. <Typography variant="h6" className={classes.title}>
  288. ArOZ Photo
  289. </Typography>
  290. <Button variant="contained" startIcon={<CloudUploadIcon />} type="button" onClick={handleAlertClick}>Upload</Button>
  291. <IconButton style={{ color: '#ffffff' }} aria-label="help" onClick={handleAlertClick}>
  292. <HelpOutlineIcon />
  293. </IconButton>
  294. <IconButton style={{ color: '#ffffff' }} aria-label="settings" onClick={handleSettingOpen}>
  295. <SettingsIcon />
  296. </IconButton>
  297. <Avatar alt={items.username} src={items.usericon} />
  298. </Toolbar>
  299. </AppBar>
  300. <Drawer
  301. variant="permanent"
  302. className={
  303. clsx(classes.drawer, {
  304. [classes.drawerOpen]: open,
  305. [classes.drawerClose]: !open,
  306. })
  307. }
  308. classes={
  309. {
  310. paper: clsx({
  311. [classes.drawerOpen]: open,
  312. [classes.drawerClose]: !open,
  313. }),
  314. }
  315. }>
  316. <div className={classes.toolbar}>
  317. <IconButton onClick={handleDrawerClose}>
  318. {theme.direction === 'ltr' ? <ChevronLeftIcon /> : <ChevronRightIcon />}
  319. </IconButton>
  320. </div>
  321. <Divider />
  322. <List>
  323. {['Photos', /* 'Sharing', */ 'Albums', /* 'Utilities' */].map((text, index) => (
  324. <ListItem button key={text} onClick={handleClick(text)}>
  325. { /* index == 0 ? < PhotoIcon /> : index == 1 ? < ShareIcon /> : index == 2 ? < PhotoAlbumIcon /> : < LibraryAddCheckIcon /> */}
  326. <ListItemIcon>{index == 0 ? < PhotoIcon /> : < PhotoAlbumIcon />}</ListItemIcon>
  327. <ListItemText primary={text} />
  328. </ListItem>
  329. ))}
  330. </List>
  331. <Divider />
  332. <List>
  333. <ListItem button key="Storage">
  334. <ListItemIcon>< CloudIcon /></ListItemIcon>
  335. <ListItemText primary="Storage" secondary={<BorderLinearProgress variant="determinate" value={items.quota} />} />
  336. </ListItem>
  337. </List>
  338. </Drawer>
  339. <main className={classes.content}>
  340. <div className={classes.toolbar} />
  341. {Imagelistopen && <ImageList path={folderName} />}
  342. {Folderlistopen && <FolderList onChange={setFolderNameF} folderName={setFolderNameF} />}
  343. </main>
  344. <Snackbar open={Alertopen} autoHideDuration={6000} onClose={handleAlertClose}>
  345. <Alert onClose={handleAlertClose} severity="error">
  346. This function has not been implemented on this platform (aCloud 0x0)
  347. </Alert>
  348. </Snackbar>
  349. <Modal
  350. aria-labelledby="transition-modal-title"
  351. aria-describedby="transition-modal-description"
  352. className={classes.modal}
  353. open={Settingopen}
  354. onClose={handleSettingClose}
  355. closeAfterTransition
  356. BackdropComponent={Backdrop}
  357. BackdropProps={{
  358. timeout: 500,
  359. }}
  360. >
  361. <Fade in={Settingopen}>
  362. <div className={classes.paper}>
  363. <Grid container alignItems="flex-start" justify="flex-end" direction="row">
  364. <IconButton color="primary" aria-label="close" onClick={handleSettingClose}>
  365. <CloseIcon />
  366. </IconButton>
  367. </Grid>
  368. <List>
  369. <ListItem button>
  370. <ListItemAvatar>
  371. <Avatar>
  372. <InfoIcon />
  373. </Avatar>
  374. </ListItemAvatar>
  375. <ListItemText primary="Version" secondary="v1.0.0-alpha" />
  376. </ListItem>
  377. <ListItem button>
  378. <ListItemAvatar>
  379. <Avatar>
  380. <InfoIcon />
  381. </Avatar>
  382. </ListItemAvatar>
  383. <ListItemText primary="Developer" secondary="Alanyeung.co" />
  384. </ListItem>
  385. </List>
  386. </div>
  387. </Fade>
  388. </Modal>
  389. </div>
  390. );
  391. }
  392. }