From 7cb23c6cc84154205b3880e06555f2923371b11f Mon Sep 17 00:00:00 2001 From: michal Date: Wed, 15 Jan 2020 21:57:51 +0100 Subject: [PATCH] Added notes --- src/App.js | 59 +++++---- src/Notes.js | 304 +++++++++++++++++++++++++++++++++++++++++++++++ src/userPanel.js | 52 +++++++- 3 files changed, 386 insertions(+), 29 deletions(-) create mode 100644 src/Notes.js diff --git a/src/App.js b/src/App.js index 019a35a..f8ffe1e 100644 --- a/src/App.js +++ b/src/App.js @@ -6,15 +6,20 @@ import AppBar from '@material-ui/core/AppBar'; import Tabs from '@material-ui/core/Tabs'; import Tab from '@material-ui/core/Tab'; + + import { UserPanel, Login } from './userPanel.js'; import { Transactions } from './Transactions.js'; import Contacts from './Contacts.js'; import Supervisors from './Supervisors.js'; +import Notes from './Notes.js'; + const menu = { // index of menu items TRANSACTIONS: 0, CONTACTS: 1, SUPERVISORS: 2, + NOTES: 3, } class App extends React.Component { @@ -37,8 +42,8 @@ class App extends React.Component { componentDidMount() { // const onValueChanged = this.onValueChanged; - let request= new XMLHttpRequest(); - request.onreadystatechange = function() { + let request = new XMLHttpRequest(); + request.onreadystatechange = function () { if (this.readyState === 4 && this.status === 200) { console.log("RETURNED:", this.responseText); // const supervisors = JSON.parse(this.responseText); @@ -51,37 +56,43 @@ class App extends React.Component { } render() { - const { loggedUser, page} = this.state; + const { loggedUser, page } = this.state; console.log(this.state); + //console.log("habadub"); return (
{!loggedUser ? - : <> -
- - this.onValueChanged("page", value)} - value={page} - > - Transactions} /> - Contacts} /> - Supervisors} /> - - - -
-
-
- { page === menu.TRANSACTIONS && } - { page === menu.CONTACTS && } - { page === menu.SUPERVISORS && } + : <> +
+ + this.onValueChanged("page", value)} + value={page} + > + Transactions} /> + Contacts} /> + Supervisors} /> + Notes} /> + + + +
-
- } +
+ +
+ {page === menu.TRANSACTIONS && } + {page === menu.CONTACTS && } + {page === menu.SUPERVISORS && } + {page === menu.NOTES && } +
+
+ }
); } } export default App; + diff --git a/src/Notes.js b/src/Notes.js new file mode 100644 index 0000000..c2f8ab3 --- /dev/null +++ b/src/Notes.js @@ -0,0 +1,304 @@ +// Author: Michal Zelenak, xzelen24 + +import React from 'react'; +import ExpansionPanel from '@material-ui/core/ExpansionPanel'; +import ExpansionPanelDetails from '@material-ui/core/ExpansionPanelDetails'; +import ExpansionPanelSummary from '@material-ui/core/ExpansionPanelSummary'; +import ExpansionPanelActions from '@material-ui/core/ExpansionPanelActions'; +import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; +import Box from '@material-ui/core/Box'; +import Button from '@material-ui/core/Button'; +import Dialog from '@material-ui/core/Dialog'; +import DialogActions from '@material-ui/core/DialogActions'; +import DialogContent from '@material-ui/core/DialogContent'; +import DialogTitle from '@material-ui/core/DialogTitle'; +import TextField from '@material-ui/core/TextField'; +import Grid from '@material-ui/core/Grid'; + + +import './styles.css'; + +class DeleteNote extends React.Component { + constructor(props) { + super(props); + + this.state = { + showModal: false, + }; + + this.open = this.open.bind(this); + this.close = this.close.bind(this); + this.onValueChanged = this.onValueChanged.bind(this); + this.delete = this.delete.bind(this); + } + + onValueChanged(key, value) { + this.setState({ [key]: value }); + } + + close() { + this.setState({ showModal: false, dialogError: undefined }); + } + + open() { + this.setState({ showModal: true }); + } + + delete() { + const loggedUser = this.props.loggedUser; + const appOnValueChanged = this.props.appOnValueChanged; + + const data = { date: this.props.note.date, createDate: this.props.note.createDate, note: this.props.note.note, shortNote: this.props.note.shortNote }; + const call = { + action: "deleteContact", + arguments: data + }; + // const callStr = JSON.stringify(call); + // console.log("Delete Contact API:", callStr); + + const newNotes = [...loggedUser.notes]; + + var finded = 0; + var index = 0; + + for (const result of newNotes) { if (result.note === data.note) { finded = index } else { index = index + 1 } }; + + newNotes.splice(finded, 1); + console.log(finded); + loggedUser.notes = newNotes; + appOnValueChanged("loggedUser", loggedUser); + this.close(); + } + + render() { + const id = this.props.note + "-delete"; + return ( + <> + + + Delete Note + + Delete this Note? + + {this.state.errorMessage && (
)} + {this.state.errorMessage} +
+
+ + + + + + +
+ + ); + } +} + +class CreateNote extends React.Component { + constructor(props) { + super(props); + + this.state = { + showModal: false, + date: "", + createDate: "", + shortNote: "", + note: "", + }; + + this.open = this.open.bind(this); + this.close = this.close.bind(this); + this.onValueChanged = this.onValueChanged.bind(this); + this.create = this.create.bind(this); + } + + onValueChanged(key, value) { + this.setState({ [key]: value }); + } + + close() { + this.setState({ showModal: false, date: "", shortNote: "", note: "", dialogError: undefined }); + } + + open() { + this.setState({ showModal: true }); + } + + create() { + const loggedUser = this.props.loggedUser; + const appOnValueChanged = this.props.appOnValueChanged; + + const { date, createDate, shortNote, note } = this.state; + const data = { date, createDate, shortNote, note }; + const call = { + action: "createNote", + arguments: data + }; + const callStr = JSON.stringify(call); + console.log("CreateNote", callStr); + + const newNotes = [...loggedUser.notes]; + newNotes.push({ + date, + createDate, + shortNote, + note + + }); + loggedUser.notes = newNotes; + appOnValueChanged("loggedUser", loggedUser); + this.close(); + } + + render() { + const id = "create"; + return ( + <> + + + Create New Note + + + this.onValueChanged("shortNote", e.target.value)} + fullWidth + /> + + + this.onValueChanged("note", e.target.value)} + fullWidth + /> + + + this.onValueChanged("date", e.target.value)} + fullWidth + /> + + + + {this.state.errorMessage && (
)} + {this.state.errorMessage} +
+
+ + + + +
+ + ); + } +} + +export default class Notes extends React.Component { + constructor(props) { + super(props); + console.log("this.state"); + this.onValueChanged = this.onValueChanged.bind(this); + } + + onValueChanged(key, value) { + this.setState({ [key]: value }); + } + + render() { + const day = new Date().getDate(); + const month = new Date().getMonth() + 1; + const year = new Date().getFullYear(); + const date = day + "-" + month + "-" + year; + console.log(date); + // console.log("sdaf"); + const NotesPanel = (note) => { + return ( + + } + aria-controls="panel1c-content" + id="panel1c-header" + classes={{ layout: "grid", gridTemplateColumns: "100px 100px 100px" }} + > + {note.shortNote} + {"Date: "} + {note.date} + + + + + + + + + + + + + + + +
CreateDate: {note.createDate}Note: {note.note}
+
+ + + + +
+ ); + }; + + const body = this.props.notes.map(note => NotesPanel(note)); + //console.log("sdaf"); + return ( + + { + this.props.loggedUser && + + + + + + } + < Grid item xs={12} > + {body} + + + + ); + }; +} + diff --git a/src/userPanel.js b/src/userPanel.js index 786b735..ba24425 100644 --- a/src/userPanel.js +++ b/src/userPanel.js @@ -7,6 +7,8 @@ import DialogActions from '@material-ui/core/DialogActions'; import DialogContent from '@material-ui/core/DialogContent'; import DialogTitle from '@material-ui/core/DialogTitle'; import TextField from '@material-ui/core/TextField'; +//import Card from '@material-ui/core/Card'; + class Logout extends React.Component { constructor(props) { @@ -48,6 +50,12 @@ class Logout extends React.Component { Logout + + + + + + - { this.state.errorMessage && (
) } - { this.state.errorMessage } + {this.state.errorMessage && (
)} + {this.state.errorMessage}
@@ -238,7 +278,9 @@ export const UserPanel = ({ appOnValueChanged, loggedUser }) => { return ( + ); } +