Fix image edition

pull/3413/head
Julio Montoya 4 years ago
parent bcd4249b7a
commit a1a590a6fb
  1. 32
      assets/vue/components/documents/FormNewDocument.vue
  2. 1
      assets/vue/mixins/UpdateMixin.js
  3. 3
      src/CoreBundle/Entity/Listener/ResourceListener.php
  4. 2
      src/CoreBundle/Entity/Listener/ResourceNodeListener.php
  5. 61
      src/CoreBundle/Entity/ResourceNode.php
  6. 25
      src/CoreBundle/EventSubscriber/ResolveResourceFileContentUrlSubscriber.php

@ -12,6 +12,7 @@
@blur="$v.item.title.$touch()"
/>
<editor
v-if="item.resourceNode && item.resourceNode.fileEditableText"
:error-messages="contentFileErrors"
required
v-model="item.contentFile"
@ -39,12 +40,12 @@
}
},*/
images_upload_handler: (blobInfo, success, failure) => {
console.log(blobInfo);
/*console.log(blobInfo);
console.log(success);
console.log(failure);
console.log(failure);*/
const img = 'data:image/jpeg;base64,' + blobInfo.base64();
console.log(img);
//console.log(img);
success(img);
},
//menubar: true,
@ -96,6 +97,7 @@ export default {
title: null,
contentFile: null,
parentResourceNodeId: null,
resourceNode: null,
};
},
computed: {
@ -104,7 +106,6 @@ export default {
},
titleErrors() {
const errors = [];
if (!this.$v.item.title.$dirty) return errors;
has(this.violations, 'title') && errors.push(this.violations.title);
!this.$v.item.title.required && errors.push(this.$t('Field is required'));
@ -113,12 +114,24 @@ export default {
},
contentFileErrors() {
const errors = [];
if (!this.$v.item.contentFile.$dirty) return errors;
has(this.violations, 'contentFile') && errors.push(this.violations.contentFile);
!this.$v.item.contentFile.required && errors.push(this.$t('Content is required'));
if (this.item.resourceNode && this.item.resourceNode.fileEditableText) {
if (!this.$v.item.contentFile.$dirty) return errors;
has(this.violations, 'contentFile') && errors.push(this.violations.contentFile);
!this.$v.item.contentFile.required && errors.push(this.$t('Content is required'));
}
return errors;
},
resourceNodeErrors() {
const errors = [];
if (!this.$v.item.resourceNode.$dirty) return errors;
has(this.violations, 'resourceNode') && errors.push(this.violations.resourceNode);
!this.$v.item.resourceNode.required && errors.push(this.$t('resourceNode is required'));
return errors;
},
violations() {
return this.errors || {};
}
@ -166,9 +179,12 @@ export default {
required,
},
contentFile: {
required,
//required,
},
parentResourceNodeId: {
},
resourceNode:{
required,
}
}
}

@ -36,7 +36,6 @@ export default {
let item = this.find(decodeURIComponent(id));
return item;
//return this.find(decodeURIComponent(this.$route.params.id));
}
},

@ -218,7 +218,6 @@ class ResourceListener
}
$resource->setResourceNode($resourceNode);
//$em->persist($resourceNode);
return $resourceNode;
}
@ -235,7 +234,6 @@ class ResourceListener
$resourceNode->setTitle($resource->getResourceName());
if ($resource->hasUploadFile()) {
error_log('found a uploadFile');
$uploadedFile = $resource->getUploadFile();
// File upload
@ -249,7 +247,6 @@ class ResourceListener
}
}
/*
error_log($fieldIdentifier);
$em = $event->getEntityManager();

@ -55,7 +55,7 @@ class ResourceNodeListener
{
error_log('resource node preUpdate');
if ($resourceNode->hasResourceFile() && $resourceNode->hasEditableContent()) {
if ($resourceNode->hasResourceFile() && $resourceNode->isFileEditableText()) {
$fileName = $this->resourceNodeRepository->getFilename($resourceNode->getResourceFile());
if ($fileName) {
$content = $resourceNode->getContent();

@ -46,6 +46,7 @@ class ResourceNode
{
use TimestampableEntity;
use TimestampableAgoTrait;
public const PATH_SEPARATOR = '`';
/**
@ -177,8 +178,6 @@ class ResourceNode
*/
protected $createdAt;
protected $content;
/**
* @var \DateTime
*
@ -188,6 +187,15 @@ class ResourceNode
*/
protected $updatedAt;
/**
* @var bool
*
* @Groups({"resource_node:read", "document:read"})
*/
protected $fileEditableText;
protected $content;
/**
* Constructor.
*/
@ -198,6 +206,7 @@ class ResourceNode
$this->resourceLinks = new ArrayCollection();
$this->comments = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->editableContent = false;
}
/**
@ -480,26 +489,17 @@ class ResourceNode
return $links->matching($criteria);
}
/**
* @return bool
*/
public function hasResourceFile()
public function hasResourceFile(): bool
{
return null !== $this->resourceFile;
}
/**
* @return ResourceFile
*/
public function getResourceFile(): ?ResourceFile
{
return $this->resourceFile;
}
/**
* @return bool
*/
public function hasEditableContent()
public function hasEditableContent(): bool
{
if ($this->hasResourceFile()) {
$mimeType = $this->getResourceFile()->getMimeType();
@ -511,10 +511,12 @@ class ResourceNode
return false;
}
/**
* @return bool
*/
public function isResourceFileAnImage()
public function isFileEditableText(): bool
{
return $this->hasEditableContent();
}
public function isResourceFileAnImage(): bool
{
if ($this->hasResourceFile()) {
$mimeType = $this->getResourceFile()->getMimeType();
@ -526,10 +528,7 @@ class ResourceNode
return false;
}
/**
* @return bool
*/
public function isResourceFileAVideo()
public function isResourceFileAVideo(): bool
{
if ($this->hasResourceFile()) {
$mimeType = $this->getResourceFile()->getMimeType();
@ -548,10 +547,7 @@ class ResourceNode
return $this;
}
/**
* @return string
*/
public function getIcon()
public function getIcon(): string
{
$class = 'fa fa-folder';
if ($this->hasResourceFile()) {
@ -568,10 +564,7 @@ class ResourceNode
return '<i class="'.$class.'"></i>';
}
/**
* @return string
*/
public function getThumbnail(RouterInterface $router)
public function getThumbnail(RouterInterface $router): string
{
$size = 'fa-3x';
$class = "fa fa-folder $size";
@ -602,20 +595,12 @@ class ResourceNode
return '<i class="'.$class.'"></i>';
}
/**
* @return mixed
*/
public function getContent()
{
return $this->content;
}
/**
* @param mixed $content
*
* @return ResourceNode
*/
public function setContent($content)
public function setContent(string $content): self
{
$this->content = $content;

@ -17,12 +17,12 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class ResolveResourceFileContentUrlSubscriber implements EventSubscriberInterface
{
private $generator;
private $nodeRepository;
private $resourceNodeRepository;
public function __construct(UrlGeneratorInterface $generator, ResourceNodeRepository $nodeRepository)
public function __construct(UrlGeneratorInterface $generator, ResourceNodeRepository $resourceNodeRepository)
{
$this->generator = $generator;
$this->nodeRepository = $nodeRepository;
$this->resourceNodeRepository = $resourceNodeRepository;
}
public static function getSubscribedEvents(): array
@ -54,23 +54,28 @@ class ResolveResourceFileContentUrlSubscriber implements EventSubscriberInterfac
$mediaObjects = [$mediaObjects];
}
//error_log($request->get('getFile'));
//$getFile = $request->get('getFile');
$getFile = true;
$getFile = $request->get('getFile');
//$getFile = true;
foreach ($mediaObjects as $mediaObject) {
if (!$mediaObject instanceof AbstractResource) {
continue;
}
if ($mediaObject->hasResourceNode()) {
$resourceNode = $mediaObject->getResourceNode();
$params = [
'id' => $mediaObject->getResourceNode()->getId(),
'tool' => $mediaObject->getResourceNode()->getResourceType()->getTool()->getName(),
'type' => $mediaObject->getResourceNode()->getResourceType()->getName(),
'id' => $resourceNode->getId(),
'tool' => $resourceNode->getResourceType()->getTool()->getName(),
'type' => $resourceNode->getResourceType()->getName(),
];
$mediaObject->contentUrl = $this->generator->generate('chamilo_core_resource_view_file', $params);
if ($getFile && $mediaObject->getResourceNode()->hasResourceFile()) {
//$mediaObject->contentFile = $this->nodeRepository->getResourceNodeFileContent($mediaObject->getResourceNode());
if ($getFile &&
$resourceNode->hasResourceFile() &&
$resourceNode->hasEditableContent()
) {
$mediaObject->contentFile = $this->resourceNodeRepository->getResourceNodeFileContent($resourceNode);
}
}
}

Loading…
Cancel
Save