Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #470 from InfyOmLabs/develop
Browse files Browse the repository at this point in the history
Release v0.1.8-beta
  • Loading branch information
mitulgolakiya authored May 29, 2020
2 parents 0833bd7 + 0e6cd34 commit de90b29
Show file tree
Hide file tree
Showing 27 changed files with 357 additions and 678 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cache:
- node_modules

before_install:
- nvm install 'lts/*'
- nvm install 12.6.0
- npm i -g npm

install:
Expand Down
10 changes: 10 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,14 @@ public function developerWorkReport(Request $request)

return $this->sendResponse($data, 'Daily Work Report retrieved successfully.');
}

/**
* @return JsonResponse
*/
public function userOpenTasks()
{
$data = $this->dashboardRepo->getUserOpenTasks();

return $this->sendResponse($data, 'Open Task retrieved successfully.');
}
}
11 changes: 8 additions & 3 deletions app/Http/Controllers/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ public function index(Request $request)
if ($request->ajax()) {
return Datatables::of((new ReportDataTable())->get($request->only(['filter_created_by'])))->make(true);
}
$users = User::orderBy('name')->pluck('name', 'id');

$users = [];

if (Auth::user()->hasPermissionTo('manage_reports')) {
$users = User::whereIsActive(true)->whereIsEmailVerified(true)->orderBy('name')->pluck('name', 'id');
}

return view('reports.index', compact('users'));
}
Expand Down Expand Up @@ -111,10 +116,10 @@ public function store(CreateReportRequest $request)
$input = $request->all();
$input['owner_id'] = Auth::id();

$this->reportRepository->store($input);
$report = $this->reportRepository->store($input);
Flash::success('Report saved successfully.');

return redirect(route('reports.index'));
return redirect(route('reports.show', $report->id));
}

/**
Expand Down
29 changes: 29 additions & 0 deletions app/Http/Controllers/TimeEntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Queries\TimeEntryDataTable;
use App\Repositories\TimeEntryRepository;
use Auth;
use Carbon\Carbon;
use DataTables;
use Exception;
use Illuminate\Contracts\View\Factory;
Expand Down Expand Up @@ -173,4 +174,32 @@ public function getStartTimer(Request $request)

return $this->sendSuccess('Start timer broadcasts successfully.');
}

/**
* @return string
*/
public function copyTodayActivity()
{
$timeEntries = $this->timeEntryRepository->getTodayEntries();

$note = '**End of the Day - '.Carbon::now()->format('jS M Y')."**\n";

$projects = [];
/** @var TimeEntry $entry */
foreach ($timeEntries as $entry) {
$projects[$entry->task->project->name][$entry->task_id]['name'] = $entry->task->title;
$projects[$entry->task->project->name][$entry->task_id]['note'] = $entry->note;
}

foreach ($projects as $name => $project) {
$note .= "\n*".$name."*\n";

foreach ($project as $task) {
$note .= "\t- ".$task['name'];
$note .= "\t- ".$task['note'];
}
}

return $note;
}
}
11 changes: 11 additions & 0 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Project whereDeletedBy($value)
* @method static \Illuminate\Database\Query\Builder|\App\Models\Project withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\Models\Project withoutTrashed()
*
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Task[] $openTasks
* @property-read int|null $open_tasks_count
*/
class Project extends Model
{
Expand Down Expand Up @@ -140,4 +143,12 @@ public function tasks()
{
return $this->hasMany(Task::class);
}

/**
* @return HasMany
*/
public function openTasks()
{
return $this->tasks()->where('status', '=', Task::STATUS_ACTIVE);
}
}
5 changes: 5 additions & 0 deletions app/Queries/ReportDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ class ReportDataTable
*/
public function get($input = [])
{
$user = getLoggedInUser();
$query = Report::with('user')->select('reports.*');

if (!$user->hasPermissionTo('manage_reports')) {
return $query->where('owner_id', $user->id);
}

$query->when(!empty($input['filter_created_by']), function (Builder $query) use ($input) {
$query->where('owner_id', $input['filter_created_by']);
});
Expand Down
52 changes: 52 additions & 0 deletions app/Repositories/DashboardRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace App\Repositories;

use App\Models\Task;
use App\Models\TimeEntry;
use App\Models\User;
use Arr;
Expand Down Expand Up @@ -163,4 +164,55 @@ public function getDeveloperWorkReport($input)

return $data;
}

/**
* @return mixed
*/
public function getUserOpenTasks()
{
$tasks = Task::with(['project', 'taskAssignee'])->whereStatus(Task::STATUS_ACTIVE)->get();
$result['name'] = [];
$projects = [];
/** @var TimeEntry $entry */
foreach ($tasks as $task) {
$name = $task->project->name;
$id = $task->project->id;

if (!isset($projects[$name])) {
$projects[$name]['name'] = $name;
$projects[$name]['id'] = $id;
}
$taskAssignees = $task->taskAssignee;
/** @var User $taskAssignee */
foreach ($taskAssignees as $taskAssignee) {
$userName = $taskAssignee->name;
if (!in_array($userName, $result['name'])) {
$result['name'][] = $userName;
}

if (!isset($projects[$name][$userName])) {
$projects[$name][$userName] = 0;
}
$projects[$name][$userName] = $projects[$name][$userName] + 1;
}
}

$data = [];
$totalRecords = 0;
foreach ($projects as $key => $project) {
$item['label'] = $project['name'];
$item['data'] = [];
foreach ($result['name'] as $userName) {
$item['data'][] = isset($project[$userName]) ? $project[$userName] : 0;
$totalRecords = $totalRecords + 1;
$item['backgroundColor'] = getColor(0.7, getColorRGBCode($project['id']));
}

$data[] = (object) $item;
}
$result['data'] = $data;
$result['totalRecords'] = $totalRecords;

return $result;
}
}
5 changes: 4 additions & 1 deletion app/Repositories/TaskRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ public function store($input)
}

if (isset($input['assignees']) && !empty($input['assignees'])) {
array_push($input['assignees'], getLoggedInUserId());
$task->taskAssignee()->sync($input['assignees']);
} else {
$task->taskAssignee()->sync(getLoggedInUserId());
}
DB::commit();
} catch (Exception $e) {
Expand Down Expand Up @@ -127,7 +130,7 @@ public function update($input, $id)
$tags = !empty($input['tags']) ? $input['tags'] : [];
$this->attachTags($task, $tags);

$assignees = !empty($input['assignees']) ? $input['assignees'] : [];
$assignees = !empty($input['assignees']) ? $input['assignees'] : $input['assignees'] = getLoggedInUserId();
$task->taskAssignee()->sync($assignees);

DB::commit();
Expand Down
9 changes: 9 additions & 0 deletions app/Repositories/TimeEntryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Auth;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\Builder as BuilderAlias;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
use Log;
Expand Down Expand Up @@ -319,4 +320,12 @@ public function assignTaskToAdmin($input)

return true;
}

/**
* @return TimeEntry[]|Builder[]|BuilderAlias[]|Collection
*/
public function getTodayEntries()
{
return TimeEntry::with('task.project')->whereDate('created_at', '=', Carbon::now()->format('Y-m-d'))->get();
}
}
2 changes: 1 addition & 1 deletion app/Repositories/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function model()
public function getUserList($projectIds = [])
{
/** @var Builder $query */
$query = User::whereIsActive(true)->orderBy('name');
$query = User::whereIsActive(true)->whereIsEmailVerified(true)->orderBy('name');
if (!empty($projectIds)) {
$query = $query->whereHas('projects', function (Builder $query) use ($projectIds) {
$query->whereIn('projects.id', $projectIds);
Expand Down
2 changes: 1 addition & 1 deletion app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function getColorRGBCode($id)
'rgba(247, 83, 148)',
'rgba(255, 160, 137)',
'rgba(143, 80, 157)',
'rgba(255, 255, 255)',
'rgba(255, 109, 1)',
'rgba(162, 173, 208)',
'rgba(255, 67, 164)',
'rgba(252, 108, 133)',
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "infyomlabs/infy-tracker",
"type": "project",
"version": "0.1.7-beta",
"version": "0.1.8-beta",
"description": "Create Projects / Tasks, Track Time, Show Daily Reports",
"keywords": [
"time",
Expand Down
Loading

0 comments on commit de90b29

Please sign in to comment.