Skip to content

Commit

Permalink
updated whole project (laravel v8)
Browse files Browse the repository at this point in the history
  • Loading branch information
unbreakablery committed May 24, 2021
1 parent 8d6fad7 commit 2374a89
Show file tree
Hide file tree
Showing 29 changed files with 3,246 additions and 1,858 deletions.
1 change: 1 addition & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected function create(array $data)
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'role' => '2'
]);
}
}
82 changes: 62 additions & 20 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Tasks;
use App\Models\Task;
use App\Models\User;
use App\Models\Action;
use App\Models\Step;
use App\Models\Setting;
use App\Models\SuggestSetting;

use Auth;

class HomeController extends Controller
Expand All @@ -18,25 +24,66 @@ public function __construct()
$this->middleware('auth');
}

/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$tasks = Tasks::where([
public function tasks(Request $request)
{
if (Auth::user()->role == '2') {
User::where('id', Auth::user()->id)
->update(['role' => '1']);
return redirect()->route('settings');
}

$actions = Action::get();
$steps = Step::get();
$settings = Setting::where('user_id', Auth::user()->id)
->get();

$tasks = Task::where([
['status', '=', '0'],
['user', '=', Auth::user()->id]
])
->join('actions', 'actions.id', '=', 'tasks.action')
->join('steps', 'steps.id', '=', 'tasks.step')
->select('tasks.*', 'actions.name AS action_name', 'steps.name AS step_name')
->orderBy('by_date', 'ASC')
->get()
->all();

return view('pages.tasks', [
'nl_tasks_class' => 'active',
'tasks' => $tasks
]);

$nl_tasks_class = 'active';
$user_action = (isset($request->user_action)) ? $request->user_action : '';
$saved_step = old('saved_step');
$suggest_person_account = (isset($request->person_account)) ? $request->person_account : '';
$suggest_opportunity = (isset($request->opportunity)) ? $request->opportunity : '';

//get suggested steps for additional tasks
$suggest_steps = SuggestSetting::where('user_id', Auth::user()->id)
->where('step_id', (!empty($saved_step)) ? $saved_step : 0)
->join('steps', 'suggest_settings.suggest_step_id', '=', 'steps.id')
->select('steps.id', 'steps.name')
->distinct('steps.id')
->orderBy('steps.name')
->get();
$suggest_actions = Setting::where('user_id', Auth::user()->id)
->where('section_type', 1)
->join('actions', 'settings.section_id', '=', 'actions.id')
->select('actions.id', 'actions.name')
->distinct('actions.id')
->orderBy('actions.name')
->get();

return view('pages.tasks',
compact(
'actions',
'steps',
'settings',
'tasks',
'nl_tasks_class',
'user_action',
'suggest_steps',
'suggest_actions',
'suggest_person_account',
'suggest_opportunity'
)
);
}

public function outbound()
Expand Down Expand Up @@ -95,10 +142,5 @@ public function analytics()
]);
}

public function settings()
{
return view('pages.settings', [

]);
}

}
67 changes: 66 additions & 1 deletion app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,73 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Step;
use App\Models\Action;
use App\Models\Setting;
use App\Models\SuggestSetting;
use Auth;

class SettingsController extends Controller
{
//
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}

public function index()
{
$user_id = Auth::user()->id;
$actions = Action::get();
$steps = Step::get();
$settings = Setting::where('user_id', $user_id)->get();
$suggestSettings = SuggestSetting::where('user_id', $user_id)->get();
$step_setting = Setting::where('user_id', $user_id)
->where('section_type', 2)->get();

return view('pages.settings', compact('actions', 'steps', 'suggestSettings', 'settings', 'step_setting'));
}

public function store(Request $request)
{
$user_id = Auth::user()->id;

Setting::where('user_id', $user_id)
->delete();
SuggestSetting::where('user_id', $user_id)->delete();

if($request->actions != null){
foreach ($request->actions as $action) {
$insert_action = new Setting;
$insert_action->user_id = $user_id;
$insert_action->section_type = 1;
$insert_action->section_id = $action;
$insert_action->save();
}
}
if($request->steps != null){
foreach ($request->steps as $step) {
$insert_step = new Setting;
$insert_step->user_id = $user_id;
$insert_step->section_type = 2;
$insert_step->section_id = $step;
$insert_step->save();
}
}
if($request->suggest_steps != null){
foreach ($request->suggest_steps as $suggest_step) {
$split_suggest_step = explode(":", $suggest_step);
$insert_step = new SuggestSetting;
$insert_step->user_id = $user_id;
$insert_step->step_id = $split_suggest_step[0];
$insert_step->suggest_step_id = $split_suggest_step[1];
$insert_step->save();
}
}
return redirect()->back()->with('success', 'Saved');
}
}
67 changes: 43 additions & 24 deletions app/Http/Controllers/TasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Tasks;
use App\Models\Task;
use Auth;
use DateTime;

Expand All @@ -21,25 +21,44 @@ public function __construct()

public function addTask(Request $request)
{
if ($request->ajax()) {
$action = $request->suggest_action;
$step = $request->suggest_step;
$person_account = $request->suggest_person_account;
$opportunity = $request->suggest_opportunity;
$note = $request->suggest_note;
$by_date = $request->suggest_date;
$priority = $request->suggest_priority;

$task = storeTask($action, $step, $person_account, $opportunity, $note, $by_date, $priority);
$task = getTask($task->id);
return response()->json([
'task_id' => $task->id,
'action_name' => $task->action_name,
'step_name' => $task->step_name,
'status' => 'success'
]);
}

$action = $request->input('action');
$step = $request->input('step');
$from_to_account = $request->input('from-to-account');
$person_account = $request->input('person-account');
$opportunity = $request->input('opportunity');
$note = $request->input('note');
$by_date = $request->input('by-date');
$priority = $request->input('priority');

$task = new Tasks();
$task->user = Auth::user()->id;
$task->action = $action;
$task->step = $step;
$task->from_to_account = $from_to_account;
$task->opportunity = $opportunity;
$task->by_date = DateTime::createFromFormat('d-m-Y', $by_date);
$task->priority = $priority;
$task->save();

// $request->session()->flash('success', 'Task was added successfully ! (Task #: ' . $task->id . ')');
return redirect()->route('tasks');
$task = storeTask($action, $step, $person_account, $opportunity, $note, $by_date, $priority);

return redirect()->route('tasks')->withInput([
'user_action' => 'add-task',
'saved_action' => $task->action,
'saved_step' => $task->step,
'saved_person_account' => $task->person_account,
'saved_opportunity' => $task->opportunity,
]);


}

public function saveTask(Request $request)
Expand All @@ -52,17 +71,17 @@ public function saveTask(Request $request)
$completed_at = DateTime::createFromFormat('d-m-Y', date('d-m-Y'));
}

Tasks::where([
'id' => $id
])
->update([
'status' => $status,
'completed_at' => $completed_at
]);
Task::where([
'id' => $id
])
->update([
'status' => $status,
'completed_at' => $completed_at
]);

return response()->json([
'type' => 'success',
'message' => 'Task #'. $id . ' was updated successfully !'
]);
'type' => 'success',
'message' => 'Task #'. $id . ' was updated successfully !'
]);
}
}
37 changes: 37 additions & 0 deletions app/Http/Helpers/Helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use App\Models\Task;
use Illuminate\Support\Facades\Auth;
// use DateTime;

if (!function_exists('storeTask')) {
function storeTask($action, $step, $person_account, $opportunity, $note, $by_date, $priority) {
$task = new Task();
$task->user = Auth::user()->id;
$task->action = $action;
$task->step = $step;
$task->person_account = $person_account;
$task->opportunity = $opportunity;
$task->note = $note;
$task->by_date = \DateTime::createFromFormat('d-m-Y', $by_date);
$task->priority = $priority;
$task->save();

return $task;
}
}

if (!function_exists('getTask')) {
function getTask($id) {
$task = Task::where([
['tasks.id', '=', $id],
['tasks.user', '=', Auth::user()->id]
])
->join('actions', 'actions.id', '=', 'tasks.action')
->join('steps', 'steps.id', '=', 'tasks.step')
->select('tasks.*', 'actions.name AS action_name', 'steps.name AS step_name')
->get()
->first();
return $task;
}
}
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^6.3.1|^7.0.1",
"laravel/framework": "^7.29",
"laravel/framework": "^8.0",
"laravel/tinker": "^2.5",
"laravel/ui": "^2.5"
"laravel/ui": "^3.0"
},
"require-dev": {
"facade/ignition": "^2.0",
"facade/ignition": "^2.3.6",
"fakerphp/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^4.3",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^8.5.8|^9.3.3"
},
"config": {
Expand All @@ -35,11 +35,12 @@
},
"autoload": {
"psr-4": {
"App\\": "app/"
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
},
"classmap": [
"database/seeds",
"database/factories"
"files": [
"app/Http/Helpers/Helpers.php"
]
},
"autoload-dev": {
Expand Down
Loading

0 comments on commit 2374a89

Please sign in to comment.