Skip to content

Commit

Permalink
Added file uploads for #81
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Jul 21, 2014
1 parent 56d619b commit f3c2369
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 31 deletions.
19 changes: 10 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/bootstrap/compiled.php
/vendor
composer.phar
.DS_Store
/app/config/*/app.php
/app/config/*/database.php
/app/config/*/mail.php
/app/config/database.php
/app/config/mail.php
/app/database/*.sqlite
/app/storage/debugbar/
/app/storage/logs/*
/app/storage/meta/services.json
/app/config/*/mail.php
/app/config/*/database.php
/app/config/*/app.php
public/packages/*
/app/storage/uploads/*
/app/storage/views/*
/app/storage/logs/*
/app/storage/debugbar/
/bootstrap/compiled.php
/vendor
composer.phar
public/packages/*
42 changes: 41 additions & 1 deletion app/controllers/admin/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Input;
use Lang;
use Asset;
use FileUpload;
use Supplier;
use Statuslabel;
use User;
Expand Down Expand Up @@ -172,6 +173,8 @@ public function postCreate()
// get the POST data
$new = Input::all();

$file = Input::file('file');

// create a new model instance
$asset = new Asset();

Expand Down Expand Up @@ -225,8 +228,44 @@ public function postCreate()

// Was the asset created?
if($asset->save()) {
$assetid = $asset->id;

if ($file) {

// Make the directory if it doesn't exist
if (!file_exists(storage_path().'/uploads/assets/asset-'.$assetid)) {
mkdir(storage_path().'/uploads/assets/asset-'.$assetid, 0755, true);
}

// Strip out spaces in filenames and upload
$cleaner_name = str_replace(" ",'-',Input::file('file')->getClientOriginalName());
$upload_success = Input::file('file')->move(storage_path().'/uploads/assets/asset-'.$assetid, $cleaner_name);

if( $upload_success) {

$uploadfile = new FileUpload();
$uploadfile->asset_id = $assetid;
$uploadfile->filename = $cleaner_name;
$uploadfile->created_at = date("Y-m-d H:i:s");
$uploadfile->user_id = Sentry::getUser()->id;
$uploadfile->filenotes = e(Input::get('note'));
$uploadfile->save();

$logaction = new Actionlog();
$logaction->asset_id = $assetid;
$logaction->asset_type = 'file';
$logaction->user_id = Sentry::getUser()->id;
$logaction->note = $cleaner_name;
$log = $logaction->logaction('uploaded');


}

}


// Redirect to the asset listing page
return Redirect::to("hardware")->with('success', Lang::get('admin/hardware/message.create.success'));
return Redirect::to("hardware/$assetid/view")->with('success', Lang::get('admin/hardware/message.create.success'));
}
} else {
// failure
Expand Down Expand Up @@ -533,6 +572,7 @@ public function getView($assetId = null)
if (isset($asset->id)) {

$settings = Setting::getSettings();
$files = $asset->assetfiles();

$qr_code = (object) array(
'display' => $settings->qr_code == '1',
Expand Down
2 changes: 2 additions & 0 deletions app/lang/en/admin/hardware/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'expires' => 'Expires',
'fully_depreciated' => 'Fully Depreciated',
'help_checkout' => 'If you wish to assign this asset immediately, you should select "Ready to Deploy" from the status list above, or unexpected things may happen. ',
'help_upload' => 'You can use this to upload purchase orders, invoices, etc.',
'manufacturer' => 'Manufacturer',
'model' => 'Model',
'months' => 'months',
Expand All @@ -27,6 +28,7 @@
'supplier' => 'Supplier',
'tag' => 'Asset Tag',
'update' => 'Asset Update',
'upload_files' => 'Upload Files',
'warranty' => 'Warranty',
'years' => 'years',
)
Expand Down
2 changes: 2 additions & 0 deletions app/lang/en/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
'editprofile' => 'Edit Profile',
'eol' => 'EOL',
'first_name' => 'First Name',
'files' => 'Uploaded Files',
'groups' => 'Groups',
'history_for' => 'History for',
'history' => 'History',
'id' => 'ID',
'last_name' => 'Last Name',
'license' => 'License',
Expand Down
3 changes: 2 additions & 1 deletion app/lang/en/table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

return array(

'actions' => 'Actions'
'actions' => 'Actions',
'action' => 'Action'

);
1 change: 1 addition & 0 deletions app/lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"digits_between" => "The :attribute must be between :min and :max digits.",
"email" => "The :attribute format is invalid.",
"exists" => "The selected :attribute is invalid.",
"file" => "The :attribute is not a valid filetype.",
"image" => "The :attribute must be an image.",
"in" => "The selected :attribute is invalid.",
"integer" => "The :attribute must be an integer.",
Expand Down
20 changes: 13 additions & 7 deletions app/models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ class Asset extends Elegant
protected $table = 'assets';
protected $softDelete = true;
protected $rules = array(
'name' => 'alpha_space',
'asset_tag' => 'required|alpha_space|min:3|unique:assets',
'model_id' => 'required',
'serial' => 'alpha_dash|min:3|unique:assets',
'name' => 'alpha_space',
'asset_tag' => 'required|alpha_space|min:3|unique:assets',
'model_id' => 'required',
'serial' => 'alpha_dash|min:3|unique:assets',
'warranty_months' => 'integer',
'note' => 'alpha_space',
'notes' => 'alpha_space',
'note' => 'alpha_space',
'notes' => 'alpha_space',
'file' => 'mimes:doc,docx,jpeg,jpg,gif,png,pdf,xls,tiff',
);


Expand Down Expand Up @@ -66,7 +67,7 @@ public function assetloc()
*/
public function assetlog()
{
return $this->hasMany('Actionlog','asset_id')->where('asset_type','=','hardware')->orderBy('added_on', 'desc')->withTrashed();
return $this->hasMany('Actionlog','asset_id')->orderBy('added_on', 'desc')->withTrashed();
}

/**
Expand Down Expand Up @@ -169,6 +170,11 @@ public function supplier()
return $this->belongsTo('Supplier','supplier_id');
}

public function assetfiles()
{
return $this->hasMany('FileUpload', 'asset_id');
}

public function months_until_eol()
{
$today = date("Y-m-d");
Expand Down
Empty file added app/storage/uploads/.gitkeep
Empty file.
15 changes: 14 additions & 1 deletion app/views/backend/hardware/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<!-- left column -->
<div class="col-md-12 column">

<form class="form-horizontal" method="post" action="" autocomplete="off" role="form">
<form class="form-horizontal" method="post" action="" autocomplete="off" role="form" enctype="multipart/form-data">
<!-- CSRF Token -->
<input type="hidden" name="_token" value="{{ csrf_token() }}" />

Expand Down Expand Up @@ -155,8 +155,21 @@
{{ $errors->first('assigned_to', '<span class="alert-msg"><i class="icon-remove-sign"></i> :message</span>') }}
</div>
</div>

<!-- File Uploads -->
<div class="form-group {{ $errors->has('file') ? ' has-error' : '' }}">
<label for="parent" class="col-md-2 control-label">@lang('admin/hardware/form.upload_files')
</label>
<div class="col-md-7">
<input class="col-md-6 form-control" type="file" name="file" id="file" />
<p class="help-block">@lang('admin/hardware/form.help_upload')</p>
{{ $errors->first('assigned_to', '<span class="alert-msg"><i class="icon-remove-sign"></i> :message</span>') }}
</div>
</div>
@endif



<!-- Requestable -->
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
Expand Down
55 changes: 43 additions & 12 deletions app/views/backend/hardware/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@

<!-- Licenses assets table -->

<h6>Software Assigned to {{{ $asset->name }}}</h6>
<h6>Software Assigned</h6>
<br>
<!-- checked out assets table -->
@if (count($asset->licenses) > 0)
Expand Down Expand Up @@ -164,13 +164,44 @@
</div>
@endif

<!-- checked out assets table -->
<!-- Files log -->
<h6>@lang('general.files')</h6>
@if (count($asset->assetfiles) > 0)
<table class="table table-hover">
<thead>
<tr>

<th class="col-md-3">@lang('general.date')</th>
<th class="col-md-2"><span class="line"></span>@lang('general.name')</th>
<th class="col-md-2"><span class="line"></span>@lang('general.admin')</th>
<th class="col-md-3"><span class="line"></span>@lang('general.notes')</th>
</tr>
</thead>
<tbody>


@for ($i = 0; $i < count($asset->assetfiles); $i++)
<tr>
<td>{{{ $asset->assetfiles[$i]->created_at }}}</td>
<td>{{{ $asset->assetfiles[$i]->filename }}}</td>
<td>{{{ $asset->assetfiles[$i]->adminuser->fullName() }}}</td>
<td>{{{ $asset->assetfiles[$i]->notes }}}</td>
</tr>
@endfor

</tbody>
</table>
@endif




<!-- History -->
<h6>@lang('general.history')</h6>
<table class="table table-hover">
<thead>
<tr>
<th class="col-md-1"></th>
<th class="col-md-3"><span class="line"></span>@lang('general.date')</th>
<th class="col-md-3">@lang('general.date')</th>
<th class="col-md-2"><span class="line"></span>@lang('general.admin')</th>
<th class="col-md-2"><span class="line"></span>@lang('table.action')</th>
<th class="col-md-2"><span class="line"></span>@lang('general.user')</th>
Expand All @@ -181,14 +212,10 @@
@if (count($asset->assetlog) > 0)
@foreach ($asset->assetlog as $log)
<tr>
<td>
@if ((isset($log->checkedout_to)) && ($log->checkedout_to == $asset->assigned_to))
<i class="icon-star"></i>
@endif
</td>
<td>{{{ $log->added_on }}}</td>
<td>
@if (isset($log->user_id)) {{{ $log->adminlog->fullName() }}}
@if (isset($log->user_id))
{{{ $log->adminlog->fullName() }}}
@endif
</td>
<td>{{ $log->action_type }}</td>
Expand All @@ -200,14 +227,14 @@
@endif
</td>
<td>
@if ($log->note) {{{ $log->note }}}
@if ($log->note)
{{{ $log->note }}}
@endif
</td>
</tr>
@endforeach
@endif
<tr>
<td></td>
<td>{{ $asset->created_at }}</td>
<td>
@if ($asset->adminuser->id) {{{ $asset->adminuser->fullName() }}}
Expand All @@ -223,6 +250,10 @@
</table>






</div>

<!-- side address column -->
Expand Down

0 comments on commit f3c2369

Please sign in to comment.