Get resource link in the show page.

pull/3346/head
Julio Montoya 5 years ago
parent d5b0102945
commit f731918f43
  1. 4
      assets/vue/App.vue
  2. 1
      assets/vue/components/ErrorMessage.vue
  3. 3
      assets/vue/components/course/Form.vue
  4. 9
      assets/vue/main.js
  5. 10
      assets/vue/mixins/ListMixin.js
  6. 36
      assets/vue/mixins/ShowMixin.js
  7. 3
      assets/vue/router/documents.js
  8. 3
      assets/vue/services/resourcelink.js
  9. 15
      assets/vue/store/modules/crud.js
  10. 5
      assets/vue/views/Login.vue
  11. 35
      assets/vue/views/documents/Show.vue
  12. 4
      config/services.yaml
  13. 1
      src/CoreBundle/Entity/AbstractResource.php
  14. 39
      src/CoreBundle/Entity/ResourceLink.php
  15. 4
      src/CoreBundle/Entity/ResourceNode.php
  16. 5
      src/CoreBundle/Entity/Usergroup.php
  17. 24
      src/CoreBundle/Security/HTTPExceptionListener.php
  18. 4
      src/CourseBundle/Entity/CDocument.php

@ -368,6 +368,10 @@
return new Promise(() => {
if (err.response.status === 401) {
this.$router.push({path: "/login"})
} else if (err.response.status === 500) {
document.open();
document.write(err.response.data);
document.close();
}
throw err;
});

@ -4,6 +4,7 @@
role="alert"
>
{{ error.response.data.error }}
{{ error.response.data.message }}
</div>
</template>

@ -49,7 +49,6 @@
/>
</v-col>
</v-row>
</v-container>
</v-form>
</template>
@ -151,7 +150,7 @@
},
methods: {
...mapActions({
categoryGetSelectItems: 'coursecategory/fetchSelectItems'
categoryGetSelectItems: 'coursecategory/load'
}),
},
validations: {

@ -5,6 +5,7 @@ import store from "./store";
import courseCategoryService from './services/coursecategory';
import documentsService from './services/documents';
import courseService from './services/course';
import resourceLinkService from './services/resourcelink';
import makeCrudModule from './store/modules/crud';
import vuetify from './plugins/vuetify' // path to vuetify export
require('@fancyapps/fancybox');
@ -28,7 +29,6 @@ const apolloProvider = new VueApollo({
defaultClient: apolloClient,
});
//import './quasar'
store.registerModule(
'course',
makeCrudModule({
@ -36,6 +36,13 @@ store.registerModule(
})
);
store.registerModule(
'resourcelink',
makeCrudModule({
service: resourceLinkService
})
);
store.registerModule(
'coursecategory',
makeCrudModule({

@ -84,18 +84,16 @@ export default {
showHandler(item) {
let folderParams = this.$route.query;
folderParams['id'] = item['@id'];
this.$router.push({
name: `${this.$options.servicePrefix}Show`,
params: { id: item['@id'] },
//params: { id: item['@id'] },
query: folderParams
});
},
handleClick(item) {
/*this.$router.push({
name: `${this.$options.servicePrefix}Show`,
params: { id: item['@id'] }
});*/
let folderParams = this.$route.query;
this.resetList = true;
this.$route.params.node = item['resourceNode']['id'];
@ -112,9 +110,7 @@ export default {
/*console.log(item['resourceNode']['id']);
this.$route.params.node = item['resourceNode']['id'];
this.onUpdateOptions(this.options);*/
},
editHandler(item) {
let folderParams = this.$route.query;
this.$router.push({

@ -1,15 +1,42 @@
import isEmpty from 'lodash/isEmpty';
import NotificationMixin from './NotificationMixin';
import { formatDateTime } from '../utils/dates';
import {mapActions, mapGetters} from "vuex";
export default {
mixins: [NotificationMixin],
created() {
this.retrieve(decodeURIComponent(this.$route.params.id));
// Changed
let id = this.$route.params.id;
if (isEmpty(id)) {
id = this.$route.query.id;
}
this.retrieve(decodeURIComponent(id));
//this.retrieve(decodeURIComponent(this.$route.params.id));
},
computed: {
item() {
return this.find(decodeURIComponent(this.$route.params.id));
// Changed
let id = this.$route.params.id;
if (isEmpty(id)) {
id = this.$route.query.id;
}
let item = this.find(decodeURIComponent(id));
if (item) {
item.resourceNode.resourceLinks.forEach((link) => {
this.resourcelinkfind('/api/resource_links/' + link.id).then( data => {
if (data) {
link = data;
return data;
}
});
});
}
return item;
//return this.find(decodeURIComponent(this.$route.params.id));
},
},
methods: {
list() {
@ -31,7 +58,10 @@ export default {
name: `${this.$options.servicePrefix}Update`,
params: { id: this.item['@id'] }
});
}
},
...mapActions({
resourcelinkfind: 'resourcelink/loadItem'
}),
},
watch: {
error(message) {

@ -27,7 +27,8 @@ export default {
},
{
name: 'DocumentsShow',
path: ':id',
//path: ':id',
path: 'show',
component: () => import('../views/documents/Show')
}
]

@ -0,0 +1,3 @@
import makeService from './api';
export default makeService('resource_links');

@ -139,11 +139,26 @@ export default function makeCrudModule({
.find(id)
.then(response => response.json())
.then(item => {
console.log(item);
commit(ACTIONS.TOGGLE_LOADING);
commit(ACTIONS.ADD, normalizeRelations(item));
})
.catch(e => handleError(commit, e));
},
loadItem: ({ commit }, id) => {
if (!service) throw new Error('No service specified!');
commit(ACTIONS.TOGGLE_LOADING);
service
.find(id)
.then(response => response.json())
.then(item => {
console.log(item);
return item;
})
.catch(e => handleError(commit, e));
},
resetCreate: ({ commit }) => {
commit(ACTIONS.RESET_CREATE);
},

@ -1,5 +1,4 @@
<template>
<v-container
class="fill-height"
fluid
@ -24,7 +23,6 @@
<v-card-text>
<v-form>
<v-text-field
v-model="login"
label="Login"
name="login"
@ -33,7 +31,6 @@
></v-text-field>
<v-text-field
v-model="password"
id="password"
label="Password"
@ -58,7 +55,6 @@
<error-message :error="error" />
</div>
<v-spacer></v-spacer>
<v-btn color="primary"
:disabled="login.length === 0 || password.length === 0 || isLoading"
@ -100,7 +96,6 @@
}
},
created() {
console.log('login CREATED');
let redirect = this.$route.query.redirect;
if (this.$store.getters["security/isAuthenticated"]) {
if (typeof redirect !== "undefined") {

@ -11,6 +11,25 @@
<br />
<div v-if="item" class="table-documents-show">
<div v-if="item['resourceNode']['resourceLinks']">
<ul>
<li
v-for="link in item['resourceNode']['resourceLinks']"
>
{{ link.id }}
{{ link.visibility }}
{{ link.course }}
{{ link.session }}
{{ link.published }}
{{ link.visibilityName }}
</li>
</ul>
</div>
<v-simple-table>
<template slot="default">
<thead>
@ -36,7 +55,7 @@
<tr>
<td><strong>{{ $t('Created at') }}</strong></td>
<td>
{{ item['resourceNode'] && item['resourceNode'].createdAt }}
{{ item['resourceNode'] && item['resourceNode'].createdAt | moment("from", "now") }}
</td>
<td></td>
</tr>
@ -44,7 +63,9 @@
<td><strong>{{ $t('file') }}</strong></td>
<td>
<div v-if="item['resourceNode']['resourceFile']">
<img v-bind:src=" item['contentUrl'] " />
<v-img
v-bind:src=" item['contentUrl'] "
></v-img>
</div>
<div v-else>
-
@ -56,7 +77,6 @@
</template>
</v-simple-table>
</div>
<Loading :visible="isLoading" />
</div>
</template>
@ -82,14 +102,19 @@ export default {
...mapFields('documents', {
isLoading: 'isLoading'
}),
...mapGetters('documents', ['find'])
...mapGetters('documents', ['find']),
},
methods: {
...mapActions('documents', {
deleteItem: 'del',
reset: 'resetShow',
retrieve: 'load'
})
}),
/*...mapActions('resourcelink', {
resourcelinkfind: 'load',
}),*/
}
};
</script>

@ -98,6 +98,10 @@ services:
tags:
- {name: security.voter}
Chamilo\CoreBundle\Security\HTTPExceptionListener:
tags:
- { name: kernel.event_listener, event: kernel.exception }
sylius_settings:
driver: doctrine/orm

@ -9,6 +9,7 @@ use ApiPlatform\Core\Annotation\ApiSubresource;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Validator\Constraints as Assert;
/**

@ -12,8 +12,6 @@ use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* shortName="ResourceLink",
* normalizationContext={"groups"={"resource_link:read", "course:read"}}
* )
* @ORM\Entity
* @ORM\Table(name="resource_link")
@ -26,6 +24,7 @@ class ResourceLink
public const VISIBILITY_DELETED = 3;
/**
* @Groups({"resource_node:read", "resource_node:write", "document:write", "document:read"})
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
@ -63,6 +62,8 @@ class ResourceLink
protected $group;
/**
* @Groups({"resource_node:read", "resource_node:write", "document:write", "document:read"})
*
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Usergroup")
* @ORM\JoinColumn(name="usergroup_id", referencedColumnName="id", nullable=true)
*/
@ -77,20 +78,27 @@ class ResourceLink
protected $resourceRight;
/**
* @var int
*
* @Groups({"resource_link:read", "resource_node:read", "course:read"})
* @Groups({"resource_node:read", "resource_node:write", "document:write", "document:read"})
*
* @ORM\Column(name="visibility", type="integer", nullable=false)
*/
protected $visibility;
/**
* @Groups({"resource_link:read", "resource_node:read", "course:read"})
*/
protected $linkName;
/**
* @Groups({"resource_link:read", "resource_node:read", "document:read"})
*
* @ORM\Column(name="start_visibility_at", type="datetime", nullable=true)
*/
protected $startVisibilityAt;
/**
* @Groups({"resource_link:read", "resource_node:read", "course:read"})
*
* @ORM\Column(name="end_visibility_at", type="datetime", nullable=true)
*/
protected $endVisibilityAt;
@ -101,6 +109,27 @@ class ResourceLink
public function __construct()
{
$this->resourceRight = new ArrayCollection();
$this->linkName = 'ju';
}
/**
* @return int
*/
public function getLinkName()
{
return $this->linkName;
}
/**
* @param int $linkName
*
* @return ResourceLink
*/
public function setLinkName(int $linkName): ResourceLink
{
$this->linkName = $linkName;
return $this;
}
/**

@ -76,8 +76,8 @@ class ResourceNode
protected $resourceType;
/**
* @Groups({"resource_node:read", "resource_node:write", "document:write"})
*
* @Groups({"resource_node:read", "resource_node:write", "document:write", "document:read"})
* @ApiSubresource()
* @var ResourceLink[]
*
* @ORM\OneToMany(targetEntity="ResourceLink", mappedBy="resourceNode", cascade={"persist", "remove"})

@ -4,11 +4,16 @@
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
/**
* @ApiResource(
* normalizationContext={"groups"={"usergroup:read"}}
* )
*
* @ORM\Table(name="usergroup")
* @ORM\Entity
*/

@ -0,0 +1,24 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Security;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;
final class HTTPExceptionListener
{
public function onKernelException(ExceptionEvent $event): void
{
$exception = $event->getThrowable();
if (! ($exception instanceof HttpException) || strpos($event->getRequest()->getRequestUri(), '/api/') === false) {
return;
}
$response = new JsonResponse(['error' => $exception->getMessage()]);
$response->setStatusCode($exception->getStatusCode());
$event->setResponse($response);
}
}

@ -106,8 +106,8 @@ use Symfony\Component\Serializer\Annotation\Groups;
* @ORM\Index(name="idx_cdoc_sid", columns={"session_id"}),
* }
* )
* @GRID\Source(columns="iid, title, resourceNode.createdAt", filterable=false, groups={"resource"})
* @GRID\Source(columns="iid, title", filterable=false, groups={"editor"})
* GRID\Source(columns="iid, title, resourceNode.createdAt", filterable=false, groups={"resource"})
* GRID\Source(columns="iid, title", filterable=false, groups={"editor"})
* @ORM\Entity
*/
class CDocument extends AbstractResource implements ResourceInterface, ResourceToCourseInterface

Loading…
Cancel
Save