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 { Button } from '@material-ui/core';
import Modal from '@material-ui/core/Modal';
import Backdrop from '@material-ui/core/Backdrop';
import Fade from '@material-ui/core/Fade';
import styled from 'styled-components'
import { Store } from '../Store.js'
import { apiDomain } from '../env';

Lucas Eduardo Schoenfelder
committed
import CloseIcon from '@material-ui/icons/Close';
import PublicIcon from '@material-ui/icons/Public';
import LockIcon from '@material-ui/icons/Lock';
import LoadingSpinner from './LoadingSpinner.js'
import CriarColecaoForm from './CriarColecaoForm.js'
import SnackbarComponent from './SnackbarComponent'
import { getRequest, postRequest } from './HelperFunctions/getAxiosConfig'

Lucas Eduardo Schoenfelder
committed

Lucas Eduardo Schoenfelder
committed
return (
<StyledCloseModalButton onClick={props.handleClose}>

Lucas Eduardo Schoenfelder
committed
</StyledCloseModalButton>
)
}
export default function GuardarModal(props) {

Lucas Eduardo Schoenfelder
committed
const [collsArr, setcolls] = useState([])
const [loading, toggleLoading] = useState(true)
const [creatingCol, setCreating] = useState(false)
const [snackbarOpen, setSnackOpen] = useState({
open: false,
severity: "",
text: "",
color: ""
})

Lucas Eduardo Schoenfelder
committed
setcolls(data)
toggleLoading(false)
}
function handleError(error) {
toggleLoading(false)
setSnackOpen({
open: true,
severity: "error",
text: "Error ao guardar o recurso",
color: "red",
})
}

Lucas Eduardo Schoenfelder
committed
const getCols = () => {
if (collsArr.length === 0) {
const id = state.currentUser.id
const url = `/users/${id}/collections/`

Lucas Eduardo Schoenfelder
committed
}
}
function handleSuccessPostToCol(data) {
setSnackOpen({
open: true,
severity: "info",
text: "O Recurso foi guardado na coleção!",
color: ""
})
setCreating(false)
props.handleClose()
}

Lucas Eduardo Schoenfelder
committed
const postToCol = (colId) => {
const url = `/collections/${colId}/items`

Lucas Eduardo Schoenfelder
committed
const payload = {
"collection": {
"items": [{ "id": props.recursoId, "type": "LearningObject" }]

Lucas Eduardo Schoenfelder
committed
}
}
postRequest(url, payload, handleSuccessPostToCol, handleError)

Lucas Eduardo Schoenfelder
committed
}
return (
<React.Fragment>
<SnackbarComponent
snackbarOpen={snackbarOpen.open}
severity={snackbarOpen.severity}
handleClose={() => {
setSnackOpen({
open: false,
severity: "",
text: "",
color: ""
})
}}
text={snackbarOpen.text}
color={snackbarOpen.color}
<StyledModal
aria-labelledby="transition-modal-title"
aria-describedby="transition-modal-description"
open={props.open}
centered="true"
onClose={props.handleClose}
closeAfterTransition
BackdropComponent={Backdrop}
BackdropProps={{
timeout: 500,
}}
onRendered={() => { getCols() }}
>
<Fade in={props.open}>
<Container>
<Header>
<span style={{ width: "32px" }} />
<h2>Guardar recurso</h2>
<CloseModalButton handleClose={props.handleClose} />
</Header>
<Content style={{ paddingTop: "0" }}>
<ResourceInfo>
<img src={props.thumb ? apiDomain + props.thumb : require('../img/logo_small.svg')} alt="thumbnail recurso" />
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<div className="text">
<h3>{props.title}</h3>
</div>
</ResourceInfo>
{
loading ?
(
<LoadingSpinner text="Carregando coleções" />
)
:
(
<ChooseColContainer>
{
creatingCol ?
(
<CriarColecaoForm
handleClose={() => setCreating(false)}
finalize={postToCol}
/>
)
:
(
collsArr.length === 0 ?
(
<>
<div classname="no-cols">
<h2>Você não possui coleções ainda.</h2>
</div>
</>
)
:
(
<>
<ChooseCol>
<h2>Escolha uma Coleção: </h2>
<div className="cols-list">

Lucas Eduardo Schoenfelder
committed
{
collsArr.map(collection =>
<div className="row" key={collection.id}>
<div style={{ display: "flex", flexDirection: "row", justifyContent: "space-between", alignItems: "center" }}>
{
collection.privacy === "public" ?
<PublicIcon className="icon" />
: <LockIcon className="icon" />
}
<h5>{collection.name}</h5>
</div>
<GuardarBotao onClick={() => { postToCol(collection.id) }}>GUARDAR</GuardarBotao>
</div>
)

Lucas Eduardo Schoenfelder
committed
}
</div>
</ChooseCol>
</>
)
)
}
</ChooseColContainer>
}
<div style={{ display: "flex", justifyContent: "center" }}>
<CriarColButton onClick={() => { setCreating(true) }}>CRIAR COLEÇÃO</CriarColButton>
</div>
</Content>
</Container>
</Fade>
</StyledModal>
</React.Fragment>

Lucas Eduardo Schoenfelder
committed
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
)
}
const GuardarBotao = styled(Button)`
&:hover {
background-color : #503096 !important;
}
max-height : 36px !important;
background-color : #673ab7 !important;
color : #fff !important;
box-shadow : 0 2px 5px 0 rgba(0,0,0,.26) !important;
padding-left : 32px !important;
padding-right : 32px !important;
`
const ChooseCol = styled.div`
display : flex;
flex-direction : column;
h2 {
margin-top : 20px;
margin-bottom : 10px;
font-size : 24px;
font-weight : 500;
}
.icon {
vertical-align : middle !important;
font-weight : normal !important;
font-style : normal !important;
font-size : 24px !important;
line-height : 1 !important;
letter-spacing : normal !important;
text-transform : none !important;
display : inline-block !important;
white-space : nowrap !important;
word-wrap : normal !important;
direction : ltr !important;
padding-right : 2px;
}
.cols-list {
overflow-x : hidden;
overflow-y : auto;
.row {
display : flex;
flex-direction : row;
padding : 10px;
border-radius : 5px;
max-height : 60px;
align-items : center;
align-content : center;
max-width : 100%;
justify-content : space-between;
h5 {
padding : 0 20px;
margin : 0;
font-size : 14px;
font-weight : 600;
}
}
}
`
const CriarColButton = styled(Button)`
width : 200px !important;
margin-top : 16px !important;
background-color : #673ab7 !important;
margin-left : auto !important;
margin-right : auto !important;
color : #fff !important;
font-weight : 600 !important;
box-shadow : !important;
padding-left : 0 2px 5px 0 rgba(0,0,0,.26) 16px !important;
padding-right : 16px !important;
`
const ChooseColContainer = styled.div`
display : flex;
flex-direction : column;
color : #666;
.no-cols {
align-self : center;
margin-top : 20px;
margin-bottom : 30px;
font-size : 24px;
font-weight : 500;
}
`
const ResourceInfo = styled.div`
margin-top : 0;
background-color : #f4f4f4;
overflow : hidden;
border-radius : 5px;
display : flex;
flex-direction : column;

Lucas Eduardo Schoenfelder
committed
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
align-items : center;
align-content : center;
max-wdith : 100%;
justify-content : space-between;
.text {
max-height : 100%;
max-width : 66.66%;
display : flex;
flex-direction : column;
text-align : center;
h3 {
font-size : 20px;
font-weight : 500;
padding : 10px;
}
}
img {
object-fit : cover;
height : 115px;
max-width : 165px;
background-color : #e5e5e5;
float : left;
padding : 0;
@media screen and (min-width : 600px) {
margin-right : 20px;
margin-bottom : 0;
}
@media screen and (max-width : 768px) {
width : 100%;
}
}
`
const Content = styled.div`
padding : 20px 30px;
overflow-y : scroll;
`
const Header = styled.div`
display : flex;
flex-direction : row;
padding : 10px 26px 0 26px;
align-items : center;
justify-content : space-between;
height : 64px;
h2 {
font-size : 26px;
font-weight : lighter;
color : #666
}
`
const StyledCloseModalButton = styled(Button)`
display : inline-block;
position : relative;
float : right !important;
margin-right : -8px !important;
background : transparent !important;
min-width: 0 !important;
width : 40px;
`
const StyledModal = styled(Modal)`
.djXaxP{
margin : 0 !important;
}
display : flex;
align-items: center;
justify-content : center;
text-align : center;
padding : 10px !important;
max-width : none;
max-height : none;
`
const Container = styled.div`
box-sizing : border-box;
box-shadow : 0 7px 8px -4px rgba(0,0,0,.2),0 13px 19px 2px rgba(0,0,0,.14),0 5px 24px 4px rgba(0,0,0,.12);
background-color : white;
align : center;
display : flex;
flex-direction : column;
min-width : 240px;
max-height : none;
position : relative;
padding : 10px;
border-radius : 4px;
@media screen and (min-width : 700px) {
max-width : 600px;
max-height : 600px;
}
@media screen and (max-width : 699px) {
width : 100%;
height : 100%;
}
`