Newer
Older

Lucas Eduardo Schoenfelder
committed
/*Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
Departamento de Informatica - Universidade Federal do Parana
This file is part of Plataforma Integrada MEC.
Plataforma Integrada MEC is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Plataforma Integrada MEC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Plataforma Integrada MEC. If not, see <http://www.gnu.org/licenses/>.*/

Lucas Eduardo Schoenfelder
committed
import styled from 'styled-components'
import ListItem from '@material-ui/core/ListItem';
import ListItemAvatar from '@material-ui/core/ListItemAvatar';
import ListItemText from '@material-ui/core/ListItemText';
import Avatar from '@material-ui/core/Avatar';
import { GetActivityProperties, Tag, ObjectColor } from './Activities/Definitions.js'

Lucas Eduardo Schoenfelder
committed
//icons
import FavoriteIcon from '@material-ui/icons/Favorite';
import CreateIcon from '@material-ui/icons/Create';
import GetAppIcon from '@material-ui/icons/GetApp';
import StarIcon from '@material-ui/icons/Star';
import SpeakerNotesIcon from '@material-ui/icons/SpeakerNotes';
import ReportIcon from '@material-ui/icons/Report';
import CloudUploadIcon from '@material-ui/icons/CloudUpload';
import ThumbDownIcon from '@material-ui/icons/ThumbDown';
import DeleteIcon from '@material-ui/icons/Delete';

Lucas Eduardo Schoenfelder
committed
//Image Import
import { noAvatar } from "ImportImages.js";

Lucas Eduardo Schoenfelder
committed
const GetObjectColor = (tag) => {
return ObjectColor[tag]
}
const getNotificationIcon = (iconType) => {

Lucas Eduardo Schoenfelder
committed
case 'create':

Lucas Eduardo Schoenfelder
committed
case 'favorite':

Lucas Eduardo Schoenfelder
committed
case 'get_app':

Lucas Eduardo Schoenfelder
committed
case 'star':

Lucas Eduardo Schoenfelder
committed
case 'report':

Lucas Eduardo Schoenfelder
committed
case 'cloud_upload':

Lucas Eduardo Schoenfelder
committed
case 'delete':

Lucas Eduardo Schoenfelder
committed
case 'thumb_down':
return <ThumbDownIcon className="icon" />;
default:
return <SpeakerNotesIcon className="icon" />;

Lucas Eduardo Schoenfelder
committed
}
}
const getTimeDifference = (timestamp) => {
//returns time difference between now and the moment the notification was created
var moment = require('moment')
const now = moment()
const then = moment(timestamp, moment.ISO_8601)
let duration = moment.duration(now.diff(then))
// {/*console.log('duration: ', duration)*/}

Lucas Eduardo Schoenfelder
committed
let timeDiff;

Lucas Eduardo Schoenfelder
committed
timeDiff = duration._data.years + (duration._data.years > 1 ? ' anos' : ' ano')
}
else if (duration._data.months > 0) {
timeDiff = duration._data.months + (duration._data.months > 1 ? ' meses' : ' mês')

Lucas Eduardo Schoenfelder
committed
}

Lucas Eduardo Schoenfelder
committed
timeDiff = duration._data.days + (duration._data.days > 1 ? ' dias' : ' dia')
}

Lucas Eduardo Schoenfelder
committed
timeDiff = duration._data.hours + (duration._data.hours > 1 ? ' horas' : ' hora')
}

Lucas Eduardo Schoenfelder
committed
timeDiff = duration._data.minutes + (duration._data.minutes > 1 ? ' minutos' : ' minuto')
}
return timeDiff;
}

Lucas Eduardo Schoenfelder
committed
const [activity, setActivity] = React.useState({

Lucas Eduardo Schoenfelder
committed
})

Lucas Eduardo Schoenfelder
committed
const newTag = Tag[(props.actionType === 'CuratorAssignment' ? props.actionType : props.objectType)]
const { icon, text, text2 } = GetActivityProperties(props.activity)
// {/*console.log('icon, text, text2: ', icon, text, text2)*/}

Lucas Eduardo Schoenfelder
committed
setActivity({
...activity,
tag: newTag,
icon: icon,
text: text,
text2: text2

Lucas Eduardo Schoenfelder
committed
})

Lucas Eduardo Schoenfelder
committed
return (
<StyledListItem onMenuBar={props.onMenuBar} contrast={props.contrast}>
<ListItemAvatar>
<Avatar alt='user avatar' src={props.avatar ? props.avatar : noAvatar} />
</ListItemAvatar>
{getNotificationIcon(activity.icon)}

Lucas Eduardo Schoenfelder
committed
<ListItemText
primary={
<div>
<span className={`tag-object ${GetObjectColor(activity.tag)}`}>

Lucas Eduardo Schoenfelder
committed
{activity.tag}
</span>
<span className="time-ago-span"> · há {getTimeDifference(props.createdAt)}</span>
</div>
}
secondary={

Lucas Eduardo Schoenfelder
committed
<div>
<span style={props.contrast === "" ? { color: "#666" } : {color: "white"}}>
state: '0',
}} className="owner-name-a" >{props.ownerName}</Link> {activity.text} <Link to={props.recipientHref} className="recipient-name-a">{props.recipientName}</Link> {activity.text2}

Lucas Eduardo Schoenfelder
committed
</span>
</div>
}

Lucas Eduardo Schoenfelder
committed
</StyledListItem>
)
}
const StyledListItem = styled(ListItem)`
padding : ${props => props.onMenuBar ? "8px 16px !important" : "20px 60px !important"};

Lucas Eduardo Schoenfelder
committed
border-bottom : 1px solid #eee;
display : flex;
justify-content : flex-start;
align-items : center;
min-heigth : 40px;
a {
text-decoration : none !important;
}
.time-ago-span {
font-size : 12px;
color: ${props => props.contrast === '' ? "#787380" : "white"};

Lucas Eduardo Schoenfelder
committed
}
.owner-name-a {
color: ${props => props.contrast === '' ? "#00bcd4" : "yellow"};
text-decoration: ${props => props.contrast === "" ? "none" : "underline !important"};

Lucas Eduardo Schoenfelder
committed
}
.recipient-name-a {
cursor : pointer;
color: ${props => props.contrast === '' ? "#337ab7" : "yellow"};
text-decoration: ${props => props.contrast === "" ? "none" : "underline !important"};

Lucas Eduardo Schoenfelder
committed
}
.icon {
padding-right : 10px;
color: ${props => props.contrast === '' ? "#666" : "white"};

Lucas Eduardo Schoenfelder
committed
}
.tag-object {
font-family: Roboto;
font-style: normal;
font-weight: 700;
font-size: 12px;
line-height: normal;
text-align: center;
letter-spacing: .06em;
text-transform: uppercase;
color: #fff;
height: -webkit-fit-content;
height: -moz-fit-content;
height: fit-content;
width: -webkit-fit-content;
width: -moz-fit-content;
width: fit-content;
border-radius: 10px;
padding: 2px 4px;
}
.recurso-color {
background-color: ${props => props.contrast === '' ? "orange" : ""};
border: ${props => props.contrast === '' ? "" : "1px solid #d4d4d4"};

Lucas Eduardo Schoenfelder
committed
}
.colecao-color {
background-color: ${props => props.contrast === '' ? "blue" : ""};
border: ${props => props.contrast === '' ? "" : "1px solid #d4d4d4"};

Lucas Eduardo Schoenfelder
committed
}
.curadoria-color {
background-color: ${props => props.contrast === '' ? "red" : ""};
border: ${props => props.contrast === '' ? "" : "1px solid #d4d4d4"};