Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add camps tab #207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/Camp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Camp extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $guarded = [];
}
107 changes: 107 additions & 0 deletions app/Http/Controllers/CampController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace App\Http\Controllers;

use App\Repositories\CampRepository;
use Illuminate\Http\Request;
use Validator;

class CampController extends Controller
{
private $camp;

/**
* CampController constructor.
* @param CampRepository $campRepository
*/
public function __construct(CampRepository $campRepository)
{
$this->camp = $campRepository;
}

/**
* Save camp
*
* @param Request $request
* @return $this|\Illuminate\Http\RedirectResponse
*/
public function save(Request $request)
{

$messages = [
'region.required' => 'ග්‍රාම නිළධාරි වසම ඇතුලත් කිරීම අනිවාර්යයි',
'location.required' => 'කදවුරු පිහිටි ස්ථානය ඇතුලත් කිරීම අනිවාර්යයි',
'g-recaptcha-response.required' => 'ඔබව තහවුරු කිරීම අනිවාර්යයි'
];

$validator = Validator::make($request->all(), [
'region' => 'required|max:100',
'location' => 'required|max:100'
], $messages);

if ($validator->fails()) {
return redirect('/camps/add')
->with('isSuccess', false)
->with('errors', $validator->errors()->all())
->withInput();
} else {
$response = $this->camp->addCamp($request->all());
if ($response) {
return redirect('/camps')
->with('isSuccess', true)
->with('message', 'සාර්ථකව ඇතුලත්කරන ලදී.');
} else {
return redirect('/camps/add')
->with('isSuccess', false)
->with('errors', ['ඇතුලත්කිරීම දෝෂ සහිතය.'])
->withInput();
}
}
}

/**
* List all camps
*
* @return $this
*/
public function index()
{
$camps = $this->camp->getCamps();

return view('/frontend/camps/index')->with(
['camps' => ($camps) ? $camps : array()]
);
}

/**
* Add camp
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function add()
{
return view('/frontend/camps/add');
}

/**
* Show camp
*
* @param $id
* @return mixed
*/
public function show($id)
{
$camp = $this->camp->findCamp($id);

if ($camp) {
return Response::json([
'isSuccess' => true,
'donation' => $camp,
]);
} else {
return Response::json([
'isSuccess' => false
]);
}
}
}
63 changes: 63 additions & 0 deletions app/Repositories/CampRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
namespace App\Repositories;


use App\Camp;
use App\Repositories\Contracts\CampInterface;
use Illuminate\Support\Facades\Log;

class CampRepository implements CampInterface
{
/**
* Add camp
*
* @param $input
* @return mixed
*/
public function addCamp($input)
{
try {
Camp::create($input);
return true;
} catch (\Exception $e) {
Log::error($e->getMessage());
echo $e->getMessage();
return false;
}
}

/**
* Get all camps
*
* @param $limit
* @return mixed
*/
public function getCamps($limit = null)
{
try {
if ($limit) {
return Camp::orderBy('id', 'desc')->take($limit)->get();
}
return Camp::orderBy('id', 'desc')->paginate(10);
} catch (\Exception $e) {
Log::error($e->getMessage());
return false;
}
}

/**
* Find camp
*
* @param $id
* @return mixed
*/
public function findCamp($id)
{
try {
return Camp::find($id);
} catch (\Exception $e) {
Log::error($e->getMessage());
return false;
}
}
}
29 changes: 29 additions & 0 deletions app/Repositories/Contracts/CampInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
namespace App\Repositories\Contracts;

interface CampInterface
{
/**
* Add camp
*
* @param $input
* @return mixed
*/
public function addCamp($input);

/**
* Get all camps
*
* @param $limit
* @return mixed
*/
public function getCamps($limit = null);

/**
* Find camp
*
* @param $id
* @return mixed
*/
public function findCamp($id);
}
77 changes: 77 additions & 0 deletions database/migrations/2018_05_13_082339_create_camp_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

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

class CreateCampTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('camps', function (Blueprint $table) {
$table->increments('id');
$table->string('region');
$table->string('name')->nullable();
$table->string('telephone')->nullable();
$table->string('email')->nullable();

$table->integer('families')->nullable();
$table->integer('men')->nullable();
$table->integer('women')->nullable();
$table->integer('children')->nullable();
$table->integer('babies')->nullable();
$table->integer('pregnents')->nullable();
$table->integer('heart_patients')->nullable();
$table->integer('blood_pressure_patients')->nullable();
$table->integer('special_needs')->nullable();
$table->integer('other_patients')->nullable();
$table->integer('elders')->nullable();

$table->string('location');
$table->integer('count')->nullable();
$table->string('geograghy')->nullable();
$table->string('route')->nullable();
$table->string('pre_max_water_level')->nullable();
$table->string('pre_settle_time')->nullable();

$table->string('transport_categories')->nullable();
$table->string('transport_suppliers')->nullable();
$table->string('boats_usable_locations')->nullable();
$table->string('current_wires_locations')->nullable();
$table->string('tree_cutter_suppliers')->nullable();

$table->integer('water_motors')->nullable();
$table->integer('water_tanks')->nullable();
$table->integer('lifesaving_jackets')->nullable();
$table->integer('sanitary')->nullable();
$table->integer('generators')->nullable();
$table->integer('torches')->nullable();
$table->integer('mosquito_nets_pillows')->nullable();
$table->integer('cooking_instruments')->nullable();

$table->integer('deaths')->nullable();
$table->integer('casualties')->nullable();
$table->integer('full_damage_houses')->nullable();
$table->integer('half_damage_houses')->nullable();
$table->integer('full_damage_business')->nullable();
$table->integer('half_damage_business')->nullable();

$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('camps');
}
}
42 changes: 42 additions & 0 deletions public/css/step-form.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
body {
margin-top:40px;
}
.stepwizard-step p {
margin-top: 10px;
}
.stepwizard-row {
display: table-row;
}
.stepwizard {
display: table;
width: 50%;
position: relative;
}
.stepwizard-step button[disabled] {
opacity: 1 !important;
filter: alpha(opacity=100) !important;
}
.stepwizard-row:before {
top: 14px;
bottom: 0;
position: absolute;
content: " ";
width: 100%;
height: 1px;
background-color: #ccc;
z-order: 0;
}
.stepwizard-step {
display: table-cell;
text-align: center;
position: relative;
}
.btn-circle {
width: 30px;
height: 30px;
text-align: center;
padding: 6px 0;
font-size: 12px;
line-height: 1.428571429;
border-radius: 15px;
}
42 changes: 42 additions & 0 deletions public/js/step-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
$(document).ready(function () {
var navListItems = $('div.setup-panel div a'),
allWells = $('.setup-content'),
allNextBtn = $('.nextBtn');

allWells.hide();

navListItems.click(function (e) {
e.preventDefault();
var $target = $($(this).attr('href')),
$item = $(this);

if (!$item.hasClass('disabled')) {
navListItems.removeClass('btn-primary').addClass('btn-default');
$item.addClass('btn-primary');
allWells.hide();
$target.show();
$target.find('input:eq(0)').focus();
}
});

allNextBtn.click(function(){
var curStep = $(this).closest(".setup-content"),
curStepBtn = curStep.attr("id"),
nextStepWizard = $('div.setup-panel div a[href="#' + curStepBtn + '"]').parent().next().children("a"),
curInputs = curStep.find("input[type='text'],input[type='url']"),
isValid = true;

$(".form-group").removeClass("has-error");
for(var i=0; i<curInputs.length; i++){
if (!curInputs[i].validity.valid){
isValid = false;
$(curInputs[i]).closest(".form-group").addClass("has-error");
}
}

if (isValid)
nextStepWizard.removeAttr('disabled').trigger('click');
});

$('div.setup-panel div a.btn-primary').trigger('click');
});
Loading