Skip to content

Commit

Permalink
Merge branch 'release/1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewNatoli committed Nov 29, 2016
2 parents 4273872 + 7c2d77f commit 6aacd6f
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/Child.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class Child extends Model
"favourite_colour",
"interests",
"additional_ideas",
"preferred_contact_method"
"preferred_contact_method",
"gender"
];

public function household()
Expand Down
3 changes: 3 additions & 0 deletions app/Household.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

use Illuminate\Database\Eloquent\Model;
use Delatbabel\Elocrypt\Elocrypt;
use Illuminate\Database\Eloquent\SoftDeletes;

class Household extends Model
{
use Elocrypt;

use SoftDeletes;

protected $table = "household";

protected $fillable = [
Expand Down
10 changes: 10 additions & 0 deletions app/Http/Controllers/Admin/HouseholdController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ public function show($id)
return $this->viewPath("show", $household);
}

public function delete($id)
{
if(!\Auth::user()->hasRole("admin")) {
return [ "ok" => false, "error" => "Unauthorized" ];
}else{
Household::findOrFail($id)->delete();
return [ "ok" => true ];
}
}

/**
* Show the form for editing the specified user.
*/
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ public function update(User $user, UserRequest $request)
};

$fields = $request->all();
$fields['password'] = Hash::make($fields['password']);
if($fields['password']) {
$fields['password'] = Hash::make($fields['password']);
} else {
unset($fields['password']);
}
$user->fill($fields);
if ($user->save())
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class Export extends Controller {
public function export_data_excel(Request $request) {
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="GiftProjectDump_' . date("YmdHis") . '.xslx"');
header('Content-Disposition: attachment; filename="GiftProjectDump_' . date("YmdHis") . '.xlsx"');
header('Cache-Control: max-age=0');

$excel = new PHPExcel();
Expand Down
1 change: 1 addition & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@

Route::post('household/search', 'HouseholdController@search'); // Used for the table (household.index)
Route::post('household/{id}/review', 'HouseholdController@review'); // Used for feedback
Route::post('household/{id}/delete', 'HouseholdController@delete');

Route::resource('affiliation', 'AffiliationController');
Route::post('affiliation/search', 'AffiliationController@search'); // Used for the table (affiliation.index)
Expand Down
4 changes: 3 additions & 1 deletion app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
"affiliation_id",
"email",
"password",
"active"
"active",
"nomination_limit",
"confirmed_email"
];

protected $hidden = ['password'];
Expand Down
31 changes: 31 additions & 0 deletions database/migrations/2016_11_28_011612_household_deleted_at.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class HouseholdDeletedAt extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('household', function ($table) {
$table->softDeletes();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('household', function ($table) {
$table->dropColumn('deleted_at');
});
}
}
31 changes: 31 additions & 0 deletions database/migrations/2016_11_28_034450_add_child_gender.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddChildGender extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('child', function ($table) {
$table->string('gender')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('child', function ($table) {
$table->dropColumn('gender');
});
}
}
31 changes: 31 additions & 0 deletions resources/views/admin/households/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ function renderActions (data, type, row) {
let output = '<ul class="list-inline no-margin-bottom">';
output += '<li><button class="btn btn-xs bg-navy action" data-action="show"><i class="fa fa-search"></i> Show</button></li>';
output += '<li><button class="btn btn-xs bg-olive action" data-action="edit"><i class="fa fa-pencil-square-o"></i> Edit</button></li>';
@if (Auth::user()->hasRole("admin"))
output += '<li><button class="btn btn-xs btn-danger action" data-action="delete"><i class="fa fa-trash"></i> Delete</button></li>';
@endif
output += '</ul>';
return output;
Expand All @@ -91,6 +95,33 @@ function renderActions (data, type, row) {
case "edit":
window.location.href += "/" + row.id +"/edit";
break;
@if (Auth::user()->hasRole("admin"))
case "delete":
console.log(element);
if(!confirm("Delete nomination of " + row.name_last + " household?")){
return;
}
var self = this;
$.ajax ({
url: "/admin/household/" + row.id + "/delete",
type: "POST",
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
},
success: function (results) {
if (!results.ok)
{
alert("Error deleting nomination: " + (results.error || "unknown error"));
return;
}
element.closest('tr').remove();
},
error: function () {
alert("Error deleting nomination: failed");
}
});
break;
@endif
}
});
Expand Down
1 change: 1 addition & 0 deletions resources/views/admin/households/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<li class="list-group-item"><b>First Name</b><span class="pull-right">{{$child->name_first}}</span></li>
<li class="list-group-item"><b>Middle Name</b><span class="pull-right">{{$child->name_middle}}</span></li>
<li class="list-group-item"><b>Last Name</b><span class="pull-right">{{$child->name_last}}</span></li>
<li class="list-group-item"><b>Gender</b> <span class="pull-right">{{ $child->gender }}</span></li>
<li class="list-group-item"><b>Date of Birth</b><span class="pull-right">{{$child->dob}}</span></li>
<li class="list-group-item"><b>Age</b><span class="pull-right">{{$child->age}}</span></li>
<li class="list-group-item"><b>Ethnicity</b><span class="pull-right">{{$child->race}}</span></li>
Expand Down
15 changes: 13 additions & 2 deletions resources/views/partials/forms/household.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,18 @@
<!--</div> /box-body -->

<div class="row">
<div class="col-xs-12 col-sm-4">
<div class="col-xs-12 col-sm-2">
<div class="form-group required">
<label for="gender" class="control-label">Gender</label>
<select class="form-control" v-model="record.gender" name="gender">
<option value="">==== Select ====</option>
<option value="M">Male</option>
<option value="F">Female</option>
</select>
</div>
</div>

<div class="col-xs-12 col-sm-3">

<div class="form-group required">

Expand All @@ -299,7 +310,7 @@
</div>
</div>

<div class="col-xs-12 col-sm-4">
<div class="col-xs-12 col-sm-3">

<div class="form-group required">

Expand Down

0 comments on commit 6aacd6f

Please sign in to comment.