Skip to content

Commit

Permalink
browse attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
gwen001 committed Apr 30, 2017
1 parent 377748d commit 29cb589
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 276 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
/.tmp/
/.sass-cache/
/.idea/*
/web/attachments/*
3 changes: 3 additions & 0 deletions full_install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ ln -s /etc/php5/mods-available/yaml.ini /etc/php5/apache2/conf.d/20-yaml.ini
ln -s /etc/php5/mods-available/yaml.ini /etc/php5/cli/conf.d/20-yaml.ini


(Ubuntu)
aptitude install php7 php7-dev php7-curl php-pecl-http
aptitue install libnet-ssleay-perl
cp /usr/include/php/20151012/ext/standard/php_smart_str.h /usr/include/php/20151012/ext/standard/php_smart_string.h


Database
Expand Down
61 changes: 61 additions & 0 deletions src/ArusEntityAttachmentBundle/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use ArusEntityAttachmentBundle\Entity\Search;
use ArusEntityAttachmentBundle\Form\SearchType;

use ArusProjectBundle\Entity\ArusProject;

use Actarus\Utils;


Expand Down Expand Up @@ -262,4 +264,63 @@ public function getListAction(Request $request, $entity_id)
echo $this->get('entity_attachment')->getListAction( $entity_id );
exit();
}


public function browseAction(Request $request)
{
$absolute_path = dirname($this->get('kernel')->getRootDir()).'/web/'.$this->getParameter('attachments_path');
//var_dump($absolute_path);

$d = opendir( $absolute_path );
$t_dir = [];

while( ($o=readdir($d)) ) {
$p = $absolute_path.$o;
if( (int)$o && is_dir($p)) {
$t_dir[$o] = count( glob($p.'/*') );
}
}

//var_dump( $t_dir );
closedir( $d );

$em = $this->getDoctrine()->getManager();
$t_project = $em->getRepository('ArusProjectBundle:ArusProject')->findArray();
//var_dump( $t_project );

$t_final = [];
foreach( $t_project as $id=>$name ) {
if( isset($t_dir[$id]) ) {
$t_final[$id] = [ $name, $t_dir[$id] ];
}
}
//var_dump( $t_final );

return $this->render('ArusEntityAttachmentBundle:Default:browse.html.twig', array(
't_dir' => $t_final,
't_project' => $t_project,
));
}


public function listAction(Request $request, ArusProject $project)
{
$t_entity_type = array_flip( $this->getParameter('entity')['type'] );
$t_attachment = $this->get('entity_attachment')->search( ['project'=>$project] );
$absolute_path = dirname($this->get('kernel')->getRootDir()).'/web/'.$this->getParameter('attachments_path').$project->getId();
//var_dump( count($t_attachment) );

$t_size = [];
foreach( $t_attachment as $a ) {
$f = $absolute_path.'/'.$a->getFilename();
$t_size[ $a->getId() ] = filesize( $f );
}

return $this->render('ArusEntityAttachmentBundle:Default:list.html.twig', array(
'project' => $project,
't_size' => $t_size,
't_attachment' => $t_attachment,
't_entity_type' => $t_entity_type,
));
}
}
9 changes: 9 additions & 0 deletions src/ArusEntityAttachmentBundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ attachment_delete:
path: /attachment/{id}/delete
defaults: { _controller: "ArusEntityAttachmentBundle:Default:delete" }
methods: DELETE

attachment_browse:
path: /attachment/browse
defaults: { _controller: "ArusEntityAttachmentBundle:Default:browse" }

attachment_list:
path: /attachment/list/{id}
defaults: { _controller: "ArusEntityAttachmentBundle:Default:list" }
methods: [GET]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends 'base.html.twig' %}


{% block body %}
<div class="mod mod-attachment-browse">

<a href="{{ url('attachment_homepage') }}" class="btn btn-default pull-right" style="margin-right:20px;">Back</a>

<h2 class="page-title">Browse attachment</h2>

<div class="row">
<div class="col-md-12">
{% for id,d in t_dir %}
{% set title = d.0 ~ ' (' ~ d.1 ~ ')' %}
<div class="col-md-1">
<a href="{{ url('attachment_list',{id:id}) }}">
<img src="{{ asset("img/folder.png") }}" alt="{{ title }}" title="{{ title }}" />
<br />
{{ title }}
</a>
</div>
{% if loop.index%12 == 0 %}
</div>
<div class="col-md-12">
{%endif %}
{% endfor %}
</div>
</div>
</div>
{% endblock %}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

{% block body %}
<div class="mod mod-attachment">

<a href="{{ url('attachment_browse') }}" class="btn btn-success pull-right" style="margin-right:20px;">Browse directory</a>

<h2 class="page-title">Attachment managment</h2>

<div class="row">
Expand Down
156 changes: 28 additions & 128 deletions src/ArusEntityAttachmentBundle/Resources/views/Default/list.html.twig
Original file line number Diff line number Diff line change
@@ -1,129 +1,29 @@
<div class="mod mod-attachments panel panel-danger">
<div class="panel-heading">
Attachments ({{ t_attachment|length }})
<a href="#" class="pull-right btn btn-warning btn-xs attachment-add">Add attachment</a>
{% extends 'base.html.twig' %}


{% block body %}
<div class="mod mod-attachment-list">

<a href="{{ url('attachment_browse') }}" class="btn btn-default pull-right" style="margin-right:20px;">Back</a>

<h2 class="page-title">Browse attachment / {{ project.getName() }}</h2>

<div class="row">
<div class="col-md-12">
{% for a in t_attachment %}
{% set title = a.getTitle() %}
<div class="col-md-2 preview">
<a href="{{ attachments_path }}{{ project.getId() }}/{{ a.getFilename() }}" data-featherlight="image" title="{{ a.getTitle() }}"><img src="{{ attachments_path }}{{ project.getId() }}/{{ a.getFilename() }}" title="{{ a.getTitle() }}" /></a>
<br />
<a href="{{ url(t_entity_type[a.getEntity().getType()]~'_show',{'id':a.getEntity().getId()}) }}" target="_blank">{{ title }}</a>
({{ t_size[a.getId()] }})
</div>
{% if loop.index%12 == 0 %}
</div>
<div class="col-md-12">
{%endif %}
{% endfor %}
</div>
</div>
</div>
<div class="panel-body">
{% for alt in t_attachment %}
{{ include('ArusEntityAttachmentBundle:Default:unit.html.twig') }}
{% endfor %}
</div>
</div>

<script type="text/javascript">
$(document).ready(function() {
if( $('.panel-info') ) {
window.setTimeout( function(){$('.mod-attachments .panel-body').css('height', $('.panel-info .panel-body').css('height'))}, 300 );
window.setTimeout( function(){$('.mod-attachments .panel-body').css('max-height', $('.panel-info .panel-body').css('height'))}, 300 );
}
});
</script>

<script type="text/javascript">
$(document).ready(function() {
$('.attachment-confirm').unbind();
$('.attachment-confirm').on('click', function(e) {
e.preventDefault();
obj = $(this);
url = obj.attr('href');
$.ajax({
url: url,
method: 'POST'
}).done(function(){
reloadBlock( '.mod-attachments', '{{ url('attachment_getlist',{'entity_id':entity_id}) }}' );
});
});
$('.attachment-cancel').unbind();
$('.attachment-cancel').on('click', function(e) {
e.preventDefault();
obj = $(this);
url = obj.attr('href');
$.ajax({
url: url,
method: 'POST'
}).done(function(){
reloadBlock( '.mod-attachments', '{{ url('attachment_getlist',{'entity_id':entity_id}) }}' );
});
});
});
</script>

<script type="text/javascript">
$(document).ready(function() {
$('#modalAttachmentAdd').unbind();
$('.attachment-add').on('click', function(e) {
e.preventDefault();
$('#modalAttachmentAdd').modal();
$('#modalAttachmentAdd').on('click','#confirm-save',function(e){
e.preventDefault();
form = $('#modalAttachmentAdd form');
$.post( form.attr('action'), form.serialize(), function(data) {
$('#modalAttachmentAdd').find('.close').click();
reloadBlock( '.mod-attachments', '{{ url('attachment_getlist',{'entity_id':entity_id}) }}' );
});
});
});
$('#modalAttachmentAdd').on('shown.bs.modal', function () {
$('#modalAttachmentAdd form').find('#arus_entity_attachment_add_descr').focus();
});
$('#modalAttachmentAdd').on('hide.bs.modal',function(){
$('#modalAttachmentAdd form')[0].reset();
});
});
</script>

<script type="text/javascript">
$(document).ready(function() {
$('#modalAttachmentEdit').unbind();
$('.attachment-edit').on('click', function(e) {
e.preventDefault();
obj = $(this);
url = obj.attr('href');
level = parseInt( obj.parent().parent().find('.attachment-level').html() );
$('#modalAttachmentEdit').modal();
form = $('#modalAttachmentEdit form');
form.attr( 'action', url );
form.find('#arus_entity_attachment_edit_limited_level_'+level).prop('checked',true);
form.find('#arus_entity_attachment_edit_limited_descr').val( obj.parent().parent().find('.attachment-descr').html() );
form.find('#arus_entity_attachment_edit_limited_entity_id').val( obj.attr('data-entity-id') );
$('#modalAttachmentEdit').on('click','#confirm-save',function(e){
form = $('#modalAttachmentEdit form');
$.post( form.attr('action'), form.serialize(), function(data) {
$('#modalAttachmentEdit').find('.close').click();
reloadBlock( '.mod-attachments', '{{ url('attachment_getlist',{'entity_id':entity_id}) }}' );
});
});
});
$('#modalAttachmentEdit').on('shown.bs.modal', function () {
$('#modalAttachmentEdit form').find('#arus_entity_attachment_edit_limited_descr').focus();
});
$('#modalAttachmentEdit').on('hide.bs.modal',function(){
$('#modalAttachmentEdit form')[0].reset();
});
});
</script>

<script type="text/javascript">
$(document).ready(function() {
$('#modalAttachmentDelete').unbind();
$('.attachment-delete').on('click', function(e) {
e.preventDefault();
obj = $(this);
url = obj.attr('href');
$('#modalAttachmentDelete').modal();
$('#modalAttachmentDelete').on('click','#confirm-delete',function(e){
e.preventDefault();
$.ajax({
url: url,
method: 'DELETE'
}).done(function(){
$('#modalAttachmentDelete').find('.close').click();
reloadBlock( '.mod-attachments', '{{ url('attachment_getlist',{'entity_id':entity_id}) }}' );
});
});
});
});
</script>
{% endblock %}
Loading

0 comments on commit 29cb589

Please sign in to comment.