Skip to content
Snippets Groups Projects
Commit 9ab6a0d7 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

UP : Ajout d'une option permettant d'ajouter des liens sur les documents

parent cd7940b2
No related branches found
No related tags found
No related merge requests found
......@@ -92,15 +92,35 @@
<div class="overlay-content">
<h2>
Téléverser un nouveau document
dans <strong>{{ selectedIdTypeDocument }}</strong>
dans <strong>{{ selectedTab.label }}</strong>
<span class="overlay-closer" @click="uploadDoc = null">X</span>
</h2>
<div class="alert">
<label for="switch_mode">
Cochez cette case si le fichier est un URL
<input type="checkbox" name="switch_mode" v-model="mode_url">
</label>
</div>
<div style="width: 90%; margin-left: 5%">
<div class="row">
<div class="col-md-6">
<div v-if="mode_url">
<!-- Fichier upload -->
<label for="url">URL du fichier</label>
<input type="text" class="form-control" name="url" id="url"
placeholder="Lien vers la ressource"
v-model="fileUrl" />
<label for="label">Description de l'URL</label>
<input type="text" class="form-control" name="label" id="label"
placeholder="Description rapide de la ressource"
v-model="fileUrlLabel" />
</div>
<div v-else>
<!-- Fichier upload -->
<label for="file">Fichier</label>
<input @change="uploadFile" type="file" class="form-control" name="file" id="file"/>
</div>
<!-- Date de dépot -->
<label>Date de dépôt</label>
<p class="help">Date à laquelle le fichier a été reçu</p>
......@@ -122,7 +142,7 @@
</select>
<!-- PRIVE, SI PRIVE AJOUT PERSONNES -->
<div class="row" style="margin-top: 20px;">
<div class="row" style="margin-top: 20px;" v-if="mode_url != true">
<div class="col-md-6">
<label for="private">Document privé</label>
</div>
......@@ -130,6 +150,9 @@
<input type="checkbox" name="private" id="private" class="form-control" v-model="privateDocument">
</div>
</div>
<div v-else class="alert alert-info">
Les URL ne peuvent pas être définie comme privée dans Oscar
</div>
<span v-if="privateDocument === true">
<h4>Ce document sera classé automatiquement dans l'onglet privé</h4>
<label>Choix des personnes ayant accès à ce document</label>
......@@ -226,10 +249,11 @@
<hr>
<article class="card xs" v-for="doc in tab.documents" :key="doc.id" :class="{'private-document': doc.private }">
<div class="">
<i class="picto icon-doc" :class="'doc' + doc.extension"></i>
<i class="picto icon-anchor-outline" v-if="doc.location == 'link'"></i>
<i class="picto icon-doc" :class="'doc' + doc.extension" v-else></i>
<small class="text-light">{{ doc.category.label }} ~ </small>
<strong>{{doc.fileName}}</strong>
<small class="text-light" :title="doc.fileSize + ' octet(s)'">&nbsp;
<small class="text-light" :title="doc.fileSize + ' octet(s)'" v-if="doc.location != 'url'">&nbsp;
({{doc.fileSize | filesize}}) - Version {{ doc.version }}
</small>
</div>
......@@ -265,7 +289,14 @@
</div>
<nav class="text-right show-over">
<a class="btn btn-default btn-xs" :href="doc.urlDownload" v-if="doc.urlDownload">
<a class="btn btn-default btn-xs"
:href="doc.basename"
v-if="doc.location == 'url'" target="_blank">
<i class="icon-link-ext"></i>
Accéder au lien
</a>
<a class="btn btn-default btn-xs"
:href="doc.urlDownload" v-if="doc.urlDownload && doc.location != 'url'">
<i class="icon-upload-outline"></i>
Télécharger
</a>
......@@ -275,7 +306,7 @@
Nouvelle Version
</button>
-->
<button v-on:click="handlerNewVersion(doc)" class="btn btn-default btn-xs" v-if="tab.manage">
<button v-on:click="handlerNewVersion(doc)" class="btn btn-default btn-xs" v-if="tab.manage && doc.location != 'url'">
<i class="icon-download-outline"></i>
Nouvelle Version
</button>
......@@ -283,7 +314,7 @@
<i class="icon-trash"></i>
Supprimer
</a>
<a class="btn btn-xs btn-default" href="#" @click.prevent="handlerEdit(doc)" v-if="tab.manage">
<a class="btn btn-xs btn-default" href="#" @click.prevent="handlerEdit(doc)" v-if="tab.manage && doc.location != 'url'">
<i class="icon-pencil"></i>
Modifier
</a>
......@@ -339,6 +370,8 @@ export default {
persons: [],
dateDeposit: '',
dateSend: '',
fileUrl: '',
fileUrlLabel: '',
privateDocument: false,
selectedIdTypeDocument: null,
selectedIdTabDocument: null,
......@@ -354,6 +387,7 @@ export default {
'informations': this.informationsDocument,
'persons': this.persons,
'baseUrlUpload': this.urlUploadNewDoc,
'url': '',
'init': false
},
// Message boite modal pour l'utilisateur (erreurs pour exemple)
......@@ -374,6 +408,9 @@ export default {
sortDirection: -1,
editable: true,
remoterState: oscarRemoteData.state,
displayComputed: false,
mode_url: false,
// Onglet active
selectedTab: null,
......@@ -569,6 +606,8 @@ export default {
this.privateDocument = privateTab;
this.selectedIdTypeDocument = typeId;
this.informationsDocument = '';
this.fileUrl = this.uploadNewDocData.url = '';
this.fileUrlLabel = '';
this.persons = [];
// initialise objet de base
this.uploadNewDocData.init = true;
......@@ -610,12 +649,19 @@ export default {
let value = this.uploadNewDocData[key];
fd.append(key, value);
}
if( this.mode_url ){
fd.append('url', this.fileUrl);
fd.append('label_url', this.fileUrlLabel);
} else {
// Document file
if (this.fileToDownload !== null) {
fd.append('file', this.fileToDownload, this.fileToDownload.name);
} else {
this.errorMessages.push("Aucun fichier sélectionner a téléverser !");
}
}
if (this.uploadNewDocData.type === null) {
this.errorMessages.push("Vous devez qualifier le type de votre document !");
}
......
......@@ -39,6 +39,7 @@ use Oscar\Traits\UseServiceContainerTrait;
use Oscar\Utils\FileSystemUtils;
use Oscar\Utils\UnicaenDoctrinePaginator;
use Psr\Container\ContainerInterface;
use Zend\Db\Sql\Ddl\Column\Datetime;
use Zend\Http\Request;
use Zend\Http\Response;
use Zend\Json\Server\Exception\HttpException;
......@@ -273,6 +274,38 @@ class ContractDocumentController extends AbstractOscarController implements UseS
}
}
if( $this->getRequest()->getPost('url') ){
$this->getLoggerService()->info(print_r($_POST, true));
try {
$document = new ContractDocument();
$document
->setVersion(1)
->setDateUpdoad(new \DateTime())
->setFileName($this->getRequest()->getPost('label_url'))
->setPath($this->getRequest()->getPost('url'))
->setLocation(ContractDocument::LOCATION_URL)
->setFileSize(0)
->setFileTypeMime("")
->setInformation($this->getRequest()->getPost('informations'))
->setPerson($this->getCurrentPerson())
->setTabDocument($this->getContractDocumentService()->getContractTabDocument(
$this->getRequest()->getPost('tab')
))
->setTypeDocument($this->getContractDocumentService()->getContractDocumentType(
$this->getRequest()->getPost('type')
))
->setGrant($activity)
->setDateDeposit(new \DateTime())
->setDateSend(new \DateTime());
$this->getEntityManager()->persist($document);
$this->getEntityManager()->flush($document);
return $this->jsonOutput(['message' => 'ok']);
} catch (Exception $e) {
return $this->getResponseInternalError($e->getMessage());
}
}
try {
// Get ID doc pour remplacement ou ajout
$docId = $this->params()->fromRoute('id', null);
......@@ -305,6 +338,7 @@ class ContractDocumentController extends AbstractOscarController implements UseS
$infos = $serviceUpload->getStrategy()->getDatas();
if ($infos['error']) {
$datas['error'] = $infos['error'];
return $this->getResponseInternalError($infos['error']);
} else {
$this->redirect()->toRoute(
'contract/show',
......
......@@ -19,6 +19,10 @@ use Doctrine\ORM\Mapping\ManyToMany;
*/
class ContractDocument extends AbstractVersionnedDocument
{
const LOCATION_LOCAL_FILE = 'local';
const LOCATION_URL = 'url';
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
......@@ -89,11 +93,19 @@ class ContractDocument extends AbstractVersionnedDocument
*/
private $dateSend;
/**
* @var string Emplacement (URL ou fichier physique)
*
* @ORM\Column(type="string", options={"default":"local"})
*/
private $location;
public function __construct()
{
parent::__construct();
$this->persons = new ArrayCollection();
$this->location = self::LOCATION_LOCAL_FILE;
}
......@@ -112,6 +124,23 @@ class ContractDocument extends AbstractVersionnedDocument
return $this->id;
}
/**
* @return string
*/
public function getLocation(): string
{
return $this->location;
}
/**
* @param string $location
*/
public function setLocation(string $location): self
{
$this->location = $location;
return $this;
}
/**
* @return Activity
*/
......@@ -312,12 +341,19 @@ class ContractDocument extends AbstractVersionnedDocument
}
}
$fileName = $this->getFileName();
$basename = preg_replace('/(.*)(\.[\w]*)/', '$1', $this->getFileName());
if( $this->getLocation() == self::LOCATION_URL ){
$basename = $this->getPath();
}
return [
'id' => $this->getId(),
'version' => $this->getVersion(),
'information' => $this->getInformation(),
'fileName' => $this->getFileName(),
'basename' => preg_replace('/(.*)(\.[\w]*)/', '$1', $this->getFileName()),
'fileName' => $fileName,
// 'fileName' => $this->getFileName(),
'basename' => $basename,
'fileSize' => $this->getFileSize(),
'typeMime' => $this->getFileTypeMime(),
'dateUpload' => $this->getDateUpdoad()->format('Y-m-d H:i:s'),
......@@ -328,6 +364,7 @@ class ContractDocument extends AbstractVersionnedDocument
'tabDocument' => $this->getTabDocument() ? $this->getTabDocument()->toJson() : null,
'private' => $this->isPrivate(),
'persons' => $this->personsToJson(),
'location' => $this->getLocation(),
'urlDelete' => $options['urlDelete'],
'urlDownload' => $options['urlDownload'],
'urlReupload' => $options['urlReupload'],
......@@ -379,6 +416,11 @@ class ContractDocument extends AbstractVersionnedDocument
return sprintf("oscar-%s-%s-%s", $this->getGrant()->getId(), $this->getVersion(), $slugify->slugify($this->getFileName()));
}
public function islink() :bool
{
return $this->getLocation() == self::LOCATION_URL;
}
////////////////////////////////////////////////////////////////////////////
......
......@@ -5,12 +5,18 @@ $showDelete = isset($showDelete) && $showDelete === true ? true : false;
<article class="card xs <?= $document->isPrivate() ? 'private-document' : '' ?>" data-openable>
<div class="card-title">
<div>
<?php if( $document->islink() ): ?>
<i class="picto icon-link-ext"></i>
<?php else: ?>
<i class="picto icon-doc doc-<?= $document->getExtension() ?>"></i>
<?php if( $document->isPrivate() ) { echo " BBBBB "; } ?>
<?php endif; ?>
<small class="text-light"><?= $document->getTypeDocument() ?> ~ </small> <br>
<strong><?= $document->getFileName() ?></strong>
</div>
<?php if( !$document->islink() ): ?>
<small class="text-light">&nbsp;(<?= $this->fileSize($document->getFileSize()) ?>)</small>
<?php endif; ?>
</div>
<div class="card-content">
<p class="text-highlight" style="display: none">
......@@ -23,11 +29,18 @@ $showDelete = isset($showDelete) && $showDelete === true ? true : false;
</p>
<?php endif; ?>
<nav class="text-right show-over">
<a class="btn btn-default btn-xs" href="<?= $this->url('contractdocument/download',
['id' => $document->getId()]) ?>">
<?php if( $document->islink() ): ?>
<a class="btn btn-default btn-xs" href="<?= $document->getPath() ?>" target="_blank">
<i class="icon-link-ext"></i>
Ouvrir le lien
</a>
<?php else: ?>
<a class="btn btn-default btn-xs" href="<?= $this->url('contractdocument/download',['id' => $document->getId()]) ?>">
<i class="icon-download-outline"></i>
Télécharger le fichier
</a>
<?php endif; ?>
<?php if($showDelete): ?>
<a class="btn btn-default btn-xs" data-confirm="Êtes-vous sûr de vouloir supprimer ce document ?" data-href="<?= $this->url('contractdocument/delete',
['id' => $document->getId()]) ?>">
......
......@@ -4,6 +4,10 @@
DÉPENSES 2 13106
</div>
<?= $this->Vite()->addJs('src/ActivitySpentSynthesis.js'); ?>
<div id="unexpected"></div>
<?= $this->Vite()->addJs('src/Unexpected.js'); ?>
<!--
Selecteur de structure :
<div id="foo"></div>
......
This diff is collapsed.
This diff is collapsed.
import { createApp } from 'vue'
import ActivityDocument from './views/ActivityDocument.vue'
let elemDatas = document.querySelector('#activitydocuments');
const app = createApp(ActivityDocument, {
"url": elemDatas.dataset.url,
"manage": elemDatas.dataset.manage
})
app.mount('#activitydocuments')
\ No newline at end of file
<template>
<section>
DOCUMENTS
</section>
</template>
<script>
import axios from "axios";
export default {
props: {
url: {
required: true
}
},
computed:{
},
data(){
return {
pendingMsg: null
}
},
methods: {
fetch(){
this.pendingMsg = "Chargement des données financières";
axios.get(this.url).then(
ok => {
console.log("OK",ok);
this.infos = ok.data.synthesis;
this.masses = ok.data.masses;
},
ko => {
console.log(ko)
}
).then(foo=> {
this.pendingMsg = false;
})
}
},
mounted() {
this.fetch()
}
}
</script>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment